IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37807


Ignore:
Timestamp:
Jan 11, 2015, 2:14:39 PM (12 years ago)
Author:
eugene
Message:

merge changes from eam branch ipp-20140904

Location:
trunk/Ohana
Files:
304 edited
133 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/Makefile.in

    r35110 r37807  
    3434dvopsps     \
    3535elixir      \
     36fakeastro   \
    3637gastro      \
    3738gastro2     \
  • trunk/Ohana/configure.tcsh

    r34088 r37807  
    240240set needlibs   = "$needlibs X11"
    241241set needlibs   = "$needlibs pthread"
     242set needlibs   = "$needlibs gsl"
     243set needlibs   = "$needlibs gslcblas"
    242244set needlibs   = "$needlibs m"
    243245
     
    269271set needincs = "$needincs png.h"
    270272set needincs = "$needincs pthread.h"
     273set needincs = "$needincs gsl/gsl_sf_legendre.h"
    271274set needincs = "$needincs readline/history.h"
    272275set needincs = "$needincs readline/readline.h"
  • trunk/Ohana/src/addstar/Makefile

    r37357 r37807  
    2424sedstar      : $(BIN)/sedstar.$(ARCH)
    2525load2mass    : $(BIN)/load2mass.$(ARCH)
     26loadstarpar  : $(BIN)/loadstarpar.$(ARCH)
     27loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH)
     28loadICRF  : $(BIN)/loadICRF.$(ARCH)
     29loadICRF_client : $(BIN)/loadICRF_client.$(ARCH)
    2630loadwise     : $(BIN)/loadwise.$(ARCH)
    2731dumpskycells : $(BIN)/dumpskycells.$(ARCH)
     
    3135mkcmf        : $(BIN)/mkcmf.$(ARCH)
    3236
    33 all: addstar addstar_client sedstar load2mass skycells mkcmf loadwise loadsupercos dumpskycells findskycell
    34 
    35 INSTALL = addstar addstar_client sedstar load2mass skycells mkcmf loadwise loadsupercos dumpskycells findskycell
     37all: addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
     38
     39INSTALL = addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadsupercos dumpskycells findskycell
    3640
    3741# I need to fix the client/server version of addstar now that I have dropped Stars
     
    241245$(SRC)/psps_ids.$(ARCH).o
    242246
     247LOAD-STARPAR = \
     248$(SRC)/loadstarpar.$(ARCH).o \
     249$(SRC)/ConfigInit.$(ARCH).o \
     250$(SRC)/SetSignals.$(ARCH).o \
     251$(SRC)/Shutdown.$(ARCH).o \
     252$(SRC)/SkyRegionUtils.$(ARCH).o \
     253$(SRC)/args_loadstarpar.$(ARCH).o \
     254$(SRC)/find_matches_starpar.$(ARCH).o \
     255$(SRC)/loadstarpar_catalog.$(ARCH).o \
     256$(SRC)/loadstarpar_io.$(ARCH).o \
     257$(SRC)/loadstarpar_make_subset.$(ARCH).o \
     258$(SRC)/loadstarpar_readstars.$(ARCH).o \
     259$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
     260$(SRC)/loadstarpar_save_remote.$(ARCH).o \
     261$(SRC)/loadstarpar_table.$(ARCH).o \
     262$(SRC)/psps_ids.$(ARCH).o
     263
     264LOAD-STARPAR-CLIENT = \
     265$(SRC)/loadstarpar_client.$(ARCH).o \
     266$(SRC)/ConfigInit.$(ARCH).o \
     267$(SRC)/SetSignals.$(ARCH).o \
     268$(SRC)/Shutdown.$(ARCH).o \
     269$(SRC)/SkyRegionUtils.$(ARCH).o \
     270$(SRC)/args_loadstarpar.$(ARCH).o \
     271$(SRC)/find_matches_starpar.$(ARCH).o \
     272$(SRC)/loadstarpar_catalog.$(ARCH).o \
     273$(SRC)/loadstarpar_io.$(ARCH).o \
     274$(SRC)/loadstarpar_make_subset.$(ARCH).o \
     275$(SRC)/loadstarpar_readstars.$(ARCH).o \
     276$(SRC)/loadstarpar_remote_hosts.$(ARCH).o \
     277$(SRC)/loadstarpar_save_remote.$(ARCH).o \
     278$(SRC)/loadstarpar_table.$(ARCH).o \
     279$(SRC)/psps_ids.$(ARCH).o
     280
     281LOAD-ICRF = \
     282$(SRC)/loadICRF.$(ARCH).o \
     283$(SRC)/ConfigInit.$(ARCH).o \
     284$(SRC)/SetSignals.$(ARCH).o \
     285$(SRC)/Shutdown.$(ARCH).o \
     286$(SRC)/SkyRegionUtils.$(ARCH).o \
     287$(SRC)/args_loadICRF.$(ARCH).o \
     288$(SRC)/find_matches_ICRF.$(ARCH).o \
     289$(SRC)/loadICRF_catalog.$(ARCH).o \
     290$(SRC)/loadICRF_io.$(ARCH).o \
     291$(SRC)/loadICRF_make_subset.$(ARCH).o \
     292$(SRC)/loadICRF_readstars.$(ARCH).o \
     293$(SRC)/loadICRF_remote_hosts.$(ARCH).o \
     294$(SRC)/loadICRF_save_remote.$(ARCH).o \
     295$(SRC)/loadICRF_table.$(ARCH).o \
     296$(SRC)/psps_ids.$(ARCH).o
     297
     298LOAD-ICRF-CLIENT = \
     299$(SRC)/loadICRF_client.$(ARCH).o \
     300$(SRC)/ConfigInit.$(ARCH).o \
     301$(SRC)/SetSignals.$(ARCH).o \
     302$(SRC)/Shutdown.$(ARCH).o \
     303$(SRC)/SkyRegionUtils.$(ARCH).o \
     304$(SRC)/args_loadICRF.$(ARCH).o \
     305$(SRC)/find_matches_ICRF.$(ARCH).o \
     306$(SRC)/loadICRF_catalog.$(ARCH).o \
     307$(SRC)/loadICRF_io.$(ARCH).o \
     308$(SRC)/loadICRF_make_subset.$(ARCH).o \
     309$(SRC)/loadICRF_readstars.$(ARCH).o \
     310$(SRC)/loadICRF_remote_hosts.$(ARCH).o \
     311$(SRC)/loadICRF_save_remote.$(ARCH).o \
     312$(SRC)/loadICRF_table.$(ARCH).o \
     313$(SRC)/psps_ids.$(ARCH).o
     314
    243315LOAD-WISE = \
    244316$(SRC)/loadwise.$(ARCH).o \
     
    309381$(SRC)/Shutdown.$(ARCH).o
    310382
    311 $(ADDSTARC)       : $(INC)/addstar.h
    312 $(ADDSTARD)       : $(INC)/addstar.h
    313 $(ADDSTART)       : $(INC)/addstar.h
    314 $(ADDSTAR)        : $(INC)/addstar.h
    315 $(ADDSTAR_CLIENT) : $(INC)/addstar.h
    316 $(SKYCELLS)       : $(INC)/addstar.h
    317 $(DUMPSKYCELLS)   : $(INC)/addstar.h
    318 $(FINDSKYCELL)    : $(INC)/addstar.h
    319 $(LOAD-2MASS)     : $(INC)/addstar.h $(INC)/2mass.h
    320 $(LOAD-WISE)      : $(INC)/addstar.h $(INC)/WISE.h
    321 $(MKCMF)          : $(INC)/mkcmf.h
     383$(ADDSTARC)            : $(INC)/addstar.h
     384$(ADDSTARD)            : $(INC)/addstar.h
     385$(ADDSTART)            : $(INC)/addstar.h
     386$(ADDSTAR)             : $(INC)/addstar.h
     387$(ADDSTAR_CLIENT)      : $(INC)/addstar.h
     388$(SKYCELLS)            : $(INC)/addstar.h
     389$(DUMPSKYCELLS)        : $(INC)/addstar.h
     390$(FINDSKYCELL)         : $(INC)/addstar.h
     391$(LOAD-2MASS)          : $(INC)/addstar.h $(INC)/2mass.h
     392$(LOAD-STARPAR)        : $(INC)/addstar.h $(INC)/loadstarpar.h
     393$(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h
     394$(LOAD-ICRF)           : $(INC)/addstar.h $(INC)/loadICRF.h
     395$(LOAD-ICRF-CLIENT)    : $(INC)/addstar.h $(INC)/loadICRF.h
     396$(LOAD-WISE)           : $(INC)/addstar.h $(INC)/WISE.h
     397$(MKCMF)               : $(INC)/mkcmf.h
    322398
    323399$(BIN)/addstar.$(ARCH)        : $(ADDSTAR)
     
    330406$(BIN)/load2mass.$(ARCH)      : $(LOAD-2MASS)
    331407$(BIN)/loadwise.$(ARCH)       : $(LOAD-WISE)
     408$(BIN)/loadstarpar.$(ARCH)    : $(LOAD-STARPAR)
     409$(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT)
     410$(BIN)/loadICRF.$(ARCH)       : $(LOAD-ICRF)
     411$(BIN)/loadICRF_client.$(ARCH): $(LOAD-ICRF-CLIENT)
    332412$(BIN)/loadsupercos.$(ARCH)   : $(LOAD-SUPERCOS)
    333413$(BIN)/skycells.$(ARCH)       : $(SKYCELLS)
  • trunk/Ohana/src/addstar/include/WISE.h

    r33963 r37807  
    2121short WISE_W1, WISE_W2, WISE_W3, WISE_W4;
    2222
    23 int ALLSKY;
     23enum {MODE_NONE, MODE_ALLWISE, MODE_ALLSKY, MODE_PRELIM};
     24int MODE;
    2425
    2526AddstarClientOptions args_loadwise (int argc, char **argv, AddstarClientOptions options);
    2627
    27 int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options, int ALLSKY);
     28int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options);
    2829
    2930int getWISE_setup ();
  • trunk/Ohana/src/addstar/include/addstar.h

    r37357 r37807  
    2020# define IN_REGION(R,D) ( \
    2121((D) >= region[0].Dmin) && ((D) < region[0].Dmax) && \
    22 ((R) >= region[0].Rmin)  && ((R) < region[0].Rmax))
     22((R) >= region[0].Rmin) && ((R) < region[0].Rmax))
    2323
    2424/* grab named photcode */
     
    3131# define dCOS(A)   ((double) cos ((double)RAD_DEG*A))
    3232# define dSIN(A)   ((double) sin ((double)RAD_DEG*A))
     33
     34# define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
    3335
    3436typedef struct {
     
    326328int strextend (char *input, char *format,...);
    327329
     330void initMosaicCoords ();
     331void saveMosaicCoords (Coords *input);
     332
     333
    328334/**
    329335    there is an inconsistency to be resolved: fixed structures (like Image)
  • trunk/Ohana/src/addstar/src/LoadData.c

    r37357 r37807  
    3333  // we need to perform that analysis here
    3434  GetZeroPointExposure (headers, headerSets, Nimages);
     35
     36  if (!options[0].mosaic) {
     37    // we are requiring a single set of N x WRPs + 1 DIS per file set.
     38    // NOTE: if the -mosaic was supplied, do not reset the mosaic coords here
     39    initMosaicCoords ();
     40  }
    3541
    3642  // now run through the images, interpret the headers and read the stars
  • trunk/Ohana/src/addstar/src/LoadDataPMM.c

    r36485 r37807  
    193193
    194194    // XXX for now, we define a totally fake coordinate system centered on the plate center
    195     strcpy (image[0].coords.ctype, "DEC--TAN");
     195    InitCoords (&image[0].coords, "DEC--TAN");
    196196   
    197197    image[0].coords.crval1  = pmm_get_ra (RA);
     
    203203    image[0].coords.crpix2 = 0.5*PLATE_NY;
    204204    image[0].coords.cdelt1 = image[0].coords.cdelt2 = 0.9 / 3600.0;
    205 
    206     image[0].coords.pc1_1 = 0.0;
    207     image[0].coords.pc1_2 = 1.0;
    208     image[0].coords.pc2_1 = 1.0;
    209     image[0].coords.pc2_2 = 0.0;
    210 
    211     image[0].coords.Npolyterms = 0;
    212     memset (image[0].coords.polyterms, 0, 2*7*sizeof(float));
    213205
    214206    image[0].NX = PLATE_NX;
  • trunk/Ohana/src/addstar/src/LoadStars.c

    r28241 r37807  
    8888      exit (1);
    8989    }
     90    /* supplied photcode is incompatible with multi-chip images */
     91    if ((NheaderSets > 1) && options[0].mosaic) {
     92      fprintf (stderr, "ERROR: -mosaic cannot be supplied to multiple images\n");
     93      exit (1);
     94    }
    9095
    9196    // if these are SDSS data, load with SDSS-specific wrapper
  • trunk/Ohana/src/addstar/src/NewImage.c

    r10939 r37807  
    3333      goto reject;
    3434    }
     35    saveMosaicCoords (mosaic);
    3536  }   
    3637
  • trunk/Ohana/src/addstar/src/ReadImageHeader.c

    r37036 r37807  
    11# include "addstar.h"
     2
     3// for DIS/WRP sets, we need to save the DIS set and supply it to the WRP entries
     4static Coords *mosaic = NULL;
     5
     6void initMosaicCoords () {
     7  mosaic = NULL;
     8}
     9
     10void saveMosaicCoords (Coords *input) {
     11  ALLOCATE (mosaic, Coords, 1);
     12  memcpy (mosaic, input, sizeof(Coords));
     13}
    214
    315/* read an image header corresponding to a CMF / CMP data block */
     
    5466  /* only load astrometry, NAXIS1,2, and time if this is a MOSAIC_PHU (ctype is ....-DIS) */
    5567  if (!strcmp (&image[0].coords.ctype[4], "-DIS")) {
    56     RegisterMosaic (&image[0].coords);
     68    saveMosaicCoords (&image[0].coords);
    5769    return (TRUE);
    5870  }
     
    7991  }
    8092  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
    81     if (!isRegisteredMosaic()) {
     93    if (!mosaic) {
    8294      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
    8395      return (FALSE);
    8496    }
     97    image[0].coords.mosaic = mosaic;
    8598  } else {
    8699    /* force image to lie in 0-360 range */
  • trunk/Ohana/src/addstar/src/ReadStarsSDSS.c

    r36485 r37807  
    201201   
    202202    // XXX for now, we define a totally fake coordinate system centered on the first listed star
    203     strcpy (images[N].coords.ctype, "DEC--TAN");
    204    
     203    InitCoords (&images[N].coords, "DEC--TAN");
    205204    images[N].coords.crval1 = stars[0].average.R;
    206205    images[N].coords.crval2 = stars[0].average.D;
    207    
    208206    images[N].coords.crpix1 = stars[0].measure.Xccd;
    209207    images[N].coords.crpix2 = stars[0].measure.Yccd;
    210208    images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
    211 
    212     images[N].coords.pc1_1 = 0.0;
    213     images[N].coords.pc1_2 = 1.0;
    214     images[N].coords.pc2_1 = 1.0;
    215     images[N].coords.pc2_2 = 0.0;
    216 
    217     images[N].coords.Npolyterms = 0;
    218     memset (images[N].coords.polyterms, 0, 2*7*sizeof(float));
    219209
    220210    images[N].NX = 2048;
  • trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c

    r27435 r37807  
    2121
    2222  /* find correpsonding regions for image */
    23   RegisterMosaic (mosaic);
    2423  skylist = NULL;
    2524  newlist = NULL;
  • trunk/Ohana/src/addstar/src/addstar.c

    r37357 r37807  
    132132      }
    133133    }
    134     MARKTIME ("load cpt: %f sec\n", dtime); RESETTIME;
     134    if (VERBOSE) MARKTIME ("load cpt: %f sec\n", dtime); RESETTIME;
    135135
    136136    // Naves_disk == 0 implies an empty catalog file
     
    163163        break;
    164164    }
    165     MARKTIME ("match stars: %f sec\n", dtime); RESETTIME;
     165    if (VERBOSE) MARKTIME ("match stars: %f sec\n", dtime); RESETTIME;
    166166
    167167    /* report total updated values */
     
    183183    dvo_catalog_unlock (&catalog);
    184184    dvo_catalog_free (&catalog);
    185     MARKTIME ("save cpt: %f sec\n", dtime); RESETTIME;
     185    if (VERBOSE) MARKTIME ("save cpt: %f sec\n", dtime); RESETTIME;
    186186
    187187    if (options.mode == ADDSTAR_MODE_REFCAT) free (stars);
  • trunk/Ohana/src/addstar/src/args.c

    r37357 r37807  
    175175      exit (1);
    176176    }
    177     RegisterMosaic (&MOSAIC);
     177    saveMosaicCoords (&MOSAIC);
    178178    remove_argument (N, &argc, argv);
    179179    gfits_free_header (&header);
  • trunk/Ohana/src/addstar/src/args_client.c

    r33963 r37807  
    8383      exit (1);
    8484    }
    85     RegisterMosaic (&MOSAIC);
     85    saveMosaicCoords (&MOSAIC);
    8686    remove_argument (N, &argc, argv);
    8787    gfits_free_header (&header);
  • trunk/Ohana/src/addstar/src/args_loadwise.c

    r33963 r37807  
    5353  }
    5454
     55enum {MODE_NONE, MODE_ALLWISE, MODE_ALLSKY, MODE_PRELIM};
     56int MODE;
     57
    5558  /* load the prelim data dump */
    56   ALLSKY = TRUE;
    57   if ((N = get_argument (argc, argv, "-prelim"))) {
    58     ALLSKY = FALSE;
     59  MODE = MODE_ALLWISE;
     60  if ((N = get_argument (argc, argv, "-mode"))) {
     61    MODE = MODE_NONE;
     62    remove_argument (N, &argc, argv);
     63    if (!strcasecmp(argv[N], "allwise")) MODE = MODE_ALLWISE;
     64    if (!strcasecmp(argv[N], "allsky"))  MODE = MODE_ALLSKY;
     65    if (!strcasecmp(argv[N], "prelim"))  MODE = MODE_PRELIM;
     66    if (MODE == MODE_NONE) {
     67      fprintf (stderr, "invalid mode: %s\n", argv[N]);
     68      exit (2);
     69    }
    5970    remove_argument (N, &argc, argv);
    6071  }
  • trunk/Ohana/src/addstar/src/build_links.c

    r37334 r37807  
    11# include "addstar.h"
    2 
    3 # define myAbortF(FORMAT,...) { fprintf (stderr, FORMAT, __VA_ARGS__); abort(); }
    42
    53/*
  • trunk/Ohana/src/addstar/src/fakeimage.c

    r37036 r37807  
    33Image *fakeimage (char *rootname, off_t *Nimage, int photcode) {
    44
    5   int i, j, Nx, Ny, Nchips;
     5  int i, Nx, Ny, Nchips;
    66  double pltscale, pixscale;
    77  double Rmin, Rmax, Dmin, Dmax;
     
    3333
    3434  /* create a mosaic distortion structure */
    35   strcpy (MOSAIC.ctype, "DEC--DIS");
     35  InitCoords (&MOSAIC, "DEC--DIS");
    3636  MOSAIC.crval1 = FAKE_RA;
    3737  MOSAIC.crval2 = FAKE_DEC;
    38  
    39   MOSAIC.crpix1 = MOSAIC.crpix2 = 0.0;
    4038 
    4139  /* mosaic 'pixels' are millimeters */
     
    4947
    5048  MOSAIC.Npolyterms = 3;
    51   for (i = 0; i < 7; i++) {
    52     MOSAIC.polyterms[i][0] = 0;
    53     MOSAIC.polyterms[i][1] = 0;
    54   }
    5549  ScanConfig (config, "DPLATE_X",   "%lf", 0, &pltscale);
    5650  MOSAIC.polyterms[3][0] = pltscale;  // L : X^3 Y^0
     
    5953  MOSAIC.polyterms[4][1] = pltscale;  // M : X^0 Y^0
    6054  MOSAIC.polyterms[6][1] = pltscale;  // M : X^2 Y^0
    61 
    62   RegisterMosaic (&MOSAIC);
    6355
    6456  /* some basic data about the chisp */
     
    8577    strcpy (image[i+1].name, name);
    8678
    87     strcpy (image[i+1].coords.ctype, "DEC--WRP");
     79    InitCoords (&image[i+1].coords, "DEC--WRP");
    8880   
    8981    image[i+1].coords.crval1 = dX*pixscale;
    9082    image[i+1].coords.crval2 = dY*pixscale;
    91    
    92     image[i+1].coords.crpix1 = image[i+1].coords.crpix2 = 0.0;
     83
    9384    image[i+1].coords.cdelt1 = image[i+1].coords.cdelt2 = pixscale;
    9485
    95     image[i+1].coords.pc1_1 = 1.0;
    96     image[i+1].coords.pc1_2 = 0.0;
    97     image[i+1].coords.pc2_1 = 0.0;
    98     image[i+1].coords.pc2_2 = 1.0;
    99 
    100     image[i+1].coords.Npolyterms = 0;
    101     for (j = 0; j < 7; j++) {
    102       image[i+1].coords.polyterms[j][0] = 0;
    103       image[i+1].coords.polyterms[j][1] = 0;
    104     }
     86    image[i+1].coords.mosaic = &MOSAIC;
    10587
    10688    image[i+1].sidtime  = 0.0;
  • trunk/Ohana/src/addstar/src/find_matches.c

    r37036 r37807  
    5353   * coordops.update.c).  We use the center of the region (catalog) for crval1,2.
    5454   */
     55  InitCoords (&tcoords, "DEC--ARC");
    5556  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5657  if (region[0].Dmax < 90) {
     
    5960    tcoords.crval2 = 90.0;
    6061  }
    61   tcoords.crpix1 = 0;
    62   tcoords.crpix2 = 0;
    6362  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    64   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    65   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    66   tcoords.Npolyterms = 1;
    67   strcpy (tcoords.ctype, "DEC--ARC");
    6863
    6964  /* build spatial index (RA sort) referencing input array sequence */
  • trunk/Ohana/src/addstar/src/find_matches_closest.c

    r37036 r37807  
    5353   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    5454   */
     55  InitCoords (&tcoords, "DEC--ARC");
    5556  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5657  if (region[0].Dmax < 90) {
     
    5960    tcoords.crval2 = 90.0;
    6061  }
    61   tcoords.crpix1 = 0;
    62   tcoords.crpix2 = 0;
    6362  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    64   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    65   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    66   tcoords.Npolyterms = 1;
    67   strcpy (tcoords.ctype, "DEC--ARC");
    6863
    6964  /* build spatial index (RA sort) referencing input array sequence */
  • trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r37036 r37807  
    4747   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    4848   */
     49  InitCoords (&tcoords, "DEC--ARC");
    4950  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5051  if (region[0].Dmax < 90) {
     
    5354    tcoords.crval2 = 90.0;
    5455  }
    55   tcoords.crpix1 = 0.0;
    56   tcoords.crpix2 = 0.0;
    5756  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    58   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    59   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    60   tcoords.Npolyterms = 0;
    61   strcpy (tcoords.ctype, "DEC--ARC");
    6257 
    6358  /* build spatial index (RA sort) referencing input array sequence */
  • trunk/Ohana/src/addstar/src/find_matches_refstars.c

    r37036 r37807  
    5151  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    5252  /* reference for coords is catalog center */
     53  InitCoords (&tcoords, "DEC--ZEA");
    5354  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    5455  tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax);
    55   tcoords.crpix1 = tcoords.crpix2 = 0.0;
    5656  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    57   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    58   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    59   strcpy (tcoords.ctype, "DEC--ZEA");
    60   tcoords.Npolyterms = 0;
    6157 
    6258  for (i = 0; i < Nstars; i++) {
  • trunk/Ohana/src/addstar/src/find_missing.c

    r10937 r37807  
    1414    REALLOCATE (catalog[0].missing, Missing, NMISS);
    1515  }
    16   if (!FindMosaicForImage (overlap, Noverlap, j)) continue;
    1716  if (!in_image (catalog[0].average[Nave].R, catalog[0].average[Nave].D, &overlap[j])) continue;
    1817  add_miss_link (&catalog[0].average[Nave], next_miss, Nmiss);
     
    2726/* add reference for undetected catalog stars */
    2827/* XXX allow this option only for single images? */
    29 if (!strcmp (&image[0].coords.ctype[4], "-WRP")) RegisterMosaic (mosaic);
     28if (!strcmp (&image[0].coords.ctype[4], "-WRP")) image[0].coords = mosaic;
    3029for (j = 0; (j < Nave) && !options.skip_missed; j++) {
    3130  n = N2[j];
  • trunk/Ohana/src/addstar/src/loadsupercos_plates.c

    r37472 r37807  
    118118
    119119    // for now, we define a fake coordinate system based on the boresite center
    120     strcpy (image[Nimage].coords.ctype, "DEC--TAN");
     120    InitCoords (&image[Nimage].coords, "DEC--TAN");
    121121   
    122122    image[Nimage].coords.crval1 = RAo;
     
    126126    image[Nimage].coords.crpix2 = 0.5*image[Nimage].NY;
    127127    image[Nimage].coords.cdelt1 = image[Nimage].coords.cdelt2 = scale;
    128 
    129     image[Nimage].coords.pc1_1 = 0.0;
    130     image[Nimage].coords.pc1_2 = 1.0;
    131     image[Nimage].coords.pc2_1 = 1.0;
    132     image[Nimage].coords.pc2_2 = 0.0;
    133 
    134     image[Nimage].coords.Npolyterms = 0;
    135     memset (image[Nimage].coords.polyterms, 0, 2*7*sizeof(float));
    136128
    137129    Nimage ++;
  • trunk/Ohana/src/addstar/src/loadwise.c

    r33963 r37807  
    4040  for (i = 1; i < argc; i++) {
    4141      fprintf (stderr, "loading %s\n", argv[i]);
    42       loadwise_rawdata (skylist, argv[i], options, ALLSKY);
     42      loadwise_rawdata (skylist, argv[i], options);
    4343  }
    4444  exit (0);
  • trunk/Ohana/src/addstar/src/loadwise_rawdata.c

    r34088 r37807  
    1010# define DEBUG 0
    1111
    12 int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options, int ALLSKY) {
     12int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options) {
    1313 
    1414  int i, j, verbose;
     
    159159        stars[Nstars+3][0].average.D = tstars[j].D;
    160160       
    161         if (ALLSKY) {
    162           loadwise_star_allsky (&stars[Nstars], &buffer[offset], Nbyte - offset);
    163         } else {
    164           loadwise_star_prelim (&stars[Nstars], &buffer[offset], Nbyte - offset);
     161        switch (MODE) {
     162          case MODE_PRELIM:
     163            loadwise_star_prelim (&stars[Nstars], &buffer[offset], Nbyte - offset);
     164            break;
     165          case MODE_ALLSKY:
     166            loadwise_star_allsky (&stars[Nstars], &buffer[offset], Nbyte - offset);
     167            break;
     168          case MODE_ALLWISE:
     169          default:
     170            // loadwise_star_allwise (&stars[Nstars], &buffer[offset], Nbyte - offset);
     171            break;
    165172        }
    166173
  • trunk/Ohana/src/addstar/src/mkcmf.c

    r37246 r37807  
    200200   
    201201  /* bore site center guess */
    202   strcpy (coords.ctype, "DEC--TAN");
     202  InitCoords (&coords, "DEC--TAN");
    203203  coords.crval1 = RA;
    204204  coords.crval2 = DEC;
     
    208208  coords.cdelt1 = 0.25/3600.0;
    209209  coords.cdelt2 = 0.25/3600.0;
    210 
    211   coords.pc1_1  = 1;
    212   coords.pc2_2  = 1;
    213   coords.pc1_2  = 0;
    214   coords.pc2_1  = 0;
    215   coords.Npolyterms = 1;
    216210
    217211  // load stars and generate complete output fields
     
    300294  gfits_modify (&header, "NASTRO",   "%d", 1, 100);
    301295
    302   if (imageID == -1) imageID = 1000.0*drand48();
    303   if (sourceID == -1) sourceID = 100.0*drand48();
     296  if (imageID == -1) imageID = 100000.0*drand48();
     297  if (sourceID == -1) sourceID = 1000.0*drand48();
    304298  gfits_modify (&header, "IMAGEID",  "%d", 1, imageID);
    305299  gfits_modify (&header, "SOURCEID", "%d", 1, sourceID);
  • trunk/Ohana/src/addstar/src/resort_catalog.c

    r37334 r37807  
    44void resort_catalog_measure (Catalog *catalog);
    55void resort_catalog_lensing (Catalog *catalog);
     6void resort_catalog_starpar (Catalog *catalog);
    67
    78void resort_catalog_old (Catalog *catalog) {
     
    3839  resort_catalog_measure (catalog);
    3940  resort_catalog_lensing (catalog);
     41  resort_catalog_starpar (catalog);
    4042}
    4143
     
    335337}
    336338
     339void resort_catalog_starpar (Catalog *catalog) {
     340
     341  off_t Naverage, Nstarpar;
     342  StarPar *starpar;
     343  Average *average;
     344  off_t i, j, N, currentAve;
     345
     346  off_t *starparSeq = NULL;
     347  off_t *averageSeq = NULL;
     348  StarPar *starparTMP = NULL;
     349
     350  // struct timeval start, stop;
     351  // gettimeofday (&start, NULL);
     352
     353  /* internal counters */
     354  Nstarpar = catalog[0].Nstarpar;
     355  Naverage = catalog[0].Naverage;
     356
     357  if (!Nstarpar) return;
     358
     359  starpar = catalog[0].starpar;
     360  average = catalog[0].average;
     361 
     362  // we have a table of average objects and an unsorted table of measurements.  each measurement
     363  // has a reference to the average object sequence (as well as an ID)
     364  // starpar[i].averef -> average[averef]
     365  // starpar[i].objID = average[averef].objID
     366  // starpar[i].catID = average[averef].catID
     367
     368  // we want a sorted starpar array with all averef entries in sequence
     369
     370  ALLOCATE (starparSeq, off_t,   Nstarpar);
     371  ALLOCATE (averageSeq, off_t,   Nstarpar);
     372
     373  for (i = 0; i < Nstarpar; i++) {
     374    starparSeq[i] = i;
     375    averageSeq[i] = starpar[i].averef;
     376   
     377    if (catalog[0].catformat >= DVO_FORMAT_PS1_V1) {
     378      // earlier formats did not carry the objID or catID, so they are not available (we could assign on load, but we don't)
     379      myAssert(average[averageSeq[i]].catID == starpar[starparSeq[i]].catID, "object / detection mismatch");
     380# if (1)
     381      myAssert(average[averageSeq[i]].objID == starpar[starparSeq[i]].objID, "object / detection mismatch");
     382# else
     383      // for reasons I do not understand, the mini dvodbs generated on stsci1X had a handful of detections with an inconsistency between averef and objID. 
     384      // this happened for 28 detections in the dbs on /data/stsci1?.0/eugene/dvo3pi.20130616, but not at all (as far as I know) in the rest of LAP DVO
     385      if (average[averageSeq[i]].objID != starpar[starparSeq[i]].objID) {
     386        fprintf (stderr, "R");
     387        starpar[starparSeq[i]].objID = average[averageSeq[i]].objID; // XXX I don't really like this...
     388      }
     389# endif
     390    }
     391  }
     392 
     393  // check that averageSeq is now in order
     394  // for (i = 1; i < Nstarpar; i++) {
     395  //   if (averageSeq[i] < averageSeq[i-1]) {
     396  //     fprintf (stderr, "%d ", (int) i);
     397  //   }
     398  // }
     399  // fprintf (stderr, "\n");
     400
     401  SortAveMatch(starparSeq, averageSeq, Nstarpar);
     402  // MARKTIME("sort : %f sec\n", dtime);
     403
     404  // check that averageSeq is now in order
     405  // for (i = 1; i < Nstarpar; i++) {
     406  //   if (averageSeq[i] < averageSeq[i-1]) {
     407  //     fprintf (stderr, "%d ", (int) i);
     408  //   }
     409  // }
     410  // fprintf (stderr, "\n");
     411
     412  // copy the starpar entries in the sorted order
     413  ALLOCATE (starparTMP, StarPar, Nstarpar);
     414  for (i = 0; i < Nstarpar; i++) {
     415    j = starparSeq[i];
     416    starparTMP[i] = starpar[j];
     417  }
     418  // MARKTIME("assign starpar : %f sec\n", dtime);
     419
     420  // update the values of average.starparOffset and average.Nstarpar
     421  FREE(starpar);
     422  catalog[0].starpar = starparTMP;
     423
     424  N = 0;
     425  currentAve = averageSeq[0];
     426  average[currentAve].starparOffset = 0;
     427  for (i = 0; i < Nstarpar; i++) {
     428    if (averageSeq[i] != currentAve) {
     429      // we have hit the next entry in the list
     430      average[currentAve].Nstarpar = N;
     431      N = 0;
     432      currentAve = averageSeq[i];
     433      average[currentAve].starparOffset = i;
     434    }
     435    N++;
     436  }
     437  // N++;
     438  average[currentAve].Nstarpar = N;
     439  // MARKTIME("update Nstarpar : %f sec\n", dtime);
     440
     441  int NstarparTotal = 0;
     442  int starparOffsetOK = TRUE;
     443  for (i = 0; i < Naverage; i++) {
     444    NstarparTotal += catalog[0].average[i].Nstarpar;
     445    if (VERBOSE && !(NstarparTotal <= catalog[0].Nstarpar)) {
     446      fprintf (stderr, "too few starpar: %d %d %d\n", (int) i, NstarparTotal, (int) catalog[0].Nstarpar);
     447    }
     448    starparOffsetOK &= (catalog[0].average[i].starparOffset < catalog[0].Nstarpar);
     449    if (VERBOSE && !(catalog[0].average[i].starparOffset < catalog[0].Nstarpar)) {
     450      fprintf (stderr, "offset too large: %d %d %d\n", (int) i, catalog[0].average[i].Nstarpar, (int) catalog[0].Nstarpar);
     451    }
     452    starparOffsetOK &= (catalog[0].average[i].starparOffset + catalog[0].average[i].Nstarpar <= catalog[0].Nstarpar);
     453    if (VERBOSE && !(catalog[0].average[i].starparOffset + catalog[0].average[i].Nstarpar <= catalog[0].Nstarpar)) {
     454      fprintf (stderr, "orrset + Nstarpar too large: %d + %d > %d %d\n", (int) i, catalog[0].average[i].starparOffset, catalog[0].average[i].Nstarpar, (int) catalog[0].Nstarpar);
     455    }
     456  }
     457
     458  if (!starparOffsetOK) {
     459    fprintf (stderr, "ERROR: catalog %s has an invalid starparOffset\n", catalog[0].filename);
     460  }
     461
     462  if (NstarparTotal != catalog[0].Nstarpar) {
     463    fprintf (stderr, "ERROR: catalog %s has an invalid Nstarpar\n", catalog[0].filename);
     464  }
     465
     466  // MARKTIME("  match time %9.4f sec for %7lld starpars, %6lld average\n", dtime, (long long) Nstarpar, (long long) Naverage);
     467
     468  catalog[0].sorted = TRUE;
     469
     470  FREE (starparSeq);
     471  FREE (averageSeq);
     472
     473  return;
     474}
     475
    337476// sort the measure or lensing Sequence based on the average Sequence entries
    338477void SortAveMatch (off_t *MEAS, off_t *AVE, off_t N) {
  • trunk/Ohana/src/addstar/src/sky_tessalation.c

    r36485 r37807  
    581581
    582582  memset (rectangle, 0, sizeof(SkyRectangle));
     583
     584  InitCoords (&rectangle[0].coords, "DEC--TAN");
     585
    583586  rectangle[0].coords.crval1 = CENTER_RA;
    584587  rectangle[0].coords.crval2 = CENTER_DEC;
     
    609612  rectangle[0].coords.cdelt2 = SCALE / 3600.0;
    610613
    611   strcpy (rectangle[0].coords.ctype, "DEC--TAN");
    612 
    613614  rectangle[0].NX = NX;
    614615  rectangle[0].NY = NY;
     
    699700  for (i = 0; i < nRA; i++) {
    700701    memset (&ring[i], 0, sizeof(SkyRectangle));
    701     memset (&ring[i].coords, 0, sizeof(Coords));
     702
     703    InitCoords (&ring[i].coords, "DEC--TAN");
    702704    ring[i].coords.crval1 = i*dRA;
    703705    ring[i].coords.crval2 = dec;
    704706
    705707    ring[i].coords.pc1_1 = +1.0 * X_PARITY;
    706     ring[i].coords.pc1_2 = +0.0;
    707     ring[i].coords.pc2_1 = -0.0;
    708     ring[i].coords.pc2_2 = +1.0;
    709708 
    710709    // range values are in projected degrees
     
    718717    ring[i].coords.cdelt1 = SCALE / 3600.0;
    719718    ring[i].coords.cdelt2 = SCALE / 3600.0;
    720 
    721     strcpy (ring[i].coords.ctype, "DEC--TAN");
    722719
    723720    ring[i].NX = NX*(1.0 + PADDING);
     
    771768
    772769      memset (&ring[N], 0, sizeof(SkyRectangle));
    773       memset (&ring[N].coords, 0, sizeof(Coords));
     770      InitCoords (&ring[N].coords, "DEC--TAN");
    774771
    775772      ring[N].coords.crval1 = ra / d2r;
     
    779776
    780777      ring[N].coords.pc1_1 = +1.0 * X_PARITY;
    781       ring[N].coords.pc1_2 = +0.0;
    782       ring[N].coords.pc2_1 = -0.0;
    783       ring[N].coords.pc2_2 = +1.0;
    784778 
    785779      // range values are in projected degrees
     
    793787      ring[N].coords.cdelt1 = SCALE / 3600.0;
    794788      ring[N].coords.cdelt2 = SCALE / 3600.0;
    795 
    796       strcpy (ring[N].coords.ctype, "DEC--TAN");
    797789
    798790      ring[N].NX = NX*(1.0 + PADDING);
     
    10991091
    11001092  ALLOCATE (refcoords, Coords, 1);
    1101   refcoords[0].crval1 = refcoords[0].crval2 = 0.0;
    1102   refcoords[0].crpix1 = refcoords[0].crpix2 = 0.0;
     1093  InitCoords (refcoords, "DEC--TAN");
    11031094  refcoords[0].cdelt1 = refcoords[0].cdelt2 = scale / 3600;
    1104   refcoords[0].pc1_1 = refcoords[0].pc2_2 = 1.0;
    1105   refcoords[0].pc1_2 = refcoords[0].pc2_1 = 0.0;
    1106   refcoords[0].Npolyterms = 0;
    1107   memset (refcoords[0].polyterms, 0, 14*sizeof(float));
    1108   strcpy (refcoords[0].ctype, "DEC--TAN");
    11091095  return (TRUE);
    11101096}
  • trunk/Ohana/src/addstar/test/relphot.parallel.dvo

    r33653 r37807  
    2525  if (not($?VERBOSE)) set VERBOSE = 0
    2626
    27   # images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
    28   $zpt_nominal:g = 24.58
    29   $zpt_nominal:r = 24.80
    30   $zpt_nominal:i = 24.74
    31   $zpt_nominal:z = 24.26
    32   $zpt_nominal:y = 23.41
    33 
    34   # klam is negative, so klam*(airmass - 1) increase the zero point
    35   $klam_nominal:g = -0.15
    36   $klam_nominal:r = -0.10
    37   $klam_nominal:i = -0.04
    38   $klam_nominal:z = -0.03
    39   $klam_nominal:y = -0.03
     27# images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
     28# $zpt_nominal:g = 24.58
     29# $zpt_nominal:r = 24.80
     30# $zpt_nominal:i = 24.74
     31# $zpt_nominal:z = 24.26
     32# $zpt_nominal:y = 23.41
     33
     34# klam is negative, so klam*(airmass - 1) increase the zero point
     35# $klam_nominal:g = -0.15
     36# $klam_nominal:r = -0.10
     37# $klam_nominal:i = -0.04
     38# $klam_nominal:z = -0.03
     39# $klam_nominal:y = -0.03
     40
     41  $zpt_nominal:g = 24.563; $klam_nominal:g = -0.147
     42  $zpt_nominal:r = 24.750; $klam_nominal:r = -0.085
     43  $zpt_nominal:i = 24.611; $klam_nominal:i = -0.044
     44  $zpt_nominal:z = 24.250; $klam_nominal:z = -0.033
     45  $zpt_nominal:y = 23.320; $klam_nominal:y = -0.073
    4046
    4147  # we have two sets of images: ubercaled and not-ubercaled
     
    111117  mksequence $fileroot $catdir
    112118  for i 0 mjd_nc[]
    113     ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw
     119    ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw 0
    114120  end
    115121
     
    121127
    122128  # run relphot on the serial db and check that the images now match the expected values
    123   exec relphot g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& log.relphot.s0
     129  exec relphot -images g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update >& log.relphot.s0
    124130
    125131  for i 0 mjd_nc[]
     
    128134    # matching the mean zp of photometric data, which we calculate in
    129135    # 'init'
    130     ckexposure $catdir mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     136    ckexposure $catdir mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc 0
    131137  end
    132138
    133139  # run relphot on the parallel db and check that the images now match the expected values
    134   exec relphot -parallel g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir.p0 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& log.relphot.p0
    135 
    136   exec dvodist -in $catdir.p0 >& log.dvodist.in
     140  exec relphot -images -parallel g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir.p0 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update >& log.relphot.p0
    137141
    138142  for i 0 mjd_nc[]
     
    141145    # matching the mean zp of photometric data, which we calculate in
    142146    # 'init'
    143     ckexposure $catdir.p0 mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
     147    ckexposure $catdir.p0 mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc 1
    144148  end
    145149
     
    148152
    149153macro ckexposure
    150   if ($0 != 8)
    151     echo "ckexposure (catdir) (mjd) (zpt) (exptime) (airmass) (filter) (mode)"
     154  if ($0 != 9)
     155    echo "ckexposure (catdir) (mjd) (zpt) (exptime) (airmass) (filter) (mode) (isParallel)"
    152156    echo "  mode == raw or corr"
    153157    break
     
    163167  $FILTER      = $6
    164168  $MODE        = $7
     169  $PARALLEL    =
     170  if ($8)
     171    $PARALLEL = "-parallel"
     172  end
    165173
    166174  # XXX need a function to extract the nominal zpt for a given filter / photcode from the db
     
    182190
    183191  skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2}
    184   mextract ra dec mag xccd yccd where (abs(time - $MJD_IMAGE) < 0.0001)
     192  mextract $PARALLEL ra dec mag xccd yccd where (abs(time - $MJD_IMAGE) < 0.0001)
    185193  if (not(ra[]))
    186194    echo "no matching data for MJD = $MJD_IMAGE"
     
    344352    # the fake images have inconsistent ra,dec and airmass,sidtime values
    345353    if ($VERBOSE) echo addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass
    346     exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass >& /dev/null
     354    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass >& log.addstar
    347355    # costs 10/36 sec / chip
    348356  end
     
    432440  $catdir = $tmp1/$tmp2
    433441
     442  if ($VERBOSE) echo rsync -auv $catdir/ $catdir.p0/
    434443  exec rsync -auv $catdir/ $catdir.p0/ >& log.rsync
    435444  mkdir $catdir.d1
     
    442451  exec echo "3 $hostname $catdir.d3" >> $catdir.p0/HostTable.dat
    443452
     453  if ($VERBOSE) echo dvodist -out $catdir.p0
    444454  exec dvodist -out $catdir.p0 >& log.dvodist.out
    445455end
  • trunk/Ohana/src/checkastro/src/ImageOps.c

    r36833 r37807  
    130130  }
    131131
    132   BuildChipMatch (image, Nimage);
    133 
    134132  char output[128];
    135133  snprintf (output, 128, "checkastrom.%+3.0f.%+3.0f.%03.0f.%03.0f.dat", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
     
    148146    name = GetPhotcodeNamebyCode (image[i].photcode);
    149147
    150     off_t myMosaic = FindMosaicForImage (image, Nimage, i);
    151 
    152148    /* only check exposure center */
    153149    double Rexp = NAN, Dexp = NAN, Rccd = NAN, Dccd = NAN;
    154150
    155     if (myMosaic) {
    156       myMosaic --;
    157       XY_to_RD (&Rccd, &Dccd, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    158       XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &image[myMosaic].coords);
    159     }
     151    XY_to_RD (&Rccd, &Dccd, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
     152    XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &image[i].parent->coords);
    160153
    161154    char *date = ohana_sec_to_date(image[i].tzero);
  • trunk/Ohana/src/checkastro/src/bcatalog.c

    r36833 r37807  
    191191  /* project coordinates to a plane centered on the object with units of arcsec */
    192192  Coords coords;
     193  InitCoords (&coords, "DEC--SIN");
    193194  coords.crval1 = Rc;
    194195  coords.crval2 = Dc;
    195   coords.crpix1 = 0;
    196   coords.crpix2 = 0;
    197196  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    198   coords.pc1_1  = coords.pc2_2 = 1.0;
    199   coords.pc1_2  = coords.pc2_1 = 0.0;
    200   coords.Npolyterms = 1;
    201   strcpy (coords.ctype, "DEC--SIN");
    202197
    203198  // convert all average R,D values to X,Y:
  • trunk/Ohana/src/checkastro/src/load_images.c

    r36833 r37807  
    1717  MARKTIME("  convert image table: %f sec\n", dtime);
    1818
     19  BuildChipMatch (image, Nimage);
     20
    1921  // select the images which overlap the selected sky regions
    2022  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
  • trunk/Ohana/src/checkastro/src/select_images.c

    r36833 r37807  
    4343
    4444  if (VERBOSE) fprintf (stderr, "finding images\n");
    45   BuildChipMatch (timage, Ntimage);
    46   MARKTIME("build chip match: %f sec\n", dtime);
    4745
    4846  nimage = 0;
     
    8381    }
    8482   
    85     // this adds 1.3 sec for 3M images
    86     off_t myMosaic = FindMosaicForImage (timage, Ntimage, i);
    87     if (!myMosaic) {
    88       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    89       continue;
    90     }
    91     myMosaic --;
    92 
    9383    /* only check exposure center */
    9484    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
    9585      XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &timage[i].coords);
    9686    } else {
    97       XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &timage[myMosaic].coords);
     87      XY_to_RD (&Rexp, &Dexp, 0.0, 0.0, &timage[i].parent->coords);
    9888    }
    9989    Rexp = ohana_normalize_angle_to_midpoint (Rexp, RmidSkyRegion);
  • trunk/Ohana/src/delstar/src/ImageOpsFixLAP.c

    r37040 r37807  
    320320    if ((Nimage_valid[i] + Nimage_invalid[i] == 0) || (found_ratio < 0.995)) {
    321321      double r, d;
    322       if (!FindMosaicForImage (image, Nimage, i)) {
    323         fprintf (stderr, "failed to get astrometry for %s\n", image[i].name);
     322      if (!strcmp(&image[i].coords.ctype[4], "-DIS")) {
     323        XY_to_RD (&r, &d, 0.0, 0.0, &image[i].coords);
    324324      } else {
    325         if (!strcmp(&image[i].coords.ctype[4], "-DIS")) {
    326           XY_to_RD (&r, &d, 0.0, 0.0, &image[i].coords);
    327         } else {
    328           XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    329         }
     325        XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    330326      }
    331327      char *date = ohana_sec_to_date (image[i].tzero);
  • trunk/Ohana/src/delstar/src/delete_duplicate_measures.c

    r35758 r37807  
    6161    }
    6262
    63     delete_duplicate_measures_catalog (&catalog);
    64 
    65     if (UPDATE) {
    66       // XXX skip if nothing was deleted
    67       dvo_catalog_save_complete (&catalog, VERBOSE2);
     63    if (delete_duplicate_measures_catalog (&catalog)) {
     64      // skip if nothing was deleted
     65      if (UPDATE) {
     66        if (!dvo_catalog_backup (&catalog, TRUE)) {
     67          fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", catalog.filename);
     68          exit (1);
     69        }
     70        dvo_catalog_save_complete (&catalog, VERBOSE2);
     71      }
    6872    }
    6973
     
    234238    measureDrop[j] = TRUE;
    235239    off_t N = measure[j].averef;
    236     fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
     240    if (VERBOSE) fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[j].imageID, measure[j].detID, average[N].R, average[N].D, measure[j].photcode);
    237241  }
    238242
     
    385389  off_t NdelAves = Naverage - catalog[0].Naverage;
    386390  off_t NdelMeas = Nmeasure - catalog[0].Nmeasure;
     391
    387392  if (NdelAves || NdelMeas) {
    388393    fprintf (stderr, "deleting "OFF_T_FMT" measures and "OFF_T_FMT" averages : %s\n",  NdelMeas, NdelAves, catalog[0].filename);
     
    404409  FREE (measureAveOut);
    405410
    406   return TRUE;
     411  if (NdelAves || NdelMeas) return TRUE;
     412  return FALSE;
    407413}
    408414
  • trunk/Ohana/src/delstar/src/delete_imagename.c

    r34749 r37807  
    2424  }
    2525
     26  BuildChipMatch (image, Nimage);
     27
    2628  /* find image in db by name */
    2729  imlist = find_images_name (db, IMAGENAME, &Nimlist);
     
    3335    if (VERBOSE) fprintf (stderr, "deleting %s\n", image[j].name);
    3436   
    35     // XXX EAM : need to handle failure
    36     FindMosaicForImage (image, Nimage, j);
    3737    skylist = SkyListByImage (sky, -1, &image[j]);
    3838
  • trunk/Ohana/src/delstar/src/delete_times.c

    r29001 r37807  
    3131  }
    3232
     33  BuildChipMatch (image, Nimage);
     34
    3335  /* find images for time range, delete each image */
    3436  imlist = find_images_time (db, START, END, PHOTCODE, &Nimlist);
     
    3941    if (VERBOSE) fprintf (stderr, "finding regions for %s\n", image[j].name);
    4042
    41     // XXX EAM : need to handle failure
    42     FindMosaicForImage (image, Nimage, j);
    4343    skyset = SkyListByImage (sky, -1, &image[j]);
    4444
  • trunk/Ohana/src/dvomerge/Makefile

    r35416 r37807  
    2323dvoverify_client : $(BIN)/dvoverify_client.$(ARCH)
    2424
    25 all: dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvoverify dvoverify_client
     25dvoutils        : $(BIN)/dvoutils.$(ARCH)
     26
     27all: dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client dvoutils
    2628
    2729#  $(SRC)/dvomergeContinue.$(ARCH).o
     
    120122$(SRC)/dvorepairImagesVsMeasures.$(ARCH).o \
    121123$(SRC)/dvorepairDeleteImageList.$(ARCH).o \
     124$(SRC)/dvorepairDeleteImagesByExternID.$(ARCH).o \
     125$(SRC)/dvorepairDeleteImagesByExternID.$(ARCH).o \
    122126$(SRC)/dvorepairFixImages.$(ARCH).o \
    123127$(SRC)/psps_ids.$(ARCH).o \
    124128$(SRC)/LoadImages.$(ARCH).o \
    125129$(SRC)/ReadDeleteList.$(ARCH).o \
     130$(SRC)/ReadDeleteListExternID.$(ARCH).o \
     131$(SRC)/myIndex.$(ARCH).o \
    126132$(SRC)/match_image.$(ARCH).o \
    127133$(SRC)/help.$(ARCH).o \
     
    149155$(BIN)/dvoverify_client.$(ARCH) : $(DVOVERIFY_CLIENT)
    150156
    151 INSTALL = dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client
     157DVOUTILS = \
     158$(SRC)/dvoutils.$(ARCH).o \
     159$(SRC)/dvoutils_args.$(ARCH).o \
     160$(SRC)/dvoutils_uniq_images.$(ARCH).o \
     161$(SRC)/dvoutils_load_image_index.$(ARCH).o
     162
     163$(DVOUTILS)  : $(INC)/dvoutils.h
     164$(BIN)/dvoutils.$(ARCH) : $(DVOUTILS)
     165
     166INSTALL = dvomerge dvomerge_client dvoconvert dvosecfilt dvosecfilt_client dvorepair dvoverify dvoverify_client dvoverify
    152167
    153168# dependancy rules for binary code #########################
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r37116 r37807  
    4141int    REPLACE_BY_PHOTCODE;
    4242int    FORCE_MERGE;
     43char  *UPDATE_CATFORMAT;
     44
     45int    MATCHED_TABLES;
    4346
    4447char *SINGLE_CPT;
    4548SkyRegion UserPatch;  // used by MODE CAT
     49
     50# ifndef MAX_INT
     51# define MAX_INT 2147483647
     52# endif
     53
     54typedef struct {
     55  int minID;
     56  int maxID;
     57  int *index;
     58  int Nindex;
     59  int NINDEX;
     60} myIndexType;
    4661
    4762typedef struct {
     
    138153int        add_lens_link          PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
    139154Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next));
     155
     156off_t     *build_starpar_links    PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
     157off_t     *init_starpar_links     PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
     158int        add_star_link          PROTO((Average *average, off_t *next, off_t Nstarpar, off_t NSTARPAR));
     159StarPar   *sort_starpar           PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next));
    140160
    141161off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
     
    200220int dvoCreateID (char *catdir);
    201221
     222myIndexType *myIndexInit ();
     223int myIndexFree (myIndexType *myIndex);
     224int myIndexUpdateLimits (myIndexType *myIndex, int value);
     225int myIndexSetRange (myIndexType *myIndex);
     226int myIndexSetEntry (myIndexType *myIndex, int value, int entry);
     227int myIndexGetEntry (myIndexType *myIndex, int value);
     228
     229int dvorepairDeleteImagesByExternID (int argc, char **argv);
     230int RepairTableCPT_V1(char *cptFilenameSrc, char *cptFilenameTgt, char *cpsFilenameSrc, char *cpsFilenameTgt, Measure *measure, off_t Nmeasure, Image *image, off_t Nimage, myIndexType *imageIDindex, char catformat);
     231int *ReadDeleteListExternID(char *filename, int *nindex);
  • trunk/Ohana/src/dvomerge/src/ImageOps.c

    r29938 r37807  
    1818  }
    1919  if (m == -1) return (NULL);
    20   if (!FindMosaicForImage (image, Nimage, m)) return (NULL);
    2120  return (&image[m]);
    2221}
  • trunk/Ohana/src/dvomerge/src/LoadCatalog.c

    r37116 r37807  
    88
    99    // always load all of the data (if any exists)
    10     catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING | LOAD_LENSOBJ;
     10    catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING | LOAD_LENSOBJ | LOAD_STARPAR;
    1111
    1212    catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  • trunk/Ohana/src/dvomerge/src/args.c

    r35765 r37807  
    3737  }
    3838
     39  /* extra error messages */
     40  MATCHED_TABLES = FALSE;
     41  if ((N = get_argument (*argc, argv, "-matched-tables"))) {
     42    MATCHED_TABLES = TRUE;
     43    remove_argument (N, argc, argv);
     44  }
     45
    3946  /* use a different photcode file to define mean values */
    4047  if ((N = get_argument (*argc, argv, "-photcode-file"))) {
     
    4855  if ((N = get_argument (*argc, argv, "-force-merge"))) {
    4956    FORCE_MERGE = TRUE;
     57    remove_argument (N, argc, argv);
     58  }
     59
     60  UPDATE_CATFORMAT = NULL;
     61  if ((N = get_argument (*argc, argv, "-update-catformat"))) {
     62    remove_argument (N, argc, argv);
     63    UPDATE_CATFORMAT = strcreate (argv[N]);
    5064    remove_argument (N, argc, argv);
    5165  }
     
    185199  }
    186200
     201  /* extra error messages */
     202  MATCHED_TABLES = FALSE;
     203  if ((N = get_argument (*argc, argv, "-matched-tables"))) {
     204    MATCHED_TABLES = TRUE;
     205    remove_argument (N, argc, argv);
     206  }
     207
    187208  /* replace measurement, don't duplicate */
    188209  REPLACE_BY_PHOTCODE = FALSE;
  • trunk/Ohana/src/dvomerge/src/build_links.c

    r37762 r37807  
    382382}
    383383
    384 
     384/********  StarPar ********************************************************************************/
     385
     386/* build the initial links assuming the table is sorted,
     387   not partial, and has a correct set of average[].starparOffset,Nstarpar values */
     388off_t *init_starpar_links (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar) {
     389
     390  off_t i, j, N;
     391  off_t *next_star;
     392
     393  N = 0;
     394
     395  ALLOCATE (next_star, off_t, Nstarpar);
     396  for (i = 0; i < Naverage; i++) {
     397    if (!average[i].Nstarpar) continue;
     398    for (j = 0; j < average[i].Nstarpar - 1; j++, N++) {
     399      next_star[N] = N + 1;
     400      if (N >= Nstarpar) {
     401        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     402      }
     403    }
     404    next_star[N] = -1;
     405    if (N >= Nstarpar) {
     406      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     407    }
     408
     409    if (N >= Nstarpar) {
     410      fprintf (stderr, "overflow in init_starpar_links\n");
     411      abort ();
     412    }
     413    N++;
     414  }
     415  return (next_star);
     416}
     417
     418/* construct starpar links which are valid FOR THIS LOAD
     419 * - if we have a full load, we will get links which can
     420 *   be used by other programs (eg, relphot, etc)
     421 * - if we have a partial load, the links are only valid
     422 *   for that partial load
     423 */
     424
     425off_t *build_starpar_links (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar) {
     426
     427  off_t i, m, k, Nm, averef;
     428  off_t *next_star;
     429
     430  ALLOCATE (next_star, off_t, Nstarpar);
     431
     432  /* reset the Nm, offset values for average */
     433  for (i = 0; i < Naverage; i++) {
     434    average[i].starparOffset = -1;
     435    average[i].Nstarpar     =  0;
     436  }
     437
     438  for (Nm = 0; Nm < Nstarpar; Nm++) {
     439    averef = starpar[Nm].averef;
     440    m = average[averef].starparOffset; 
     441    next_star[Nm] = -1;
     442
     443    if (m == -1) { /* no links yet for source */
     444      average[averef].starparOffset = Nm;
     445      average[averef].Nstarpar     = 1;
     446      continue;
     447    }
     448
     449    for (k = 0; next_star[m] != -1; k++) {
     450      m = next_star[m];
     451      if (m >= Nstarpar) {
     452        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     453      }
     454    }
     455
     456    average[averef].Nstarpar = k + 2;
     457    next_star[m] = Nm;
     458    if (m >= Nstarpar) {
     459      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     460    }
     461  }
     462  return (next_star);
     463}
     464
     465/* average[].starparOffset, average[].Nstarpar are valid within an addstar run */
     466int add_star_link (Average *average, off_t *next_star, off_t Nstarpar, off_t NSTARPAR) {
     467
     468  off_t k, m;
     469
     470  /* if we have trouble, check validity of next_star[m] : m < Nstarpar */
     471  m = average[0].starparOffset; 
     472
     473  for (k = 0; k < average[0].Nstarpar - 1; k++)  {
     474    m = next_star[m];
     475    if (m >= NSTARPAR) {
     476      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     477    }
     478  }
     479
     480  /* set up references */
     481  next_star[Nstarpar] = -1;
     482  if (Nstarpar >= NSTARPAR) {
     483    fprintf (stderr, "WARNING: Nstarpar out of bounds (1)\n");
     484  }
     485
     486  if (m == -1) {
     487    average[0].starparOffset = Nstarpar;
     488  } else {
     489    next_star[m] = Nstarpar;
     490    if (m >= NSTARPAR) {
     491      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     492    }
     493  }
     494
     495  return (TRUE);
     496}
     497
     498StarPar *sort_starpar (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next_star) {
     499
     500  off_t i, k, n, np, N;
     501  StarPar *tmpstarpar;
     502
     503  /*
     504  for (i = 0; i < Naverage; i++) {
     505    if (average[i].Nstarpar != 4) {
     506      fprintf (stderr, "check %d %d %d\n", (int) i, (int) average[i].Nstarpar, (int) average[i].starparOffset);
     507    }
     508  }
     509  */
     510
     511  /* fix order of StarPar (memory intensive, but fast) */
     512  N = 0;
     513  ALLOCATE (tmpstarpar, StarPar, Nstarpar);
     514  for (i = 0; i < Naverage; i++) {
     515    if (!average[i].Nstarpar) continue;
     516    n = average[i].starparOffset;
     517    average[i].starparOffset = N;
     518    for (k = 0; k < average[i].Nstarpar; k++, N++) {
     519      if (n == -1) {
     520        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     521        abort();
     522      }
     523      tmpstarpar[N] = starpar[n];
     524      if (starpar[n].averef != i) abort();
     525      tmpstarpar[N].averef = i;
     526      np = n;
     527      n = next_star[n];
     528    }
     529  }
     530  free (starpar);
     531  return (tmpstarpar);
     532}
     533
     534
  • trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r37360 r37807  
    113113  create_IDmap_lookup (IDmap);
    114114
    115   if (!out[0].swapped) {
    116     gfits_convert_Image ((Image *) out[0].ftable.buffer, sizeof(Image), Nout);
    117     out[0].swapped = TRUE;
    118   }
    119 
    120115  Nout += Nimages;
    121116  IDstart += Nimages;
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r37116 r37807  
    5858    }
    5959
     60# ifdef OLD_CODE
     61    // NOTE: i was having trouble dropping objects on edges with the option below.  Since an object can move outside the catalog grab the neighbors.
    6062    // SkyListByBounds will return neighbor catalogs if the boundaries exactly match (due to rounding).  Since the regions are not infinitely small,
    6163    // compare to a slightly reduced footprint
    6264    float dPos = 2.0/3600.0;
    6365    outlist = SkyListByBounds (outsky, -1, inlist[0].regions[i][0].Rmin + dPos, inlist[0].regions[i][0].Rmax - dPos, inlist[0].regions[i][0].Dmin + dPos, inlist[0].regions[i][0].Dmax - dPos);
     66# endif
     67
     68    if (MATCHED_TABLES) {
     69      // if we know the output will have the same depth / layout as the input, just choose the matched table
     70      outlist = SkyRegionByIndex (outsky, inlist[0].regions[i][0].index);
     71    } else {
     72      // Since an object can move outside the catalog grab the neighbors.
     73      float dPos = 2.0/3600.0;
     74      outlist = SkyListByBounds (outsky, -1, inlist[0].regions[i][0].Rmin - dPos, inlist[0].regions[i][0].Rmax + dPos, inlist[0].regions[i][0].Dmin - dPos, inlist[0].regions[i][0].Dmax + dPos);
     75    }
    6476
    6577    OutputStatus *outstat = OutputStatusInit (outlist->Nregions);
     
    163175      LoadCatalog (&outcatalog, outlist[0].regions[j], outcatalog.filename, "w", NsecfiltOutput);
    164176
    165       // if no catalog already exists, use the input catalog to define the format
     177      // if no catalog already exists, use the input catalog to define the format or the specified format
    166178      if (outcatalog.Naves_disk == 0) {
    167         outcatalog.catformat = incatalog.catformat;
     179        if (UPDATE_CATFORMAT) {
     180          outcatalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT);
     181        } else {
     182          outcatalog.catformat = incatalog.catformat;
     183        }
    168184      }
    169185
     
    187203      SetProtect (FALSE);
    188204
     205      if (!dvo_catalog_unlock (&outcatalog)) {
     206        fprintf (stderr, "ERROR: failed to unlock catalog %s\n", outlist[0].filename[j]);
     207        exit (1);
     208      }
     209
    189210      if (!dvo_catalog_unlink_backup (&outcatalog, TRUE)) {
    190211        fprintf (stderr, "WARNING: failed to remove backup for catalog %s\n", outlist[0].filename[j]);
    191212      }
    192213
    193       dvo_catalog_unlock (&outcatalog);
    194214      dvo_catalog_free (&outcatalog);
    195215
     
    256276    if (PARALLEL_INPUT)      { snprintf (tmpline, DVO_MAX_PATH, "%s -parallel-input",  command); strcpy (command, tmpline); }
    257277    if (FORCE_MERGE)         { snprintf (tmpline, DVO_MAX_PATH, "%s -force-merge",     command); strcpy (command, tmpline); }
     278    if (MATCHED_TABLES)      { snprintf (tmpline, DVO_MAX_PATH, "%s -matched-tables",  command); strcpy (command, tmpline); }
    258279
    259280    // add some config variables:
  • trunk/Ohana/src/dvomerge/src/dvorepair.c

    r37046 r37807  
    33int main (int argc, char **argv) {
    44
    5   fprintf (stderr, "this program needs to be updated to load old format Measure tables (pre PV1_V5) in which dR,dD are saved, not R,D\n");
    6   fprintf (stderr, "reminder: relastro can re-construct R,D from X,Y; FtableToMeasure and vice versa could just NAN those values\n");
    7   exit (2);
     5  // fprintf (stderr, "this program needs to be updated to load old format Measure tables (pre PV1_V5) in which dR,dD are saved, not R,D\n");
     6  // fprintf (stderr, "reminder: relastro can re-construct R,D from X,Y; FtableToMeasure and vice versa could just NAN those values\n");
     7  // exit (2);
    88
    99  dvorepair_help(argc, argv);
     
    1313  if (!strcmp(argv[1], "-images-vs-measures")) dvorepairImagesVsMeasures(argc, argv);
    1414  if (!strcmp(argv[1], "-delete-image-list")) dvorepairDeleteImageList(argc, argv);
     15  if (!strcmp(argv[1], "-delete-images-by-extern-id")) dvorepairDeleteImagesByExternID(argc, argv);
    1516  if (!strcmp(argv[1], "-fix-images")) dvorepairFixImages(argc, argv);
    1617  dvorepair_help(0, NULL);
  • trunk/Ohana/src/dvomerge/src/dvorepairCPT.c

    r37046 r37807  
    119119    thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID);
    120120    XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords);
     121    average[Nave].R = ohana_normalize_angle (average[Nave].R);
    121122
    122123    average[Nave].Nmeasure = 1;
  • trunk/Ohana/src/dvomerge/src/dvorepairDeleteImageList.c

    r37046 r37807  
    114114    index = deleteIDs[i];
    115115    seq = imageIdx[index];
    116     if (!FindMosaicForImage (image, Nimage, seq)) {
    117       fprintf (stderr, "cannot find mosaic for %s, skipping\n", image[seq].name);
    118       continue;
    119     }
    120116
    121117    XY_to_RD(&Rthis, &Dthis, 0, 0, &image[seq].coords);
     
    404400    thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID);
    405401    XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords);
     402    average[Nave].R = ohana_normalize_angle (average[Nave].R);
    406403
    407404    average[Nave].Nmeasure = 1;
  • trunk/Ohana/src/dvomerge/src/dvorepairFixImages.c

    r29938 r37807  
    130130int MarkMosaicsToDelete(Image *image, off_t Nimage, int *deleteIndex) {
    131131
     132  myAbort ("this function needs to be redone with a concept to match the old BuildChipMatch");
     133
     134# if (0) 
     135
    132136  off_t i;
    133137 
     
    140144     marked.  Now find all WRP images for which none/some/all images are to be deleted.
    141145  */
     146
     147 
    142148
    143149  // make a copy of the ChipMatch table (generated by BuildChipMatch, see libdvo/src/mosaic_astrom.c)
     
    237243  free (ChipByMosaicID);
    238244
     245# endif
     246
    239247  return TRUE;
    240248}
  • trunk/Ohana/src/dvomerge/src/dvorepairFixTables.c

    r37046 r37807  
    259259    thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID);
    260260    XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords);
     261    average[Nave].R = ohana_normalize_angle (average[Nave].R);
    261262
    262263    average[Nave].Nmeasure = 1;
  • trunk/Ohana/src/dvomerge/src/dvoverify_utils.c

    r37360 r37807  
    238238    }
    239239    // lensingOffset needs to be in range for each object
    240     lensingOffsetOK &= (catalog.average[i].lensingOffset < catalog.Nlensing);
    241     if (VERBOSE && !(catalog.average[i].lensingOffset < catalog.Nlensing)) {
     240    lensingOffsetOK &= (!catalog.Nlensing || (catalog.average[i].lensingOffset < catalog.Nlensing));
     241    if (VERBOSE && catalog.Nlensing && !(catalog.average[i].lensingOffset < catalog.Nlensing)) {
    242242      fprintf (stderr, "lensingOffset >= catalog.Nlensing: %d %d %d\n", i, catalog.average[i].lensingOffset, (int) catalog.Nlensing);
    243243    }
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_new.c

    r37472 r37807  
    1111 
    1212  off_t i, j, offset;
    13   off_t NAVERAGE, NMEASURE, NLENSING, Naverage, Nmeasure, Nlensing, NsecfiltIn, NsecfiltOut, Nm;
     13  off_t NAVERAGE, NMEASURE, NLENSING, NSTARPAR, Naverage, Nmeasure, Nlensing, Nstarpar, NsecfiltIn, NsecfiltOut, Nm;
    1414
    1515  Naverage = output[0].Naverage;
     
    8181      output[0].average[Naverage].Nlensing = Nm;
    8282
     83      Nm = 0;
     84      for (j = 0; j < input[0].average[i].Nstarpar; j++) {
     85          offset = input[0].average[i].starparOffset + j;
     86
     87          output[0].starpar[Nstarpar] = input[0].starpar[offset];
     88          output[0].starpar[Nstarpar].averef = Naverage;
     89
     90          Nstarpar ++;
     91          Nm ++;
     92          if (Nstarpar == NSTARPAR) {
     93              NSTARPAR += 1000;
     94              REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     95          }
     96      }
     97      output[0].average[Naverage].Nstarpar = Nm;
     98
    8399      Naverage ++;
    84100      if (Naverage == NAVERAGE) {
     
    91107  REALLOCATE (output[0].measure, Measure, MAX (Nmeasure, 1));
    92108  REALLOCATE (output[0].lensing, Lensing, MAX (Nlensing, 1));
     109  REALLOCATE (output[0].starpar, StarPar, MAX (Nstarpar, 1));
    93110  REALLOCATE (output[0].secfilt, SecFilt, NsecfiltOut*MAX (Naverage, 1));
    94111  output[0].Naverage = Naverage;
    95112  output[0].Nlensing = Nlensing;
     113  output[0].Nstarpar = Nstarpar;
    96114  output[0].Nsecf_mem = Naverage * NsecfiltOut;
    97115
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r37116 r37807  
    44# define IN_REGION(R,D) (                                       \
    55    ((D) >= region[0].Dmin) && ((D) < region[0].Dmax) &&        \
    6     ((R) >= region[0].Rmin)  && ((R) < region[0].Rmax))
     6    ((R) >= region[0].Rmin) && ((R) < region[0].Rmax))
    77
    88// merge the input data into the output catalog
     
    1414  double *X1, *Y1, *X2, *Y2;
    1515  double dX, dY, dR;
    16   off_t *N1, *N2, *next_meas, *next_lens;
    17   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS;
     16  off_t *N1, *N2, *next_meas, *next_lens, *next_star;
     17  off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS, Nstar, NSTAR;
    1818  int NsecfiltIn;
    1919  int NsecfiltOut;
     
    5353  NMEAS = Nmeas = output[0].Nmeasure;
    5454  NLENS = Nlens = output[0].Nlensing;
     55  NSTAR = Nstar = output[0].Nstarpar;
    5556
    5657  // current max obj ID for this catalog
     
    6465   * coordops.update.c).  We use the center of the region (catalog) for crval1,2.
    6566   */
     67
     68  InitCoords (&tcoords, "DEC--ARC");
    6669  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    6770  if (region[0].Dmax < 90) {
     
    7073    tcoords.crval2 = 90.0;
    7174  }
    72   tcoords.crpix1 = 0;
    73   tcoords.crpix2 = 0;
    7475  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    75   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    76   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    77   tcoords.Npolyterms = 1;
    78   strcpy (tcoords.ctype, "DEC--ARC");
    7976
    8077  if (VERBOSE) fprintf (stderr, "merging %s into %s\n", input[0].filename, output[0].filename);
     
    120117    next_meas = init_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
    121118    next_lens = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
     119    next_star = init_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    122120  } else {
    123121    next_meas = build_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
    124122    next_lens = build_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
     123    next_star = build_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    125124  }   
    126125
     
    184183      REALLOCATE (output[0].measure, Measure, NMEAS);
    185184    }
    186     if (Nlens + input[0].average[N].Nmeasure >= NLENS) {
    187       NLENS = Nlens + input[0].average[N].Nmeasure + 1000;
     185    if (Nlens + input[0].average[N].Nlensing >= NLENS) {
     186      NLENS = Nlens + input[0].average[N].Nlensing + 1000;
    188187      REALLOCATE (next_lens, off_t, NLENS);
    189188      REALLOCATE (output[0].lensing, Lensing, NLENS);
     189    }
     190    if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
     191      NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
     192      REALLOCATE (next_star, off_t, NSTAR);
     193      REALLOCATE (output[0].starpar, StarPar, NSTAR);
    190194    }
    191195
     
    274278    }
    275279
     280    // if lensing measurements exist, add them too
     281    if (output[0].starpar) {
     282      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin++) {
     283        /* add to end of lensing list */
     284        add_star_link (&output[0].average[n], next_star, Nstar, NSTAR);
     285       
     286        // set the new starpar
     287        off_t staroff = input[0].average[N].starparOffset + Nin;
     288        output[0].starpar[Nstar] = input[0].starpar[staroff];
     289
     290        output[0].starpar[Nstar].averef   = n;
     291        output[0].starpar[Nstar].objID    = output[0].average[n].objID;
     292        output[0].starpar[Nstar].catID    = output[0].catID;
     293        output[0].average[n].Nstarpar ++;
     294        Nstar ++;
     295      }
     296    }
     297
    276298    // update the average properties to reflect the incoming entries:
    277299    // if the original value is NAN but the input value is not, accept the input:
     
    319341      REALLOCATE (output[0].lensing, Lensing, NLENS);
    320342    }
     343    if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
     344      NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
     345      REALLOCATE (next_star, off_t, NSTAR);
     346      REALLOCATE (output[0].starpar, StarPar, NSTAR);
     347    }
    321348    if (Nave >= NAVE) {
    322349      NAVE = Nave + 1000;
     
    326353
    327354    if (input[0].found_t[N] >= 0) continue;
    328     if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
     355
     356    // if we are using MATCHED_TABLES, we are going to leave the edge cases in their
     357    // source catalog, even if they have leaked beyond the edge
     358    if (!MATCHED_TABLES && !IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
    329359
    330360    // XXX should we accept the input measurements for these fields?
     
    413443    }
    414444
     445    /** add starpar for this input average object **/
     446    if (output[0].starpar) {
     447      output[0].average[Nave].starparOffset  = Nstar;
     448      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin ++) {
     449        // supply the starpar values from this detection
     450        off_t staroff = input[0].average[N].starparOffset + Nin;
     451        output[0].starpar[Nstar]           = input[0].starpar[staroff];
     452
     453        // the following starpar elements cannot be set until here:
     454        output[0].starpar[Nstar].averef   = Nave;
     455        output[0].starpar[Nstar].objID    = output[0].average[Nave].objID;
     456        output[0].starpar[Nstar].catID    = output[0].catID;
     457
     458        // as we add starpar, update Nstarpar to match
     459        output[0].average[Nave].Nstarpar ++;
     460
     461        /* we set next[Nstar] to -1 here, and update correctly below */
     462        next_star[Nstar] = -1;
     463        Nstar ++;
     464      }
     465      int Ngroup = input[0].average[N].Nstarpar;
     466      for (j = 0; j < Ngroup - 1; j++) {
     467        next_star[Nstar - Ngroup + j] = Nstar - Ngroup + j + 1;
     468      }
     469    }
     470
    415471    Nave ++;
    416472  }
     
    421477  REALLOCATE (output[0].measure, Measure, Nmeas);
    422478  REALLOCATE (output[0].lensing, Lensing, Nlens);
     479  REALLOCATE (output[0].starpar, StarPar, Nstar);
    423480 
    424481# define NOSORT 0
     
    429486    output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas);
    430487    output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens);
     488    output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star);
    431489  }
    432490
     
    445503  output[0].Nmeasure = Nmeas;
    446504  output[0].Nlensing = Nlens;
     505  output[0].Nstarpar = Nstar;
    447506  output[0].Nsecf_mem = Nave*NsecfiltOut;
    448507  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Nmatch);
     
    450509  free (next_meas);
    451510  free (next_lens);
     511  free (next_star);
    452512
    453513  free (X2);
  • trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r37361 r37807  
    239239  }
    240240
    241   PrintIOBuffer (buffer, "(%lu, ", detection->objID);       // objID
    242   PrintIOBuffer (buffer,  "%lu, ", detection->detectID);    // detectID
    243   PrintIOBuffer (buffer,  "%lu, ", detection->ippObjID);    // ippObjID
     241  // XXX I needed OFF_T_FMT on my 32bit ubuntu laptop; ok on 64bit?
     242  PrintIOBuffer (buffer, "("OFF_T_FMT", ", detection->objID);       // objID
     243  PrintIOBuffer (buffer,  OFF_T_FMT", ", detection->detectID);    // detectID
     244  PrintIOBuffer (buffer,  OFF_T_FMT", ", detection->ippObjID);    // ippObjID
    244245  PrintIOBuffer (buffer,  "%u,  ", detection->ippDetectID); // ippDetectID
    245246  PrintIOBuffer (buffer,  "%d,  ", detection->imageID);     // imageID
  • trunk/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r37246 r37807  
    256256// XXX this bit could/should be autocoded...
    257257  PrintIOBuffer (ave_buffer, " (");
    258   PrintIOBuffer (ave_buffer, "%lu, ", average->extID);         
     258  PrintIOBuffer (ave_buffer, OFF_T_FMT", ", average->extID);         
    259259  PrintIOBuffer (ave_buffer, "%u,  ", average->objID);         
    260260  PrintIOBuffer (ave_buffer, "%u,  ", average->catID);         
  • trunk/Ohana/src/dvosplit/include/dvosplit.h

    r33656 r37807  
    2222} AveLinks;
    2323
     24int    FULL_TABLE;
    2425int    VERBOSE;
    2526char  *OUTDIR;
  • trunk/Ohana/src/dvosplit/src/args.c

    r33656 r37807  
    5757  }
    5858
     59  // override input catalog format (PS1_V1, PS1_REF, etc)
     60  FULL_TABLE = FALSE;
     61  if ((N = get_argument (argc, argv, "-full-table"))) {
     62    remove_argument (N, &argc, argv);
     63    FULL_TABLE = TRUE;
     64  }
     65
    5966  /* extra error messages */
    6067  VERBOSE = FALSE;
  • trunk/Ohana/src/dvosplit/src/split_averages.c

    r37043 r37807  
    2727  incatalog[0].catflags = LOAD_AVES | LOAD_SECF;
    2828
    29   if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     29  if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    3030    Nblocks = incatalog[0].Naves_disk / NROWS;
    3131    if (incatalog[0].Naves_disk % NROWS) Nblocks ++;
     
    3636  for (block = 0; block < Nblocks; block++) {
    3737
    38     if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     38    if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    3939      // read up to NROWS at a time
    4040      dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
    4141      fprintf (stderr, "splitting %s (averages) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
     42      assert (block*NROWS == incatalog[0].Naves_off);
    4243    } else {
    4344      dvo_catalog_load (incatalog, VERBOSE);
    4445      fprintf (stderr, "splitting %s (averages)\n", incatalog[0].filename);
    4546    }
    46 
    47     assert (block*NROWS == incatalog[0].Naves_off);
    4847
    4948    // distribute data to the output catalogs
     
    5453      inD = incatalog[0].average[ave].D;
    5554
     55      if (incatalog[0].average[ave].Nmeasure == 0) {
     56        fprintf (stderr, "WARNING: object with no measurements, skipping %d (%f, %f)\n", averef, inR, inD);
     57        continue;
     58      }
    5659      // which of the outcatalogs contains this coordinate?
    5760
     
    98101
    99102    // write out the new values
    100     for (cat = 0; cat < outlist[0].Nregions; cat++) {
    101       outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF;
     103    if (!FULL_TABLE) {
     104      for (cat = 0; cat < outlist[0].Nregions; cat++) {
     105        outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF;
    102106
    103       dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    104       // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
     107        dvo_catalog_save (&outcatalogs[cat], VERBOSE);
     108        // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
    105109
    106       // advance the pointers and free the current data
    107       // XXX these should be done within save segment:
    108       outcatalogs[cat].Naves_disk += outcatalogs[cat].Naverage;
    109       outcatalogs[cat].Naves_off  += outcatalogs[cat].Naverage;
    110       outcatalogs[cat].Nsecf_disk += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
    111       outcatalogs[cat].Nsecf_off  += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
    112       outcatalogs[cat].Nsecfilt    = Nsecfilt;
     110        // advance the pointers and free the current data
     111        // XXX these should be done within save segment:
     112        outcatalogs[cat].Naves_disk += outcatalogs[cat].Naverage;
     113        outcatalogs[cat].Naves_off  += outcatalogs[cat].Naverage;
     114        outcatalogs[cat].Nsecf_disk += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
     115        outcatalogs[cat].Nsecf_off  += outcatalogs[cat].Nsecfilt * outcatalogs[cat].Naverage;
     116        outcatalogs[cat].Nsecfilt    = Nsecfilt;
    113117
    114       outcatalogs[cat].Naverage    = 0;
    115       outcatalogs[cat].Nsecf_mem   = 0;
     118        outcatalogs[cat].Naverage    = 0;
     119        outcatalogs[cat].Nsecf_mem   = 0;
     120      }
    116121    }
    117122  }
    118123
    119   for (cat = 0; cat < outlist[0].Nregions; cat++) {
    120     dvo_catalog_free_data (&outcatalogs[cat]);
     124  if (!FULL_TABLE) {
     125    for (cat = 0; cat < outlist[0].Nregions; cat++) {
     126      dvo_catalog_free_data (&outcatalogs[cat]);
     127    }
    121128  }
    122129
  • trunk/Ohana/src/dvosplit/src/split_measures.c

    r37043 r37807  
    2727  // }
    2828
    29   if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     29  if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    3030    Nblocks = incatalog[0].Nmeas_disk / NROWS;
    3131    if (incatalog[0].Nmeas_disk % NROWS) Nblocks ++;
     
    3737
    3838    // read up to NROWS at a time
    39     if (incatalog[0].catmode == DVO_MODE_SPLIT) {
     39    if ((incatalog[0].catmode == DVO_MODE_SPLIT) && !FULL_TABLE) {
    4040      dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
    4141      fprintf (stderr, "splitting %s (measures) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
     42      assert (block*NROWS == incatalog[0].Nmeas_off);
    4243    } else {
    4344      dvo_catalog_load (incatalog, VERBOSE);
    4445      fprintf (stderr, "splitting %s (measures)\n", incatalog[0].filename);
    4546    }
    46 
    47     assert (block*NROWS == incatalog[0].Nmeas_off);
    4847
    4948    for (meas = 0; meas < incatalog[0].Nmeasure; meas++) {
     
    5251      Ncat = outcat[averef];
    5352
     53      int averef_out = outref[averef];
     54      if (averef_out >= outcatalogs[Ncat].Naverage) {
     55        fprintf (stderr, "mismatch 1\n");
     56        abort();
     57      }
     58
    5459      Nout = outcatalogs[Ncat].Nmeasure;
    5560      outcatalogs[Ncat].measure[Nout] = incatalog[0].measure[meas];
    5661      outcatalogs[Ncat].measure[Nout].averef = outref[averef];
     62
    5763      outcatalogs[Ncat].Nmeasure++;
    5864
     
    6470    dvo_catalog_free_data (incatalog);
    6571
     72    if (!FULL_TABLE) {
     73      for (cat = 0; cat < outlist[0].Nregions; cat++) {
     74        outcatalogs[cat].catflags = LOAD_MEAS;
     75        dvo_catalog_save (&outcatalogs[cat], VERBOSE);
     76
     77        outcatalogs[cat].Nmeas_disk += outcatalogs[cat].Nmeasure;
     78        outcatalogs[cat].Nmeas_off  += outcatalogs[cat].Nmeasure;
     79        outcatalogs[cat].Nmeasure    = 0;
     80      }
     81    }
     82  }
     83
     84  if (FULL_TABLE) {
    6685    for (cat = 0; cat < outlist[0].Nregions; cat++) {
    67       outcatalogs[cat].catflags = LOAD_MEAS;
     86      outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
    6887      dvo_catalog_save (&outcatalogs[cat], VERBOSE);
    69 
    70       outcatalogs[cat].Nmeas_disk += outcatalogs[cat].Nmeasure;
    71       outcatalogs[cat].Nmeas_off  += outcatalogs[cat].Nmeasure;
    72       outcatalogs[cat].Nmeasure    = 0;
    73 
    7488    }
    7589  }
  • trunk/Ohana/src/fixcat/src/gcatstats.c

    r36481 r37807  
    4646  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    4747  /* reference for coords is center of field  */
     48  InitCoords (&catstats[0].coords, "DEC--TAN");
    4849  catstats[0].coords.crval1 = RaCenter;
    4950  catstats[0].coords.crval2 = DecCenter;
    50   catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
    5151  catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
    52   catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    53   catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    54   strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5552
    5653  X1 = catstats[0].X;
  • trunk/Ohana/src/gastro/src/gfitpoly.c

    r27435 r37807  
    261261    det = 1.0 / (a1*b2 - a2*b1);
    262262
     263    InitCoords (coords, "DEC--PLY");
     264
    263265    coords[0].pc1_1 = p11*a1 + p12*b1*(S2/S1);
    264266    coords[0].pc2_1 = p21*a1 + p22*b1*(S2/S1);
     
    273275
    274276    coords[0].Npolyterms = NORDER;
    275     strcpy (coords[0].ctype, "DEC--PLY");
    276277
    277278    /* generate higher order terms from vector */
  • trunk/Ohana/src/gastro/src/gstars.c

    r36481 r37807  
    7979  if (!strcasecmp (ROUGH_ASTROMETRY, "config")) {
    8080    /* default values for coords */
    81     strcpy (coords[0].ctype, "DEC--TAN");
     81    InitCoords (coords, "DEC--TAN");
    8282    coords[0].pc1_1 = CCD_PC1_1; coords[0].pc1_2 = CCD_PC1_2;
    8383    coords[0].pc2_1 = CCD_PC2_1; coords[0].pc2_2 = CCD_PC2_2;
    8484    coords[0].cdelt1 = coords[0].cdelt2 = ASEC_PIX / 3600.0;
    85     coords[0].Npolyterms = 0;
    8685    coords[0].crpix1 = 0.5*(*NX);
    8786    coords[0].crpix2 = 0.5*(*NY);
  • trunk/Ohana/src/gastro2/src/gproject2.c

    r12332 r37807  
    1919
    2020  /* create Tangent Plane to Sky transformation from input coords */
    21   strcpy (TPtoSky.ctype, coords[0].ctype);
     21  InitCoords (&TPtoSky, coords[0].ctype);
    2222  TPtoSky.crval1 = coords[0].crval1;
    2323  TPtoSky.crval2 = coords[0].crval2;
    2424
    25   TPtoSky.cdelt1 = TPtoSky.cdelt2 = 1;
    26   TPtoSky.crpix1 = TPtoSky.crpix2 = 0;
    27   TPtoSky.pc1_1 = TPtoSky.pc2_2 = 1;
    28   TPtoSky.pc1_2 = TPtoSky.pc2_1 = 0;
    29   TPtoSky.Npolyterms = 0;
    30   for (i = 0; i < 7; i++) {
    31     TPtoSky.polyterms[i][0] = 0;
    32     TPtoSky.polyterms[i][1] = 0;
    33   }
    34 
    3525  /* create Focal Plane to Tangent Plane transformation from input coords */
    36   strcpy (FPtoTP.ctype, "FP---PLY");
    37   FPtoTP.crval1 = FPtoTP.crval2 = 0;
    38 
     26  InitCoords (&FPtoTP, "FP---PLY");
    3927  FPtoTP.cdelt1 = coords[0].cdelt1;
    4028  FPtoTP.cdelt2 = coords[0].cdelt2;
  • trunk/Ohana/src/gastro2/src/gstars2.c

    r37054 r37807  
    2828
    2929  /* default values for coords */
    30   strcpy (Target[0].coords.ctype, "DEC--TAN");
     30  InitCoords (&Target[0].coords, "DEC--TAN");
    3131  Target[0].coords.pc1_1 = CCD_PC1_1; Target[0].coords.pc1_2 = CCD_PC1_2;
    3232  Target[0].coords.pc2_1 = CCD_PC2_1; Target[0].coords.pc2_2 = CCD_PC2_2;
    3333  Target[0].coords.cdelt1 = Target[0].coords.cdelt2 = ASEC_PIX / 3600.0;
    34   Target[0].coords.Npolyterms = 0;
    3534  Target[0].coords.crpix1 = 0.5*NX;
    3635  Target[0].coords.crpix2 = 0.5*NY;
  • trunk/Ohana/src/getstar

  • trunk/Ohana/src/getstar/include/dvoImageOverlaps.h

    r27435 r37807  
    3737int edge_check (double *x1, double *y1, double *x2, double *y2);
    3838double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
     39
     40void initMosaicCoords ();
     41void saveMosaicCoords (Coords *input);
  • trunk/Ohana/src/getstar/src/MatchCoords.c

    r31238 r37807  
    2929    if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    3030    if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    31 
    32     /* if any of these images are WRP images, need to find matching DIS */
    33     if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
    3431
    3532    /* define image corners */
  • trunk/Ohana/src/getstar/src/MatchImages.c

    r36481 r37807  
    2323  /* we keep the original crpix1,2 and crref1,2 */
    2424  /* for mosaic astrometry, the grid should be w.r.t. the tangent-plane, not chip coords */
     25  InitCoords (&tcoords, "DEC--TAN");
    2526  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
    26     // if the input image is a mosaic, we need to register that mosaic for the calculations below
    27     if (MOSAIC == NULL) {
    28       fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
    29       return NULL;
    30     }
    31     RegisterMosaic (MOSAIC);
    32 
    33     tcoords = MOSAIC[0];
     27    myAssert (image[0].coords.mosaic, "should already have tested this");
     28    tcoords = image[0].coords.mosaic[0];
    3429    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    35     tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    36     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    37     tcoords.Npolyterms = 1;
    38     strcpy (tcoords.ctype, "DEC--TAN");
    3930    /* register so image->sky conversions below have correct mosaic */
    4031  } else {
    4132    tcoords = image[0].coords;
    4233    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    43     tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    44     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    45     tcoords.Npolyterms = 1;
    46     strcpy (tcoords.ctype, "DEC--TAN");
    4734  }
    4835
     
    7764    if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    7865    if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
    79 
    80     /* if any of these images are WRP images, need to find matching DIS */
    81     if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
    8266
    8367    /* define image corners */
  • trunk/Ohana/src/getstar/src/ReadImageFiles.c

    r36874 r37807  
    4242
    4343  mode = GetFileMode (header);
     44
     45  initMosaicCoords ();
    4446
    4547  /*** load data from a single PHU or a collection of PHU files ***/
  • trunk/Ohana/src/getstar/src/ReadImageHeader.c

    r21508 r37807  
    11# include "dvoImageOverlaps.h"
     2
     3// for DIS/WRP sets, we need to save the DIS set and supply it to the WRP entries
     4static Coords *mosaic = NULL;
     5
     6void initMosaicCoords () {
     7  mosaic = NULL;
     8}
     9
     10void saveMosaicCoords (Coords *input) {
     11  mosaic = input;
     12}
    213
    314/* read an image header corresponding to a CMF / CMP data block */
     
    4455  /* only load astrometry, NAXIS1,2, and time if this is a MOSAIC_PHU (ctype is ....-DIS) */
    4556  if (!strcmp (&image[0].coords.ctype[4], "-DIS")) {
    46     MOSAIC = &image[0].coords;
     57    saveMosaicCoords (&image[0].coords);
    4758    return (TRUE);
    4859  }
     
    5667  }
    5768  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
    58     if (MOSAIC == NULL) {
     69    if (mosaic == NULL) {
    5970      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
    6071      return (FALSE);
    6172    }
    62     RegisterMosaic (MOSAIC);
     73    image[0].coords.mosaic = mosaic;
    6374  } else {
    6475    /* force image to lie in 0-360 range */
  • trunk/Ohana/src/getstar/src/WriteImages.c

    r27435 r37807  
    55 
    66  int i, N;
    7   int nWRP, newWRP, isWRP;
     7  int isWRP;
    88  FILE *f;
    99
     
    1616  }
    1717
    18   nWRP = -1;
     18  Image *mosaic = NULL;
    1919  isWRP = FALSE;
    2020  for (i = 0; i < Nmatches; i++) {
    21     if (!strcmp (&images[0].coords.ctype[4], "-WRP")) {
    22       if (!FindMosaicForImage (images, Nimages, i)) {
    23         fprintf (stderr, "failed to find matching mosaic\n");
    24         exit (1);
    25       }
     21    N = matches[i];
     22    if (!strcmp (&images[N].coords.ctype[4], "-WRP")) {
    2623      if (isWRP) {
    27         newWRP = GetRegisteredMosaic();
    28         if (newWRP != nWRP) {
     24        if (mosaic != images[N].parent) {
    2925          fprintf (stderr, "only one mosaic allowed in an output file\n");
    3026          exit (1);
    3127        }
    3228      } else {
    33         nWRP = GetRegisteredMosaic();
    34         isWRP = TRUE;
     29        mosaic = images[N].parent;
    3530      }
    3631    }     
     
    3833
    3934  if (isWRP) {
    40     WriteImageFITS (f, &images[nWRP]);
     35    WriteImageFITS (f, mosaic);
    4136  } else {
    4237    // write a blank
  • trunk/Ohana/src/imregister/imphot/dumpfits.c

    r30617 r37807  
    3434
    3535  ftable.header = &theader;
    36   gfits_table_set_Image (&ftable, subset, Nmatch);
     36  // gfits_table_set_Image (&ftable, subset, Nmatch);
    3737
    3838  gfits_fwrite_header  (f, &header);
  • trunk/Ohana/src/imregister/imphot/modify.c

    r27435 r37807  
    3030  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, match, Nmatch);
    3131  for (i = 0; i < Nmatch; i++) {
    32     gfits_convert_Image ((Image *) db[0].vtable.buffer[i], sizeof (Image), 1);
     32    fprintf (stderr, "need to work with real output format\n");
     33    exit (2);
     34    // gfits_convert_Image ((Image *) db[0].vtable.buffer[i], sizeof (Image), 1);
    3335  }
    3436  gfits_db_update (db);
  • trunk/Ohana/src/kapa2/include/constants.h

    r36084 r37807  
    1010 | PointerMotionMask)
    1111
    12 # define NCHANNELS 3
     12# define NCHANNELS 10
    1313# define NPIXELS_DYNAMIC 128
    1414
  • trunk/Ohana/src/kapa2/include/structures.h

    r32695 r37807  
    217217  KapaImageChannel *image;
    218218  KapaImageChannel channel[NCHANNELS];
     219  int currentChannel;
    219220} KapaImageWidget;
    220221
  • trunk/Ohana/src/kapa2/src/CreatePicture.c

    r16270 r37807  
    4040
    4141  case 24:
     42   
     43    extra = 4 - (image[0].wide.dx * 3) % 4;
     44    REALLOCATE (image[0].wide.data, char, image[0].wide.dy*(3*image[0].wide.dx+extra));
     45
     46    extra = 4 - (image[0].zoom.dx * 3) % 4;
     47    REALLOCATE (image[0].zoom.data, char, image[0].zoom.dy*(3*image[0].zoom.dx+extra));
     48
    4249    extra = 4 - (image[0].picture.dx * 3) % 4;
    43     REALLOCATE (image[0].wide.data, char, image[0].wide.dy*(3*image[0].wide.dx+extra));
    44     REALLOCATE (image[0].zoom.data, char, image[0].zoom.dy*(3*image[0].zoom.dx+extra));
    4550    REALLOCATE (image[0].picture.data, char, image[0].picture.dy*(3*image[0].picture.dx+extra));
    4651    c = (unsigned char *) image[0].picture.data;
  • trunk/Ohana/src/kapa2/src/CursorOps.c

    r25757 r37807  
    100100  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    101101  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
     102 
     103  // Sx,Sy should be forced into the pixel
     104  int Sxi = Sx + 0.5;
     105  int Syi = Sy + 0.5;
    102106
    103107  // i_start, j_start are now limited to valid screen coordinates
    104   *i_start = MIN (MAX (Sx, 0), picture[0].dx);
    105   *j_start = MIN (MAX (Sy, 0), picture[0].dy);
     108  *i_start = MIN (MAX (Sxi, 0), picture[0].dx);
     109  *j_start = MIN (MAX (Syi, 0), picture[0].dy);
    106110}
    107111 
     
    127131  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
    128132
    129   // I_end, J_end are the last displayed image pixel
    130   // *I_end = Ix;
    131   // *J_end = Iy;
    132 
    133133  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
    134134  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
    135135
     136  // Sx,Sy should be forced into the pixel
     137  int Sxi = Sx + 0.5;
     138  int Syi = Sy + 0.5;
     139
     140  // double IxTest, IyTest;
     141  // Picture_to_Image (&IxTest, &IyTest, Sx, Sy, picture);
     142  // fprintf (stderr, "dx,dy: %d,%d : %f,%f : %f,%f : %f:%f\n", picture[0].dx, picture[0].dy, Ix, Iy, Sx, Sy, IxTest, IyTest);
     143
    136144  // i_start, j_start are now limited to valid screen coordinates
    137   *i_end = MIN (MAX (Sx, 0), picture[0].dx);
    138   *j_end = MIN (MAX (Sy, 0), picture[0].dy);
     145  // XXX: i_end, j_end *should* be the last valid screen pixel plus 1
     146  *i_end = MIN (MAX (Sxi, 0), picture[0].dx);
     147  *j_end = MIN (MAX (Syi, 0), picture[0].dy);
    139148
    140149  // round off error can leave us with a small number of extra pixels here.
  • trunk/Ohana/src/kapa2/src/Graphs.c

    r36487 r37807  
    5757  graph[0].data.flipnorth = FALSE;      // +North = +Y by default
    5858
    59   graph[0].data.coords.pc1_1 = graph[0].data.coords.pc2_2 = 1.0;
    60   graph[0].data.coords.pc1_2 = graph[0].data.coords.pc2_1 = 0.0;
    61   graph[0].data.coords.crval1 = 0.0;
    62   graph[0].data.coords.crval2 = 0.0;
    63   graph[0].data.coords.crpix1 = 0.0;
    64   graph[0].data.coords.crpix2 = 0.0;
    65   graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
    66   strcpy (graph[0].data.coords.ctype, "DEC--LIN");
     59  InitCoords (&graph[0].data.coords, "DEC--LIN");
    6760  strcpy (graph[0].data.axis, "2222");
    6861  strcpy (graph[0].data.ticks, "2222");
  • trunk/Ohana/src/kapa2/src/Image.c

    r36487 r37807  
    1111  channel->slope = 1;
    1212
    13   channel->coords.pc1_1 = channel->coords.pc2_2 = 1.0;
    14   channel->coords.pc1_2 = channel->coords.pc2_1 = 0.0;
    15   channel->coords.crval1 = 0.0;
    16   channel->coords.crval2 = 0.0;
    17   channel->coords.crpix1 = 0.0;
    18   channel->coords.crpix2 = 0.0;
    19   channel->coords.cdelt1 = channel->coords.cdelt2 = 1.0;
    20   strcpy (channel->coords.ctype, "DEC--LIN");
    21   channel->coords.Npolyterms = 0;
     13  InitCoords (&channel->coords, "DEC--LIN");
    2214
    2315  channel->matrix.datasize = 0; /* a flag to show there is no data in the matrix */
     
    4234    InitImageChannel (&image[0].channel[i]);
    4335  }
    44   image[0].image = &image[0].channel[0];
     36
     37  image[0].currentChannel = 0;
     38  image[0].image = &image[0].channel[image[0].currentChannel];
    4539
    4640  image[0].nPixels = 0;
  • trunk/Ohana/src/kapa2/src/InterpretKeys.c

    r37412 r37807  
    9090  switch (keysym) {
    9191
    92     case XK_F1:
    93       image[0].image = &image[0].channel[0];
    94       SetColorScale (graphic, image);
    95       Remap (graphic, image);
    96       Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
     92# define SET_CHANNEL_CASE(NCHAN) \
     93    case XK_F##NCHAN: \
     94      image[0].currentChannel = NCHAN-1; \
     95      image[0].image = &image[0].channel[NCHAN-1]; \
     96      SetColorScale (graphic, image); \
     97      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0); \
     98      Screen_to_Image (&X, &Y, (double)(event[0].x + 0.5), (double)(event[0].y + 0.5), &image[0].picture); \
     99      UpdateStatusBox (graphic, image, X, Y, 0.0, 1); \
    97100      break;
    98101
    99     case XK_F2:
    100       image[0].image = &image[0].channel[1];
    101       SetColorScale (graphic, image);
    102       Remap (graphic, image);
    103       Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
    104       break;
     102//    Remap (graphic, image);
    105103
    106     case XK_F3:
    107       image[0].image = &image[0].channel[2];
    108       SetColorScale (graphic, image);
    109       Remap (graphic, image);
    110       Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
    111       break;
     104    // the number of entries here must match the value of NCHANNELS in contants.h
     105    SET_CHANNEL_CASE(1);
     106    SET_CHANNEL_CASE(2);
     107    SET_CHANNEL_CASE(3);
     108    SET_CHANNEL_CASE(4);
     109    SET_CHANNEL_CASE(5);
     110    SET_CHANNEL_CASE(6);
     111    SET_CHANNEL_CASE(7);
     112    SET_CHANNEL_CASE(8);
     113    SET_CHANNEL_CASE(9);
     114    SET_CHANNEL_CASE(10);
    112115
    113116    case XK_KP_Home:
  • trunk/Ohana/src/kapa2/src/LoadPicture.c

    r28241 r37807  
    5555  // choose expand for wide to guarantee we fit:
    5656  wx = MAX ((header.Naxis[0] / (float) image[0].wide.dx), (header.Naxis[1] / (float) image[0].wide.dy));
    57   if (wx > 1.0) {
    58     image[0].wide.expand = -wx;
    59   } else {
    60     image[0].wide.expand = 1.0 / wx;
    61   }   
     57
     58  // -4.002 -> -5
     59  // image[0].wide.expand = (wx > 1.0) ? ceil (-wx) : floor (1.0 / wx);
     60  image[0].wide.expand = (wx > 1.0) ? floor (-wx) : ceil (1.0 / wx);
     61  // fprintf (stderr, "%d : %f\n", image[0].wide.expand, wx);
     62  image[0].wide.expand = (wx > 1.0) ? ceil (-wx) : floor (1.0 / wx);
     63
    6264  image[0].wide.Xc = 0.5*header.Naxis[0];
    6365  image[0].wide.Yc = 0.5*header.Naxis[1];
  • trunk/Ohana/src/kapa2/src/Reconfig.c

    r21153 r37807  
    1515
    1616  // if the new size is the same as the old size, do nothing.
    17   if ((graphic->dx == NX) && (graphic->dy == NY)) return (TRUE);
     17  if ((graphic->dx == NX) && (graphic->dy == NY)) {
     18    if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
     19    Refresh ();
     20    return (TRUE);
     21  }
    1822
    1923  // set the new window size
  • trunk/Ohana/src/kapa2/src/Remap32.c

    r34088 r37807  
    3737  swap_client = 0;
    3838# endif 
    39 
    4039  swap_server = ImageByteOrder (graphic[0].display);
    4140  swap_bytes = !(swap_client ^ swap_server);
     
    9190  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    9291
     92  unsigned short *in_base = image[0].pixmap;
     93  OUT_TYPE *out_base = (OUT_TYPE *) picture[0].data;
     94
     95  int Ninmax = matrix[0].Naxis[0] * matrix[0].Naxis[1];
     96  int Noutmax = picture[0].dx * picture[0].dy;
     97
    9398  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
    9499
    95100  /**** fill in bottom area ****/
    96101  for (j = 0; j < dx*j_start; j++, out_pix++) {
     102    myAssert (out_pix - out_base < Noutmax, "too far out");
    97103    *out_pix = back;
    98104  }
     
    105111      out_pix2 = out_pix + jj*dx;
    106112      for (i = 0; i < i_start; i++, out_pix2++) {
     113        myAssert (out_pix2 - out_base < Noutmax, "too far out");
    107114        *out_pix2 = back;
    108115      }
     
    114121    if (expand_out == 1) {
    115122      for (i = i_start; i < i_end; i++, in_pix2 += inDX*expand_in, out_pix++) {
     123        myAssert (out_pix - out_base < Noutmax, "too far out");
     124        myAssert (in_pix2 - in_base < Ninmax, "too far in");
    116125        *out_pix = pixel[*in_pix2];
    117126      }
    118127    } else {
    119128      for (i = i_start; i < i_end; i+= expand_out, in_pix2 += inDX, out_pix+= expand_out) {
     129        myAssert (in_pix2 - in_base < Ninmax, "too far in");
    120130        pixvalue = pixel[*in_pix2];
    121131        out_pix2 = out_pix;
    122132        for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) {
    123133          for (ii = 0; ii < expand_out; ii++, out_pix2++) {
     134            myAssert (out_pix2 - out_base < Noutmax, "too far out");
    124135            *out_pix2 = pixvalue;
    125136          }
     
    133144      out_pix2 = out_pix + jj*dx;
    134145      for (i = i_end; i < dx; i++, out_pix2++) {
     146        myAssert (out_pix2 - out_base < Noutmax, "too far out");
    135147        *out_pix2 = back;
    136148      }
     
    142154  for (j = 0; j < dy - j_end; j++) {
    143155    for (i = 0; i < dx; i++, out_pix ++) {
     156      myAssert (out_pix - out_base < Noutmax, "too far out");
    144157      *out_pix = back;
    145158    }
  • trunk/Ohana/src/kapa2/src/SetChannel.c

    r31665 r37807  
    2121  if (Nchannel >= NCHANNELS) return (TRUE);
    2222 
    23   image[0].image = &image[0].channel[Nchannel];
     23  image[0].currentChannel = Nchannel;
     24  image[0].image = &image[0].channel[image[0].currentChannel];
    2425  SetColorScale (graphic, image);
    2526
     
    6162
    6263  Refresh ();
    63   XFlush (graphic[0].display);
     64  if (USE_XWINDOW) XFlush (graphic[0].display);
    6465
    6566  return (TRUE);
  • trunk/Ohana/src/kapa2/src/UpdateStatusBox.c

    r30606 r37807  
    2020 
    2121    bzero (line, 100);
    22     snprintf (line, 100, "(%d x %d) @ %d                                         ",
    23              image[0].picture.dx, image[0].picture.dy, image[0].picture.expand);
     22    snprintf (line, 100, "(%d x %d) @ %d   ch: %d                                     ",
     23              image[0].picture.dx, image[0].picture.dy, image[0].picture.expand, image[0].currentChannel+1);
    2424    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    2525                 image[0].text_x + PAD1, image[0].text_y + 4*textpad + 4*PAD1, line, 25);
  • trunk/Ohana/src/libautocode/Makefile.Targets

    r37034 r37807  
    11AOBJS = \
    2 $(ASRC)/coords.$(ARCH).o \
     2$(ASRC)/coords-disk.$(ARCH).o \
     3$(ASRC)/AstromOffsetMap_Disk.$(ARCH).o \
    34$(ASRC)/average.$(ARCH).o \
    45$(ASRC)/average-loneos.$(ARCH).o \
     
    1314$(ASRC)/average-ps1-v4.$(ARCH).o \
    1415$(ASRC)/average-ps1-v5.$(ARCH).o \
     16$(ASRC)/average-ps1-sim.$(ARCH).o \
    1517$(ASRC)/average-ps1-ref.$(ARCH).o \
    1618$(ASRC)/secfilt.$(ARCH).o \
     
    2628$(ASRC)/secfilt-ps1-v4.$(ARCH).o \
    2729$(ASRC)/secfilt-ps1-v5.$(ARCH).o \
     30$(ASRC)/secfilt-ps1-sim.$(ARCH).o \
    2831$(ASRC)/secfilt-ps1-ref.$(ARCH).o \
    2932$(ASRC)/measure.$(ARCH).o \
     
    3942$(ASRC)/measure-ps1-v4.$(ARCH).o \
    4043$(ASRC)/measure-ps1-v5.$(ARCH).o \
     44$(ASRC)/measure-ps1-sim.$(ARCH).o \
    4145$(ASRC)/measure-ps1-ref.$(ARCH).o \
    4246$(ASRC)/lensing.$(ARCH).o \
    4347$(ASRC)/lensing-ps1-v5.$(ARCH).o \
     48$(ASRC)/lensing-ps1-v5-alt.$(ARCH).o \
    4449$(ASRC)/lensobj.$(ARCH).o \
    4550$(ASRC)/lensobj-ps1-v5.$(ARCH).o \
     51$(ASRC)/starpar.$(ARCH).o \
     52$(ASRC)/starpar-ps1-v5.$(ARCH).o \
     53$(ASRC)/starpar-ps1-sim.$(ARCH).o \
    4654$(ASRC)/missing.$(ARCH).o \
    4755$(ASRC)/photcode.$(ARCH).o \
     
    5664$(ASRC)/photcode-ps1-v5.$(ARCH).o \
    5765$(ASRC)/photcode-ps1-ref.$(ARCH).o \
    58 $(ASRC)/image.$(ARCH).o \
    5966$(ASRC)/image-loneos.$(ARCH).o \
    6067$(ASRC)/image-elixir.$(ARCH).o \
     
    6976$(ASRC)/image-ps1-v4.$(ARCH).o \
    7077$(ASRC)/image-ps1-v5.$(ARCH).o \
     78$(ASRC)/image-ps1-sim.$(ARCH).o \
    7179$(ASRC)/image-ps1-ref.$(ARCH).o \
    7280$(ASRC)/regimage.$(ARCH).o \
     
    98106
    99107AINCS = \
    100 $(AINC)/coords.h \
     108$(AINC)/coords-disk.h \
     109$(AINC)/AstromOffsetMap_Disk.h \
    101110$(AINC)/average.h \
    102111$(AINC)/average-loneos.h \
     
    111120$(AINC)/average-ps1-v4.h \
    112121$(AINC)/average-ps1-v5.h \
     122$(AINC)/average-ps1-sim.h \
    113123$(AINC)/average-ps1-ref.h \
    114124$(AINC)/secfilt.h \
     
    124134$(AINC)/secfilt-ps1-v4.h \
    125135$(AINC)/secfilt-ps1-v5.h \
     136$(AINC)/secfilt-ps1-sim.h \
    126137$(AINC)/secfilt-ps1-ref.h \
    127138$(AINC)/measure.h \
     
    137148$(AINC)/measure-ps1-v4.h \
    138149$(AINC)/measure-ps1-v5.h \
     150$(AINC)/measure-ps1-sim.h \
    139151$(AINC)/measure-ps1-ref.h \
    140152$(AINC)/lensing.h \
    141153$(AINC)/lensing-ps1-v5.h \
     154$(AINC)/lensing-ps1-v5-alt.h \
    142155$(AINC)/lensobj.h \
    143156$(AINC)/lensobj-ps1-v5.h \
     157$(AINC)/starpar.h \
     158$(AINC)/starpar-ps1-v5.h \
     159$(AINC)/starpar-ps1-sim.h \
    144160$(AINC)/missing.h \
    145161$(AINC)/photcode.h \
     
    154170$(AINC)/photcode-ps1-v5.h \
    155171$(AINC)/photcode-ps1-ref.h \
    156 $(AINC)/image.h \
    157172$(AINC)/image-loneos.h \
    158173$(AINC)/image-elixir.h \
     
    167182$(AINC)/image-ps1-v4.h \
    168183$(AINC)/image-ps1-v5.h \
     184$(AINC)/image-ps1-sim.h \
    169185$(AINC)/image-ps1-ref.h \
    170186$(AINC)/regimage.h \
  • trunk/Ohana/src/libautocode/def/average-ps1-v5.d

    r37246 r37807  
    4747FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
    4848FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
     49FIELD starparOffset,  OFF_STARPAR, int,             offset to stellar parameter data
    4950FIELD extendOffset,   OFF_EXTEND,  int,             offset to extended object entry
    50 FIELD paramsOffset,   OFF_PARAMS,  int,             offset to stellar parameter data
    5151
    5252FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
     
    5757FIELD projectionID,   PROJECTION_ID, short,         ID of projection for primary skycell
    5858
    59 FIELD dummy,          DUMMY,         int,           unassigned bytes
     59FIELD Nstarpar,       DUMMY,         short,         number of stellar parameter entries
     60FIELD dummy,          DUMMY,         short,         unassigned bytes
    6061
    6162# 'flags' was called 'code' prior to 2009.02.07
  • trunk/Ohana/src/libautocode/def/average.d

    r37246 r37807  
    4747FIELD lensingOffset,  OFF_LENSING, int,             offset to first lensing obs
    4848FIELD lensobjOffset,  OFF_LENSOBJ, int,             offset to mean lensing data
     49FIELD starparOffset,  OFF_STARPAR, int,             offset to stellar parameter data
    4950FIELD extendOffset,   OFF_EXTEND,  int,             offset to extended object entry
    50 FIELD paramsOffset,   OFF_PARAMS,  int,             offset to stellar parameter data
    5151
    5252FIELD refColorBlue,   REF_COLOR_BLUE, float,        color of astrometry ref stars
     
    5757FIELD projectionID,   PROJECTION_ID, short,         ID of projection for primary skycell
    5858
    59 FIELD dummy,          DUMMY,         int,           unassigned bytes
     59FIELD Nstarpar,       DUMMY,         short,         number of stellar parameter entries
     60FIELD dummy,          DUMMY,         short,         unassigned bytes
    6061
    6162# 'flags' was called 'code' prior to 2009.02.07
  • trunk/Ohana/src/libautocode/def/coords.d

    r6454 r37807  
    1717FIELD  pc2_2,            PC2_2,                float,            rotation matrix
    1818FIELD  polyterms,        POLYTERMS,            float[7][2],      higher order warping terms
    19 FIELD  ctype,            CTYPE,                char[15],      coordinate type
     19FIELD  ctype,            CTYPE,                char[15],         coordinate type
    2020FIELD  Npolyterms,       NPOLYTERMS,           char,             order of polynomial
     21FIELD  astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
  • trunk/Ohana/src/libautocode/def/image-elixir.d

    r30604 r37807  
    66# elements of the image structure
    77
    8 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     8SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    99SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1010SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-loneos.d

    r30604 r37807  
    66# elements of the image structure
    77
    8 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     8SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    99SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1010SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-panstarrs-dev-0.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-panstarrs-dev-1.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-dev-1.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-dev-2.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-dev-3.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-ref.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-v1.d

    r30604 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-v2.d

    r36833 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-v3.d

    r36833 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-v4.d

    r36833 r37807  
    77# elements of the image structure
    88
    9 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     9SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1010SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1111SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image-ps1-v5.d

    r37034 r37807  
    88# careful of 8-byte boundaries
    99
    10 SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
     10SUBSTRUCT coords,           COORDS,               CoordsDisk,    astrometric data
    1111SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
    1212SUBFIELD  crval2,           CRVAL2,               double,        coordinate at reference pixel
  • trunk/Ohana/src/libautocode/def/image.d

    r37034 r37807  
    22EXTNAME      DVO_IMAGE
    33TYPE         BINTABLE
    4 SIZE         360
     4SIZE         384
    55DESCRIPTION  DVO Image Table
    66
     
    88# careful of 8-byte boundaries
    99
     10# Coords is an internal structure defined in def/common.h
    1011SUBSTRUCT coords,           COORDS,               Coords,        astrometric data
    1112SUBFIELD  crval1,           CRVAL1,               double,        coordinate at reference pixel
     
    2223SUBFIELD  ctype,            CTYPE,                char[15],      coordinate type
    2324SUBFIELD  Npolyterms,       NPOLYTERMS,           char,          order of polynomial
    24 # 120 bytes
     25SUBFIELD  mosaic,           MOSAIC,               e_void,        pointer to parent mosaic
     26SUBFIELD  imageMap,         IMAGE_MAP,            e_void,        pointer to image map
     27# 136 bytes
    2528
    2629# change this to a double?
     
    7679FIELD     photom_map_id,    PHOTOM_MAP_ID,        unsigned int,   reference to 2D zero point map
    7780FIELD     astrom_map_id,    ASTROM_MAP_ID,        unsigned int,   reference to 2D astrometry map
     81
     82FIELD    *parent,           PARENT,               e_void,         pointer to parent mosaic (not save to disk)
    7883# nFitPhotom lands on the old location of Mxxxx, which was used to mean nFitPhotom in some cases
    7984
  • trunk/Ohana/src/libautocode/def/lensing-ps1-v5.d

    r37356 r37807  
    3030
    3131FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    3636FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
    37 FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 5
    38 FIELD sF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
    39 FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD  detID,          DET_ID,       unsigned int,   detection ID
  • trunk/Ohana/src/libautocode/def/lensing.d

    r37356 r37807  
    2929FIELD  E2_sh_psf,      E2_SH_PSF,    float,          lensing shear psf stars E2
    3030
    31 FIELD  F_ApR5,       FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
     31FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    36 FIELD  F_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 6
    37 FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 6
    38 FIELD sF_ApR6,       FLUX_STD_R6,    float,          Flux inside r = 6
    39 FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 6
     36FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD   detID,          DET_ID,      int,            detection ID
  • trunk/Ohana/src/libautocode/def/lensobj-ps1-v5.d

    r37356 r37807  
    3030
    3131FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    3636FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
    37 FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 5
    38 FIELD sF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
    39 FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD  gamma,            GAMMA,      float
  • trunk/Ohana/src/libautocode/def/lensobj.d

    r37356 r37807  
    2929FIELD  E2_sh_psf,      E2_SH_PSF,    float,          mean lensing shear psf stars E2
    3030
    31 FIELD     F_ApR5,    FLUX_AP_R5,     float,          Flux inside r = 5
    32 FIELD    dF_ApR5,    FLUX_ERR_AP_R5, float,          Flux inside r = 5
    33 FIELD    sF_ApR5,    FLUX_STD_AP_R5, float,          Flux inside r = 5
    34 FIELD    fF_ApR5,    FLUX_FIL_AP_R5, float,          Flux inside r = 5
     31FIELD F_ApR5,        FLUX_AP_R5,     float,          Flux inside r = 5
     32FIELD dF_ApR5,       FLUX_ERR_AP_R5, float,          error on Flux inside r = 5
     33FIELD sF_ApR5,       FLUX_STD_AP_R5, float,          stdev of Flux inside r = 5
     34FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          fill factor for Flux inside r = 5
    3535
    36 FIELD     F_ApR6,    FLUX_AP_R6,     float,          Flux inside r = 5
    37 FIELD    dF_ApR6,    FLUX_ERR_AP_R6, float,          Flux inside r = 5
    38 FIELD    sF_ApR6,    FLUX_AP_R6,     float,          Flux inside r = 5
    39 FIELD    fF_ApR6,    FLUX_AP_R6,     float,          Flux inside r = 5
     36FIELD F_ApR6,        FLUX_AP_R6,     float,          Flux inside r = 5
     37FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          error on Flux inside r = 5
     38FIELD sF_ApR6,       FLUX_STD_AP_R6, float,          stdev of Flux inside r = 5
     39FIELD fF_ApR6,       FLUX_FIL_AP_R6, float,          fill factor for Flux inside r = 5
    4040
    4141FIELD      gamma,        GAMMA,      float
  • trunk/Ohana/src/libautocode/doc/autocode.txt

    r21508 r37807  
    3535
    3636- the element name
     37- the element FITS field (in FITS table)
    3738- the element data type
    3839- the element description
    3940- the element physical unit
     41
     42SUBFIELD / SUBSTRUCT keywords allows the user to define elements of a
     43structure which are themselves structures.  These fields are used as
     44follow:
     45
     46Binary / ASCII FITS tables write out the SUBFIELD entries as if they
     47were regular table rows (substructure distinction not visible in FITS
     48table).  SUBSTRUCT rows are NOT added to the FITS table.
     49
     50In a C-structure, the SUBFIELD rows are skipped and only the SUBSTRUCT
     51row is saved.  The definition of the substructure is assumed to be
     52defined elsewhere in the C code.
    4053
    4154Template File
     
    4356The template file is a source code in whatever language is desired.
    4457Within the template, the defined keywords may be used as desired,
    45 wherever needed.  In addition, there are special directives which
    46 invoke additional special behavior.  All special directives have the
    47 form of comments within their target language.  They are replaced with
    48 a block of code in that target language, normally one which iterates
    49 over the FIELD elements of the schema file.  As such, the directive
    50 appropriate for one language should not be used within code for a
    51 different language.  Here is a list of existing special directives:
     58wherever needed. 
     59
     60In addition, there are special directives which invoke additional
     61special behavior.  All special directives have the form of comments
     62within their target language.  They are replaced with a block of code
     63in that target language, normally one which iterates over the FIELD
     64elements of the schema file.  As such, the directive appropriate for
     65one language should not be used within code for a different language.
     66Here is a list of existing special directives:
    5267
    5368/** STRUCT DEFINITION **/
  • trunk/Ohana/src/libautocode/generate

    r26384 r37807  
    144144        if ($type eq "e_time")        { $pt1 = "J"; }
    145145        if ($type eq "e_void")        { $pt1 = "B"; $Np = 8*$Np; }
     146        # if ($type eq "Image")               { $pt1 = "B"; $Np = 8*$Np; }
    146147        # e_void is a 64 bit pointer, cast to size_t.  its value is not loaded
    147148        # from the table.
     
    248249        if ($type eq "e_time")        { $pt1 = sprintf "I%s", $length; }
    249250        if ($type eq "e_void")        { $pt1 = sprintf "I%s", $length; }
     251        # if ($type eq "Image")               { $pt1 = sprintf "I%s", $length; }
    250252
    251253        if (!$pt1) { die "unknown type $type"; }
     
    331333        if ($type eq "e_time")        { $T = "WORD"; $n = 4; }
    332334        if ($type eq "e_void")        { $T = "DBLE"; $n = 8; }
     335        # if ($type eq "Image")               { $T = "DBLE"; $n = 8; }
    333336
    334337        if (!$n) { die "unknown type $type"; }
     
    375378        if ($type eq "e_time")         { $Nbytes += 4*$Np; $valid = 1; }
    376379        if ($type eq "e_void")         { $Nbytes += 8*$Np; $valid = 1; }
     380        # if ($type eq "Image")                { $Nbytes += 8*$Np; $valid = 1; }
    377381        if (!$valid) { die "unknown type $type"; }
    378382    }
  • trunk/Ohana/src/libdvo/Makefile

    r37729 r37807  
    3838$(DESTINC)/ps1_v5_defs.h \
    3939$(DESTINC)/ps1_ref_defs.h \
     40$(DESTINC)/ps1_sim_defs.h \
    4041$(DESTINC)/cmf-ps1-dv3.h \
    4142$(DESTINC)/cmf-ps1-v5.h \
     
    5051$(SRC)/version.$(ARCH).o         \
    5152$(SRC)/coordops.$(ARCH).o        \
     53$(SRC)/galaxy_model.$(ARCH).o    \
    5254$(SRC)/dvosorts.$(ARCH).o        \
    5355$(SRC)/dvo_photcode_ops.$(ARCH).o \
     
    8486$(SRC)/dvo_convert_PS1_V5.$(ARCH).o \
    8587$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
     88$(SRC)/dvo_convert_PS1_SIM.$(ARCH).o \
    8689$(SRC)/flatcorr_io.$(ARCH).o    \
    8790$(SRC)/skyregion_io.$(ARCH).o    \
    8891$(SRC)/skyregion_gsc.$(ARCH).o    \
    8992$(SRC)/skyregion_ops.$(ARCH).o \
     93$(SRC)/AstromOffsetMapIO.$(ARCH).o    \
     94$(SRC)/AstromOffsetMapOps.$(ARCH).o \
     95$(SRC)/AstromOffsetMapUtils.$(ARCH).o \
    9096$(SRC)/dvo_set_skyregion.$(ARCH).o \
    9197$(SRC)/dvo_set_catdir.$(ARCH).o \
  • trunk/Ohana/src/libdvo/include/dvo.h

    r37729 r37807  
    2424  DVO_FORMAT_PS1_DEV_3,
    2525  DVO_FORMAT_PS1_REF,
     26  DVO_FORMAT_PS1_SIM,
    2627  DVO_FORMAT_PS1_V1,
    2728  DVO_FORMAT_PS1_V2,
     
    3637
    3738typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
    38 
    39 typedef enum {
    40   PROJ_NONE, // undefined
    41   PROJ_ZEA, // zenithal
    42   PROJ_ZPL, // zenithal
    43   PROJ_ARC, // zenithal
    44   PROJ_STG, // zenithal
    45   PROJ_SIN, // zenithal
    46   PROJ_TAN, // zenithal
    47   PROJ_TNX, // zenithal
    48   PROJ_DIS, // zenithal (TAN + polyterms)
    49   PROJ_LIN, // cartesian
    50   PROJ_PLY, // cartesian
    51   PROJ_WRP, // cartesian
    52   PROJ_AIT, // pseudocyl
    53   PROJ_GLS, // pseudocyl
    54   PROJ_PAR, // pseudocyl
    55 } OhanaProjection;
    56 
    57 typedef enum {
    58   PROJ_MODE_NONE,
    59   PROJ_MODE_CARTESIAN,
    60   PROJ_MODE_ZENITHAL,
    61   PROJ_MODE_PSEUDOCYL,
    62 } OhanaProjectionMode;
    6339
    6440// these are used as NAN for types of int values
     
    7955
    8056/* catalog values to be loaded */
    81 # define LOAD_NONE      0x000
    82 # define LOAD_AVES      0x001
    83 # define LOAD_MEAS      0x002
    84 # define LOAD_MISS      0x004
    85 # define LOAD_SECF      0x008
    86 # define SKIP_AVES      0x010
    87 # define SKIP_MEAS      0x020
    88 # define SKIP_MISS      0x040
    89 # define SKIP_SECF      0x080
    90 # define LOAD_LENSING   0x100
    91 # define LOAD_LENSOBJ   0x200
    92 # define SKIP_LENSING   0x400
    93 # define SKIP_LENSOBJ   0x800
     57# define LOAD_NONE      0x0000
     58# define LOAD_AVES      0x0001
     59# define LOAD_MEAS      0x0002
     60# define LOAD_MISS      0x0004
     61# define LOAD_SECF      0x0008
     62# define SKIP_AVES      0x0010
     63# define SKIP_MEAS      0x0020
     64# define SKIP_MISS      0x0040
     65# define SKIP_SECF      0x0080
     66# define LOAD_LENSING   0x0100
     67# define LOAD_LENSOBJ   0x0200
     68# define SKIP_LENSING   0x0400
     69# define SKIP_LENSOBJ   0x0800
     70# define LOAD_STARPAR   0x1000
     71# define SKIP_STARPAR   0x2000
    9472
    9573/* photometry code types */
     
    11492  ID_IMAGE_ASTROM_FEW     = 0x00000100,  /* currently too few measurements for astrometry */
    11593  ID_IMAGE_PHOTOM_UBERCAL = 0x00000200,  /* externally-supplied photometry zero point from ubercal analysis */
     94  ID_IMAGE_ASTROM_GMM     = 0x00000400,  /* image was fitted to positions corrected by the galaxy motion model */
    11695} DVOImageFlags;
    11796
     
    136115  ID_MEAS_STACK_PRIMARY  = 0x00010000,  // this stack measurement is in the primary skycell
    137116  ID_MEAS_STACK_PHOT_SRC = 0x00020000,  // this measurement supplied the stack photometry
     117  ID_MEAS_ICRF_QSO       = 0x00040000,  // this measurement is an ICRF reference position
     118  ID_MEAS_IMAGE_EPOCH    = 0x00080000,  // this measurement is registered to the image epoch (not tied to ref catalog epoch)
    138119} DVOMeasureFlags;
    139120
     
    152133*/
    153134
     135/** these names were previously used for Average flags in old (LONEOS-era) dvo versions
     136  ID_BAD_OBJECT        = 0x00004000, // if all measurements are bad, set this bit
     137  ID_MOVING            = 0x00008000, // is a moving object
     138  ID_ROCK              = 0x0000a000, // 0x8000 + 0x2000
     139  ID_GHOST             = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
     140  ID_TRAIL             = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
     141  ID_BLEED             = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
     142  ID_COSMIC            = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
     143**/
     144
    154145/* Average.flags values -- these values are 32 bit (as of PS1_V1) */
    155146typedef enum {
    156   ID_STAR_FEW       = 0x00000001, // used within relphot: skip star
    157   ID_STAR_POOR      = 0x00000002, // used within relphot: skip star
    158   ID_PROPER         = 0x00000400, // star with large proper motion
    159   ID_TRANSIENT      = 0x00001000, // is this mutually exclusive with USNO?
    160   ID_VARIABLE       = 0x00002000, // not currently set?
    161   ID_ASTEROID       = 0x00002000, // identified with an asteroid
    162   ID_BAD_OBJECT     = 0x00004000, // if all measurements are bad, set this bit
    163   ID_MOVING         = 0x00008000, // is a moving object
    164   ID_ROCK           = 0x0000a000, // 0x8000 + 0x2000
    165   ID_GHOST          = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
    166   ID_TRAIL          = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
    167   ID_BLEED          = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
    168   ID_COSMIC         = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
    169   ID_STAR_FIT_AVE   = 0x00010000, // average position fitted
    170   ID_STAR_FIT_PM    = 0x00020000, // proper motion fitted
    171   ID_STAR_FIT_PAR   = 0x00040000, // parallax fitted
    172   ID_STAR_USE_AVE   = 0x00080000, // average position used (not PM or PAR)
    173   ID_STAR_USE_PM    = 0x00100000, // proper motion used (not AVE or PAR)
    174   ID_STAR_USE_PAR   = 0x00200000, // parallax used (not AVE or PM)
    175   ID_STAR_NO_ASTROM = 0x00400000, // mean astrometry could not be measured
    176   ID_STAR_BAD_PM    = 0x00800000, // mean astrometry could not be measured
    177   ID_OBJ_EXT        = 0x01000000, // extended in our data (eg, PS)
    178   ID_OBJ_EXT_ALT    = 0x02000000, // extended in external data (eg, 2MASS)
    179   ID_OBJ_GOOD       = 0x04000000, // good-quality measurement in our data (eg,PS)
    180   ID_OBJ_GOOD_ALT   = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
    181   ID_OBJ_GOOD_STACK = 0x10000000, // good-quality object in the stack (> 1 good stack)
     147  ID_STAR_FEW          = 0x00000001, // used within relphot: skip star
     148  ID_STAR_POOR         = 0x00000002, // used within relphot: skip star
     149  ID_ICRF_QSO          = 0x00000004, // object IDed with known ICRF quasar (may have ICRF position measurement)
     150  ID_OTHEF_QSO         = 0x00000008, // object IDed with known or suspected quasar, without ICRF reference data
     151  ID_PROPER            = 0x00000010, // star with large proper motion
     152  ID_TRANSIENT         = 0x00000020, // identified as a non-periodic (stationary) transient
     153  ID_VARIABLE          = 0x00000040, // identified as a period variable
     154  ID_ASTEROID          = 0x00000080, // identified with a known solar-system object (asteroid or other)
     155  // bits 0x00000100 - 0x00008000 are currently unused
     156  ID_STAR_FIT_AVE      = 0x00010000, // average position fitted
     157  ID_STAR_FIT_PM       = 0x00020000, // proper motion fitted
     158  ID_STAR_FIT_PAR      = 0x00040000, // parallax fitted
     159  ID_STAR_USE_AVE      = 0x00080000, // average position used (not PM or PAR)
     160  ID_STAR_USE_PM       = 0x00100000, // proper motion used (not AVE or PAR)
     161  ID_STAR_USE_PAR      = 0x00200000, // parallax used (not AVE or PM)
     162  ID_STAR_NO_ASTROM    = 0x00400000, // mean astrometry could not be measured
     163  ID_STAR_BAD_PM       = 0x00800000, // mean astrometry could not be measured
     164  ID_OBJ_EXT           = 0x01000000, // extended in our data (eg, PS)
     165  ID_OBJ_EXT_ALT       = 0x02000000, // extended in external data (eg, 2MASS)
     166  ID_OBJ_GOOD          = 0x04000000, // good-quality measurement in our data (eg,PS)
     167  ID_OBJ_GOOD_ALT      = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
     168  ID_OBJ_GOOD_STACK    = 0x10000000, // good-quality object in the stack (> 1 good stack)
    182169  ID_OBJ_SUSPECT_STACK = 0x20000000, // suspect object in the stack (> 1 good or suspect stack, < 2 good)
    183   ID_OBJ_BAD_STACK  = 0x40000000, // good-quality object in the stack (> 1 good stack)
     170  ID_OBJ_BAD_STACK     = 0x40000000, // good-quality object in the stack (> 1 good stack)
    184171} DVOAverageFlags;
    185172
     
    202189} DVOSecfiltFlags;
    203190
     191/* definitions for parallel dvo host information
     192   XXX : need better names (safer namespace)
     193*/
     194
     195typedef enum {
     196  DATA_ON_TGT  = 0x01,
     197  DATA_ON_BCK  = 0x02,
     198  DATA_USE_BCK = 0x04,
     199
     200  DATA_COPY_FAILURE = 0x80,
     201} SkyTableDataFlags;
     202
     203typedef enum {
     204  HOST_STDIN = 0,
     205  HOST_STDOUT = 1,
     206  HOST_STDERR = 2,
     207} HostInfoIOfd;
     208
    204209/*** general dvo structures (internal use only / not IO) ***/
    205210
     
    253258} FlatCorrectionTable;
    254259
    255 /* definitions for parallel dvo host information
    256    XXX : need better names (safer namespace)
    257 */
    258 
    259 typedef enum {
    260   DATA_ON_TGT  = 0x01,
    261   DATA_ON_BCK  = 0x02,
    262   DATA_USE_BCK = 0x04,
    263 
    264   DATA_COPY_FAILURE = 0x80,
    265 } SkyTableDataFlags;
    266 
    267 typedef enum {
    268   HOST_STDIN = 0,
    269   HOST_STDOUT = 1,
    270   HOST_STDERR = 2,
    271 } HostInfoIOfd;
    272 
    273260typedef struct {
    274261  char *hostname;             // name of remote machine
     
    289276} HostTable;
    290277
     278typedef struct {
     279  int Nhosts;
     280  HostInfo **hosts;
     281} HostTableGroup;
     282
    291283// A RegionHost processes data for some region in parallel with other regions
    292284typedef struct RegionHostInfo {
     
    314306  Image *image;
    315307  off_t *imseq;
     308
     309  AstromOffsetTable *astromTable;
    316310
    317311  int *neighbors;             // list of neighbor index values
     
    444438  double         R;
    445439  double         D;
     440  float          RoffGAL;
     441  float          DoffGAL;
    446442  float          M;
    447443  float          Mcal;
     
    645641  int              lensobjOffset;        // offset to mean lensing data
    646642  int              extendOffset;         // offset to extended object entry
    647   int              paramsOffset;         // offset to stellar parameter data
     643  int              starparOffset;        // offset to stellar parameter data
    648644  float            refColorBlue;         // color of astrometry ref stars
    649645  float            refColorRed;          // color of astrometry ref stars
     
    679675  Lensing *lensing;
    680676  Lensobj *lensobj;
     677  StarPar *starpar;
    681678
    682679  int Nsecfilt;  /* number of secfilt entries for each average entry */
    683   off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nsecf_mem;  /* current number of each component in memory */
    684   off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nsecf_disk; /* current number of each component on disk */
    685   off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nsecf_off;  /* index of first loaded data value */
     680  off_t Naverage,   Nmeasure,   Nmissing,   Nlensing,      Nlensobj,      Nstarpar,      Nsecf_mem;  /* current number of each component in memory */
     681  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nlensing_disk, Nlensobj_disk, Nstarpar_disk, Nsecf_disk; /* current number of each component on disk */
     682  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nlensing_off,  Nlensobj_off,  Nstarpar_off,  Nsecf_off;  /* index of first loaded data value */
    686683
    687684  // note that we use these for the full-sky relphot analysis
     
    704701  struct Catalog *lensing_catalog;              /* lensing catalog data (split) */
    705702  struct Catalog *lensobj_catalog;              /* lensobj catalog data (split) */
     703  struct Catalog *starpar_catalog;              /* starpar catalog data (split) */
    706704
    707705  unsigned int objID;
     
    739737int   gfits_db_close               PROTO((FITS_DB *db));
    740738int   gfits_db_free                PROTO((FITS_DB *db));
    741 
    742 /* in coords.c, using libautocode/def/coords.d */
    743 int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
    744 int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
    745 int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
    746 int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
    747 int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
    748 int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
    749 int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
    750 int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
    751 int  GetCoords (Coords *coords, Header *header);
    752 int  PutCoords (Coords *coords, Header *header);
    753 void RegisterMosaic (Coords *coords);
    754 void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
    755 OhanaProjection GetProjection (char *ctype);
    756 int SetProjection (char *ctype, OhanaProjection proj);
    757 OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
    758739
    759740char *libdvo_version (void);
     
    913894Lensing *FtableToLensing (FTable *ftable, off_t *Nlensing, char *format);
    914895Lensobj *FtableToLensobj (FTable *ftable, off_t *Nlensobj, char *format);
     896StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format);
    915897int      FtableToImage   (FTable *ftable, Header *theader, char *format);
    916898
     
    920902int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, char format);
    921903int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, char format);
     904int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format);
    922905int ImageToFtable (FTable *ftable, Header *theader, char format);
    923906int ImageToVtable (VTable *vtable, Header *theader, char format);
     
    936919# include "ps1_v5_defs.h"
    937920# include "ps1_ref_defs.h"
     921# include "ps1_sim_defs.h"
    938922
    939923/*** DVO image db I/O Functions ***/
     
    950934void dvo_image_create (FITS_DB *db, double ZeroPoint);
    951935
     936int gfits_table_set_Image (FTable *ftable);
     937int gfits_table_mkheader_Image (Header *header);
     938Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped);
     939
    952940/* flatcorr APIs */
    953941FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE);
     
    963951SkyTable  *SkyTableLoadOptimal     PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int readwrite, int depth, int VERBOSE));
    964952int        SkyTableSetDepth        PROTO((SkyTable *sky, int depth));
     953SkyList   *SkyRegionByIndex        PROTO((SkyTable *table, int index));
    965954SkyList   *SkyRegionByCPT          PROTO((SkyTable *table, char *filename));
    966955SkyList   *SkyRegionByPoint        PROTO((SkyTable *table, int depth, double ra, double dec));
     
    1009998int HostTableTestHost (SkyRegion *region, int hostID);
    1010999
     1000void InitHost (HostInfo *host);
     1001
     1002HostTableGroup *HostTableGroups (HostTable *table, int *ngroups);
     1003int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE);
     1004
    10111005// functions to support tiny versions of Average and Measure
    10121006void CopyAverageToTiny (AverageTiny *averageT, Average *average);
     
    10421036void dvo_lensing_init (Lensing *lensing);
    10431037void dvo_lensobj_init (Lensobj *lensobj, int toZero);
     1038void dvo_starpar_init (StarPar *starpar);
    10441039
    10451040void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
     
    10511046int RegionHostFindNeighbors (RegionHostTable *table, int Nhost);
    10521047
     1048// galaxy_model:
     1049int TransformProperMotion_radians (double *uR, double *uD, double uL, double uB, double Rrad, double Drad, CoordTransform *transform);
     1050int TransformProperMotion (double *uR, double *uD, double uL, double uB, double R, double D, CoordTransform *transform);
     1051int SolarMotionModel_radians (double *uL_sol, double *uB_sol, double Lrad, double Brad, double distance);
     1052int SolarMotionModel (double *uL_sol, double *uB_sol, double L, double B, double distance);
     1053int GalaxyMotionModel_radians (double *uL_gal, double *uB_gal, double Lrad, double Brad);
     1054int GalaxyMotionModel (double *uL_gal, double *uB_gal, double L, double B);
     1055int InitGalaxyModel (char *version);
     1056
     1057# define LENSFIELD(NAME) float LensValue_##NAME (PhotCode *code, Lensobj *lensobj);
     1058
     1059LENSFIELD(X11_sm_obj)
     1060LENSFIELD(X12_sm_obj)
     1061LENSFIELD(X22_sm_obj)
     1062LENSFIELD(E1_sm_obj)
     1063LENSFIELD(E2_sm_obj)
     1064
     1065LENSFIELD(X11_sh_obj)
     1066LENSFIELD(X12_sh_obj)
     1067LENSFIELD(X22_sh_obj)
     1068LENSFIELD(E1_sh_obj)
     1069LENSFIELD(E2_sh_obj)
     1070
     1071LENSFIELD(X11_sm_psf)
     1072LENSFIELD(X12_sm_psf)
     1073LENSFIELD(X22_sm_psf)
     1074LENSFIELD(E1_sm_psf)
     1075LENSFIELD(E2_sm_psf)
     1076
     1077LENSFIELD(X11_sh_psf)
     1078LENSFIELD(X12_sh_psf)
     1079LENSFIELD(X22_sh_psf)
     1080LENSFIELD(E1_sh_psf)
     1081LENSFIELD(E2_sh_psf)
     1082
     1083# undef LENSFIELD
     1084
    10531085# endif // DVO_H
  • trunk/Ohana/src/libdvo/include/dvodb.h

    r37116 r37807  
    5555  MAG_OPTION_UC_DIST,
    5656  MAG_OPTION_FLAGS,
     57
     58  MAG_OPTION_X11_SM_OBJ,
     59  MAG_OPTION_X12_SM_OBJ,
     60  MAG_OPTION_X22_SM_OBJ,
     61  MAG_OPTION_E1_SM_OBJ,
     62  MAG_OPTION_E2_SM_OBJ,
     63
     64  MAG_OPTION_X11_SH_OBJ,
     65  MAG_OPTION_X12_SH_OBJ,
     66  MAG_OPTION_X22_SH_OBJ,
     67  MAG_OPTION_E1_SH_OBJ,
     68  MAG_OPTION_E2_SH_OBJ,
     69
     70  MAG_OPTION_X11_SM_PSF,
     71  MAG_OPTION_X12_SM_PSF,
     72  MAG_OPTION_X22_SM_PSF,
     73  MAG_OPTION_E1_SM_PSF,
     74  MAG_OPTION_E2_SM_PSF,
     75
     76  MAG_OPTION_X11_SH_PSF,
     77  MAG_OPTION_X12_SH_PSF,
     78  MAG_OPTION_X22_SH_PSF,
     79  MAG_OPTION_E1_SH_PSF,
     80  MAG_OPTION_E2_SH_PSF,
     81
     82  MAG_OPTION_F_AP_R5,
     83  MAG_OPTION_F_ERR_AP_R5,
     84  MAG_OPTION_F_STDEV_AP_R5,
     85  MAG_OPTION_F_FILL_AP_R5,
     86
     87  MAG_OPTION_F_AP_R6,
     88  MAG_OPTION_F_ERR_AP_R6,
     89  MAG_OPTION_F_STDEV_AP_R6,
     90  MAG_OPTION_F_FILL_AP_R6,
    5791} dvoMagOptionType;
    5892
     
    139173      MEAS_XFIX,
    140174      MEAS_YFIX,
     175      MEAS_XOFF_KH,
     176      MEAS_YOFF_KH,
     177      MEAS_XOFF_DCR,
     178      MEAS_YOFF_DCR,
     179      MEAS_ROFF_GAL,
     180      MEAS_DOFF_GAL,
    141181      MEAS_POS_SYS_ERR,
    142182      MEAS_XFIELD,
     
    162202      MEAS_FLAT,
    163203      MEAS_CENTER_OFFSET,
    164       MEAS_REF_COLOR,
     204      MEAS_REF_COLOR_BLUE,
     205      MEAS_REF_COLOR_RED,
     206      MEAS_X11_SM_OBJ,
     207      MEAS_X12_SM_OBJ,
     208      MEAS_X22_SM_OBJ,
     209      MEAS_E1_SM_OBJ,
     210      MEAS_E2_SM_OBJ,
     211      MEAS_X11_SH_OBJ,
     212      MEAS_X12_SH_OBJ,
     213      MEAS_X22_SH_OBJ,
     214      MEAS_E1_SH_OBJ,
     215      MEAS_E2_SH_OBJ,
     216      MEAS_X11_SM_PSF,
     217      MEAS_X12_SM_PSF,
     218      MEAS_X22_SM_PSF,
     219      MEAS_E1_SM_PSF,
     220      MEAS_E2_SM_PSF,
     221      MEAS_X11_SH_PSF,
     222      MEAS_X12_SH_PSF,
     223      MEAS_X22_SH_PSF,
     224      MEAS_E1_SH_PSF,
     225      MEAS_E2_SH_PSF,
     226      MEAS_E_BV,                      // extinction (mags)
     227      MEAS_E_BV_ERR,
     228      MEAS_DISTANCE_MOD, // distance modulus (mags)
     229      MEAS_DISTANCE_MOD_ERR,
     230      MEAS_M_R,               // absolute mag in r-band
     231      MEAS_M_R_ERR,
     232      MEAS_FEH,               // metallicity
     233      MEAS_FEH_ERR,
     234      MEAS_URA_GALMODEL,      // model pm prediction
     235      MEAS_UDEC_GALMODEL,     // model pm prediction
     236      MEAS_RA_GALMODEL,      // model pm prediction
     237      MEAS_DEC_GALMODEL,     // model pm prediction
    165238};
    166239
     
    200273      AVE_EXTID_HI,
    201274      AVE_EXTID_LO,
    202       AVE_REF_COLOR,
     275      AVE_REF_COLOR_BLUE,
     276      AVE_REF_COLOR_RED,
    203277      AVE_PHOT, // photometry class of values
     278      AVE_E_BV,               // extinction (mags)
     279      AVE_E_BV_ERR,
     280      AVE_DISTANCE_MOD, // distance modulus (mags)
     281      AVE_DISTANCE_MOD_ERR,
     282      AVE_M_R,                // absolute mag in r-band
     283      AVE_M_R_ERR,
     284      AVE_FEH,                // metallicity
     285      AVE_FEH_ERR,
     286      AVE_URA_GALMODEL,      // model pm prediction
     287      AVE_UDEC_GALMODEL,     // model pm prediction
     288      AVE_RA_GALMODEL,      // model pm prediction
     289      AVE_DEC_GALMODEL,     // model pm prediction
    204290};
    205291
     
    276362      IMAGE_NLINK_PHOTOM,
    277363      IMAGE_NLINK_ASTROM,
    278       IMAGE_REF_COLOR
     364      IMAGE_REF_COLOR_BLUE,
     365      IMAGE_REF_COLOR_RED
    279366};
    280367
     
    368455int          ParseImageField        PROTO((dbField *field, char *fieldName));
    369456
    370 dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
    371 dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
     457dbValue      dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, Lensobj *lensobj, StarPar *starpar, dbField *field));
     458dbValue      dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, Lensing *lensing, StarPar *starpar, dbField *field));
    372459dbValue      dbExtractImages        PROTO((Image *image, off_t Nimage, off_t N, dbField *field));
    373460
     
    376463int          dbAstroRegionLimits    PROTO((dbStack **stack, int *nstack, SkyRegionSelection *selection, int table));
    377464char        *strfloat               PROTO((float value));
     465
     466int dbFieldNeedMeasure (dbField *fields, int Nfields);
     467int dbFieldNeedLensobj (dbField *fields, int Nfields);
     468int dbFieldNeedLensing (dbField *fields, int Nfields);
     469int dbFieldNeedStarpar (dbField *fields, int Nfields, int isAverage);
    378470
    379471void FreeImageSelection (void);
  • trunk/Ohana/src/libdvo/include/libdvo_astro.h

    r31635 r37807  
    1 #ifdef notdef
    2 # include "external.h"
    3 # include "shell.h"
    4 # include "dvomath.h"
    5 # include "convert.h"
    6 # include "display.h"
    7 # include "data.h"
    8 #endif
     1# ifndef LIBDVO_ASTRO_H
     2# define LIBDVO_ASTRO_H
    93
    10 # ifndef ASTRO_H
    11 # define ASTRO_H
     4typedef enum {
     5  COORD_NONE,
     6  COORD_CELESTIAL,
     7  COORD_GALACTIC, // based on Liu et al 2011
     8  COORD_ECLIPTIC,
     9  COORD_GALACTIC_REID_2004, // an older definition of the galactic plane
     10} CoordTransformSystem;
    1211
    13 void InitAstro (void);
    14 void FreeAstro (void);
     12typedef enum {
     13  PROJ_NONE, // undefined
     14  PROJ_ZEA, // zenithal
     15  PROJ_ZPL, // zenithal
     16  PROJ_ARC, // zenithal
     17  PROJ_STG, // zenithal
     18  PROJ_SIN, // zenithal
     19  PROJ_TAN, // zenithal
     20  PROJ_TNX, // zenithal
     21  PROJ_DIS, // zenithal (TAN + polyterms)
     22  PROJ_LIN, // cartesian
     23  PROJ_PLY, // cartesian (allow polyterms)
     24  PROJ_WRP, // cartesian (allow polyterms, require mosaic)
     25  PROJ_AIT, // pseudocyl
     26  PROJ_GLS, // pseudocyl
     27  PROJ_PAR, // pseudocyl
     28} OhanaProjection;
     29
     30typedef enum {
     31  PROJ_MODE_NONE,
     32  PROJ_MODE_CARTESIAN,
     33  PROJ_MODE_ZENITHAL,
     34  PROJ_MODE_PSEUDOCYL,
     35} OhanaProjectionMode;
    1536
    1637typedef struct {
     
    2950} CoordTransform;
    3051
    31 typedef enum {COORD_NONE, COORD_CELESTIAL, COORD_GALACTIC, COORD_ECLIPTIC} CoordTransformSystem;
     52typedef struct {
     53  int Nx;
     54  int Ny;
     55  float dX;
     56  float dY;
     57  float **dXv;
     58  float **dYv;
     59  unsigned int tableID;
     60  unsigned int imageID;
     61  int keep;
     62} AstromOffsetMap;
     63
     64typedef struct {
     65  int Nmap;
     66  AstromOffsetMap **map;
     67   int *imageIDtoTableSeq;
     68  int MaxImageID;
     69  int MaxTableID;
     70} AstromOffsetTable;
     71
     72/* Internal version of Coords (see CoordsDisk in libautocode/def/coords-disk.d) */
     73typedef struct Coords {
     74  double           crval1;               // coordinate at reference pixel
     75  double           crval2;               // coordinate at reference pixel
     76  float            crpix1;               // coordinate of reference pixel
     77  float            crpix2;               // coordinate of reference pixel
     78  float            cdelt1;               // degrees per pixel
     79  float            cdelt2;               // degrees per pixel
     80  float            pc1_1;                // rotation matrix
     81  float            pc1_2;                // rotation matrix
     82  float            pc2_1;                // rotation matrix
     83  float            pc2_2;                // rotation matrix
     84  float            polyterms[7][2];      // higher order warping terms
     85  char             ctype[15];            // coordinate type
     86  char             Npolyterms;           // order of polynomial
     87  struct Coords   *mosaic;               // pointer to parent mosaic
     88  AstromOffsetMap *offsetMap;            // pointer to offset map transformation
     89} Coords;
     90
     91typedef struct Image {
     92  Coords           coords;               // astrometric data
     93  e_time           tzero;                // readout time (row 0)
     94  unsigned int     nstar;                // number of stars on image
     95  float            secz;                 // airmass (mag)
     96  unsigned short   NX;                   // image width
     97  unsigned short   NY;                   // image height
     98  float            apmifit;              // aperture correction (mag)
     99  float            dapmifit;             // apmifit error (mag)
     100  float            Mcal;                 // calibration mag (mag)
     101  float            dMcal;                // error on Mcal (mag)
     102  short            Xm;                   // image chisq (10*log(value))
     103  short            photcode;             // identifier for CCD,
     104  float            exptime;              // exposure time (seconds)
     105  float            sidtime;              // sidereal time of exposure
     106  float            latitude;             // observatory latitude (degrees)
     107  float            RAo;                  // image center (degrees)
     108  float            DECo;                 // image center (degrees)
     109  float            Radius;               // image radius (degrees)
     110  float            refColorBlue;         // median astrometry ref color
     111  float            refColorRed;          // median astrometry ref color
     112  char             name[117];            // name of original image
     113  unsigned char    detection_limit;      // detection limit (10*mag)
     114  unsigned char    saturation_limit;     // saturation limit (10*mag)
     115  unsigned char    cerror;               // astrometric error (50*arcsec)
     116  unsigned char    fwhm_x;               // PSF x width (25*arcsec)
     117  unsigned char    fwhm_y;               // PSF y width (25*arcsec)
     118  unsigned char    trate;                // scan rate (100 usec/pixel)
     119  unsigned char    ccdnum;               // CCD ID number
     120  unsigned int     flags;                // image quality flags
     121  unsigned int     imageID;              // internal image ID
     122  unsigned int     parentID;             // associated ref image
     123  unsigned int     externID;             // external image ID
     124  unsigned short   sourceID;             // analysis source ID
     125  short            nLinkAstrom;          // mean number of matched measurements for astrometry
     126  short            nLinkPhotom;          // mean number of matched measurements for astrometry
     127  short            ubercalDist;          // distance to nearest ubercal image
     128  float            dXpixSys;             // systematic astrometry error in X
     129  float            dYpixSys;             // systematic astrometry error in Y
     130  float            dMagSys;              // systematic photometry error
     131  unsigned short   nFitAstrom;           // number of stars used for astrometry cal
     132  unsigned short   nFitPhotom;           // number of stars used for photometry cal
     133  unsigned int     photom_map_id;        // reference to 2D zero point map
     134  unsigned int     astrom_map_id;        // reference to 2D astrometry map
     135  struct Image    *parent;               // pointer to parent mosaic (not save to disk)
     136} Image;
    32137
    33138CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output);
    34139int ApplyTransform (double *x, double *y, double X, double Y, CoordTransform *transform);
    35140
     141/* in coords.c */
     142void InitCoords (Coords *coords, char *projection);
     143void CopyCoords (Coords *tgt, Coords *src);
     144
     145int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
     146int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
     147int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
     148int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
     149int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
     150int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
     151int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
     152int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
     153int  GetCoords (Coords *coords, Header *header);
     154int  PutCoords (Coords *coords, Header *header);
     155void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
     156OhanaProjection GetProjection (char *ctype);
     157int SetProjection (char *ctype, OhanaProjection proj);
     158OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
     159
     160/* in AstromOffsetMapIO.c */
     161AstromOffsetTable *AstromOffsetMapLoad (char *filename, int VERBOSE);
     162int AstromOffsetMapSave (AstromOffsetTable *table, char *filename);
     163AstromOffsetTable *AstromOffsetMapToTable(AstromOffsetMap_Disk_6x6 *map_disk, off_t Nmap);
     164AstromOffsetMap_Disk_6x6 *AstromOffsetTableToMap(AstromOffsetTable *table, off_t *Nmap);
     165
     166/* in AstromOffsetMapOps.c */
     167float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir);
     168int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
     169
     170/* in AstromOffsetMapUtils.c */
     171AstromOffsetMap *AstromOffsetMapInit (int Nx, int Ny);
     172void AstromOffsetMapFree (AstromOffsetMap *map);
     173
     174int AstromOffsetTableNewMap (AstromOffsetTable *table, int Nx, int Ny, Image *image);
     175int AstromOffsetTableMatchChips (Image *images, off_t Nimages, AstromOffsetTable *table);
     176AstromOffsetTable *AstromOffsetTableInit();
     177void AstromOffsetTableFree(AstromOffsetTable *table);
     178int AstromOffsetTableAddMapFromImage (AstromOffsetTable *table, Image *image);
     179void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename);
     180int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir);
     181AstromOffsetMap *AstromOffsetMapCopy (AstromOffsetMap *map);
     182void AstromOffsetMapCopyData (AstromOffsetMap *tgt, AstromOffsetMap *src);
     183void AstromOffsetMapSetOrder (AstromOffsetMap *map, int Nx, int Ny, Image *image);
     184
    36185# endif
  • trunk/Ohana/src/libdvo/include/ps1_v5_defs.h

    r37035 r37807  
    99
    1010Lensing                 *Lensing_PS1_V5_ToInternal (Lensing_PS1_V5 *in, off_t Nvalues);
     11Lensing                 *Lensing_PS1_V5_ALT_ToInternal (Lensing_PS1_V5_ALT *in, off_t Nvalues);
    1112Lensing_PS1_V5          *LensingInternalTo_PS1_V5 (Lensing *in, off_t Nvalues);
    1213Lensobj                 *Lensobj_PS1_V5_ToInternal (Lensobj_PS1_V5 *in, off_t Nvalues);
    1314Lensobj_PS1_V5          *LensobjInternalTo_PS1_V5 (Lensobj *in, off_t Nvalues);
    1415
     16StarPar                 *StarPar_PS1_V5_ToInternal (StarPar_PS1_V5 *in, off_t Nvalues);
     17StarPar_PS1_V5          *StarParInternalTo_PS1_V5 (StarPar *in, off_t Nvalues);
     18
    1519PhotCode                *PhotCode_PS1_V5_To_Internal (PhotCode_PS1_V5 *in, off_t Nvalues);
    1620PhotCode_PS1_V5         *PhotCode_Internal_To_PS1_V5 (PhotCode *in, off_t Nvalues);
  • trunk/Ohana/src/libdvo/src/BoundaryTree.c

    r37116 r37807  
    371371int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec) {
    372372
     373  ra = ohana_normalize_angle (ra);
     374
    373375  // first, find the containing zone
    374376
  • trunk/Ohana/src/libdvo/src/HostTable.c

    r35848 r37807  
    33# include <sys/wait.h>
    44
     5void InitHost (HostInfo *host) {
     6  host->hostname = NULL;
     7  host->pathname = NULL;
     8  host->results = NULL;
     9  host->stdio[HOST_STDIN] = -1;
     10  host->stdio[HOST_STDOUT] = -1;
     11  host->stdio[HOST_STDERR] = -1;
     12  host->pid = 0;
     13  return;
     14}
     15
    516void InitHosts (HostInfo *hosts, int Nhosts, int NHOSTS) {
    617
    718  int i;
    819  for (i = Nhosts; i < NHOSTS; i++) {
    9     hosts[i].hostname = NULL;
    10     hosts[i].pathname = NULL;
    11     hosts[i].results = NULL;
    12     hosts[i].stdio[HOST_STDIN] = -1;
    13     hosts[i].stdio[HOST_STDOUT] = -1;
    14     hosts[i].stdio[HOST_STDERR] = -1;
    15     hosts[i].pid = 0;
     20    InitHost (&hosts[i]);
    1621  }
    1722  return;
     
    3641  }
    3742  if (table->index) free (table->index);
     43  free (table);
     44  return;
     45}
     46
     47// a HostTableGroup is a pointer set to one or more HostTable entries
     48void FreeTableGroup (HostTableGroup *table) {
     49
     50  if (!table) return;
     51  if (table->hosts) {
     52    free (table->hosts);
     53  }
    3854  free (table);
    3955  return;
     
    136152  fclose (f);
    137153  return table;
     154}
     155
     156// split a host table into Ngroups, each with a unique set of hosts
     157HostTableGroup *HostTableGroups (HostTable *table, int *ngroups) {
     158
     159  // identify the unique host names and the number of times they each exist
     160  // (Host tables are not very large; I can afford to do this in an inefficient way)
     161  int i, j, k;
     162
     163  int Nunique = 0;
     164  char **unique_hosts = NULL; // an array of pointers to a set of the names
     165  int  *Nunique_hosts = NULL; // an array of pointers to the count of each
     166  ALLOCATE ( unique_hosts, char *, table->Nhosts);
     167  ALLOCATE (Nunique_hosts, int, table->Nhosts);
     168  for (i = 0; i < table->Nhosts; i++) Nunique_hosts[i] = 0;
     169
     170  for (i = 0; i < table->Nhosts; i++) {
     171    int found = FALSE;
     172    for (j = 0; !found && (j < Nunique); j++) {
     173      if (!strcmp(table->hosts[i].hostname, unique_hosts[j])) {
     174        Nunique_hosts[j] ++;
     175        found = TRUE;
     176      }
     177    }
     178    if (!found) {
     179      unique_hosts[Nunique] = table->hosts[i].hostname;
     180      Nunique_hosts[Nunique] = 1;
     181      Nunique ++;
     182    }
     183  }
     184
     185  int Ngroups = 0;
     186  for (i = 0; i < Nunique; i++) {
     187    Ngroups = MAX (Nunique_hosts[i], Ngroups);
     188  }
     189
     190  HostTableGroup *groups = NULL;
     191  int *foundHost = NULL;
     192 
     193  ALLOCATE (foundHost, int, table->Nhosts);
     194  ALLOCATE (groups, HostTableGroup, Ngroups);
     195
     196  for (i = 0; i < table->Nhosts; i++) foundHost[i] = FALSE;
     197
     198  // in each group, attempt to add one of each unique host
     199  for (i = 0; i < Ngroups; i++) {
     200    groups[i].Nhosts = 0;
     201    ALLOCATE (groups[i].hosts, HostInfo *, Nunique);
     202    for (j = 0; j < Nunique; j++) {
     203      int found = FALSE;
     204      for (k = 0; !found && (k < table->Nhosts); k++) {
     205        if (foundHost[k]) continue;
     206        if (strcmp(unique_hosts[j], table->hosts[k].hostname)) continue;
     207        groups[i].hosts[groups[i].Nhosts] = &table->hosts[k];
     208        groups[i].Nhosts ++;
     209        found = TRUE;
     210        foundHost[k] = TRUE;
     211      }
     212    }
     213  }
     214  *ngroups = Ngroups;
     215  return groups;
    138216}
    139217
     
    255333
    256334  // this loop has 2 chunks: (a) check for I/O + (b) check for jobs done
    257   while (1) {
     335  while (Nfound < Nrunning) {
    258336
    259337    // Wait up to 0.5 second for host to provide I/O
     
    284362        // if (table->hosts[i].stdout.Nbuffer > 0x10000) {
    285363        if (table->hosts[i].stdout.Nbuffer > 0x1000) {
    286           int printHead = VERBOSE || (table->hosts[i].stdout.Nbuffer > 0);
     364          int printHead = VERBOSE && (table->hosts[i].stdout.Nbuffer > 0);
    287365          if (printHead) fprintf (stdout, "--- stdout from %s --- (%d bytes, v1)\n", table->hosts[i].hostname, table->hosts[i].stdout.Nbuffer);
    288366          int Nout = write (STDOUT_FILENO, table->hosts[i].stdout.buffer, table->hosts[i].stdout.Nbuffer);
     
    298376        // if (table->hosts[i].stderr.Nbuffer > 0x10000) {
    299377        if (table->hosts[i].stderr.Nbuffer > 0x1000) {
    300           int printHead = VERBOSE || (table->hosts[i].stderr.Nbuffer > 0);
     378          int printHead = VERBOSE && (table->hosts[i].stderr.Nbuffer > 0);
    301379          if (printHead) fprintf (stdout, "--- stderr from %s --- (%d bytes, v1)\n", table->hosts[i].hostname, table->hosts[i].stderr.Nbuffer);
    302380          int Nout = write (STDOUT_FILENO, table->hosts[i].stderr.buffer, table->hosts[i].stderr.Nbuffer);
     
    314392      if (!pid) {
    315393        // fprintf (stderr, "no hosts to harvest\n");
    316         usleep (500000);
     394        usleep (200000);
    317395        break; // no outstanding jobs have finished
    318396      }
     
    367445        }
    368446      }
    369       if (!found) {
    370         fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
    371         exit (2);
    372       }
    373       Nfound ++;
     447      if (found) Nfound ++;
     448      // we sometimes harvest children not in the list (eg, closed kapa window).  just ignore
    374449      if (Nfound == Nrunning) goto escape; // we've harvested all jobs
    375450    }
     
    389464}
    390465
     466// wait for all children to complete, report output to stdout
     467int HostTableGroupWaitJobsGetIO (HostTableGroup *table, char *file, int lineno, int VERBOSE) {
     468
     469  // we have launched table->Nhosts jobs; wait for all of them to complete...
     470  // if one (N) failed to launch, we will get an ECHILD error from the last (N) calls
     471
     472  // we need to read any data waiting on stderr or stdout from these jobs, or the overfull
     473  // buffers can cause a problem.  we alternate between 'select' and 'waitpid' calls with
     474  // timeouts for both
     475
     476  // add all hosts' sockets to the fd_sets
     477  fd_set rdSet, wtSet;
     478  FD_ZERO (&rdSet);
     479  FD_ZERO (&wtSet);
     480
     481  // XXX can I set the fd_sets once, since I am not actually closing the fd's?
     482
     483  int globalStatus = TRUE;
     484
     485  int i;
     486  int Nmax = 0;
     487  for (i = 0; i < table->Nhosts; i++) {
     488    if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     489    FD_SET (table->hosts[i][0].stdio[HOST_STDIN], &wtSet);
     490    Nmax = MAX (Nmax, table->hosts[i][0].stdio[HOST_STDIN]);
     491    FD_SET (table->hosts[i][0].stdio[HOST_STDOUT], &rdSet);
     492    Nmax = MAX (Nmax, table->hosts[i][0].stdio[HOST_STDOUT]);
     493    FD_SET (table->hosts[i][0].stdio[HOST_STDERR], &rdSet);
     494    Nmax = MAX (Nmax, table->hosts[i][0].stdio[HOST_STDERR]);
     495  }   
     496  Nmax ++;
     497
     498  // need the list of connected hosts for exit test below
     499  int Nrunning = 0;
     500  for (i = 0; i < table->Nhosts; i++) {
     501    if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     502    Nrunning ++;
     503  }
     504
     505  int Nfound = 0;
     506
     507  // this loop has 2 chunks: (a) check for I/O + (b) check for jobs done
     508  while (1) {
     509
     510    // Wait up to 0.5 second for host to provide I/O
     511    // timeout gets mucked: need to reset before each select
     512    struct timeval timeout;
     513    timeout.tv_sec = 10;
     514    timeout.tv_usec = 500000;
     515
     516    int status = select (Nmax, NULL, &wtSet, NULL, &timeout);
     517    if (status == -1) {
     518      perror("select()");
     519      exit (2);
     520    }
     521
     522    // we have some sockets to check, check sockets for all hosts
     523    for (i = 0; (status > 0) && (i < table->Nhosts); i++) {
     524      if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     525
     526      if (FALSE && FD_ISSET (table->hosts[i][0].stdio[HOST_STDIN], &wtSet)) {
     527        // this host is waiting for input : this is an error, so exit
     528        fprintf (stderr, "host %s is waiting for input\n", table->hosts[i][0].hostname);
     529        abort();
     530      }
     531     
     532      if ((table->hosts[i][0].stdio[HOST_STDOUT] > 0) && FD_ISSET (table->hosts[i][0].stdio[HOST_STDOUT], &rdSet)) {
     533        // this host has waiting output : read to buffer, and dump if necessary
     534        ReadtoIOBuffer (&table->hosts[i][0].stdout, table->hosts[i][0].stdio[HOST_STDOUT]);
     535        // if (table->hosts[i][0].stdout.Nbuffer > 0x10000) {
     536        if (table->hosts[i][0].stdout.Nbuffer > 0x1000) {
     537          int printHead = VERBOSE || (table->hosts[i][0].stdout.Nbuffer > 0);
     538          if (printHead) fprintf (stdout, "--- stdout from %s --- (%d bytes, v1)\n", table->hosts[i][0].hostname, table->hosts[i][0].stdout.Nbuffer);
     539          int Nout = write (STDOUT_FILENO, table->hosts[i][0].stdout.buffer, table->hosts[i][0].stdout.Nbuffer);
     540          if (Nout != table->hosts[i][0].stdout.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     541          FlushIOBuffer (&table->hosts[i][0].stdout);
     542          if (printHead) fprintf (stdout, "\n");
     543        }
     544      }
     545
     546      if ((table->hosts[i][0].stdio[HOST_STDERR] > 0) && FD_ISSET (table->hosts[i][0].stdio[HOST_STDERR], &rdSet)) {
     547        // this host has waiting output : read to buffer, and dump if necessary
     548        ReadtoIOBuffer (&table->hosts[i][0].stderr, table->hosts[i][0].stdio[HOST_STDERR]);
     549        // if (table->hosts[i][0].stderr.Nbuffer > 0x10000) {
     550        if (table->hosts[i][0].stderr.Nbuffer > 0x1000) {
     551          int printHead = VERBOSE || (table->hosts[i][0].stderr.Nbuffer > 0);
     552          if (printHead) fprintf (stdout, "--- stderr from %s --- (%d bytes, v1)\n", table->hosts[i][0].hostname, table->hosts[i][0].stderr.Nbuffer);
     553          int Nout = write (STDOUT_FILENO, table->hosts[i][0].stderr.buffer, table->hosts[i][0].stderr.Nbuffer);
     554          if (Nout != table->hosts[i][0].stderr.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     555          FlushIOBuffer (&table->hosts[i][0].stderr);
     556          if (printHead) fprintf (stdout, "\n");
     557        }
     558      }
     559    }
     560
     561    // now check if any children have finished...
     562    while (TRUE) {
     563      int status = 0;
     564      int pid = waitpid (-1, &status, WNOHANG);
     565      if (!pid) {
     566        // fprintf (stderr, "no hosts to harvest\n");
     567        usleep (500000);
     568        break; // no outstanding jobs have finished
     569      }
     570      if ((pid == -1) && (errno == ECHILD)) goto escape; // no more jobs on which to wait
     571      if ((pid == -1) && (errno != ECHILD)) {
     572        fprintf (stderr, "programming error (2)? %s %d", file, lineno);
     573        exit (2);
     574      }
     575
     576      // find the host which has finished
     577      int found = FALSE;
     578      for (i = 0; (i < table->Nhosts) && !found; i++) {
     579        if (table->hosts[i][0].pid != pid) continue;
     580        found = TRUE;
     581
     582        HostInfo *host = table->hosts[i];
     583
     584        // check on the status of this and report any output?
     585        if (VERBOSE) fprintf (stdout, "job finished for %s (%d)\n", host->hostname, pid);
     586
     587        // read stdout
     588        int printHead;
     589        printHead = VERBOSE || (host->stdout.Nbuffer > 0);
     590        EmptyIOBuffer (&host->stdout, 100, host->stdio[HOST_STDOUT]);
     591        if (printHead) fprintf (stdout, "--- stdout from %s --- (%d bytes, v2)\n", host->hostname, host->stdout.Nbuffer);
     592        int Nout = write (STDOUT_FILENO, host->stdout.buffer, host->stdout.Nbuffer);
     593        if (Nout != host->stdout.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     594        FlushIOBuffer (&host->stdout);
     595        if (printHead) fprintf (stdout, "\n");
     596           
     597        // read stderr
     598        printHead = VERBOSE || (host->stderr.Nbuffer > 0);
     599        EmptyIOBuffer (&host->stderr, 100, host->stdio[HOST_STDERR]);
     600        if (printHead) fprintf (stdout, "--- stderr from %s --- (%d bytes, v2)\n", host->hostname, host->stderr.Nbuffer);
     601        Nout = write (STDOUT_FILENO, host->stderr.buffer, host->stderr.Nbuffer);
     602        if (Nout != host->stderr.Nbuffer) { fprintf (stderr, "(error writing log?)\n"); }
     603        FlushIOBuffer (&host->stderr);
     604        if (printHead) fprintf (stdout, "\n");
     605
     606        if (WIFEXITED(status)) {
     607          if (VERBOSE) fprintf (stdout, "normal completion, exit status is %d\n", WEXITSTATUS(status));
     608          host->status = WEXITSTATUS(status);
     609          if (host->status) {
     610            fprintf (stdout, "job failed on %s\n", host->hostname);
     611            globalStatus = FALSE;
     612          }
     613        } else {
     614          host->status = -1;
     615          fprintf (stdout, "job exited abnormally on %s\n", host->hostname);
     616          globalStatus = FALSE;
     617          continue;
     618        }
     619      }
     620      if (!found) {
     621        fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
     622        exit (2);
     623      }
     624      Nfound ++;
     625      if (Nfound == Nrunning) goto escape; // we've harvested all jobs
     626    }
     627  }
     628
     629escape:
     630
     631  // close all opened connections
     632  for (i = 0; i < table->Nhosts; i++) {
     633    if (!table->hosts[i][0].pid) continue; // any unconnected hosts should be skipped
     634    close (table->hosts[i][0].stdio[HOST_STDIN]);
     635    close (table->hosts[i][0].stdio[HOST_STDOUT]);
     636    close (table->hosts[i][0].stdio[HOST_STDERR]);
     637  }
     638
     639  return globalStatus;
     640}
     641
    391642int HostTableTestHost (SkyRegion *region, int hostID) {
    392643
  • trunk/Ohana/src/libdvo/src/ImageMetadata.c

    r37035 r37807  
    156156  // assign the storage arrays
    157157  for (i = 0; i < Nimage; i++) {
    158     int Nmosaic = FindMosaicForImage (image, Nimage, i);
    159     if (!Nmosaic) continue;
    160     Nmosaic --;
     158    if (!image[i].coords.mosaic) continue;
    161159    imageID[i]  = image[i].imageID;
    162160    externID[i] = image[i].externID;
    163     crval1[i]   = image[Nmosaic].coords.crval1;
    164     crval2[i]   = image[Nmosaic].coords.crval2;
    165 
    166     theta[i]    = DEG_RAD*atan2(image[Nmosaic].coords.pc1_2, image[Nmosaic].coords.pc1_1);
     161    Coords *mosaic = image[i].coords.mosaic;
     162
     163    crval1[i]   = mosaic->crval1;
     164    crval2[i]   = mosaic->crval2;
     165
     166    theta[i]    = DEG_RAD*atan2(mosaic->pc1_2, mosaic->pc1_1);
    167167
    168168    Mcal[i]     = image[i].Mcal;
  • trunk/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r36490 r37807  
    1313 
    1414  /* field defines a frame with 0,0 at the field center, and 1 arcsec / pixel */
    15   field.crpix1 = field.crpix2 = 0.0;
     15  InitCoords (&field, "DEC--SIN");
    1616  field.cdelt1 = field.cdelt2 = 1.0 / 3600;
    17   field.pc1_1  = field.pc2_2  = 1.0;
    18   field.pc1_2  = field.pc2_1  = 0.0;
    19   field.Npolyterms = 0;
    20   strcpy (field.ctype, "DEC--SIN");
    2117
    2218  /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
    23   mosaic.crpix1 = mosaic.crpix2 = 0.0;
     19  InitCoords (&mosaic, "DEC--SIN");
    2420  mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
    25   mosaic.pc1_1  = mosaic.pc2_2  = 1.0;
    26   mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    27   mosaic.Npolyterms = 0;
    28   strcpy (mosaic.ctype, "DEC--SIN");
    2921
    3022  if ((image = ImageMetadataLoad (filename, &Nimage)) == NULL) return (FALSE);
  • trunk/Ohana/src/libdvo/src/ImageOps.c

    r34088 r37807  
    5555    if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
    5656    if (selection->useDisplay) {
    57       if (!FindMosaicForImage (image, Nimage, i)) continue;
    5857      // first check if region center is in image
    5958      status = RD_to_XY (&X, &Y, Rmid, graph.coords.crval2, &image[i].coords);
     
    8988    }
    9089    if (selection->useSkyregion) {
    91       if (!FindMosaicForImage (image, Nimage, i)) continue;
    9290      /* project this image to screen display coords */
    9391      x[0] = 0;           y[0] = 0;
  • trunk/Ohana/src/libdvo/src/ImageSelection.c

    r36490 r37807  
    2222
    2323  if (mosaicMode) {
    24       /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
    25       mosaic.crpix1 = mosaic.crpix2 = 0.0;
    26       mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
    27       mosaic.pc1_1  = mosaic.pc2_2  = 1.0;
    28       mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    29       mosaic.Npolyterms = 0;
    30       strcpy (mosaic.ctype, "DEC--SIN");
     24    /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
     25    InitCoords (&mosaic, "DEC--SIN");
     26    mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
    3127  }
    3228
     
    6460  }
    6561  if (m == -1) return (NULL);
    66   if (!FindMosaicForImage (image, Nimage, m)) return (NULL);
    6762  return (&image[m]);
    6863}
     
    8580  }
    8681  if (m == -1) return (NULL);
    87   if (!FindMosaicForImage (image, Nimage, m)) return (NULL);
    8882  return (&image[m]);
    8983}
  • trunk/Ohana/src/libdvo/src/LoadImages.c

    r33649 r37807  
    99static Image *imageCache = NULL;
    1010static off_t cacheNimage = 0;
     11AstromOffsetTable *table = NULL;
    1112
    1213static time_t getLastModified(char *filename);
     
    3940    lastModified = 0;
    4041  }
    41 
    4242
    4343  gfits_db_init (&db);
     
    7777  }
    7878
     79  // assign image->parent and image->coords.mosaic
     80  BuildChipMatch (image, *Nimage);
     81  // MARKTIME("build chip match: %f sec\n", dtime);
     82
     83  char mapfile[DVO_MAX_PATH];
     84  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", catdir);
     85
     86  if (table) AstromOffsetTableFree(table);
     87  table = AstromOffsetMapLoad (mapfile, FALSE);
     88
     89  // assign images.coords.offsetMap -> table->map[i]
     90  if (table) {
     91    AstromOffsetTableMatchChips (image, *Nimage, table);
     92  }
     93
    7994  return (image);
    8095}
     
    92107  if (!dvoUseImageCache && (images != NULL)) {
    93108    free(images);
     109    AstromOffsetTableFree (table);
    94110  } else {
    95111    // defer free until next LoadImages with a different or modified Images.dat
  • trunk/Ohana/src/libdvo/src/RegionHostTable.c

    r36630 r37807  
    3131    hosts[i].Nneighbors = 0;
    3232    hosts[i].isNeighbor = FALSE;
     33
     34    hosts[i].astromTable = NULL;
    3335  }
    3436  return;
  • trunk/Ohana/src/libdvo/src/coord_systems.c

    r31635 r37807  
    11# include "dvo.h"
    2 # include "libdvo_astro.h"
    32   
    43CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output) {
     
    4039          // \delta^p_J = +27d 07' 41.7087"
    4140          // \theta_J   = 122.93192526 deg
     41
    4242          // these differ from the above at the several milliarcsec level
    43 
    4443
    4544          // These values were used in the past, but transform to/from B1950.0
     
    4746          // transform->Xo  = 282.25*RAD_DEG;
    4847          // transform->xo  =  33.00;
     48
     49          break;
     50        case COORD_GALACTIC_REID_2004:
     51
     52          // J2000 FK5 transformation from Reid et al 2004, ApJ 616, 872
     53          transform->phi = (27.128336111 - 90.0)*RAD_DEG; // +27d 07' 42.01" (J2000)
     54          transform->Xo  = (192.859508333 + 90.0)*RAD_DEG; // 12h 51m 26.282s (J2000)
     55          transform->xo  =  32.932;
     56
     57          // comments from LSD code (lsd/builtins/misc.py, Mario Juric)
     58          // # Appendix of Reid et al. (http://adsabs.harvard.edu/cgi-bin/bib_query?2004ApJ...616..872R)
     59          // # This convention is also used by LAMBDA/WMAP (http://lambda.gsfc.nasa.gov/toolbox/tb_coordconv.cfm)
     60
     61          // _angp = np.radians(192.859508333) #  12h 51m 26.282s (J2000)
     62          // _dngp = np.radians(27.128336111)  # +27d 07' 42.01" (J2000)
     63          // _l0   = np.radians(32.932)
    4964
    5065          break;
     
    87102      switch (output) {
    88103        case COORD_CELESTIAL:
    89           // J2000 transformation from Liu et al 2011 ()
     104          // J2000 transformation from Liu et al 2011 (A&A 526, A16)
    90105          transform->phi =  62.8717488056*RAD_DEG;
    91106          transform->Xo  =  32.9319185700*RAD_DEG;
    92107          transform->xo  = 282.8594812080;
     108
     109          // These values were used in the past, but transform to/from B1950.0
     110          // transform->phi =  62.60*RAD_DEG;
     111          // transform->Xo  =  33.00*RAD_DEG;
     112          // transform->xo  = 282.25;
     113          break;
     114        case COORD_GALACTIC:
     115          transform->phi = 0.0;
     116          transform->Xo  = 0.0;
     117          transform->xo  = 0.0;
     118          transform->isIdentity = TRUE;
     119          break;
     120        case COORD_ECLIPTIC:
     121          return NULL;
     122        default:
     123          abort();
     124      }
     125      break;
     126    case COORD_GALACTIC_REID_2004:
     127      switch (output) {
     128        case COORD_CELESTIAL:
     129          // J2000 FK5 transformation from Reid et al 2004, ApJ 616, 872
     130          transform->phi = (90.0 - 27.128336111)*RAD_DEG; // +27d 07' 42.01" (J2000)
     131          transform->Xo  =  32.932*RAD_DEG;
     132          transform->xo  = (192.859508333 + 90.0); // 12h 51m 26.282s (J2000)
    93133
    94134          // These values were used in the past, but transform to/from B1950.0
     
    144184  Y *= RAD_DEG;
    145185
     186  double cosY = cos(Y);
     187  double sinY = sin(Y);
     188 
     189  double cosX = cos(X);
     190  double sinX = sin(X);
     191
    146192  // recast with constants extracted:
    147   sin_y = cos(Y)*sin(X)*transform->sin_phi_cos_Xo - cos(Y)*cos(X)*transform->sin_phi_sin_Xo + sin(Y)*transform->cos_phi;
     193  sin_y = cosY*sinX*transform->sin_phi_cos_Xo - cosY*cosX*transform->sin_phi_sin_Xo + sinY*transform->cos_phi;
    148194  cos_y = sqrt (1 - sin_y*sin_y);
    149195
    150   sin_x = cos(Y)*sin(X)*transform->cos_phi_cos_Xo - cos(Y)*cos(X)*transform->cos_phi_sin_Xo - sin(Y)*transform->sin_phi;
    151   cos_x = cos(Y)*cos(X)*transform->cos_Xo + cos(Y)*sin(X)*transform->sin_Xo;
     196  sin_x = cosY*sinX*transform->cos_phi_cos_Xo - cosY*cosX*transform->cos_phi_sin_Xo - sinY*transform->sin_phi;
     197  cos_x = cosY*cosX*transform->cos_Xo + cosY*sinX*transform->sin_Xo;
    152198     
    153199  // atan2 returns -pi : +pi
  • trunk/Ohana/src/libdvo/src/coordops.c

    r37412 r37807  
    33/* note that Coords.ctype carries the DEC (ctype2) value */
    44
    5 static Coords mosaic;
    6 static int gotMosaic = FALSE;
    7 
    8 void RegisterMosaic (Coords *coords) {
    9   mosaic = *coords;
    10   gotMosaic = TRUE;
    11 }
    12 
    13 int isRegisteredMosaic () {
    14   return (gotMosaic);
    15 }
    16 
    17 int GetMosaicCoords (Coords *coords) {
    18   *coords = mosaic;
    19   return (TRUE);
    20 }
     5// default coordinates have unit scale and no rotation
     6void InitCoords (Coords *coords, char *projection) {
     7  coords->crval1 = 0.0;
     8  coords->crval2 = 0.0;
     9  coords->crpix1 = 0.0;
     10  coords->crpix2 = 0.0;
     11
     12  coords->cdelt1 = 1.0;
     13  coords->cdelt2 = 1.0;
     14
     15  coords->pc1_1 = 1.0; // EW is flipped relative to sky parity (dRA/dX > 0)
     16  coords->pc2_2 = 1.0;
     17  coords->pc2_1 = 0.0;
     18  coords->pc1_2 = 0.0;
     19
     20  coords->Npolyterms = 1;
     21  coords->mosaic = NULL;
     22  coords->offsetMap = NULL;
     23
     24  memset (coords->polyterms, 0, 7*2*sizeof(float));
     25
     26  if (projection) {
     27    strcpy (coords->ctype, projection);
     28  } else {
     29    strcpy (coords->ctype, "NONE");
     30  }
     31}
     32
     33// default coordinates have unit scale and no rotation
     34void CopyCoords (Coords *tgt, Coords *src) {
     35  tgt->crval1     = src->crval1;
     36  tgt->crval2     = src->crval2;
     37  tgt->crpix1     = src->crpix1;
     38  tgt->crpix2     = src->crpix2;
     39  tgt->cdelt1     = src->cdelt1;
     40  tgt->cdelt2     = src->cdelt2;
     41  tgt->pc1_1      = src->pc1_1;
     42  tgt->pc2_2      = src->pc2_2;
     43  tgt->pc2_1      = src->pc2_1;
     44  tgt->pc1_2      = src->pc1_2;
     45  tgt->Npolyterms = src->Npolyterms;
     46  tgt->mosaic     = src->mosaic;      // pointer to another structure
     47  tgt->offsetMap  = src->offsetMap;   // pointer to another structure
     48
     49  memcpy (tgt->polyterms, src->polyterms, 7*2*sizeof(float));
     50  strcpy (tgt->ctype,     src->ctype);
     51}
    2152
    2253int XY_to_LM (double *L, double *M, double x, double y, Coords *coords) {
     
    2859  proj = GetProjection (coords[0].ctype);
    2960  mode = GetProjectionMode (proj);
     61
     62  // if we have an image map, it should be applied to the pixel coordinates
     63  // before anything else is done.  It is easier to invert the map if it is
     64  // of the form (dX,dY) = f(X,Y), then if (dL,dM) = f(X,Y).
     65  if (coords[0].Npolyterms == -1) {
     66    myAssert (coords[0].offsetMap, "offsetMap is requested by not defined");
     67    float dX = AstromOffsetMapValue (coords->offsetMap, x, y, TRUE);
     68    float dY = AstromOffsetMapValue (coords->offsetMap, x, y, FALSE);
     69    if (isnan(dX)) dX = 0.0;
     70    if (isnan(dY)) dY = 0.0;
     71    x += dX;
     72    y += dY;
     73  }
    3074
    3175  /** convert pixel coordinates to cartesian system **/
     
    78122    /* mosaic astrometry : WRP is chip astrometry; apply mosaic (DIS) term */
    79123    if (proj == PROJ_WRP) {
    80       if (!gotMosaic) return (FALSE);
    81       XY_to_RD (ra, dec, L, M, &mosaic);
     124      if (!coords->mosaic) {
     125        myAbort ("missing mosaic element");
     126        return (FALSE);
     127      }
     128      XY_to_RD (ra, dec, L, M, coords->mosaic);
    82129    }
    83130    return (TRUE);
     
    149196    *dec = DEG_RAD*delta;
    150197
    151     *ra = ohana_normalize_angle (*ra);
     198    // *ra = ohana_normalize_angle (*ra);
    152199
    153200    return (TRUE);
     
    182229    *dec = delta + coords[0].crval2;
    183230
    184     *ra = ohana_normalize_angle (*ra);
     231    // *ra = ohana_normalize_angle (*ra);
    185232
    186233    return (TRUE);
     
    208255  if (mode == PROJ_MODE_CARTESIAN) {
    209256    if (proj == PROJ_WRP) {
    210       if (!gotMosaic) return (FALSE);
    211       RD_to_XY (L, M, ra, dec, &mosaic);
     257      if (!coords->mosaic) {
     258        myAbort ("missing mosaic element");
     259        return (FALSE);
     260      }
     261      RD_to_XY (L, M, ra, dec, coords->mosaic);
    212262      return (TRUE);
    213263    }
     
    381431  *y = Yo / coords[0].cdelt2 + coords[0].crpix2;
    382432
     433  // if we have an image map, it should be applied to the pixel coordinates
     434  // after anything else is done.  It is easier to invert the map if it is
     435  // of the form (dX,dY) = f(X,Y), then if (dL,dM) = f(X,Y).
     436  if (coords[0].Npolyterms == -1) {
     437    myAssert (coords[0].offsetMap, "offsetMap is requested by not defined");
     438
     439    double xraw = *x;
     440    double yraw = *y;
     441
     442    double dXo = 0.0;
     443    double dYo = 0.0;
     444
     445    int i;
     446    for (i = 0; i < 4; i++) {
     447      double dX = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, TRUE);
     448      double dY = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, FALSE);
     449
     450      if (isnan(dX)) dX = 0.0;
     451      if (isnan(dY)) dY = 0.0;
     452
     453      dX -= dXo;
     454      dY -= dYo;
     455
     456      xraw -= dX;
     457      yraw -= dY;
     458
     459      dXo += dX;
     460      dYo += dY;
     461    }
     462
     463    *x = xraw;
     464    *y = yraw;
     465
     466    // I need to iterate since the position at which I have first made the correction is
     467    // not the true position.  but if dX,dY is small and the gradient of dX,dY is also
     468    // small, then even a single pass gets us close.
     469
     470    // XXX test this and use a while (hypot(dX,dY) > XXX) condition
     471  }
    383472  return (TRUE);
    384473}
     
    449538 
    450539  rotate = 0.0;
    451   coords[0].crval1 = coords[0].crpix1 = coords[0].cdelt1 = 0.0;
    452   coords[0].crval2 = coords[0].crpix2 = coords[0].cdelt2 = 0.0;
    453   coords[0].pc1_1 = coords[0].pc2_2 = 1.0;
    454   coords[0].pc2_1 = coords[0].pc1_2 = 0.0;
    455   coords[0].Npolyterms = 1;
    456   strcpy (coords[0].ctype, "NONE");
     540
     541  InitCoords (coords, NULL);
    457542 
    458543  mode = COORD_TYPE_NONE;
     
    619704    }
    620705  }
    621 
     706 
    622707  if (!status) {
    623708    // fprintf (stderr, "error getting all elements for coordinate mode %s\n", coords[0].ctype);
  • trunk/Ohana/src/libdvo/src/dbExtractAverages.c

    r37116 r37807  
    5050
    5151/* return average.field based on the selection */
    52 dbValue dbExtractAverages (Average *average, SecFilt *secfilt, Measure *measure, dbField *field) {
     52dbValue dbExtractAverages (Average *average, SecFilt *secfilt, Measure *measure, Lensobj *lensobj, StarPar *starpar, dbField *field) {
    5353
    5454  // off_t i;
     
    161161      value.Flt = average[0].stargal;
    162162      break;
    163     case AVE_REF_COLOR:
     163    case AVE_REF_COLOR_BLUE:
    164164      value.Flt = average[0].refColorBlue;
     165      break;
     166    case AVE_REF_COLOR_RED:
     167      value.Flt = average[0].refColorRed;
    165168      break;
    166169
     
    306309          value.Flt = PhotUCdist (field->photcode, average, secfilt);
    307310          break;
    308         // XX case MAG_OPTION_STACK_DET_ID:
    309         // XX   value.Int = PhotStackID (field->photcode, average, secfilt);
    310         // XX   break;
    311311        case MAG_OPTION_FLAGS: {
    312312          int Nsec = GetPhotcodeNsec (field->photcode->code);
     
    315315          break;
    316316        }
     317
     318          // g:X11_SM_OBJ, etc, are only valid for average
     319        case MAG_OPTION_X11_SM_OBJ: { value.Flt = LensValue_X11_sm_obj (field->photcode, lensobj); break; }
     320        case MAG_OPTION_X12_SM_OBJ: { value.Flt = LensValue_X12_sm_obj (field->photcode, lensobj); break; }
     321        case MAG_OPTION_X22_SM_OBJ: { value.Flt = LensValue_X22_sm_obj (field->photcode, lensobj); break; }
     322        case MAG_OPTION_E1_SM_OBJ:  { value.Flt = LensValue_E1_sm_obj  (field->photcode, lensobj); break; }
     323        case MAG_OPTION_E2_SM_OBJ:  { value.Flt = LensValue_E2_sm_obj  (field->photcode, lensobj); break; }
     324
     325        case MAG_OPTION_X11_SH_OBJ: { value.Flt = LensValue_X11_sh_obj (field->photcode, lensobj); break; }
     326        case MAG_OPTION_X12_SH_OBJ: { value.Flt = LensValue_X12_sh_obj (field->photcode, lensobj); break; }
     327        case MAG_OPTION_X22_SH_OBJ: { value.Flt = LensValue_X22_sh_obj (field->photcode, lensobj); break; }
     328        case MAG_OPTION_E1_SH_OBJ:  { value.Flt = LensValue_E1_sh_obj  (field->photcode, lensobj); break; }
     329        case MAG_OPTION_E2_SH_OBJ:  { value.Flt = LensValue_E2_sh_obj  (field->photcode, lensobj); break; }
     330
     331        case MAG_OPTION_X11_SM_PSF: { value.Flt = LensValue_X11_sm_psf (field->photcode, lensobj); break; }
     332        case MAG_OPTION_X12_SM_PSF: { value.Flt = LensValue_X12_sm_psf (field->photcode, lensobj); break; }
     333        case MAG_OPTION_X22_SM_PSF: { value.Flt = LensValue_X22_sm_psf (field->photcode, lensobj); break; }
     334        case MAG_OPTION_E1_SM_PSF:  { value.Flt = LensValue_E1_sm_psf  (field->photcode, lensobj); break; }
     335        case MAG_OPTION_E2_SM_PSF:  { value.Flt = LensValue_E2_sm_psf  (field->photcode, lensobj); break; }
     336
     337        case MAG_OPTION_X11_SH_PSF: { value.Flt = LensValue_X11_sh_psf (field->photcode, lensobj); break; }
     338        case MAG_OPTION_X12_SH_PSF: { value.Flt = LensValue_X12_sh_psf (field->photcode, lensobj); break; }
     339        case MAG_OPTION_X22_SH_PSF: { value.Flt = LensValue_X22_sh_psf (field->photcode, lensobj); break; }
     340        case MAG_OPTION_E1_SH_PSF:  { value.Flt = LensValue_E1_sh_psf  (field->photcode, lensobj); break; }
     341        case MAG_OPTION_E2_SH_PSF:  { value.Flt = LensValue_E2_sh_psf  (field->photcode, lensobj); break; }
     342
    317343        case MAG_OPTION_NONE:
    318344          break;
    319       }
    320       break;
     345
     346        default:
     347          break;
     348      }
     349      break;
     350
     351    case AVE_E_BV:             { value.Flt = starpar->Ebv;      break; }
     352    case AVE_E_BV_ERR:         { value.Flt = starpar->dEbv;     break; }
     353    case AVE_DISTANCE_MOD:     { value.Flt = starpar->DistMag;  break; }
     354    case AVE_DISTANCE_MOD_ERR: { value.Flt = starpar->dDistMag; break; }
     355    case AVE_M_R:              { value.Flt = starpar->M_r;      break; }
     356    case AVE_M_R_ERR:          { value.Flt = starpar->dM_r;     break; }
     357    case AVE_FEH:              { value.Flt = starpar->FeH;      break; }
     358    case AVE_FEH_ERR:          { value.Flt = starpar->dFeH;     break; }
     359    case AVE_URA_GALMODEL:     { value.Flt = starpar->uRA;      break; }
     360    case AVE_UDEC_GALMODEL:    { value.Flt = starpar->uDEC;     break; }
     361    case AVE_RA_GALMODEL:      { value.Flt = starpar->R;        break; }
     362    case AVE_DEC_GALMODEL:     { value.Flt = starpar->D;        break; }
    321363
    322364    case AVE_TYPE:
     
    324366    case AVE_TYPEFRAC:
    325367      break;
     368
     369
    326370  }
    327371  return (value);
  • trunk/Ohana/src/libdvo/src/dbExtractImages.c

    r37035 r37807  
    5959  time_t t;
    6060  dbValue value;
    61   off_t Nmosaic;
    6261
    6362  value.Flt = NAN;
     
    6867    case IMAGE_RA:
    6968      if (!haveCelestial) {
    70         if (!FindMosaicForImage (image, Nimage, N)) return value;
    7169        if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    7270          x = 0.0;
     
    8381    case IMAGE_DEC:
    8482      if (!haveCelestial) {
    85         if (!FindMosaicForImage (image, Nimage, N)) return value;
    8683        if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    8784          x = 0.0;
     
    9996      if (!haveGalactic) {
    10097        if (!haveCelestial) {
    101           if (!FindMosaicForImage (image, Nimage, N)) return value;
    10298          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    10399            x = 0.0;
     
    118114      if (!haveGalactic) {
    119115        if (!haveCelestial) {
    120           if (!FindMosaicForImage (image, Nimage, N)) return value;
    121116          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    122117            x = 0.0;
     
    137132      if (!haveEcliptic) {
    138133        if (!haveCelestial) {
    139           if (!FindMosaicForImage (image, Nimage, N)) return value;
    140134          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    141135            x = 0.0;
     
    156150      if (!haveEcliptic) {
    157151        if (!haveCelestial) {
    158           if (!FindMosaicForImage (image, Nimage, N)) return value;
    159152          if (!strcmp(&image[N].coords.ctype[4], "-DIS")) {
    160153            x = 0.0;
     
    269262
    270263    case IMAGE_FWHM_MEDIAN:
    271       if (!(Nmosaic = FindMosaicForImage (image, Nimage, N))) return value;
    272       Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    273       value.Flt = (image[Nmosaic].fwhm_x + image[Nmosaic].fwhm_y) / 50.0;
     264      if (!image[N].parent) return value;
     265      value.Flt = (image[N].parent->fwhm_x + image[N].parent->fwhm_y) / 50.0;
    274266      break;
    275267    case IMAGE_FWHM_MAJ_MEDIAN:
    276       if (!(Nmosaic = FindMosaicForImage (image, Nimage, N))) return value;
    277       Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    278       value.Flt = image[Nmosaic].fwhm_x / 25.0;
     268      if (!image[N].parent) return value;
     269      value.Flt = image[N].parent->fwhm_x / 25.0;
    279270      break;
    280271    case IMAGE_FWHM_MIN_MEDIAN:
    281       if (!(Nmosaic = FindMosaicForImage (image, Nimage, N))) return value;
    282       Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    283       value.Flt = image[Nmosaic].fwhm_y / 25.0;
     272      if (!image[N].parent) return value;
     273      value.Flt = image[N].parent->fwhm_y / 25.0;
    284274      break;
    285275
     
    375365      break;
    376366
    377     case IMAGE_REF_COLOR:
     367    case IMAGE_REF_COLOR_BLUE:
    378368      value.Flt = image[N].refColorBlue;
     369      break;
     370    case IMAGE_REF_COLOR_RED:
     371      value.Flt = image[N].refColorRed;
    379372      break;
    380373  }
  • trunk/Ohana/src/libdvo/src/dbExtractMeasures.c

    r37246 r37807  
    8585
    8686/* return measure.field based on the selection */
    87 dbValue dbExtractMeasures (Average *average, SecFilt *secfilt, Measure *measure, dbField *field) {
     87dbValue dbExtractMeasures (Average *average, SecFilt *secfilt, Measure *measure, Lensing *lensing, StarPar *starpar, dbField *field) {
    8888
    8989  int Nsec;
     
    249249        case MAG_OPTION_UC_DIST:
    250250        case MAG_OPTION_FLAGS:
     251        case MAG_OPTION_X11_SM_OBJ:
     252        case MAG_OPTION_X12_SM_OBJ:
     253        case MAG_OPTION_X22_SM_OBJ:
     254        case MAG_OPTION_E1_SM_OBJ:
     255        case MAG_OPTION_E2_SM_OBJ:
     256        case MAG_OPTION_X11_SH_OBJ:
     257        case MAG_OPTION_X12_SH_OBJ:
     258        case MAG_OPTION_X22_SH_OBJ:
     259        case MAG_OPTION_E1_SH_OBJ:
     260        case MAG_OPTION_E2_SH_OBJ:
     261        case MAG_OPTION_X11_SM_PSF:
     262        case MAG_OPTION_X12_SM_PSF:
     263        case MAG_OPTION_X22_SM_PSF:
     264        case MAG_OPTION_E1_SM_PSF:
     265        case MAG_OPTION_E2_SM_PSF:
     266        case MAG_OPTION_X11_SH_PSF:
     267        case MAG_OPTION_X12_SH_PSF:
     268        case MAG_OPTION_X22_SH_PSF:
     269        case MAG_OPTION_E1_SH_PSF:
     270        case MAG_OPTION_E2_SH_PSF:
     271        case MAG_OPTION_F_AP_R5:
     272        case MAG_OPTION_F_ERR_AP_R5:
     273        case MAG_OPTION_F_STDEV_AP_R5:
     274        case MAG_OPTION_F_FILL_AP_R5:
     275        case MAG_OPTION_F_AP_R6:
     276        case MAG_OPTION_F_ERR_AP_R6:
     277        case MAG_OPTION_F_STDEV_AP_R6:
     278        case MAG_OPTION_F_FILL_AP_R6:
     279
    251280        case MAG_OPTION_NONE:
    252281          break;
     
    474503      break;
    475504
    476     case MEAS_REF_COLOR:
     505    case MEAS_REF_COLOR_BLUE:
    477506      value.Flt = average[0].refColorBlue;
     507      break;
     508    case MEAS_REF_COLOR_RED:
     509      value.Flt = average[0].refColorRed;
    478510      break;
    479511
     
    528560# endif
    529561      break;
    530     case MEAS_XFIX: /* OK */
    531       value.Flt = measure[0].Xfix;
    532       break;
    533     case MEAS_YFIX: /* OK */
    534       value.Flt = measure[0].Yfix;
    535       break;
    536     case MEAS_XCCD_ERR: /* OK */
    537       value.Flt = FromShortPixels(measure[0].dXccd);
    538       break;
    539     case MEAS_YCCD_ERR: /* OK */
    540       value.Flt = FromShortPixels(measure[0].dYccd);
    541       break;
    542     case MEAS_POS_SYS_ERR: /* OK */
    543       value.Flt = FromShortPixels(measure[0].dRsys);
    544       break;
     562    case MEAS_XFIX: { value.Flt = measure[0].Xfix; break; }
     563    case MEAS_YFIX: { value.Flt = measure[0].Yfix; break; }
     564    case MEAS_XCCD_ERR: { value.Flt = FromShortPixels(measure[0].dXccd); break; }
     565    case MEAS_YCCD_ERR: { value.Flt = FromShortPixels(measure[0].dYccd); break; }
     566    case MEAS_POS_SYS_ERR: { value.Flt = FromShortPixels(measure[0].dRsys); }
     567
     568    case MEAS_XOFF_KH:  { value.Flt = measure[0].XoffKH;  break; }
     569    case MEAS_YOFF_KH:  { value.Flt = measure[0].YoffKH;  break; }
     570    case MEAS_XOFF_DCR: { value.Flt = measure[0].XoffDCR; break; }
     571    case MEAS_YOFF_DCR: { value.Flt = measure[0].YoffDCR; break; }
     572    case MEAS_ROFF_GAL: { value.Flt = measure[0].RoffGAL; break; }
     573    case MEAS_DOFF_GAL: { value.Flt = measure[0].DoffGAL; break; }
    545574
    546575    case MEAS_XFIELD: /* offset relative to exposure center in ra,dec space */
     
    581610    case MEAS_XMOSAIC: /* offset relative to exposure center in camera coords */
    582611      if (!haveMosaicMeas) {
    583         if (REMOTE_CLIENT) {
    584           mosaic = MatchMosaicMetadata (measure[0].imageID);
    585         } else {
    586           // fprintf (stderr, "non-parallel Xmos broken\n");
    587           // abort();
    588           // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
    589           mosaic = MatchMosaicMetadata (measure[0].imageID);
    590         }
     612        mosaic = MatchMosaicMetadata (measure[0].imageID);
    591613        if (mosaic == NULL) break;
    592614        double Rm = measure[0].R;
     
    598620    case MEAS_YMOSAIC: /* OK */
    599621      if (!haveMosaicMeas) {
    600         if (REMOTE_CLIENT) {
    601           mosaic = MatchMosaicMetadata (measure[0].imageID);
    602         } else {
    603           // fprintf (stderr, "non-parallel Xmos broken\n");
    604           // abort();
    605           // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
    606           mosaic = MatchMosaicMetadata (measure[0].imageID);
    607         }
     622        mosaic = MatchMosaicMetadata (measure[0].imageID);
    608623        if (mosaic == NULL) break;
    609624        double Rm = measure[0].R;
     
    680695      break;
    681696
    682     case MEAS_MCAL_OFFSET: /* OK */
    683       value.Flt = measure[0].Mcal;
    684       break;
     697    case MEAS_MCAL_OFFSET: { value.Flt = measure[0].Mcal; break; }
    685698
    686699    case MEAS_FLAT: /* OK */
     
    717730      }
    718731      break;
     732
     733    case MEAS_E_BV:             { value.Flt = starpar->Ebv;      break; }
     734    case MEAS_E_BV_ERR:         { value.Flt = starpar->dEbv;     break; }
     735    case MEAS_DISTANCE_MOD:     { value.Flt = starpar->DistMag;  break; }
     736    case MEAS_DISTANCE_MOD_ERR: { value.Flt = starpar->dDistMag; break; }
     737    case MEAS_M_R:              { value.Flt = starpar->M_r;      break; }
     738    case MEAS_M_R_ERR:          { value.Flt = starpar->dM_r;     break; }
     739    case MEAS_FEH:              { value.Flt = starpar->FeH;      break; }
     740    case MEAS_FEH_ERR:          { value.Flt = starpar->dFeH;     break; }
     741    case MEAS_URA_GALMODEL:     { value.Flt = starpar->uRA;      break; }
     742    case MEAS_UDEC_GALMODEL:    { value.Flt = starpar->uDEC;     break; }
     743    case MEAS_RA_GALMODEL:      { value.Flt = starpar->R;        break; }
     744    case MEAS_DEC_GALMODEL:     { value.Flt = starpar->D;        break; }
    719745
    720746    // case MEAS_FLUX_PSF: /* OK */
  • trunk/Ohana/src/libdvo/src/dbFields.c

    r37116 r37807  
    2828}
    2929
     30int dbFieldNeedMeasure (dbField *fields, int Nfields) {
     31  int i;
     32  for (i = 0; i < Nfields; i++) {
     33    if (fields[i].photcode == NULL) continue; // non-measure fields do not have a photcode
     34    if (fields[i].photcode[0].type == PHOT_REF) return TRUE;
     35    if (fields[i].photcode[0].type == PHOT_DEP) return TRUE;
     36  }
     37  return FALSE;
     38}
     39
     40int dbFieldNeedLensing (dbField *fields, int Nfields) {
     41  int i;
     42  for (i = 0; i < Nfields; i++) {
     43    if (fields[i].ID == MEAS_X11_SM_OBJ) return TRUE;
     44    if (fields[i].ID == MEAS_X12_SM_OBJ) return TRUE;
     45    if (fields[i].ID == MEAS_X22_SM_OBJ) return TRUE;
     46    if (fields[i].ID == MEAS_E1_SM_OBJ)  return TRUE;
     47    if (fields[i].ID == MEAS_E2_SM_OBJ)  return TRUE;
     48    if (fields[i].ID == MEAS_X11_SH_OBJ) return TRUE;
     49    if (fields[i].ID == MEAS_X12_SH_OBJ) return TRUE;
     50    if (fields[i].ID == MEAS_X22_SH_OBJ) return TRUE;
     51    if (fields[i].ID == MEAS_E1_SH_OBJ)  return TRUE;
     52    if (fields[i].ID == MEAS_E2_SH_OBJ)  return TRUE;
     53    if (fields[i].ID == MEAS_X11_SM_PSF) return TRUE;
     54    if (fields[i].ID == MEAS_X12_SM_PSF) return TRUE;
     55    if (fields[i].ID == MEAS_X22_SM_PSF) return TRUE;
     56    if (fields[i].ID == MEAS_E1_SM_PSF)  return TRUE;
     57    if (fields[i].ID == MEAS_E2_SM_PSF)  return TRUE;
     58    if (fields[i].ID == MEAS_X11_SH_PSF) return TRUE;
     59    if (fields[i].ID == MEAS_X12_SH_PSF) return TRUE;
     60    if (fields[i].ID == MEAS_X22_SH_PSF) return TRUE;
     61    if (fields[i].ID == MEAS_E1_SH_PSF)  return TRUE;
     62    if (fields[i].ID == MEAS_E2_SH_PSF)  return TRUE;
     63  }
     64  return FALSE;
     65}
     66
     67int dbFieldNeedLensobj (dbField *fields, int Nfields) {
     68  int i;
     69  for (i = 0; i < Nfields; i++) {
     70    if (fields[i].magOption == MAG_OPTION_NONE) continue; // non-measure fields do not have a photcode
     71
     72    if (fields[i].magOption == MAG_OPTION_X11_SM_OBJ) return TRUE;
     73    if (fields[i].magOption == MAG_OPTION_X12_SM_OBJ) return TRUE;
     74    if (fields[i].magOption == MAG_OPTION_X22_SM_OBJ) return TRUE;
     75    if (fields[i].magOption == MAG_OPTION_E1_SM_OBJ)  return TRUE;
     76    if (fields[i].magOption == MAG_OPTION_E2_SM_OBJ)  return TRUE;
     77    if (fields[i].magOption == MAG_OPTION_X11_SH_OBJ) return TRUE;
     78    if (fields[i].magOption == MAG_OPTION_X12_SH_OBJ) return TRUE;
     79    if (fields[i].magOption == MAG_OPTION_X22_SH_OBJ) return TRUE;
     80    if (fields[i].magOption == MAG_OPTION_E1_SH_OBJ)  return TRUE;
     81    if (fields[i].magOption == MAG_OPTION_E2_SH_OBJ)  return TRUE;
     82    if (fields[i].magOption == MAG_OPTION_X11_SM_PSF) return TRUE;
     83    if (fields[i].magOption == MAG_OPTION_X12_SM_PSF) return TRUE;
     84    if (fields[i].magOption == MAG_OPTION_X22_SM_PSF) return TRUE;
     85    if (fields[i].magOption == MAG_OPTION_E1_SM_PSF)  return TRUE;
     86    if (fields[i].magOption == MAG_OPTION_E2_SM_PSF)  return TRUE;
     87    if (fields[i].magOption == MAG_OPTION_X11_SH_PSF) return TRUE;
     88    if (fields[i].magOption == MAG_OPTION_X12_SH_PSF) return TRUE;
     89    if (fields[i].magOption == MAG_OPTION_X22_SH_PSF) return TRUE;
     90    if (fields[i].magOption == MAG_OPTION_E1_SH_PSF)  return TRUE;
     91    if (fields[i].magOption == MAG_OPTION_E2_SH_PSF)  return TRUE;
     92  }
     93  return FALSE;
     94}
     95
     96int dbFieldNeedStarpar (dbField *fields, int Nfields, int isAverage) {
     97  int i;
     98  for (i = 0; i < Nfields; i++) {
     99    if (isAverage) {
     100      if (fields[i].ID == AVE_E_BV)             return TRUE;
     101      if (fields[i].ID == AVE_E_BV_ERR)         return TRUE;
     102      if (fields[i].ID == AVE_DISTANCE_MOD)     return TRUE;
     103      if (fields[i].ID == AVE_DISTANCE_MOD_ERR) return TRUE;
     104      if (fields[i].ID == AVE_M_R)              return TRUE;
     105      if (fields[i].ID == AVE_M_R_ERR)          return TRUE;
     106      if (fields[i].ID == AVE_FEH)              return TRUE;
     107      if (fields[i].ID == AVE_FEH_ERR)          return TRUE;
     108      if (fields[i].ID == AVE_URA_GALMODEL)     return TRUE;
     109      if (fields[i].ID == AVE_UDEC_GALMODEL)    return TRUE;
     110      if (fields[i].ID == AVE_RA_GALMODEL)      return TRUE;
     111      if (fields[i].ID == AVE_DEC_GALMODEL)     return TRUE;
     112    } else {
     113      if (fields[i].ID == MEAS_E_BV)             return TRUE;
     114      if (fields[i].ID == MEAS_E_BV_ERR)         return TRUE;
     115      if (fields[i].ID == MEAS_DISTANCE_MOD)     return TRUE;
     116      if (fields[i].ID == MEAS_DISTANCE_MOD_ERR) return TRUE;
     117      if (fields[i].ID == MEAS_M_R)              return TRUE;
     118      if (fields[i].ID == MEAS_M_R_ERR)          return TRUE;
     119      if (fields[i].ID == MEAS_FEH)              return TRUE;
     120      if (fields[i].ID == MEAS_FEH_ERR)          return TRUE;
     121      if (fields[i].ID == MEAS_URA_GALMODEL)     return TRUE;
     122      if (fields[i].ID == MEAS_UDEC_GALMODEL)    return TRUE;
     123      if (fields[i].ID == MEAS_RA_GALMODEL)      return TRUE;
     124      if (fields[i].ID == MEAS_DEC_GALMODEL)     return TRUE;
     125    }
     126  }
     127  return FALSE;
     128}
     129
    30130dvoMagSourceType GetMagSource (char *string) {
    31131
    32   if (!strcasecmp (string, "chip")) return (MAG_SRC_CHP);
    33   if (!strcasecmp (string, "warp")) return (MAG_SRC_WRP);
     132  if (!strcasecmp (string, "chip"))  return (MAG_SRC_CHP);
     133  if (!strcasecmp (string, "warp"))  return (MAG_SRC_WRP);
    34134  if (!strcasecmp (string, "stack")) return (MAG_SRC_STK);
    35135
     
    66166dvoMagOptionType GetMagOption (char *string) {
    67167
    68   if (!strcasecmp (string, "mag"))          return (MAG_OPTION_MAG);
    69   if (!strcasecmp (string, "err"))          return (MAG_OPTION_ERR);
    70   if (!strcasecmp (string, "magerr"))       return (MAG_OPTION_ERR);
    71   if (!strcasecmp (string, "flux"))         return (MAG_OPTION_FLUX);
    72   if (!strcasecmp (string, "fluxerr"))      return (MAG_OPTION_FLUX_ERR);
    73   if (!strcasecmp (string, "stdev"))        return (MAG_OPTION_STDEV);
    74   if (!strcasecmp (string, "chisq"))        return (MAG_OPTION_CHISQ);
    75   if (!strcasecmp (string, "min"))          return (MAG_OPTION_MIN);
    76   if (!strcasecmp (string, "max"))          return (MAG_OPTION_MAX);
    77   if (!strcasecmp (string, "ncode"))        return (MAG_OPTION_NCODE);
    78   if (!strcasecmp (string, "nphot"))        return (MAG_OPTION_NPHOT);
    79   if (!strcasecmp (string, "uc_dist"))      return (MAG_OPTION_UC_DIST);
    80   if (!strcasecmp (string, "flags"))        return (MAG_OPTION_FLAGS);
     168  if (!strcasecmp (string, "mag"))           return MAG_OPTION_MAG;
     169  if (!strcasecmp (string, "err"))           return MAG_OPTION_ERR;
     170  if (!strcasecmp (string, "magerr"))        return MAG_OPTION_ERR;
     171  if (!strcasecmp (string, "flux"))          return MAG_OPTION_FLUX;
     172  if (!strcasecmp (string, "fluxerr"))       return MAG_OPTION_FLUX_ERR;
     173  if (!strcasecmp (string, "stdev"))         return MAG_OPTION_STDEV;
     174  if (!strcasecmp (string, "chisq"))         return MAG_OPTION_CHISQ;
     175  if (!strcasecmp (string, "min"))           return MAG_OPTION_MIN;
     176  if (!strcasecmp (string, "max"))           return MAG_OPTION_MAX;
     177  if (!strcasecmp (string, "ncode"))         return MAG_OPTION_NCODE;
     178  if (!strcasecmp (string, "nphot"))         return MAG_OPTION_NPHOT;
     179  if (!strcasecmp (string, "uc_dist"))       return MAG_OPTION_UC_DIST;
     180  if (!strcasecmp (string, "flags"))         return MAG_OPTION_FLAGS;
     181  if (!strcasecmp (string, "X11_SM_OBJ"))    return MAG_OPTION_X11_SM_OBJ;
     182  if (!strcasecmp (string, "X12_SM_OBJ"))    return MAG_OPTION_X12_SM_OBJ;
     183  if (!strcasecmp (string, "X22_SM_OBJ"))    return MAG_OPTION_X22_SM_OBJ;
     184  if (!strcasecmp (string, "E1_SM_OBJ"))     return MAG_OPTION_E1_SM_OBJ;
     185  if (!strcasecmp (string, "E2_SM_OBJ"))     return MAG_OPTION_E2_SM_OBJ;
     186  if (!strcasecmp (string, "X11_SH_OBJ"))    return MAG_OPTION_X11_SH_OBJ;
     187  if (!strcasecmp (string, "X12_SH_OBJ"))    return MAG_OPTION_X12_SH_OBJ;
     188  if (!strcasecmp (string, "X22_SH_OBJ"))    return MAG_OPTION_X22_SH_OBJ;
     189  if (!strcasecmp (string, "E1_SH_OBJ"))     return MAG_OPTION_E1_SH_OBJ;
     190  if (!strcasecmp (string, "E2_SH_OBJ"))     return MAG_OPTION_E2_SH_OBJ;
     191  if (!strcasecmp (string, "X11_SM_PSF"))    return MAG_OPTION_X11_SM_PSF;
     192  if (!strcasecmp (string, "X12_SM_PSF"))    return MAG_OPTION_X12_SM_PSF;
     193  if (!strcasecmp (string, "X22_SM_PSF"))    return MAG_OPTION_X22_SM_PSF;
     194  if (!strcasecmp (string, "E1_SM_PSF"))     return MAG_OPTION_E1_SM_PSF;
     195  if (!strcasecmp (string, "E2_SM_PSF"))     return MAG_OPTION_E2_SM_PSF;
     196  if (!strcasecmp (string, "X11_SH_PSF"))    return MAG_OPTION_X11_SH_PSF;
     197  if (!strcasecmp (string, "X12_SH_PSF"))    return MAG_OPTION_X12_SH_PSF;
     198  if (!strcasecmp (string, "X22_SH_PSF"))    return MAG_OPTION_X22_SH_PSF;
     199  if (!strcasecmp (string, "E1_SH_PSF"))     return MAG_OPTION_E1_SH_PSF;
     200  if (!strcasecmp (string, "E2_SH_PSF"))     return MAG_OPTION_E2_SH_PSF;
     201  // if (!strcasecmp (string, "F_AP_R5"))       return MAG_OPTION_F_AP_R5;
     202  // if (!strcasecmp (string, "F_ERR_AP_R5"))   return MAG_OPTION_F_ERR_AP_R5;
     203  // if (!strcasecmp (string, "F_STDEV_AP_R5")) return MAG_OPTION_F_STDEV_AP_R5;
     204  // if (!strcasecmp (string, "F_FILL_AP_R5"))  return MAG_OPTION_F_FILL_AP_R5;
     205  // if (!strcasecmp (string, "F_AP_R6"))       return MAG_OPTION_F_AP_R6;
     206  // if (!strcasecmp (string, "F_ERR_AP_R6"))   return MAG_OPTION_F_ERR_AP_R6;
     207  // if (!strcasecmp (string, "F_STDEV_AP_R6")) return MAG_OPTION_F_STDEV_AP_R6;
     208  // if (!strcasecmp (string, "F_FILL_AP_R6"))  return MAG_OPTION_F_FILL_AP_R6;
    81209
    82210  return MAG_OPTION_NONE;
    83211}
    84 
    85 # if (0)
    86 int GetMagMode (char *string) {
    87 
    88   // these all imply PSF mags:
    89   if (!strcasecmp (string, "inst"))        return (MAG_INST);
    90   if (!strcasecmp (string, "cat"))         return (MAG_CAT);
    91   if (!strcasecmp (string, "sys"))         return (MAG_SYS);
    92   if (!strcasecmp (string, "rel"))         return (MAG_REL);
    93   if (!strcasecmp (string, "cal"))         return (MAG_CAL);
    94   if (!strcasecmp (string, "ave"))         return (MAG_AVE);
    95   if (!strcasecmp (string, "ref"))         return (MAG_REF);
    96   if (!strcasecmp (string, "err"))         return (MAG_ERR);
    97   if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
    98 
    99   // these are explicit PSF mags:
    100   if (!strcasecmp (string, "psf_inst"))    return (MAG_INST);
    101   if (!strcasecmp (string, "psf_cat"))     return (MAG_CAT);
    102   if (!strcasecmp (string, "psf_sys"))     return (MAG_SYS);
    103   if (!strcasecmp (string, "psf_rel"))     return (MAG_REL);
    104   if (!strcasecmp (string, "psf_cal"))     return (MAG_CAL);
    105   if (!strcasecmp (string, "psf_ave"))     return (MAG_AVE);
    106   if (!strcasecmp (string, "psf_ref"))     return (MAG_REF);
    107   if (!strcasecmp (string, "psf_err"))     return (MAG_ERR);
    108   if (!strcasecmp (string, "psf_aveerr"))  return (MAG_AVE_ERR);
    109 
    110   // these are aper mags:
    111   if (!strcasecmp (string, "ap"))          return (MAG_APER);
    112   if (!strcasecmp (string, "aper"))        return (MAG_APER);
    113   if (!strcasecmp (string, "aperinst"))    return (MAG_APER_INST);
    114   if (!strcasecmp (string, "aper_inst"))   return (MAG_APER_INST);
    115   if (!strcasecmp (string, "aper_cat"))    return (MAG_APER_CAT);
    116   if (!strcasecmp (string, "aper_sys"))    return (MAG_APER_SYS);
    117   if (!strcasecmp (string, "aper_rel"))    return (MAG_APER_REL);
    118   if (!strcasecmp (string, "aper_cal"))    return (MAG_APER_CAL);
    119   if (!strcasecmp (string, "aper_ave"))    return (MAG_APER_AVE);
    120   if (!strcasecmp (string, "aper_ref"))    return (MAG_APER_REF);
    121   if (!strcasecmp (string, "aper_err"))    return (MAG_APER_ERR);
    122 
    123   // these are kron mags:
    124   if (!strcasecmp (string, "kron"))        return (MAG_KRON);
    125   if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
    126   if (!strcasecmp (string, "kron_cat"))    return (MAG_KRON_CAT);
    127   if (!strcasecmp (string, "kron_sys"))    return (MAG_KRON_SYS);
    128   if (!strcasecmp (string, "kron_rel"))    return (MAG_KRON_REL);
    129   if (!strcasecmp (string, "kron_cal"))    return (MAG_KRON_CAL);
    130   if (!strcasecmp (string, "kron_ave"))    return (MAG_KRON_AVE);
    131   if (!strcasecmp (string, "kron_ref"))    return (MAG_KRON_REF);
    132   if (!strcasecmp (string, "kron_err"))    return (MAG_KRON_ERR);
    133   if (!strcasecmp (string, "kroninst"))    return (MAG_KRON_INST);
    134   if (!strcasecmp (string, "kronerr"))     return (MAG_KRON_ERR);
    135 
    136   // other fields:
    137   if (!strcasecmp (string, "photflags"))   return (MAG_PHOT_FLAGS);
    138   if (!strcasecmp (string, "flags"))       return (MAG_PHOT_FLAGS);
    139   if (!strcasecmp (string, "chisq"))       return (MAG_CHISQ);
    140   if (!strcasecmp (string, "ncode"))       return (MAG_NCODE);
    141   if (!strcasecmp (string, "nphot"))       return (MAG_NPHOT);
    142   if (!strcasecmp (string, "stdev"))       return (MAG_STDEV);
    143   if (!strcasecmp (string, "min"))         return (MAG_MIN);
    144   if (!strcasecmp (string, "max"))         return (MAG_MAX);
    145   if (!strcasecmp (string, "ucdist"))      return (MAG_UC_DIST);
    146   if (!strcasecmp (string, "fluxpsf"))     return (MAG_FLUX_PSF);
    147   if (!strcasecmp (string, "fluxpsferr"))  return (MAG_FLUX_PSF_ERR);
    148   if (!strcasecmp (string, "fluxkron"))    return (MAG_FLUX_KRON);
    149   if (!strcasecmp (string, "fluxkronerr")) return (MAG_FLUX_KRON_ERR);
    150   return (MAG_NONE);
    151 }
    152 # endif
    153212
    154213// field may be of the form mag:psf:inst:wrp.  except for the first subword,
     
    285344    fprintf (stderr, "ERROR: unknown mag/photocode argument %s\n", word);
    286345    free (word);
     346    return FALSE;
    287347  }
    288348
     
    414474  if (!strcasecmp (fieldName, "XFIX"))           ESCAPE (MEAS_XFIX,           OPIHI_FLT);
    415475  if (!strcasecmp (fieldName, "YFIX"))           ESCAPE (MEAS_YFIX,           OPIHI_FLT);
     476  if (!strcasecmp (fieldName, "XOFF_KH"))        ESCAPE (MEAS_XOFF_KH,        OPIHI_FLT);
     477  if (!strcasecmp (fieldName, "YOFF_KH"))        ESCAPE (MEAS_YOFF_KH,        OPIHI_FLT);
     478  if (!strcasecmp (fieldName, "XOFF_DCR"))       ESCAPE (MEAS_XOFF_DCR,       OPIHI_FLT);
     479  if (!strcasecmp (fieldName, "YOFF_DCR"))       ESCAPE (MEAS_YOFF_DCR,       OPIHI_FLT);
     480  if (!strcasecmp (fieldName, "ROFF_GAL"))       ESCAPE (MEAS_ROFF_GAL,       OPIHI_FLT);
     481  if (!strcasecmp (fieldName, "DOFF_GAL"))       ESCAPE (MEAS_DOFF_GAL,       OPIHI_FLT);
    416482  if (!strcasecmp (fieldName, "POS_SYS_ERR"))    ESCAPE (MEAS_POS_SYS_ERR,    OPIHI_FLT);
    417483  if (!strcasecmp (fieldName, "XFIELD"))         ESCAPE (MEAS_XFIELD,         OPIHI_FLT);
     
    441507  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
    442508  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
    443   // if (!strcasecmp (fieldName, "FLUX"))                ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     509
     510  // individual lensing measurements are not grouped by photcode:
     511  if (!strcasecmp (fieldName, "X11_SM_OBJ"))     ESCAPE (MEAS_X11_SM_OBJ,  OPIHI_FLT);
     512  if (!strcasecmp (fieldName, "X12_SM_OBJ"))     ESCAPE (MEAS_X12_SM_OBJ,  OPIHI_FLT);
     513  if (!strcasecmp (fieldName, "X22_SM_OBJ"))     ESCAPE (MEAS_X22_SM_OBJ,  OPIHI_FLT);
     514  if (!strcasecmp (fieldName, "E1_SM_OBJ"))      ESCAPE (MEAS_E1_SM_OBJ,  OPIHI_FLT);
     515  if (!strcasecmp (fieldName, "E2_SM_OBJ"))      ESCAPE (MEAS_E2_SM_OBJ,  OPIHI_FLT);
     516  if (!strcasecmp (fieldName, "X11_SH_OBJ"))     ESCAPE (MEAS_X11_SH_OBJ,  OPIHI_FLT);
     517  if (!strcasecmp (fieldName, "X12_SH_OBJ"))     ESCAPE (MEAS_X12_SH_OBJ,  OPIHI_FLT);
     518  if (!strcasecmp (fieldName, "X22_SH_OBJ"))     ESCAPE (MEAS_X22_SH_OBJ,  OPIHI_FLT);
     519  if (!strcasecmp (fieldName, "E1_SH_OBJ"))      ESCAPE (MEAS_E1_SH_OBJ,  OPIHI_FLT);
     520  if (!strcasecmp (fieldName, "E2_SH_OBJ"))      ESCAPE (MEAS_E2_SH_OBJ,  OPIHI_FLT);
     521  if (!strcasecmp (fieldName, "X11_SM_PSF"))     ESCAPE (MEAS_X11_SM_PSF,  OPIHI_FLT);
     522  if (!strcasecmp (fieldName, "X12_SM_PSF"))     ESCAPE (MEAS_X12_SM_PSF,  OPIHI_FLT);
     523  if (!strcasecmp (fieldName, "X22_SM_PSF"))     ESCAPE (MEAS_X22_SM_PSF,  OPIHI_FLT);
     524  if (!strcasecmp (fieldName, "E1_SM_PSF"))      ESCAPE (MEAS_E1_SM_PSF,  OPIHI_FLT);
     525  if (!strcasecmp (fieldName, "E2_SM_PSF"))      ESCAPE (MEAS_E2_SM_PSF,  OPIHI_FLT);
     526  if (!strcasecmp (fieldName, "X11_SH_PSF"))     ESCAPE (MEAS_X11_SH_PSF,  OPIHI_FLT);
     527  if (!strcasecmp (fieldName, "X12_SH_PSF"))     ESCAPE (MEAS_X12_SH_PSF,  OPIHI_FLT);
     528  if (!strcasecmp (fieldName, "X22_SH_PSF"))     ESCAPE (MEAS_X22_SH_PSF,  OPIHI_FLT);
     529  if (!strcasecmp (fieldName, "E1_SH_PSF"))      ESCAPE (MEAS_E1_SH_PSF,  OPIHI_FLT);
     530  if (!strcasecmp (fieldName, "E2_SH_PSF"))      ESCAPE (MEAS_E2_SH_PSF,  OPIHI_FLT);
     531
     532  if (!strcasecmp (fieldName, "E_BV"))             ESCAPE (MEAS_E_BV          ,   OPIHI_FLT);
     533  if (!strcasecmp (fieldName, "E_BV_ERR"))         ESCAPE (MEAS_E_BV_ERR      ,   OPIHI_FLT);
     534  if (!strcasecmp (fieldName, "DISTANCE_MOD"))     ESCAPE (MEAS_DISTANCE_MOD  ,   OPIHI_FLT);
     535  if (!strcasecmp (fieldName, "DISTANCE_MOD_ERR")) ESCAPE (MEAS_DISTANCE_MOD_ERR, OPIHI_FLT);
     536  if (!strcasecmp (fieldName, "D_M"))              ESCAPE (MEAS_DISTANCE_MOD  ,   OPIHI_FLT);
     537  if (!strcasecmp (fieldName, "D_M_ERR"))          ESCAPE (MEAS_DISTANCE_MOD_ERR, OPIHI_FLT);
     538  if (!strcasecmp (fieldName, "M_R"))              ESCAPE (MEAS_M_R           ,   OPIHI_FLT);
     539  if (!strcasecmp (fieldName, "M_R_ERR"))          ESCAPE (MEAS_M_R_ERR       ,   OPIHI_FLT);
     540  if (!strcasecmp (fieldName, "FEH"))              ESCAPE (MEAS_FEH           ,   OPIHI_FLT);
     541  if (!strcasecmp (fieldName, "FEH_ERR"))          ESCAPE (MEAS_FEH_ERR       ,   OPIHI_FLT);
     542  if (!strcasecmp (fieldName, "URA_GALMODEL"))     ESCAPE (MEAS_URA_GALMODEL  ,   OPIHI_FLT);
     543  if (!strcasecmp (fieldName, "UDEC_GALMODEL"))    ESCAPE (MEAS_UDEC_GALMODEL ,   OPIHI_FLT);
     544  if (!strcasecmp (fieldName, "RA_GALMODEL"))      ESCAPE (MEAS_RA_GALMODEL   ,   OPIHI_FLT);
     545  if (!strcasecmp (fieldName, "DEC_GALMODEL"))     ESCAPE (MEAS_DEC_GALMODEL  ,   OPIHI_FLT);
     546  if (!strcasecmp (fieldName, "URA_GAL"))          ESCAPE (MEAS_URA_GALMODEL  ,   OPIHI_FLT);
     547  if (!strcasecmp (fieldName, "UDEC_GAL"))         ESCAPE (MEAS_UDEC_GALMODEL ,   OPIHI_FLT);
     548  if (!strcasecmp (fieldName, "RA_GAL"))           ESCAPE (MEAS_RA_GALMODEL   ,   OPIHI_FLT);
     549  if (!strcasecmp (fieldName, "DEC_GAL"))          ESCAPE (MEAS_DEC_GALMODEL  ,   OPIHI_FLT);
     550
     551  // if (!strcasecmp (fieldName, "FLUX"))           ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
    444552  // if (!strcasecmp (fieldName, "FLUX_ERR"))       ESCAPE (MEAS_FLUX_PSF_ERR,   OPIHI_FLT);
    445553  // if (!strcasecmp (fieldName, "FLUX_PSF"))       ESCAPE (MEAS_FLUX_PSF,       OPIHI_FLT);
     
    447555  // if (!strcasecmp (fieldName, "FLUX_KRON"))      ESCAPE (MEAS_FLUX_KRON,      OPIHI_FLT);
    448556  // if (!strcasecmp (fieldName, "FLUX_KRON_ERR"))  ESCAPE (MEAS_FLUX_KRON_ERR,  OPIHI_FLT);
    449   if (!strcasecmp (fieldName, "REF_COLOR"))      ESCAPE (MEAS_REF_COLOR,      OPIHI_FLT);
     557  if (!strcasecmp (fieldName, "REF_COLOR_BLUE"))    ESCAPE (MEAS_REF_COLOR_BLUE, OPIHI_FLT);
     558  if (!strcasecmp (fieldName, "REF_COLOR_RED"))     ESCAPE (MEAS_REF_COLOR_RED,  OPIHI_FLT);
    450559
    451560  // for words that don't parse, try a photcode
     
    522631  if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    OPIHI_INT);
    523632  if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    OPIHI_INT);
    524   if (!strcasecmp (fieldName, "REF_COLOR"))   ESCAPE (AVE_REF_COLOR,   OPIHI_FLT);
     633  if (!strcasecmp (fieldName, "REF_COLOR_BLUE")) ESCAPE (AVE_REF_COLOR_BLUE, OPIHI_FLT);
     634  if (!strcasecmp (fieldName, "REF_COLOR_RED"))  ESCAPE (AVE_REF_COLOR_RED,  OPIHI_FLT);
     635
     636  if (!strcasecmp (fieldName, "E_BV"))             ESCAPE (AVE_E_BV          ,   OPIHI_FLT);
     637  if (!strcasecmp (fieldName, "E_BV_ERR"))         ESCAPE (AVE_E_BV_ERR      ,   OPIHI_FLT);
     638  if (!strcasecmp (fieldName, "DISTANCE_MOD"))     ESCAPE (AVE_DISTANCE_MOD  ,   OPIHI_FLT);
     639  if (!strcasecmp (fieldName, "DISTANCE_MOD_ERR")) ESCAPE (AVE_DISTANCE_MOD_ERR, OPIHI_FLT);
     640  if (!strcasecmp (fieldName, "M_R"))              ESCAPE (AVE_M_R           ,   OPIHI_FLT);
     641  if (!strcasecmp (fieldName, "M_R_ERR"))          ESCAPE (AVE_M_R_ERR       ,   OPIHI_FLT);
     642  if (!strcasecmp (fieldName, "FEH"))              ESCAPE (AVE_FEH           ,   OPIHI_FLT);
     643  if (!strcasecmp (fieldName, "FEH_ERR"))          ESCAPE (AVE_FEH_ERR       ,   OPIHI_FLT);
     644  if (!strcasecmp (fieldName, "URA_GALMODEL"))     ESCAPE (AVE_URA_GALMODEL  ,   OPIHI_FLT);
     645  if (!strcasecmp (fieldName, "UDEC_GALMODEL"))    ESCAPE (AVE_UDEC_GALMODEL ,   OPIHI_FLT);
     646  if (!strcasecmp (fieldName, "RA_GALMODEL"))      ESCAPE (AVE_RA_GALMODEL   ,   OPIHI_FLT);
     647  if (!strcasecmp (fieldName, "DEC_GALMODEL"))     ESCAPE (AVE_DEC_GALMODEL  ,   OPIHI_FLT);
     648
    525649
    526650  // check for code:mode in photcode name
     
    652776  if (!strcasecmp (fieldName, "NLINK_PHOTOM")) ESCAPE (IMAGE_NLINK_PHOTOM, OPIHI_INT);
    653777  if (!strcasecmp (fieldName, "NLINK_ASTROM")) ESCAPE (IMAGE_NLINK_ASTROM, OPIHI_INT);
    654   if (!strcasecmp (fieldName, "REF_COLOR"))    ESCAPE (IMAGE_REF_COLOR,    OPIHI_FLT);
     778  if (!strcasecmp (fieldName, "REF_COLOR_BLUE")) ESCAPE (IMAGE_REF_COLOR_BLUE, OPIHI_FLT);
     779  if (!strcasecmp (fieldName, "REF_COLOR_RED"))  ESCAPE (IMAGE_REF_COLOR_RED,  OPIHI_FLT);
    655780
    656781  // for words that don't parse, try a photcode
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r37356 r37807  
    5858  if (!strcasecmp (catformat, "PS1_V5"))          return (DVO_FORMAT_PS1_V5);
    5959  if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
     60  if (!strcasecmp (catformat, "PS1_SIM"))         return (DVO_FORMAT_PS1_SIM);
    6061  return (DVO_FORMAT_UNDEF);
    6162}
     
    129130  average->Nlensing        = 0;
    130131  average->Nlensobj        = 0;
     132  average->Nstarpar        = 0;
    131133  average->Nextend         = 0;
    132134
     
    135137  average->lensingOffset   = -1;
    136138  average->lensobjOffset   = -1;
     139  average->starparOffset   = -1;
    137140  average->extendOffset    = -1;
    138   average->paramsOffset    = -1;
    139141
    140142  average->refColorBlue    = NAN;
     
    144146  average->skycellID       = 0;
    145147  average->projectionID    = 0;
     148
    146149  average->dummy           = 0;
    147150
     
    437440
    438441// init all data, or just catalog data
     442void dvo_starpar_init (StarPar *starpar) {
     443  starpar->R        = NAN;
     444  starpar->D        = NAN;
     445  starpar->galLat   = NAN;
     446  starpar->galLon   = NAN;
     447  starpar->Ebv      = NAN;
     448  starpar->dEbv     = NAN;
     449  starpar->DistMag  = NAN;
     450  starpar->dDistMag = NAN;
     451  starpar->M_r      = NAN;
     452  starpar->dM_r     = NAN;
     453  starpar->FeH      = NAN;
     454  starpar->dFeH     = NAN;
     455  starpar->uRA      = NAN;
     456  starpar->uDEC     = NAN;
     457  starpar->averef   = -1;
     458  starpar->objID    = -1;
     459  starpar->catID    = -1;
     460}
     461
     462// init all data, or just catalog data
    439463void dvo_catalog_init (Catalog *catalog, int complete) {
    440464
     
    462486  catalog[0].lensobj = NULL;
    463487
     488  catalog[0].starpar = NULL;
     489
    464490  catalog[0].averageT = NULL;
    465491  catalog[0].measureT = NULL;
     
    477503  catalog[0].Nlensobj = 0;
    478504
     505  catalog[0].Nstarpar = 0;
     506
    479507  catalog[0].Naves_disk = 0;
    480508  catalog[0].Nmeas_disk = 0;
     
    485513  catalog[0].Nlensobj_disk = 0;
    486514
     515  catalog[0].Nstarpar_disk = 0;
     516
    487517  catalog[0].Naves_off  = 0;
    488518  catalog[0].Nmeas_off  = 0;
     
    492522  catalog[0].Nlensing_off  = 0;
    493523  catalog[0].Nlensobj_off  = 0;
     524
     525  catalog[0].Nstarpar_off  = 0;
    494526
    495527  /* pointers to SPLIT data files */
     
    499531  catalog[0].lensing_catalog = NULL;
    500532  catalog[0].lensobj_catalog = NULL;
     533  catalog[0].starpar_catalog = NULL;
    501534
    502535  /* pointers for data manipulation */
     
    540573
    541574  if (catalog[0].f == (FILE *) NULL) return (2);
    542   fflush (catalog[0].f);
     575
     576  if (fflush (catalog[0].f)) {
     577    fprintf (stderr, "failed to flush file\n");
     578    return FALSE;
     579  }
     580
    543581  // fprintf (stderr, "unlocking: %s\n", catalog[0].filename);
    544582
     
    552590
    553591  // closes f but does not set back to NULL
    554   fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate);
     592  if (!fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate)) {
     593    fprintf (stderr, "failed to unlock or close file\n");
     594    return (0);
     595  }
    555596
    556597  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    557     if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
    558     if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
    559     if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
    560     if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
    561     if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
     598    if (catalog[0].measure_catalog) { if (!dvo_catalog_unlock (catalog[0].measure_catalog)) { fprintf (stderr, "failed to unlock measures\n"); return (0); }}
     599    if (catalog[0].missing_catalog) { if (!dvo_catalog_unlock (catalog[0].missing_catalog)) { fprintf (stderr, "failed to unlock missing\n"); return (0); }}
     600    if (catalog[0].secfilt_catalog) { if (!dvo_catalog_unlock (catalog[0].secfilt_catalog)) { fprintf (stderr, "failed to unlock secfilt\n"); return (0); }}
     601    if (catalog[0].lensing_catalog) { if (!dvo_catalog_unlock (catalog[0].lensing_catalog)) { fprintf (stderr, "failed to unlock lensing\n"); return (0); }}
     602    if (catalog[0].lensobj_catalog) { if (!dvo_catalog_unlock (catalog[0].lensobj_catalog)) { fprintf (stderr, "failed to unlock lensobj\n"); return (0); }}
     603    if (catalog[0].starpar_catalog) { if (!dvo_catalog_unlock (catalog[0].starpar_catalog)) { fprintf (stderr, "failed to unlock starpar\n"); return (0); }}
    562604  }
    563605  return (1);
     
    597639  }
    598640 
     641  // NOTE: this only check if we can write a backup; it does not actually write the backup
    599642  if (!check_file_access (catalog[0].filename, BACKUP, READWRITE, VERBOSE)) {
    600643    fprintf (stderr, "no permission to access %s\n", catalog[0].filename);
     
    835878      free (catalog[0].lensobj_catalog);
    836879    }
     880    if (catalog[0].starpar_catalog) {
     881      free (catalog[0].starpar_catalog[0].filename);
     882      dvo_catalog_free (catalog[0].starpar_catalog);
     883      free (catalog[0].starpar_catalog);
     884    }
    837885  }
    838886  dvo_catalog_free_data (catalog);
     
    873921    catalog[0].Nlensobj = 0;
    874922    catalog[0].lensobj = NULL;
     923  }
     924  if (catalog[0].starpar) {
     925    free (catalog[0].starpar);
     926    catalog[0].Nstarpar = 0;
     927    catalog[0].starpar = NULL;
    875928  }
    876929  if (catalog[0].nOwn_t)      { free (catalog[0].nOwn_t); catalog[0].nOwn_t = NULL; }
     
    9851038      }
    9861039    }
     1040    if (catalog[0].starpar_catalog != NULL) {
     1041      if (catalog[0].Nstarpar_disk == 0) {
     1042        // need to relock (and re-open) file for close elsewhere
     1043        status = dvo_catalog_lock (catalog[0].starpar_catalog, lockmode);
     1044      } else {
     1045        if (!dvo_catalog_backup (catalog[0].starpar_catalog, FALSE)) {
     1046          return FALSE;
     1047        }
     1048      }
     1049    }
    9871050  }
    9881051  return TRUE;
     
    10361099      }
    10371100    }
     1101    if ((catalog[0].starpar_catalog != NULL) && (catalog[0].Nstarpar_disk > 0)) {
     1102      if (!dvo_catalog_unlink_backup (catalog[0].starpar_catalog, FALSE)) {
     1103        return FALSE;
     1104      }
     1105    }
    10381106  }
    10391107  return TRUE;
  • trunk/Ohana/src/libdvo/src/dvo_catalog_create.c

    r37035 r37807  
    9595    free (file);
    9696
     97    /* define starpar catalog file */
     98    ALLOCATE (catalog[0].starpar_catalog, Catalog, 1);
     99    dvo_catalog_init (catalog[0].starpar_catalog, TRUE);
     100
     101    /* create basic data for starpar catalog file */
     102    gfits_create_header (&catalog[0].starpar_catalog[0].header);
     103    ALLOCATE (catalog[0].starpar_catalog[0].filename, char, length);
     104    sprintf (catalog[0].starpar_catalog[0].filename, "%s/%s.cpz", path, root);
     105    file = filebasename (catalog[0].starpar_catalog[0].filename);
     106    gfits_modify (&catalog[0].header, "STARPAR", "%s", 1, file);
     107    free (file);
     108
    97109    free (path);
    98110    free (root);
     
    117129    }
    118130    if (dvo_catalog_lock (catalog[0].lensobj_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
     131      fprintf (stderr, "error with file lock\n");
     132      exit (2);
     133    }
     134    if (dvo_catalog_lock (catalog[0].starpar_catalog, catalog[0].lockmode) != DVO_CAT_OPEN_EMPTY) {
    119135      fprintf (stderr, "error with file lock\n");
    120136      exit (2);
     
    146162  ALLOCATE (catalog[0].lensing, Lensing, 1);
    147163  ALLOCATE (catalog[0].lensobj, Lensobj, 1);
     164  ALLOCATE (catalog[0].starpar, StarPar, 1);
    148165
    149166  /* setup secondary filters to match photcodes:
  • trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r37035 r37807  
    44 
    55  off_t Nbytes;
    6   off_t Naverage;
    7   off_t Nmeasure;
    8   off_t Nmissing;
    9   off_t Nlensing;
    10   off_t Nlensobj;
    116  off_t Nitems, Nexpect;
    127  int Nsecfilt;
     
    1813
    1914  ftable.header = &header;
    20 
    21   /* get the components from the header */
    22   if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
    23   if (!gfits_scan (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  &Nmeasure)) return (FALSE);
    24   if (!gfits_scan (&catalog[0].header, "NMISS",    OFF_T_FMT, 1,  &Nmissing)) return (FALSE);
    25   if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d",   1,               &Nsecfilt)) Nsecfilt = 0;
    26   if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) return (FALSE);
    27   if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) return (FALSE);
    2815
    2916  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    3825    catalog[0].catID = 0;
    3926  }
     27
     28  // NSTARS, average, Naves_disk
     29
     30# define GET_TABLE_SIZES(HFIELD, CFIELD, DFIELD, REQUIRED)              \
     31  off_t N##CFIELD;                                                      \
     32  if (REQUIRED) {                                                       \
     33    if (!gfits_scan (&catalog[0].header, HFIELD, OFF_T_FMT, 1, &N##CFIELD)) return (FALSE); \
     34  } else {                                                              \
     35    if (!gfits_scan (&catalog[0].header, HFIELD, OFF_T_FMT, 1, &N##CFIELD)) N##CFIELD = 0; \
     36  }                                                                     \
     37  /* save the current number so we can do partial updates */            \
     38  catalog[0].DFIELD = N##CFIELD;                                        \
     39  /* default values, but we will assign these a valid value before we exit (even if empty) */ \
     40  catalog[0].CFIELD = NULL;
    4041 
    41   /* save the current number so we can do partial updates */
    42   catalog[0].Naves_disk = Naverage;
    43   catalog[0].Nmeas_disk = Nmeasure;
    44   catalog[0].Nmiss_disk = Nmissing;
    45   catalog[0].Nsecf_disk = Naverage * Nsecfilt;
    46   catalog[0].Nlensing_disk = Nlensing;
    47   catalog[0].Nlensobj_disk = Nlensobj;
     42  /* get the components and sizes from the header */
     43  GET_TABLE_SIZES ("NSTARS",   average, Naves_disk,    TRUE);
     44  GET_TABLE_SIZES ("NMEAS",    measure, Nmeas_disk,    TRUE);
     45  GET_TABLE_SIZES ("NMISS",    missing, Nmiss_disk,    FALSE);
     46  GET_TABLE_SIZES ("NLENSING", lensing, Nlensing_disk, FALSE);
     47  GET_TABLE_SIZES ("NLENSOBJ", lensobj, Nlensobj_disk, FALSE);
     48  GET_TABLE_SIZES ("NSTARPAR", starpar, Nstarpar_disk, FALSE);
    4849
    4950  /**  Nsecfilt is unusual: it does not list the number of data items in the table
    5051       instead, the number of items is Nsecfilt * Naverage.  **/
     52
     53  if (!gfits_scan (&catalog[0].header, "NSECFILT", "%d", 1, &Nsecfilt)) Nsecfilt = 0;
    5154  catalog[0].Nsecfilt = Nsecfilt;
    52 
    53   /* default values, but we will assign these a valid value before we exit (even if empty) */
    54   catalog[0].average = NULL;
    55   catalog[0].measure = NULL;
    56   catalog[0].missing = NULL;
     55  catalog[0].Nsecf_disk = Naverage * Nsecfilt;
    5756  catalog[0].secfilt = NULL;
    58   catalog[0].lensing = NULL;
    59   catalog[0].lensobj = NULL;
    60 
    61   /* validate table mode ?*/
    6257
    6358  /*** Average Table ***/
     
    259254  }
    260255
     256  /* read StarPar table header */
     257  if (!gfits_fread_header (catalog[0].f, &header)) {
     258    if (VERBOSE) fprintf (stderr, "can't read table starpar header");
     259    return (FALSE);
     260  }
     261  /* read StarPar table data */
     262  if (catalog[0].catflags & LOAD_STARPAR) {
     263    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
     264      if (VERBOSE) fprintf (stderr, "can't read table starpar data");
     265      return (FALSE);
     266    }
     267    catalog[0].starpar = FtableToStarPar (&ftable, &catalog[0].Nstarpar, &catalog[0].catformat);
     268    if (Nstarpar != catalog[0].Nstarpar_disk) {
     269      fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  catalog[0].Nstarpar_disk);
     270    }
     271    catalog[0].Nstarpar = catalog[0].Nstarpar_disk;
     272    catalog[0].Nstarpar_off = 0;
     273  } else {
     274    Nbytes = gfits_data_size (&header);
     275    fseeko (catalog[0].f, Nbytes, SEEK_CUR);
     276    ALLOCATE (catalog[0].starpar, StarPar, 1);
     277    catalog[0].Nstarpar = 0;
     278    catalog[0].Nstarpar_off = catalog[0].Nstarpar_disk;
     279  }
     280
    261281  return (TRUE);
    262282}
     
    309329  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  catalog[0].Nlensing);
    310330  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  catalog[0].Nlensobj);
     331  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  catalog[0].Nstarpar);
    311332  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    312333  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    403424  /* write out Lensobj table (convert to FITS table format) */
    404425  LensobjToFtable (&ftable, catalog[0].lensobj, catalog[0].Nlensobj, catalog[0].catformat);
     426  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
     427    fprintf (stderr, "can't write table header");
     428    goto failure;
     429  }
     430  if (!gfits_fwrite_table (catalog[0].f, &ftable)) {
     431    fprintf (stderr, "can't write table data");
     432    goto failure;
     433  }
     434  gfits_free_table (&ftable);
     435  gfits_free_header (&header);
     436
     437  /* free temp storage */
     438  if (primary != NULL) {
     439    free (primary);
     440    free (secfilt);
     441  }
     442  return (TRUE);
     443
     444  /* write out StarPar table (convert to FITS table format) */
     445  StarParToFtable (&ftable, catalog[0].starpar, catalog[0].Nstarpar, catalog[0].catformat);
    405446  if (!gfits_fwrite_Theader (catalog[0].f, &header)) {
    406447    fprintf (stderr, "can't write table header");
     
    446487  lensobj header
    447488  lensobj table
     489  starpar header
     490  starpar table
    448491*/
    449492   
  • trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r37035 r37807  
    9292      FORMAT_CASE (PS1_V5,    PS1_V5);
    9393      FORMAT_CASE (PS1_REF,   PS1_REF);
     94      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    9495
    9596    default:
     
    287288  if (catalog[0].catformat == DVO_FORMAT_PS1_V5)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V5");
    288289  if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
     290  if (catalog[0].catformat == DVO_FORMAT_PS1_SIM)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_SIM");
    289291
    290292  /* rewind file pointers and truncate file */
     
    391393      FORMAT_CASE (PS1_V5,    PS1_V5);
    392394      FORMAT_CASE (PS1_REF,   PS1_REF);
     395      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    393396
    394397    default:
     
    443446      FORMAT_CASE (PS1_V5,    PS1_V5);
    444447      FORMAT_CASE (PS1_REF,   PS1_REF);
     448      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    445449
    446450    default:
     
    498502      FORMAT_CASE (PS1_V5,    PS1_V5);
    499503      FORMAT_CASE (PS1_REF,   PS1_REF);
     504      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    500505
    501506    default:
     
    550555      FORMAT_CASE (PS1_V5,    PS1_V5);
    551556      FORMAT_CASE (PS1_REF,   PS1_REF);
     557      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    552558
    553559    default:
     
    606612      FORMAT_CASE (PS1_V5,    PS1_V5);
    607613      FORMAT_CASE (PS1_REF,   PS1_REF);
     614      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    608615
    609616    default:
     
    658665      FORMAT_CASE (PS1_V5,    PS1_V5);
    659666      FORMAT_CASE (PS1_REF,   PS1_REF);
     667      FORMAT_CASE (PS1_SIM,   PS1_SIM);
    660668
    661669    default:
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r37035 r37807  
    7575  Matrix matrix;
    7676
     77  // ohana_memcheck_func (TRUE);
     78 
     79
     80  if (0) {
     81    // XXX a TEST : is the data corrupted or the file?
     82    char name[1024];
     83    snprintf (name, 1024, "%s.phu.v2", catalog->filename);
     84    FILE *f = fopen (name, "w");
     85    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     86    // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     87    // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     88    //       catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     89    //       catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     90    fclose (f);
     91  }
     92  if (0) {
     93    // XXX a TEST : is the data corrupted or the file?
     94    char name[1024];
     95    snprintf (name, 1024, "%s.phu", catalog->filename);
     96    FILE *f = fopen (name, "w");
     97    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     98    // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     99    // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     100    //       catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     101    //       catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     102    fclose (f);
     103  }
     104# if (0)
     105  {
     106    // XXX a TEST : is the data corrupted or the file?
     107    char name[1024];
     108    snprintf (name, 1024, "%s.phu.v2", catalog->filename);
     109    FILE *f = fopen (name, "w");
     110    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     111    fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     112    fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     113             catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     114             catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     115    fclose (f);
     116  }
     117  {
     118    // XXX a TEST : is the data corrupted or the file?
     119    char name[1024];
     120    snprintf (name, 1024, "%s.phu.v3", catalog->filename);
     121    FILE *f = fopen (name, "w");
     122    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
     123    fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
     124    fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n",
     125             catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3],
     126             catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
     127    fclose (f);
     128  }
     129# endif
    77130  /* rewind file pointers and truncate (file is still open) */
    78   fseeko (catalog->f, 0LL, SEEK_SET);
     131  if (fseeko (catalog->f, 0LL, SEEK_SET)) {
     132    perror ("dvo_catalog_save_subset: ");
     133    fprintf (stderr, "failed to seek to beginning\n");
     134  }
    79135
    80136  // write PHU header
     
    134190  if (!gfits_scan (&catalog[0].header, name,  "%s", 1, string)) {
    135191    free (path);
    136     // databases created prior to ~2014.07.01 did not have the LENSING or LENSOBJ paths in their headers.
     192    // databases created prior to ~2014.07.01 did not have the LENSING, LENSOBJ, STARPAR paths in their headers.
    137193    // in these cases, we do not try to lock or open the relevant file
    138194    if (!strcmp (name, "LENSING")) return (DVO_CAT_OPEN_EMPTY);
    139195    if (!strcmp (name, "LENSOBJ")) return (DVO_CAT_OPEN_EMPTY);
     196    if (!strcmp (name, "STARPAR")) return (DVO_CAT_OPEN_EMPTY);
    140197    return (DVO_CAT_OPEN_FAIL);
    141198  }
     
    182239  off_t Nlensing;
    183240  off_t Nlensobj;
     241  off_t Nstarpar;
    184242  off_t Nitems;
    185243  int status, Nsecfilt;
     
    196254
    197255  /* get the components from the header - these duplicate information in the split files (NAXIS2) */
    198   // NSTARS, NMEAS, NMISS are required; NLENSING, NLENSOBJ are not (0 if not found)
     256  // NSTARS, NMEAS, NMISS are required; NLENSING, NLENSOBJ, NSTARPAR are not (0 if not found)
    199257  if (!gfits_scan (&catalog[0].header, "NSTARS",   OFF_T_FMT, 1,  &Naverage)) return (FALSE);
    200258  if (!gfits_scan (&catalog[0].header, "NMEAS",    OFF_T_FMT, 1,  &Nmeasure)) return (FALSE);
     
    203261  if (!gfits_scan (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  &Nlensing)) Nlensing = 0;
    204262  if (!gfits_scan (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  &Nlensobj)) Nlensobj = 0;
     263  if (!gfits_scan (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  &Nstarpar)) Nstarpar = 0;
    205264
    206265  /* the OBJID is a counter that uniquely defines an average entry and never changes.  if
     
    223282  catalog[0].Nlensing_disk = Nlensing;
    224283  catalog[0].Nlensobj_disk = Nlensobj;
     284  catalog[0].Nstarpar_disk = Nstarpar;
    225285
    226286  /**  Nsecfilt is unusual: it does not list the number of data items in the table
     
    235295  catalog[0].lensing = NULL;
    236296  catalog[0].lensobj = NULL;
     297  catalog[0].starpar = NULL;
    237298
    238299  /*** Average Table ***/
     
    348409  /*** Secfilt Table ***/
    349410  status = dvo_catalog_open_subcat (catalog, &catalog[0].secfilt_catalog, ftable.header, "SECFILT", VERBOSE);
     411  // fprintf (stderr, "secfilt header %s : %zx\n", catalog[0].secfilt_catalog[0].filename, (size_t) catalog[0].secfilt_catalog[0].header.buffer);
    350412  if (status == DVO_CAT_OPEN_FAIL) {
    351413    return (FALSE);
     
    465527  gfits_free_header (&header);
    466528
     529  /*** StarPar Table ***/
     530  if (!(catalog[0].catflags & SKIP_STARPAR)) {
     531    // unless we specify 'skip', we still need to load the
     532    status = dvo_catalog_open_subcat (catalog, &catalog[0].starpar_catalog, ftable.header, "STARPAR", VERBOSE);
     533    if (status == DVO_CAT_OPEN_FAIL) {
     534      return (FALSE);
     535    }
     536    // the StarPar file need not exist, unless we expect data to exist
     537    if ((status == DVO_CAT_OPEN_EMPTY) && (catalog[0].Nstarpar_disk > 0)) {
     538      return (FALSE);
     539    }
     540  }
     541  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_STARPAR)) {
     542    // only read the StarPar table if the file actually exists
     543    /* read StarPar table data */
     544    if (!gfits_fread_ftable_data (catalog[0].starpar_catalog[0].f, &ftable, FALSE)) {
     545      if (VERBOSE) fprintf (stderr, "can't read table starpar data\n");
     546      return (FALSE);
     547    }
     548    /* convert data format to internal : returns number of row read in Nstarpar */
     549    catalog[0].starpar = FtableToStarPar (&ftable, &Nstarpar, &catalog[0].catformat);
     550    if (Nstarpar != catalog[0].Nstarpar_disk) {
     551      fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  catalog[0].Nstarpar_disk);
     552    }
     553    catalog[0].Nstarpar = catalog[0].Nstarpar_disk;
     554    catalog[0].Nstarpar_off = 0;
     555  } else {
     556    if (catalog[0].starpar_catalog) {
     557      gfits_free_header (&catalog[0].starpar_catalog[0].header);
     558    } else {
     559      ALLOCATE (catalog[0].starpar_catalog, Catalog, 1);
     560      dvo_catalog_init (catalog[0].starpar_catalog, TRUE);
     561    }
     562    gfits_create_header (&catalog[0].starpar_catalog[0].header);
     563    ALLOCATE (catalog[0].starpar, StarPar, 1);
     564    catalog[0].Nstarpar = 0;
     565    catalog[0].Nstarpar_off = catalog[0].Nstarpar_disk;
     566  }
     567  gfits_free_header (&header);
     568
    467569  return (TRUE);
    468570}
     
    473575
    474576  off_t Nbytes;
    475   off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj;
     577  off_t Naverage, Nexpect, Nitems, Nmeasure, Nmissing, Nlensing, Nlensobj, Nstarpar;
    476578  Header header;
    477579  FTable ftable;
     
    497599    }
    498600    /* read Average table data : format is irrelevant here */
    499     if (!gfits_fread_ftable_range (catalog[0].f, &ftable, start, Nrows)) {
     601    if (!gfits_fread_ftable_range (catalog[0].f, FALSE, &ftable, start, Nrows)) {
    500602      if (VERBOSE) fprintf (stderr, "can't read table average data");
    501603      return (FALSE);
     
    527629    }
    528630    /* read Secfilt table data : format is irrelevant here */
    529     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
     631    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
    530632      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    531633      return (FALSE);
     
    563665    }
    564666    /* read Measure table data : format is irrelevant here */
    565     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     667    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    566668      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    567669      return (FALSE);
     
    594696    }
    595697    /* read Missing table data : format is irrelevant here */
    596     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     698    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    597699      if (VERBOSE) fprintf (stderr, "can't read table missing data");
    598700      return (FALSE);
     
    628730    }
    629731    /* read Lensing table data : format is irrelevant here */
    630     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     732    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    631733      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
    632734      return (FALSE);
     
    659761    }
    660762    /* read Lensobj table data : format is irrelevant here */
    661     if (!gfits_fread_ftable_range (subcat[0].f, &ftable, start, Nrows)) {
     763    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
    662764      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
    663765      return (FALSE);
     
    675777  }
    676778
     779  // XXX check the open status of the catalog
     780  if (catalog[0].catflags & LOAD_STARPAR) {
     781
     782    Catalog *subcat = catalog[0].starpar_catalog;
     783
     784    /* move pointer past header -- must be already read (load_catalog) */
     785    Nbytes = subcat[0].header.datasize + gfits_data_size (&subcat[0].header);
     786    fseeko (subcat[0].f, Nbytes, SEEK_SET);
     787
     788    /* read StarPar table header */
     789    if (!gfits_fread_header (subcat[0].f, &header)) {
     790      if (VERBOSE) fprintf (stderr, "can't read table starpar header");
     791      return (FALSE);
     792    }
     793    /* read StarPar table data : format is irrelevant here */
     794    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     795      if (VERBOSE) fprintf (stderr, "can't read table starpar data");
     796      return (FALSE);
     797    }
     798
     799    /* convert data format to internal : returns number of row read in Nstarpar */
     800    catalog[0].starpar = FtableToStarPar (&ftable, &Nstarpar, &catalog[0].catformat);
     801    if (Nstarpar != Nrows) {
     802      // XXX this condition denotes the eof has been reached; not an error or a warning
     803      // fprintf (stderr, "Warning: mismatch between Nstarpar in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nstarpar,  Nrows);
     804    }
     805    gfits_free_header (&header);
     806    catalog[0].Nstarpar = Nstarpar;
     807    catalog[0].Nstarpar_off = start;
     808  }
     809
    677810  return (TRUE);
    678811}
     
    686819  SecFilt *primary, *secfilt;
    687820  int Nsecfilt;
    688   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
     821  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    689822  off_t first, start, Nrows;
    690823
     
    719852  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
    720853  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
     854  Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
    721855
    722856  /* make sure header is consistent with data */
     
    727861  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    728862  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     863  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    729864  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    730865  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    845980  }
    846981
    847   /*** Lensing Table ***/
    848   if ((catalog[0].catflags & LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     982  /*** Lensing Table (optional, do not save if not loaded) ***/
     983  if ((catalog[0].catflags & LOAD_LENSING) && catalog[0].lensing_catalog->f && catalog[0].lensing) {
    849984
    850985    first  = 0;                    // first row in memory to write
     
    8721007  }
    8731008
    874   /*** Lensobj Table ***/
    875   if ((catalog[0].catflags & LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     1009  /*** Lensobj Table (optional, do not save if not loaded) ***/
     1010  if ((catalog[0].catflags & LOAD_LENSOBJ) && catalog[0].lensobj_catalog->f && catalog[0].lensobj) {
    8761011
    8771012    first  = 0;                    // first row in memory to write
     
    8931028    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    8941029      fprintf (stderr, "trouble writing Lensobj table\n");
     1030      goto failure;
     1031    }
     1032    gfits_free_header (&header);
     1033    gfits_free_table (&ftable);
     1034  }
     1035
     1036  /*** StarPar Table (optional, do not save if not loaded) ***/
     1037    if ((catalog[0].catflags & LOAD_STARPAR) && catalog[0].starpar_catalog->f && catalog[0].starpar) {
     1038
     1039    first  = 0;                    // first row in memory to write
     1040    start  = catalog[0].Nstarpar_off; // first disk row to write
     1041    Nrows  = catalog[0].Nstarpar - first;
     1042
     1043    assert (Nrows >= 0);
     1044    assert (first >= 0);
     1045    assert (first <= catalog[0].Nstarpar);
     1046    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1047
     1048    // convert to external table format (note that the block above does not damage or free catalog.average)
     1049    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1050      fprintf (stderr, "trouble converting format\n");
     1051      goto failure;
     1052    }
     1053
     1054    // write out StarPar table
     1055    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1056      fprintf (stderr, "trouble writing StarPar table\n");
    8951057      goto failure;
    8961058    }
     
    9251087  SecFilt *primary, *secfilt;
    9261088  int Nsecfilt;
    927   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
     1089  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    9281090  off_t first, start, Nrows;
    9291091
     
    9561118  if (catalog[0].Nlensobj_off > 0) {
    9571119    fprintf (stderr, "ERROR: only partial catalog (Lensobj) was loaded\n");
     1120    goto failure;
     1121  }
     1122  if (catalog[0].Nstarpar_off > 0) {
     1123    fprintf (stderr, "ERROR: only partial catalog (StarPar) was loaded\n");
    9581124    goto failure;
    9591125  }
     
    9841150  Nlensing_disk_new = catalog[0].Nlensing;
    9851151  Nlensobj_disk_new = catalog[0].Nlensobj;
     1152  Nstarpar_disk_new = catalog[0].Nstarpar;
    9861153
    9871154  /* make sure header is consistent with data */
     
    9921159  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    9931160  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     1161  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    9941162  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    9951163  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    11581326    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    11591327      fprintf (stderr, "trouble writing Lensobj table\n");
     1328      goto failure;
     1329    }
     1330    gfits_free_header (&header);
     1331    gfits_free_table (&ftable);
     1332  }
     1333
     1334  /*** StarPar Table ***/
     1335  if ((catalog[0].catflags & LOAD_STARPAR) && (catalog[0].starpar != NULL)) {
     1336
     1337    first  = 0;                    // first row in memory to write
     1338    start  = catalog[0].Nstarpar_off; // first disk row to write
     1339    Nrows  = catalog[0].Nstarpar - first;
     1340
     1341    assert (Nrows >= 0);
     1342    assert (first >= 0);
     1343    assert (first <= catalog[0].Nstarpar);
     1344    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1345
     1346    // convert to external table format
     1347    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1348      fprintf (stderr, "trouble converting format\n");
     1349      goto failure;
     1350    }
     1351
     1352    // write out StarPar table
     1353    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1354      fprintf (stderr, "trouble writing StarPar table\n");
    11601355      goto failure;
    11611356    }
     
    11891384  SecFilt *primary, *secfilt;
    11901385  int Nsecfilt;
    1191   off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new;
     1386  off_t Naves_disk_new, Nmeas_disk_new, Nmiss_disk_new, Nsecf_disk_new, Nlensing_disk_new, Nlensobj_disk_new, Nstarpar_disk_new;
    11921387  off_t first, start, Nrows;
    11931388
     
    12211416  Nlensing_disk_new = MAX (catalog[0].Nlensing_disk, catalog[0].Nlensing + catalog[0].Nlensing_off);
    12221417  Nlensobj_disk_new = MAX (catalog[0].Nlensobj_disk, catalog[0].Nlensobj + catalog[0].Nlensobj_off);
     1418  Nstarpar_disk_new = MAX (catalog[0].Nstarpar_disk, catalog[0].Nstarpar + catalog[0].Nstarpar_off);
    12231419
    12241420  /* make sure header is consistent with data */
     
    12291425  gfits_modify (&catalog[0].header, "NLENSING", OFF_T_FMT, 1,  Nlensing_disk_new);
    12301426  gfits_modify (&catalog[0].header, "NLENSOBJ", OFF_T_FMT, 1,  Nlensobj_disk_new);
     1427  gfits_modify (&catalog[0].header, "NSTARPAR", OFF_T_FMT, 1,  Nstarpar_disk_new);
    12311428  gfits_modify_alt (&catalog[0].header, "EXTEND",   "%t", 1, TRUE);
    12321429  gfits_modify (&catalog[0].header, "OBJID",    "%d", 1, catalog[0].objID);
     
    13991596    if (!dvo_catalog_save_subcat (catalog[0].lensobj_catalog, &ftable, start, Nrows, catalog[0].Nlensobj_disk, Nlensobj_disk_new)) {
    14001597      fprintf (stderr, "trouble writing Lensobj table\n");
     1598      goto failure;
     1599    }
     1600    gfits_free_header (&header);
     1601    gfits_free_table (&ftable);
     1602  }
     1603
     1604  /*** StarPar Table ***/
     1605  if (catalog[0].starpar != NULL) {
     1606
     1607    first  = catalog[0].Nstarpar_disk - catalog[0].Nstarpar_off;  // first row in memory to write
     1608    start  = catalog[0].Nstarpar_disk; // first disk row to write
     1609    Nrows  = catalog[0].Nstarpar - first;
     1610
     1611    assert (Nrows >= 0);
     1612    assert (first >= 0);
     1613    assert (first <= catalog[0].Nstarpar);
     1614    assert (catalog[0].Nstarpar_disk >= catalog[0].Nstarpar_off);
     1615
     1616    // convert to external table format
     1617    // XXX does catalog.starpar have averef correctly set up?
     1618    if (!StarParToFtable (&ftable, &catalog[0].starpar[first], Nrows, catalog[0].catformat)) {
     1619      fprintf (stderr, "trouble converting format\n");
     1620      goto failure;
     1621    }
     1622
     1623    // write out StarPar table
     1624    if (!dvo_catalog_save_subcat (catalog[0].starpar_catalog, &ftable, start, Nrows, catalog[0].Nstarpar_disk, Nstarpar_disk_new)) {
     1625      fprintf (stderr, "trouble writing StarPar table\n");
    14011626      goto failure;
    14021627    }
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r37246 r37807  
    4343  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5);
    4444  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
     45  CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM);
    4546# undef CONVERT_FORMAT
    4647
     
    129130  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5,          PS1_V5);
    130131  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
     132  CONVERT_FORMAT ("DVO_AVERAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
    131133# undef CONVERT_FORMAT
    132134
     
    165167      FORMAT_CASE (PS1_V5,          PS1_V5);
    166168      FORMAT_CASE (PS1_REF,         PS1_REF);
     169      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    167170# undef FORMAT_CASE
    168171
     
    240243  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5",          PS1_V5,          PS1_V5,          TRUE);
    241244  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
     245  CONVERT_FORMAT ("DVO_MEASURE_PS1_SIM",         PS1_SIM,         PS1_SIM,         TRUE);
    242246# undef CONVERT_FORMAT
    243247
     
    254258    case DVO_FORMAT_##FORMAT: { \
    255259      Measure_##TYPE *tmpMeasure; \
    256       myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     260      myAssert (ABS_COORDS || average, "conversion from internal needs average table"); \
    257261      tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    258262      gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure); \
     
    278282      FORMAT_CASE (PS1_V5,          PS1_V5,          TRUE);
    279283      FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
     284      FORMAT_CASE (PS1_SIM,         PS1_SIM,         TRUE);
    280285# undef FORMAT_CASE
    281286
     
    350355  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5",          PS1_V5,          PS1_V5);
    351356  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
     357  CONVERT_FORMAT ("DVO_SECFILT_PS1_SIM",         PS1_SIM,         PS1_SIM);
    352358# undef CONVERT_FORMAT
    353359
     
    386392      FORMAT_CASE (PS1_V5,          PS1_V5);
    387393      FORMAT_CASE (PS1_REF,         PS1_REF);
     394      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    388395# undef FORMAT_CASE
    389396
     
    407414    return (FALSE);
    408415  }
     416
     417  if (!strcmp (extname, "DVO_LENSING_PS1_V5") && (ftable[0].header[0].Naxis[0] == 128)) {
     418    Lensing_PS1_V5_ALT *tmpLensing;                                             
     419    tmpLensing = gfits_table_get_Lensing_PS1_V5_ALT (ftable, Nlensing, NULL);
     420    if (!tmpLensing) {                                                 
     421      fprintf (stderr, "ERROR: failed to read lensings\n");             
     422      exit (2);                                                         
     423    }                                                                   
     424    lensing = Lensing_PS1_V5_ALT_ToInternal (tmpLensing, *Nlensing);
     425    free (tmpLensing);                                                 
     426    *format = DVO_FORMAT_PS1_V5;                                       
     427    return (lensing); }
    409428
    410429# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     
    585604    default:
    586605      fprintf (stderr, "table format unknown (lensobj)\n");
     606      return (FALSE);
     607  }
     608  return (TRUE);
     609}
     610
     611/*** StarPar / FTable conversion functions ***/
     612
     613StarPar *FtableToStarPar (FTable *ftable, off_t *Nstarpar, char *format) {
     614
     615  StarPar *starpar;
     616  char extname[80];
     617
     618  /* convert to the internal format */
     619  if (!gfits_scan (ftable[0].header, "EXTNAME", "%s", 1, extname)) {
     620    fprintf (stderr, "EXTNAME missing for starpar table\n");
     621    return (FALSE);
     622  }
     623
     624# define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     625  if (!strcmp (extname, NAME)) {                                        \
     626    StarPar_##TYPE *tmpStarPar;                                         \
     627    tmpStarPar = gfits_table_get_StarPar_##TYPE (ftable, Nstarpar, NULL); \
     628    if (!tmpStarPar) {                                                  \
     629      fprintf (stderr, "ERROR: failed to read starpar\n");              \
     630      exit (2);                                                         \
     631    }                                                                   \
     632    starpar = StarPar_##TYPE##_ToInternal (tmpStarPar, *Nstarpar); \
     633    free (tmpStarPar);                                                  \
     634    *format = DVO_FORMAT_##FORMAT;                                      \
     635    return (starpar); }
     636
     637  if (!strcmp (extname, "DVO_STARPAR")) {
     638    starpar = gfits_table_get_StarPar (ftable, Nstarpar, NULL);
     639    if (!starpar) {
     640      fprintf (stderr, "ERROR: failed to read starpar\n");
     641      exit (2);
     642    }
     643    *format = DVO_FORMAT_INTERNAL;
     644    return (starpar);
     645  }
     646
     647   CONVERT_FORMAT ("DVO_STARPAR_PS1_SIM",         PS1_SIM,         PS1_SIM);
     648// CONVERT_FORMAT ("DVO_STARPAR_PS1_REF",         PS1_REF,         PS1_REF);
     649// CONVERT_FORMAT ("DVO_STARPAR_ELIXIR",          ELIXIR,          Elixir);
     650// CONVERT_FORMAT ("DVO_STARPAR_LONEOS",          LONEOS,          Loneos);
     651// CONVERT_FORMAT ("DVO_STARPAR_PANSTARRS_DEV_0", PANSTARRS_DEV_0, Panstarrs_DEV_0);
     652// CONVERT_FORMAT ("DVO_STARPAR_PANSTARRS_DEV_1", PANSTARRS_DEV_1, Panstarrs_DEV_1);
     653// CONVERT_FORMAT ("DVO_STARPAR_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
     654// CONVERT_FORMAT ("DVO_STARPAR_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     655// CONVERT_FORMAT ("DVO_STARPAR_PS1_V1",          PS1_V1,          PS1_V1);
     656// CONVERT_FORMAT ("DVO_STARPAR_PS1_V2",          PS1_V2,          PS1_V2);
     657// CONVERT_FORMAT ("DVO_STARPAR_PS1_V3",          PS1_V3,          PS1_V3);
     658// CONVERT_FORMAT ("DVO_STARPAR_PS1_V4",          PS1_V4,          PS1_V4);
     659  CONVERT_FORMAT ("DVO_STARPAR_PS1_V5",          PS1_V5,          PS1_V5);
     660//  CONVERT_FORMAT ("DVO_STELLAR_PARAMS_PS1_V5",          PS1_V5,          PS1_V5);
     661  // XXX fix in libauto: STELLAR_PARAMS to STARPAR
     662# undef CONVERT_FORMAT
     663
     664  fprintf (stderr, "table format unknown: %s\n", extname);
     665
     666  *Nstarpar = 0;
     667  return (NULL);
     668}
     669
     670// StarParToFtable needs the Average since old formats stored starpar.dR,dD only
     671int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, char format) {
     672
     673# define FORMAT_CASE(FORMAT, TYPE)              \
     674    case DVO_FORMAT_##FORMAT: { \
     675      StarPar_##TYPE *tmpStarPar; \
     676      tmpStarPar = StarParInternalTo_##TYPE (starpar, Nstarpar); \
     677      gfits_table_set_StarPar_##TYPE (ftable, tmpStarPar, Nstarpar); \
     678      free (tmpStarPar); \
     679      break; }
     680
     681  /* convert from the internal format */
     682  switch (format) {
     683    case DVO_FORMAT_INTERNAL: {
     684      gfits_table_set_StarPar (ftable, starpar, Nstarpar);
     685      break; }
     686
     687      FORMAT_CASE (PS1_SIM,         PS1_SIM);
     688//    FORMAT_CASE (PS1_REF,         PS1_REF);
     689//    FORMAT_CASE (ELIXIR,          Elixir);
     690//    FORMAT_CASE (LONEOS,          Loneos);
     691//    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     692//    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     693//    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     694//    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     695//    FORMAT_CASE (PS1_V1,          PS1_V1);
     696//    FORMAT_CASE (PS1_V2,          PS1_V2);
     697//    FORMAT_CASE (PS1_V3,          PS1_V3);
     698//    FORMAT_CASE (PS1_V4,          PS1_V4);
     699      FORMAT_CASE (PS1_V5,          PS1_V5);
     700# undef FORMAT_CASE
     701
     702    default:
     703      fprintf (stderr, "table format unknown (starpar)\n");
    587704      return (FALSE);
    588705  }
     
    643760    return (TRUE); }
    644761
    645   if (!strcmp (extname, "DVO_IMAGE")) {
    646     Image *image;
    647     image = gfits_table_get_Image (ftable, &Nimage, NULL);
    648     if (!image) {
    649       fprintf (stderr, "ERROR: failed to read images\n");
    650       exit (2);
    651     }
    652     *format = DVO_FORMAT_INTERNAL;
    653     return (TRUE);
    654   }
    655 
    656762  CONVERT_FORMAT ("DVO_IMAGE_ELIXIR",          ELIXIR,          Elixir);
    657763  CONVERT_FORMAT ("DVO_IMAGE_LONEOS",          LONEOS,          Loneos);
     
    666772  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5",          PS1_V5,          PS1_V5);
    667773  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
     774  CONVERT_FORMAT ("DVO_IMAGE_PS1_SIM",         PS1_SIM,         PS1_SIM);
    668775
    669776# undef CONVERT_FORMAT
     
    690797  /* convert from the internal format */
    691798  switch (format) {
    692     case DVO_FORMAT_INTERNAL: {
    693       gfits_convert_Image ((Image *) ftable[0].buffer, sizeof(Image), Nimage);
    694       break; }
    695 
    696799      FORMAT_CASE (ELIXIR,          Elixir);
    697800      FORMAT_CASE (LONEOS,          Loneos);
     
    706809      FORMAT_CASE (PS1_V5,          PS1_V5);
    707810      FORMAT_CASE (PS1_REF,         PS1_REF);
     811      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    708812
    709813# undef FORMAT_CASE
     
    744848  /* convert from the internal format */
    745849  switch (format) {
    746     case DVO_FORMAT_INTERNAL: {
    747       for (i = 0; i < Nrow; i++) {
    748         gfits_convert_Image ((Image *) vtable[0].buffer[i], sizeof(Image), 1);
    749       }
    750       return (TRUE); }
    751 
    752850      FORMAT_CASE (ELIXIR,          Elixir);
    753851      FORMAT_CASE (LONEOS,          Loneos);
     
    762860      FORMAT_CASE (PS1_V5,          PS1_V5);
    763861      FORMAT_CASE (PS1_REF,         PS1_REF);
     862      FORMAT_CASE (PS1_SIM,         PS1_SIM);
    764863
    765864# undef FORMAT_CASE
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r37246 r37807  
    219219
    220220  for (i = 0; i < Nvalues; i++) {
    221     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     221    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     222    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     223    out[i].coords.mosaic   = NULL;
     224    out[i].coords.offsetMap = NULL;
    222225
    223226    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    287290
    288291  for (i = 0; i < Nvalues; i++) {
    289     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     292    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     293    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    290294
    291295    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r37246 r37807  
    214214
    215215  for (i = 0; i < Nvalues; i++) {
    216     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     216    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     217    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     218    out[i].coords.mosaic   = NULL;
     219    out[i].coords.offsetMap = NULL;
    217220
    218221    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    279282
    280283  for (i = 0; i < Nvalues; i++) {
    281     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     284    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     285    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    282286
    283287    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r37055 r37807  
    1818
    1919  for (i = 0; i < Nvalues; i++) {
    20     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     20    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     21    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     22    out[i].coords.mosaic   = NULL;
     23    out[i].coords.offsetMap = NULL;
    2124
    2225    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    7881
    7982  for (i = 0; i < Nvalues; i++) {
    80     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     83    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     84    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    8185
    8286    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r37035 r37807  
    145145
    146146  for (i = 0; i < Nvalues; i++) {
    147     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     147    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     148    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     149    out[i].coords.mosaic   = NULL;
     150    out[i].coords.offsetMap = NULL;
    148151
    149152    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    208211
    209212  for (i = 0; i < Nvalues; i++) {
    210     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     213    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     214    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    211215
    212216    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r37246 r37807  
    238238
    239239  for (i = 0; i < Nvalues; i++) {
    240     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     240    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     241    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     242    out[i].coords.mosaic   = NULL;
     243    out[i].coords.offsetMap = NULL;
    241244
    242245    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    302305
    303306  for (i = 0; i < Nvalues; i++) {
    304     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     307    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     308    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    305309
    306310    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r37246 r37807  
    249249
    250250  for (i = 0; i < Nvalues; i++) {
    251     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     251    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     252    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     253    out[i].coords.mosaic   = NULL;
     254    out[i].coords.offsetMap = NULL;
    252255
    253256    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    313316
    314317  for (i = 0; i < Nvalues; i++) {
    315     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     318    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     319    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    316320
    317321    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r37246 r37807  
    259259
    260260  for (i = 0; i < Nvalues; i++) {
    261     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     261    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     262    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     263    out[i].coords.mosaic   = NULL;
     264    out[i].coords.offsetMap = NULL;
    262265
    263266    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    323326
    324327  for (i = 0; i < Nvalues; i++) {
    325     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     328    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     329    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    326330
    327331    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r37246 r37807  
    299299
    300300  for (i = 0; i < Nvalues; i++) {
    301     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     301    // this is only save because the initial 120 bytes in Coords match CoordsDisk
     302    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     303    out[i].coords.mosaic    = NULL;
     304    out[i].coords.offsetMap = NULL;
    302305
    303306    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
     
    363366
    364367  for (i = 0; i < Nvalues; i++) {
    365     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     368    // this is only save because the initial 120 bytes in Coords match CoordsDisk
     369    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    366370
    367371    // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r37356 r37807  
    191191    out[i].Nlensing      = in[i].Nlensing;     
    192192    out[i].Nlensobj      = in[i].Nlensobj;     
     193    out[i].Nstarpar      = in[i].Nstarpar;     
    193194    out[i].Nextend       = in[i].Nextend;     
    194195
     
    197198    out[i].lensingOffset = in[i].lensingOffset;
    198199    out[i].lensobjOffset = in[i].lensobjOffset;
     200    out[i].starparOffset = in[i].starparOffset;
    199201    out[i].extendOffset  = in[i].extendOffset;
    200     out[i].paramsOffset  = in[i].paramsOffset;
    201202
    202203    out[i].refColorBlue  = in[i].refColorBlue;
     
    258259    out[i].Nlensing       = in[i].Nlensing;     
    259260    out[i].Nlensobj       = in[i].Nlensobj;     
     261    out[i].Nstarpar       = in[i].Nstarpar;     
    260262    out[i].Nextend        = in[i].Nextend;     
    261263                         
     
    264266    out[i].lensingOffset  = in[i].lensingOffset;
    265267    out[i].lensobjOffset  = in[i].lensobjOffset;
     268    out[i].starparOffset  = in[i].starparOffset;
    266269    out[i].extendOffset   = in[i].extendOffset;
    267     out[i].paramsOffset   = in[i].paramsOffset;
    268270                         
    269271    out[i].refColorBlue   = in[i].refColorBlue;
     
    663665}
    664666
     667StarPar *StarPar_PS1_V5_ToInternal (StarPar_PS1_V5 *in, off_t Nvalues) {
     668
     669  off_t i;
     670  StarPar *out;
     671
     672  ALLOCATE_ZERO (out, StarPar, Nvalues);
     673
     674  for (i = 0; i < Nvalues; i++) {
     675    dvo_starpar_init (&out[i]);
     676
     677    out[i].R         = in[i].R;     
     678    out[i].D         = in[i].D;     
     679    out[i].galLat    = in[i].galLat;     
     680    out[i].galLon    = in[i].galLon;     
     681
     682    out[i].Ebv       = in[i].Ebv     ;     
     683    out[i].dEbv      = in[i].dEbv    ;     
     684    out[i].DistMag   = in[i].DistMag ;     
     685    out[i].dDistMag  = in[i].dDistMag;     
     686    out[i].M_r       = in[i].M_r     ;     
     687    out[i].dM_r      = in[i].dM_r    ;     
     688    out[i].FeH       = in[i].FeH     ;     
     689    out[i].dFeH      = in[i].dFeH    ;     
     690    out[i].uRA       = in[i].uRA     ;     
     691    out[i].uDEC      = in[i].uDEC    ;     
     692
     693    out[i].averef  = in[i].averef;
     694    out[i].objID   = in[i].objID ;
     695    out[i].catID   = in[i].catID ;
     696  }
     697  return (out);
     698}
     699
     700StarPar_PS1_V5 *StarParInternalTo_PS1_V5 (StarPar *in, off_t Nvalues) {
     701
     702  off_t i;
     703  StarPar_PS1_V5 *out;
     704
     705  ALLOCATE_ZERO (out, StarPar_PS1_V5, Nvalues);
     706
     707  for (i = 0; i < Nvalues; i++) {
     708
     709    out[i].R         = in[i].R;     
     710    out[i].D         = in[i].D;     
     711    out[i].galLat    = in[i].galLat;     
     712    out[i].galLon    = in[i].galLon;     
     713
     714    out[i].Ebv       = in[i].Ebv     ;     
     715    out[i].dEbv      = in[i].dEbv    ;     
     716    out[i].DistMag   = in[i].DistMag ;     
     717    out[i].dDistMag  = in[i].dDistMag;     
     718    out[i].M_r       = in[i].M_r     ;     
     719    out[i].dM_r      = in[i].dM_r    ;     
     720    out[i].FeH       = in[i].FeH     ;     
     721    out[i].dFeH      = in[i].dFeH    ;     
     722    out[i].uRA       = in[i].uRA     ;     
     723    out[i].uDEC      = in[i].uDEC    ;     
     724
     725    out[i].averef  = in[i].averef;
     726    out[i].objID   = in[i].objID ;
     727    out[i].catID   = in[i].catID ;
     728  }
     729  return (out);
     730}
     731
    665732# define RAW_IMAGE_NAME_LEN 117
    666733
     
    676743
    677744  for (i = 0; i < Nvalues; i++) {
    678     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     745    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     746    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     747    out[i].coords.mosaic   = NULL;
     748    out[i].coords.offsetMap = NULL;
    679749
    680750    // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
     
    741811
    742812  for (i = 0; i < Nvalues; i++) {
    743     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     813    // this is only save because the initial 120 bytes in Coords match CoordsDisk
     814    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    744815
    745816    // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
     
    920991    out[i].lensingOffset  = in[i].lensingOffset;
    921992    out[i].lensobjOffset  = in[i].lensobjOffset;
     993    out[i].starparOffset  = in[i].starparOffset;
    922994    out[i].extendOffset   = in[i].extendOffset;
    923     out[i].paramsOffset   = in[i].paramsOffset;
    924995                         
    925996    out[i].refColorBlue   = in[i].refColorBlue;
     
    11941265
    11951266
     1267Lensing *Lensing_PS1_V5_ALT_ToInternal (Lensing_PS1_V5_ALT *in, off_t Nvalues) {
     1268
     1269  off_t i;
     1270  Lensing *out;
     1271
     1272  ALLOCATE_ZERO (out, Lensing, Nvalues);
     1273
     1274  for (i = 0; i < Nvalues; i++) {
     1275    dvo_lensing_init (&out[i]);
     1276
     1277    out[i].X11_sm_obj  = in[i].X11_sm_obj;     
     1278    out[i].X12_sm_obj  = in[i].X12_sm_obj;     
     1279    out[i].X22_sm_obj  = in[i].X22_sm_obj;     
     1280    out[i].E1_sm_obj   = in[i].E1_sm_obj;     
     1281    out[i].E2_sm_obj   = in[i].E2_sm_obj;     
     1282                                         
     1283    out[i].X11_sh_obj  = in[i].X11_sh_obj;     
     1284    out[i].X12_sh_obj  = in[i].X12_sh_obj;     
     1285    out[i].X22_sh_obj  = in[i].X22_sh_obj;     
     1286    out[i].E1_sh_obj   = in[i].E1_sh_obj;     
     1287    out[i].E2_sh_obj   = in[i].E2_sh_obj;     
     1288                                         
     1289    out[i].X11_sm_psf  = in[i].X11_sm_psf;
     1290    out[i].X12_sm_psf  = in[i].X12_sm_psf;
     1291    out[i].X22_sm_psf  = in[i].X22_sm_psf;
     1292    out[i].E1_sm_psf   = in[i].E1_sm_psf;
     1293    out[i].E2_sm_psf   = in[i].E2_sm_psf;     
     1294                                         
     1295    out[i].X11_sh_psf  = in[i].X11_sh_psf;
     1296    out[i].X12_sh_psf  = in[i].X12_sh_psf;
     1297    out[i].X22_sh_psf  = in[i].X22_sh_psf;
     1298    out[i].E1_sh_psf   = in[i].E1_sh_psf;
     1299    out[i].E2_sh_psf   = in[i].E2_sh_psf;
     1300
     1301    out[i].F_ApR5      = in[i].F_ApR5;
     1302    out[i].dF_ApR5     = in[i].dF_ApR5;
     1303    out[i].sF_ApR5     = in[i].sF_ApR5;
     1304    out[i].fF_ApR5     = in[i].fF_ApR5;
     1305                                   
     1306    out[i].F_ApR6      = in[i].F_ApR6;
     1307    out[i].dF_ApR6     = in[i].dF_ApR6;
     1308    out[i].sF_ApR6     = in[i].sF_ApR6;
     1309    out[i].fF_ApR6     = in[i].fF_ApR6;
     1310                                   
     1311    out[i].detID       = in[i].detID;
     1312    out[i].objID       = in[i].objID;
     1313    out[i].catID       = in[i].catID;
     1314
     1315    out[i].averef      = in[i].averef;
     1316  }
     1317  return (out);
     1318}
     1319
  • trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r37035 r37807  
    210210
    211211  for (i = 0; i < Nvalues; i++) {
    212     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     212    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     213    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     214    out[i].coords.mosaic   = NULL;
     215    out[i].coords.offsetMap = NULL;
    213216
    214217    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    280283
    281284  for (i = 0; i < Nvalues; i++) {
    282     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     285    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     286    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    283287
    284288    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r37035 r37807  
    188188
    189189  for (i = 0; i < Nvalues; i++) {
    190     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     190    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     191    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     192    out[i].coords.mosaic   = NULL;
     193    out[i].coords.offsetMap = NULL;
    191194
    192195    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    259262
    260263  for (i = 0; i < Nvalues; i++) {
    261     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     264    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     265    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    262266
    263267    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r37035 r37807  
    227227
    228228  for (i = 0; i < Nvalues; i++) {
    229     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     229    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     230    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     231    out[i].coords.mosaic   = NULL;
     232    out[i].coords.offsetMap = NULL;
    230233
    231234    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    297300
    298301  for (i = 0; i < Nvalues; i++) {
    299     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     302    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     303    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    300304
    301305    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r37035 r37807  
    227227
    228228  for (i = 0; i < Nvalues; i++) {
    229     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     229    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     230    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     231    out[i].coords.mosaic   = NULL;
     232    out[i].coords.offsetMap = NULL;
    230233
    231234    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
     
    297300
    298301  for (i = 0; i < Nvalues; i++) {
    299     memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
     302    // this is only safe because the initial 120 bytes in Coords match CoordsDisk
     303    memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
    300304
    301305    // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
  • trunk/Ohana/src/libdvo/src/dvo_image.c

    r37035 r37807  
    200200
    201201  gfits_create_matrix (&db[0].header, &db[0].matrix);
    202   gfits_table_set_Image (&db[0].ftable, NULL, 0);
     202  gfits_table_set_Image (&db[0].ftable);
    203203
    204204  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, 0);
     
    207207  dvo_image_createID (&db[0].header);
    208208
    209   if (db[0].format == DVO_FORMAT_INTERNAL)        gfits_modify (&db[0].header, "FORMAT", "%s", 1, "INTERNAL");
     209  // if (db[0].format == DVO_FORMAT_INTERNAL)     gfits_modify (&db[0].header, "FORMAT", "%s", 1, "INTERNAL");
    210210  if (db[0].format == DVO_FORMAT_LONEOS)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "LONEOS");
    211211  if (db[0].format == DVO_FORMAT_ELIXIR)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "ELIXIR");
     
    221221  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V5");
    222222  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
     223  if (db[0].format == DVO_FORMAT_PS1_SIM)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_SIM");
    223224 
    224225  return;
     
    267268}
    268269
     270int gfits_table_set_Image (FTable *ftable) {
     271
     272  Header *header;
     273
     274  header = ftable[0].header;
     275
     276  gfits_table_mkheader_Image (header);
     277 
     278  /* create table */
     279  if (!gfits_create_table (header, ftable)) return (FALSE);
     280
     281  return (TRUE);
     282}
     283
     284int gfits_table_mkheader_Image (Header *header) {
     285
     286  /* create table header */
     287  if (!gfits_create_table_header (header, "BINTABLE", "DVO_IMAGE")) return (FALSE);
     288
     289  /* define table layout */
     290  /** TABLE DEFINITION **/
     291  gfits_define_bintable_column (header, "D",    "CRVAL1",           "coordinate at reference pixel",   "",                  1.0, 0.0);
     292  gfits_define_bintable_column (header, "D",    "CRVAL2",           "coordinate at reference pixel",   "",                  1.0, 0.0);
     293  gfits_define_bintable_column (header, "E",    "CRPIX1",           "coordinate of reference pixel",   "",                  1.0, 0.0);
     294  gfits_define_bintable_column (header, "E",    "CRPIX2",           "coordinate of reference pixel",   "",                  1.0, 0.0);
     295  gfits_define_bintable_column (header, "E",    "CDELT1",           "degrees per pixel",               "",                  1.0, 0.0);
     296  gfits_define_bintable_column (header, "E",    "CDELT2",           "degrees per pixel",               "",                  1.0, 0.0);
     297  gfits_define_bintable_column (header, "E",    "PC1_1",            "rotation matrix",                 "",                  1.0, 0.0);
     298  gfits_define_bintable_column (header, "E",    "PC1_2",            "rotation matrix",                 "",                  1.0, 0.0);
     299  gfits_define_bintable_column (header, "E",    "PC2_1",            "rotation matrix",                 "",                  1.0, 0.0);
     300  gfits_define_bintable_column (header, "E",    "PC2_2",            "rotation matrix",                 "",                  1.0, 0.0);
     301  gfits_define_bintable_column (header, "14E",  "POLYTERMS",        "higher order warping terms",      "",                  1.0, 0.0);
     302  if (sizeof(void *) == 4) {
     303    gfits_define_bintable_column (header, "J",    "POINTER1",       "",  "",                  1.0, 0.0);
     304    gfits_define_bintable_column (header, "J",    "POINTER2",       "",  "",                  1.0, 0.0);
     305  }
     306  if (sizeof(void *) == 8) {
     307    gfits_define_bintable_column (header, "K",    "POINTER1",       "",  "",                  1.0, 0.0);
     308    gfits_define_bintable_column (header, "K",    "POINTER2",       "",  "",                  1.0, 0.0);
     309  }
     310  gfits_define_bintable_column (header, "15A",  "CTYPE",            "coordinate type",                 "",                  1.0, 0.0);
     311  gfits_define_bintable_column (header, "A",    "NPOLYTERMS",       "order of polynomial",             "",                  1.0, 0.0);
     312  gfits_define_bintable_column (header, "J",    "TZERO",            "readout time (row 0)",            "",                  1.0, 0.0);
     313  gfits_define_bintable_column (header, "J",    "NSTAR",            "number of stars on image",        "",                  1.0, 0.0);
     314  gfits_define_bintable_column (header, "E",    "SECZ",             "airmass",                         "mag",               1.0, 0.0);
     315  gfits_define_bintable_column (header, "I",    "NX",               "image width",                     "",                  1.0, 0.0);
     316  gfits_define_bintable_column (header, "I",    "NY",               "image height",                    "",                  1.0, 0.0);
     317  gfits_define_bintable_column (header, "E",    "APMIFIT",          "aperture correction",             "mag",               1.0, 0.0);
     318  gfits_define_bintable_column (header, "E",    "DAPMIFIT",         "apmifit error",                   "mag",               1.0, 0.0);
     319  gfits_define_bintable_column (header, "E",    "MCAL",             "calibration mag",                 "mag",               1.0, 0.0);
     320  gfits_define_bintable_column (header, "E",    "DMCAL",            "error on Mcal",                   "mag",               1.0, 0.0);
     321  gfits_define_bintable_column (header, "I",    "XM",               "image chisq",                     "10*log(value)",     1.0, 0.0);
     322  gfits_define_bintable_column (header, "I",    "PHOTCODE",         "identifier for CCD,",             "",                  1.0, 0.0);
     323  gfits_define_bintable_column (header, "E",    "EXPTIME",          "exposure time",                   "seconds",           1.0, 0.0);
     324  gfits_define_bintable_column (header, "E",    "ST",               "sidereal time of exposure",       "",                  1.0, 0.0);
     325  gfits_define_bintable_column (header, "E",    "LAT",              "observatory latitude",            "degrees",           1.0, 0.0);
     326  gfits_define_bintable_column (header, "E",    "RA_CENTER",        "image center",                    "degrees",           1.0, 0.0);
     327  gfits_define_bintable_column (header, "E",    "DEC_CENTER",       "image center",                    "degrees",           1.0, 0.0);
     328  gfits_define_bintable_column (header, "E",    "RADIUS",           "image radius",                    "degrees",           1.0, 0.0);
     329  gfits_define_bintable_column (header, "E",    "REF_COLOR_BLUE",   "median astrometry ref color",     "",                  1.0, 0.0);
     330  gfits_define_bintable_column (header, "E",    "REF_COLOR_RED",    "median astrometry ref color",     "",                  1.0, 0.0);
     331  gfits_define_bintable_column (header, "117A", "NAME",             "name of original image ",         "",                  1.0, 0.0);
     332  gfits_define_bintable_column (header, "B",    "DETECTION_LIMIT",  "detection limit",                 "10*mag",            1.0, 0.0);
     333  gfits_define_bintable_column (header, "B",    "SATURATION_LIMIT", "saturation limit",                "10*mag",            1.0, 0.0);
     334  gfits_define_bintable_column (header, "B",    "CERROR",           "astrometric error",               "50*arcsec",         1.0, 0.0);
     335  gfits_define_bintable_column (header, "B",    "FWHM_X",           "PSF x width",                     "25*arcsec",         1.0, 0.0);
     336  gfits_define_bintable_column (header, "B",    "FWHM_Y",           "PSF y width",                     "25*arcsec",         1.0, 0.0);
     337  gfits_define_bintable_column (header, "B",    "TRATE",            "scan rate",                       "100 usec/pixel",    1.0, 0.0);
     338  gfits_define_bintable_column (header, "B",    "CCDNUM",           "CCD ID number",                   "",                  1.0, 0.0);
     339  gfits_define_bintable_column (header, "J",    "FLAGS",            "image quality flags",             "",                  1.0, 0.0);
     340  gfits_define_bintable_column (header, "J",    "IMAGE_ID",         "internal image ID",               "",                  1.0, 0.0);
     341  gfits_define_bintable_column (header, "J",    "PARENT_ID",        "associated ref image",            "",                  1.0, 0.0);
     342  gfits_define_bintable_column (header, "J",    "EXTERN_ID",        "external image ID",               "",                  1.0, 0.0);
     343  gfits_define_bintable_column (header, "I",    "SOURCE_ID",        "analysis source ID",              "",                  1.0, 0.0);
     344  gfits_define_bintable_column (header, "I",    "NLINK_ASTROM",     "mean number of matched measurements for astrometry", "",                  1.0, 0.0);
     345  gfits_define_bintable_column (header, "I",    "NLINK_PHOTOM",     "mean number of matched measurements for astrometry", "",                  1.0, 0.0);
     346  gfits_define_bintable_column (header, "I",    "UBERCAL_DIST",     "distance to nearest ubercal image", "",                  1.0, 0.0);
     347  gfits_define_bintable_column (header, "E",    "XPIX_SYS_ERR",     "systematic astrometry error in X", "",                  1.0, 0.0);
     348  gfits_define_bintable_column (header, "E",    "YPIX_SYS_ERR",     "systematic astrometry error in Y", "",                  1.0, 0.0);
     349  gfits_define_bintable_column (header, "E",    "MAG_SYS_ERR",      "systematic photometry error",     "",                  1.0, 0.0);
     350  gfits_define_bintable_column (header, "I",    "N_FIT_ASTROM",     "number of stars used for astrometry cal", "",                  1.0, 0.0);
     351  gfits_define_bintable_column (header, "I",    "N_FIT_PHOTOM",     "number of stars used for photometry cal", "",                  1.0, 0.0);
     352  gfits_define_bintable_column (header, "J",    "PHOTOM_MAP_ID",    "reference to 2D zero point map",  "",                  1.0, 0.0);
     353  gfits_define_bintable_column (header, "J",    "ASTROM_MAP_ID",    "reference to 2D astrometry map",  "",                  1.0, 0.0);
     354  if (sizeof(void *) == 4) {
     355    gfits_define_bintable_column (header, "J",    "POINTER3",       "",  "",                  1.0, 0.0);
     356  }
     357  if (sizeof(void *) == 8) {
     358    gfits_define_bintable_column (header, "K",    "POINTER3",       "",  "",                  1.0, 0.0);
     359  }
     360
     361  return (TRUE);
     362}
     363
     364/* return internal structure representation */
     365Image *gfits_table_get_Image (FTable *ftable, off_t *Ndata, char *swapped) {
     366
     367  int Ncols;
     368  Image *data;
     369
     370  Ncols = ftable[0].header[0].Naxis[0];
     371  if (Ncols != sizeof(Image)) {
     372    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, (int) sizeof(Image));
     373    return NULL;
     374  }
     375
     376  *Ndata = ftable[0].header[0].Naxis[1];
     377  data = (Image *) ftable[0].buffer;
     378
     379  if (!swapped) {
     380    myAbort ("invalid to call this without suppying 'swapped'");
     381  }
     382  if (*swapped == FALSE) {
     383    myAbort ("invalid for table to be swapped");
     384  }
     385   
     386  return (data);
     387}
     388
  • trunk/Ohana/src/libdvo/src/dvo_image_raw.c

    r37035 r37807  
    6161  if (db[0].format == DVO_FORMAT_PS1_V5)          ImageSize = sizeof(Image_PS1_V5);
    6262  if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
     63  if (db[0].format == DVO_FORMAT_PS1_SIM)         ImageSize = sizeof(Image_PS1_SIM);
    6364
    6465  /* check that filesize makes sense */
     
    9293  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_table_mkheader_Image_PS1_V5 (&db[0].theader);
    9394  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
     95  if (db[0].format == DVO_FORMAT_PS1_SIM)         gfits_table_mkheader_Image_PS1_SIM (&db[0].theader);
    9496   
    9597  /* read data from file */
  • trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r37116 r37807  
    17881788  m2 = (Ns2 == -1) ? average[0].M : secfilt[Ns2].M;
    17891789*/
     1790
     1791/*** lensing *********************************************************************************/
     1792
     1793# define LENSFIELD(NAME) \
     1794  float LensValue_##NAME (PhotCode *code, Lensobj *lensobj) { \
     1795  if (code == NULL) return NAN; \
     1796  int Ns = photcodes->hashNsec[code->code]; \
     1797  float value = (Ns == -1) ? NAN : lensobj[Ns].NAME; \
     1798  return (value); \
     1799}
     1800
     1801LENSFIELD(X11_sm_obj);
     1802LENSFIELD(X12_sm_obj);
     1803LENSFIELD(X22_sm_obj);
     1804LENSFIELD(E1_sm_obj);
     1805LENSFIELD(E2_sm_obj);
     1806
     1807LENSFIELD(X11_sh_obj);
     1808LENSFIELD(X12_sh_obj);
     1809LENSFIELD(X22_sh_obj);
     1810LENSFIELD(E1_sh_obj);
     1811LENSFIELD(E2_sh_obj);
     1812
     1813LENSFIELD(X11_sm_psf);
     1814LENSFIELD(X12_sm_psf);
     1815LENSFIELD(X22_sm_psf);
     1816LENSFIELD(E1_sm_psf);
     1817LENSFIELD(E2_sm_psf);
     1818
     1819LENSFIELD(X11_sh_psf);
     1820LENSFIELD(X12_sh_psf);
     1821LENSFIELD(X22_sh_psf);
     1822LENSFIELD(E1_sh_psf);
     1823LENSFIELD(E2_sh_psf);
  • trunk/Ohana/src/libdvo/src/dvo_tiny_values.c

    r37035 r37807  
    2020  measureT[0].dM         = measure[0].dM;
    2121  measureT[0].airmass    = measure[0].airmass;
     22  measureT[0].RoffGAL    = measure[0].RoffGAL;
     23  measureT[0].DoffGAL    = measure[0].DoffGAL;
    2224  measureT[0].Xccd       = measure[0].Xccd;
    2325  measureT[0].Yccd       = measure[0].Yccd;
  • trunk/Ohana/src/libdvo/src/dvo_util.c

    r33030 r37807  
    145145        if ((image->externID == externID) && (image->sourceID == sourceID)) {
    146146            BuildChipMatch(dvoConfig->images, dvoConfig->nImages);
    147             if (FindMosaicForImage(dvoConfig->images, dvoConfig->nImages, i)) {
    148                 return image;
    149             } else {
    150                 fprintf(stderr, "FindMosaicForImage failed\n");
    151                 return NULL;
    152             }
     147            return image;
    153148        }
    154149    }
  • trunk/Ohana/src/libdvo/src/flatcorr_io.c

    r33963 r37807  
    183183}
    184184
     185// eddie uses cell_x = (int) (X + X_PAD) / (base + X_PAD)
     186// where base = 600, X_PAD = 8, Y_PAD = 10.  denominator is thus (608,610), whic is (4880/8),(4864/8)
     187// these match Eddie's NCELL_X,Y / CHIP_DX,DY, so I think we are good with this:
     188
     189# define X_PAD 8
     190# define Y_PAD 10
     191
    185192float FlatCorrectionOffset (FlatCorrectionTable *flatcorr, int ID, int X, int Y) {
    186193
     
    191198
    192199  // convert X,Y to Xbin, Ybin:
    193   int Xbin = MAX(MIN(X * flatcorr->image[seq].Nx / flatcorr->image[seq].DX, flatcorr->image[seq].Nx - 1), 0);
    194   int Ybin = MAX(MIN(Y * flatcorr->image[seq].Ny / flatcorr->image[seq].DY, flatcorr->image[seq].Ny - 1), 0);
     200  int Xbin = MAX(MIN((X + X_PAD) * flatcorr->image[seq].Nx / flatcorr->image[seq].DX, flatcorr->image[seq].Nx - 1), 0);
     201  int Ybin = MAX(MIN((Y + Y_PAD) * flatcorr->image[seq].Ny / flatcorr->image[seq].DY, flatcorr->image[seq].Ny - 1), 0);
    195202
    196203  // XXX warn if X,Y are out of range? not super important unless *way* out of range
  • trunk/Ohana/src/libdvo/src/mosaic_astrom.c

    r29938 r37807  
    11# include <dvo.h>
     2
     3//  the block of code below was used to define the chip->mosaic relationship before this
     4//  was assigned to the coords value
    25
    36off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic);
    47void SortDISindex (e_time *S, off_t *I, off_t N);
     8
     9# if (0)
    510
    611/* chip-match table: j = ChipMatch[i], images[j] is DIS for images[i] WRP */
     
    9398}
    9499
    95 int BuildChipMatch_old (Image *images, off_t Nimages) {
     100// this is a very old version of BuildChipMatch which does not use bisection
     101int BuildChipMatch_nosort (Image *images, off_t Nimages) {
    96102
    97103  off_t i, j, NDIS;
     
    140146}
    141147
    142 int BuildChipMatch (Image *images, off_t Nimages) {
     148// this is an old version of BuildChipMatch which stores the results here in a local static variable
     149int BuildChipMatch_static (Image *images, off_t Nimages) {
    143150
    144151  off_t i, j, NDIS;
     
    198205  return (TRUE);
    199206}
    200 
     207# endif
     208
     209// XXX Note that this links (images[i].coords.mosaic, images[i].parent) will break
     210// if we reallocate the Image array in the middle of program
     211int BuildChipMatch (Image *images, off_t Nimages) {
     212
     213  off_t i, j, NDIS;
     214
     215  off_t  Ndis = 0;
     216  off_t  *DISentry = NULL;
     217  e_time *DIStzero = NULL;
     218
     219  if (DISentry != NULL) free (DISentry);
     220  if (DIStzero != NULL) free (DIStzero);
     221
     222  // allocate containers for DIS indexing
     223  Ndis = 0;
     224  NDIS = 100;
     225  ALLOCATE (DISentry, off_t, NDIS);
     226  ALLOCATE (DIStzero, e_time, NDIS);
     227
     228  // find all DIS images, save tzero (& photcode?)
     229  for (i = 0; i < Nimages; i++) {
     230    if (strcmp(&images[i].coords.ctype[4], "-DIS")) continue;
     231    DISentry[Ndis] = i;
     232    DIStzero[Ndis] = images[i].tzero;
     233    Ndis ++;
     234    if (Ndis >= NDIS) {
     235      NDIS += 100;
     236      REALLOCATE (DISentry, off_t, NDIS);
     237      REALLOCATE (DIStzero, e_time, NDIS);
     238    }
     239  }
     240
     241  // sort the index, start, and stop by the start times:
     242  SortDISindex (DIStzero, DISentry, Ndis);
     243
     244  /* find all matched WRP images */
     245  for (i = 0; i < Nimages; i++) {
     246    images[i].parent        = NULL; // reset to NULL
     247    images[i].coords.mosaic = NULL; // reset to NULL
     248    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue; // only define link for WRP coords
     249
     250    j = getDISentry (images[i].tzero, images[i].tzero + (int) images[i].exptime, DIStzero, DISentry, Ndis);
     251    if (j == -1) {
     252      fprintf (stderr, "WARNING: can't find matching mosaic \n");
     253      continue;
     254    }
     255    if (j >= Nimages) myAbort("invalid DIS entry");
     256    images[i].parent = &images[j];
     257    images[i].coords.mosaic = &images[j].coords;
     258  }
     259  return (TRUE);
     260}
     261
     262// use bisection to find the overlapping mosaic
    201263off_t getDISentry (e_time start, e_time stop, e_time *startMos, off_t *indexMos, off_t Nmosaic) {
    202 
    203   // use bisection to find the overlapping mosaic
    204264
    205265  off_t Nlo, Nhi, N;
  • trunk/Ohana/src/libdvo/src/skyregion_gsc.c

    r34088 r37807  
    204204  for (i = 0; i < Nregions; i++) {
    205205    strncpy (temp, &buffer[i*48], 48);
    206     temp[49] = 0;
     206    temp[48] = 0;
    207207    hstgsc_hms_to_deg (&Rmin, &Rmax, &Dmin, &Dmax, &temp[7]);
    208208    if (Dmax < Dmin) SWAP (Dmin, Dmax);
  • trunk/Ohana/src/libdvo/src/skyregion_ops.c

    r35102 r37807  
    1616  if (c) return (c+1);
    1717  return name;
     18}
     19
     20/* find region which corresponds to the given index */
     21SkyList *SkyRegionByIndex (SkyTable *table, int index) {
     22 
     23  SkyList *list;
     24
     25  ALLOCATE (list, SkyList, 1);
     26  ALLOCATE (list[0].regions,  SkyRegion *, 1);
     27  ALLOCATE (list[0].filename,  char *, 1);
     28  list[0].Nregions = 0;
     29  list[0].ownElements = FALSE; // this list is only holding a view to the elements
     30  strcpy (list[0].hosts, table[0].hosts);
     31
     32  list[0].regions[0] = &table[0].regions[index];
     33  list[0].filename[0] = table[0].filename[index];
     34  list[0].Nregions = 1;
     35  return (list);
    1836}
    1937
     
    250268  }
    251269
    252   if( Rmax > (Rmin+180.)) {
    253    
    254       double temp = Rmax;
    255       Rmax = Rmin;
    256       Rmin = temp;
    257   }
    258 
    259270  list = SkyListByBounds (table, depth, Rmin, Rmax, Dmin, Dmax);
    260   return (list);
    261 }
    262 
     271
     272  // fprintf (stderr, "%s : %f - %f, %f - %f : %d\n",
     273  // image->name, Rmin, Rmax, Dmin, Dmax, (int) list->Nregions);
     274
     275  return (list);
     276}
     277
     278// a region like -10 10 0 20 will become 350 10 0 20 and return all regions on both sides of 0,360
    263279SkyList *SkyListByBounds (SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax) {
    264280
  • trunk/Ohana/src/libfits/Makefile

    r34088 r37807  
    3232$(HEAD)/F_scan.$(ARCH).o                        $(HEAD)/F_print.$(ARCH).o     \
    3333$(HEAD)/F_copy_H.$(ARCH).o                      $(HEAD)/F_delete.$(ARCH).o    \
    34 $(HEAD)/F_read_XH.$(ARCH).o                     $(HEAD)/F_init_H.$(ARCH).o    \
    35 $(HEAD)/F_convert_H.$(ARCH).o                   $(HEAD)/version.$(ARCH).o
     34$(HEAD)/F_find_H.$(ARCH).o                      $(HEAD)/F_init_H.$(ARCH).o    \
     35$(HEAD)/F_convert_H.$(ARCH).o                   $(HEAD)/F_read_XH.$(ARCH).o   \
     36$(HEAD)/version.$(ARCH).o
    3637
    3738MATRIX_OBJ = \
  • trunk/Ohana/src/libfits/header/F_free_H.c

    r7054 r37807  
    44/*********************** fits free header ***********************************/
    55void gfits_free_header (Header *header) {
     6
     7  // fprintf (stderr, "free data for %zx\n", (size_t) header->buffer);
    68
    79  if (header[0].buffer == (char *) NULL) return;
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r37039 r37807  
    1717# define NEWLINE                 10  /* UNIX RETURN character */
    1818# endif /* NEWLINE */
     19
     20/* gfits_bintable_format returns 'byte' as the type associated with one-byte logical (non-char) values */
     21typedef char byte;
    1922
    2023/********** FITS Constants *********/
     
    116119int     gfits_modify_alt               PROTO((Header *header, char *field, char *mode, int N,...));
    117120int     gfits_print_alt                PROTO((Header *header, char *field, char *mode, int N,...));
     121int     gfits_find_Xheader             PROTO((FILE *f, Header *header, char *extname));
    118122int     gfits_read_Xheader             PROTO((char *filename, Header *header, int N));
    119123int     gfits_read_header              PROTO((char *filename, Header *header));
     
    184188int     gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname));
    185189int     gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable, int padIfShort));
    186 int     gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, off_t start, off_t Nrows));
     190int     gfits_fread_ftable_range       PROTO((FILE *f, int padIfShort, FTable *ftable, off_t start, off_t Nrows));
    187191int     gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row));
    188192int     gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, off_t start, off_t Nrows));
  • trunk/Ohana/src/libfits/table/F_read_T.c

    r29938 r37807  
    1919int gfits_fread_ftable (FILE *f, FTable *table, char *extname) {
    2020
    21   int j, found;
    22   off_t Nbytes;
    2321  Header *header;
    24   char tname[80];
    2522
    2623  header = table[0].header;
    27   fseeko (f, 0, SEEK_SET);
    28 
    29   found = FALSE;
    30   for (j = -1; !found; j++) {
    31     /* load data for this header */
    32     if (!gfits_load_header (f, header)) return (FALSE);
    33 
    34     /* check if this is the correct extension or not */
    35     bzero (tname, 80);
    36     gfits_scan (header, "EXTNAME", "%s", 1, tname);
    37     if (!strcmp (tname, extname)) {
    38       if (gfits_fread_ftable_data (f, table, FALSE)) return (TRUE);
    39       gfits_free_header (header);
    40       return (FALSE);
    41     }
    42 
    43     /* skip to next header */
    44     Nbytes = gfits_data_size (header);
    45     fseeko (f, Nbytes, SEEK_CUR);
    46     gfits_free_header (header);
    47   }
    48   return (TRUE);
    49 }       
     24  if (!gfits_find_Xheader (f, header, extname)) return FALSE;
     25
     26  if (gfits_fread_ftable_data (f, table, FALSE)) return (TRUE);
     27  gfits_free_header (header);
     28  return (FALSE);
     29}
    5030
    5131/*********************** fits read ftable data ***********************************/
     
    8464
    8565/*********************** fits read ftable data ***********************************/
    86 int gfits_fread_ftable_range (FILE *f, FTable *table, off_t start, off_t Nrows) {
     66int gfits_fread_ftable_range (FILE *f, int padIfShort, FTable *table, off_t start, off_t Nrows) {
    8767
    8868  off_t Nbytes, Nread, Nskip, Nx, Ny;
     
    10989    if (ferror (f)) {
    11090      perror ("fits read error");
     91      free (table[0].buffer);
     92      return (FALSE);
     93    }
     94    fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  Nbytes);
     95    if (padIfShort) {
     96      memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
     97      fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
     98      table[0].validsize = Nread;
     99      table[0].datasize = Nbytes;
    111100    } else {
    112       fprintf (stderr, "unexpected eof\n");
    113     }     
    114     free (table[0].buffer);
    115     return (FALSE);
     101      free (table[0].buffer);
     102      return (FALSE);
     103    }
    116104  }
    117105
  • trunk/Ohana/src/libfits/table/F_write_T.c

    r28241 r37807  
    9595
    9696  // cursor must be at start of the table (after table header)
    97   fseeko (f, Nskip, SEEK_CUR);
     97  if (fseeko (f, Nskip, SEEK_CUR)) {
     98    fprintf (stderr, "can't seek table start\n");
     99    return (FALSE);
     100  }
     101
    98102  Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
    99103  if (Nwrite != Nbytes) {
  • trunk/Ohana/src/libkapa/src/KapaWindow.c

    r36488 r37807  
    9898  graphdata[0].lweight = graphdata[0].size = 1.0;
    9999   
    100   graphdata[0].coords.pc1_1 = graphdata[0].coords.pc2_2 = 1.0;
    101   graphdata[0].coords.pc1_2 = graphdata[0].coords.pc2_1 = 0.0;
    102   strcpy (graphdata[0].coords.ctype, "DEC--LIN");
    103   graphdata[0].coords.crval1 = 0.0;
    104   graphdata[0].coords.crval2 = 0.0;
    105   graphdata[0].coords.crpix1 = 0.0;
    106   graphdata[0].coords.crpix2 = 0.0;
    107   graphdata[0].coords.cdelt1 = graphdata[0].coords.cdelt2 = 1.0;
    108   graphdata[0].flipeast = TRUE;
     100  InitCoords (&graphdata[0].coords, "DEC--LIN");
     101  graphdata[0].flipeast = TRUE; // default coords has EW flipped relative to sky
    109102  graphdata[0].flipnorth = FALSE;
    110103
  • trunk/Ohana/src/libohana/Makefile

    r33646 r37807  
    3535$(SRC)/time.$(ARCH).o            \
    3636$(SRC)/gaussj.$(ARCH).o          \
     37$(SRC)/spherical.$(ARCH).o       \
     38$(SRC)/vstats.$(ARCH).o          \
    3739$(SRC)/config.$(ARCH).o          \
    3840$(SRC)/Fread.$(ARCH).o           \
     
    4547$(SRC)/gprint.$(ARCH).o  \
    4648$(SRC)/version.$(ARCH).o
     49
     50# $(SRC)/legendre.$(ARCH).o      \
     51# $(SRC)/gsl_utils.$(ARCH).o     \
    4752
    4853TYPETEST = \
  • trunk/Ohana/src/libohana/include/ohana.h

    r37356 r37807  
    242242// sorting is now defined as a macro call
    243243# include <ohana_sort.h>
     244
     245// vector statistics options
     246typedef enum {
     247  VSTATS_NONE,
     248  VSTATS_MEAN,
     249  VSTATS_MEDIAN,
     250  VSTATS_WT_MEAN,
     251  VSTATS_INNER_MEAN,
     252  VSTATS_INNER_WTMEAN,
     253  VSTATS_CHI_INNER_MEAN,
     254  VSTATS_CHI_INNER_WTMEAN
     255} VStatsMode;
     256
     257typedef struct {
     258  double median;
     259  double mean;
     260  double sigma;
     261  double error;
     262  double chisq;
     263  double min;
     264  double max;
     265  double Upper80;
     266  double Lower20;
     267  double total;
     268  int    Nmeas;
     269  VStatsMode statmode;
     270} VStatsType;
    244271
    245272/* socket / pipe communication buffer */
     
    314341char   *ohana_version          PROTO((void));
    315342
     343int     dgaussjordan_pivot     PROTO((double **A, double **B, int N, int M, double minPivot));
    316344int     dgaussjordan           PROTO((double **A, double **B, int N, int M));
    317345int     fgaussjordan           PROTO((float **A, float **B, int n, int m));
     
    388416int rconnect (char *command, char *hostname, char *shell, int *stdio, int *errorInfo, int doHandshake);
    389417
     418int vstats_setmode (VStatsType *stats, char *mode);
     419int vstats_getstats (double *value, double *dvalue, double *weight, int N, VStatsType *stats);
     420int vstats_getstats_f (float *value, float *dvalue, float *weight, int N, VStatsType *stats);
     421
    390422/*
    391423#   define F_SETFL         4   
     
    404436*/
    405437
    406 # endif
     438
     439/** gsl-based functions for legendre and related polynomials **/
     440
     441double ohana_gsl_sf_log_1plusx (double x, double *err);
     442double ohana_gsl_sf_lnpoch(const double a, const double x, double *err);
     443double ohana_gsl_lnpoch_pos (const double a, const double x, double *err);
     444double ohana_gsl_pochrel_smallx(const double a, const double x, double *err);
     445
     446double legendre_Pl (int l, double x, double *err);
     447double legendre_Plm (int l, int m, double x, double *err);
     448double legendre_Plm_sphere(int l, int m, double x, double *err);
     449
     450typedef struct {
     451  double *Fr;
     452  double *Fi;
     453  int    *l;
     454  int    *m;
     455  int lmax;
     456  int Nterms;
     457} SHterms;
     458
     459SHterms *SHtermsInit (int lmax);
     460void SHtermsFree (SHterms *terms);
     461void SHtermsForRD (SHterms *terms, double R, double D);
     462void SHtermsForLM (SHterms *terms, double R, double D, int l, int m);
     463
     464typedef struct {
     465  double *dR_B;
     466  double *dR_E;
     467  double *dD_B;
     468  double *dD_E;
     469  int    *l;
     470  int    *m;
     471  int lmax;
     472  int Nterms;
     473} VSHterms;
     474
     475VSHterms *VSHtermsInit (int lmax);
     476void VSHtermsFree (VSHterms *terms);
     477void VSHtermsForRD (VSHterms *terms, double R, double D);
     478void VSHtermsForLM (VSHterms *terms, double R, double D, int l, int m);
     479
     480# endif
  • trunk/Ohana/src/libohana/src/gaussj.c

    r36084 r37807  
    11# include <ohana.h>
    22# define GROWTHTEST 0
    3 # define MAX_RANGE 1.0e9
     3# define VERY_VERBOSE 0
     4# define MAX_RANGE 1.0e16
    45
    56// Gauss-Jordan elimination using full pivots based on Press et al's description.  Substantially
     
    89// than their implementation.  (largely based on version by William Kahan)
    910
     11int dgaussjordan (double **A, double **B, int N, int M) {
     12
     13# define myMIN_PIVOT 1.0e-7
     14  int status = dgaussjordan_pivot (A, B, N, M, myMIN_PIVOT);
     15  return status;
     16}
     17
    1018// MAX_RANGE is used to test for ill-conditioned input matrices.  For an ill-conditioned
    1119// matrix, one or more of the pivots trends towards zero.  Rather than allow this to go to the
    1220// numerical precision, I am raising an error if |growth| > 1e8
    13 int dgaussjordan (double **A, double **B, int N, int M) {
     21int dgaussjordan_pivot (double **A, double **B, int N, int M, double MIN_PIVOT) {
    1422
    1523  int *colIndex;
     
    4856    // search for the next pivot
    4957    for (row = 0; row < N; row++) {
    50       if (!finite(A[row][diag])) goto escape;
     58      if (!finite(A[row][diag])) {
     59        fprintf (stderr, "infinity\n");
     60        goto escape;
     61      }
    5162
    5263      // if we have already operated on this row (pivot[row] is true), skip it
     
    6576# if (GROWTHTEST)
    6677    fprintf (stderr, "maxcol: %d\n", maxcol);
     78# if (VERY_VERBOSE)
    6779    fprintf (stderr, "full A matrix:\n");
    6880    for (row = 0; row < N; row++) {
    69         for (col = 0; col < N; col++) {
    70             fprintf (stderr, "%10.3e ", A[row][col]);
    71         }
    72         fprintf (stderr, "\n");
     81      for (col = 0; col < N; col++) {
     82        fprintf (stderr, "%10.3e ", A[row][col]);
     83      }
     84      fprintf (stderr, "\n");
    7385    }
    7486    fprintf (stderr, "\n");
    7587# endif
     88# endif
    7689
    7790    // if pivot[maxcol] is set, we have already done this row: this implies a singular matrix
    78     if (pivot[maxcol]) goto escape;
     91    if (pivot[maxcol]) {
     92      fprintf (stderr, "singular\n");
     93      goto escape;
     94    }
    7995    pivot[maxcol] = TRUE;
    8096
     
    86102    rowIndex[diag] = maxrow;
    87103    colIndex[diag] = maxcol;
    88     if (A[maxcol][maxcol] == 0.0) goto escape;
     104    if (A[maxcol][maxcol] == 0.0) {
     105      fprintf (stderr, "zero pivot\n");
     106      goto escape;
     107    }
     108
    89109    // XXX Kahan replaces the 0.0 pivot with epsilon*(largest element in column) + underFlow
    90110
    91111    /* rescale by pivot reciprocal */
    92112    double tmpval = 1.0 / A[maxcol][maxcol];
     113
     114# if (0)
     115    if (fabs(A[maxcol][maxcol]) < MIN_PIVOT) {
     116      // we are ill-conditioned.  set this row & col to 0.0, 1.0 on pivot
     117      // fprintf (stderr, "WARNING: eliminating degenerate pivot %lf @ A[%d][%d]\n", A[maxcol][maxcol], maxcol, maxcol);
     118      for (col = 0; col < N; col++) A[maxcol][col] = 0.0;
     119      for (col = 0; col < M; col++) B[maxcol][col] = 0.0;
     120      for (row = 0; row < N; row++) A[row][maxcol] = 0.0;
     121      A[maxcol][maxcol] = 1.0;
     122      continue;
     123    }
     124# endif
     125
    93126    // XXX why is this here (don't I double count this element?) A[maxcol][maxcol] = 1.0;
    94127    A[maxcol][maxcol] = 1.0;
     
    102135#   if (GROWTHTEST)
    103136    fprintf (stderr, "column: %d, maxval : %f, growth: %e, epsilon: %e\n", maxcol, tmpval, growth, epsilon);
     137# if (VERY_VERBOSE)
    104138    fprintf (stderr, "A diagonal: ");
    105139    for (col = 0; col < N; col++) fprintf (stderr, "%f ", A[col][col]);
    106140    fprintf (stderr, "\n");
    107141# endif
    108 
    109     if (fabs(growth) > MAX_RANGE) goto escape;
     142# endif
     143
     144    if (fabs(growth) > MAX_RANGE) {
     145      fprintf (stderr, "max range\n");
     146      goto escape;
     147    }
    110148
    111149    /* adjust the elements above the pivot */
     
    119157  }
    120158
    121 # if (GROWTHTEST)
    122     fprintf (stderr, "final A matrix:\n");
    123     for (row = 0; row < N; row++) {
    124         for (col = 0; col < N; col++) {
    125             fprintf (stderr, "%10.3e ", A[row][col]);
    126         }
    127         fprintf (stderr, "\n");
     159# if (GROWTHTEST && VERY_VERBOSE)
     160  fprintf (stderr, "final A matrix:\n");
     161  for (row = 0; row < N; row++) {
     162    for (col = 0; col < N; col++) {
     163      fprintf (stderr, "%10.3e ", A[row][col]);
    128164    }
    129165    fprintf (stderr, "\n");
     166  }
     167  fprintf (stderr, "\n");
    130168# endif
    131169
  • trunk/Ohana/src/libohana/src/glockfile.c

    r35754 r37807  
    288288
    289289    /* set value to IDLE */
    290     fseeko (flock, 0LL, SEEK_SET);
     290    if (fseeko (flock, 0LL, SEEK_SET)) {
     291      *state = LCK_HARDCLOSE;
     292      goto failure;
     293    }
     294
    291295    nbytes = fprintf (flock, "IDLE\n");
    292296    if (nbytes != 5) {
     
    303307 
    304308  /* now unlock the file */
    305   fclose (f);
     309  if (fclose (f)) {
     310    *state = LCK_UNKNOWN;
     311    goto failure;
     312  }
    306313
    307314  *state = LCK_UNLOCK;
  • trunk/Ohana/src/libohana/src/ohana_allocate.c

    r32632 r37807  
    178178  if (!in) return;
    179179
     180  // fprintf (stderr, "free %zx\n", (size_t) in);
     181
    180182  ref = (Memblock *) in - 1;
     183
     184  // fprintf (stderr, "  file: %s, line: %d, func: %s, size: %zd, addr: %zx\n",
     185  // ref->file, ref->line, ref->func, ref->size, (size_t) ref);
    181186
    182187  pthread_mutex_lock(&memBlockListMutex);
  • trunk/Ohana/src/markrock/src/gcatstats.c

    r36481 r37807  
    3434  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    3535  /* reference for coords is center of field  */
     36  InitCoords (&catstats[0].coords, "DEC--TAN");
    3637  catstats[0].coords.crval1 = RaCenter;
    3738  catstats[0].coords.crval2 = DecCenter;
    38   catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
    3939  catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
    40   catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    41   catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    42   strcpy (catstats[0].coords.ctype, "DEC--TAN");
    43 
     40 
    4441  X1 = catstats[0].X;
    4542  Y1 = catstats[0].Y;
  • trunk/Ohana/src/markstar/src/gcatstats.c

    r36483 r37807  
    4444  /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
    4545  /* reference for coords is center of field  */
     46  InitCoords (&catstats[0].coords, "DEC--TAN");
    4647  catstats[0].coords.crval1 = RaCenter;
    4748  catstats[0].coords.crval2 = DecCenter;
    48   catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
    4949  catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
    50   catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    51   catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    52   strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5350
    5451  X1 = catstats[0].X;
  • trunk/Ohana/src/mosastro/src/chips.c

    r7401 r37807  
    2121
    2222    /* bore site center guess */
    23     strcpy (chip[i].map.ctype, "DEC--PLY");
    24     chip[i].map.crpix1 = 0.0;
    25     chip[i].map.crpix2 = 0.0;
    26     chip[i].map.cdelt1 = 1.0;
    27     chip[i].map.cdelt2 = 1.0;
     23    InitCoords (&chip[i].map, "DEC--PLY");
    2824
    2925    /* find (L,M) coords of reference pixel (0,0) */
  • trunk/Ohana/src/mosastro/src/fakefield.c

    r3401 r37807  
    2222
    2323  /* bore site center guess */
    24   strcpy (field.project.ctype, "DEC--TAN");
    25   field.project.crpix1 = 0;
    26   field.project.crpix2 = 0;
     24  InitCoords (&field.project, "DEC--TAN");
    2725 
    2826  /* set TP plate scale */
     
    3028  field.project.cdelt2 = 1.0/3600.0;
    3129
    32   /** allow guess at field rotation?? **/
    33   field.project.pc1_1  = 1;
    34   field.project.pc2_2  = 1;
    35   field.project.pc1_2  = 0;
    36   field.project.pc2_1  = 0;
    37   field.project.Npolyterms = 1;
    38 
    3930  /** distort only has power in polyterms **/
    40   strcpy (field.distort.ctype, "DEC--PLY");
    41   field.distort.crval1 = 0.0;
    42   field.distort.crval2 = 0.0;
    43   field.distort.crpix1 = 0.0;
    44   field.distort.crpix2 = 0.0;
    45   field.distort.cdelt1 = 1.0;
    46   field.distort.cdelt2 = 1.0;
    47  
    48   field.distort.pc1_1  = 1;
    49   field.distort.pc2_2  = 1;
    50   field.distort.pc1_2  = 0;
    51   field.distort.pc2_1  = 0;
    52 
    53   /* how do we handle renormalization? (fixed at 1000 pixels??) */
    54   field.distort.Npolyterms = 3;
    55   for (i = 0; i < 7; i++) {
    56     field.distort.polyterms[i][0] = 0;
    57     field.distort.polyterms[i][1] = 0;
    58   }
     31  InitCoords (&field.distort, "DEC--PLY");
    5932
    6033  return (1);
  • trunk/Ohana/src/mosastro/src/field.c

    r7401 r37807  
    1212
    1313  /* bore site center guess */
    14   strcpy (field.project.ctype, "DEC--TAN");
     14  InitCoords (&field.project, "DEC--TAN");
    1515
    1616  # if (PSASTRO_MODE)
     
    2323  # endif
    2424
    25   field.project.crpix1 = 0;
    26   field.project.crpix2 = 0;
    27  
    2825  /* measure average plate scale - would be better using parabolic min... */
    2926  field.project.cdelt1 = 0;
     
    4744           3600*field.project.cdelt1, 3600*field.project.cdelt2);
    4845
    49   /** allow guess at field rotation?? **/
    50   field.project.pc1_1  = 1;
    51   field.project.pc2_2  = 1;
    52   field.project.pc1_2  = 0;
    53   field.project.pc2_1  = 0;
    54   field.project.Npolyterms = 1;
    55 
    5646  /* bore site center guess */
    57   strcpy (field.distort.ctype, "DEC--PLY");
    58   field.distort.crval1 = 0.0;
    59   field.distort.crval2 = 0.0;
    60   field.distort.crpix1 = 0.0;
    61   field.distort.crpix2 = 0.0;
    62   field.distort.cdelt1 = 1.0;
    63   field.distort.cdelt2 = 1.0;
    64  
    65   /** allow guess at field rotation?? **/
    66   field.distort.pc1_1  = 1;
    67   field.distort.pc2_2  = 1;
    68   field.distort.pc1_2  = 0;
    69   field.distort.pc2_1  = 0;
    70 
    71   /* allow 2nd and 3rd order? */
    72   /* how do we handle renormalization? (fixed at 1000 pixels??) */
    73   field.distort.Npolyterms = 1;
    74   for (i = 0; i < 7; i++) {
    75     field.distort.polyterms[i][0] = 0;
    76     field.distort.polyterms[i][1] = 0;
    77   }
     47  InitCoords (&field.distort, "DEC--PLY");
    7848  return (TRUE);
    7949}
     
    138108int load_field (char *filename) {
    139109
    140   int i;
    141110  Coords coords;
    142111  Header header;
     
    156125
    157126  /* bore site center guess */
    158   strcpy (field.project.ctype, "DEC--TAN");
     127  InitCoords (&field.project, "DEC--TAN");
    159128  field.project.crval1 = 0.5*(field.Rmin + field.Rmax);
    160129  field.project.crval2 = 0.5*(field.Dmin + field.Dmax);
    161   field.project.crpix1 = 0;
    162   field.project.crpix2 = 0;
    163130 
    164131  /* measure average plate scale - would be better using parabolic min... */
     
    174141
    175142  /* bore site center guess */
    176   strcpy (field.distort.ctype, "DEC--PLY");
    177   field.distort.crval1 = 0.0;
    178   field.distort.crval2 = 0.0;
    179   field.distort.crpix1 = 0.0;
    180   field.distort.crpix2 = 0.0;
    181   field.distort.cdelt1 = 1.0;
    182   field.distort.cdelt2 = 1.0;
    183  
    184   /** allow guess at field rotation?? **/
    185   field.distort.pc1_1  = 1;
    186   field.distort.pc2_2  = 1;
    187   field.distort.pc1_2  = 0;
    188   field.distort.pc2_1  = 0;
     143  InitCoords (&field.distort, "DEC--PLY");
    189144
    190   /* allow 2nd and 3rd order? */
    191   /* how do we handle renormalization? (fixed at 1000 pixels??) */
    192   field.distort.Npolyterms = coords.Npolyterms;
    193   for (i = 0; i < 7; i++) {
    194     field.distort.polyterms[i][0] = coords.polyterms[i][0];
    195     field.distort.polyterms[i][1] = coords.polyterms[i][1];
    196   }
    197145  return (TRUE);
    198146}
  • trunk/Ohana/src/mosastro/src/fitpoly.c

    r16058 r37807  
    130130  double R;
    131131
     132  InitCoords (coords, "DEC--PLY");
     133
    132134  /* update the higher order terms */
    133135  if (NORDER > 1) {
     
    166168
    167169  coords[0].Npolyterms = NORDER;
    168   strcpy (coords[0].ctype, "DEC--PLY");
    169170}
    170171
  • trunk/Ohana/src/mosastro/src/mkobs.c

    r7080 r37807  
    104104
    105105      /* Chip-Sky terms */
    106       strcpy (coords.ctype, "DEC--WRP");
     106      InitCoords (&coords, "DEC--WRP");
    107107      coords.crval1 = Ro;
    108108      coords.crval2 = Do;
     
    124124      }
    125125
    126       coords.pc1_1  = 1;
    127       coords.pc2_2  = 1;
    128       coords.pc1_2  = 0;
    129       coords.pc2_1  = 0;
    130       coords.Npolyterms = 1;
    131 
    132126      header = mkheader (2*dX, 2*dY, Nstars, &coords);
    133127
  • trunk/Ohana/src/mosastro/src/mkstandards.c

    r7080 r37807  
    3232
    3333  /* bore site center guess */
    34   strcpy (coords.ctype, "DEC--TAN");
     34  InitCoords (&coords, "DEC--TAN");
    3535  coords.crval1 = atof(argv[1]);
    3636  coords.crval2 = atof(argv[2]);
    3737  coords.crpix1 = dX;
    3838  coords.crpix2 = dX;
    39  
    4039  coords.cdelt1 = 1/3600.0;
    4140  coords.cdelt2 = 1/3600.0;
    42 
    43   coords.pc1_1  = 1;
    44   coords.pc2_2  = 1;
    45   coords.pc1_2  = 0;
    46   coords.pc2_1  = 0;
    47   coords.Npolyterms = 1;
    4841
    4942  if (Random) {
  • trunk/Ohana/src/mosastro/src/testcoords.c

    r3404 r37807  
    5353    exit (1);
    5454  }
    55   RegisterMosaic (&field.project);
     55
     56  chip[0].map.mosaic = &field.project;
    5657  strcpy (chip[0].map.ctype, "DEC--WRP");
    5758  for (i = 0; i < chip[0].Nmatch; i++) {
  • trunk/Ohana/src/opihi/cmd.astro/Makefile

    r36489 r37807  
    7171$(SRC)/star.$(ARCH).o              \
    7272$(SRC)/transform.$(ARCH).o         \
     73$(SRC)/vshimage.$(ARCH).o         \
     74$(SRC)/shimage.$(ARCH).o         \
    7375$(SRC)/imsub.$(ARCH).o             \
    7476$(SRC)/imfit.$(ARCH).o             \
  • trunk/Ohana/src/opihi/cmd.astro/cdensify.c

    r36489 r37807  
    9797  // generate the PSF in a local tangent plane
    9898  Coords coords;
    99   coords.crpix1 = coords.crpix2 = 0.0;
    100   coords.crval1 = coords.crval2 = 0.0;
    101   coords.cdelt1 = coords.cdelt2 = 1.0;
    102   coords.pc1_1  = coords.pc2_2  = 1.0;
    103   coords.pc1_2  = coords.pc2_1  = 0.0;
    104   coords.Npolyterms = 0;
    105   strcpy (coords.ctype, "DEC--TAN");
     99  InitCoords (&coords, "DEC--TAN");
    106100
    107101  r = vr[0].elements.Flt;
  • trunk/Ohana/src/opihi/cmd.astro/coords.c

    r33662 r37807  
    7171    if ((mosbuffer = SelectBuffer (MOSAIC, OLDBUFFER, TRUE)) == NULL) goto escape;
    7272    GetCoords (&moscoords, &mosbuffer[0].header);
    73     RegisterMosaic (&moscoords);
     73    coords.mosaic = &moscoords;
    7474  }
    7575 
  • trunk/Ohana/src/opihi/cmd.astro/csystem.c

    r34342 r37807  
    1313  if (argc != 5) goto syntax;
    1414
    15   switch (argv[1][0]) {
    16     case 'C': input = COORD_CELESTIAL; break;
    17     case 'G': input = COORD_GALACTIC; break;
    18     case 'E': input = COORD_ECLIPTIC; break;
    19     default: goto syntax;
     15  if (!strcmp(argv[1], "G2004")) {
     16    input = COORD_GALACTIC_REID_2004;
     17  } else {
     18    switch (argv[1][0]) {
     19      case 'C': input = COORD_CELESTIAL; break;
     20      case 'G': input = COORD_GALACTIC; break;
     21      case 'E': input = COORD_ECLIPTIC; break;
     22      default: goto syntax;
     23    }
    2024  }
    2125
    22   switch (argv[2][0]) {
    23     case 'C': output = COORD_CELESTIAL; break;
    24     case 'G': output = COORD_GALACTIC; break;
    25     case 'E': output = COORD_ECLIPTIC; break;
    26     default: goto syntax;
     26  if (!strcmp(argv[2], "G2004")) {
     27    output = COORD_GALACTIC_REID_2004;
     28  } else {
     29    switch (argv[2][0]) {
     30      case 'C': output = COORD_CELESTIAL; break;
     31      case 'G': output = COORD_GALACTIC; break;
     32      case 'E': output = COORD_ECLIPTIC; break;
     33      default: goto syntax;
     34    }
    2735  }
    2836
  • trunk/Ohana/src/opihi/cmd.astro/fitplx.c

    r36489 r37807  
    104104  /* project coordinates to a plane centered on the object with units of arcsec */
    105105  Coords coords;
     106  InitCoords (&coords, "DEC--SIN");
    106107  coords.crval1 = Rmean;
    107108  coords.crval2 = Dmean;
    108   coords.crpix1 = 0;
    109   coords.crpix2 = 0;
    110109  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    111   coords.pc1_1  = coords.pc2_2 = 1.0;
    112   coords.pc1_2  = coords.pc2_1 = 0.0;
    113   coords.Npolyterms = 1;
    114   strcpy (coords.ctype, "DEC--SIN");
    115110
    116111  double *X, *Y, *t, *pX, *pY, *dX, *dY;
  • trunk/Ohana/src/opihi/cmd.astro/fitpm.c

    r36489 r37807  
    100100  /* project coordinates to a plane centered on the object with units of arcsec */
    101101  Coords coords;
     102  InitCoords (&coords, "DEC--SIN");
    102103  coords.crval1 = Rmean;
    103104  coords.crval2 = Dmean;
    104   coords.crpix1 = 0;
    105   coords.crpix2 = 0;
    106105  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    107   coords.pc1_1  = coords.pc2_2 = 1.0;
    108   coords.pc1_2  = coords.pc2_1 = 0.0;
    109   coords.Npolyterms = 1;
    110   strcpy (coords.ctype, "DEC--SIN");
    111106
    112107  double *X, *Y, *t, *dX, *dY;
  • trunk/Ohana/src/opihi/cmd.astro/gauss.c

    r36679 r37807  
    3030  if (!GetImageData (&data, &kapa, name)) return (FALSE);
    3131  FREE (name);
     32
     33  int channel = 0;
     34  if ((N = get_argument (argc, argv, "-ch"))) {
     35    channel = GetKapaChannelFromString (argv[N]);
     36    if (!channel) return FALSE;
     37    KiiSetChannel (kapa, channel - 1);
     38  }
    3239
    3340  Nborder = 3;
  • trunk/Ohana/src/opihi/cmd.astro/getcoords.c

    r34345 r37807  
    5454  if (!strcmp(&coords.ctype[4], "-WRP")) {
    5555    if (MOSAIC == NULL) {
    56       gprint (GP_ERR, "must supply mosaic for WRP coords\n");
     56      gprint (GP_ERR, "must supply mosaic for WRP coords with -mosaic [buffer]\n");
    5757      return (FALSE);
    5858    }
     
    6565    }
    6666    GetCoords (&moscoords, &mosbuffer[0].header);
    67     RegisterMosaic (&moscoords);
     67    coords.mosaic = &moscoords;
    6868  }
    6969 
  • trunk/Ohana/src/opihi/cmd.astro/init.c

    r36489 r37807  
    6161int times                   PROTO((int, char **));
    6262int transform               PROTO((int, char **));
     63int vshimage                PROTO((int, char **));
     64int shimage                 PROTO((int, char **));
    6365
    6466static Command cmds[] = { 
     
    121123  {1, "star",        star,         "star stats at rough coords"},
    122124  {1, "transform",   transform,    "geometric transformation of image"},
     125  {1, "vshimage",    vshimage,     "generate images for vector spherical harmonic terms"},
     126  {1, "shimage",     shimage,      "generate images for spherical harmonic terms"},
    123127};
    124128
  • trunk/Ohana/src/opihi/cmd.astro/objload.c

    r34088 r37807  
    1919  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    2020  FREE (name);
     21
     22  int channel = 0;
     23  if ((N = get_argument (argc, argv, "-ch"))) {
     24    channel = GetKapaChannelFromString (argv[N]);
     25    if (!channel) return FALSE;
     26    KiiSetChannel (kapa, channel - 1);
     27  }
    2128
    2229  Objtype = 0;
  • trunk/Ohana/src/opihi/cmd.astro/region.c

    r36489 r37807  
    1717  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
    1818  FREE (name);
     19
     20  int channel = 0;
     21  if ((N = get_argument (argc, argv, "-ch"))) {
     22    channel = GetKapaChannelFromString (argv[N]);
     23    if (!channel) return FALSE;
     24    KiiSetChannel (kapa, channel - 1);
     25  }
    1926
    2027  NoClear = FALSE;
     
    8087  if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE);
    8188  Radius = atof (argv[3]);
    82   strcpy (graphmode.coords.ctype, "DEC--TAN");
     89  InitCoords (&graphmode.coords, "DEC--TAN");
     90
    8391  if (argc == 5) {
    8492    if (!strcasecmp (argv[4], "TAN"))
     
    99107      strcpy (graphmode.coords.ctype, "DEC--PAR");
    100108  }
     109 
     110  graphmode.coords.crval1 = Ra;
     111  graphmode.coords.crval2 = Dec;
    101112
    102  
     113  graphmode.coords.pc1_1 = (graphmode.flipeast) ? -1 : 1;
     114  graphmode.coords.pc2_2 = (graphmode.flipnorth) ? -1 : 1;
     115
    103116  /* ask kapa for coordinate limits, to get the right aspect ratio */
    104117  KapaGetLimits (kapa, &dx, &dy);
     
    132145  set_int_variable ("NORTH_UP", !graphmode.flipnorth);
    133146
    134   graphmode.coords.pc1_1 = (graphmode.flipeast) ? -1 : 1;
    135   graphmode.coords.pc2_2 = (graphmode.flipnorth) ? -1 : 1;
    136 
    137   graphmode.coords.pc1_2 = graphmode.coords.pc2_1 = 0.0;
    138   graphmode.coords.crval1 = Ra;
    139   graphmode.coords.crval2 = Dec;
    140   graphmode.coords.crpix1 = 0.0;
    141   graphmode.coords.crpix2 = 0.0;
    142   graphmode.coords.cdelt1 = graphmode.coords.cdelt2 = 1.0;
    143 
    144147  if (!NoClear) KapaClearSections (kapa);
    145148  KapaSetLimits (kapa, &graphmode);
  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r37049 r37807  
    3939$(SRC)/densify.$(ARCH).o        \
    4040$(SRC)/device.$(ARCH).o \
     41$(SRC)/dft2d.$(ARCH).o  \
    4142$(SRC)/dimendown.$(ARCH).o      \
    4243$(SRC)/dimenup.$(ARCH).o        \
     
    160161$(SRC)/vstats.$(ARCH).o            \
    161162$(SRC)/xsection.$(ARCH).o          \
     163$(SRC)/vsh.$(ARCH).o       \
     164$(SRC)/vshfit.$(ARCH).o    \
     165$(SRC)/shterms.$(ARCH).o           \
     166$(SRC)/shfit.$(ARCH).o     \
     167$(SRC)/shdot.$(ARCH).o     \
     168$(SRC)/shapply.$(ARCH).o           \
    162169$(SRC)/wd.$(ARCH).o                \
    163170$(SRC)/write_vectors.$(ARCH).o     \
  • trunk/Ohana/src/opihi/cmd.data/center.c

    r29540 r37807  
    1616  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1717  FREE (name);
     18
     19  int channel = 0;
     20  if ((N = get_argument (argc, argv, "-ch"))) {
     21    channel = GetKapaChannelFromString (argv[N]);
     22    if (!channel) return FALSE;
     23    KiiSetChannel (kapa, channel - 1);
     24  }
    1825
    1926  // XXX need an option to center the image based on the current plot limits
  • trunk/Ohana/src/opihi/cmd.data/dimenup.c

    r20936 r37807  
    2323    return (FALSE);
    2424  }
    25 
    26   gfits_free_matrix (&buf[0].matrix);
    27   gfits_free_header (&buf[0].header);
    28   CreateBuffer (buf, Nx, Ny, -32, 0.0, 1.0);
     25  ResetBuffer (buf, Nx, Ny, -32, 0.0, 1.0);
    2926
    3027  out = (float *) buf[0].matrix.buffer;
  • trunk/Ohana/src/opihi/cmd.data/erase.c

    r13479 r37807  
    1515  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1616  FREE (name);
     17
     18  int channel = 0;
     19  if ((N = get_argument (argc, argv, "-ch"))) {
     20    channel = GetKapaChannelFromString (argv[N]);
     21    if (!channel) return FALSE;
     22    KiiSetChannel (kapa, channel - 1);
     23  }
    1724
    1825  if (argc < 2) {
  • trunk/Ohana/src/opihi/cmd.data/fit2d.c

    r31160 r37807  
    138138    y = yvec[0].elements.Flt;
    139139    z = zvec[0].elements.Flt;
     140    if (Weight) dz = dzvec[0].elements.Flt;
     141
    140142    for (i = 0; i < xvec[0].Nelements; i++, x++, y++, z++) {
    141143      if (mask[i]) continue;
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r37049 r37807  
    11# include "data.h"
     2// XXX adding a comment
    23
    34int accum            PROTO((int, char **));
     
    3132int densify          PROTO((int, char **));
    3233int device           PROTO((int, char **));
     34int dft2d            PROTO((int, char **));
    3335int dimendown        PROTO((int, char **));
    3436int dimenup          PROTO((int, char **));
     
    147149int vpop             PROTO((int, char **));
    148150int vsmooth          PROTO((int, char **));
     151int vsh              PROTO((int, char **));
     152int vshfit           PROTO((int, char **));
     153int shterms          PROTO((int, char **));
     154int shfit            PROTO((int, char **));
     155int shdot            PROTO((int, char **));
     156int shapply          PROTO((int, char **));
    149157int wd               PROTO((int, char **));
    150158int write_vectors    PROTO((int, char **));
     
    189197  {1, "densify",      densify,          "create an image histogram from a set of vectors"},
    190198  {1, "device",       device,           "set / get current graphics device"},
     199  {1, "dft2d",        dft2d,            "2D discrete fourier transform"},
    191200  {1, "dimendown",    dimendown,        "convert image to vector"},
    192201  {1, "dimenup",      dimenup,          "convert vector to image"},
     
    314323  {1, "vstats",       vstats,           "statistics on a vector"},
    315324  {1, "vzload",       vzload,           "load vectors as overlay on image display (scaled points)"},
     325  {1, "vsh",          vsh,              "Vector Spherical Harmonics"},
     326  {1, "vshfit",       vshfit,           "Vector Spherical Harmonics fits"},
     327  {1, "shterms",      shterms,          "Spherical Harmonics terms"},
     328  {1, "shfit",        shfit,            "Spherical Harmonics fits"},
     329  {1, "shdot",        shdot,            "Spherical Harmonics dot product"},
     330  {1, "shapply",      shapply,          "Spherical Harmonics fit application"},
    316331  {1, "wd",           wd,               "write an image to a file"},
    317332  {1, "write",        write_vectors,    "write vectors to datafile"},
  • trunk/Ohana/src/opihi/cmd.data/load.c

    r34088 r37807  
    2323  if (!GetImageData (&data, &kapa, name)) return (FALSE);
    2424  FREE (name);
     25
     26  int channel = 0;
     27  if ((N = get_argument (argc, argv, "-ch"))) {
     28    channel = GetKapaChannelFromString (argv[N]);
     29    if (!channel) return FALSE;
     30    KiiSetChannel (kapa, channel - 1);
     31  }
    2532
    2633  ISCEL = FALSE;
  • trunk/Ohana/src/opihi/cmd.data/point.c

    r15620 r37807  
    2121  if (!GetImageData (&data, &kapa, name)) return (FALSE);
    2222  FREE (name);
     23
     24  int channel = 0;
     25  if ((N = get_argument (argc, argv, "-ch"))) {
     26    channel = GetKapaChannelFromString (argv[N]);
     27    if (!channel) return FALSE;
     28    KiiSetChannel (kapa, channel - 1);
     29  }
    2330
    2431  celestial = FALSE;
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r37049 r37807  
    55
    66void read_vectors_cleanup ();
     7int read_table_sizes (Header *header);
    78
    89int datafile (int argc, char **argv) {
     
    331332
    332333  off_t Nbytes;
    333   int i, j, N, Nextend, Ny, Binary, vecType, padIfShort;
    334   char type[16], ID[80], *CCDKeyword;
     334  int i, j, N, Ny, Binary, vecType;
     335  char type[16], ID[80];
    335336  FTable table;
    336337  Header header;
    337338  Vector **vec;
    338   int FITS_TRANSPOSE;
    339339
    340340  table.buffer = NULL;
    341341  header.buffer = NULL;
    342342
    343   FITS_TRANSPOSE = FALSE;
     343  int FITS_TRANSPOSE = FALSE;
    344344  if ((N = get_argument (argc, argv, "-transpose"))) {
    345345    remove_argument (N, &argc, argv);
     
    347347  }
    348348
    349   CCDKeyword = NULL;
     349  char *CCDKeyword = NULL;
    350350  if ((N = get_argument (argc, argv, "-keyword"))) {
    351351    remove_argument (N, &argc, argv);
     
    354354  }
    355355
    356   padIfShort = FALSE;
     356  int padIfShort = FALSE;
    357357  if ((N = get_argument (argc, argv, "-pad-if-short"))) {
    358358    remove_argument (N, &argc, argv);
     
    360360  }
    361361
    362   Nextend = -1;
     362  int getSizes = FALSE;
     363  if ((N = get_argument (argc, argv, "-sizes"))) {
     364    remove_argument (N, &argc, argv);
     365    getSizes = TRUE;
     366  }
     367
     368  int Nextend = -1;
    363369  if ((N = get_argument (argc, argv, "-extnum"))) {
    364370    remove_argument (N, &argc, argv);
    365371    Nextend = atoi (extname);
     372  }
     373
     374  int start = 0;
     375  int Nrows = -1; // -1 : read entire table
     376  if ((N = get_argument (argc, argv, "-range"))) {
     377    remove_argument (N, &argc, argv);
     378    start = atoi (argv[N]);
     379    remove_argument (N, &argc, argv);
     380    Nrows = atoi (argv[N]);
     381    remove_argument (N, &argc, argv);
     382  }
     383
     384  // if CharAsVectors, char fields will be saved as vectors NAME:0 -- NAME:n for n characters
     385  // else char fields will be saved as $NAME:0 - $NAME:m for m rows
     386  // if (Ny > 10000), force CharAsVectors
     387  int CharAsVectors = FALSE;
     388  if ((N = get_argument (argc, argv, "-char-vectors"))) {
     389    remove_argument (N, &argc, argv);
     390    CharAsVectors = TRUE;
    366391  }
    367392
     
    397422    }
    398423    if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend);
    399     if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend);
    400 
     424
     425    if (getSizes) {
     426      read_table_sizes (&header);
     427      if (CCDKeyword != NULL) free (CCDKeyword);
     428      gfits_free_header (&header);
     429      return TRUE;
     430    }
     431
     432    if (Nrows == -1) {
     433      Nrows = header.Naxis[1] - start;
     434    }
     435    if (start < 0) ESCAPE ("invalid range: start < 0\n");
     436    if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
     437    if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
     438    if (start + Nrows > header.Naxis[1]) ESCAPE ("invalid range: start + Nrows > Ny (%d)\n", header.Naxis[1]);
     439
     440    // Ny = 100, start = 0, Nrows = -1 -> Nrows => 100
     441    // Ny = 100, start = 10, Nrows = 90
     442
     443    if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
    401444  } else {
    402445    if (CCDKeyword == NULL) {
     
    428471        continue;
    429472      }
    430       if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
     473
     474      if (Nrows == -1) {
     475        Nrows = header.Naxis[1] - start;
     476      }
     477      if (start < 0) ESCAPE ("invalid range: start < 0\n");
     478      if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
     479      if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
     480      if (start + Nrows > header.Naxis[1]) ESCAPE ("invalid range: start + Nrows > Ny (%d)\n", header.Naxis[1]);
     481
     482      if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend);
     483
     484      // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
     485
    431486      break;
    432487    }
     
    465520    if (!FITS_TRANSPOSE) {
    466521      // read string column into a list rather than a vector
    467       if (!strcmp (type, "char")) {
     522      if (!strcmp (type, "char") && !CharAsVectors && (Ny < 3000)) {
    468523        char *fieldName = argv[i];
    469524        char *Ptr = data;
     
    537592  if (vec) free (vec);
    538593}
     594
     595// read -fits foo -sizes -- Nx, Ny, Nfields -> $table:Nx, $table:Ny, $table:$Nfields
     596// read -fits foo -fields
     597
     598int read_table_sizes (Header *header) {
     599 
     600  int Nfields;
     601
     602  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
     603
     604  set_int_variable ("table:Nx", header->Naxis[0]);
     605  set_int_variable ("table:Nx", header->Naxis[0]);
     606  set_int_variable ("table:Nfields", Nfields);
     607
     608  return TRUE;
     609}
     610
  • trunk/Ohana/src/opihi/cmd.data/relocate.c

    r27435 r37807  
    1717  FREE (name);
    1818
     19  int channel = 0;
     20  if ((N = get_argument (argc, argv, "-ch"))) {
     21    channel = GetKapaChannelFromString (argv[N]);
     22    if (!channel) return FALSE;
     23    KiiSetChannel (kapa, channel - 1);
     24  }
     25
    1926  if (argc != 3) {
    2027    gprint (GP_ERR, "USAGE: relocate x y [-n]\n");
  • trunk/Ohana/src/opihi/cmd.data/resize.c

    r29938 r37807  
    1717  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1818  FREE (name);
     19
     20  int channel = 0;
     21  if ((N = get_argument (argc, argv, "-ch"))) {
     22    channel = GetKapaChannelFromString (argv[N]);
     23    if (!channel) return FALSE;
     24    KiiSetChannel (kapa, channel - 1);
     25  }
    1926
    2027  if ((N = get_argument (argc, argv, "-by-image"))) {
  • trunk/Ohana/src/opihi/cmd.data/save.c

    r13479 r37807  
    1616  FREE (name);
    1717
     18  int channel = 0;
     19  if ((N = get_argument (argc, argv, "-ch"))) {
     20    channel = GetKapaChannelFromString (argv[N]);
     21    if (!channel) return FALSE;
     22    KiiSetChannel (kapa, channel - 1);
     23  }
     24
    1825  celestial = FALSE;
    1926  if ((N = get_argument (argc, argv, "-c"))) {
  • trunk/Ohana/src/opihi/cmd.data/tv.c

    r35757 r37807  
    1818  if (!GetImage (&data, &kapa, name)) return (FALSE);
    1919  FREE (name);
     20
     21  int channel = 0;
     22  if ((N = get_argument (argc, argv, "-ch"))) {
     23    remove_argument (N, &argc, argv);
     24    channel = GetKapaChannelFromString (argv[N]);
     25    remove_argument (N, &argc, argv);
     26    if (!channel) return FALSE;
     27    KiiSetChannel (kapa, channel - 1);
     28  }
    2029
    2130  /* shell exits on pipe close, FIX */
  • trunk/Ohana/src/opihi/cmd.data/tvchannel.c

    r16038 r37807  
    2222  }
    2323
    24   Nchannel = atoi (argv[1]);
     24  Nchannel = GetKapaChannelFromString (argv[1]);
     25  if (!Nchannel) return FALSE;
     26
     27  KiiSetChannel (kapa, Nchannel - 1);
     28  return (TRUE);
     29}
     30
     31int GetKapaChannelFromString (char *string) {
     32
     33  int Nchannel = atoi (string);
    2534  if (Nchannel == 0) {
    2635    // try the string values R/Red, G/Green, B/Blue
    27     if (!strcasecmp (argv[1], "R") || !strcasecmp (argv[1], "RED")) {
     36    if (!strcasecmp (string, "R") || !strcasecmp (string, "RED")) {
    2837      Nchannel = 1;
    2938    }
    30     if (!strcasecmp (argv[1], "G") || !strcasecmp (argv[1], "GREEN")) {
     39    if (!strcasecmp (string, "G") || !strcasecmp (string, "GREEN")) {
    3140      Nchannel = 2;
    3241    }
    33     if (!strcasecmp (argv[1], "B") || !strcasecmp (argv[1], "BLUE")) {
     42    if (!strcasecmp (string, "B") || !strcasecmp (string, "BLUE")) {
    3443      Nchannel = 3;
    3544    }
    3645  }
    37   if ((Nchannel < 1) || (Nchannel > 3)) {
    38     gprint (GP_ERR, "invalid channel : use 1 - 3 or (R)ed, (G)reen, (B)lue\n");
    39     return (FALSE);
     46  if ((Nchannel < 1) || (Nchannel > 10)) {
     47    gprint (GP_ERR, "invalid channel : use 1 - 10 or (R)ed, (G)reen, (B)lue\n");
     48    gprint (GP_ERR, "   (R)ed, (G)reen, (B)lue == (1,2,3)\n");
     49    return (0);
    4050  }
    41    
    42   KiiSetChannel (kapa, Nchannel - 1);
    43   return (TRUE);
     51  return Nchannel;
    4452}
  • trunk/Ohana/src/opihi/cmd.data/tvcontour.c

    r13479 r37807  
    7171  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    7272  FREE (name);
     73
     74  int channel = 0;
     75  if ((N = get_argument (argc, argv, "-ch"))) {
     76    channel = GetKapaChannelFromString (argv[N]);
     77    if (!channel) return FALSE;
     78    KiiSetChannel (kapa, channel - 1);
     79  }
    7380
    7481  if ((argc != 4) && (argc != 5)) {
  • trunk/Ohana/src/opihi/cmd.data/tvgrid.c

    r13479 r37807  
    2424  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    2525  FREE (name);
     26
     27  int channel = 0;
     28  if ((N = get_argument (argc, argv, "-ch"))) {
     29    channel = GetKapaChannelFromString (argv[N]);
     30    if (!channel) return FALSE;
     31    KiiSetChannel (kapa, channel - 1);
     32  }
    2633
    2734  if (argc != 3) {
  • trunk/Ohana/src/opihi/cmd.data/vload.c

    r20936 r37807  
    1818  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1919  FREE (name);
     20
     21  int channel = 0;
     22  if ((N = get_argument (argc, argv, "-ch"))) {
     23    channel = GetKapaChannelFromString (argv[N]);
     24    if (!channel) return FALSE;
     25    KiiSetChannel (kapa, channel - 1);
     26  }
    2027
    2128  type = KII_OVERLAY_BOX;
  • trunk/Ohana/src/opihi/cmd.data/vzload.c

    r20936 r37807  
    1818  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1919  FREE (name);
     20
     21  int channel = 0;
     22  if ((N = get_argument (argc, argv, "-ch"))) {
     23    channel = GetKapaChannelFromString (argv[N]);
     24    if (!channel) return FALSE;
     25    KiiSetChannel (kapa, channel - 1);
     26  }
    2027
    2128  MAX_OUTPUT_SIZE = 10.0;
  • trunk/Ohana/src/opihi/dvo/Makefile

    r37049 r37807  
    4646$(SRC)/badimages.$(ARCH).o              \
    4747$(SRC)/catdir.$(ARCH).o                 \
     48$(SRC)/catname.$(ARCH).o                \
    4849$(SRC)/cmatch.$(ARCH).o         \
    4950$(SRC)/cmpload.$(ARCH).o                \
  • trunk/Ohana/src/opihi/dvo/avextract.c

    r37049 r37807  
    55  off_t i, j, n, m;
    66  int N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
    7   int Nsecfilt, VERBOSE, needMeasures;
     7  int Nsecfilt, VERBOSE;
    88  char **cstack, name[1024];
    99  void *Signal;
     
    137137  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    138138  if (PARALLEL && !HOST_ID) {
    139       int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);
     139    int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, 0, VERBOSE);
    140140
    141141    dbFreeFields (fields, Nfields);
     
    163163  }
    164164
    165   // check the requested fields : are all average/secfilt entries, or do we need measures?
    166   needMeasures = FALSE;
    167   for (i = 0; !needMeasures && (i < Nfields); i++) {
    168     if (fields[i].photcode == NULL) continue; // non-measure fields do not have a photcode
    169     if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
    170     if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    171   }
     165  // check the requested fields
     166  int needMeasure = dbFieldNeedMeasure (fields, Nfields);
     167  int needLensobj = dbFieldNeedLensobj (fields, Nfields);
     168  int needStarpar = dbFieldNeedStarpar (fields, Nfields, TRUE);
    172169
    173170  // grab data from all selected sky regions
     
    189186    catalog.filename = (HOST_ID || PARALLEL_LOCAL) ? hostfile : skylist[0].filename[i];
    190187    catalog.catflags = LOAD_AVES | LOAD_SECF;
    191     catalog.catflags |= needMeasures ? LOAD_MEAS : SKIP_MEAS;
     188    catalog.catflags |= needMeasure ? LOAD_MEAS : SKIP_MEAS;
     189    catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
     190    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    192191    catalog.Nsecfilt = 0;
    193192
     
    205204      // XXX for measure values, this could be optimized for one loop over measures...
    206205
    207       m = catalog.average[j].measureOffset;
    208 
    209206      dbExtractAveragesInitAve ();  // reset counters for saved fields (costs very little)
    210207
     208      Average *average = &catalog.average[j];
     209
     210      m = average->measureOffset;
     211      Measure *measure = needMeasure ? &catalog.measure[m] : NULL;
     212
     213      m = average->lensobjOffset;
     214      Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     215
     216      m = average->starparOffset;
     217      StarPar *starpar = needStarpar ? &catalog.starpar[m] : NULL;
     218
     219      m = j*Nsecfilt;
     220      SecFilt *secfilt = &catalog.secfilt[m];
     221
    211222      for (n = 0; n < Nfields; n++) {
    212         values[n] = dbExtractAverages (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     223        values[n] = dbExtractAverages (average, secfilt, measure, lensobj, starpar, &fields[n]);
    213224      }
    214225
  • trunk/Ohana/src/opihi/dvo/avmatch.c

    r37049 r37807  
    149149  }
    150150
    151   // check the requested fields : are all average/secfilt entries, or do we need measures?
    152   int needMeasures = FALSE;
    153   for (i = 0; !needMeasures && (i < Nfields); i++) {
    154     if (fields[i].photcode == NULL) continue; // assert this?
    155     if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
    156     if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    157   }
     151  // check the requested fields
     152  int needMeasure = dbFieldNeedMeasure (fields, Nfields);
     153  int needLensobj = dbFieldNeedLensobj (fields, Nfields);
     154  int needStarpar = dbFieldNeedStarpar (fields, Nfields, TRUE);
    158155
    159156  /* create output storage vectors */
     
    194191    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    195192    catalog.catflags = LOAD_AVES | LOAD_SECF;
    196     catalog.catflags |= needMeasures ? LOAD_MEAS : SKIP_MEAS;
     193    catalog.catflags |= needMeasure ? LOAD_MEAS    : SKIP_MEAS;
     194    catalog.catflags |= needLensobj ? LOAD_LENSOBJ : SKIP_LENSOBJ;
     195    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    197196    catalog.Nsecfilt = 0;
    198197
     
    219218      if (Ncat == -2) continue; // no matches to this point
    220219
    221       m = catalog.average[Ncat].measureOffset;
     220      m = Ncat;
     221      Average *average = &catalog.average[m];
     222
     223      m = average->measureOffset;
     224      Measure *measure = needMeasure ? &catalog.measure[m] : NULL;
     225
     226      m = average->lensobjOffset;
     227      Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     228
     229      m = average->starparOffset;
     230      StarPar *starpar = needStarpar ? &catalog.starpar[m] : NULL;
     231
     232      m = Ncat*Nsecfilt;
     233      SecFilt *secfilt = &catalog.secfilt[m];
    222234
    223235      // reset counters for saved fields, extract fields
    224236      dbExtractAveragesInitAve ();
    225237      for (n = 0; n < Nfields; n++) {
    226         values[n] = dbExtractAverages (&catalog.average[Ncat], &catalog.secfilt[Ncat*Nsecfilt], &catalog.measure[m], &fields[n]);
     238        values[n] = dbExtractAverages (average, secfilt, measure, lensobj, starpar, &fields[n]);
    227239      }
    228240
  • trunk/Ohana/src/opihi/dvo/cmpload.c

    r34088 r37807  
    2424  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    2525  FREE (name);
     26
     27  int channel = 0;
     28  if ((N = get_argument (argc, argv, "-ch"))) {
     29    channel = GetKapaChannelFromString (argv[N]);
     30    if (!channel) return FALSE;
     31    KiiSetChannel (kapa, channel - 1);
     32  }
    2633
    2734  Objtype = 0;
  • trunk/Ohana/src/opihi/dvo/dvo_host_utils.c

    r35416 r37807  
    137137
    138138  // determine the sky region
     139  // XXX EAM 20141230 : this needs to respect the -region selection
    139140  double Rmin, Rmax, Dmin, Dmax;
    140141  get_skyregion (&Rmin, &Rmax, &Dmin, &Dmax);
  • trunk/Ohana/src/opihi/dvo/find_matches.c

    r36489 r37807  
    3838   * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    3939   */
     40  InitCoords (&tcoords, "DEC--ARC");
    4041  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    4142  if (region[0].Dmax < 90) {
     
    4445    tcoords.crval2 = 90.0;
    4546  }
    46   tcoords.crpix1 = 0;
    47   tcoords.crpix2 = 0;
    4847  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    49   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    50   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    51   tcoords.Npolyterms = 1;
    52   strcpy (tcoords.ctype, "DEC--ARC");
    5348
    5449  // this region includes a boundary layer of size RADIUS
  • trunk/Ohana/src/opihi/dvo/gimages.c

    r36489 r37807  
    8585  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    8686  image_subset (image, Nimage, &subset, &Nsubset, selection, tzero, trange, TimeSelect);
    87   BuildChipMatch (image, Nimage);
     87  // BuildChipMatch (image, Nimage);
    8888
    8989  int DistortImage = wordhash ("-DIS");
     
    102102      }
    103103    }     
    104     if (!FindMosaicForImage (image, Nimage, i)) continue;
    105104
    106105    typehash = wordhash (&image[i].coords.ctype[4]);
     
    129128      if (fabs(Ro - Ra) > 120.0) continue;
    130129
     130      InitCoords (&local, "DEC--TAN");
    131131      local.crval1 = Ro;
    132132      local.crval2 = Do;
    133       local.crpix1 = local.crpix2 = 0.0;
    134133      local.cdelt1 = local.cdelt2 = 1.0/3600.0;
    135       local.pc1_1 = local.pc2_2 = 1.0;
    136       local.pc2_1 = local.pc1_2 = 0.0;
    137       local.Npolyterms = 1;
    138       strcpy (local.ctype, "DEC--TAN");
    139134
    140135      if (typehash == DistortImage) {
  • trunk/Ohana/src/opihi/dvo/images.c

    r34584 r37807  
    131131  /* it is not an error for the database not to have any images */
    132132  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (TRUE);
    133   BuildChipMatch (image, Nimage);
     133  // BuildChipMatch (image, Nimage);
    134134
    135135  if (SOLO_MOSAIC && photcode) {
     
    152152  SetVector (&Yvec, OPIHI_FLT, NPTS);
    153153
     154  Image *mosaic = NULL;
     155
    154156  ALLOCATE (plist, int, NPTS);
    155157  n = N = 0;
     
    157159    if (ByName && strncmp (image[i].name, name, strlen(name))) continue;
    158160    if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
    159     if (!(Nmosaic = FindMosaicForImage (image, Nimage, i))) continue;
    160     Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
     161
     162    mosaic = image[i].parent;
     163    Nmosaic = (SOLO_MOSAIC && mosaic) ? mosaic - image : -1;
     164
    161165    if (photcode) {
    162166      if ( photcodeEquiv && (photcode[0].code != GetPhotcodeEquivCodebyCode(image[i].photcode))) continue;
     
    170174    typehash = wordhash (&image[i].coords.ctype[4]);
    171175
    172     if (photcode && SOLO_MOSAIC) {
     176    if (photcode && SOLO_MOSAIC && (Nmosaic >= 0)) {
    173177      // mosaic (DIS) images are not currently given a photcode : plot these via the WRP entries
    174178      /* DIS images represent a field, not a chip */
    175179      if (typehash != ChipImage) continue;
    176180      if (foundMosaic[Nmosaic]) continue;
    177       x[0] = -0.5*image[Nmosaic].NX; y[0] = -0.5*image[Nmosaic].NY;
    178       x[1] = +0.5*image[Nmosaic].NX; y[1] = -0.5*image[Nmosaic].NY;
    179       x[2] = +0.5*image[Nmosaic].NX; y[2] = +0.5*image[Nmosaic].NY;
    180       x[3] = -0.5*image[Nmosaic].NX; y[3] = +0.5*image[Nmosaic].NY;
     181      x[0] = -0.5*mosaic->NX; y[0] = -0.5*mosaic->NY;
     182      x[1] = +0.5*mosaic->NX; y[1] = -0.5*mosaic->NY;
     183      x[2] = +0.5*mosaic->NX; y[2] = +0.5*mosaic->NY;
     184      x[3] = -0.5*mosaic->NX; y[3] = +0.5*mosaic->NY;
    181185      for (j = 0; j < Npts; j++) {
    182         status = XY_to_RD (&r[j], &d[j], x[j], y[j], &image[Nmosaic].coords);
     186        status = XY_to_RD (&r[j], &d[j], x[j], y[j], &mosaic->coords);
    183187        if (!status) break;
    184188        r[j] = ohana_normalize_angle (r[j]);
     
    198202
    199203    /* DIS images represent a field, not a chip */
    200     if ((typehash == DistortImage) && !WITH_MOSAIC) continue;
    201     if ((typehash != DistortImage) &&  SOLO_MOSAIC) continue;
     204    if ((typehash == DistortImage) && !WITH_MOSAIC) continue; // do not plot the mosaic images
     205    if ((typehash != DistortImage) &&  SOLO_MOSAIC) continue; // plot only the mosaic images
     206
    202207    if (typehash == DistortImage) {
    203208      x[0] = -0.5*image[i].NX; y[0] = -0.5*image[i].NY;
  • trunk/Ohana/src/opihi/dvo/imbox.c

    r34584 r37807  
    4343  SetVector (&Yvec, OPIHI_FLT, NPTS);
    4444
     45  mosaic.ctype[0] = 0; 
     46
    4547  while (gfits_fread_header (f, &header)) {
    4648    if (!GetCoords (&coords, &header)) goto skip;
    4749    if (!SOLO_PHU && !strcmp (&coords.ctype[4], "-DIS")) {
    4850      mosaic = coords;
    49       RegisterMosaic (&mosaic);
    5051      goto skip;
     52    }
     53    if (!strcmp (&coords.ctype[4], "-WRP")) {
     54      if (!mosaic.ctype[0]) {
     55        fprintf (stderr, "PHU mosaic not found\n");
     56        return FALSE;
     57      }
     58      coords.mosaic = &mosaic;
    5159    }
    5260
  • trunk/Ohana/src/opihi/dvo/imdata.c

    r37049 r37807  
    8787  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    8888  image_subset (image, Nimage, &subset, &Nsubset, selection, tzero, trange, TimeSelect);
    89   BuildChipMatch (image, Nimage);
     89  // BuildChipMatch (image, Nimage);
    9090  GetTimeFormat (&TimeReference, &TimeFormat);
    9191
     
    103103    I = subset[i];
    104104
    105     if (!FindMosaicForImage (image, Nimage, I)) continue;
    106105    skyset = SkyListByImage (sky, -1, &image[I]);
    107106
  • trunk/Ohana/src/opihi/dvo/imdense.c

    r34584 r37807  
    2222
    2323  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    24   BuildChipMatch (image, Nimage);
     24  // BuildChipMatch (image, Nimage);
    2525
    2626  Rmin = graphmode.coords.crval1 - 182.0;
     
    4242    /* project this image to screen display coords */
    4343    status = FALSE;
    44     if (!FindMosaicForImage (image, Nimage, i)) continue;
    4544    XY_to_RD (&r, &d, x, y, &image[i].coords);
    4645    r = ohana_normalize_angle (r);
  • trunk/Ohana/src/opihi/dvo/imextract.c

    r37049 r37807  
    9090
    9191  if ((image = LoadImagesDVO (&Nimage)) == NULL) goto escape;
    92   BuildChipMatch (image, Nimage);
     92  // BuildChipMatch (image, Nimage);
    9393  dbExtractImagesInit ();
    9494
  • trunk/Ohana/src/opihi/dvo/imlist.c

    r34088 r37807  
    3838  }
    3939
    40   // int RegionSelect = FALSE;
    41   // if ((N = get_argument (argc, argv, "-region"))) {
    42   //   remove_argument (N, &argc, argv);
    43   //   RegionSelect = TRUE;
    44   // }
    45 
    4640  PhotcodeValue = NULL;
    4741  PhotcodeSelect = FALSE;
     
    7670  }
    7771
     72  int MAX_LIST = -1;
     73  if ((N = get_argument (argc, argv, "-max-list"))) {
     74    remove_argument (N, &argc, argv);
     75    MAX_LIST = atoi (argv[N]);
     76    remove_argument (N, &argc, argv);
     77  }
     78
    7879  if (argc != 1) {
    79     gprint (GP_ERR, "USAGE: image [-time start range] [-region] [-name string]\n");
     80    gprint (GP_ERR, "USAGE: image [-time start range] [-region] [-name string] [-photcode code] [-Nphotcode N] [-max-list N]\n");
    8081    return (FALSE);
    8182  }
     
    8384  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    8485  image_subset (image, Nimage, &subset, &Nsubset, selection, tzero, trange, TimeSelect);
    85   BuildChipMatch (image, Nimage);
     86  MAX_LIST = MAX_LIST < 0 ? Nsubset : MIN(MAX_LIST, Nsubset);
    8687
    8788  GetTimeFormat (&TimeReference, &TimeFormat);
    8889
    89   for (j = 0; j < Nsubset; j++) {
     90  for (j = 0; j < MAX_LIST; j++) {
    9091    i = subset[j];
    9192    if (NameSelect && (strstr (image[i].name, name) == (char *) NULL)) continue;
     
    9798      }
    9899    }
    99     if (!FindMosaicForImage (image, Nimage, i)) continue;
    100100    t = TimeValue (image[i].tzero, TimeReference, TimeFormat);
    101101    if (!strcmp(&image[i].coords.ctype[4], "-DIS")) {
  • trunk/Ohana/src/opihi/dvo/imstats.c

    r34584 r37807  
    3131
    3232  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    33   BuildChipMatch (image, Nimage);
     33  // BuildChipMatch (image, Nimage);
    3434
    3535  /* assign vector values */
     
    4444    else
    4545      Yvec.elements.Flt[i] = image[i].dMcal;
    46     if (!FindMosaicForImage (image, Nimage, i)) continue;
    4746    XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    4847    gprint (GP_ERR, "%d %8.4f %8.4f %10d %6d  %5.3f %6.3f %6.3f\n",
  • trunk/Ohana/src/opihi/dvo/init.c

    r37049 r37807  
    77int calmextract     PROTO((int, char **));
    88int catlog          PROTO((int, char **));
     9int catname         PROTO((int, char **));
    910int catdir_define   PROTO((int, char **));
    1011int ccd             PROTO((int, char **));
     
    6869//  {1, "calextract",  calextract,   "extract photometry calibration"},
    6970//  {1, "calmextract", calmextract,  "extract photometry calibration"},
     71  {1, "catname",     catname,      "list catalog files by name"},
    7072  {1, "catdir",      catdir_define,"re-define CATDIR"},
    7173//  {1, "ccd",         ccd,          "plot color-color diagram"},
  • trunk/Ohana/src/opihi/dvo/mextract.c

    r35416 r37807  
    211211  }
    212212
     213  // int needLensing = dbFieldNeedLensing (fields, Nfields);
     214  int needStarpar = dbFieldNeedStarpar (fields, Nfields, FALSE);
     215
    213216  // grab data from all selected sky regions
    214217  Signal = signal (SIGINT, handle_interrupt);
     
    227230    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    228231    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     232    // catalog.catflags |= needLensing ? LOAD_LENSING : SKIP_LENSING;
     233    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    229234    catalog.Nsecfilt = Nsecfilt;
    230235
     
    259264        // extract the relevant values for this measurement
    260265        dbExtractMeasuresInitMeas (); // reset counters for saved fields  (costs very little
     266
     267        Average *average = &catalog.average[j];
     268
     269        int Nstarpar = average->starparOffset;
     270        StarPar *starpar = needStarpar ? &catalog.starpar[Nstarpar] : NULL;
     271
     272        // int Nlensing = average->lensobjOffset;
     273        // Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     274
     275        int Nsec = j*Nsecfilt;
     276        SecFilt *secfilt = &catalog.secfilt[Nsec];
     277
    261278        for (n = 0; n < Nfields; n++) {
    262           values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     279          values[n] = dbExtractMeasures (average, secfilt, &catalog.measure[m], NULL, starpar, &fields[n]);
    263280        }
    264281        // fprintf (stderr, "object: ave: %f, cat: %f, averef %d\n", fields[n].name, values[2], values[3], catalog.measure[m].averef);
  • trunk/Ohana/src/opihi/dvo/mmatch.c

    r35416 r37807  
    233233  ALLOCATE (index, off_t, Nelem);
    234234
     235  // int needLensing = dbFieldNeedLensing (fields, Nfields);
     236  int needStarpar = dbFieldNeedStarpar (fields, Nfields, FALSE);
     237
    235238  // grab data from all selected sky regions
    236239  Signal = signal (SIGINT, handle_interrupt);
     
    246249    catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i];
    247250    catalog.catflags = LOAD_AVES | LOAD_SECF | LOAD_MEAS;
     251    catalog.catflags |= needStarpar ? LOAD_STARPAR : SKIP_STARPAR;
    248252    catalog.Nsecfilt = Nsecfilt;
    249253
     
    282286        // extract the relevant values for this measurement
    283287        dbExtractMeasuresInitMeas (); // reset counters for saved fields  (costs very little
     288
     289        Average *average = &catalog.average[Ncat];
     290
     291        int Nstarpar = average->starparOffset;
     292        StarPar *starpar = needStarpar ? &catalog.starpar[Nstarpar] : NULL;
     293
     294        // int Nlensing = average->lensobjOffset;
     295        // Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     296
     297        int Nsec = Ncat*Nsecfilt;
     298        SecFilt *secfilt = &catalog.secfilt[Nsec];
     299
    284300        for (n = 0; n < Nfields; n++) {
    285           values[n] = dbExtractMeasures (&catalog.average[Ncat], &catalog.secfilt[Ncat*Nsecfilt], &catalog.measure[m], &fields[n]);
     301          values[n] = dbExtractMeasures (average, secfilt, &catalog.measure[m], NULL, starpar, &fields[n]);
    286302        }
    287303
  • trunk/Ohana/src/opihi/dvo/mmextract.c

    r35263 r37807  
    174174  }
    175175
     176  // int needLensing = dbFieldNeedLensing (fields, Nfields);
     177  int needStarpar = dbFieldNeedStarpar (fields, Nfields, FALSE);
     178
    176179  // grab data from all selected sky regions
    177180  Signal = signal (SIGINT, handle_interrupt);
     
    213216        // extract the relevant values for this measurement
    214217        dbExtractMeasuresInitMeas (); // reset counters for saved fields
     218
     219        Average *average = &catalog.average[j];
     220
     221        int Nstarpar = average->starparOffset;
     222        StarPar *starpar = needStarpar ? &catalog.starpar[Nstarpar] : NULL;
     223
     224        // int Nlensing = average->lensobjOffset;
     225        // Lensobj *lensobj = needLensobj ? &catalog.lensobj[m] : NULL;
     226
     227        int Nsec = j*Nsecfilt;
     228        SecFilt *secfilt = &catalog.secfilt[Nsec];
     229
    215230        for (n = 0; n < Nfields; n++) {
    216231          // values needs to be a pointer to a type with FLT and INT (with a union, we would save a bit of memory...)
    217           values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     232          values[n] = dbExtractMeasures (average, secfilt, &catalog.measure[m], NULL, starpar, &fields[n]);
    218233        }
    219234        // fprintf (stderr, "object: ave: %f, cat: %f, averef %d\n", fields[n].name, values[2], values[3], catalog.measure[m].averef);
  • trunk/Ohana/src/opihi/dvo/objectcoverage.c

    r34088 r37807  
    147147  strcpy (buf[0].file, "(empty)");
    148148
     149  InitCoords (&coords, projection);
    149150  coords.crval1 = RaCenter;
    150151  coords.crval2 = DecCenter;
    151152  coords.crpix1 = 0.5*Nx;
    152153  coords.crpix2 = 0.5*Ny;
    153   strcpy (coords.ctype, projection);
    154   coords.pc1_1 = -1.0;
     154  coords.pc1_1 = -1.0; // sky parity
    155155  coords.pc2_2 = +1.0;
    156   coords.pc1_2 =  0.0;
    157   coords.pc2_1 =  0.0;
    158156  coords.cdelt1 = coords.cdelt2 = pixscale;
    159   coords.Npolyterms = 0;
    160157
    161158  PutCoords (&coords, &buf[0].header);
     
    166163    for (xs = 0; xs < Nx; xs++) {
    167164      status = XY_to_RD (&r, &d, (double)(xs), (double)(ys), &coords);
    168       status &= (r >= 0);
    169       status &= (r <= 360);
     165      r = ohana_normalize_angle (r);
    170166      if (status) {
    171167        V[ys*Nx + xs] = ShowDensity ?  0 : 2;
  • trunk/Ohana/src/opihi/dvo/showtile.c

    r36489 r37807  
    2828
    2929  /* reference for coords is this image */
    30   coords.crpix1 = coords.crpix2 = 0.0;
    31   coords.crval1 = coords.crval2 = 0.0;
    32   coords.cdelt1 = coords.cdelt2 = 1.0;
    33   coords.pc1_1  = coords.pc2_2  = 1.0;
    34   coords.pc1_2  = coords.pc2_1  = 0.0;
    35   coords.Npolyterms = 0;
    36   strcpy (coords.ctype, "DEC--TAN");
     30  InitCoords (&coords, "DEC--TAN");
    3731 
    3832  /* fill in top-left region */
  • trunk/Ohana/src/opihi/dvo/simage.c

    r36489 r37807  
    4242  }
    4343  /* get astrometry information */
    44   strcpy (coords.ctype, "NONE");
    45   gfits_scan (&header, "CTYPE2",   "%s",  1, coords.ctype);
    46   if (strcmp (coords.ctype, "DEC--PLY")) {
    47     gprint (GP_ERR, "ERROR: wrong astrometric info in header\n");
     44  if (!GetCoords (&coords, &header)) {
     45    gprint (GP_ERR, "ERROR: can't get coord info from header\n");
    4846    return (FALSE);
    4947  }
    50   gfits_scan (&header, "CDELT1",   "%f", 1, &coords.cdelt1);
    51   gfits_scan (&header, "CDELT2",   "%f", 1, &coords.cdelt2);
    52   gfits_scan (&header, "CRVAL1",   "%lf", 1, &coords.crval1);
    53   gfits_scan (&header, "CRVAL2",   "%lf", 1, &coords.crval2); 
    54   gfits_scan (&header, "CRPIX1",   "%f", 1, &coords.crpix1);
    55   gfits_scan (&header, "CRPIX2",   "%f", 1, &coords.crpix2);
    56   gfits_scan (&header, "PC001001", "%f", 1, &coords.pc1_1);
    57   gfits_scan (&header, "PC001002", "%f", 1, &coords.pc1_2);
    58   gfits_scan (&header, "PC002001", "%f", 1, &coords.pc2_1);
    59   gfits_scan (&header, "PC002002", "%f", 1, &coords.pc2_2);
    60   /* RA Terms */
    61   gfits_scan (&header, "PCA1X2Y0", "%f", 1, &coords.polyterms[0][0]);
    62   gfits_scan (&header, "PCA1X1Y1", "%f", 1, &coords.polyterms[1][0]);
    63   gfits_scan (&header, "PCA1X0Y2", "%f", 1, &coords.polyterms[2][0]);
    64   gfits_scan (&header, "PCA1X3Y0", "%f", 1, &coords.polyterms[3][0]);
    65   gfits_scan (&header, "PCA1X2Y1", "%f", 1, &coords.polyterms[4][0]);
    66   gfits_scan (&header, "PCA1X1Y2", "%f", 1, &coords.polyterms[5][0]);
    67   gfits_scan (&header, "PCA1X0Y3", "%f", 1, &coords.polyterms[6][0]);
    68   /* Dec Terms */                           
    69   gfits_scan (&header, "PCA2X2Y0", "%f", 1, &coords.polyterms[0][1]);
    70   gfits_scan (&header, "PCA2X1Y1", "%f", 1, &coords.polyterms[1][1]);
    71   gfits_scan (&header, "PCA2X0Y2", "%f", 1, &coords.polyterms[2][1]);
    72   gfits_scan (&header, "PCA2X3Y0", "%f", 1, &coords.polyterms[3][1]);
    73   gfits_scan (&header, "PCA2X2Y1", "%f", 1, &coords.polyterms[4][1]);
    74   gfits_scan (&header, "PCA2X1Y2", "%f", 1, &coords.polyterms[5][1]);
    75   gfits_scan (&header, "PCA2X0Y3", "%f", 1, &coords.polyterms[6][1]);
    76   coords.Npolyterms = 2; /* how many do we use? */
    7748
    7849  /* find number of stars */
  • trunk/Ohana/src/opihi/dvo/skycoverage.c

    r33963 r37807  
    204204  strcpy (buf[0].file, "(empty)");
    205205
     206  InitCoords (&coords, projection);
    206207  coords.crval1 = RaCenter;
    207208  coords.crval2 = DecCenter;
    208209  coords.crpix1 = 0.5*Nx;
    209210  coords.crpix2 = 0.5*Ny;
    210   strcpy (coords.ctype, projection);
    211   coords.pc1_1 = -1.0;
     211  coords.pc1_1 = -1.0; // sky parity
    212212  coords.pc2_2 = +1.0;
    213   coords.pc1_2 =  0.0;
    214   coords.pc2_1 =  0.0;
    215213  coords.cdelt1 = coords.cdelt2 = pixscale;
    216   coords.Npolyterms = 0;
    217214
    218215  PutCoords (&coords, &buf[0].header);
     
    222219      return (FALSE);
    223220  }
    224   BuildChipMatch (image, Nimage);
     221  // BuildChipMatch (image, Nimage);
    225222
    226223  V = (float *)buf[0].matrix.buffer;
     
    230227    for (xs = 0; xs < Nx; xs++) {
    231228      status = XY_to_RD (&r, &d, (double)(xs), (double)(ys), &coords);
    232       status &= (r >= 0);
    233       status &= (r <= 360);
     229      r = ohana_normalize_angle (r);
     230
    234231      // are we in a part of the projection covering the sky or not?
    235232      if (status) {
     
    284281      }
    285282    }
    286 
    287     if (!FindMosaicForImage (image, Nimage, i)) continue;
    288283
    289284    typehash = wordhash (&image[i].coords.ctype[4]);
  • trunk/Ohana/src/opihi/dvo/subpix.c

    r37049 r37807  
    115115  /* load all images, extract those touching Ra, Dec */
    116116  if ((image = LoadImagesDVO (&Nimage)) == NULL) return (FALSE);
    117   BuildChipMatch (image, Nimage);
     117  // BuildChipMatch (image, Nimage);
    118118
    119119  for (i = 0; i < Nimage; i++) {
    120     if (!FindMosaicForImage (image, Nimage, i)) continue;
    121120    status = RD_to_XY (&X, &Y, Ra, Dec, &image[i].coords);
    122121    if (!status || (X < 0) || (X > image[i].NX) || (Y < 0) || (Y > image[i].NY)) continue;
     
    134133  for (i = 0; i < Nsub; i++) {
    135134    I = index[i];
    136     if (!FindMosaicForImage (image, Nimage, I)) continue;
    137135    Timage = image[I].tzero;
    138136    for (j = 0; j < Nmeasure; j++) {
  • trunk/Ohana/src/opihi/include/astro.h

    r31635 r37807  
    1212void FreeAstro (void);
    1313
    14 typedef struct {
    15   int    isIdentity;          // identity transformation
    16   double phi;                 // saved in radians
    17   double Xo;                  // saved in radians
    18   double xo;                  // saved in degrees
    19   double sin_phi_cos_Xo;      // pre-computed values
    20   double sin_phi_sin_Xo;      // pre-computed values
    21   double cos_phi_cos_Xo;      // pre-computed values
    22   double cos_phi_sin_Xo;      // pre-computed values
    23   double cos_phi;             // pre-computed values
    24   double sin_phi;             // pre-computed values
    25   double cos_Xo;              // pre-computed values
    26   double sin_Xo;              // pre-computed values
    27 } CoordTransform;
    28 
    29 #ifndef MOVED_TO_LIBDVO
    30 typedef enum {COORD_NONE, COORD_CELESTIAL, COORD_GALACTIC, COORD_ECLIPTIC} CoordTransformSystem;
    31 #endif
    32 
    33 CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output);
    34 int ApplyTransform (double *x, double *y, double X, double Y, CoordTransform *transform);
    35 
    3614# endif
  • trunk/Ohana/src/opihi/include/data.h

    r36679 r37807  
    224224void ListMedImages ();
    225225
     226// in tvchannel.c
     227int GetKapaChannelFromString (char *string);
     228
    226229# endif
  • trunk/Ohana/src/opihi/include/dvomath.h

    r37049 r37807  
    187187int           ListBuffersToList     PROTO((char *name));
    188188int           CreateBuffer          PROTO((Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale));
     189int           ResetBuffer           PROTO((Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale));
    189190Buffer       *SelectBuffer          PROTO((char *name, int mode, int verbose));
    190191void          dump_buffers          PROTO((int n));  /* deprecated? */
  • trunk/Ohana/src/opihi/lib.shell/BufferOps.c

    r33662 r37807  
    8888}
    8989
     90int ResetBuffer (Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale) {
     91
     92  gfits_free_matrix (&buf[0].matrix);
     93  gfits_free_header (&buf[0].header);
     94  CreateBuffer (buf, Nx, Ny, bitpix, bzero, bscale);
     95  return TRUE;
     96}
     97
    9098int CreateBuffer (Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale) {
    9199
  • trunk/Ohana/src/opihi/pantasks/controller_status.c

    r23530 r37807  
    33int controller_status (int argc, char **argv) {
    44
    5   int status;
    6   char command[1024];
     5  int i, status;
     6  char command[1024], tmpline[1024];
    77  IOBuffer buffer;
    88
    9   if (argc != 1) {
    10     gprint (GP_ERR, "USAGE: controller status\n");
     9  if ((argc > 1) && (!strcasecmp(argv[1], "help")))  {
     10    gprint (GP_ERR, "USAGE: controller status [options]\n");
     11    gprint (GP_ERR, "  OPTIONS:\n");
     12    gprint (GP_ERR, "  -cmd command\n");
     13    gprint (GP_ERR, "  -host hostname\n");
     14    gprint (GP_ERR, "  -state state\n");
     15    gprint (GP_ERR, "  -age seconds\n");
     16    gprint (GP_ERR, "  +jobs [-nohost]\n");
     17    gprint (GP_ERR, "  +host [-nojobs]\n");
    1118    return (FALSE);
    1219  }
     
    1926  }
    2027
     28  snprintf (command, 1024, "status");
     29  for (i = 1; i < argc; i++) {
     30    snprintf (tmpline, 1024, "%s %s", command, argv[i]);
     31    strcpy (command, tmpline);
     32  }
    2133
    22   sprintf (command, "status");
    2334  InitIOBuffer (&buffer, 0x100);
    2435
  • trunk/Ohana/src/opihi/pcontrol/Makefile

    r34088 r37807  
    1111
    1212# programs may add their own internal requirements here
    13 LIBS1         = -lkapa -lFITS -lohana
     13LIBS1         = -ldvo -lkapa -lFITS -lohana
    1414LIBS2         = -lbasiccmd -lshell -ldata
    1515FULL_CFLAGS   = $(BASE_CFLAGS)
  • trunk/Ohana/src/opihi/pcontrol/status.c

    r36623 r37807  
    8585
    8686usage:
    87   gprint (GP_ERR, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
     87  gprint (GP_LOG, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
    8888  return FALSE;
    8989}
  • trunk/Ohana/src/photdbc/include/photdbc.h

    r37045 r37807  
    3131int    PARALLEL_MANUAL;
    3232int    PARALLEL_SERIAL;
     33char  *PARALLEL_OUTHOSTS;
    3334
    3435int          HOST_ID;
    3536char        *HOSTDIR;
     37char        *HOSTDIR_OUTPUT;
    3638
    3739// need to get RADIUS from Config
     
    4042
    4143/* global variables */
     44int    SKIP_IMAGES;
     45int    ONLY_IMAGES;
    4246int    SHOW_PARAMS;
    4347int    VERBOSE;
  • trunk/Ohana/src/photdbc/src/CopyToHostLocation.c

    r33655 r37807  
    5454    }
    5555
    56     char extname[4][16] = {"cpm", "cpt", "cps", "cpn"};
    57     for (j = 0; success && (j < 4); j++) {
     56    # define NEXTNAME 7
     57    char extname[NEXTNAME][16] = {"cpm", "cpt", "cps", "cpn", "cpx", "cpy", "cpz"};
     58    for (j = 0; success && (j < NEXTNAME); j++) {
    5859
    5960      // set the in and out table names
  • trunk/Ohana/src/photdbc/src/args.c

    r36833 r37807  
    1515    remove_argument (N, &argc, argv);
    1616    SHOW_PARAMS = TRUE;
     17  }
     18
     19  SKIP_IMAGES = FALSE;
     20  if ((N = get_argument (argc, argv, "-skip-images"))) {
     21    SKIP_IMAGES = TRUE;
     22    remove_argument (N, &argc, argv);
     23  }
     24
     25  ONLY_IMAGES = FALSE;
     26  if ((N = get_argument (argc, argv, "-only-images"))) {
     27    if (SKIP_IMAGES) {
     28      fprintf (stderr, "-skip-images and -only-images cannot be used together\n");
     29    }
     30    ONLY_IMAGES = TRUE;
     31    remove_argument (N, &argc, argv);
    1732  }
    1833
     
    131146  }
    132147
     148  // XXX for the moment, make this selection manual.  it needs to be automatic
     149  // based on the state of the SkyTable
     150  HOSTDIR_OUTPUT = NULL;
     151  PARALLEL_OUTHOSTS = NULL;
     152  if ((N = get_argument (argc, argv, "-parallel-output"))) {
     153    remove_argument (N, &argc, argv);
     154    PARALLEL_OUTHOSTS = strcreate (argv[N]);
     155    remove_argument (N, &argc, argv);
     156  }
     157
    133158  if (argc != 2) usage();
    134159
     
    171196  if (!HOSTDIR) usage();
    172197
     198  HOSTDIR_OUTPUT = NULL;
     199  if ((N = get_argument (argc, argv, "-hostdir-output"))) {
     200    remove_argument (N, &argc, argv);
     201    HOSTDIR_OUTPUT = strcreate (argv[N]);
     202    remove_argument (N, &argc, argv);
     203  }
     204
    173205  VERBOSE = FALSE;
    174206  if ((N = get_argument (argc, argv, "-v"))) {
     
    289321  fprintf (stderr, " photdbc (output)\n\n");
    290322
     323  fprintf (stderr, " parallel options:\n");
     324  fprintf (stderr, "  -parallel:\n");
     325  fprintf (stderr, "  -parallel-output HostTable : HostTable should be relative path in OUTPUT directory\n");
     326  fprintf (stderr, "  -parallel-manual\n");
     327  fprintf (stderr, "  -parallel-serial\n\n");
     328
    291329  fprintf (stderr, " allowed filters / restrictions include:\n\n");
    292330
     
    303341  fprintf (stderr, " option options:\n");
    304342  fprintf (stderr, " -v : verbose mode\n");
    305   fprintf (stderr, " -params : list the current parameters\n\n");
     343  fprintf (stderr, " -params : list the current parameters\n");
     344  fprintf (stderr, " -skip-images\n");
     345  fprintf (stderr, " -only-images\n");
     346  fprintf (stderr, " -set-format (catformat)\n");
     347  fprintf (stderr, " -set-mode (catmode)\n");
    306348
    307349  fprintf (stderr, "ptolemy.rc config values used by this program:\n");
  • trunk/Ohana/src/photdbc/src/copy_images.c

    r36833 r37807  
    5252  }
    5353
     54  BuildChipMatch (image, Nimage);
     55  // MARKTIME("build chip match: %f sec\n", dtime);
     56
     57  char mapfile[DVO_MAX_PATH];
     58  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     59  AstromOffsetTable *table_src = AstromOffsetMapLoad (mapfile, VERBOSE);
     60
     61  // assign images.coords.offsetMap -> table->map[i]
     62  if (table_src) {
     63    AstromOffsetTableMatchChips (image, Nimage, table_src);
     64  }
     65
    5466  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset, FALSE);
     67
     68  if (table_src) {
     69    AstromOffsetTable *table_tgt = AstromOffsetTableInit ();
     70   
     71    off_t i;
     72    for (i = 0; i < Nsubset; i++) {
     73      if (!subset[i].coords.offsetMap) continue;
     74      if (subset[i].coords.Npolyterms != -1) continue; // assert on this?
     75      AstromOffsetTableAddMapFromImage (table_tgt, &subset[i]);
     76    }
     77    snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", outdir);
     78    AstromOffsetMapSave (table_tgt, mapfile);
     79    free (table_tgt->imageIDtoTableSeq);
     80    free (table_tgt->map);
     81    free (table_tgt);
     82  }
    5583
    5684  dvo_image_addrows (&out, subset, Nsubset);
     
    73101  SavePhotcodesFITS (filename);
    74102
     103  // free the astrom offset tables
     104  AstromOffsetTableFree (table_src);
     105
    75106  return (TRUE);
    76107}
  • trunk/Ohana/src/photdbc/src/find_images.c

    r36481 r37807  
    1919
    2020  /* we make positional comparisons in the projection of catalog */
     21  InitCoords (&tcoords, "DEC--TAN");
    2122  tcoords.crval1 = 0.5*(region[0].RA[0]  + region[0].RA[1]);
    2223  tcoords.crval2 = 0.5*(region[0].DEC[0] + region[0].DEC[1]);
    23   tcoords.crpix1 = tcoords.crpix2 = 0.0;
    2424  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    25   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    26   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    27   strcpy (tcoords.ctype, "DEC--TAN");
    2825
    2926  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
  • trunk/Ohana/src/photdbc/src/join_stars.c

    r37045 r37807  
    5050
    5151  /* coordinate system for projection */
     52  InitCoords (&tcoords, "DEC--TAN");
    5253  tcoords.crval1 = Rmid;
    5354  tcoords.crval2 = Dmid;
    54   tcoords.crpix1 = tcoords.crpix2 = 0.0;
    5555  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    56   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    57   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    58   tcoords.Npolyterms = 0;
    59   strcpy (tcoords.ctype, "DEC--TAN");
    6056 
    6157  /* project & sort coordinates in local linear frame */
  • trunk/Ohana/src/photdbc/src/photdbc.c

    r36833 r37807  
    1515
    1616  // load and copy the image table
    17   copy_images (argv[1], skylist);
     17  if (!SKIP_IMAGES) {
     18    copy_images (argv[1], skylist);
     19  }
    1820
    1921  // hostID is 0 for master program
    20   photdbc_catalogs (argv[1], skylist, 0);
     22  if (!ONLY_IMAGES) {
     23    photdbc_catalogs (argv[1], skylist, 0);
     24  }
    2125
    2226  char *skyfile = SkyTableFilename (argv[1]);
  • trunk/Ohana/src/photdbc/src/photdbc_catalogs.c

    r36833 r37807  
    4242    snprintf (outfile, DVO_MAX_PATH, "%s/%s.cpt", outroot, skylist[0].regions[i]->name);
    4343    outcatalog.filename = outfile;
     44
     45    if (HOSTDIR_OUTPUT) {
     46      // parallel-ouput puts the output in a per-host directory (keeps the source sky partition)
     47      snprintf (outfile, DVO_MAX_PATH, "%s/%s.cpt", HOSTDIR_OUTPUT, skylist[0].regions[i]->name);
     48    }
     49
    4450    if (outcatalog.filename == NULL) Shutdown ("error with input catalog name");
    4551
     
    95101  }   
    96102
     103  HostTable *table_output = NULL;
     104  if (PARALLEL_OUTHOSTS) {
     105    table_output = HostTableLoad (outroot, PARALLEL_OUTHOSTS);
     106    if (!table_output) {
     107      fprintf (stderr, "%s not found in %s, please create\n", PARALLEL_OUTHOSTS, outroot);
     108    }
     109  }
     110
    97111  int i;
    98112  for (i = 0; i < table->Nhosts; i++) {
     
    123137    if (CATFORMAT)          { snprintf (tmpline, DVO_MAX_PATH, "%s -set-format %s",    command, CATFORMAT);                     strcpy (command, tmpline); }
    124138    if (CATMODE)            { snprintf (tmpline, DVO_MAX_PATH, "%s -set-mode %s",      command, CATMODE);                       strcpy (command, tmpline); }
     139
     140    if (PARALLEL_OUTHOSTS) {
     141      tmppath = abspath (table_output->hosts[i].pathname, DVO_MAX_PATH);
     142      free  (table_output->hosts[i].pathname);
     143      table_output->hosts[i].pathname = tmppath;
     144      snprintf (tmpline, DVO_MAX_PATH, "%s -hostdir-output %s", command, table_output->hosts[i].pathname); strcpy (command, tmpline);
     145    }
    125146
    126147    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/photdbc/src/select_images.c

    r36833 r37807  
    3434
    3535  // the comparison is made in the catalog local projection. below we set crval1,2
    36   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     36  InitCoords (&tcoords, "DEC--TAN");
    3737  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    38   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    39   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    40   strcpy (tcoords.ctype, "DEC--TAN");
    4138
    4239  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     
    9289
    9390  if (VERBOSE) fprintf (stderr, "finding images\n");
    94   BuildChipMatch (timage, Ntimage);
    95   MARKTIME("build chip match: %f sec\n", dtime);
    9691
    9792  nimage = 0;
     
    115110keep_image:
    116111
    117     // this adds 1.3 sec for 3M images
    118     if (!FindMosaicForImage (timage, Ntimage, i)) {
    119       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    120       continue;
    121     }
    122 
    123112    /* define image corners - note the DIS images (mosaic phu) are special */
    124113    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
  • trunk/Ohana/src/relastro/Makefile

    r37261 r37807  
    6060$(SRC)/CoordOps.$(ARCH).o            \
    6161$(SRC)/extra.$(ARCH).o            \
    62 $(SRC)/FixProblemImages.$(ARCH).o    \
    6362$(SRC)/StarMaps.$(ARCH).o    \
    6463$(SRC)/high_speed_catalogs.$(ARCH).o  \
     
    7574$(SRC)/relastro_parallel_regions.$(ARCH).o \
    7675$(SRC)/MeanPosIO.$(ARCH).o \
     76$(SRC)/MeasPosIO.$(ARCH).o \
    7777$(SRC)/share_mean_pos.$(ARCH).o \
     78$(SRC)/share_meas_pos.$(ARCH).o \
    7879$(SRC)/share_images_pos.$(ARCH).o \
     80$(SRC)/share_icrf_obj.$(ARCH).o \
     81$(SRC)/ICRF.$(ARCH).o \
     82$(SRC)/ICRFobjIO.$(ARCH).o \
     83$(SRC)/FrameCorrection.$(ARCH).o \
     84$(SRC)/FrameCorrectionIO.$(ARCH).o \
     85$(SRC)/FrameCorrectionUtils.$(ARCH).o \
    7986$(SRC)/ImagePosIO.$(ARCH).o \
    8087$(SRC)/ImageTable.$(ARCH).o \
     
    8289$(SRC)/indexCatalogs.$(ARCH).o \
    8390$(SRC)/syncfile.$(ARCH).o \
     91$(SRC)/client_logger.$(ARCH).o \
    8492$(SRC)/relastroVisual.$(ARCH).o
    8593
     
    117125$(SRC)/relastro_objects.$(ARCH).o    \
    118126$(SRC)/save_catalogs.$(ARCH).o       \
    119 $(SRC)/CoordOps.$(ARCH).o            \
    120127$(SRC)/extra.$(ARCH).o            \
    121128$(SRC)/high_speed_catalogs.$(ARCH).o  \
     
    128135$(SRC)/plot_scatter.$(ARCH).o        \
    129136$(SRC)/plotstuff.$(ARCH).o           \
     137$(SRC)/ICRF.$(ARCH).o \
    130138$(SRC)/relastroVisual.$(ARCH).o \
    131139$(SRC)/syncfile.$(ARCH).o \
    132140$(SRC)/BrightCatalog.$(ARCH).o
    133 
    134 #$(SRC)/FitChip.$(ARCH).o             \
    135 #$(SRC)/FitMosaic.$(ARCH).o           \
    136 #$(SRC)/UpdateChips.$(ARCH).o         \
    137 #$(SRC)/UpdateMosaic.$(ARCH).o        \
    138 #$(SRC)/UpdateSimple.$(ARCH).o        \
    139 #$(SRC)/write_coords.$(ARCH).o        \
    140 #$(SRC)/FixProblemImages.$(ARCH).o    \
    141 #$(SRC)/StarMaps.$(ARCH).o    \
    142141
    143142$(RELASTRO_CLIENT): $(INC)/relastro.h
  • trunk/Ohana/src/relastro/doc/pv2.txt

    r37038 r37807  
     1
     22014.10.28
     3
     4Going over the sequence of steps in relastro.  I'm concerned that the
     5iteration is not modifying the measure.R,D values, preventing any
     6actual iterative improvements.
     7
     8* UpdateObjects : takes measure.R,D to calculate average.R,D and
     9  motion terms
     10
     11* ImageOps :
     12  * getImageRaw : takes measure.X,Y, applies image.coords to get (L,M),
     13                  (P,Q), etc, calculates
     14  * getImageRef : takes average.R,D, applies image.coords to get
     15                  (P,Q), (L,M), etc
     16  * FitChip : fit raw.X,Y to ref.L,M, plus residual map (dX,dY)
     17 
     18  *** modified raw.L,M values are then dropped and not used to update measure.R.D
    119
    2202014.07.03
  • trunk/Ohana/src/relastro/include/relastro.h

    r37261 r37807  
    3434
    3535typedef struct {
    36   float R;
    37   float D;
     36  double R;
     37  double D;
    3838  unsigned int objID;
    3939  unsigned int catID;
    4040} MeanPos;
     41
     42typedef struct {
     43  double R;
     44  double D;
     45  unsigned int objID;
     46  unsigned int catID;
     47  unsigned int imageID;
     48} MeasPos;
    4149
    4250typedef struct {
     
    4755  int nFitAstrom;
    4856  int flags;
     57  float refColorBlue;
     58  float refColorRed;
    4959} ImagePos;
    5060
     
    142152} FitStats;
    143153
     154typedef struct {
     155  double scale;
     156  double **Roff;
     157  double **Doff;
     158  double  *dR;
     159  int *Nra;
     160  int Ndec;
     161} FrameCorrectionType;
     162
     163typedef struct {
     164  // AstromOffsetMap *map;
     165  Coords *coords; // carries a pointer to the AstromOffsetMap
     166  FrameCorrectionType *frame;
     167} FrameCorrectionSet;
     168
     169
     170typedef struct {
     171  double *Rave;
     172  double *Dave;
     173  double *dRoff;
     174  double *dDoff;
     175  int Nicrfobj;
     176} ICRFobj;
     177
    144178/* global variables set in parameter file */
    145179# define DVO_MAX_PATH 1024
     
    172206double MIN_ERROR;
    173207
     208int    IMFIT_TOO_FEW; // need more than this number of stars to fit an image
    174209int    IMFIT_CLIP_NITER; // number of clipping iterations to perform in FitChip
    175210double IMFIT_CLIP_NSIGMA; // number of sigma to clip in FitChip
     
    188223
    189224int    USE_FIXED_PIXCOORDS;
     225int    USE_GALAXY_MODEL;
     226int    USE_ICRF_CORRECT;
     227
     228int    USE_ICRF_LOCAL;
     229int    USE_ICRF_SHFIT;
     230int    USE_ICRF_POLE;
    190231
    191232int    RESET;
     233int    RESET_IMAGES;
    192234int    RESET_BAD_IMAGES;
    193235int    NLOOP;
     
    204246int    PLOTDELAY;
    205247int    CHIPORDER;
     248int    CHIPMAP;
    206249
    207250int MaxDensityUse;
     
    242285int    CLIP_THRESH;
    243286int USE_BASIC_CHECK;
     287int APPLY_OFFSETS; // in parallel-regions mode, do not launch UpdateObjectOffsets unless -apply-offsets is called
    244288
    245289int ExcludeBogus;
     
    397441void FitSimple (StarData *raw, StarData *ref, int Nmatch, Coords *coords);
    398442void initObjectData (Catalog *catalog, int Ncatalog);
    399 int UpdateObjects (Catalog *catalog, int Ncatalog);
     443int UpdateObjects (Catalog *catalog, int Ncatalog, int Nloop);
    400444int UpdateSimple (Catalog *catalog, int Ncatalog);
    401445int UpdateChips (Catalog *catalog, int Ncatalog);
     
    417461StarData *getImageRef (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode);
    418462StarData *getImageRaw (Catalog *catalog, int Ncatalog, off_t im, off_t *Nstars, CoordMode mode);
     463int setImageRaw (Catalog *catalog, int Ncatalog, off_t im, StarData *raw, off_t Nraw, CoordMode mode);
    419464off_t getImageByID (off_t ID);
     465int updateImageRaw (Catalog *catalog, int Ncatalog, off_t im);
    420466
    421467Mosaic *getmosaics (off_t *N);
     
    447493int relastroGetVisual(void);
    448494
    449 int FixProblemImages (SkyList *skylist);
    450495int *getCatlist (int *N, off_t im);
    451496
    452 void initCoords (void);
    453 void getOffsets (double *dPos, off_t *nPos, off_t N);
    454 void saveOffsets (double dPos, off_t nPos, off_t N);
    455 void setBadCoords (off_t N);
    456 int badCoords (off_t N);
    457 Coords *getCoords (off_t N);
    458 int saveCoords (Coords *coords, off_t N);
    459 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im);
     497void SaveCoords (Coords *tgt, Coords *src);
     498void RestoreCoords (Coords *tgt, Coords *src, Image *image);
    460499
    461500int high_speed_catalogs (SkyTable *sky, SkyList *skylist, int hostID, char *hostpath);
     
    468507int checkStarMap(int N);
    469508int createStarMap (Catalog *catalog, int Ncatalog);
     509int printStarMap(int N, char *filename);
    470510
    471511int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit);
     
    519559MeanPos *MeanPosLoad(char *filename, off_t *nmeanpos);
    520560
     561int share_meas_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     562int slurp_meas_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     563int set_meas_pos (MeasPos *measpos, Average *average, MeasureTiny *measure);
     564MeasPos *merge_meas_pos (MeasPos *target, int *ntarget, MeasPos *source, int Nsource);
     565
     566int MeasPosSave(char *filename, MeasPos *measpos, off_t Nmeaspos);
     567MeasPos *MeasPosLoad(char *filename, off_t *nmeaspos);
     568
    521569int indexCatalogs (Catalog *catalog, int Ncatalog);
    522570int catID_and_objID_to_seq (int catID, int objID, int *catSeq, off_t *objSeq);
     
    528576
    529577int share_image_pos (RegionHostTable *regionHosts, int nloop);
    530 int slurp_image_pos (RegionHostTable *regionHosts, int nloop);
     578int slurp_image_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
    531579ImagePos *merge_image_pos (ImagePos *target, int *ntarget, ImagePos *source, int Nsource);
    532580int set_image_pos (ImagePos *image_pos, Image *image);
     
    547595int isGPC1stack (int photcode);
    548596int isGPC1warp (int photcode);
     597
     598int save_astrom_table ();
     599AstromOffsetTable *get_astrom_table ();
     600void put_astrom_table (AstromOffsetTable *myTable);
     601
     602int fit_map (AstromOffsetMap *map, StarData *raw, StarData *ref, int Npts);
     603
     604// ICRF QSOs : these must be marked in the database (flag on average, flag on measure)
     605
     606void ICRFinit ();
     607int ICRFsave (int cat, int ave, int meas);
     608int ICRFdata (int n, int *cat, int *ave, int *meas);
     609int ICRFmax ();
     610int select_catalog_ICRF (Catalog *catalog, int Ncatalog);
     611
     612void ICRFobjFree (ICRFobj *icrfobj);
     613ICRFobj *get_ICRF_data (Catalog *catalog, int Ncatalog);
     614ICRFobj *merge_icrf_obj (ICRFobj *target, ICRFobj *source);
     615ICRFobj *slurp_icrf_obj (RegionHostTable *regionHosts, int nloop);
     616int share_icrf_obj (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     617
     618int ICRFobjSave(char *filename, ICRFobj *icrfobj);
     619ICRFobj *ICRFobjLoad(char *filename);
     620
     621int SHfitWithMask (double *R, double *D, double *value, int *mask, int Npts, SHterms *fit);
     622
     623FrameCorrectionType *FrameCorrectionInit (double scale);
     624void FrameCorrectionFree (FrameCorrectionType *frame);
     625
     626int FrameCorrectionParallelMaster (RegionHostTable *regionHosts);
     627int FrameCorrectionParallelSlave (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     628int FrameCorrectionSerial (Catalog *catalog, int Ncatalog);
     629
     630FrameCorrectionSet *FrameCorrectionMeasure (ICRFobj *icrfobj);
     631
     632int FrameCorrectionFromSH (FrameCorrectionType *frame, SHterms *dR, SHterms *dD);
     633
     634Coords *FrameCorrectionImageToMap (Header *header, Matrix *matrix, Coords *coords, int raDirection);
     635int FrameCorrectionMapToImage (Header *header, Matrix *matrix, Coords *coords, int raDirection);
     636int FrameCorrectionSHtoImage (Header *header, Matrix *matrix, FrameCorrectionType *frame, int raDirection);
     637FrameCorrectionType *FrameCorrectionImageToSH (Header *header, Matrix *matrix, FrameCorrectionType *frame, int raDirection);
     638int FrameCorrectionFromSH (FrameCorrectionType *frame, SHterms *dR, SHterms *dD);
     639void FrameCorrectionFree (FrameCorrectionType *frame);
     640FrameCorrectionType *FrameCorrectionInit (double scale);
     641void FrameCorrectionSetFree (FrameCorrectionSet *set);
     642FrameCorrectionSet *FrameCorrectionSetInit ();
     643
     644int FrameCorrectionSetSave(char *filename, FrameCorrectionSet *set);
     645FrameCorrectionSet *FrameCorrectionSetLoad(char *filename);
     646
     647int FrameCorrectionFitSH (ICRFobj *icrfobj, SHterms *dRc, SHterms *dDc);
     648int FrameCorrectionFitLocal (ICRFobj *icrfobj, Coords *coords);
     649int FrameCorrectionApply (Catalog *catalog, int Ncatalog, FrameCorrectionType *frame, Coords *coords);
     650
     651int dump_stardata_pts (StarData *raw, int Npts, char *filename);
     652void printNcatTotal ();
     653
     654int HarvestRegionHosts (RegionHostTable *regionHosts);
     655
     656void lockUpdateChips ();
     657void unlockUpdateChips ();
     658
     659int client_logger_init (char *dirname);
     660int client_logger_message (char *format,...);
  • trunk/Ohana/src/relastro/src/BrightCatalog.c

    r37038 r37807  
    4343  if (!gfits_fread_header (f, &header)) {
    4444    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
    45     fclose (f);
    4645    goto escape;
    4746  }
    4847  if (!gfits_fread_matrix (f, &matrix, &header)) {
    4948    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
    50     gfits_free_header (&header);
    51     fclose (f);
    5249    goto escape;
    5350  }
     
    7067    GET_COLUMN(R,         "RA",         double);
    7168    GET_COLUMN(D,         "DEC",        double);
     69    GET_COLUMN(RoffGAL,   "ROFF_GAL",   float);
     70    GET_COLUMN(DoffGAL,   "DOFF_GAL",   float);
    7271    GET_COLUMN(M,         "MAG_SYS",    float);
    7372    GET_COLUMN(Mcal,      "MAG_CAL",    float);
     
    9493      measure[i].R         = R[i];
    9594      measure[i].D         = D[i];
     95      measure[i].RoffGAL   = RoffGAL[i];
     96      measure[i].DoffGAL   = DoffGAL[i];
    9697      measure[i].M         = M[i];
    9798      measure[i].Mcal      = Mcal[i];
     
    115116    free (R       );
    116117    free (D       );
     118    free (RoffGAL );
     119    free (DoffGAL );
    117120    free (M       );
    118121    free (Mcal    );
     
    310313  if (catalog) free (catalog);
    311314
    312   fclose (f);
     315  if (f) fclose (f);
    313316  return NULL;
    314317}
     
    343346    gfits_create_table_header (&theader, "BINTABLE", "MEASURE_TINY");
    344347
    345     gfits_define_bintable_column (&theader, "E", "RA_OFF",   "ra offset",                  "arcsec", 1.0, 0.0);
    346     gfits_define_bintable_column (&theader, "E", "DEC_OFF",  "dec offset",                 "arcsec", 1.0, 0.0);
     348    gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degrees", 1.0, 0.0);
     349    gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degrees", 1.0, 0.0);
     350    gfits_define_bintable_column (&theader, "E", "ROFF_GAL", "ra offset",                  "arcsec", 1.0, 0.0);
     351    gfits_define_bintable_column (&theader, "E", "DOFF_GAL", "dec offset",                 "arcsec", 1.0, 0.0);
    347352    gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
    348353    gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
     
    368373    double *R         ; ALLOCATE (R        ,  double, catalog->Nmeasure);
    369374    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
     375    float  *RoffGAL   ; ALLOCATE (RoffGAL  ,  float,  catalog->Nmeasure);
     376    float  *DoffGAL   ; ALLOCATE (DoffGAL  ,  float,  catalog->Nmeasure);
    370377    float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
    371378    float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
     
    390397      R[i]        = measure[i].R        ;
    391398      D[i]        = measure[i].D        ;
     399      RoffGAL[i]  = measure[i].RoffGAL  ;
     400      DoffGAL[i]  = measure[i].DoffGAL  ;
    392401      M[i]        = measure[i].M        ;
    393402      Mcal[i]     = measure[i].Mcal     ;
     
    411420    gfits_set_bintable_column (&theader, &ftable, "RA",         R,         catalog->Nmeasure);
    412421    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
     422    gfits_set_bintable_column (&theader, &ftable, "ROFF_GAL",   RoffGAL,   catalog->Nmeasure);
     423    gfits_set_bintable_column (&theader, &ftable, "DOFF_GAL",   DoffGAL,   catalog->Nmeasure);
    413424    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    414425    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     
    430441    free (R       );
    431442    free (D       );
     443    free (RoffGAL );
     444    free (DoffGAL );
    432445    free (M       );
    433446    free (Mcal    );
  • trunk/Ohana/src/relastro/src/ConfigInit.c

    r36630 r37807  
    2525  if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NSIGMA",   "%lf", 0, &IMFIT_CLIP_NSIGMA))   IMFIT_CLIP_NSIGMA = 3.0;
    2626  if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
     27  if (!ScanConfig (config, "RELASTRO_IMFIT_TOO_FEW",       "%d",  0, &IMFIT_TOO_FEW))       IMFIT_TOO_FEW = 5;
    2728
    2829  if (!ScanConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN))        PM_DT_MIN = 0.25;   
     
    3637
    3738  if (!ScanConfig (config, "USE_FIXED_PIXCOORDS", "%d", 0, &USE_FIXED_PIXCOORDS))  USE_FIXED_PIXCOORDS = FALSE;
     39  if (!ScanConfig (config, "USE_GALAXY_MODEL",    "%d", 0, &USE_GALAXY_MODEL))     USE_GALAXY_MODEL = FALSE;
     40  if (!ScanConfig (config, "USE_ICRF_CORRECT",    "%d", 0, &USE_ICRF_CORRECT))     USE_ICRF_CORRECT = FALSE;
     41  if (!ScanConfig (config, "USE_ICRF_LOCAL",      "%d", 0, &USE_ICRF_LOCAL))       USE_ICRF_LOCAL = FALSE;
     42  if (!ScanConfig (config, "USE_ICRF_SHFIT",      "%d", 0, &USE_ICRF_SHFIT))       USE_ICRF_SHFIT = FALSE;
     43  if (!ScanConfig (config, "USE_ICRF_POLE",       "%d", 0, &USE_ICRF_POLE))        USE_ICRF_POLE = FALSE;
    3844
    3945  // force CATDIR to be absolute (so parallel mode will work)
  • trunk/Ohana/src/relastro/src/FitChip.c

    r37038 r37807  
    1414
    1515  for (Niter = 0; Niter < IMFIT_CLIP_NITER; Niter ++) {
    16    
     16
    1717    // measure the scatter for the unmarked (good) measurements with dM < limit
    1818    // SIGMA_LIM here is redundant with ImageOps.c:915
     
    4949    // use that count to set order_use below
    5050
     51    // 20140925 : the same logic below is used to constrain the dimensions of the image map
     52
    5153    // figures to assess the fitting process:
    5254    // x vs dx, x vs dy, y vs dx, y vs dy :
    5355    // residual vector field
    5456    // dx vs mag, dy vs mag
     57    if (relastroGetVisual()) {
     58      fprintf (stderr, "fitting chip %s, %d matched stars\n", image->name, Nmatch);
     59    }
    5560    relastroVisualPlotChipFit(raw, ref, dRmax, Nmatch);
     61
     62    // for polynomial fits, I used (5,30,60) = (5,6,7) stars per term
    5663
    5764    // set the maximum order for the polynomial (based on number of stars kept above)
    5865    int order_use = 0;
    59     if (Nkeep >  5) order_use = 1; // 4 stars per polynomial term (per dimension)
    60     if (Nkeep > 30) order_use = 2; // 5 stars per polynomial term (per dimension)
    61     if (Nkeep > 60) order_use = 3; // 6 stars per polynomial term (per dimension)
     66    if (Nkeep >   5) order_use = 1; //  5 stars per cell
     67    if (Nkeep >  24) order_use = 2; //  6 stars per cell
     68    if (Nkeep >  63) order_use = 3; //  7 stars per cell
     69    if (Nkeep > 128) order_use = 4; //  8 stars per cell
     70    if (Nkeep > 225) order_use = 5; //  9 stars per cell
     71    if (Nkeep > 360) order_use = 6; // 10 stars per cell
    6272    if (order_use < 1) {
    6373      if (VERBOSE2) fprintf (stderr, "insufficient measurements (%d) for linear fit\n", Nkeep);
     
    6575      return FALSE;
    6676    }
    67     image[0].coords.Npolyterms = order_use;
     77    if (CHIPMAP) {
     78      order_use = MIN(MIN(order_use, CHIPMAP), 6); // can only go up to 6th order map (can be user limited)
     79    } else {
     80      order_use = MIN(order_use, 3); // can only go up to 3rd order for polynomials
     81    }
     82
     83    if (VERBOSE2) fprintf (stderr, "using %d for %s\n", order_use, image[0].name);
     84
     85    // when fitting the map, first fit a linear model (below? change Npolyterms to -1)
     86    image[0].coords.Npolyterms = CHIPMAP ? 1 : order_use;
    6887
    6988    if (fit) fit_free (fit);
     
    91110    }
    92111
     112    // apply fit to get the fitted X,Y coordinates.  we need these to fit the residual map below
    93113    for (i = 0; i < Nmatch; i++) {
     114      // we have not yet fitted the map, so Npolyterms needs to be 1 here:
     115      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[0].coords);
     116    }
     117
     118    if (CHIPMAP) {
     119      if (image[0].coords.offsetMap == NULL) {
     120        // allocate a new table and assign to this image
     121        // need to lock threads here because 'table' is a static with
     122        // modifiable elements
     123        lockUpdateChips ();
     124        AstromOffsetTable *table = get_astrom_table ();
     125        AstromOffsetTableNewMap(table, order_use, order_use, image);
     126        unlockUpdateChips ();
     127      }
     128      // XXX Need to check / update the order of the map here.  if we already have a map, it might have been
     129      // allocated with too small arrays
     130      AstromOffsetMapSetOrder (image[0].coords.offsetMap, order_use, order_use, image);
     131      image[0].coords.offsetMap->keep = TRUE; // if we are trying or re-trying this map, we should keep it unless it fails
     132      fit_map (image[0].coords.offsetMap, raw, ref, Nmatch);
     133      image[0].coords.Npolyterms = -1;
     134    }
     135
     136    if (!strcmp(image[0].name, "o5745g0403o.356777.cm.982487.smf[XY17.hdr]")) {
     137      fprintf (stderr, "test image\n");
     138    }
     139
     140    for (i = 0; i < Nmatch; i++) {
     141      // if we have fitted the map above, Npolyterms needs to be -1 here:
    94142      XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[0].coords);
    95143    }
    96 
    97144  }
    98145
     
    223270   L,M -> X,Y (polynomial transformation : WRP)
    224271
    225 Some details about this function:
    226 
    227 - the initial value of the clipping radius is set based on the distribution of the dR
    228   values for the bright sources.
    229 
    230 - NITER clipping passes are performed
    231 
    232 - the per-star astrometric errors are included in the fit.  The photcode table controls
    233   whether only the reported positional errors are used, or if the magnitudes errors are
    234   scaled to determine the error, and if there is a systematic floor for all sources.
    235 
    236 - input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
    237 
    238 - outlying detections are clipped in the iterative passes, but the clipped detections are
    239   not recorded
     272   Some details about this function:
     273
     274   - the initial value of the clipping radius is set based on the distribution of the dR
     275   values for the bright sources.
     276
     277   - NITER clipping passes are performed
     278
     279   - the per-star astrometric errors are included in the fit.  The photcode table controls
     280   whether only the reported positional errors are used, or if the magnitudes errors are
     281   scaled to determine the error, and if there is a systematic floor for all sources.
     282
     283   - input detections are pre-filtered on the basis of the photFlags, etc, in bcatalog
     284
     285   - outlying detections are clipped in the iterative passes, but the clipped detections are
     286   not recorded
    240287
    241288*/
     
    243290/* example using fit_apply() :
    244291
    245   f = fopen ("test3.dat", "w");
    246 
    247   // apply new coords to raw (X,Y -> L,M)
    248   for (i = 0; i < Nmatch; i++) {
    249     fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
    250     fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
    251     fprintf (f, "%f %f\n", L1, M1);
     292   f = fopen ("test3.dat", "w");
     293
     294   // apply new coords to raw (X,Y -> L,M)
     295   for (i = 0; i < Nmatch; i++) {
     296   fprintf (f, "%f %f  %f %f  ", raw[i].X, raw[i].Y, raw[i].L, raw[i].M);
     297   fit_apply (newfit, &L1, &M1, raw[i].X - coords[0].crpix1, raw[i].Y - coords[0].crpix2);
     298   fprintf (f, "%f %f\n", L1, M1);
     299   }
     300   fclose (f);
     301*/
     302
     303int fit_map (AstromOffsetMap *map, StarData *raw, StarData *ref, int Npts) {
     304
     305  // we are actually fitting the residual after the linear fit has been taken off
     306 
     307  // fit the linear terms as above
     308  // calculate dX (raw.X - ref.X) and dY
     309
     310  int i, N;
     311
     312  float *x, *y, *dX, *dY;
     313  ALLOCATE (x,  float, Npts);
     314  ALLOCATE (y,  float, Npts);
     315  ALLOCATE (dX, float, Npts);
     316  ALLOCATE (dY, float, Npts);
     317
     318  N = 0;
     319  for (i = 0; i < Npts; i++) {
     320    if (raw[i].mask) continue;
     321    x[N] = raw[i].X;
     322    y[N] = raw[i].Y;
     323    dX[N] = ref[i].X - raw[i].X;
     324    dY[N] = ref[i].Y - raw[i].Y;
     325    N++;
     326  }
     327
     328  // in coordsops.c:XY_to_LM, the map is defined to carry dX,dY so that:
     329  // (L,M) = f(X',Y') : (X',Y') = (X,Y) + (dX,dY)
     330
     331  AstromOffsetMapFit (map, x, y, dX, N, TRUE);
     332  AstromOffsetMapFit (map, x, y, dY, N, FALSE);
     333
     334  AstromOffsetMapRepair (map, TRUE);
     335  AstromOffsetMapRepair (map, FALSE);
     336
     337  free (x);
     338  free (y);
     339  free (dX);
     340  free (dY);
     341
     342  return TRUE;
     343}
     344
     345int dump_stardata_pts (StarData *raw, int Npts, char *filename) {
     346
     347  FILE *f = fopen (filename, "w");
     348  if (!f) {
     349    fprintf (stderr, "failed to open file %s\n", filename);
     350    return FALSE;
     351  }
     352
     353  int i;
     354  for (i = 0; i < Npts; i++) {
     355    fprintf (f, "%4d %10.6f %10.6f  %10.6f %10.6f  %9.2f %9.2f  %9.2f %9.2f  %9.4f %3d\n",
     356             i, raw[i].R, raw[i].D, raw[i].P, raw[i].Q, raw[i].L, raw[i].M, raw[i].X, raw[i].Y, raw[i].dPos, raw[i].mask);
    252357  }
    253358  fclose (f);
    254 */
    255 
     359
     360  return TRUE;
     361}
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r37038 r37807  
    2828static off_t        *imageIDs; // list of all image IDs
    2929static off_t        *imageIdx; // list of index for image IDs
    30 # else
     30
     31// as an alternative, we generate imageSeq, which directly maps imageID -> seq
     32static off_t        *imageSeq; // list of index for image IDs
     33
     34// MAX_ID requires 512M to store the image index
     35# define MAX_ID      0x8000000
     36static off_t         minImageID = MAX_ID;
     37static off_t         maxImageID = 0;
     38
     39# else /* not using IMAGE_ID */
    3140static unsigned int *start;
    3241static unsigned int *stop;
     
    8493    imageIdx[i] = i;
    8594    imageIDs[i] = image[i].imageID;
     95    minImageID = MIN(minImageID, image[i].imageID);
     96    maxImageID = MAX(maxImageID, image[i].imageID);
     97    myAssert (image[i].imageID < MAX_ID, "image IDs too large for index memory");
    8698  }
    8799  llsortpair (imageIDs, imageIdx, Nimage);
     100
     101  ALLOCATE (imageSeq, off_t, maxImageID + 1);
     102  for (i = 0; i < maxImageID + 1; i++)  {
     103    imageSeq[i] = -1; // not yet assigned
     104  }
     105
     106  for (i = 0; i < Nimage; i++) {
     107    off_t N = image[i].imageID;
     108    myAssert (imageSeq[N] == -1, "previously assigned");
     109    imageSeq[N] = i;
     110  }
     111
    88112# else
    89113  ALLOCATE (start, unsigned, Nimage);
     
    98122
    99123off_t getImageByID (off_t ID) {
     124# if USE_IMAGE_ID
     125
     126  if (imageSeq) {
     127    if (ID < minImageID) return (-1);
     128    if (ID > maxImageID) return (-1);
     129    off_t N = imageSeq[ID];
     130    return N;
     131  }
    100132
    101133  // we have a pair of vectors (imageIDs, imageIdx) sorted by imageIDs
    102134  // use bisection to find the specified image ID
    103135
    104 # if USE_IMAGE_ID
    105136  off_t Nlo, Nhi, N;
    106137
     
    207238    if (VERBOSE2 || (MATCHCAT && (N_onImage[i] < 20))) {
    208239      name = GetPhotcodeNamebyCode (image[i].photcode);
    209       fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s)",  i,  image[i].imageID, image[i].name, N_onImage[i], image[i].nstar,
     240      int showExample = (Nfew < 30);
     241      if (showExample) fprintf (stderr, "image "OFF_T_FMT" (%d, %s) has "OFF_T_FMT" of %d measures (%s, %s) ",  i,  image[i].imageID, image[i].name, N_onImage[i], image[i].nstar,
    210242               ohana_sec_to_date(image[i].tzero), name);
    211243      if (N_onImage[i] < 20) {
    212         fprintf (stderr, "*");
     244        if (showExample) fprintf (stderr, "*");
    213245        Nfew ++;
    214246      }
    215247      if (N_onImage[i] < 15) {
    216         fprintf (stderr, "*** warning ***");
     248        if (showExample) fprintf (stderr, "*** warning ***");
    217249        Nbad ++;
    218250      }
    219       fprintf (stderr, "\n");
    220     }
    221   }
    222   fprintf (stderr, OFF_T_FMT" total images, %d with < 20 measurements, %d with < 15\n", Nimage, Nfew, Nbad);
     251      if (showExample) fprintf (stderr, "\n");
     252    }
     253  }
     254  if (MATCHCAT) fprintf (stderr, OFF_T_FMT" total images, %d with < 20 measurements, %d with < 15\n", Nimage, Nfew, Nbad);
    223255}
    224256
     
    245277  }
    246278
     279  if (!ID) return; // detection not associated with an image
     280
    247281  idx = getImageByID (ID);
    248282  if (idx == -1) {
     
    250284    return;
    251285  }
     286  measure->myDet = TRUE; // I 'own' this detection (I am calibrating its image)
    252287
    253288  // index for (catalog, measure) -> image
     
    334369# endif
    335370
    336 /*
    337 Coords *getCoords (off_t meas, int cat) {
    338 
    339   off_t i;
    340 
    341   i = MeasureToImage[cat][meas];
    342   if (i == -1) return (NULL);
    343   return (&image[i].coords);
    344 }
    345 */
    346 
    347371float getColorBlue (off_t meas, int cat) {
    348372
     
    433457  Coords *moscoords, *imcoords;
    434458
    435   // check if this image is bad and should be skipped
    436   if (badCoords(im)) return;
    437 
    438459  // WRP images need to have an associated mosaic
    439460  moscoords = NULL;
     
    491512
    492513    int TESTPT = FALSE;
    493 
    494     TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
    495     TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
     514    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measure->catID == CAT_ID_SRC) && (measure->objID == OBJ_ID_SRC);
     515    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measure->catID == CAT_ID_DST) && (measure->objID == OBJ_ID_DST);
    496516    if (TESTPT) {
    497517      fprintf (stderr, "got test det\n");
     
    597617  int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
    598618  if (VERBOSE2 && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori);
    599   saveOffsets (dPos, nPos, im);
    600619
    601620  return;
     
    604623void printNcatTotal () {
    605624  fprintf (stderr, "NcatTotal: %d\n", NcatTotal);
    606 }
    607 
    608 // return StarData values for detections in the specified image, converting coordinates from the
    609 // chip positions: X,Y -> L,M -> P,Q -> R,D
    610 void resetImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
    611 
    612   off_t i, m, c, n;
    613   double X, Y, L, M, P, Q, R, D;
    614 
    615   Mosaic *mosaic;
    616   Coords *moscoords, *imcoords, *oldcoords;
    617 
    618   fprintf (stderr, "fix resetImageRaw wrt MeasureTiny\n");
    619   abort();
    620 
    621   // check if this image is bad and should be skipped
    622   if (!badCoords(im)) {
    623     fprintf (stderr, "ERROR: inconsistent result?");
    624     abort();
    625   }
    626 
    627   // replace the current coords with the old coords:
    628   oldcoords = getCoords (im);
    629   memcpy (&image[im].coords, oldcoords, sizeof(Coords));
    630 
    631   // WRP images need to have an associated mosaic
    632   moscoords = NULL;
    633   if (!strcmp(&image[im].coords.ctype[4], "-WRP")) {
    634     mosaic = getMosaicForImage (im);
    635     if (mosaic == NULL) return;  // if we cannot find the associated image, skip it
    636     moscoords = &mosaic[0].coords;
    637   }
    638   imcoords = &image[im].coords;
    639 
    640   for (i = 0; i < N_onImage[im]; i++) {
    641     m = ImageToMeasure[im][i];
    642     c = ImageToCatalog[im][i];
    643 
    644     // XXX unclear if this should use Measure or MeasureTiny; it is only called by FixProblemImages, which has not been updated
    645     Measure *measure = &catalog[c].measure[m];
    646 
    647     X = measure[0].Xccd;
    648     Y = measure[0].Yccd;
    649     if (USE_FIXED_PIXCOORDS) {
    650       if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
    651         float dX = measure[0].Xfix - measure[0].Xccd;
    652         float dY = measure[0].Yfix - measure[0].Yccd;
    653         if (hypot(dX,dY) < 2.0) {
    654           X = measure[0].Xfix;
    655           Y = measure[0].Yfix;
    656         }
    657       }
    658     }
    659     n = measure[0].averef;
    660 
    661     if (moscoords == NULL) {
    662       // this is a Simple image (not a mosaic)
    663       // note that for a Simple image, L,M = P,Q
    664       XY_to_LM (&L, &M, X, Y, imcoords);
    665       LM_to_RD (&R, &D, L, M, imcoords);
    666     } else {
    667       XY_to_LM (&L, &M, X, Y, imcoords);
    668       XY_to_LM (&P, &Q, L, M, moscoords);
    669       LM_to_RD (&R, &D, P, Q, moscoords);
    670     }
    671     measure[0].R = R;
    672     measure[0].D = D;
    673 
    674     float dRoff = dvoOffsetR(measure, &catalog[c].average[n]);
    675 
    676     if (dRoff > +180.0*3600.0) {
    677       // average on high end of boundary, move star up
    678       measure[0].R += 360.0;
    679       dRoff -= 360.0*3600.0;
    680     }
    681     if (dRoff < -180.0*3600.0) {
    682       measure[0].R -= 360.0;
    683       dRoff += 360.0*3600.0;
    684     }
    685   }
    686 
    687   return;
    688625}
    689626
     
    736673
    737674    n = measure[0].averef;
     675
     676    int TESTPT = FALSE;
     677    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (catalog[c].average[n].catID == CAT_ID_SRC) && (catalog[c].average[n].objID == OBJ_ID_SRC);
     678    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (catalog[c].average[n].catID == CAT_ID_DST) && (catalog[c].average[n].objID == OBJ_ID_DST);
     679    if (TESTPT) {
     680      fprintf (stderr, "got test det\n");
     681    }
    738682
    739683    // an object with only one detection provides no information about the image calibration
     
    808752    ref[i].D = catalog[c].average[n].D;
    809753
     754    // if we are correcting for the Galaxy Motion Model, we assume the mean R,D is at the J2000 epoch position
     755    if (USE_GALAXY_MODEL) {
     756      myAssert (!isnan(measure[0].RoffGAL), "oops");
     757      myAssert (!isnan(measure[0].DoffGAL), "oops");
     758      ref[i].R += measure[0].RoffGAL / 3600.0;
     759      ref[i].D += measure[0].DoffGAL / 3600.0;
     760    }
     761
    810762    ref[i].Mag  = measure[0].M;
    811763    ref[i].dMag = measure[0].dM;
     
    842794  *Nstars = N_onImage[im];
    843795  return (ref);
     796}
     797
     798// return StarData values for detections in the specified image, converting coordinates from the
     799// chip positions: X,Y -> L,M -> P,Q -> R,D.  This function is used by the image fitting steps, for
     800// which the detections have already been filtered when they were loaded (bcatalog)
     801int setImageRaw (Catalog *catalog, int Ncatalog, off_t im, StarData *raw, off_t Nraw, CoordMode mode) {
     802
     803  off_t i, m, c;
     804
     805  Coords *moscoords;
     806
     807  moscoords = NULL;
     808  if (mode == MODE_MOSAIC) {
     809    moscoords = image[im].coords.mosaic;
     810    myAssert (moscoords, "coords.mosaic not defined for image %s (%d)", image[im].name, (int) im);
     811  }
     812
     813  myAssert (Nraw == N_onImage[im], "impossible!");
     814
     815  for (i = 0; i < N_onImage[im]; i++) {
     816    m = ImageToMeasure[im][i];
     817    c = ImageToCatalog[im][i];
     818
     819    // XXX should I use the raw coords or just measure.X,Y -> R,D?
     820
     821    switch (mode) {
     822      case MODE_SIMPLE:
     823        /* note that for a Simple image, L,M = P,Q */
     824        XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
     825        raw[i].P = raw[i].L;
     826        raw[i].Q = raw[i].M;
     827        LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, &image[im].coords);
     828        break;
     829      case MODE_MOSAIC:
     830        XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
     831        XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, moscoords);
     832        LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords);
     833        break;
     834      default:
     835        fprintf (stderr, "error: invalid mode in getImageRaw");
     836        abort ();
     837    }
     838
     839    MeasureTiny *measure = &catalog[c].measureT[m];
     840    measure->R = raw[i].R;
     841    measure->D = raw[i].D;
     842    if (catalog[c].measure) {
     843      catalog[c].measure[m].R = raw[i].R;
     844      catalog[c].measure[m].D = raw[i].D;
     845    }     
     846  }
     847  return TRUE;
     848}
     849
     850// return StarData values for detections in the specified image, converting coordinates from the
     851// chip positions: X,Y -> L,M -> P,Q -> R,D.  This function is used by the image fitting steps, for
     852// which the detections have already been filtered when they were loaded (bcatalog)
     853int updateImageRaw (Catalog *catalog, int Ncatalog, off_t im) {
     854
     855  off_t i, m, c;
     856
     857  for (i = 0; i < N_onImage[im]; i++) {
     858    m = ImageToMeasure[im][i];
     859    c = ImageToCatalog[im][i];
     860
     861    MeasureTiny *measure = &catalog[c].measureT[m];
     862
     863    /* apply the current image transformation or use the current value of R+dR, D+dD? */
     864    double X = measure[0].Xccd;
     865    double Y = measure[0].Yccd;
     866    if (USE_FIXED_PIXCOORDS) {
     867      if (isfinite(measure[0].Xfix) && isfinite(measure[0].Yfix)) {
     868        float dX = measure[0].Xfix - measure[0].Xccd;
     869        float dY = measure[0].Yfix - measure[0].Yccd;
     870        if (hypot(dX,dY) < 2.0) {
     871          X = measure[0].Xfix;
     872          Y = measure[0].Yfix;
     873        }
     874      }
     875    }
     876
     877    double R, D;
     878    XY_to_RD (&R, &D, X, Y, &image[im].coords);
     879    measure->R = R;
     880    measure->D = D;
     881    if (catalog[c].measure) {
     882      catalog[c].measure[m].R = R;
     883      catalog[c].measure[m].D = D;
     884    }     
     885  }
     886  return TRUE;
    844887}
    845888
  • trunk/Ohana/src/relastro/src/ImagePosIO.c

    r36630 r37807  
    7070  GET_COLUMN (polyterms,        "POLYTERMS",         float); // verify that we got 14 columns?
    7171  GET_COLUMN (ctype,            "CTYPE",             char);  // verify that we got 15 columns?
    72   GET_COLUMN (Npolyterms,       "NPOLYTERMS",        char);
     72  GET_COLUMN (Npolyterms,       "NPOLYTERMS",        byte);
    7373  GET_COLUMN (dXpixSys,         "XPIX_SYS_ERR",      float);
    7474  GET_COLUMN (dYpixSys,         "YPIX_SYS_ERR",      float);
     75  GET_COLUMN (refColorBlue,     "REF_COLOR_BLUE",    float);
     76  GET_COLUMN (refColorRed,      "REF_COLOR_RED",     float);
    7577  GET_COLUMN (imageID,          "ID",                int);
    7678  GET_COLUMN (nFitAstrom,       "NFIT",              int);
     
    8587  ALLOCATE (image_pos, ImagePos, Nrow);
    8688  for (i = 0; i < Nrow; i++) {
    87     image_pos[i].coords.crval1             = crval1    [i];
    88     image_pos[i].coords.crval2             = crval2    [i];
    89     image_pos[i].coords.crpix1             = crpix1    [i];
    90     image_pos[i].coords.crpix2             = crpix2    [i];
    91     image_pos[i].coords.cdelt1             = cdelt1    [i];
    92     image_pos[i].coords.cdelt2             = cdelt2    [i];
    93     image_pos[i].coords.pc1_1              = pc1_1     [i];
    94     image_pos[i].coords.pc1_2              = pc1_2     [i];
    95     image_pos[i].coords.pc2_1              = pc2_1     [i];
    96     image_pos[i].coords.pc2_2              = pc2_2     [i];
    97     image_pos[i].coords.Npolyterms         = Npolyterms[i];
    98     image_pos[i].dXpixSys                  = dXpixSys  [i];
    99     image_pos[i].dYpixSys                  = dYpixSys  [i];
    100     image_pos[i].imageID                   = imageID   [i];
    101     image_pos[i].nFitAstrom                = nFitAstrom[i];
    102     image_pos[i].flags                     = flags     [i];
     89    InitCoords(&image_pos[i].coords, NULL);
     90    image_pos[i].coords.crval1             = crval1      [i];
     91    image_pos[i].coords.crval2             = crval2      [i];
     92    image_pos[i].coords.crpix1             = crpix1      [i];
     93    image_pos[i].coords.crpix2             = crpix2      [i];
     94    image_pos[i].coords.cdelt1             = cdelt1      [i];
     95    image_pos[i].coords.cdelt2             = cdelt2      [i];
     96    image_pos[i].coords.pc1_1              = pc1_1       [i];
     97    image_pos[i].coords.pc1_2              = pc1_2       [i];
     98    image_pos[i].coords.pc2_1              = pc2_1       [i];
     99    image_pos[i].coords.pc2_2              = pc2_2       [i];
     100    image_pos[i].coords.Npolyterms         = Npolyterms  [i];
     101    image_pos[i].dXpixSys                  = dXpixSys    [i];
     102    image_pos[i].dYpixSys                  = dYpixSys    [i];
     103    image_pos[i].refColorBlue              = refColorBlue[i];
     104    image_pos[i].refColorRed               = refColorRed [i];
     105    image_pos[i].imageID                   = imageID     [i];
     106    image_pos[i].nFitAstrom                = nFitAstrom  [i];
     107    image_pos[i].flags                     = flags       [i];
    103108
    104109    // polyterms and ctype are a bit different
     
    108113  fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
    109114
    110   free (crval1    );
    111   free (crval2    );
    112   free (crpix1    );
    113   free (crpix2    );
    114   free (cdelt1    );
    115   free (cdelt2    );
    116   free (pc1_1     );
    117   free (pc1_2     );
    118   free (pc2_1     );
    119   free (pc2_2     );
    120   free (polyterms );
    121   free (ctype     );
    122   free (Npolyterms);
    123   free (dXpixSys  );
    124   free (dYpixSys  );
    125   free (imageID   );
    126   free (nFitAstrom);
    127   free (flags     );
     115  free (crval1      );
     116  free (crval2      );
     117  free (crpix1      );
     118  free (crpix2      );
     119  free (cdelt1      );
     120  free (cdelt2      );
     121  free (pc1_1       );
     122  free (pc1_2       );
     123  free (pc2_1       );
     124  free (pc2_2       );
     125  free (polyterms   );
     126  free (ctype       );
     127  free (Npolyterms  );
     128  free (dXpixSys    );
     129  free (dYpixSys    );
     130  free (refColorBlue);
     131  free (refColorRed );
     132  free (imageID     );
     133  free (nFitAstrom  );
     134  free (flags       );
    128135
    129136  *nimage_pos = Nrow;
     
    153160  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_POS");
    154161
    155   gfits_define_bintable_column (&theader, "D",   "CRVAL1",       "word", "unit", 1.0, 0.0);
    156   gfits_define_bintable_column (&theader, "D",   "CRVAL2",       "word", "unit", 1.0, 0.0);
    157   gfits_define_bintable_column (&theader, "E",   "CRPIX1",       "word", "unit", 1.0, 0.0);
    158   gfits_define_bintable_column (&theader, "E",   "CRPIX2",       "word", "unit", 1.0, 0.0);
    159   gfits_define_bintable_column (&theader, "E",   "CDELT1",       "word", "unit", 1.0, 0.0);
    160   gfits_define_bintable_column (&theader, "E",   "CDELT2",       "word", "unit", 1.0, 0.0);
    161   gfits_define_bintable_column (&theader, "E",   "PC1_1",        "word", "unit", 1.0, 0.0);
    162   gfits_define_bintable_column (&theader, "E",   "PC1_2",        "word", "unit", 1.0, 0.0);
    163   gfits_define_bintable_column (&theader, "E",   "PC2_1",        "word", "unit", 1.0, 0.0);
    164   gfits_define_bintable_column (&theader, "E",   "PC2_2",        "word", "unit", 1.0, 0.0);
    165   gfits_define_bintable_column (&theader, "14E", "POLYTERMS",    "word", "unit", 1.0, 0.0);
    166   gfits_define_bintable_column (&theader, "15A", "CTYPE",        "word", "unit", 1.0, 0.0);
    167   gfits_define_bintable_column (&theader, "L",   "NPOLYTERMS",   "word", "unit", 1.0, 0.0);
    168   gfits_define_bintable_column (&theader, "E",   "XPIX_SYS_ERR", "word", "unit", 1.0, 0.0);
    169   gfits_define_bintable_column (&theader, "E",   "YPIX_SYS_ERR", "word", "unit", 1.0, 0.0);
    170   gfits_define_bintable_column (&theader, "J",   "ID",           "image ID",               "unitless", 1.0, 0.0);
    171   gfits_define_bintable_column (&theader, "J",   "NFIT",         "number of fitted stars", "unitless", 1.0, 0.0);
    172   gfits_define_bintable_column (&theader, "J",   "FLAGS",        "analysis flags",         "unitless", 1.0, 0.0);
     162  gfits_define_bintable_column (&theader, "D",   "CRVAL1",         "word", "unit", 1.0, 0.0);
     163  gfits_define_bintable_column (&theader, "D",   "CRVAL2",         "word", "unit", 1.0, 0.0);
     164  gfits_define_bintable_column (&theader, "E",   "CRPIX1",         "word", "unit", 1.0, 0.0);
     165  gfits_define_bintable_column (&theader, "E",   "CRPIX2",         "word", "unit", 1.0, 0.0);
     166  gfits_define_bintable_column (&theader, "E",   "CDELT1",         "word", "unit", 1.0, 0.0);
     167  gfits_define_bintable_column (&theader, "E",   "CDELT2",         "word", "unit", 1.0, 0.0);
     168  gfits_define_bintable_column (&theader, "E",   "PC1_1",          "word", "unit", 1.0, 0.0);
     169  gfits_define_bintable_column (&theader, "E",   "PC1_2",          "word", "unit", 1.0, 0.0);
     170  gfits_define_bintable_column (&theader, "E",   "PC2_1",          "word", "unit", 1.0, 0.0);
     171  gfits_define_bintable_column (&theader, "E",   "PC2_2",          "word", "unit", 1.0, 0.0);
     172  gfits_define_bintable_column (&theader, "14E", "POLYTERMS",      "word", "unit", 1.0, 0.0);
     173  gfits_define_bintable_column (&theader, "15A", "CTYPE",          "word", "unit", 1.0, 0.0);
     174  gfits_define_bintable_column (&theader, "L",   "NPOLYTERMS",     "word", "unit", 1.0, 0.0);
     175  gfits_define_bintable_column (&theader, "E",   "XPIX_SYS_ERR",   "word", "unit", 1.0, 0.0);
     176  gfits_define_bintable_column (&theader, "E",   "YPIX_SYS_ERR",   "word", "unit", 1.0, 0.0);
     177  gfits_define_bintable_column (&theader, "E",   "REF_COLOR_BLUE", "word", "unit", 1.0, 0.0);
     178  gfits_define_bintable_column (&theader, "E",   "REF_COLOR_RED",  "word", "unit", 1.0, 0.0);
     179  gfits_define_bintable_column (&theader, "J",   "ID",             "image ID",               "unitless", 1.0, 0.0);
     180  gfits_define_bintable_column (&theader, "J",   "NFIT",           "number of fitted stars", "unitless", 1.0, 0.0);
     181  gfits_define_bintable_column (&theader, "J",   "FLAGS",          "analysis flags",         "unitless", 1.0, 0.0);
    173182
    174183  // generate the output array that carries the data
    175184  gfits_create_table (&theader, &ftable);
    176185
    177   double *crval1    ;
    178   double *crval2    ;
    179   float  *crpix1    ;
    180   float  *crpix2    ;
    181   float  *cdelt1    ;
    182   float  *cdelt2    ;
    183   float  *pc1_1     ;
    184   float  *pc1_2     ;
    185   float  *pc2_1     ;
    186   float  *pc2_2     ;
    187   float  *polyterms ;
    188   char   *ctype     ;
    189   char   *Npolyterms;
    190   float  *dXpixSys  ;
    191   float  *dYpixSys  ;
    192   int    *imageID   ;
    193   int    *nFitAstrom;
    194   int    *flags     ;
     186  double *crval1      ;
     187  double *crval2      ;
     188  float  *crpix1      ;
     189  float  *crpix2      ;
     190  float  *cdelt1      ;
     191  float  *cdelt2      ;
     192  float  *pc1_1       ;
     193  float  *pc1_2       ;
     194  float  *pc2_1       ;
     195  float  *pc2_2       ;
     196  float  *polyterms   ;
     197  char   *ctype       ;
     198  char   *Npolyterms  ;
     199  float  *dXpixSys    ;
     200  float  *dYpixSys    ;
     201  float  *refColorBlue;
     202  float  *refColorRed ;
     203  int    *imageID     ;
     204  int    *nFitAstrom  ;
     205  int    *flags       ;
    195206
    196207  // create intermediate storage arrays
     
    210221  ALLOCATE (dXpixSys  ,         float ,          Nimage_pos);
    211222  ALLOCATE (dYpixSys  ,         float ,          Nimage_pos);
     223  ALLOCATE (refColorBlue,       float ,          Nimage_pos);
     224  ALLOCATE (refColorRed ,       float ,          Nimage_pos);
    212225  ALLOCATE (imageID   ,         int   ,          Nimage_pos);
    213226  ALLOCATE (nFitAstrom,         int   ,          Nimage_pos);
     
    216229  // assign the storage arrays
    217230  for (i = 0; i < Nimage_pos; i++) {
    218     crval1    [i] = image_pos[i].coords.crval1    ;
    219     crval2    [i] = image_pos[i].coords.crval2    ;
    220     crpix1    [i] = image_pos[i].coords.crpix1    ;
    221     crpix2    [i] = image_pos[i].coords.crpix2    ;
    222     cdelt1    [i] = image_pos[i].coords.cdelt1    ;
    223     cdelt2    [i] = image_pos[i].coords.cdelt2    ;
    224     pc1_1     [i] = image_pos[i].coords.pc1_1     ;
    225     pc1_2     [i] = image_pos[i].coords.pc1_2     ;
    226     pc2_1     [i] = image_pos[i].coords.pc2_1     ;
    227     pc2_2     [i] = image_pos[i].coords.pc2_2     ;
    228     Npolyterms[i] = image_pos[i].coords.Npolyterms;
    229     dXpixSys  [i] = image_pos[i].dXpixSys         ;
    230     dYpixSys  [i] = image_pos[i].dYpixSys         ;
    231     imageID   [i] = image_pos[i].imageID          ;
    232     nFitAstrom[i] = image_pos[i].nFitAstrom       ;
    233     flags     [i] = image_pos[i].flags            ;
     231    crval1      [i] = image_pos[i].coords.crval1    ;
     232    crval2      [i] = image_pos[i].coords.crval2    ;
     233    crpix1      [i] = image_pos[i].coords.crpix1    ;
     234    crpix2      [i] = image_pos[i].coords.crpix2    ;
     235    cdelt1      [i] = image_pos[i].coords.cdelt1    ;
     236    cdelt2      [i] = image_pos[i].coords.cdelt2    ;
     237    pc1_1       [i] = image_pos[i].coords.pc1_1     ;
     238    pc1_2       [i] = image_pos[i].coords.pc1_2     ;
     239    pc2_1       [i] = image_pos[i].coords.pc2_1     ;
     240    pc2_2       [i] = image_pos[i].coords.pc2_2     ;
     241    Npolyterms  [i] = image_pos[i].coords.Npolyterms;
     242    dXpixSys    [i] = image_pos[i].dXpixSys         ;
     243    dYpixSys    [i] = image_pos[i].dYpixSys         ;
     244    refColorBlue[i] = image_pos[i].refColorBlue     ;
     245    refColorRed [i] = image_pos[i].refColorRed      ;
     246    imageID     [i] = image_pos[i].imageID          ;
     247    nFitAstrom  [i] = image_pos[i].nFitAstrom       ;
     248    flags       [i] = image_pos[i].flags            ;
    234249
    235250    // polyterms and ctype are a bit different
     
    239254
    240255  // add the columns to the output array
    241   gfits_set_bintable_column (&theader, &ftable, "CRVAL1",      crval1    ,         Nimage_pos);
    242   gfits_set_bintable_column (&theader, &ftable, "CRVAL2",      crval2    ,         Nimage_pos);
    243   gfits_set_bintable_column (&theader, &ftable, "CRPIX1",      crpix1    ,         Nimage_pos);
    244   gfits_set_bintable_column (&theader, &ftable, "CRPIX2",      crpix2    ,         Nimage_pos);
    245   gfits_set_bintable_column (&theader, &ftable, "CDELT1",      cdelt1    ,         Nimage_pos);
    246   gfits_set_bintable_column (&theader, &ftable, "CDELT2",      cdelt2    ,         Nimage_pos);
    247   gfits_set_bintable_column (&theader, &ftable, "PC1_1",       pc1_1     ,         Nimage_pos);
    248   gfits_set_bintable_column (&theader, &ftable, "PC1_2",       pc1_2     ,         Nimage_pos);
    249   gfits_set_bintable_column (&theader, &ftable, "PC2_1",       pc2_1     ,         Nimage_pos);
    250   gfits_set_bintable_column (&theader, &ftable, "PC2_2",       pc2_2     ,         Nimage_pos);
    251   gfits_set_bintable_column (&theader, &ftable, "POLYTERMS",   polyterms ,         Nimage_pos);
    252   gfits_set_bintable_column (&theader, &ftable, "CTYPE",       ctype     ,         Nimage_pos);
    253   gfits_set_bintable_column (&theader, &ftable, "NPOLYTERMS",  Npolyterms,         Nimage_pos);
    254   gfits_set_bintable_column (&theader, &ftable, "XPIX_SYS_ERR",dXpixSys  ,         Nimage_pos);
    255   gfits_set_bintable_column (&theader, &ftable, "YPIX_SYS_ERR",dYpixSys  ,         Nimage_pos);
    256   gfits_set_bintable_column (&theader, &ftable, "ID",          imageID   ,         Nimage_pos);
    257   gfits_set_bintable_column (&theader, &ftable, "NFIT",        nFitAstrom,         Nimage_pos);
    258   gfits_set_bintable_column (&theader, &ftable, "FLAGS",       flags     ,         Nimage_pos);
    259 
    260   free (crval1    );
    261   free (crval2    );
    262   free (crpix1    );
    263   free (crpix2    );
    264   free (cdelt1    );
    265   free (cdelt2    );
    266   free (pc1_1     );
    267   free (pc1_2     );
    268   free (pc2_1     );
    269   free (pc2_2     );
    270   free (polyterms );
    271   free (ctype     );
    272   free (Npolyterms);
    273   free (dXpixSys  );
    274   free (dYpixSys  );
    275   free (imageID   );
    276   free (nFitAstrom);
    277   free (flags     );
     256  gfits_set_bintable_column (&theader, &ftable, "CRVAL1",         crval1    ,         Nimage_pos);
     257  gfits_set_bintable_column (&theader, &ftable, "CRVAL2",         crval2    ,         Nimage_pos);
     258  gfits_set_bintable_column (&theader, &ftable, "CRPIX1",         crpix1    ,         Nimage_pos);
     259  gfits_set_bintable_column (&theader, &ftable, "CRPIX2",         crpix2    ,         Nimage_pos);
     260  gfits_set_bintable_column (&theader, &ftable, "CDELT1",         cdelt1    ,         Nimage_pos);
     261  gfits_set_bintable_column (&theader, &ftable, "CDELT2",         cdelt2    ,         Nimage_pos);
     262  gfits_set_bintable_column (&theader, &ftable, "PC1_1",          pc1_1     ,         Nimage_pos);
     263  gfits_set_bintable_column (&theader, &ftable, "PC1_2",          pc1_2     ,         Nimage_pos);
     264  gfits_set_bintable_column (&theader, &ftable, "PC2_1",          pc2_1     ,         Nimage_pos);
     265  gfits_set_bintable_column (&theader, &ftable, "PC2_2",          pc2_2     ,         Nimage_pos);
     266  gfits_set_bintable_column (&theader, &ftable, "POLYTERMS",      polyterms ,         Nimage_pos);
     267  gfits_set_bintable_column (&theader, &ftable, "CTYPE",          ctype     ,         Nimage_pos);
     268  gfits_set_bintable_column (&theader, &ftable, "NPOLYTERMS",     Npolyterms,         Nimage_pos);
     269  gfits_set_bintable_column (&theader, &ftable, "XPIX_SYS_ERR",   dXpixSys  ,         Nimage_pos);
     270  gfits_set_bintable_column (&theader, &ftable, "YPIX_SYS_ERR",   dYpixSys  ,         Nimage_pos);
     271  gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_BLUE", refColorBlue,       Nimage_pos);
     272  gfits_set_bintable_column (&theader, &ftable, "REF_COLOR_RED",  refColorRed ,       Nimage_pos);
     273  gfits_set_bintable_column (&theader, &ftable, "ID",             imageID   ,         Nimage_pos);
     274  gfits_set_bintable_column (&theader, &ftable, "NFIT",           nFitAstrom,         Nimage_pos);
     275  gfits_set_bintable_column (&theader, &ftable, "FLAGS",          flags     ,         Nimage_pos);
     276
     277  free (crval1      );
     278  free (crval2      );
     279  free (crpix1      );
     280  free (crpix2      );
     281  free (cdelt1      );
     282  free (cdelt2      );
     283  free (pc1_1       );
     284  free (pc1_2       );
     285  free (pc2_1       );
     286  free (pc2_2       );
     287  free (polyterms   );
     288  free (ctype       );
     289  free (Npolyterms  );
     290  free (dXpixSys    );
     291  free (dYpixSys    );
     292  free (refColorBlue);
     293  free (refColorRed );
     294  free (imageID     );
     295  free (nFitAstrom  );
     296  free (flags       );
    278297 
    279298  FILE *f = fopen (filename, "w");
  • trunk/Ohana/src/relastro/src/StarMaps.c

    r36630 r37807  
    176176}
    177177
     178int printStarMap(int N, char *filename) {
     179
     180  off_t i, Nimages;
     181  Image *images = getimages(&Nimages, NULL);
     182  double L, M;
     183
     184  FILE *f = fopen (filename, "w");
     185
     186  for (i = 0; i < starmap[N].Npoints; i++) {
     187    // set the transformed coordinates
     188    XY_to_LM (&L, &M, starmap[N].points[i].X, starmap[N].points[i].Y, &images[N].coords);
     189
     190    fprintf (f, "%d %7.2f %f : %7.2f %7.2f : %7.2f %7.2f : %7.2f %7.2f\n", (int) i, starmap[N].points[i].X, starmap[N].points[i].Y, starmap[N].points[i].L, starmap[N].points[i].M, L, M, starmap[N].points[i].L - L, starmap[N].points[i].M - M);
     191  }
     192  fclose (f);
     193  return (TRUE);
     194}
     195
  • trunk/Ohana/src/relastro/src/UpdateChips.c

    r33652 r37807  
    3636  off_t i, Nraw, Nref, nFitAstr;
    3737  StarData *raw, *ref;
    38   Coords *oldCoords;
    3938  float dXpixSys, dYpixSys;
    4039  double *Ro, *Do;
     
    7473      Nskip ++;
    7574      mode[i] = 0;
     75      continue;
     76    }
     77    if (Nraw <= IMFIT_TOO_FEW) {
     78      Nskip ++;
     79      mode[i] = 0;
     80      free (raw);
    7681      continue;
    7782    }
     
    9095
    9196    // save these in case of failure
    92     saveCoords (&image[i].coords, i);
     97    Coords oldCoords;
     98    SaveCoords (&oldCoords, &image[i].coords);
     99
    93100    dXpixSys = image[i].dXpixSys;
    94101    dYpixSys = image[i].dYpixSys;
     
    100107      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name,  i,  Nraw, image[i].nstar);
    101108
    102       // restore status quo ante
    103       oldCoords = getCoords (i);
    104       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
    105       image[i].dXpixSys = dXpixSys;
    106       image[i].dYpixSys = dYpixSys;
    107       image[i].nFitAstrom = nFitAstr;
    108 
    109       saveCenter (image, &Ro[i], &Do[i], i);
    110       mode[i] = 1;
    111       NoldFit ++;
    112       free (raw);
    113       free (ref);
    114       continue;
     109      if (1) {
     110        // restore status quo ante (replace truMap with tmpMap)
     111        RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
     112        image[i].dXpixSys = dXpixSys;
     113        image[i].dYpixSys = dYpixSys;
     114        image[i].nFitAstrom = nFitAstr;
     115
     116        saveCenter (image, &Ro[i], &Do[i], i);
     117        mode[i] = 1;
     118        NoldFit ++;
     119        free (raw);
     120        free (ref);
     121        continue;
     122      }
    115123    }
    116124
    117125    if (!checkStarMap (i)) {
    118126      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
    119       // restore status quo ante
    120       oldCoords = getCoords (i);
    121       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
    122       image[i].dXpixSys = dXpixSys;
    123       image[i].dYpixSys = dYpixSys;
    124       image[i].nFitAstrom = nFitAstr;
    125 
    126       saveCenter (image, &Ro[i], &Do[i], i);
    127       mode[i] = 2;
    128       image[i].flags |= ID_IMAGE_ASTROM_POOR;
    129       NoldFit ++;
    130       free (raw);
    131       free (ref);
    132       continue;
     127
     128      if (1) {
     129        // restore status quo ante (replace truMap with tmpMap)
     130        RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
     131        image[i].dXpixSys = dXpixSys;
     132        image[i].dYpixSys = dYpixSys;
     133        image[i].nFitAstrom = nFitAstr;
     134
     135        saveCenter (image, &Ro[i], &Do[i], i);
     136        mode[i] = 2;
     137        image[i].flags |= ID_IMAGE_ASTROM_POOR;
     138        NoldFit ++;
     139        free (raw);
     140        free (ref);
     141        continue;
     142      }
    133143    }
     144
     145    // Apply the modified coords back to the measure.R,D.  Note that raw.R,D, ref.L,M, etc
     146    // are all automatically updated in this block because they are re-generated from
     147    // image.coords on each pass.
     148    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_MOSAIC);
     149    if (USE_GALAXY_MODEL) {
     150      image[i].flags |= ID_IMAGE_ASTROM_GMM;
     151    }
    134152
    135153    saveCenter (image, &Ro[i], &Do[i], i);
     
    235253  off_t Nraw, Nref, nFitAstr;
    236254  StarData *raw, *ref;
    237   Coords *oldCoords;
    238255  float dXpixSys, dYpixSys;
    239256
     
    260277      threadinfo->Nskip ++;
    261278      threadinfo->mode[i] = 0;
     279      continue;
     280    }
     281    if (Nraw <= IMFIT_TOO_FEW) {
     282      threadinfo->Nskip ++;
     283      threadinfo->mode[i] = 0;
     284      free (raw);
    262285      continue;
    263286    }
     
    276299
    277300    // save these in case of failure
    278     saveCoords (&image[i].coords, i);
     301    Coords oldCoords;
     302    SaveCoords (&oldCoords, &image[i].coords);
    279303    dXpixSys = image[i].dXpixSys;
    280304    dYpixSys = image[i].dYpixSys;
     
    286310      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT" of %d\n", image[i].name,  i,  Nraw, image[i].nstar);
    287311
    288       // restore status quo ante
    289       oldCoords = getCoords (i);
    290       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     312      // restore status quo ante (replace truMap with tmpMap)
     313      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    291314      image[i].dXpixSys = dXpixSys;
    292315      image[i].dYpixSys = dYpixSys;
     
    303326    if (!checkStarMap (i)) {
    304327      if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name,  i,  Nraw);
    305       // restore status quo ante
    306       oldCoords = getCoords (i);
    307       memcpy (&image[i].coords, oldCoords, sizeof(Coords));
     328
     329      // restore status quo ante (replace truMap with tmpMap)
     330      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
    308331      image[i].dXpixSys = dXpixSys;
    309332      image[i].dYpixSys = dYpixSys;
     
    319342    }
    320343
     344    // apply the modified R,D back to the measures
     345    setImageRaw (threadinfo->catalog, threadinfo->Ncatalog, i, raw, Nraw, MODE_MOSAIC);
     346
    321347    saveCenter (image, &threadinfo->Ro[i], &threadinfo->Do[i], i);
    322348    threadinfo->mode[i] = 3;
     
    333359static pthread_mutex_t UpdateChips_mutex = PTHREAD_MUTEX_INITIALIZER;
    334360
     361void lockUpdateChips () {
     362  pthread_mutex_lock (&UpdateChips_mutex);
     363}
     364void unlockUpdateChips () {
     365  pthread_mutex_unlock (&UpdateChips_mutex);
     366}
     367
    335368// we have an array of chips (image, Nimage).  we need to hand out images one at a time to
    336369// the worker threads as they need
    337370off_t getNextImageForThread () {
    338371
    339   pthread_mutex_lock (&UpdateChips_mutex);
     372  lockUpdateChips ();
    340373  if (nextImage >= Nimage) {
    341     pthread_mutex_unlock (&UpdateChips_mutex);
     374    unlockUpdateChips ();
    342375    return (-1);
    343376  }
     
    345378  nextImage ++;
    346379
    347   pthread_mutex_unlock (&UpdateChips_mutex);
     380  unlockUpdateChips ();
    348381  return (thisImage);
    349382}
     
    494527}
    495528
    496 // XXX if (!FindMosaicForImage (image, Nimage, i)) { }
     529// save the coords and offset map in src at tgt
     530void SaveCoords (Coords *tgt, Coords *src) {
     531  myAssert (tgt, "oops");
     532  myAssert (src, "oops");
     533  CopyCoords (tgt, src); // src retains a pointer to the AstromOffsetMap table, to be saved
     534  tgt->offsetMap = AstromOffsetMapCopy(src->offsetMap); // oldCoords now saves the old values in a new structure
     535}
     536
     537// restore the coords and offset map at tgt from src
     538void RestoreCoords (Coords *tgt, Coords *src, Image *image) {
     539
     540  AstromOffsetMap *truMap = tgt->offsetMap;
     541  AstromOffsetMap *tmpMap = src->offsetMap;
     542
     543  // copy the coords structure data first, then fix the offsetMap pointers
     544  // this modifies tgt.coords, but we need to keep the original pointer
     545  CopyCoords (tgt, src);
     546  tgt->offsetMap = truMap;
     547
     548  // we want to keep the old solution, which is (maybe) a pointer to a stand-alone
     549  // map.  the image has a bad solution, but it is a pointer to the map in the I/O
     550  // table.  those values will be saved on exit.
     551
     552  if (!tmpMap && !truMap) return;
     553
     554  if (tmpMap && truMap) {
     555    AstromOffsetMapSetOrder (truMap, tmpMap->Nx, tmpMap->Ny, image);
     556    AstromOffsetMapCopyData (truMap, tmpMap);
     557    return;
     558  }
     559
     560  if (tmpMap && !truMap) {
     561    // is this even possible?
     562    lockUpdateChips ();
     563    AstromOffsetTable *table = get_astrom_table ();
     564    AstromOffsetTableNewMap(table, tmpMap->Nx, tmpMap->Ny, image);  // registers the map with the image
     565    unlockUpdateChips ();
     566    AstromOffsetMapCopyData (image->coords.offsetMap, tmpMap);
     567    return;
     568  }
     569  if (!tmpMap && truMap) {
     570    truMap->keep = FALSE;
     571    return;
     572  }
     573  myAbort ("oops");
     574}
  • trunk/Ohana/src/relastro/src/UpdateMeasures.c

    r35763 r37807  
    11# include "relastro.h"
     2void dump_measures (Average *average, Measure *measure); // in ImageOps.c
    23
    3 void printNcatTotal ();
     4// this function is called by UpdateObjectOffsets or relastro_images.c for reset
     5int UpdateMeasures (Catalog *catalog, int Ncatalog) {
     6
     7  off_t i, j, Nimage;
     8  Image *image;
     9  double DPOS_MAX_ASEC;
     10
     11  int badImage =
     12    ID_IMAGE_ASTROM_NOCAL |
     13    ID_IMAGE_ASTROM_POOR |
     14    ID_IMAGE_ASTROM_FAIL |
     15    ID_IMAGE_ASTROM_SKIP |
     16    ID_IMAGE_ASTROM_FEW;
     17
     18  if (RESET_BAD_IMAGES) badImage = 0;
     19
     20  image = getimages (&Nimage, NULL);
     21
     22  // track measurements which are far from their original position (poor at pole)
     23  int NoffRAave = 0;  int NoffRAori = 0;
     24  int NoffDECave = 0; int NoffDECori = 0;
     25
     26  for (i = 0; i < Ncatalog; i++) {
     27    myAssert (!catalog[i].Nmeasure || catalog[i].measureT, "programming error");
     28    for (j = 0; j < catalog[i].Nmeasure; j++) {
     29      MeasureTiny *measureT = &catalog[i].measureT[j];
     30      Measure     *measureB = catalog[i].measure ? &catalog[i].measure[j] : NULL;
     31
     32      off_t im = getImageByID (measureT->imageID);
     33      if (im < 0) continue; // detections without imageIDs are not associated with a known image (eg, refs)
     34
     35      // check that we have the right image:
     36      myAssert (measureT->photcode == image[im].photcode, "image photcode mismatch");
     37      myAssert (measureT->t >= image[im].tzero, "image time mismatch (1)");
     38      myAssert (measureT->t <= image[im].tzero + image[im].NX*image[im].trate/5000.0, "image time mismatch (2)");
     39      // I'm allowing the trate*NX to be a factor of 2x too small
     40
     41      // skip measurements on images that have failed solutions (divergent or otherwise)
     42      // XXX apply this or not??
     43      if (FALSE && (image[im].flags & badImage)) continue;
     44
     45      Coords *moscoords = image[im].coords.mosaic;
     46      Coords *imcoords = &image[im].coords;
     47
     48      if (moscoords) {
     49        DPOS_MAX_ASEC = 3600.0*DPOS_MAX*hypot(moscoords->cdelt1, moscoords->cdelt2);
     50      } else {
     51        DPOS_MAX_ASEC = 3600.0*DPOS_MAX*hypot(imcoords->cdelt1, imcoords->cdelt2);
     52      }
     53
     54      double X = measureT->Xccd;
     55      double Y = measureT->Yccd;
     56      if (USE_FIXED_PIXCOORDS) {
     57        if (isfinite(measureT->Xfix) && isfinite(measureT->Yfix)) {
     58          float dX = measureT->Xfix - measureT->Xccd;
     59          float dY = measureT->Yfix - measureT->Yccd;
     60          if (hypot(dX,dY) < 2.0) {
     61            X = measureT->Xfix;
     62            Y = measureT->Yfix;
     63          }
     64        }
     65      }
     66
     67      double R, D;
     68      XY_to_RD (&R, &D, X, Y, imcoords);
     69
     70      int n = measureT[0].averef;
     71      Average *average = &catalog[i].average[n];
     72
     73      double dR = 3600.0*(average[0].R - R);
     74      double dD = 3600.0*(average[0].D - D);
     75
     76      // make sure detection is on the same side of the 0,360 boundary as the average
     77      // this will give some funny results withing ~1 arcsec of the pol
     78      if (dR > +180.0*3600.0) {
     79        // average on high end of boundary, move star up
     80        R += 360.0;
     81        dR = 3600.0*(average[0].R - R);
     82      }
     83      if (dR < -180.0*3600.0) {
     84        // average on low end of boundary, move star down
     85        R -= 360.0;
     86        dR = 3600.0*(average[0].R - R);
     87      }
     88
     89      float csdec = cos(average[0].D * RAD_DEG);
     90
     91      // complain if the new location is far from the average location
     92      // NOTE: This should never happen, or our StarMap tests are not working
     93      if (fabs(dR*csdec) > 3.0*ADDSTAR_RADIUS) {
     94        NoffRAave ++;
     95        if (VERBOSE2 && catalog[i].measure) {
     96          fprintf (stderr, "measurement is far from average location (R): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, dR*csdec, dD);
     97          dump_measures (&average[0], catalog[i].measure);
     98        }
     99      }
     100      if (fabs(dD) > 3.0*ADDSTAR_RADIUS) {
     101        NoffDECave ++;
     102        if (VERBOSE2 && catalog[i].measure) {
     103          fprintf (stderr, "measurement is far from average location (D): %f %f (%f %f)\n", average[0].R, average[0].D, dR, dD);
     104          dump_measures (&average[0], catalog[i].measure);
     105        }
     106      }
     107
     108      // complain if the new location is far from the old location
     109      if (fabs(csdec*(measureT[0].R - R)) > DPOS_MAX_ASEC) {
     110        NoffRAori ++;
     111        if (VERBOSE2 && catalog[i].measure) {
     112          fprintf (stderr, "measurement moves far from original location (R): %f %f (%f %f %f %f)\n", average[0].R, average[0].D, measureT[0].R, dR, csdec*(measureT[0].R - R), dD);
     113          dump_measures (&average[0], catalog[i].measure);
     114        }
     115      }
     116      if (fabs(measureT[0].D - D) > DPOS_MAX_ASEC) {
     117        NoffDECori ++;
     118        if (VERBOSE2 && catalog[i].measure) {
     119          fprintf (stderr, "measurement moves far from original location (D): %f %f (%f %f %f)\n", average[0].R, average[0].D, dR, measureT[0].D, dD);
     120          dump_measures (&average[0], catalog[i].measure);
     121        }
     122      }
     123      measureT->R = R;
     124      measureT->D = D;
     125      if (measureB) {
     126        measureB->R = R;
     127        measureB->D = D;
     128      }
     129    }
     130  }
     131  // printNcatTotal ();
     132
     133  int Noff = NoffRAave + NoffDECave + NoffRAori + NoffDECori;
     134  if (VERBOSE && (Noff > 0)) fprintf (stderr, "Noff ave RA %d, Noff ave DEC %d, Noff ori RA %d, Noff ori DEC %d\n", NoffRAave, NoffDECave, NoffRAori, NoffDECori);
     135
     136  return (TRUE);
     137}
    4138
    5139// this function operates on Measure, not MeasureTiny
    6 int UpdateMeasures (Catalog *catalog, int Ncatalog) {
     140int UpdateMeasuresOld (Catalog *catalog, int Ncatalog) {
    7141
    8142  off_t i, Nimage;
     
    32166  }
    33167
    34   printNcatTotal ();
     168  // printNcatTotal ();
    35169
    36170  return (TRUE);
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r37038 r37807  
    5959
    6060    // uses MeasureTiny values, but will also update Measure values when populated
    61     UpdateObjects (&catalog, 1);
     61    // if Galaxy Motion Model correction is active, do not apply at this last stage
     62    UpdateObjects (&catalog, 1, FALSE);
    6263
    6364    free_tiny_values(&catalog);
     
    7475    save_catalogs (&catalog, 1);
    7576  }
    76  
     77  printNcatTotal();
    7778  return (TRUE);
    7879}
     80
     81int UpdateObjectOffsets_parallel_group (HostTableGroup *group, SkyList *sky);
     82int UpdateObjectOffsets_parallel_table (HostTable *table, SkyList *sky);
    7983
    8084// CATDIR is supplied globally
     
    9094    exit (1);
    9195  }   
     96
     97# if (0)
     98 
     99  UpdateObjectOffsets_parallel_table (table, sky);
     100
     101# else
     102
     103  int Ngroups;
     104  HostTableGroup *groups = HostTableGroups (table, &Ngroups);
     105  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
     106
     107  int i;
     108  for (i = 0; i < Ngroups; i++) {
     109    // update only a group of unique machines at a time
     110    UpdateObjectOffsets_parallel_group (&groups[i], sky);
     111  }
     112# endif
     113
     114  return TRUE;
     115}     
     116
     117// CATDIR is supplied globally
     118# define DEBUG 1
     119int UpdateObjectOffsets_parallel_group (HostTableGroup *group, SkyList *sky) {
     120
     121  // launch the relastro_client jobs to the parallel hosts
     122
     123  int i, j;
     124  for (i = 0; i < group->Nhosts; i++) {
     125
     126    if (sky->Nregions < group->Nhosts) {
     127      // do any of the regions want this host?
     128      int wantThisHost = FALSE;
     129      for (j = 0; j < sky->Nregions; j++) {
     130        if (HostTableTestHost (sky->regions[j], group->hosts[i][0].hostID)) {
     131          wantThisHost = TRUE;
     132          break;
     133        }
     134      }
     135      if (!wantThisHost) {
     136        // fprintf (stderr, "skip host %s\n", group->hosts[i][0].hostname);
     137        continue;
     138      }
     139    }
     140
     141    // ensure that the paths are absolute path names
     142    char *tmppath = abspath (group->hosts[i][0].pathname, DVO_MAX_PATH);
     143    free (group->hosts[i][0].pathname);
     144    group->hosts[i][0].pathname = tmppath;
     145
     146    // options / arguments that can affect relastro_client -load:
     147    // VERBOSE, VERBOSE2
     148    // RESET (-reset)
     149    // TimeSelect -time
     150    // (note that psfQF is applied rigidly at 0.85, as is the galaxy test)
     151    // ImagSelect, ImagMin, ImagMax
     152    // MaxDensityUse, MaxDensityValue
     153
     154    char command[1024];
     155    snprintf (command, 1024, "relastro_client -update-offsets -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -minerror %f",
     156              group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, MIN_ERROR);
     157
     158    if (FIT_MODE == FIT_PM_ONLY)         strextend (command, "-pm");
     159    if (FIT_MODE == FIT_PAR_ONLY)        strextend (command, "-par");
     160    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (command, "-pmpar");
     161
     162    if (VERBOSE)       strextend (command, "-v");
     163    if (VERBOSE2)      strextend (command, "-vv");
     164    if (RESET)         strextend (command, "-reset");
     165    if (UPDATE)        strextend (command, "-update");
     166
     167    if (RESET_BAD_IMAGES) strextend (command, "-reset-bad-images");
     168
     169    if (ImagSelect)    strextend (command, "-instmag %f %f", ImagMin, ImagMax);
     170    if (MaxDensityUse) strextend (command, "-max-density %f", MaxDensityValue);
     171   
     172    if (USE_BASIC_CHECK) strextend (command, "-basic-image-search");
     173    if (FlagOutlier)     strextend (command, "-clip %d", CLIP_THRESH);
     174    if (ExcludeBogus)    strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     175   
     176    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     177
     178    if (PHOTCODE_KEEP_LIST) strextend (command, "+photcode %s", PHOTCODE_KEEP_LIST);
     179    if (PHOTCODE_SKIP_LIST) strextend (command, "-photcode %s", PHOTCODE_SKIP_LIST);
     180    if (PhotFlagSelect)     strextend (command, "+photflags");
     181    if (PhotFlagBad)        strextend (command, "+photflagbad %d", PhotFlagBad);
     182    if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
     183    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
     184
     185    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     186      strextend (command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     187    }
     188    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     189      strextend (command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     190    }
     191
     192    if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
     193    if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     194
     195    if (TimeSelect) {
     196      char *tstart = ohana_sec_to_date (TSTART);
     197      char *tstop  = ohana_sec_to_date (TSTOP);
     198      strextend (command, "-time %s %s", tstart, tstop);
     199      free (tstart);
     200      free (tstop);
     201    }
     202    fprintf (stderr, "command: %s\n", command);
     203
     204    if (PARALLEL_MANUAL) continue;
     205
     206    if (PARALLEL_SERIAL) {
     207      int status = system (command);
     208      if (status) {
     209        fprintf (stderr, "ERROR running relastro_client\n");
     210        exit (2);
     211      }
     212    } else {
     213      // launch the job on the remote machine (no handshake)
     214      int errorInfo = 0;
     215      int pid = rconnect ("ssh", group->hosts[i][0].hostname, command, group->hosts[i][0].stdio, &errorInfo, FALSE);
     216      if (!pid) {
     217        if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", group->hosts[i][0].hostname, errorInfo);
     218        exit (1);
     219      }
     220      group->hosts[i][0].pid = pid; // save for future reference
     221    }
     222  }
     223
     224  if (PARALLEL_MANUAL) {
     225    fprintf (stderr, "run the relastro_client commands above.  when these are done, hit return\n");
     226    getchar();
     227  }
     228  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
     229    HostTableGroupWaitJobsGetIO (group, __FILE__, __LINE__, VERBOSE);
     230  }
     231
     232  return TRUE;
     233}     
     234
     235// CATDIR is supplied globally
     236# define DEBUG 1
     237int UpdateObjectOffsets_parallel_table (HostTable *table, SkyList *sky) {
     238
     239  // launch the relastro_client jobs to the parallel hosts
    92240
    93241  int i, j;
  • trunk/Ohana/src/relastro/src/UpdateObjects.c

    r37261 r37807  
    22# define PAR_TOOFEW 5
    33
    4 int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m);
     4int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m, int applyGalaxyOffset);
    55int UpdateObjects_Stack (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats);
    66
     
    6969
    7070  /* project coordinates to a plane centered on the object with units of arcsec */
    71   coords.crval1 = 0;
    72   coords.crval2 = 0;
    73   coords.crpix1 = 0;
    74   coords.crpix2 = 0;
     71  InitCoords (&coords, "DEC--SIN");
    7572  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    76   coords.pc1_1  = coords.pc2_2 = 1.0;
    77   coords.pc1_2  = coords.pc2_1 = 0.0;
    78   coords.Npolyterms = 1;
    79   strcpy (coords.ctype, "DEC--SIN");
    8073
    8174  // use J2000 as a reference time
     
    10699// This function operates on both Measure and MeasureTiny.  In the big stages, this should
    107100// be called with just MeasureTiny set and Measure == NULL
    108 int UpdateObjects (Catalog *catalog, int Ncatalog) {
     101int UpdateObjects (Catalog *catalog, int Ncatalog, int Nloop) {
    109102
    110103  initObjectData (catalog, Ncatalog);
     
    137130
    138131      UpdateObjects_Stack(average, secfilt, measure, measureBig, Nsecfilt, &fitStatsStack);
    139       UpdateObjects_Chips(average, secfilt, measure, measureBig, Nsecfilt, &fitStatsChips, i, m);
    140     }
    141     if (VERBOSE) fprintf (stderr, "catalog %d : chips "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  fitStatsChips.Nave,  fitStatsChips.Npm,  fitStatsChips.Npar,  fitStatsChips.Nskip, fitStatsChips.Noffset);
    142     if (VERBOSE) fprintf (stderr, "catalog %d : stack "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  fitStatsStack.Nave,  fitStatsStack.Npm,  fitStatsStack.Npar,  fitStatsStack.Nskip, fitStatsStack.Noffset);
     132      UpdateObjects_Chips(average, secfilt, measure, measureBig, Nsecfilt, &fitStatsChips, i, m, Nloop);
     133    }
     134    if (VERBOSE2) fprintf (stderr, "catalog %d : chips "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  fitStatsChips.Nave,  fitStatsChips.Npm,  fitStatsChips.Npar,  fitStatsChips.Nskip, fitStatsChips.Noffset);
     135    if (VERBOSE2) fprintf (stderr, "catalog %d : stack "OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par : Nskip "OFF_T_FMT", Noffset "OFF_T_FMT"\n",  i,  fitStatsStack.Nave,  fitStatsStack.Npm,  fitStatsStack.Npar,  fitStatsStack.Nskip, fitStatsStack.Noffset);
    143136    sumFitStats (&fitStatsChips, &sumStatsChips);
    144137    sumFitStats (&fitStatsStack, &sumStatsStack);
     
    146139  freeObjectData ();
    147140
    148   if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (sumStatsChips.Nave + sumStatsChips.Npm + sumStatsChips.Npar),  sumStatsChips.Nave,  sumStatsChips.Npm,  sumStatsChips.Npar,  sumStatsChips.Nskip, sumStatsChips.Noffset);
    149   if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (sumStatsStack.Nave + sumStatsStack.Npm + sumStatsStack.Npar),  sumStatsStack.Nave,  sumStatsStack.Npm,  sumStatsStack.Npar,  sumStatsStack.Nskip, sumStatsStack.Noffset);
     141  if (VERBOSE && (Ncatalog > 1)) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (sumStatsChips.Nave + sumStatsChips.Npm + sumStatsChips.Npar),  sumStatsChips.Nave,  sumStatsChips.Npm,  sumStatsChips.Npar,  sumStatsChips.Nskip, sumStatsChips.Noffset);
     142  if (VERBOSE && (Ncatalog > 1)) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (sumStatsStack.Nave + sumStatsStack.Npm + sumStatsStack.Npar),  sumStatsStack.Nave,  sumStatsStack.Npm,  sumStatsStack.Npar,  sumStatsStack.Nskip, sumStatsStack.Noffset);
    150143  return (TRUE);
    151144}
     
    153146// This function operates on both Measure and MeasureTiny.  In the big stages, this should
    154147// be called with just MeasureTiny set and Measure == NULL
    155 int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m) {
     148int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m, int applyGalaxyOffset) {
    156149
    157150  int setRefColor = areImagesMatched();
     
    215208    double Ri = getMeanR (&measure[k], average, secfilt);
    216209    double Di = getMeanD (&measure[k], average, secfilt);
     210
     211    // if we are correcting for the Galaxy Motion Model, only should apply it here
     212    // (a) when we are working to correct the images (mean R,D assumed to be at J2000) and
     213    // (b) if we think the measure R,D is already at the image epoch position
     214    if (USE_GALAXY_MODEL && applyGalaxyOffset) {
     215      Ri -= measure[k].RoffGAL / 3600.0;
     216      Di -= measure[k].DoffGAL / 3600.0;
     217    }
     218
     219    // XXX add in dR,dD GAL here
    217220
    218221    // mark (as POOR) any measurements which are deviant from the mean by > ExcludeBogusRadius
     
    329332  // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
    330333
     334  // project all of the R,D coordinates to a plane centered on this coordinate. set
     335  // the times to be relative to Tmean (this is required for parallax as well)
     336  for (k = 0; k < N; k++) {
     337    RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
     338    T[k] -= Tmean;
     339    if (XVERB) {
     340      fprintf (stderr, OFF_T_FMT" %f %f %f  %f %f +/- %f %f\n",  k, T[k], R[k], D[k], X[k], Y[k], dX[k], dY[k]);
     341    }
     342  }       
     343
    331344  // *** first fit for the proper motion (skip fit if Trange or Npts is too small) ***
    332345  if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
     
    340353    }
    341354
    342     // project all of the R,D coordinates to a plane centered on this coordinate. set
    343     // the times to be relative to Tmean (this is required for parallax as well)
    344     for (k = 0; k < N; k++) {
    345       RD_to_XY (&X[k], &Y[k], R[k], D[k], &coords);
    346       T[k] -= Tmean;
    347       if (XVERB) {
    348         fprintf (stderr, OFF_T_FMT" %f %f %f  %f %f +/- %f %f\n",  k, T[k], R[k], D[k], X[k], Y[k], dX[k], dY[k]);
    349       }
    350     }     
    351 
    352355    FitPM (&fitPM, X, dX, Y, dY, T, N, XVERB);
    353356
     
    357360    XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &coords);
    358361    if (XVERB) fprintf (stderr, "project: %f %f : %f %f : %f\n", fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.p);
     362    if (fabs(fitPM.Ro) < 0.01) fprintf (stderr, "watch out for 0,360 boundary\n");
     363    // XXX : does this make sense at 0,360 boundary?
    359364
    360365    fitPM.p  = fitPM.dp  = 0.0;
     
    409414    fitStats->Npar ++;
    410415
     416    if (fabs(fitPM.Ro) < 0.01) fprintf (stderr, "watch out for 0,360 boundary\n");
     417
    411418    // XXX a hard-wired hack...
    412419    if ((fabs(fitPAR.uR) > 2.0) || (fabs(fitPAR.uD) > 2.0)) {
     
    419426    // ALWAYS fit the average model
    420427    StatType statsR, statsD;
    421     liststats_pos (R, dR, N, &statsR, XVERB); // WARNING: this function modifies R (do not use after here)
    422     liststats_pos (D, dD, N, &statsD, XVERB); // WARNING: this function modifies D (do not use after here)
    423 
    424     fitAve.Ro = statsR.mean;
    425     fitAve.dRo = 3600.0*statsR.sigma;
    426 
    427     fitAve.Do = statsD.mean;
    428     fitAve.dDo = 3600.0*statsD.sigma;
     428    liststats_pos (X, dX, N, &statsR, XVERB); // WARNING: this function modifies R (do not use after here)
     429    liststats_pos (Y, dY, N, &statsD, XVERB); // WARNING: this function modifies D (do not use after here)
     430
     431    // project Ro, Do back to RA,DEC
     432    XY_to_RD (&fitAve.Ro, &fitAve.Do, statsR.mean, statsD.mean, &coords);
     433    if (XVERB) fprintf (stderr, "average: %f %f\n", fitAve.Ro, fitAve.Do);
     434
     435    fitAve.dRo = statsR.sigma;
     436    fitAve.dDo = statsD.sigma;
    429437
    430438    fitAve.chisq = (N > 1) ? 0.5 * (statsR.chisq + statsD.chisq) : NAN;
     
    466474      break;
    467475  }
    468   if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) plx=(%f +/- %f)\n",
    469                       average[0].R,
    470                       average[0].D,
    471                       fit.Ro, fit.Do,
    472                       3600*(average[0].R - fit.Ro),
    473                       3600*(average[0].D - fit.Do),
    474                       fit.uR, fit.uD, fit.p, fit.dp);
     476  if (XVERB) {
     477    fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) plx=(%f +/- %f)\n",
     478             average[0].R,
     479             average[0].D,
     480             fit.Ro, fit.Do,
     481             3600*(average[0].R - fit.Ro),
     482             3600*(average[0].D - fit.Do),
     483             fit.uR, fit.uD, fit.p, fit.dp);
     484    fprintf (stderr, "-----\n");
     485  }
    475486
    476487  // make sure that the fit succeeded
     
    494505  coords.crval1 = average[0].R;
    495506  coords.crval2 = average[0].D;
     507  if (isnan(coords.crval1)) {
     508    return (FALSE);
     509  }
     510  if (isnan(coords.crval2)) {
     511    return (FALSE);
     512  }
    496513
    497514  double dXoff, dYoff;
     
    505522    return FALSE; // XXX ??
    506523  }
    507 
    508   average[0].R          = fit.Ro; // RA in degrees
    509   average[0].D          = fit.Do; // DEC in degrees
    510   average[0].dR         = fit.dRo; // RA scatter in arcsec
    511   average[0].dD         = fit.dDo; // DEC scatter in arcsec
    512 
    513   average[0].uR         = fit.uR; // RA proper motion in arcsec/year
    514   average[0].uD         = fit.uD; // DEC proper motion in arcsec/year
    515   average[0].duR        = fit.duR; // RA proper motion error in arcsec/year
    516   average[0].duD        = fit.duD; // DEC proper motion error in arcsec/year
    517 
    518   average[0].P          = fit.p; // parallax in arcsec
    519   average[0].dP         = fit.dp; // parallax error in arcsec
    520 
    521   average[0].ChiSqAve   = fitAve.chisq;
    522   average[0].ChiSqPM    = fitPM.chisq;
    523   average[0].ChiSqPar   = fitPAR.chisq;
    524 
    525   average[0].Tmean      = (Tmean * 86400 * 365.25) + T2000;
    526   average[0].Trange     = (Trange * 86400 * 365.25);
    527   average[0].Npos       = fit.Nfit;
    528 
    529   // unset the NO_ASTROM bit (not(NO_ASTROM) == HAVE_ASTROM)
    530   average[0].flags &= ~ID_STAR_NO_ASTROM;
    531524
    532525  if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f) chisq=(%f, %f, %f)\n",
     
    540533                      fitAve.chisq, fitPM.chisq, fitPAR.chisq);
    541534
     535  average[0].R          = fit.Ro; // RA in degrees
     536  average[0].D          = fit.Do; // DEC in degrees
     537  average[0].dR         = fit.dRo; // RA scatter in arcsec
     538  average[0].dD         = fit.dDo; // DEC scatter in arcsec
     539
     540  average[0].uR         = fit.uR; // RA proper motion in arcsec/year
     541  average[0].uD         = fit.uD; // DEC proper motion in arcsec/year
     542  average[0].duR        = fit.duR; // RA proper motion error in arcsec/year
     543  average[0].duD        = fit.duD; // DEC proper motion error in arcsec/year
     544
     545  average[0].P          = fit.p; // parallax in arcsec
     546  average[0].dP         = fit.dp; // parallax error in arcsec
     547
     548  average[0].ChiSqAve   = fitAve.chisq;
     549  average[0].ChiSqPM    = fitPM.chisq;
     550  average[0].ChiSqPar   = fitPAR.chisq;
     551
     552  average[0].Tmean      = (Tmean * 86400 * 365.25) + T2000;
     553  average[0].Trange     = (Trange * 86400 * 365.25);
     554  average[0].Npos       = fit.Nfit;
     555
     556  // unset the NO_ASTROM bit (not(NO_ASTROM) == HAVE_ASTROM)
     557  average[0].flags &= ~ID_STAR_NO_ASTROM;
     558
    542559  return (TRUE);
    543560}
  • trunk/Ohana/src/relastro/src/args.c

    r37038 r37807  
    265265    remove_argument (N, &argc, argv);
    266266    MaxDensityUse = TRUE;
     267  }
     268
     269  APPLY_OFFSETS = FALSE;
     270  if ((N = get_argument (argc, argv, "-apply-offsets"))) {
     271    remove_argument (N, &argc, argv);
     272    APPLY_OFFSETS = TRUE;
    267273  }
    268274
     
    372378  }
    373379
     380  CHIPMAP = 0;
     381  if ((N = get_argument (argc, argv, "-chipmap"))) {
     382    remove_argument (N, &argc, argv);
     383    CHIPMAP = atoi(argv[N]);
     384    remove_argument (N, &argc, argv);
     385
     386  }
     387
    374388  SAVEPLOT = FALSE;
    375389  PLOTSTUFF = FALSE;
     
    399413    RESET = TRUE;
    400414  }
    401 
    402415  RESET_BAD_IMAGES = FALSE;
    403416  if ((N = get_argument (argc, argv, "-reset-bad-images"))) {
    404417    remove_argument (N, &argc, argv);
    405418    RESET_BAD_IMAGES = TRUE;
     419  }
     420  RESET_IMAGES = FALSE;
     421  if ((N = get_argument (argc, argv, "-reset-images"))) {
     422    remove_argument (N, &argc, argv);
     423    RESET_IMAGES = TRUE;
    406424  }
    407425
     
    868886  fprintf (stderr, "  -high-speed (code[,code,code]) (code[,code,code]) (radius) (output catdir)\n");
    869887  fprintf (stderr, "  -hpm (radius) (output catdir)\n");
     888  fprintf (stderr, "  -chipmap (MaxOrder)\n");
    870889  fprintf (stderr, "  -merge-source (objID) (catID) into (objID) (catID)\n\n");
    871890
     
    880899  fprintf (stderr, "  -statmode (mode)\n");
    881900  fprintf (stderr, "  -reset\n");
     901  fprintf (stderr, "  -reset-images\n");
    882902  fprintf (stderr, "  -nloop (N) : number of image-fit iterations\n");
    883903  fprintf (stderr, "  -update : apply new fit to database\n");
  • trunk/Ohana/src/relastro/src/assign_images.c

    r36630 r37807  
    2323  BuildChipMatch (image, Nimage);
    2424  MARKTIME("build chip match for %d images: %f sec\n", (int) Nimage, dtime);
     25
     26  char mapfile[DVO_MAX_PATH];
     27  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     28  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, VERBOSE);
     29
     30  // assign images.coords.offsetMap -> table->map[i]
     31  if (table) {
     32    AstromOffsetTableMatchChips (image, Nimage, table);
     33  } else {
     34    table = AstromOffsetTableInit ();
     35  }
     36  put_astrom_table (table);
    2537
    2638  initMosaics (image, Nimage);
     
    89101    if (!strcmp(&image[j].coords.ctype[4], "-DIS")) continue;
    90102
    91     // match the image to its corresponding ASTROMETRIC mosaic (not the same as the Mosaic above)
    92     if (!FindMosaicForImage (image, Nimage, j)) {
    93       if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    94       continue;
    95     }
    96    
    97103    // Exclude images with crazy astrometry
    98104    // XXX NOTE : this is gpc1-specific
     
    150156
    151157    // this is a bit memory expensive : I am making a complete copy of the image table here
    152     off_t Nsubset = regionHosts->hosts[i].Nimage;
    153     regionHosts->hosts[i].image[Nsubset] = image[j];
    154     regionHosts->hosts[i].imseq[Nsubset] = j;
    155 
    156     regionHosts->hosts[i].Nimage ++;
    157     if (regionHosts->hosts[i].Nimage == regionHosts->hosts[i].NIMAGE) {
    158       regionHosts->hosts[i].NIMAGE += D_NIMAGE;
    159       REALLOCATE (regionHosts->hosts[i].image, Image, regionHosts->hosts[i].NIMAGE);
    160       REALLOCATE (regionHosts->hosts[i].imseq, off_t, regionHosts->hosts[i].NIMAGE);
     158    off_t Nsubset = host->Nimage;
     159    host->image[Nsubset] = image[j];
     160    host->imseq[Nsubset] = j;
     161
     162    host->Nimage ++;
     163    if (host->Nimage == host->NIMAGE) {
     164      host->NIMAGE += D_NIMAGE;
     165      REALLOCATE (host->image, Image, host->NIMAGE);
     166      REALLOCATE (host->imseq, off_t, host->NIMAGE);
     167    }
     168
     169    // save the astrometry maps, where they exist
     170    if (image[j].coords.offsetMap) {
     171      if (!host->astromTable) {
     172        host->astromTable = AstromOffsetTableInit();
     173      }
     174      AstromOffsetTableAddMapFromImage(host->astromTable, &image[j]);
    161175    }
    162176  }
     
    199213}
    200214
    201 int calculate_host_image_bounds (RegionHostTable *regionHosts) {
    202 
    203   int i, n;
    204   off_t j;
    205 
    206   for (i = 0; i < regionHosts->Nhosts; i++) {
    207 
    208     RegionHostInfo *host = &regionHosts->hosts[i];
    209 
    210     // XXX clear the chip match?
    211 
    212     BuildChipMatch (host->image, host->Nimage);
    213 
    214     double Rmin = 360.0;
    215     double Rmax =   0.0;
    216     double Dmin = +90.0;
    217     double Dmax = -90.0;
    218 
    219     for (j = 0; j < host->Nimage; j++) {
    220 
    221       Image *image = &host->image[j];
    222 
    223       if (!FindMosaicForImage (host->image, host->Nimage, j)) {
    224         fprintf (stderr, "missing astrometry? programming error?\n");
    225         abort ();
    226       }
    227      
    228       // define image corners
    229       for (n = 0; n < 4; n++) {
    230         double Xc, Yc, Rc, Dc;
    231         Xc = Xf[n]*image->NX;
    232         Yc = Yf[n]*image->NY;
    233         XY_to_RD (&Rc, &Dc, Xc, Yc, &image->coords);
    234         Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
    235      
    236         Rmin = MIN (Rmin, Rc);
    237         Dmin = MIN (Dmin, Rc);
    238        
    239         Rmax = MAX (Rmax, Rc);
    240         Dmax = MAX (Dmax, Rc);
    241       }
    242 
    243     }
    244 
    245     host->RminCat = Rmin;
    246     host->DminCat = Dmin;
    247     host->RmaxCat = Rmax;
    248     host->DmaxCat = Dmax;
    249 
    250     // regionHosts needs to have the full outer boundary
    251     // (so reload_catalogs covers the correct region)
    252     regionHosts->Rmin = MIN(Rmin, regionHosts->Rmin);
    253     regionHosts->Rmax = MAX(Rmax, regionHosts->Rmax);
    254     regionHosts->Dmin = MIN(Dmin, regionHosts->Dmin);
    255     regionHosts->Dmax = MAX(Dmax, regionHosts->Dmax);
    256   }
    257   return TRUE;
    258 }
    259 
    260 
    261215// XXX add a search tree to speed this up?
    262216int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc) {
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r36833 r37807  
    2727
    2828  /* for outlier rejection, project coordinates to a plane centered on the object with units of arcsec */
    29   coords.crval1 = 0;
    30   coords.crval2 = 0;
    31   coords.crpix1 = 0;
    32   coords.crpix2 = 0;
     29  InitCoords (&coords, "DEC--SIN");
    3330  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    34   coords.pc1_1  = coords.pc2_2 = 1.0;
    35   coords.pc1_2  = coords.pc2_1 = 0.0;
    36   coords.Npolyterms = 1;
    37   strcpy (coords.ctype, "DEC--SIN");
    3831
    3932  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
     
    7265    if (catalog[0].average[i].Nmeasure <= SRC_MEAS_TOOFEW) {
    7366      continue;
    74       // XXX can't (easily) count this for a given chip
    7567    }
    7668   
     
    8476    if (RESET) {
    8577      subcatalog[0].average[Naverage].flags &= ~averageBits;
     78    }
     79
     80    // if we want to do static correction to ICRF, keep the ICRF QSOs (regardless of other data quality)
     81    if (USE_ICRF_CORRECT && (subcatalog[0].average[Naverage].flags & ID_ICRF_QSO)) {
     82      Nm = 0;
     83      for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
     84         
     85        offset = catalog[0].average[i].measureOffset + j;
     86         
     87        CopyMeasureToTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
     88        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_ASTROM;
     89        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
     90        subcatalog[0].measureT[Nmeasure].averef   = Naverage;
     91        if (RESET) {
     92          subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     93          subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
     94        }
     95         
     96        Nmeasure ++;
     97        Nm ++;
     98        if (Nmeasure == NMEASURE) {
     99          NMEASURE += 1000;
     100          REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
     101        }
     102      }
     103      subcatalog[0].average[Naverage].Nmeasure = Nm;
     104      Naverage ++;
     105      if (Naverage == NAVERAGE) {
     106        NAVERAGE += 50;
     107        REALLOCATE (subcatalog[0].average, Average, NAVERAGE);
     108        REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
     109      }
     110      continue;
     111    }
     112
     113    // if we want to correct to the galay model, we need to use objects with distances determined by Green & Schlafly
     114    if (USE_GALAXY_MODEL && !catalog[0].average[i].Nstarpar) {
     115      // we may want to add some starpar quality filters...
     116      continue;
    86117    }
    87118
     
    116147      // exclude bogus
    117148      if (ExcludeBogus) {
    118           double Ri = getMeanR_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
    119           double Di = getMeanD_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
    120           coords.crval1 = catalog[0].average[i].R;
    121           coords.crval2 = catalog[0].average[i].D;
    122           double Xi, Yi;
    123           RD_to_XY (&Xi, &Yi, Ri, Di, &coords);
    124           double radius = hypot(Xi, Yi);
    125           if (radius > ExcludeBogusRadius) {
    126               NskipBogus ++;
    127               if (VERBOSE2) {
    128                 FILE *foutput = fbogus ? fbogus : stderr;
    129                 char *date = ohana_sec_to_date(catalog[0].measure[offset].t);
    130                 fprintf (foutput, "exclude bogus: %10.6f %10.6f : %10.6f %10.6f : %6.2f %6.2f : %6.2f : %5d %s\n", catalog[0].average[i].R, catalog[0].average[i].D, Ri, Di, Xi, Yi, radius, catalog[0].measure[offset].photcode, date);
    131                 free (date);
    132               }
    133               continue;
     149        double Ri = getMeanR_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     150        double Di = getMeanD_Big (&catalog[0].measure[offset], &catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt]);
     151        coords.crval1 = catalog[0].average[i].R;
     152        coords.crval2 = catalog[0].average[i].D;
     153        double Xi, Yi;
     154        RD_to_XY (&Xi, &Yi, Ri, Di, &coords);
     155        double radius = hypot(Xi, Yi);
     156        if (radius > ExcludeBogusRadius) {
     157          NskipBogus ++;
     158          if (VERBOSE2) {
     159            FILE *foutput = fbogus ? fbogus : stderr;
     160            char *date = ohana_sec_to_date(catalog[0].measure[offset].t);
     161            fprintf (foutput, "exclude bogus: %10.6f %10.6f : %10.6f %10.6f : %6.2f %6.2f : %6.2f : %5d %s\n", catalog[0].average[i].R, catalog[0].average[i].D, Ri, Di, Xi, Yi, radius, catalog[0].measure[offset].photcode, date);
     162            free (date);
    134163          }
     164          continue;
     165        }
    135166      }
    136167
     
    157188      subcatalog[0].measureT[Nmeasure].averef   = Naverage;
    158189      if (RESET) {
    159         subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    160         subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
     190        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_ASTROM;
     191        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
    161192      }
    162193
     
    164195      Nm ++;
    165196      if (Nmeasure == NMEASURE) {
    166         NMEASURE += 1000;
    167         REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
    168       }
     197        NMEASURE += 1000;
     198        REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
     199      }
     200    }
     201    // we have filtered this object.  do not keep it if we now have too few meas
     202    if (Nm <= SRC_MEAS_TOOFEW) {
     203      Nmeasure -= Nm;
     204      continue;
    169205    }
    170206    subcatalog[0].average[Naverage].Nmeasure = Nm;
     
    186222  assert (Nsecfilt == catalog[0].Nsecfilt);
    187223
    188   // limit the total number of stars in the catalog
     224// limit the total number of stars in the catalog
    189225  if (MaxDensityUse) {
    190226    LimitDensityCatalog_ByNmeasureGrid (subcatalog, catalog);
     
    217253
    218254# define SWAPFUNC(A,B){ int tmpI; off_t tmpT;   \
    219   tmpI = X[A]; X[A] = X[B]; X[B] = tmpI; \
    220   tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT; \
    221 }
     255    tmpI = X[A]; X[A] = X[B]; X[B] = tmpI;      \
     256    tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT;      \
     257  }
    222258# define COMPARE(A,B)(X[A] > X[B])
    223259
     
    231267/* generate a grid in a locally-projected coordinate system, try to select average entries
    232268   from each grid cell in decending Nmeasure order.
    233  */
     269*/
    234270int LimitDensityCatalog_ByNmeasureGrid (Catalog *subcatalog, Catalog *oldcatalog) {
    235271
     
    269305  /* project coordinates to a plane centered on the object with units of arcsec */
    270306  Coords coords;
     307  InitCoords (&coords, "DEC--SIN");
    271308  coords.crval1 = Rc;
    272309  coords.crval2 = Dc;
    273   coords.crpix1 = 0;
    274   coords.crpix2 = 0;
    275310  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    276   coords.pc1_1  = coords.pc2_2 = 1.0;
    277   coords.pc1_2  = coords.pc2_1 = 0.0;
    278   coords.Npolyterms = 1;
    279   strcpy (coords.ctype, "DEC--SIN");
    280311
    281312  // convert all average R,D values to X,Y:
  • trunk/Ohana/src/relastro/src/fitpoly.c

    r33652 r37807  
    7878}
    7979 
     80int array_print (double **matrix, int Nx, int Ny) {
     81
     82  int i, j;
     83  for (i = 0; i < Nx; i++) {
     84    for (j = 0; j < Ny; j++) {
     85      fprintf (stderr, "%10.3e ", matrix[i][j]);
     86    }
     87    fprintf (stderr, "\n");
     88  }
     89  return TRUE;
     90}
     91
     92int fit_print (CoordFit *fit) {
     93
     94  fprintf (stderr, "Npts: %d, Norder: %d, Nterms: %d, Nsums: %d, Nelems: %d\n",
     95           fit[0].Npts, fit[0].Norder, fit[0].Nterms, fit[0].Nsums, fit[0].Nelems);
     96
     97  fprintf (stderr, "sums: \n");
     98  array_print (fit[0].sum, fit[0].Nsums, fit[0].Nsums);
     99
     100  fprintf (stderr, "xsums: \n");
     101  array_print (fit[0].xsum, fit[0].Nterms, fit[0].Nterms);
     102
     103  fprintf (stderr, "ysums: \n");
     104  array_print (fit[0].ysum, fit[0].Nterms, fit[0].Nterms);
     105
     106  fprintf (stderr, "xfits: \n");
     107  array_print (fit[0].xfit, fit[0].Nterms, fit[0].Nterms);
     108
     109  fprintf (stderr, "yfits: \n");
     110  array_print (fit[0].yfit, fit[0].Nterms, fit[0].Nterms);
     111 
     112  return TRUE;
     113}
     114
    80115// XXX use implicit masks as below or explicit masks (with function to set?)
    81116// XXX eg, add a global mask to this file and
     
    134169      for (j = 0; j < fit[0].Nelems; j++) {
    135170        matrix[i][j] = 0.0;
     171        matrix[j][i] = 0.0;
    136172      }
    137173      vector[i][0] = 0.0;
     
    148184  }     
    149185 
    150   if (!dgaussjordan (matrix, vector, fit[0].Nelems, 2)) {
     186  if (!dgaussjordan_pivot (matrix, vector, fit[0].Nelems, 2, 1e-16)) {
    151187    array_free (matrix, fit[0].Nelems);
    152188    array_free (vector, fit[0].Nelems);
     
    277313/* this should only apply to the polynomial, not the projection terms */
    278314/* compare with psastro supporting code */
     315// this code will work for linear (Npolyterm == 0 or 1) and linear + map fits
    279316int fit_apply_coords (CoordFit *fit, Coords *coords, int keepRef) {
    280317
     
    352389  /* keep the order and type from initial values */
    353390 
     391  if (isnan(coords[0].crval1)) {
     392    return FALSE;
     393  }
     394  if (isnan(coords[0].crval2)) {
     395    return FALSE;
     396  }
     397  if (isnan(coords[0].crpix1)) {
     398    return FALSE;
     399  }
     400  if (isnan(coords[0].crpix2)) {
     401    return FALSE;
     402  }
     403
    354404  return (TRUE);
    355405}
  • trunk/Ohana/src/relastro/src/high_speed_objects.c

    r37038 r37807  
    149149
    150150  // define a local projection
     151  InitCoords (&tcoords, "DEC--ARC");
    151152  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    152153  if (region[0].Dmax < 90) {
     
    155156    tcoords.crval2 = 90.0;
    156157  }
    157   tcoords.crpix1 = 0;
    158   tcoords.crpix2 = 0;
    159158  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    160   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    161   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    162   tcoords.Npolyterms = 1;
    163   strcpy (tcoords.ctype, "DEC--ARC");
    164159
    165160  /* build spatial index (RA sort) referencing input array sequence */
     
    271266
    272267  populate_tiny_values (&catalogOut, DVO_TV_MEASURE);
    273   UpdateObjects (&catalogOut, 1);
     268  UpdateObjects (&catalogOut, 1, 0);
    274269  free_tiny_values(&catalogOut);
    275270
  • trunk/Ohana/src/relastro/src/high_speed_utils.c

    r33652 r37807  
    141141    off_t n;
    142142    for (n = 0; n < NfieldsA; n++) {
    143         valuesA[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], &fieldsA[n]);
     143      valuesA[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], NULL, NULL, &fieldsA[n]);
    144144    }
    145145    return dbBooleanCond(stackA, NstackA, valuesA);
     
    155155    off_t n;
    156156    for (n = 0; n < NfieldsB; n++) {
    157         valuesB[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], &fieldsB[n]);
     157        valuesB[n] = dbExtractAverages (&catalog[0].average[i], &catalog[0].secfilt[i*Nsecfilt], &catalog[0].measure[m], NULL, NULL, &fieldsB[n]);
    158158    }
    159159    return dbBooleanCond(stackB, NstackB, valuesB);
  • trunk/Ohana/src/relastro/src/hpm_objects.c

    r37038 r37807  
    126126
    127127  // define a local projection
     128  InitCoords (&tcoords, "DEC--ARC");
    128129  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
    129130  if (region[0].Dmax < 90) {
     
    132133    tcoords.crval2 = 90.0;
    133134  }
    134   tcoords.crpix1 = 0;
    135   tcoords.crpix2 = 0;
    136135  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    137   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    138   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    139   tcoords.Npolyterms = 1;
    140136  strcpy (tcoords.ctype, "DEC--ARC");
    141137
     
    256252    // distinguishing a bad fit from a fit with 1 or 2 bad points
    257253    FIT_MODE = FIT_PM_ONLY;
    258     UpdateObjects (&testcat, 1);
     254    UpdateObjects (&testcat, 1, 0);
    259255
    260256    free_tiny_values(&testcat);
     
    286282
    287283  populate_tiny_values (&catalogOut, DVO_TV_MEASURE);
    288   UpdateObjects (&catalogOut, 1);
     284  UpdateObjects (&catalogOut, 1, 0);
    289285  free_tiny_values(&catalogOut);
    290286
  • trunk/Ohana/src/relastro/src/initialize.c

    r37038 r37807  
    99
    1010  if (DCR_BLUE_COLOR_POS)  fprintf (stderr, "DCR_BLUE_COLOR_POS:  %s - %s\n", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    11   if (DCR_BLUE_COLOR_POS)  fprintf (stderr, "DCR_BLUE_COLOR_POS:  %s - %s\n", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     11  if (DCR_RED_COLOR_POS)   fprintf (stderr, "DCR_RED_COLOR_POS:   %s - %s\n", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    1212
    1313  if (PHOTCODE_KEEP_LIST)  fprintf (stderr, "PHOTCODE_KEEP_LIST:  %s\n", PHOTCODE_KEEP_LIST);
     
    6363  initstats (STATMODE);
    6464
     65  if (USE_ICRF_CORRECT) {
     66    if (!USE_ICRF_LOCAL && !USE_ICRF_SHFIT) {
     67      fprintf (stderr, "no ICRF correction method chosen\n");
     68      exit (2);
     69    }
     70  }
     71  if (USE_ICRF_CORRECT) ICRFinit();
     72
    6573  /* XXX drop irrelevant entries */
    6674  if (SHOW_PARAMS) {
  • trunk/Ohana/src/relastro/src/launch_region_hosts.c

    r37038 r37807  
    66  int i;
    77
    8   // clear the I/O files
    9   for (i = 0; i < regionHosts->Nhosts; i++) {
    10     char *syncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.sync");
    11     if (truncate (syncfile, 0)) fprintf (stderr, "trouble clearing syncfile %s\n", syncfile);
    12     free (syncfile);
     8  // do not remote the sync and fits files if we do a manual run -- user must clear if needed
     9  if (!PARALLEL_REGIONS_MANUAL) {
     10    // clear the I/O files
     11    for (i = 0; i < regionHosts->Nhosts; i++) {
     12      char *meansync = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanpos.sync");
     13      if (truncate (meansync, 0)) fprintf (stderr, "trouble clearing meansync %s\n", meansync);
     14      free (meansync);
    1315
    14     char *fitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.fits");
    15     if (truncate (fitsfile, 0)) fprintf (stderr, "trouble clearing fitsfile %s\n", fitsfile);
    16     free (fitsfile);
     16      char *meanfits = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanpos.fits");
     17      if (truncate (meanfits, 0)) fprintf (stderr, "trouble clearing meanfits %s\n", meanfits);
     18      free (meanfits);
    1719
    18     char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.sync");
    19     if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
    20     free (imsyncfile);
     20      char *meassync = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "measpos.sync");
     21      if (truncate (meassync, 0)) fprintf (stderr, "trouble clearing meassync %s\n", meassync);
     22      free (meassync);
    2123
    22     char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.fits");
    23     if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
    24     free (imfitsfile);
     24      char *measfits = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "measpos.fits");
     25      if (truncate (measfits, 0)) fprintf (stderr, "trouble clearing measfits %s\n", measfits);
     26      free (measfits);
    2527
    26     char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
    27     if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
    28     free (loopsyncfile);
     28      char *icrfsync = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "icrfobj.sync");
     29      if (truncate (icrfsync, 0)) fprintf (stderr, "trouble clearing icrfsync %s\n", icrfsync);
     30      free (icrfsync);
     31
     32      char *icrffits = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "icrfobj.fits");
     33      if (truncate (icrffits, 0)) fprintf (stderr, "trouble clearing icrffits %s\n", icrffits);
     34      free (icrffits);
     35
     36      char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagepos.sync");
     37      if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
     38      free (imsyncfile);
     39
     40      char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagepos.fits");
     41      if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
     42      free (imfitsfile);
     43
     44      char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
     45      if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
     46      free (loopsyncfile);
     47    }
     48
     49    char *framesync = make_filename (CATDIR, "master", 0, "frame.corr.sync");
     50    if (truncate (framesync, 0)) fprintf (stderr, "trouble clearing framesync %s\n", framesync);
     51    free (framesync);
     52 
     53    char *framefits = make_filename (CATDIR, "master", 0, "frame.corr.fits");
     54    if (truncate (framefits, 0)) fprintf (stderr, "trouble clearing framefits %s\n", framefits);
     55    free (framefits);
    2956  }
    3057
     
    3764    char filename[1024];
    3865    snprintf (filename, 1024, "%s/Image.%d.fits", CATDIR, host->hostID);
     66    if (unlink (filename)) fprintf (stderr, "trouble clearing image %s\n", filename);
    3967
    4068    // write the image subset for this host
    4169    ImageTableSave (filename, host->image, host->Nimage);
     70
     71    if (host->astromTable) {
     72      char mapname[1024];
     73      snprintf (mapname, 1024, "%s/AstroMap.%d.fits", CATDIR, host->hostID);
     74
     75      // write the image subset for this host
     76      AstromOffsetMapSave (host->astromTable, mapname);
     77    }
    4278
    4379    char command[1024];
     
    92128    if (PhotFlagPoor)       strextend (command, "+photflagpoor %d", PhotFlagPoor);
    93129
     130    if (CHIPMAP)            strextend (command, "-chipmap %d", CHIPMAP);
     131    if (RESET_IMAGES)       strextend (command, "-reset-images");
     132
    94133    if (MinBadQF > 0.0)        strextend (command, "-min-bad-psfqf %f", MinBadQF);
    95134    if (MaxMeanOffset != 10.0) strextend (command, "-max-mean-offset  %f", MaxMeanOffset);
     
    99138    strextend (command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
    100139    strextend (command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
     140
     141    strextend (command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
     142
     143    strextend (command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     144    strextend (command, "-D USE_ICRF_LOCAL %d",   USE_ICRF_LOCAL);
     145    strextend (command, "-D USE_ICRF_SHFIT %d",   USE_ICRF_SHFIT);
     146    strextend (command, "-D USE_ICRF_POLE %d",    USE_ICRF_POLE);
    101147
    102148    if (USE_FIXED_PIXCOORDS) strextend (command, "-D USE_FIXED_PIXCOORDS 1");
     
    133179  }
    134180
     181  if (USE_ICRF_CORRECT) return TRUE;
     182
     183  int status = HarvestRegionHosts (regionHosts);
     184  return status;
     185}
     186
     187int HarvestRegionHosts (RegionHostTable *regionHosts) {
     188
     189  int status = TRUE;
     190
    135191  if (PARALLEL_REGIONS_MANUAL) {
    136192    fprintf (stderr, "run the relastro_client commands above.  when these are done, hit return\n");
    137193    getchar();
    138194  } else {
    139     RegionHostTableWaitJobsGetIO (regionHosts, __FILE__, __LINE__, VERBOSE);
     195    status = RegionHostTableWaitJobsGetIO (regionHosts, __FILE__, __LINE__, VERBOSE);
    140196  }
    141  
    142   int status = TRUE;
    143   for (i = 0; i < regionHosts->Nhosts; i++) {
    144     status = status && (regionHosts->hosts[i].status == 0);
    145   }
    146 
    147197  return status;
    148198}
  • trunk/Ohana/src/relastro/src/liststats.c

    r34576 r37807  
    252252    X2 += M / dM;
    253253    dS += M;
    254     if (XVERB) fprintf (stderr, "chisq contrib : %f : %f : %f : %f : %f\n", Mo, 3600.0*(value[i] - Mo), 3600.0*dvalue[i], (value[i] - Mo) / dvalue[i], X2);
     254    if (XVERB) fprintf (stderr, "chisq contrib : %f : %f : %f : %f : %f\n", Mo, (value[i] - Mo), dvalue[i], (value[i] - Mo) / dvalue[i], X2);
    255255  }
    256256  X2 = X2 / (Nm - 1);
  • trunk/Ohana/src/relastro/src/load_catalogs.c

    r37038 r37807  
    66Catalog *load_catalogs (SkyList *skylist, int *Ncatalog, int subselect, int hostID, char *hostpath, char *syncfile) {
    77
    8   int i, j, Nstar;
     8  int i, j;
    99  // int k, m;
    1010  Catalog *catalog, *pcatalog, tcatalog;
     
    8888
    8989  bcatalog_show_skips();
    90 
    91   Nstar = 0;
     90  fprintf (stderr, "included %d ICRF QSOs\n", ICRFmax());
     91
     92  int Nstar = 0;
     93  int Nmeas = 0;
    9294  for (i = 0; i < Ncat; i++) {
    9395    Nstar += catalog[i].Naverage;
     96    Nmeas += catalog[i].Nmeasure;
    9497    if ((sizeof(IDX_T) == 8) && (catalog[i].Nmeasure > 0xffffffff)) {
    9598      fprintf (stderr, "ERROR: using small-sized IDX_T on data with more than 2G detections per table will cause errors\n");
     
    101104    fprintf (stderr, "warning: insufficient stars %d\n", Nstar);
    102105  }
     106  fprintf (stderr, "using %d stars, %d measurements to calibrate\n", Nstar, Nmeas);
    103107
    104108  // if we are running with parallel_images but not a parallel database, we need to
     
    170174    if (FlagOutlier)   strextend (command, "-clip %d", CLIP_THRESH);
    171175    if (ExcludeBogus)  strextend (command, "-exclude-bogus %f", ExcludeBogusRadius);
     176
     177    if (USE_ICRF_CORRECT) strextend (command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     178    if (USE_GALAXY_MODEL) strextend (command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
    172179   
    173180    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
  • trunk/Ohana/src/relastro/src/load_images.c

    r36630 r37807  
    11# include "relastro.h"
     2
     3static AstromOffsetTable *table = NULL;
     4
     5/* AstromOffsetMap is the map of Astrometry Offsets for non-polynomial astrometric
     6 * corrections for each chip. 
     7 */
    28
    39int load_images (FITS_DB *db, SkyList *skylist, int UseFullOverlap) {
     
    1723  MARKTIME("  convert image table: %f sec\n", dtime);
    1824
     25  // assign image->parent and image->coords.mosaic
     26  BuildChipMatch (image, Nimage);
     27  MARKTIME("build chip match: %f sec\n", dtime);
     28
     29  char mapfile[DVO_MAX_PATH];
     30  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     31  table = AstromOffsetMapLoad (mapfile, VERBOSE);
     32
     33  // assign images.coords.offsetMap -> table->map[i]
     34  if (table) {
     35    AstromOffsetTableMatchChips (image, Nimage, table);
     36  } else {
     37    table = AstromOffsetTableInit ();
     38  }
     39
    1940  // select the images which overlap the selected sky regions
    2041  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset, UseFullOverlap);
    2142  MARKTIME("  select images: %f sec\n", dtime);
     43
     44  if (Nsubset == Nimage) {
     45    free (subset);
     46    subset = image;
     47  }
    2248
    2349  initImages (subset, LineNumber, Nsubset);
     
    5177  return TRUE;
    5278}
     79
     80int save_astrom_table () {
     81
     82  char mapfile[DVO_MAX_PATH];
     83  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     84  AstromOffsetMapSave (table, mapfile);
     85
     86  return TRUE;
     87}
     88
     89AstromOffsetTable *get_astrom_table () {
     90  return table;
     91}
     92
     93void put_astrom_table (AstromOffsetTable *myTable) {
     94  table = myTable;
     95}
     96
  • trunk/Ohana/src/relastro/src/markObjects.c

    r37038 r37807  
    1414      int m = catalog[i].average[j].measureOffset;
    1515      for (n = 0; n < catalog[i].average[j].Nmeasure; n++) {
    16         if (!catalog[i].measureT[m+n].myDet) continue;
    17         nOwn ++;
     16        // this is a detection I own (it is on one of my images)
     17        if (catalog[i].measureT[m+n].myDet) {
     18          nOwn ++;
     19          continue;
     20        }
     21        // 2MASS detections are counted as 'owned' (I completely control this object is nOwn_t == Nmeasure; no sharing needed)
     22        if ((catalog[i].measureT[m+n].photcode == 2011) ||
     23            (catalog[i].measureT[m+n].photcode == 2012) ||
     24            (catalog[i].measureT[m+n].photcode == 2013)) {
     25          nOwn ++;
     26          continue;
     27        }
    1828      }
    1929      catalog[i].nOwn_t[j] = nOwn;
  • trunk/Ohana/src/relastro/src/relastroVisual.c

    r37038 r37807  
    2424/** Spawn a kapa window */
    2525static int initWindow(int *kapid) {
     26  if (NTHREADS) {
     27    fprintf (stderr, "-visual and -threads are incompatible, quitting\n");
     28    exit (2);
     29  }
    2630  if (*kapid == -1) {
    2731    *kapid = KapaOpenNamedSocket("kapa", "relastro_plots");
     
    348352
    349353  int i;
    350   for(i = 0; i < numObj; i++) {
     354  for (i = 0; i < numObj; i++) {
    351355    if (raw[i].mask) continue; // XXX
    352356
  • trunk/Ohana/src/relastro/src/relastro_client.c

    r36833 r37807  
    7979      load_images (&db, skylist, FALSE);
    8080     
     81      // I can free the database after I have loaded the images...
     82
    8183      // // load the image subset table from the specified location
    8284      // off_t Nimage;
  • trunk/Ohana/src/relastro/src/relastro_images.c

    r36833 r37807  
    2323  MARKTIME("load images: %f sec\n", dtime);
    2424
    25   initCoords();
    26 
    2725  /* load catalog data from region files : subselect high-quality measurements */
    28   // XXX pass in the image table
    29   // XXX who carries the image grid?
    3026
    3127  // photcodesKeep is used here to allow measurements from the images being calibrated
     
    3329  catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL, NULL);
    3430  MARKTIME("load catalog data: %f sec\n", dtime);
     31
     32  // find ICRF QSOs for reference downstream (only if USE_ICRF_CORRECT)
     33  select_catalog_ICRF (catalog, Ncatalog);
    3534
    3635  if (photcodesReset) {
     
    6564    case TARGET_SIMPLE:
    6665      for (i = 0; i < NLOOP; i++) {
    67         UpdateObjects (catalog, Ncatalog);
     66        UpdateObjects (catalog, Ncatalog, i);
    6867        UpdateSimple (catalog, Ncatalog);
    6968      }
     
    7170
    7271    case TARGET_CHIPS:
     72      if (RESET_IMAGES) UpdateMeasures (catalog, Ncatalog);
    7373      for (i = 0; i < NLOOP; i++) {
    74         UpdateObjects (catalog, Ncatalog);
    75         UpdateChips (catalog, Ncatalog);
     74        UpdateObjects (catalog, Ncatalog, (i > 0)); // calculate <R>,<D>; if (i > 0), apply Galaxy Motion Model (if desired)
     75        if ((i > 1) || !USE_GALAXY_MODEL) {
     76          // if GALAXY_MODEL is selected, we want to delay the frame correction until we have
     77          // applied the galaxy model a couple of times.
     78          FrameCorrectionSerial (catalog, Ncatalog);
     79        }
     80        UpdateChips (catalog, Ncatalog);   // measure.X,Y -> R,D, fit image.coords
    7681        MARKTIME("update chips: %f sec\n", dtime);
    7782      }
     
    8287    case TARGET_MOSAICS:
    8388      for (i = 0; i < NLOOP; i++) {
    84         UpdateObjects (catalog, Ncatalog);
     89        UpdateObjects (catalog, Ncatalog, i);
    8590        UpdateMosaic (catalog, Ncatalog);
    8691      }
     
    102107  if (PARALLEL) {
    103108    // save the updated image parameters
     109    // need to also save the image map table...
     110    save_astrom_table ();
    104111    dvo_image_update (&db, VERBOSE);
    105112    dvo_image_unlock (&db);
     
    109116  UpdateObjectOffsets (skylist, 0, NULL);
    110117
    111   // iterate over catalogs to make detection coordinates consistant
    112   // FixProblemImages (skylist);
    113 
    114118  if (!PARALLEL) {
    115119    // save the updated image parameters
     120    save_astrom_table ();
    116121    dvo_image_update (&db, VERBOSE);
    117122    dvo_image_unlock (&db);
  • trunk/Ohana/src/relastro/src/relastro_objects.c

    r36833 r37807  
    7777    populate_tiny_values(&catalog, DVO_TV_MEASURE);
    7878
    79     UpdateObjects (&catalog, 1);
     79    UpdateObjects (&catalog, 1, 0);
    8080
    8181    free_tiny_values(&catalog);
  • trunk/Ohana/src/relastro/src/relastro_parallel_images.c

    r36833 r37807  
    1717  INITTIME;
    1818
     19  client_logger_init (CATDIR);
     20
    1921  // load the RegionTable (UserRegion should not be used at this level)
    2022  RegionHostTable *regionHosts = RegionHostTableLoad (CATDIR, REGION_FILE);
    2123  int myHost = regionHosts->index[REGION_HOST_ID];
    2224  RegionHostFindNeighbors (regionHosts, myHost);
     25  client_logger_message ("started parallel images on %s\n", regionHosts->hosts[myHost].hostname);
    2326
    2427  // load the subset images belonging to this host
     
    2932    exit (2);
    3033  }
     34
     35  // assign image->parent and image->coords.mosaic
     36  BuildChipMatch (image, Nimage);
     37
     38  char mapfile[DVO_MAX_PATH];
     39  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.%d.fits", CATDIR, REGION_HOST_ID);
     40  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, VERBOSE);
     41
     42  // assign images.coords.offsetMap -> table->map[i]
     43  if (table) {
     44    AstromOffsetTableMatchChips (image, Nimage, table);
     45  } else {
     46    table = AstromOffsetTableInit ();
     47  }
     48  put_astrom_table (table);
     49  client_logger_message ("loaded images on %s\n", regionHosts->hosts[myHost].hostname);
    3150
    3251  // once we have read this table, we should remove it for repeat runs
     
    4261  SkyList *skylist = SkyListByBounds (sky, -1, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    4362
    44   initCoords();
    45 
    4663  /* load catalog data from region files (hostID is 0 since we are not a client */
    4764  char *syncfile = make_filename (CATDIR, regionHosts->hosts[myHost].hostname, REGION_HOST_ID, "loadcat.sync");
    4865  catalog = load_catalogs (skylist, &Ncatalog, TRUE, 0, NULL, syncfile);
    49   MARKTIME("-- load catalog data: %f sec\n", dtime);
     66  MARKTIME("-- load catalog data, host %d: %f sec\n", REGION_HOST_ID, dtime);
    5067  free (syncfile);
    5168 
     69  client_logger_message ("loaded catalog data %s\n", regionHosts->hosts[myHost].hostname);
     70
     71  // find ICRF QSOs for reference downstream (only if USE_ICRF_CORRECT)
     72  select_catalog_ICRF (catalog, Ncatalog);
     73
    5274  if (photcodesReset) {
    5375    photcodesKeep  = photcodesReset;
     
    6082  /* match measurements with images, mosaics */
    6183  initImageBins  (catalog, Ncatalog, TRUE);
    62   MARKTIME("-- make image bins: %f sec\n", dtime);
     84  MARKTIME("-- make image bins, host %d: %f sec\n", REGION_HOST_ID, dtime);
    6385
    6486  findImages (catalog, Ncatalog, TRUE);
    65   MARKTIME("-- set up image indexes: %f sec\n", dtime);
     87  MARKTIME("-- set up image indexes, host %d: %f sec\n", REGION_HOST_ID, dtime);
    6688
    6789  // set test points based on the starmap
    6890  createStarMap (catalog, Ncatalog);
     91
     92  client_logger_message ("set up image indexes on %s\n", regionHosts->hosts[myHost].hostname);
    6993
    7094  markObjects (catalog, Ncatalog);
     
    7296  SAVEPLOT = FALSE;
    7397
     98  client_logger_message ("starting the loops: %s\n", regionHosts->hosts[myHost].hostname);
     99
    74100  /* major modes */
    75101  switch (FIT_TARGET) {
    76102    case TARGET_SIMPLE:
    77103      for (i = 0; i < NLOOP; i++) {
    78         UpdateObjects (catalog, Ncatalog);
     104        UpdateObjects (catalog, Ncatalog, i);
    79105        share_mean_pos (catalog, Ncatalog, regionHosts, i);
    80106        slurp_mean_pos (catalog, Ncatalog, regionHosts, i);
    81107        UpdateSimple (catalog, Ncatalog);
    82108        share_image_pos (regionHosts, i);
    83         slurp_image_pos (regionHosts, i);
     109        slurp_image_pos (catalog, Ncatalog, regionHosts, i);
    84110      }
    85111      break;
    86112
    87113    case TARGET_CHIPS:
     114      if (RESET_IMAGES) {
     115        UpdateMeasures (catalog, Ncatalog);
     116        MARKTIME("reset measures, host %d: %f sec\n", REGION_HOST_ID, dtime);
     117        client_logger_message ("reset measures: %s\n", regionHosts->hosts[myHost].hostname);
     118      }
    88119      for (i = 0; i < NLOOP; i++) {
    89         UpdateObjects (catalog, Ncatalog);
     120        UpdateObjects (catalog, Ncatalog, (i > 0));
     121        MARKTIME("update objects loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     122        client_logger_message ("update objects loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     123        if ((i > 1) || !USE_GALAXY_MODEL) {
     124          // if GALAXY_MODEL is selected, we want to delay the frame correction until we have
     125          // applied the galaxy model a couple of times.
     126          FrameCorrectionParallelSlave (catalog, Ncatalog, regionHosts, i);
     127          MARKTIME("frame correction loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     128          client_logger_message ("frame correction loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     129        }
    90130        share_mean_pos (catalog, Ncatalog, regionHosts, i);
    91131        slurp_mean_pos (catalog, Ncatalog, regionHosts, i);
     132        client_logger_message ("slurp mags loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     133
    92134        UpdateChips (catalog, Ncatalog);
     135        MARKTIME("update chips loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     136        client_logger_message ("update chips loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     137
    93138        share_image_pos (regionHosts, i);
    94         slurp_image_pos (regionHosts, i);
    95         MARKTIME("update chips: %f sec\n", dtime);
     139        slurp_image_pos (catalog, Ncatalog, regionHosts, i);
     140        client_logger_message ("slurp image pos loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
     141
     142        share_meas_pos (catalog, Ncatalog, regionHosts, i);
     143        slurp_meas_pos (catalog, Ncatalog, regionHosts, i);
     144        MARKTIME("done exchange loop %d, host %d: %f sec\n", i, REGION_HOST_ID, dtime);
     145        client_logger_message ("slurp meas loop %d: %s\n", i, regionHosts->hosts[myHost].hostname);
    96146      }
    97147      // create summary plots of the process
     
    101151    case TARGET_MOSAICS:
    102152      for (i = 0; i < NLOOP; i++) {
    103         UpdateObjects (catalog, Ncatalog);
     153        UpdateObjects (catalog, Ncatalog, i);
    104154        share_mean_pos (catalog, Ncatalog, regionHosts, i);
    105155        slurp_mean_pos (catalog, Ncatalog, regionHosts, i);
    106156        UpdateMosaic (catalog, Ncatalog);
    107157        share_image_pos (regionHosts, i);
    108         slurp_image_pos (regionHosts, i);
     158        slurp_image_pos (catalog, Ncatalog, regionHosts, i);
    109159      }
    110160      break;
     
    128178
    129179  share_image_pos (regionHosts, -1);
     180  client_logger_message ("share image pos loop %d: %s\n", -1, regionHosts->hosts[myHost].hostname);
    130181
    131182  exit (0);
  • trunk/Ohana/src/relastro/src/relastro_parallel_regions.c

    r36630 r37807  
    4444  if (!launch_region_hosts (regionHosts)) Shutdown ("error launching region hosts");
    4545
     46  // If we are doing FrameCorrection, we have to loop here waiting for ICRF objects from the region
     47  // hosts.  we then measure the frame correction and send back the result
     48  if (!FrameCorrectionParallelMaster (regionHosts)) Shutdown ("error running parallel frame correction");
     49
    4650  // retrieve updated image parameters from the remote hosts (also set Image.mcal)
    47   if (!slurp_image_pos (regionHosts, -1)) Shutdown ("error loading image updates");
     51  if (!slurp_image_pos (NULL, 0, regionHosts, -1)) Shutdown ("error loading image updates");
    4852
    4953  if (!UPDATE) {
     
    5963
    6064  if (PARALLEL) {
    61     // save the updated image parameters
     65    // save the updated image parameters.  if we are NOT PARALLEL, we have to wait
     66    // until after UpdateObjectOffsets, or the image parameters are swapped and/or freed
     67    save_astrom_table ();
    6268    dvo_image_save (&db, VERBOSE);
    6369    dvo_image_unlock (&db);
     
    6571
    6672  // iterate over catalogs to make detection coordinates consistant
    67   UpdateObjectOffsets (skylist, 0, NULL);
     73  if (APPLY_OFFSETS) {
     74    UpdateObjectOffsets (skylist, 0, NULL);
     75  }
    6876
    6977  if (!PARALLEL) {
    7078    // save the changes to the image parameters
     79    save_astrom_table ();
    7180    dvo_image_save (&db, VERBOSE);
    7281    dvo_image_unlock (&db);
  • trunk/Ohana/src/relastro/src/select_images.c

    r36630 r37807  
    2323  int InRange, found;
    2424  double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
    25   Coords tcoords;
    2625  SkyRegionCoords *skycoords;
    2726 
     
    4645
    4746  // the comparison is made in the catalog local projection. below we set crval1,2
    48   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     47  Coords tcoords;
     48  InitCoords (&tcoords, "DEC--TAN");
    4949  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    50   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    51   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    52   strcpy (tcoords.ctype, "DEC--TAN");
    5350
    5451  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     
    104101
    105102  if (VERBOSE) fprintf (stderr, "finding images\n");
    106   BuildChipMatch (timage, Ntimage);
    107   MARKTIME("build chip match: %f sec\n", dtime);
    108103
    109104  nimage = 0;
     
    148143    }
    149144   
    150     // this adds 1.3 sec for 3M images
    151     if (!FindMosaicForImage (timage, Ntimage, i)) {
    152       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    153       continue;
    154     }
    155 
    156145    /* define image corners - note the DIS images (mosaic phu) are special */
    157146    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
  • trunk/Ohana/src/relastro/src/share_images_pos.c

    r36630 r37807  
    3434  free (iposfile);
    3535
     36  // save the per-chip residual table
     37  AstromOffsetTable *table = get_astrom_table ();
     38  if (table) {
     39    char mapname[1024];
     40    snprintf (mapname, 1024, "%s/AstroMapUpdate.%d.fits", CATDIR, REGION_HOST_ID);
     41   
     42    // write the image subset for this host
     43    AstromOffsetMapSave (table, mapname);
     44  }
     45
    3646  char *syncfile = make_filename (CATDIR, hostname, REGION_HOST_ID, "imagepos.sync");
    3747  update_sync_file (syncfile, nloop);
     
    4151}
    4252
    43 int slurp_image_pos (RegionHostTable *regionHosts, int nloop) {
     53int slurp_image_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop) {
    4454
    45   off_t Nimage, i;
     55  off_t Nimage, i, j;
    4656  Image *images = getimages (&Nimage, NULL);
    4757
     
    7484      continue;
    7585    }
     86    Coords *moscoords = images[seq].coords.mosaic;
    7687    images[seq].coords     = image_pos[i].coords    ;
    77     images[seq].dXpixSys   = image_pos[i].dXpixSys  ;
    78     images[seq].dYpixSys   = image_pos[i].dYpixSys  ;
    79     images[seq].imageID    = image_pos[i].imageID   ;
    80     images[seq].nFitAstrom = image_pos[i].nFitAstrom;
    81     images[seq].flags      = image_pos[i].flags     ;
     88    images[seq].coords.mosaic = moscoords;
     89
     90    images[seq].dXpixSys     = image_pos[i].dXpixSys  ;
     91    images[seq].dYpixSys     = image_pos[i].dYpixSys  ;
     92    images[seq].refColorBlue = image_pos[i].refColorBlue;
     93    images[seq].refColorRed  = image_pos[i].refColorRed;
     94    images[seq].imageID      = image_pos[i].imageID   ;
     95    images[seq].nFitAstrom   = image_pos[i].nFitAstrom;
     96    images[seq].flags        = image_pos[i].flags     ;
     97  }
     98
     99  // load the astrometry offset maps, if they exist, and apply
     100  for (i = 0; i < regionHosts->Nhosts; i++) {
     101    if (regionHosts->hosts[i].hostID == REGION_HOST_ID) continue;
     102    if (REGION_HOST_ID && !regionHosts->hosts[i].isNeighbor) continue;
     103
     104    char mapname[1024];
     105    snprintf (mapname, 1024, "%s/AstroMapUpdate.%d.fits", CATDIR, regionHosts->hosts[i].hostID);
     106   
     107    AstromOffsetTable *table = AstromOffsetMapLoad (mapname, VERBOSE);
     108 
     109    // apply table entries here to existing images
     110    for (j = 0; j < table->Nmap; j++) {
     111      off_t seq = getImageByID (table->map[j][0].imageID);
     112      // I do not necessarily own all images listed in the table.  skip if not found
     113      if (seq < 0) continue;
     114
     115      AstromOffsetMap *oldMap = images[seq].coords.offsetMap;
     116      AstromOffsetMap *newMap = table->map[j];
     117
     118      if (oldMap) {
     119        AstromOffsetMapSetOrder (oldMap, newMap->Nx, newMap->Ny, &images[seq]);
     120        AstromOffsetMapCopyData (oldMap, newMap);
     121      } else {
     122        lockUpdateChips ();
     123        AstromOffsetTable *FullTable = get_astrom_table ();
     124        AstromOffsetTableNewMap(FullTable, newMap->Nx, newMap->Ny, &images[seq]);  // registers the map with the image
     125        unlockUpdateChips ();
     126        AstromOffsetMapCopyData (images[seq].coords.offsetMap, newMap); // oldMap is now not valid
     127      }
     128    }
     129    AstromOffsetTableFree(table);
     130  }
     131
     132  // apply the modified image parameters to my detections
     133  for (i = 0; FALSE && (Ncatalog > 0) && (i < Nimage_pos); i++) {
     134    off_t seq = getImageByID (image_pos[i].imageID);
     135    if (seq < 0) continue;
     136    updateImageRaw (catalog, Ncatalog, seq);
    82137  }
    83138  free (image_pos);
     
    93148  image_pos->dXpixSys     = image->dXpixSys;
    94149  image_pos->dYpixSys     = image->dYpixSys;
     150  image_pos->refColorBlue = image->refColorBlue;
     151  image_pos->refColorRed  = image->refColorRed;
    95152  image_pos->imageID      = image->imageID;
    96153  image_pos->nFitAstrom   = image->nFitAstrom;
  • trunk/Ohana/src/relastro/src/testparallax.c

    r36482 r37807  
    4949
    5050  /* project coordinates to a plane centered on the object with units of arcsec */
    51   coords.crval1 = 0;
    52   coords.crval2 = 0;
    53   coords.crpix1 = 0;
    54   coords.crpix2 = 0;
     51  InitCoords (&coords, "DEC--SIN");
    5552  coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
    56   coords.pc1_1  = coords.pc2_2 = 1.0;
    57   coords.pc1_2  = coords.pc2_1 = 0.0;
    58   coords.Npolyterms = 1;
    59   strcpy (coords.ctype, "DEC--SIN");
    6053
    6154  // use one point as a local reference
  • trunk/Ohana/src/relphot/include/relphot.h

    r37116 r37807  
    452452int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt);
    453453int setMrelAverageExposure (off_t meas, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found);
    454 int setMrelAverageStack (off_t meas, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure);
     454int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t Nmeasure);
     455int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found, off_t Nmeasure);
     456
    455457int setGlobalObjStats (Average *average, Measure *measure);
    456458
  • trunk/Ohana/src/relphot/src/BoundaryTreeOps.c

    r36491 r37807  
    5151  if (!tess) return FALSE;
    5252
    53   status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, ra, dec);
     53  double R = ohana_normalize_angle(ra);
     54  status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, R, dec);
    5455  return status;
    5556}
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r37116 r37807  
    3535static off_t        *imageIdx; // list of index for image IDs
    3636
     37// QQ // as an alternative, we generate imageSeq, which directly maps imageID -> seq
     38// QQ static off_t        *imageSeq; // list of index for image IDs
     39// QQ
     40// QQ // MAX_ID requires 512M to store the image index
     41// QQ # define MAX_ID 0x8000000
     42// QQ static off_t         minImageID = MAX_ID;
     43// QQ static off_t         maxImageID = 0;
     44
    3745// elsewhere, we have loaded a set of catalogs with measures (catalog[cat].measure[meas])
    3846// each image has N_onImage[ImageIndex] measurements
     
    95103
    96104    TessellationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
     105
     106    // QQ minImageID = MIN(minImageID, image[i].imageID);
     107    // QQ maxImageID = MAX(maxImageID, image[i].imageID);
     108    // QQ myAssert (image[i].imageID < MAX_ID, "image IDs too large for index memory");
    97109  }
    98110
     
    100112  // XXX does this break the imageID <-> projectID, etc match?
    101113  llsortpair (imageIDs, imageIdx, Nimage);
     114
     115  // QQ ALLOCATE (imageSeq, off_t, maxImageID + 1);
     116  // QQ for (i = 0; i < maxImageID + 1; i++)  {
     117  // QQ   imageSeq[i] = -1; // not yet assigned
     118  // QQ }
     119  // QQ
     120  // QQ for (i = 0; i < Nimage; i++) {
     121  // QQ   off_t N = image[i].imageID;
     122  // QQ   myAssert (imageSeq[N] == -1, "previously assigned");
     123  // QQ   imageSeq[N] = i;
     124  // QQ }
    102125}
    103126
     
    167190
    168191off_t getImageByID (off_t ID) {
     192
     193  // QQ  if (imageSeq) {
     194  // QQ    myAssert (ID >= minImageID, "oops");
     195  // QQ    myAssert (ID <= maxImageID, "oops");
     196  // QQ    off_t N = imageSeq[ID];
     197  // QQ    return N;
     198  // QQ  }
    169199
    170200  // we have a pair of vectors (imageIDs, imageIdx) sorted by imageIDs
  • trunk/Ohana/src/relphot/src/ImageTable.c

    r36630 r37807  
    3232  }
    3333
     34  // XXX do not make the chip match -- we have not loaded the PHU entries (and do not need them here)
     35  // BuildChipMatch (image, Nimage);
     36
    3437  *nimage = Nimage;
    3538  return image;
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r37037 r37807  
    520520      m = MosaicToImage[i][j];
    521521
    522       if (!FindMosaicForImage (image, Nimage, m)) {
    523         if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    524         continue;
    525       }
    526 
    527522      NX = image[m].NX;
    528523      NY = image[m].NY;
    529       XY_to_RD (&R, &D, 0.5*NX, 0.5*NY, &image[m].coords);
     524      if (!XY_to_RD (&R, &D, 0.5*NX, 0.5*NY, &image[m].coords)) continue;
    530525      R = ohana_normalize_angle_to_midpoint (R, 180.0);
    531526
     
    587582    }
    588583
    589     strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     584    InitCoords (&mosaic[i].coords, "DEC--TAN");
    590585    mosaic[i].coords.crval1 = Rmid;
    591586    mosaic[i].coords.crval2 = Dmid;
    592     mosaic[i].coords.crpix1 = 0.0;
    593     mosaic[i].coords.crpix2 = 0.0;
    594587    mosaic[i].coords.cdelt1 = 1.0 / 3600.0;
    595588    mosaic[i].coords.cdelt2 = 1.0 / 3600.0;
    596     mosaic[i].coords.pc1_1  = 1.0;
    597     mosaic[i].coords.pc2_2  = 1.0;
    598     mosaic[i].coords.pc1_2  = 0.0;
    599     mosaic[i].coords.pc2_1  = 0.0;
    600589
    601590    mosaic[i].Mcal   = 0.0;
     
    631620      NY = image[m].NY;
    632621      dS += hypot (image[m].coords.cdelt1*image[m].coords.pc1_1, image[m].coords.cdelt1*image[m].coords.pc2_1);
    633       XY_to_RD (&R, &D, 0.0, 0.0, &image[m].coords);
     622
     623      OhanaProjection proj = GetProjection (image[m].coords.ctype);
     624      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     625        XY_to_LM (&R, &D, 0.0, 0.0, &image[m].coords);
     626      } else {
     627        XY_to_RD (&R, &D, 0.0, 0.0, &image[m].coords);
     628      }
    634629      Rmin = MIN (Rmin, R);
    635630      Rmax = MAX (Rmax, R);
    636631      Dmin = MIN (Dmin, D);
    637632      Dmax = MAX (Dmax, D);
    638       XY_to_RD (&R, &D, (double) NX, 0.0, &image[m].coords);
     633
     634      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     635        XY_to_LM (&R, &D, (double) NX, 0.0, &image[m].coords);
     636      } else {
     637        XY_to_RD (&R, &D, (double) NX, 0.0, &image[m].coords);
     638      }
    639639      Rmin = MIN (Rmin, R);
    640640      Rmax = MAX (Rmax, R);
    641641      Dmin = MIN (Dmin, D);
    642642      Dmax = MAX (Dmax, D);
    643       XY_to_RD (&R, &D, (double) NX, (double) NY, &image[m].coords);
     643
     644      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     645        XY_to_LM (&R, &D, (double) NX, (double) NY, &image[m].coords);
     646      } else {
     647        XY_to_RD (&R, &D, (double) NX, (double) NY, &image[m].coords);
     648      }
    644649      Rmin = MIN (Rmin, R);
    645650      Rmax = MAX (Rmax, R);
    646651      Dmin = MIN (Dmin, D);
    647652      Dmax = MAX (Dmax, D);
    648       XY_to_RD (&R, &D, 0.0, (double) NY, &image[m].coords);
     653
     654      if ((proj == PROJ_WRP) && !image[m].coords.mosaic) {
     655        XY_to_LM (&R, &D, 0.0, (double) NY, &image[m].coords);
     656      } else {
     657        XY_to_RD (&R, &D, 0.0, (double) NY, &image[m].coords);
     658      }
    649659      Rmin = MIN (Rmin, R);
    650660      Rmax = MAX (Rmax, R);
     
    652662      Dmax = MAX (Dmax, D);
    653663
     664      // XXX : this probably does not handle mosaics at RA = 0,360 well
     665
    654666      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
    655667
     
    668680    }
    669681    dS /= MosaicN_Image[i];
    670     strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     682
     683    InitCoords (&mosaic[i].coords, "DEC--TAN");
    671684    mosaic[i].coords.crval1 = Rmin;
    672685    mosaic[i].coords.crval2 = Dmin;
    673     mosaic[i].coords.crpix1 = 0.0;
    674     mosaic[i].coords.crpix2 = 0.0;
    675686    mosaic[i].coords.cdelt1 = dS;
    676687    mosaic[i].coords.cdelt2 = dS;
    677     mosaic[i].coords.pc1_1  = 1.0;
    678     mosaic[i].coords.pc2_2  = 1.0;
    679     mosaic[i].coords.pc1_2  = 0.0;
    680     mosaic[i].coords.pc2_1  = 0.0;
     688
    681689    RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
    682690
  • trunk/Ohana/src/relphot/src/assign_images.c

    r37037 r37807  
    8080    if (!strcmp(&image[j].coords.ctype[4], "-DIS")) continue;
    8181
    82     // match the image to its corresponding ASTROMETRIC mosaic (not the same as the Mosaic above)
    83     if (!FindMosaicForImage (image, Nimage, j)) {
    84       if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    85       continue;
    86     }
    87    
    8882    // Exclude images with crazy astrometry
    8983    // XXX NOTE : this is gpc1-specific
     
    123117
    124118    if (MOSAIC_ZEROPT) {
    125       // use the coords of the associated mosaic to select
     119      // use the coords of the associated mosaic to select (only for chips; stacks use their own center)
    126120      Mosaic *mosaic = getMosaicForImage (j);
    127       Rc = mosaic->coords.crval1;
    128       Dc = mosaic->coords.crval2;
    129       // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the
    130       // chips are located.  but, for host assignment, we rationalize to 0.0 - 360.0
    131       Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
     121      if (mosaic) {
     122        Rc = mosaic->coords.crval1;
     123        Dc = mosaic->coords.crval2;
     124        // NOTE : have defined mosaic Rc,Dc to choose the side of 0,360 on which most of the
     125        // chips are located.  but, for host assignment, we rationalize to 0.0 - 360.0
     126        Rc = ohana_normalize_angle_to_midpoint (Rc, 180.0);
     127      }
    132128    }
    133129
     
    206202}
    207203
    208 int calculate_host_image_bounds (RegionHostTable *regionHosts, double Rmid) {
    209 
    210   int i, n;
    211   off_t j;
    212 
    213   for (i = 0; i < regionHosts->Nhosts; i++) {
    214 
    215     RegionHostInfo *host = &regionHosts->hosts[i];
    216 
    217     // XXX clear the chip match?
    218 
    219     BuildChipMatch (host->image, host->Nimage);
    220 
    221     double Rmin =  720.0;
    222     double Rmax = -360.0;
    223     double Dmin =  +90.0;
    224     double Dmax = -90.0;
    225 
    226     for (j = 0; j < host->Nimage; j++) {
    227 
    228       Image *image = &host->image[j];
    229 
    230       if (!FindMosaicForImage (host->image, host->Nimage, j)) {
    231         fprintf (stderr, "missing astrometry? programming error?\n");
    232         abort ();
    233       }
    234      
    235       // define image corners
    236       for (n = 0; n < 4; n++) {
    237         double Xc, Yc, Rc, Dc;
    238         Xc = Xf[n]*image->NX;
    239         Yc = Yf[n]*image->NY;
    240         XY_to_RD (&Rc, &Dc, Xc, Yc, &image->coords);
    241         Rc = ohana_normalize_angle_to_midpoint (Rc, Rmid);
    242      
    243         Rmin = MIN (Rmin, Rc);
    244         Dmin = MIN (Dmin, Rc);
    245        
    246         Rmax = MAX (Rmax, Rc);
    247         Dmax = MAX (Dmax, Rc);
    248       }
    249 
    250     }
    251 
    252     // RminCat, RmaxCat may extended beyond 0.0 - 360.0
    253     host->RminCat = Rmin;
    254     host->DminCat = Dmin;
    255     host->RmaxCat = Rmax;
    256     host->DmaxCat = Dmax;
    257 
    258     // regionHosts needs to have the full outer boundary
    259     // (so reload_catalogs covers the correct region)
    260     regionHosts->Rmin = MIN(Rmin, regionHosts->Rmin);
    261     regionHosts->Rmax = MAX(Rmax, regionHosts->Rmax);
    262     regionHosts->Dmin = MIN(Dmin, regionHosts->Dmin);
    263     regionHosts->Dmax = MAX(Dmax, regionHosts->Dmax);
    264   }
    265   return TRUE;
    266 }
    267 
    268 
    269204// Rc is in range 0.0 - 360.0, hosts Rmin,Rmax in range 0.0 - 360.0
    270205int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc) {
  • trunk/Ohana/src/relphot/src/load_images.c

    r35759 r37807  
    2727  }
    2828  MARKTIME("read image table: %f sec\n", dtime);
     29
     30  BuildChipMatch (image, Nimage);
     31  MARKTIME("build chip match for %d images: %f sec\n", (int) Nimage, dtime);
     32
     33  char mapfile[DVO_MAX_PATH];
     34  snprintf (mapfile, DVO_MAX_PATH, "%s/AstroMap.fits", CATDIR);
     35  AstromOffsetTable *table = AstromOffsetMapLoad (mapfile, VERBOSE);
     36
     37  // assign images.coords.offsetMap -> table->map[i]
     38  if (table) {
     39    AstromOffsetTableMatchChips (image, Nimage, table);
     40  }
    2941
    3042  // allocate and init an array to identify the images included in the subset
  • trunk/Ohana/src/relphot/src/reload_catalogs.c

    r36630 r37807  
    128128}
    129129
     130int reload_catalog_parallel_group (HostTableGroup *group, SkyList *sky, char *imageFile);
     131
    130132// XXX Image to Image Subset
    131133int reload_catalogs_parallel (SkyList *sky) {
     
    165167    free (BOUNDARY_TREE);
    166168    BOUNDARY_TREE = tmppath;
    167    
    168   }
     169  }
     170
     171  int Ngroups;
     172  HostTableGroup *groups = HostTableGroups (table, &Ngroups);
     173  // split the table into Ngroups, each with a unique set of machines (this avoids overloading the remote host machines)
     174
     175  int i;
     176  for (i = 0; i < Ngroups; i++) {
     177    // update only a group of unique machines at a time
     178    reload_catalog_parallel_group (&groups[i], sky, imageFile);
     179  }
     180  return TRUE;
     181}
     182
     183int reload_catalog_parallel_group (HostTableGroup *group, SkyList *sky, char *imageFile) {
    169184
    170185  int i, j;
    171   for (i = 0; i < table->Nhosts; i++) {
    172 
    173     if (sky->Nregions < table->Nhosts) {
     186  for (i = 0; i < group->Nhosts; i++) {
     187
     188    if (sky->Nregions < group->Nhosts) {
    174189      // do any of the regions want this host?
    175190      int wantThisHost = FALSE;
    176191      for (j = 0; j < sky->Nregions; j++) {
    177         if (HostTableTestHost (sky->regions[j], table->hosts[i].hostID)) {
     192        if (HostTableTestHost (sky->regions[j], group->hosts[i][0].hostID)) {
    178193          wantThisHost = TRUE;
    179194          break;
     
    181196      }
    182197      if (!wantThisHost) {
    183         // fprintf (stderr, "skip host %s\n", table->hosts[i].hostname);
     198        // fprintf (stderr, "skip host %s\n", group->hosts[i][0].hostname);
    184199        continue;
    185200      }
     
    187202
    188203    // ensure that the paths are absolute path names
    189     char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
    190     free (table->hosts[i].pathname);
    191     table->hosts[i].pathname = tmppath;
     204    char *tmppath = abspath (group->hosts[i][0].pathname, DVO_MAX_PATH);
     205    free (group->hosts[i][0].pathname);
     206    group->hosts[i][0].pathname = tmppath;
    192207
    193208    char command[1024];
    194209    snprintf (command, 1024, "relphot_client %s -update-catalogs %s -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f",
    195               PhotcodeList, imageFile, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
     210              PhotcodeList, imageFile, group->hosts[i][0].hostID, CATDIR, group->hosts[i][0].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
    196211
    197212    // options & configs which affect relphot_client -update-catalogs
     
    238253      // launch the job on the remote machine (no handshake)
    239254      int errorInfo = 0;
    240       int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
     255      int pid = rconnect ("ssh", group->hosts[i][0].hostname, command, group->hosts[i][0].stdio, &errorInfo, FALSE);
    241256      if (!pid) {
    242         if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
     257        if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", group->hosts[i][0].hostname, errorInfo);
    243258        exit (1);
    244259      }
    245       table->hosts[i].pid = pid; // save for future reference
     260      group->hosts[i][0].pid = pid; // save for future reference
    246261    }
    247262  }
     
    252267  }
    253268  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    254     int status = HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     269    int status = HostTableGroupWaitJobsGetIO (group, __FILE__, __LINE__, VERBOSE);
    255270    if (!status) {
    256271      fprintf (stderr, "at least one remote client job failed to load data, exiting\n");
  • trunk/Ohana/src/relphot/src/relphot.c

    r36630 r37807  
    99  switch (mode) {
    1010    case UPDATE_IMAGES:
     11      // IF CALLED WITH NLOOP == 0, DOES NOT LOAD bcatalog, just loads image table and generates ImageSubset.dat
    1112      relphot_images ();
    1213      exit (0);
     
    1415    case UPDATE_AVERAGES:
    1516      // take the current set of detections and set the mean magnitudes
     17      // DOES NOT LOAD THE IMAGE TABLE
    1618      relphot_objects (0, NULL);
    1719      exit (0);
     
    4345  exit (1);
    4446}
     47
     48/***
     49
     50    I would like to merge the functionality of relphot_images (Nloop == 0), relphot_objects, and apply_offsets
     51   
     52***/
  • trunk/Ohana/src/relphot/src/relphot_objects.c

    r35104 r37807  
    3636    if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
    3737
    38     // set up the basic catalog info
    3938    // set up the basic catalog info
    4039    char hostfile[1024];
  • trunk/Ohana/src/relphot/src/relphot_parallel_regions.c

    r37037 r37807  
    4343  MARKTIME("-- load image data: %f sec\n", dtime);
    4444
     45  // save Images.dat using the copied structure
     46  if (UPDATE_CATFORMAT) {
     47    // ensure the db format is updated
     48    db.format = dvo_catalog_catformat (UPDATE_CATFORMAT);
     49  }
     50
    4551  /* assign the images to the different region hosts */
    4652  if (!assign_images (&db, regionHosts)) Shutdown ("error assigning images to region hosts");
     
    4955  /* launch processing on the parallel region hosts */
    5056  if (!launch_region_hosts (regionHosts)) Shutdown ("error launching region hosts");
     57  MARKTIME ("finished relphot -parallel-regions: %f sec total\n", dtime);
    5158
    5259  // retrieve updated image parameters from the remote hosts (also set Image.mcal)
  • trunk/Ohana/src/relphot/src/select_images.c

    r36491 r37807  
    3636
    3737  // the comparison is made in the catalog local projection. below we set crval1,2
    38   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     38  InitCoords (&tcoords, "DEC--TAN");
    3939  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    40   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    41   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    42   strcpy (tcoords.ctype, "DEC--TAN");
    4340
    4441  double RminSkyRegion = region[0].Rmin;
     
    9390
    9491  if (VERBOSE) fprintf (stderr, "finding images\n");
    95   BuildChipMatch (timage, Ntimage);
    96   MARKTIME("build chip match for %d images: %f sec\n", (int) Ntimage, dtime);
    9792
    9893  D_NIMAGE = 6000;
     
    107102     
    108103    if (!(i % 300000)) fprintf (stderr, ".");
     104
     105    // XXX I am just going for force this for the moment:
     106    goto found_it;
    109107
    110108    /* exclude images by photcode */
     
    123121    }
    124122   
    125     // this adds 1.3 sec for 3M images
    126     if (!FindMosaicForImage (timage, Ntimage, i)) {
    127       if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    128       continue;
    129     }
    130 
    131123    /* define image corners - note the DIS images (mosaic phu) are special */
    132124    if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) {
     
    405397
    406398  // the comparison is made in the catalog local projection. below we set crval1,2
    407   tcoords.crpix1 = tcoords.crpix2 = 0.0;
     399  InitCoords (&tcoords, "DEC--TAN");
    408400  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
    409   tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    410   tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    411 
    412   tcoords.Npolyterms = 0;
    413   memset (tcoords.polyterms, 0, 14*sizeof(float));
    414   strcpy (tcoords.ctype, "DEC--TAN");
    415401
    416402  /* compare with each region file */
  • trunk/Ohana/src/relphot/src/setMrelCatalog.c

    r37740 r37807  
    3636}
    3737
    38 int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found);
    39 
    4038int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    4139
     
    6058    Average *average = catalog[Nc].average ? &catalog[Nc].average[j] : NULL;
    6159    Measure *measure = catalog[Nc].measure ? &catalog[Nc].measure[m] : NULL;
    62     setMrelAverageExposure (m, Nc, pass, flatcorr, results, average, &catalog[Nc].averageT[j], &catalog[Nc].secfilt[j*Nsecfilt], measure, &catalog[Nc].measureT[m], &catalog[Nc].found_t[Nsecfilt*j]);
     60    SecFilt *secfilt = catalog[Nc].secfilt ? &catalog[Nc].secfilt[j*Nsecfilt] : NULL;
     61    setMrelAverageExposure (m, Nc, pass, flatcorr, results, average, &catalog[Nc].averageT[j], secfilt, measure, &catalog[Nc].measureT[m], &catalog[Nc].found_t[Nsecfilt*j]);
    6362
    6463    // only apply Stack operation on setMrelFinal in first pass
    6564    if (isSetMrelFinal && (pass == 0)) {
    66       setMrelAverageStack (m, Nc, flatcorr, results, &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], &catalog[Nc].measure[m]);
     65      setMrelAverageStack (m, Nc, flatcorr, results, average, secfilt, &catalog[Nc].measure[m], catalog[Nc].Nmeasure);
    6766      setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
    6867    }
     
    7069    // only measure force-warp mean values if issetMrelFinal (make it optional?)
    7170    if (isSetMrelFinal) {
    72       setMrelAverageForcedWarp (m, Nc, pass, results, &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], &catalog[Nc].measure[m], &catalog[Nc].foundWarp_t[Nsecfilt*j]);
    73       setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
     71      setMrelAverageForcedWarp (m, Nc, pass, results, average, secfilt, measure, &catalog[Nc].foundWarp_t[Nsecfilt*j], catalog[Nc].Nmeasure);
     72      setGlobalObjStats (average, measure);
    7473    }
    7574  }
     
    456455// 2) select the BEST detections per filter (regardless of PRIMARY)
    457456// 3) apply the zero point and AB->Jy transformations
    458 int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure) {
     457int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t Nmeasure) {
    459458
    460459  off_t k;
     
    496495    int Nstack = 0; // number for this photcode
    497496    int NstackDet = 0; // number for this photcode
     497
     498    secfilt[Nsec].stackBestOff = -1;
     499    secfilt[Nsec].stackPrmryOff = -1;
    498500
    499501    off_t meas = measureOffset;
     
    526528        measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
    527529        secfilt[Nsec].stackPrmryOff = meas;
     530        myAssert (secfilt[Nsec].stackPrmryOff <= Nmeasure, "stackPrmryOff out of range");
    528531      }
    529532
     
    637640
    638641    secfilt[Nsec].stackBestOff = k + measureOffset;
     642    myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
    639643
    640644    secfilt[Nsec].Nstack    = Nstack;
     
    669673// somewhat simplified relative to chip-photometry:
    670674// * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
    671 int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found) {
     675int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found, off_t Nmeasure) {
    672676
    673677  off_t k;
     
    713717    // if we cannot make that association, skip this set of warps
    714718    int stkTessID, stkProjID, stkSkycellID;
     719
     720    myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
    715721    if (!FindImageSkycellID (secfilt[Nsec].stackBestOff, cat, &stkTessID, &stkProjID, &stkSkycellID)) continue;
    716722
  • trunk/Ohana/src/uniphot/Makefile

    r35764 r37807  
    1 default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
     1default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client setgalmodel setgalmodel_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
    22help:
    33@echo "make options: uniphot setphot setfwhm default help install default (uniphot setphot setfwhm)"
     
    2525setastrom: $(BIN)/setastrom.$(ARCH)
    2626setastrom_client: $(BIN)/setastrom_client.$(ARCH)
     27setgalmodel: $(BIN)/setgalmodel.$(ARCH)
     28setgalmodel_client: $(BIN)/setgalmodel_client.$(ARCH)
    2729fiximids: $(BIN)/fiximids.$(ARCH)
    2830fiximids_client: $(BIN)/fiximids_client.$(ARCH)
     
    3234ckids_client: $(BIN)/ckids_client.$(ARCH)
    3335
    34 install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
     36install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/setgalmodel $(DESTBIN)/setgalmodel_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
    3537
    3638UNIPHOT = \
     
    110112$(SRC)/setastrom.$(ARCH).o          \
    111113$(SRC)/initialize_setastrom.$(ARCH).o \
     114$(SRC)/dcr_correction.$(ARCH).o \
     115$(SRC)/kh_correction.$(ARCH).o \
    112116$(SRC)/astrom_correction.$(ARCH).o \
    113117$(SRC)/update_dvo_setastrom.$(ARCH).o \
     
    123127$(SRC)/update_dvo_setastrom.$(ARCH).o \
    124128$(SRC)/update_catalog_setastrom.$(ARCH).o \
     129$(SRC)/dcr_correction.$(ARCH).o \
     130$(SRC)/kh_correction.$(ARCH).o \
    125131$(SRC)/astrom_correction.$(ARCH).o \
    126132$(SRC)/initialize_setastrom.$(ARCH).o
     
    128134$(SETASTROM_CLIENT): $(INC)/setastrom.h
    129135$(BIN)/setastrom_client.$(ARCH): $(SETASTROM_CLIENT)
     136
     137SETGALMODEL = \
     138$(SRC)/setgalmodel.$(ARCH).o        \
     139$(SRC)/initialize_setgalmodel.$(ARCH).o \
     140$(SRC)/galmodel_correction.$(ARCH).o \
     141$(SRC)/update_dvo_setgalmodel.$(ARCH).o \
     142$(SRC)/update_catalog_setgalmodel.$(ARCH).o \
     143$(SRC)/SetSignals.$(ARCH).o         \
     144$(SRC)/Shutdown.$(ARCH).o           
     145
     146$(SETGALMODEL): $(INC)/setgalmodel.h
     147$(BIN)/setgalmodel.$(ARCH): $(SETGALMODEL)
     148
     149SETGALMODEL_CLIENT = \
     150$(SRC)/setgalmodel_client.$(ARCH).o         \
     151$(SRC)/update_dvo_setgalmodel.$(ARCH).o \
     152$(SRC)/update_catalog_setgalmodel.$(ARCH).o \
     153$(SRC)/galmodel_correction.$(ARCH).o \
     154$(SRC)/initialize_setgalmodel.$(ARCH).o
     155
     156$(SETGALMODEL_CLIENT): $(INC)/setgalmodel.h
     157$(BIN)/setgalmodel_client.$(ARCH): $(SETGALMODEL_CLIENT)
    130158
    131159SETFWHM =                           \
  • trunk/Ohana/src/uniphot/include/setastrom.h

    r35103 r37807  
    2525char        *SINGLE_CPT;
    2626
     27char        *KH_FILE;
     28char        *DCR_FILE;
     29
     30int          KH_RESET;
     31int          DCR_RESET;
     32
    2733SkyRegion    UserPatch;
    2834
     
    4652// int           SetSignals                      PROTO((void));
    4753
    48 int           update_dvo_setastrom            PROTO((char *corrfile));
    49 int           update_dvo_setastrom_parallel   PROTO((SkyTable *sky, char *corrfile));
     54int           update_dvo_setastrom            PROTO(());
     55int           update_dvo_setastrom_parallel   PROTO((SkyTable *sky));
    5056
    5157int           update_catalog_setastrom        PROTO((Catalog *catalog));
    5258
    5359// spline correction functions
    54 int load_astrom_correction (char *filename);
    55 int get_astrom_correction (int sub, int chip, double *dX, double *dY, float Minst);
    5660double spline_apply_dbl (double *x, double *y, double *y2, int N, double X);
     61
     62int load_kh_correction (char *filename);
     63int get_kh_correction (int sub, int chip, double *dX, double *dY, float Minst);
     64
     65int load_dcr_correction (char *filename);
     66int get_dcr_correction (int filter, double *dX, double *dY, float Color);
  • trunk/Ohana/src/uniphot/src/astrom_correction.c

    r35103 r37807  
    22
    33// astrometry correction functions:
    4 // load the correction set from a file
    5 
    6 // the correction is saved as a set of splines, one per file extension
    7 // extensions have names of the form XYnn.Dx.Td
    8 
    9 // where nn = 00 - 77, the chip number
    10 // x is X or Y, the correction direction (dir)
    11 // d is 0 or 1, pre or post camera correction (sub)
    12 
    13 // these are stored in an N-D array of (Spline *) splineset[sub][dir][chip]
    14 
    15 # define N_SUB 2
    16 # define N_DIR 2
    17 # define N_CHIP 78
    18 // note that we are allocating pointers for XY00 - XY77, but only the octal elements are set (and not the 00,07,70,77 ones)
    19 
    20 Spline ****splineset;
    21 
    22 int load_astrom_correction (char *filename) {
    23 
    24   int Ncol;
    25   off_t Nrow;
    26 
    27   char type[16];
    28   char extname[80];
    29 
    30   Header header;
    31   Header theader;
    32   FTable ftable;
    33 
    34   /* open file for input */
    35   FILE *f = fopen (filename, "r");
    36   if (f == (FILE *) NULL) {
    37     gprint (GP_ERR, "can't open file for read : %s\n", filename);
    38     return FALSE;
    39   }
    40 
    41   // read the PHU header
    42   if (!gfits_load_header (f, &header)) return (FALSE);
    43  
    44   int Nbytes = gfits_data_size (&header);
    45   fseeko (f, Nbytes, SEEK_CUR);
    46   // XXX gfits_free_header (&header);
    47 
    48   ftable.header = &theader;
    49 
    50   int sub, dir, chip;
    51 
    52   // we have a N-D array of splines:
    53   // splineset[sub][dir][chip]
    54 
    55   ALLOCATE (splineset, Spline ***, N_SUB);
    56   for (sub = 0; sub < N_SUB; sub++) {
    57     ALLOCATE (splineset[sub], Spline **, N_DIR);
    58     for (dir = 0; dir < N_DIR; dir++) {
    59       ALLOCATE (splineset[sub][dir], Spline *, N_CHIP);
    60       for (chip = 0; chip < N_CHIP; chip ++) {
    61         splineset[sub][dir][chip] = NULL;
    62       }
    63     }
    64   }
    65 
    66   while (TRUE) {
    67     // load data for this header : if not found, assume we hit the end of the file
    68     if (!gfits_load_header (f, &theader)) break;
    69    
    70     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (FALSE);
    71    
    72     if (!gfits_scan (&theader, "EXTNAME", "%s", 1, extname)) return (FALSE);
    73 
    74     // figure out the chip ID, diretion, and sequence from the EXTNAME
    75 
    76     // EXTNAME is of the form XY%d%d.D%s.T%s where
    77     char chipname[3];
    78     chipname[0] = extname[2];
    79     chipname[1] = extname[3];
    80     chipname[2] = 0;
    81     int chip = atoi(chipname);
    82     myAssert (chip >   0, "error in extname %s not(chip >   0)\n", extname);
    83     myAssert (chip <  77, "error in extname %s not(chip <  77)\n", extname);
    84     myAssert (chip !=  7, "error in extname %s not(chip !=  7)\n", extname);
    85     myAssert (chip != 70, "error in extname %s not(chip != 70)\n", extname);
    86 
    87     int dir = -1;
    88     if (extname[6] == 'X') {
    89       dir = 0;
    90     }
    91     if (extname[6] == 'Y') {
    92       dir = 1;
    93     }
    94     myAssert (dir != -1, "error in extname %s (dir)\n", extname);
    95 
    96     int sub = -1;
    97     if (extname[9] == '0') {
    98       sub = 0;
    99     }
    100     if (extname[9] == '1') {
    101       sub = 1;
    102     }
    103     myAssert (sub != -1, "error in extname %s (sub)\n", extname);
    104 
    105     // need to create and assign to flat-field correction
    106     double *xk = gfits_get_bintable_column_data (&theader, &ftable, "X_KNOT", type, &Nrow, &Ncol);
    107     myAssert (!strcmp(type, "double"), "error reading X_KNOT");
    108    
    109     // need to create and assign to flat-field correction
    110     double *yk = gfits_get_bintable_column_data (&theader, &ftable, "Y_KNOT", type, &Nrow, &Ncol);
    111     myAssert (!strcmp(type, "double"), "error reading X_KNOT");
    112    
    113     // need to create and assign to flat-field correction
    114     double *y2 = gfits_get_bintable_column_data (&theader, &ftable, "DY2_DX", type, &Nrow, &Ncol);
    115     myAssert (!strcmp(type, "double"), "error reading X_KNOT");
    116    
    117     ALLOCATE (splineset[sub][dir][chip], Spline, 1);
    118     splineset[sub][dir][chip]->xk = xk;
    119     splineset[sub][dir][chip]->yk = yk;
    120     splineset[sub][dir][chip]->y2 = y2;
    121     splineset[sub][dir][chip]->Nknots = Nrow;
    122   }
    123   return (TRUE);
    124 }
    125 
    126 int get_astrom_correction (int sub, int chip, double *dX, double *dY, float Minst) {
    127 
    128   Spline *spline = NULL;
    129 
    130   *dX = 0.0;
    131   *dY = 0.0;
    132 
    133   // XXX need to include some limits on Minst?
    134 
    135   spline = splineset[sub][0][chip];
    136   if (spline) {
    137     *dX = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst);
    138   }
    139 
    140   spline = splineset[sub][1][chip];
    141   if (spline) {
    142     *dY = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst);
    143   }
    144   return (TRUE);
    145 }
     4// KH correction
     5// DCR correction
    1466
    1477/* evaluate spline for x, y, y2 at X */
  • trunk/Ohana/src/uniphot/src/find_image_sgroups.c

    r36481 r37807  
    1818  }
    1919
    20   coords.crpix1 = coords.crpix2 = 0.0;
    21   coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
    22   coords.pc1_1 = coords.pc2_2 = 1.0;
    23   coords.pc1_2 = coords.pc2_1 = 0.0;
    24   strcpy (coords.ctype, "DEC--TAN");
     20  InitCoords (&coords, "DEC--TAN");
    2521 
    2622  Ngroup = 0;
     
    4137    // NOCAL above is used to mark images which do not match the photcode (including the DIS)
    4238    // if (!strcmp(&image[i].coords.ctype[4], "-DIS")) continue;
    43 
    44     // this adds 1.3 sec for 3M images
    45     if (!FindMosaicForImage (image, Nimage, i)) {
    46       fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
    47       continue;
    48     }
    4939
    5040    /* define image center - note the DIS images (mosaic phu) are special */
     
    8373      // if (!strcmp(&image[j].coords.ctype[4], "-DIS")) continue;
    8474
    85       // this adds 1.3 sec for 3M images
    86       if (!FindMosaicForImage (image, Nimage, j)) {
    87           fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", j);
    88           continue;
    89       }
    90 
    9175      /* project image center to local coords, check radius */
    9276      if (!strcmp(&image[j].coords.ctype[4], "-DIS")) {
  • trunk/Ohana/src/uniphot/src/initialize_setastrom.c

    r35103 r37807  
    22
    33void usage_setastrom () {
    4     fprintf (stderr, "USAGE: setastrom (corrections) [options]\n");
     4    fprintf (stderr, "USAGE: setastrom [options]\n");
    55    fprintf (stderr, "  options:\n");
     6    fprintf (stderr, "    -DCR (file) : supply DCR correction splines\n");
     7    fprintf (stderr, "    -KH (file) : supply Koppenhoefer correction splines\n");
    68    fprintf (stderr, "    -v : verbose mode\n");
    79    fprintf (stderr, "    -region Rmin Rmax Dmin Dmax\n");
     
    4951  int N;
    5052
     53  KH_FILE = NULL;
     54  if ((N = get_argument (argc, argv, "-KH"))) {
     55    remove_argument (N, &argc, argv);
     56    char *tmpfile = strcreate (argv[N]);
     57    KH_FILE = abspath (tmpfile, DVO_MAX_PATH);
     58    remove_argument (N, &argc, argv);
     59  }
     60  KH_RESET = FALSE;
     61  if ((N = get_argument (argc, argv, "-KH-reset"))) {
     62    remove_argument (N, &argc, argv);
     63    KH_RESET = TRUE;
     64  }
     65
     66  DCR_FILE = NULL;
     67  if ((N = get_argument (argc, argv, "-DCR"))) {
     68    remove_argument (N, &argc, argv);
     69    char *tmpfile = strcreate (argv[N]);
     70    DCR_FILE = abspath (tmpfile, DVO_MAX_PATH);
     71    remove_argument (N, &argc, argv);
     72  }
     73  DCR_RESET = FALSE;
     74  if ((N = get_argument (argc, argv, "-DCR-reset"))) {
     75    remove_argument (N, &argc, argv);
     76    DCR_RESET = TRUE;
     77  }
     78
    5179  SINGLE_CPT = NULL;
    5280  if ((N = get_argument (argc, argv, "-cpt"))) {
     
    118146  }
    119147
    120   if (argc != 2) usage_setastrom();
     148  if (!KH_FILE && !DCR_FILE) {
     149    fprintf (stderr, "at least one of -KH and -DCR must be supplied\n");
     150    exit (1);
     151  }
     152
     153  if (argc != 1) usage_setastrom();
    121154
    122155  return (TRUE);
     
    124157
    125158void usage_setastrom_client () {
    126   fprintf (stderr, "USAGE: setastrom_client (correction) -hostID (hostID) -catdir (catdir) -hostdir (hostdir) [options]\n");
     159  fprintf (stderr, "USAGE: setastrom_client -hostID (hostID) -catdir (catdir) -hostdir (hostdir) [options]\n");
    127160  fprintf (stderr, "  options:\n");
     161  fprintf (stderr, "    -DCR (file) : supply DCR correction splines\n");
     162  fprintf (stderr, "    -KH (file) : supply Koppenhoefer correction splines\n");
    128163  fprintf (stderr, "    -region Rmin Rmax Dmin Dmax\n");
    129164  fprintf (stderr, "    -update-catformat (format) : change database schema on output\n");
     
    163198
    164199  int N;
     200
     201  KH_FILE = NULL;
     202  if ((N = get_argument (argc, argv, "-KH"))) {
     203    remove_argument (N, &argc, argv);
     204    KH_FILE = strcreate (argv[N]);
     205    remove_argument (N, &argc, argv);
     206  }
     207  KH_RESET = FALSE;
     208  if ((N = get_argument (argc, argv, "-KH-reset"))) {
     209    remove_argument (N, &argc, argv);
     210    KH_RESET = TRUE;
     211  }
     212
     213  DCR_FILE = NULL;
     214  if ((N = get_argument (argc, argv, "-DCR"))) {
     215    remove_argument (N, &argc, argv);
     216    DCR_FILE = strcreate (argv[N]);
     217    remove_argument (N, &argc, argv);
     218  }
     219  DCR_RESET = FALSE;
     220  if ((N = get_argument (argc, argv, "-DCR-reset"))) {
     221    remove_argument (N, &argc, argv);
     222    DCR_RESET = TRUE;
     223  }
    165224
    166225  /* specify portion of the sky : allow default of all sky? */
     
    223282  if (!CATDIR) usage_setastrom_client();
    224283
    225   if (argc != 2) usage_setastrom_client();
     284  if (!KH_FILE && !DCR_FILE) {
     285    fprintf (stderr, "at least one of -KH and -DCR must be supplied\n");
     286    exit (1);
     287  }
     288
     289  if (argc != 1) usage_setastrom_client();
    226290  return (TRUE);
    227291}
  • trunk/Ohana/src/uniphot/src/load_zpt_table.c

    r33654 r37807  
    173173      mjdstart = tstart_uc[i];
    174174      mjdstop  = tstop_uc[i];
    175   } else {
     175    } else {
    176176      char name[9];
    177       snprintf (name, 9, "TS0_%04d", i);
     177      // snprintf (name, 9, "TS0_%04d", i);
     178      snprintf (name, 9, "S0_MJD%d", i);
    178179      if (!gfits_scan (&header, name, "%lf", 1, &mjdstart)) {
    179180        fprintf (stderr, "cannot find %s in header of %s\n", name, filename);
     
    182183      }
    183184
    184       snprintf (name, 9, "TS1_%04d", i);
     185      // snprintf (name, 9, "TS1_%04d", i);
     186      snprintf (name, 9, "S1_MJD%d", i);
    185187      if (!gfits_scan (&header, name, "%lf", 1, &mjdstop)) {
    186188        fprintf (stderr, "cannot find %s in header of %s\n", name, filename);
     
    189191      }
    190192    }
    191     flatcorrTable->tstart[i] = ohana_mjd_to_sec(mjdstart);
    192     flatcorrTable->tstop[i]  = ohana_mjd_to_sec(mjdstop);
     193    flatcorrTable->tstart[i] = (mjdstart > 0) ? ohana_mjd_to_sec(mjdstart) : ohana_mjd_to_sec(50000.0); // 1995/10/10 (ancient history)
     194    flatcorrTable->tstop[i]  = (mjdstop  > 0) ? ohana_mjd_to_sec(mjdstop)  : ohana_mjd_to_sec(60000.0); // 2023/02/25 (infinite future)
    193195  }
    194196
     
    247249    } else {
    248250      if (!gfits_scan (&header, "FILTER", "%s", 1, filter)) {
    249         fprintf (stderr, "cannot find FILTER in header of %s\n", filename);
    250         fclose (f);
    251         return NULL;
     251        fprintf (stderr, "cannot find FILTER in header of %s, using %s\n", filename, filters_uc[nfilter]);
     252        strcpy (filter, filters_uc[nfilter]);
     253        // fclose (f);
     254        // return NULL;
    252255      }
    253256    }
     
    278281      REALLOCATE (offset64, double, matrix.Naxis[0]);
    279282      matrix.buffer = (char *) offset64;
     283    }
     284    if (matrix.Naxes == 1) {
     285      int Ntotal = NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y;
     286      if (matrix.Naxis[0] != Ntotal) {
     287        int Nextra = Ntotal - matrix.Naxis[0];
     288        assert (Nextra >= 0);
     289        fprintf (stderr, "warning: images are not fully populated, extending by %d\n", Nextra);
     290       
     291        REALLOCATE (offset64, double, Ntotal);
     292        int npix;
     293        for (npix = matrix.Naxis[0]; npix < Ntotal; npix ++) offset64[npix] = 0.0;
     294
     295        matrix.Naxis[0] = Ntotal;
     296        matrix.buffer = (char *) offset64;
     297      }
    280298    }
    281299
  • trunk/Ohana/src/uniphot/src/match_zpts_to_images.c

    r35764 r37807  
    9797    }
    9898
     99    // if secz is crazy, do not trust ubercal; skip and move along
     100    if (image[Ni].secz < 0.1) {
     101      i++;
     102      continue;
     103    }
     104
    99105    // we have a match: set zpt and record the match
    100106    // is the zero point supplied nominally corrected or not?
  • trunk/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r37043 r37807  
    11# include "setastrom.h"
     2
     3// this code does both DCR and KH corrections, if both are specified. 
    24
    35// XXX this function is dependent in two ways on the specific numerical values of the photcodes
     
    79int update_catalog_setastrom (Catalog *catalog) {
    810
    9   off_t i, found;
     11  off_t i;
    1012
    1113  time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00");
    1214
    13   found = 0;
     15  int Nsecfilt = GetPhotcodeNsecfilt ();
     16  PhotCode *code_g = GetPhotcodebyName ("g");
     17  PhotCode *code_i = GetPhotcodebyName ("i");
     18  PhotCode *code_z = GetPhotcodebyName ("z");
     19  PhotCode *code_y = GetPhotcodebyName ("y");
     20
     21  int Nsec_g = GetPhotcodeNsec(code_g->code);
     22  int Nsec_i = GetPhotcodeNsec(code_i->code);
     23  int Nsec_z = GetPhotcodeNsec(code_z->code);
     24  int Nsec_y = GetPhotcodeNsec(code_y->code);
     25
     26  off_t found = 0;
    1427
    1528  for (i = 0; i < catalog[0].Nmeasure; i++) {
     
    1730    Measure *measure = &catalog[0].measure[i];
    1831
    19     // XXX only do GPC1 data for now
     32    // only do GPC1 data for now (true for both DCR and KH)
    2033    if (measure[0].photcode < 10000) continue;
    2134    if (measure[0].photcode > 10600) continue;
    2235     
    23     // XXX hardwire the list of chips to correct
     36    int averef = measure->averef;
     37    Average *average = &catalog[0].average[averef];
     38    SecFilt *secfilt = &catalog[0].secfilt[averef*Nsecfilt];
     39
     40    int chipID = measure[0].photcode % 100;
     41
     42    // XXX hardwire the list of chips to KH correct
    2443    // some notes:
    25     // XY24 surpisingly does not need correction
     44    // XY24 surprisingly does not need correction
    2645    // XY27 has poor astrometry with a weird correction for all mags
    27     // XY36 surpisingly does not need correction
     46    // XY36 surprisingly does not need correction
    2847    // XY67 has poor astrometry with a weird correction for all mags
    2948
    30     int chipID = measure[0].photcode % 100;
     49    int doKH = FALSE;
    3150    switch (chipID) {
    3251      case 4:
     
    5776      case 72:
    5877      case 73:
     78        doKH = TRUE;
    5979        break;
    6080      default:
    61         measure[0].Xfix = measure[0].Xccd;
    62         measure[0].Yfix = measure[0].Yccd;
    63         continue;
    64     }
    65 
    66     double Xccd = measure[0].Xccd;
    67     double Yccd = measure[0].Yccd;
     81        break;
     82    }
     83
    6884    double pltScale = fabs(measure[0].pltscale);
    69 
    70     // this is not needed, is it?
    71     // double posAngle = FromShortDegrees(measure[0].posangle);
    72 
    73     // I need to know which chip we have.  use photcode assuming range
    74     int chip = measure[0].photcode % 100;
    75 
    76     // correction may be Minst or Minst + 5.0*log(fwhm
    77     float fwhm_maj = FromShortPixels(measure[0].FWx);
    78     float Minst = PhotInst (measure, MAG_CLASS_PSF);
    79     float MinstSB = Minst + 5.0*log10(fwhm_maj);
    80 
    81     // I should validate that the spline I'm using is SB corrected not Minst...
    82 
    83     // XXX this is very ad hoc.  the splines are measured based on an extraction from dvo
    84     // the dvo values of fwhm_maj are sigmas (NOT FWHM!) in pixels. 
     85    double posAngle = FromShortDegrees(measure[0].posangle);
     86
     87    /**** KH section ****/
     88
     89    double dX_KH = 0.0;
     90    double dY_KH = 0.0;
     91    if (KH_FILE && doKH && (measure[0].t < timeRef)) {
     92
     93      // correction may be Minst or Minst + 5.0*log(fwhm
     94      float fwhm_maj = FromShortPixels(measure[0].FWx);
     95      float Minst = PhotInst (measure, MAG_CLASS_PSF);
     96      // float MinstSB = Minst + 5.0*log10(fwhm_maj);
     97
     98      // NOTE: the spline correction was measured on the nightly-science database using measurements
     99      // from the period in which fwhm_maj & fwhm_min were a factor of sqrt(2) too small.  I am making
     100      // this correction here (but ideally I would re-measure the KH trend from PV2 data and re-generate
     101      // the splines
     102      float MinstSB = Minst + 5.0*log10(M_SQRT2*fwhm_maj);
     103
     104      // I should validate that the spline I'm using is SB corrected not Minst..
     105      // NOTE: it is SB, not raw Minst
     106
     107      // XXX this is very ad hoc.  the splines are measured based on an extraction from dvo
     108      // the dvo values of fwhm_maj are sigmas (NOT FWHM!) in pixels. 
    85109   
    86     // saturate fwhm_maj in the range 1.0 < fwhm_maj < 5.0
    87     // (images with really odd psf probably have poor astrometry anyway...)
    88     fwhm_maj = MIN(fwhm_maj,5.0);
    89     fwhm_maj = MAX(fwhm_maj,1.0);
    90 
    91     double dX;
    92     double dY;
    93 
    94     // correction is in arcseconds
    95     if (measure[0].t < timeRef) {
    96       get_astrom_correction (0, chip, &dX, &dY, MinstSB);
    97     } else {
    98       // XXX do not correct new data
    99       // get_astrom_correction (1, chip, &dX, &dY, MinstSB);
    100       dX = 0.0;
    101       dY = 0.0;
    102     }
     110      // saturate fwhm_maj in the range 1.0 < fwhm_maj < 5.0
     111      // (images with really odd psf probably have poor astrometry anyway...)
     112      fwhm_maj = MIN(fwhm_maj,5.0);
     113      fwhm_maj = MAX(fwhm_maj,1.0);
     114
     115      // correction is in arcseconds
     116      get_kh_correction (0, chipID, &dX_KH, &dY_KH, MinstSB);
     117    }
     118
     119    /**** DCR section ****/
     120
     121    double dX_DCR = 0.0;
     122    double dY_DCR = 0.0;
     123    if (DCR_FILE) {
     124
     125      // check if the color*airmass term is not-nan (Skip otherwise)
     126
     127      // XXX hard-wire gpc1 photcodes for now:
     128      // I should use photcode ops: PhotCode *code = PhotCodeByCode(measure->photcode)
     129      // int equiv = code->equiv
     130      // Nsec = GetNsec(equiv)
     131
     132      float dColor = 0.0;
     133      int filtCode = (int)(measure->photcode / 100); // eg, 101 = r
     134      switch (filtCode) {
     135        case 100:
     136        case 101:
     137        case 102: {
     138          float gmag = secfilt[Nsec_g].M;
     139          float imag = secfilt[Nsec_i].M;
     140          dColor = average->refColorBlue - (gmag - imag);
     141          break;
     142        }
     143        case 103:
     144        case 104: {
     145          float zmag = secfilt[Nsec_z].M;
     146          float ymag = secfilt[Nsec_y].M;
     147          dColor = average->refColorRed - (zmag - ymag);
     148          break;
     149        }
     150      }
     151      int filtSeq = filtCode % 100;
     152      if (!isfinite(dColor)) goto skip_DCR;
     153
     154      // I need to get the parallactic angle, but I only have alt & az, s:o
     155   
     156      // airmass = 1.0 / cos(90 - alt)
     157      // cos(90 - alt) = cos(zd) = sin(alt) = 1.0 / airmass
     158      // airmass = 1.0 / sin(alt)
     159
     160      // airmass = 1.0 / cos(zd)
     161      // cos(zd) = 1.0 / airmass == sn_alt
     162      // sin(zd) = sqrt(1.0 - cos(zd)^2) == cs_alt
     163      // tan(zd) = sin(zd) / cos(zd) = cs_alt / sn_alt
     164
     165      double sn_alt = 1.0 / measure->airmass;
     166      double cs_alt = sqrt(1.0 - SQ(sn_alt));
     167      double tan_zd = cs_alt / sn_alt;
     168
     169      double cs_az  = cos(RAD_DEG*measure->az);
     170      double sn_az  = sin(RAD_DEG*measure->az);
     171
     172# define LATITUDE (20.7070999146*RAD_DEG)
     173      double sn_lat = sin(LATITUDE);
     174      double cs_lat = cos(LATITUDE);
     175
     176      // double sind = sn_alt * sn_lat + cs_alt * cs_az * cs_lat;
     177      // *dec  = DEG_RAD * asin (sind);
     178
     179      // WARNING: these are NOT sin(ha),cos(ha) but are scaled
     180      // double ha = DEG_RAD * atan2 (sinh, cosh);
     181      double sinh = -cs_alt * sn_az;
     182      double cosh =  sn_alt * cs_lat - cs_alt * cs_az * sn_lat;
     183      double r_ha = hypot(sinh, cosh);
     184      double sn_ha = sinh / r_ha;
     185      double cs_ha = cosh / r_ha;
     186
     187      sinh = -cs_az * sn_alt * sn_ha * sn_lat + sn_az * sn_alt * cs_ha - sn_ha * cs_alt * cs_lat;
     188      cosh = -sn_az          * sn_ha * sn_lat - cs_az          * cs_ha;
     189      double r_rot = hypot(sinh, cosh);
     190
     191      double sn_rot = -sinh / r_rot;
     192      double cs_rot = +cosh / r_rot;
     193
     194      double dPx = 0.0;
     195      double dPy = 0.0;
     196
     197      float colorOffset = dColor * tan_zd;
     198      get_dcr_correction (filtSeq, &dPx, &dPy, colorOffset);
     199
     200      // if we had x-terms, we would have:
     201      // double dPx = dRx *cs_rot + dD_s*sn_rot;
     202      // double dPy = dD_s*cs_rot - dRx *sn_rot;
     203      // double dR = dPx*cs_rot - dPy*sn_rot;
     204      // double dD = dPx*sn_rot + dPy*cs_rot;
     205
     206      // since dPx = 0.0, instead we have: dPx, dPy as measured in dvo.dcr.sh
     207      double dR = -dPy*sn_rot;
     208      double dD = +dPy*cs_rot;
     209
     210      // dR = (measure->R - average->R) * 3600 * dcos(dec) [ie, in the projected plane]
     211      // dD = (measure->D - average->D) * 3600
     212      // average->D = measure->D - dD/3600
     213
     214      // now we need to rotate dR,dD into the chip frame and correction Xccd,Yccd
     215
     216      // are the plate-scale and posangle correctly set in the db?
     217
     218      // XXX the koppenhoefer code implies pos if angle from y -> D, (ie negative of the
     219      // below).  if so, apply sin(pos) -> -sin(pos)
     220
     221      // if parity = sky:
     222      // double dR =  dX*cos(pos) + dY*sin(pos);
     223      // double dD = -dX*sin(pos) + dY*cos(pos);
     224
     225      // XXX signs set here to reflect pos = -pos
     226      float posAngRad = posAngle * RAD_DEG;
     227      dX_DCR =  dR*cos(posAngRad) + dD*sin(posAngRad);
     228      dY_DCR = -dR*sin(posAngRad) + dD*cos(posAngRad);
     229    }
     230
     231  skip_DCR:
    103232
    104233    // do not modify the original Xccd,Yccd values
    105     measure[0].Xfix = Xccd + dX / pltScale;
    106     measure[0].Yfix = Yccd + dY / pltScale;
    107 
     234    if (KH_FILE) {
     235      measure[0].XoffKH = dX_KH / pltScale;
     236      measure[0].YoffKH = dY_KH / pltScale;
     237    }
     238    if (KH_RESET) {
     239      measure[0].XoffKH = 0.0;
     240      measure[0].YoffKH = 0.0;
     241    }
     242    if (DCR_FILE) {
     243      measure[0].XoffDCR = -dX_DCR / pltScale;
     244      measure[0].YoffDCR = -dY_DCR / pltScale;
     245    }
     246    if (DCR_RESET) {
     247      measure[0].XoffDCR = -dX_DCR / pltScale;
     248      measure[0].YoffDCR = -dY_DCR / pltScale;
     249    }
     250
     251    measure[0].Xfix = measure[0].Xccd;
     252    measure[0].Yfix = measure[0].Yccd;
     253    if (isfinite(measure[0].XoffKH) && isfinite(measure[0].YoffKH)) {
     254      measure[0].Xfix += measure[0].XoffKH;
     255      measure[0].Yfix += measure[0].YoffKH;
     256    }
     257    if (isfinite(measure[0].XoffDCR) && isfinite(measure[0].YoffDCR)) {
     258      measure[0].Xfix += measure[0].XoffDCR;
     259      measure[0].Yfix += measure[0].YoffDCR;
     260    }
    108261    found ++;
    109262  }
  • trunk/Ohana/src/uniphot/src/update_dvo_setastrom.c

    r35103 r37807  
    11# include "setastrom.h"
    22
    3 int update_dvo_setastrom (char *corrfile) {
     3int update_dvo_setastrom () {
    44
    55  SkyTable *sky = NULL;
     
    1313 
    1414  if (PARALLEL && !HOST_ID) {
    15     int status = update_dvo_setastrom_parallel (sky, corrfile);
     15    int status = update_dvo_setastrom_parallel (sky);
    1616    return status;
    1717  }
    1818
    19   load_astrom_correction (corrfile);
     19  if (KH_FILE)  load_kh_correction (KH_FILE);
     20  if (DCR_FILE) load_dcr_correction (DCR_FILE);
    2021
    2122  // determine the populated SkyRegions overlapping the requested area (default depth)
     
    7879# define DEBUG 1
    7980
    80 int update_dvo_setastrom_parallel (SkyTable *sky, char *corrfile) {
     81int update_dvo_setastrom_parallel (SkyTable *sky) {
    8182
    8283  // now launch the setastrom_client jobs to the parallel hosts
    83 
    84   char *abscorrfile = abspath (corrfile, DVO_MAX_PATH);
    8584
    8685  // load the list of hosts
     
    9695
    9796    char command[1024];
    98     snprintf (command, 1024, "setastrom_client %s -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
    99               abscorrfile, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
     97    snprintf (command, 1024, "setastrom_client -hostID %d -catdir %s -hostdir %s -region %f %f %f %f",
     98              table->hosts[i].hostID, CATDIR, table->hosts[i].pathname,
    10099              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    101 
    102     fprintf (stderr, "command: %s\n", command);
    103100
    104101    char tmpline[1024];
    105102    if (VERBOSE)          { snprintf (tmpline, 1024, "%s -v",                   command);                   strcpy (command, tmpline); }
    106103    if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",              command);                   strcpy (command, tmpline); }
     104    if (KH_FILE)          { snprintf (tmpline, 1024, "%s -KH %s",               command, KH_FILE);          strcpy (command, tmpline); }
     105    if (DCR_FILE)         { snprintf (tmpline, 1024, "%s -DCR %s",              command, DCR_FILE);         strcpy (command, tmpline); }
    107106    if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); }
     107
     108    if (KH_RESET)         { snprintf (tmpline, 1024, "%s -KH-reset",            command);                   strcpy (command, tmpline); }
     109    if (DCR_RESET)        { snprintf (tmpline, 1024, "%s -DCR-reset",           command);                   strcpy (command, tmpline); }
     110
     111    fprintf (stderr, "command: %s\n", command);
    108112
    109113    if (PARALLEL_MANUAL) continue;
     
    126130    }
    127131  }
    128   free (abscorrfile);
    129132
    130133  // wait for the remote jobs to be completed
  • trunk/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r36481 r37807  
    5757  glob (line, 0, NULL, &pglob);
    5858
    59   coords.crpix1 = coords.crpix2 = 0.0;
    60   coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
    61   coords.pc1_1 = coords.pc2_2 = 1.0;
    62   coords.pc1_2 = coords.pc2_1 = 0.0;
    63   strcpy (coords.ctype, "DEC--TAN");
     59  InitCoords (&coords, "DEC--TAN");
    6460 
    6561  for (i = 0; i < pglob.gl_pathc; i++) {
Note: See TracChangeset for help on using the changeset viewer.