IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 27, 2015, 4:49:06 PM (11 years ago)
Author:
eugene
Message:

extensive work on relphot, relastro, uniphot, dvomerge aiming to the construction and calibration of PV3

Location:
trunk/Ohana
Files:
19 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libdvo/Makefile

    r38472 r38986  
    66HOME    =       $(ROOT)/src/libdvo
    77AUTO    =       $(ROOT)/src/libautocode
     8BIN     =       $(HOME)/bin
    89LIB     =       $(HOME)/lib
    910SRC     =       $(HOME)/src
     
    2223FULL_LDFLAGS  = $(BASE_LDFLAGS) -lFITS -lohana
    2324
    24 default: install
     25TEST_CFLAGS   = $(BASE_CFLAGS)
     26TEST_CPPFLAGS = $(BASE_CPPFLAGS)
     27TEST_LDFLAGS  = $(BASE_LDFLAGS) -ldvo -lFITS -lohana -ltap_ohana
     28
     29TESTPROG = tap_AstromOffsetMapIO
     30$(TESTPROG) : % : $(TESTBIN)/%
     31test: $(TESTPROG)
     32        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done
     33test.verbose: $(TESTPROG)
     34        for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 |& $(TESTHARNESS) -v; done
     35
    2536install: $(DESTLIB)/libdvo.a $(DESTLIB)/libdvo.$(DLLTYPE)
    2637libdvo: $(LIB)/libdvo.$(ARCH).a $(LIB)/libdvo.$(ARCH).$(DLLTYPE)
     
    183194        cd $(AUTO) && $(MAKE) clean
    184195
    185 TESTPROG =
    186 $(TESTPROG) : % : $(TESTBIN)/% $(OBJS)
    187 test: $(TESTPROG)
    188         for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done
    189 test.verbose: $(TESTPROG)
    190         for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 |& $(TESTHARNESS) -v; done
    191 
    192 .PRECIOUS: $(ASRC)/%.c
     196# .PRECIOUS: $(ASRC)/%.c
  • trunk/Ohana/src/libdvo/include/dvo.h

    r38649 r38986  
    171171  ID_PROPER            = 0x00000010, // star with large proper motion
    172172  ID_TRANSIENT         = 0x00000020, // identified as a non-periodic (stationary) transient
    173   ID_VARIABLE          = 0x00000040, // identified as a period variable
     173  ID_VARIABLE          = 0x00000040, // identified as a periodic variable
    174174  ID_ASTEROID          = 0x00000080, // identified with a known solar-system object (asteroid or other)
    175   // bits 0x00000100 - 0x00008000 are currently unused
     175  ID_STACK_ASTROM      = 0x00000100, // stack position used for astrometry
     176 
     177  // bits 0x00000200 - 0x00008000 are currently unused
    176178  ID_STAR_FIT_AVE      = 0x00010000, // average position fitted
    177179  ID_STAR_FIT_PM       = 0x00020000, // proper motion fitted
     
    813815  int sorted;                           /* is measure table average-sorted? (NOTE this is an int only because gfits_scan %t requires it) */
    814816
    815 
    816817  /* pointers for data manipulation */
    817818  off_t *found_t;
     
    819820
    820821  char *measureRank;
    821 //  off_t *image_t;
    822 //  off_t *mosaic_t;
    823 //  float *X_t;
    824 //  float *Y_t;
    825822  int   *nOwn_t; // relastro uses this to count owned detections per object
    826823
     
    840837int   gfits_db_free                PROTO((FITS_DB *db));
    841838
     839int gfits_fread_uncompressed (Catalog *catalog, FTable *ftable, char *nativeOrder, char VERBOSE);
     840
    842841char *libdvo_version (void);
    843842
     
    903902float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt);
    904903
     904int PhotSecfiltFlags (PhotCode *code, Average *average, SecFilt *secfilt);
     905int PhotNcode (PhotCode *code, Average *average, SecFilt *secfilt);
    905906int   PhotNphot (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
    906907float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
     
    969970void dvo_catalog_test (Catalog *catalog, int halt);
    970971
    971 int dvo_catalog_backup (Catalog *catalog, int primary);
    972 int dvo_catalog_unlink_backup (Catalog *catalog, int primary);
     972int dvo_catalog_backup (Catalog *catalog, char *suffix, int primary);
     973int dvo_catalog_unlink_backup (Catalog *catalog, char *suffix, int primary);
    973974
    974975/* catmode-specific APIs */
  • trunk/Ohana/src/libdvo/include/dvodb.h

    r38638 r38986  
    356356      IMAGE_FWHM_MEDIAN,
    357357      IMAGE_EXPTIME,
     358      IMAGE_EXPNAME_AS_INT,
    358359      IMAGE_NSTAR,
    359360      IMAGE_NCAL,
  • trunk/Ohana/src/libdvo/include/get_graphdata.h

    r31647 r38986  
    1111  double labelPadXm, labelPadYm, labelPadXp, labelPadYp;
    1212  double padXm, padXp, padYm, padYp;
     13  double fLabelRangeXm, fLabelRangeXp, fLabelRangeYm, fLabelRangeYp;
     14  double fMinorXm, fMinorXp, fMinorYm, fMinorYp;
    1315  Coords coords;
    1416  int flipeast, flipnorth;
  • trunk/Ohana/src/libdvo/include/libdvo_astro.h

    r38462 r38986  
    5656  float dX;
    5757  float dY;
    58   float **dXv;
    59   float **dYv;
     58  float *dXv;
     59  float *dYv;
    6060  unsigned int tableID;
    6161  unsigned int imageID;
     
    6565typedef struct {
    6666  int Nmap;
     67  int NMAP;
    6768  AstromOffsetMap **map;
    6869   int *imageIDtoTableSeq;
     
    160161
    161162/* in AstromOffsetMapIO.c */
    162 AstromOffsetTable *AstromOffsetMapLoad (char *filename, int VERBOSE);
     163AstromOffsetTable *AstromOffsetMapLoad (char *filename, int Nrows, int VERBOSE);
    163164int AstromOffsetMapSave (AstromOffsetTable *table, char *filename);
    164165AstromOffsetTable *AstromOffsetMapToTable(AstromOffsetMap_Disk_6x6 *map_disk, off_t Nmap);
    165166AstromOffsetMap_Disk_6x6 *AstromOffsetTableToMap(AstromOffsetTable *table, off_t *Nmap);
     167int AstromOffsetTableSetIDs (AstromOffsetTable *table);
     168AstromOffsetTable *AstromOffsetMapAppendToTable(AstromOffsetTable *table, AstromOffsetMap_Disk_6x6 *map_disk, off_t Nmap);
    166169
    167170/* in AstromOffsetMapOps.c */
    168171float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir);
    169 int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
     172int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir);
    170173
    171174/* in AstromOffsetMapUtils.c */
  • trunk/Ohana/src/libdvo/include/ps1_v5_defs.h

    r38441 r38986  
    2323StarPar_PS1_V5          *StarParInternalTo_PS1_V5 (StarPar *in, off_t Nvalues);
    2424
    25 GalPhot                 *GalPhot_PS1_V5_ToInternal (GalPhot_PS1_V5 *in, off_t Nvalues);
    26 GalPhot_PS1_V5         *GalPhotInternalTo_PS1_V5 (GalPhot *in, off_t Nvalues);
     25GalPhot                 *GalPhot_PS1_V5_R1_ToInternal (GalPhot_PS1_V5_R1 *in, off_t Nvalues);
     26GalPhot                 *GalPhot_PS1_V5_R0_ToInternal (GalPhot_PS1_V5_R0 *in, off_t Nvalues);
     27
     28GalPhot_PS1_V5_R1       *GalPhotInternalTo_PS1_V5_R1 (GalPhot *in, off_t Nvalues);
    2729
    2830PhotCode                *PhotCode_PS1_V5_To_Internal (PhotCode_PS1_V5 *in, off_t Nvalues);
  • trunk/Ohana/src/libdvo/src/AstromOffsetMapIO.c

    r38441 r38986  
    11# include "dvo.h"
    22
    3 AstromOffsetTable *AstromOffsetMapLoad (char *filename, int VERBOSE) {
     3AstromOffsetTable *AstromOffsetMapLoad (char *filename, int Nrows, int VERBOSE) {
    44
    55  off_t Nmap;
     
    77  Header header;
    88  Matrix matrix;
     9
    910  Header theader;
    1011  FTable ftable;
     12  ftable.header = &theader;
     13  ftable.buffer = NULL;
    1114
    1215  FILE *f = fopen (filename, "r");
     
    1720
    1821  /* load in table data */
    19   ftable.header = &theader;
    2022  if (!gfits_fread_header (f, &header)) {
    2123    if (VERBOSE) fprintf (stderr, "can't read Astrom Offset Map header\n");
     
    3032  }
    3133
    32   // for now, we only have one flavor (6x6)
    33 
    34   if (!gfits_fread_ftable (f, &ftable, "ASTROM_OFFSET_MAP_DISK_6x6")) {
    35     if (VERBOSE) fprintf (stderr, "can't read Astrom Offset Map table\n");
    36     gfits_free_header (&header);
    37     gfits_free_matrix (&matrix);
    38     fclose (f);
    39     return (NULL);
    40   }
    41   AstromOffsetMap_Disk_6x6 *map_disk = gfits_table_get_AstromOffsetMap_Disk_6x6 (&ftable, &Nmap, NULL, NULL);
    42   if (!map_disk) {
    43     fprintf (stderr, "ERROR: failed to read Astrom Offset Map\n");
    44     exit (2);
    45   }
    46 
    47   // AstromOffsetMap_Disk_6x6 *map_disk is an external format stored as an array of maps.
    48   // Convert the disk array of maps to then internal format in a rich structure:
    49   AstromOffsetTable *table = AstromOffsetMapToTable (map_disk, Nmap);
     34  // the output table is not what is stored in the FITS file.  read and convert
     35  // from the disk file format
     36  AstromOffsetTable *table = NULL;
     37
     38  // for now, we only have one flavor (6x6) of disk file format
     39
     40  // loop over the ftable reading blocks of 100k rows at a time
     41  if (Nrows) {
     42    if (!gfits_find_Xheader (f, ftable.header, "ASTROM_OFFSET_MAP_DISK_6x6")) myAbort ("problem 1");
     43    int NrowsTotal = ftable.header[0].Naxis[1];
     44    int Nblocks = (NrowsTotal % Nrows) ? (int) (NrowsTotal / Nrows) + 1 : (NrowsTotal / Nrows);
     45
     46    // allocate the full array up front.  passes through AstromOffsetMapAppendToTable
     47    // check the current allocation and will bump the allocation as needed.
     48    ALLOCATE (table, AstromOffsetTable, 1);
     49    ALLOCATE (table->map, AstromOffsetMap *, NrowsTotal);
     50    table->Nmap = 0;
     51    table->NMAP = NrowsTotal;
     52
     53    // on each call to gfits_fread_ftable_range, we need to reset the FILE pointer to the
     54    // beginning of the data block.  again this seems a little wrong.
     55    off_t diskStart = ftello (f);
     56
     57    int i;
     58    for (i = 0; i < Nblocks; i++) {
     59      if (!gfits_fread_ftable_range (f, FALSE, FALSE, &ftable, i*Nrows, Nrows)) myAbort ("problem 2");
     60   
     61      AstromOffsetMap_Disk_6x6 *map_disk = gfits_table_get_AstromOffsetMap_Disk_6x6 (&ftable, &Nmap, NULL, NULL);
     62      if (!map_disk) myAbort ("ERROR: failed to read Astrom Offset Map\n");
     63
     64      table = AstromOffsetMapAppendToTable (table, map_disk, Nmap);
     65
     66      // XXX this is kind of hack-ish: gfits_fread_ftable_range modifies Naxis[1] to the
     67      // number of rows actually read, but this makes a subsequent read invalid.  I'm
     68      // resetting the value of Naxis[1] before the next read to deal with this problem.
     69      // But is there a more consistent way to address this?
     70
     71      // Answer: the FTable structure could include information about the table
     72      // representation on disk, including start,Nrows values.  I'm not going to mess
     73      // around with that just now.
     74
     75      ftable.header[0].Naxis[1] = NrowsTotal;
     76      fseeko (f, diskStart, SEEK_SET);
     77    }
     78    AstromOffsetTableSetIDs (table);
     79    gfits_free_header (ftable.header);
     80    gfits_free_table  (&ftable);
     81  } else {
     82
     83    // convert the blocks into the equivalent table entries and append
     84    if (!gfits_fread_ftable (f, &ftable, "ASTROM_OFFSET_MAP_DISK_6x6")) {
     85      if (VERBOSE) fprintf (stderr, "can't read Astrom Offset Map table\n");
     86      gfits_free_header (&header);
     87      gfits_free_matrix (&matrix);
     88      fclose (f);
     89      return (NULL);
     90    }
     91    AstromOffsetMap_Disk_6x6 *map_disk = gfits_table_get_AstromOffsetMap_Disk_6x6 (&ftable, &Nmap, NULL, NULL);
     92    if (!map_disk) {
     93      fprintf (stderr, "ERROR: failed to read Astrom Offset Map\n");
     94      exit (2);
     95    }
     96
     97    // AstromOffsetMap_Disk_6x6 *map_disk is an external format stored as an array of maps.
     98    // Convert the disk array of maps to then internal format in a rich structure:
     99    table = AstromOffsetMapToTable (map_disk, Nmap);
     100    gfits_free_table  (&ftable);
     101  }
    50102
    51103  gfits_free_header (&theader);
    52104  gfits_free_matrix (&matrix);
    53   gfits_free_table  (&ftable);
    54105
    55106  return (table);
     
    135186    table->map[i][0].Nx           = map_disk[i].Nx;
    136187    table->map[i][0].Ny           = map_disk[i].Ny;
    137     table->map[i][0].tableID = map_disk[i].tableID;
    138     table->map[i][0].imageID = map_disk[i].imageID;
     188    table->map[i][0].tableID      = map_disk[i].tableID;
     189    table->map[i][0].imageID      = map_disk[i].imageID;
    139190   
    140191    // STORE THESE VALUES?
    141     table->map[i][0].dY           = map_disk[i].dX;
    142     table->map[i][0].dX           = map_disk[i].dY;
     192    table->map[i][0].dX           = map_disk[i].dX;
     193    table->map[i][0].dY           = map_disk[i].dY;
    143194
    144195    // since this was on disk, we obviously keep it
    145196    table->map[i][0].keep         = TRUE;
    146197
    147     ALLOCATE (table->map[i][0].dXv, float *, map_disk[i].Nx);
    148     ALLOCATE (table->map[i][0].dYv, float *, map_disk[i].Nx);
    149 
    150     for (j = 0; j < map_disk[i].Nx; j++) {
    151       ALLOCATE (table->map[i][0].dXv[j], float, map_disk[i].Ny);
    152       ALLOCATE (table->map[i][0].dYv[j], float, map_disk[i].Ny);
    153 
    154       for (k = 0; k < map_disk[i].Ny; k++) {
    155         table->map[i][0].dXv[j][k] = map_disk[i].dXv[j][k];
    156         table->map[i][0].dYv[j][k] = map_disk[i].dYv[j][k];
     198    int Nx = table->map[i][0].Nx;
     199    int Ny = table->map[i][0].Ny;
     200
     201    ALLOCATE (table->map[i][0].dXv, float, Nx*Ny);
     202    ALLOCATE (table->map[i][0].dYv, float, Nx*Ny);
     203
     204    for (j = 0; j < Nx; j++) {
     205      for (k = 0; k < Ny; k++) {
     206        table->map[i][0].dXv[j + k*Nx] = map_disk[i].dXv[j][k];
     207        table->map[i][0].dYv[j + k*Nx] = map_disk[i].dYv[j][k];
    157208      }
    158209    }
     
    182233    map_disk[Ndisk].dY      = table->map[i][0].dY;
    183234
    184    
    185 
    186     for (j = 0; j < map_disk[Ndisk].Nx; j++) {
    187       for (k = 0; k < map_disk[Ndisk].Ny; k++) {
    188         map_disk[Ndisk].dXv[j][k] = table->map[i][0].dXv[j][k];
    189         map_disk[Ndisk].dYv[j][k] = table->map[i][0].dYv[j][k];
     235    int Nx = table->map[i][0].Nx;
     236    int Ny = table->map[i][0].Ny;
     237
     238    for (j = 0; j < Nx; j++) {
     239      for (k = 0; k < Ny; k++) {
     240        map_disk[Ndisk].dXv[j][k] = table->map[i][0].dXv[j + k*Nx];
     241        map_disk[Ndisk].dYv[j][k] = table->map[i][0].dYv[j + k*Nx];
    190242      }
    191243      for (k = map_disk[Ndisk].Ny; k < 6; k++) {
     
    206258}
    207259
     260AstromOffsetTable *AstromOffsetMapAppendToTable(AstromOffsetTable *table, AstromOffsetMap_Disk_6x6 *map_disk, off_t Nmap) {
     261
     262  int i, j, k, Nstart;
     263
     264  if (table == NULL) {
     265    ALLOCATE (table, AstromOffsetTable, 1);
     266    Nstart = 0;
     267    table->Nmap = Nmap;
     268    ALLOCATE (table->map, AstromOffsetMap *, Nmap);
     269  } else {
     270    Nstart = table->Nmap;
     271    if (table->Nmap + Nmap > table->NMAP) {
     272      table->NMAP = table->Nmap + Nmap;
     273      REALLOCATE (table->map, AstromOffsetMap *, table->NMAP);
     274    }
     275    table->Nmap += Nmap;
     276  }
     277
     278  // append map values (this allocates just the area needed for each image, not the
     279  // full 6x6, saving some memory while doing the analysis)
     280  for (i = 0; i < Nmap; i++) {
     281    int N = i + Nstart;
     282    ALLOCATE (table->map[N], AstromOffsetMap, 1);
     283
     284    table->map[N][0].Nx           = map_disk[i].Nx;
     285    table->map[N][0].Ny           = map_disk[i].Ny;
     286    table->map[N][0].tableID      = map_disk[i].tableID;
     287    table->map[N][0].imageID      = map_disk[i].imageID;
     288   
     289    // STORE THESE VALUES?
     290    table->map[N][0].dX           = map_disk[i].dX;
     291    table->map[N][0].dY           = map_disk[i].dY;
     292
     293    // since this was on disk, we obviously keep it
     294    table->map[N][0].keep         = TRUE;
     295
     296    int Nx = table->map[N][0].Nx;
     297    int Ny = table->map[N][0].Ny;
     298
     299    ALLOCATE (table->map[N][0].dXv, float, Nx*Ny);
     300    ALLOCATE (table->map[N][0].dYv, float, Nx*Ny);
     301
     302    for (j = 0; j < Nx; j++) {
     303      for (k = 0; k < Ny; k++) {
     304        table->map[N][0].dXv[j + k*Nx] = map_disk[i].dXv[j][k];
     305        table->map[N][0].dYv[j + k*Nx] = map_disk[i].dYv[j][k];
     306      }
     307    }
     308  }
     309  return table;
     310}
     311
     312int AstromOffsetTableSetIDs (AstromOffsetTable *table) {
     313
     314  int i;
     315
     316  // find the max value of imageID
     317  int MaxTableID = 0;
     318  int MaxImageID = 0;
     319  for (i = 0; i < table->Nmap; i++) {
     320    MaxTableID = MAX(table->map[i][0].tableID, MaxTableID);
     321    MaxImageID = MAX(table->map[i][0].imageID, MaxImageID);
     322  }
     323  table->MaxTableID = MaxTableID;
     324  table->MaxImageID = MaxImageID;
     325
     326  // generate the index and init values to -1
     327  ALLOCATE (table->imageIDtoTableSeq, int, MaxImageID + 1);
     328  for (i = 0; i <= MaxImageID; i++) {
     329    table->imageIDtoTableSeq[i] = -1;
     330  }
     331
     332  // assign the ID values
     333  for (i = 0; i < table->Nmap; i++) {
     334    int ImageID = table->map[i][0].imageID;
     335    myAssert (table->imageIDtoTableSeq[ImageID] == -1, "oops, duplicate image IDs");
     336    table->imageIDtoTableSeq[ImageID] = i;
     337  }
     338  return TRUE;
     339}
  • trunk/Ohana/src/libdvo/src/AstromOffsetMapOps.c

    r37807 r38986  
    66int dump_map_data (float *x, float *y, float *f, int Npts, char *filename);
    77int AstromOffsetMapFit_Chisq (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
    8 int AstromOffsetMapFit_Median (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
     8int AstromOffsetMapFit_Mean (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir);
    99
    1010float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir) {
     
    1212  // given x,y find the offset (x-direction) at that location from the map
    1313
    14   float **V = xdir ? map->dXv : map->dYv;
     14  int Nx = map->Nx;
     15  int Ny = map->Ny;
     16
     17  float *V = xdir ? map->dXv : map->dYv;
    1518
    1619  // if there is no spatial information, the value at the point is the value in the map
    17   if ((map->Nx == 1) && (map->Ny == 1)) return V[0][0];
     20  if ((Nx == 1) && (Ny == 1)) return V[0];
    1821
    1922  // if there is no spatial information in 1D, the interpolation is 1D
    20   if (map->Nx == 1) {
     23  if (Nx == 1) {
    2124    float ymo = y * map->dY - 0.5;
    2225    int   ymi = floor(ymo);
    23     ymi = MAX(0,MIN(map->Ny - 2, ymi)); // force range of ymi to be 0,Ny-2 (Ny must be > 1)
     26    ymi = MAX(0,MIN(Ny - 2, ymi)); // force range of ymi to be 0,Ny-2 (Ny must be > 1)
    2427
    2528    float ymf = ymo - ymi;
    2629
    27     float value = ymf * V[0][ymi+1] + (1.0 - ymf) * V[0][ymi];
     30    float value = ymf * V[ymi+1] + (1.0 - ymf) * V[ymi];
    2831    return value;
    2932  }
    3033
    3134  // if there is no spatial information in 1D, the interpolation is 1D
    32   if (map->Ny == 1) {
     35  if (Ny == 1) {
    3336    float xmo = x * map->dX - 0.5;
    3437    int   xmi = floor(xmo);
    35     xmi = MAX(0,MIN(map->Nx - 2, xmi)); // force range of ymi to be 0,Nx-2  (Nx must be > 1)
     38    xmi = MAX(0,MIN(Nx - 2, xmi)); // force range of ymi to be 0,Nx-2  (Nx must be > 1)
    3639
    3740    float xmf = xmo - xmi;
    3841
    39     float value = xmf * V[xmi+1][0] + (1.0 - xmf) * V[xmi][0];
     42    float value = xmf * V[xmi+1] + (1.0 - xmf) * V[xmi];
    4043    return value;
    4144  }
     
    4548  float xmo = x * map->dX - 0.5;
    4649  int   xmi = floor(xmo);
    47   xmi = MAX(0,MIN(map->Nx - 2, xmi)); // force range of ymi to be 0,Nx-1
     50  xmi = MAX(0,MIN(Nx - 2, xmi)); // force range of ymi to be 0,Nx-1
    4851  float xmf = xmo - xmi;
    4952
    5053  float ymo = y * map->dY - 0.5;
    5154  int   ymi = floor(ymo);
    52   ymi = MAX(0,MIN(map->Ny - 2, ymi)); // force range of ymi to be 0,Ny-2
     55  ymi = MAX(0,MIN(Ny - 2, ymi)); // force range of ymi to be 0,Ny-2
    5356  float ymf = ymo - ymi;
    5457
    55   float V00 = V[xmi+0][ymi+0];
    56   float V01 = V[xmi+0][ymi+1];
    57   float V10 = V[xmi+1][ymi+0];
    58   float V11 = V[xmi+1][ymi+1];
     58  float V00 = V[xmi+0 + (ymi+0)*Nx];
     59  float V01 = V[xmi+0 + (ymi+1)*Nx];
     60  float V10 = V[xmi+1 + (ymi+0)*Nx];
     61  float V11 = V[xmi+1 + (ymi+1)*Nx];
    5962
    6063  float Vx0 = V10*xmf + V00*(1.0 - xmf);
     
    6568}
    6669
    67 int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
    68 
    69   int status = AstromOffsetMapFit_Median (map, x, y, f, Npts, xdir);
     70int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir) {
     71
     72  int status = AstromOffsetMapFit_Mean (map, x, y, f, df, Npts, xdir);
    7073  return status;
    7174}
     
    7881
    7982  // choose to map direction:
    80   float **V = xdir ? map->dXv : map->dYv;
     83  float *Vptr = xdir ? map->dXv : map->dYv;
    8184
    8285  // special cases:
     
    8891
    8992    vstats_getstats_f (f, NULL, NULL, Npts, &stats);
    90     V[0][0] = stats.mean;
     93    Vptr[0] = stats.mean;
    9194    return TRUE;
    9295  }
     
    352355    for (iy = 0; iy < Ny; iy++) {
    353356      int I = ix + Nx * iy;
    354       V[ix][iy] = B[I][0];
     357      Vptr[I] = B[I][0];
    355358      // error[ix][iy] = sqrt(A[I][I]);
    356359    }
     
    371374// given (x,y),value vector sets, choose the map that minimizes the difference between
    372375// the values and bilinear interpolation of the map
    373 int AstromOffsetMapFit_Median (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir) {
     376int AstromOffsetMapFit_Mean (AstromOffsetMap *map, float *x, float *y, float *f, float *df, int Npts, int xdir) {
    374377
    375378  int i, ix, iy;
    376379
    377380  // choose to map direction:
    378   float **V = xdir ? map->dXv : map->dYv;
     381  float *Vptr = xdir ? map->dXv : map->dYv;
    379382
    380383  // measure clipped median in each bin
     
    386389  int Npix = Nx*Ny;
    387390
    388   double **values;
     391  double **values, **dvalues;
    389392  int    *Nvalue;
    390393  ALLOCATE (Nvalue, int, Npix);
    391394  ALLOCATE (values, double *, Npix);
     395  ALLOCATE (dvalues, double *, Npix);
    392396  for (i = 0; i < Npix; i++) {
    393397    ALLOCATE (values[i], double, Npts);
     398    ALLOCATE (dvalues[i], double, Npts);
    394399    Nvalue[i] = 0;
    395400  }
     
    400405    // data value & weight for this point
    401406    if (!isfinite(f[i])) continue;
     407    if (df && !isfinite(df[i])) continue;
     408    if (df && df[i] == 0.0) continue;
    402409
    403410    // if (mask && (mask[i] & maskValue)) continue;
     
    414421    int N = Nvalue[I];
    415422    values[I][N] = f[i];
     423    dvalues[I][N] = df ? df[i] : 1.0;
    416424    Nvalue[I] ++;
    417425  }   
     
    421429      int I = ix + Nx * iy;
    422430      if (Nvalue[I] > 5) {
    423         vstats_getstats (values[I], NULL, NULL, Nvalue[I], &stats);
    424         V[ix][iy] = stats.mean;
     431        vstats_getstats (values[I], dvalues[I], NULL, Nvalue[I], &stats);
     432        Vptr[I] = stats.mean;
    425433      } else {
    426         V[ix][iy] = NAN;
     434        Vptr[I] = NAN;
    427435      }
    428436    }
     
    432440  for (i = 0; i < Npix; i++) {
    433441    free (values[i]);
     442    free (dvalues[i]);
    434443  }   
    435444  free (values);
     445  free (dvalues);
    436446  free (Nvalue);
    437447
     
    453463  int ix, iy;
    454464
    455   float **Vfix = NULL;
    456   ALLOCATE (Vfix, float *, Nx);
     465  float *Vfix = NULL;
     466  ALLOCATE (Vfix, float, Nx*Ny);
    457467  for (ix = 0; ix < Nx; ix++) {
    458     ALLOCATE (Vfix[ix], float, Ny);
    459     for (iy = 0; iy < Ny; iy++) {
    460       Vfix[ix][iy] = NAN;
     468    for (iy = 0; iy < Ny; iy++) {
     469      Vfix[ix + iy*Nx] = NAN;
    461470    }
    462471  }
     
    468477  for (ix = 0; ix < Nx; ix++) {
    469478    for (iy = 0; iy < Ny; iy++) {
    470       float value = xdir ? map->dXv[ix][iy] : map->dYv[ix][iy];
     479      int I = ix + iy*Nx;
     480      float value = xdir ? map->dXv[I] : map->dYv[I];
    471481      if (isnan(value)) continue;
    472482      mean += value;
     
    479489  for (ix = 0; ix < Nx; ix++) {
    480490    for (iy = 0; iy < Ny; iy++) {
    481 
    482       float value = xdir ? map->dXv[ix][iy] : map->dYv[ix][iy];
     491      int I = ix + iy*Nx;
     492      float value = xdir ? map->dXv[I] : map->dYv[I];
    483493      if (!isnan(value)) {
    484         Vfix[ix][iy] = value;
     494        Vfix[I] = value;
    485495        continue;
    486496      }
     
    499509          if (ny < 0) continue;
    500510          if (ny >= Ny) continue;
    501           float value = xdir ? map->dXv[nx][ny] : map->dYv[nx][ny];
     511          int I = ix + iy*Nx;
     512          float value = xdir ? map->dXv[I] : map->dYv[I];
    502513          if (isnan(value)) continue;
    503514
     
    508519      // if there are no valid (non-NAN) local pixels, use global mean
    509520      meanLocal = (npixLocal > 0.0) ? meanLocal / npixLocal : mean;
    510       Vfix[ix][iy] = meanLocal;
     521      Vfix[I] = meanLocal;
    511522    }
    512523  }
     
    515526  for (ix = 0; ix < Ny; ix++) {
    516527    for (iy = 0; iy < Ny; iy++) {
     528      int I = ix + iy*Nx;
    517529      if (xdir) {
    518         map->dXv[ix][iy] = Vfix[ix][iy];
     530        map->dXv[I] = Vfix[I];
    519531      } else {
    520         map->dYv[ix][iy] = Vfix[ix][iy];
    521       }
    522     }
    523   }
    524   for (ix = 0; ix < Nx; ix++) {
    525     free (Vfix[ix]);
     532        map->dYv[I] = Vfix[I];
     533      }
     534    }
    526535  }
    527536  free (Vfix);
  • trunk/Ohana/src/libdvo/src/AstromOffsetMapUtils.c

    r37807 r38986  
    3636  map->keep = TRUE; // output map size
    3737
    38   ALLOCATE (map->dXv, float *, map->Nx);
    39   ALLOCATE (map->dYv, float *, map->Nx);
    40 
    41   int j, k;
    42   for (j = 0; j < map->Nx; j++) {
    43     ALLOCATE (map->dXv[j], float, map->Ny);
    44     ALLOCATE (map->dYv[j], float, map->Ny);
    45 
    46     for (k = 0; k < map->Ny; k++) {
    47       map->dXv[j][k] = 0.0;
    48       map->dYv[j][k] = 0.0;
     38  ALLOCATE (map->dXv, float, Nx*Ny);
     39  ALLOCATE (map->dYv, float, Nx*Ny);
     40
     41  int j, k;
     42  for (j = 0; j < Nx; j++) {
     43    for (k = 0; k < Ny; k++) {
     44      map->dXv[j + k*Nx] = 0.0;
     45      map->dYv[j + k*Nx] = 0.0;
    4946    }
    5047  }
     
    5653
    5754  if (!map) return;
    58 
    59   int j;
    60   for (j = 0; j < map->Nx; j++) {
    61     if (map->dXv) free (map->dXv[j]);
    62     if (map->dYv) free (map->dYv[j]);
    63   }
    6455
    6556  free (map->dXv);
     
    7667
    7768  // rather than try to figure out how to resize, and free/allocate, lets just free the old arrays and make new ones
    78   for (j = 0; j < map->Nx; j++) {
    79     if (map->dXv) free (map->dXv[j]);
    80     if (map->dYv) free (map->dYv[j]);
    81   }
    8269  free (map->dXv);
    8370  free (map->dYv);
     
    9077  map->keep = TRUE; // output map size
    9178
    92   ALLOCATE (map->dXv, float *, map->Nx);
    93   ALLOCATE (map->dYv, float *, map->Nx);
    94 
    95   for (j = 0; j < map->Nx; j++) {
    96     ALLOCATE (map->dXv[j], float, map->Ny);
    97     ALLOCATE (map->dYv[j], float, map->Ny);
    98 
    99     for (k = 0; k < map->Ny; k++) {
    100       map->dXv[j][k] = 0.0;
    101       map->dYv[j][k] = 0.0;
     79  ALLOCATE (map->dXv, float, Nx*Ny);
     80  ALLOCATE (map->dYv, float, Nx*Ny);
     81
     82  for (j = 0; j < Nx; j++) {
     83    for (k = 0; k < Ny; k++) {
     84      map->dXv[j + k*Nx] = 0.0;
     85      map->dYv[j + k*Nx] = 0.0;
    10286    }
    10387  }
     
    116100  tgt->tableID = map->tableID;
    117101
    118   int j, k;
    119   for (j = 0; j < tgt->Nx; j++) {
    120     for (k = 0; k < map->Ny; k++) {
    121       tgt->dXv[j][k] = map->dXv[j][k];
    122       tgt->dYv[j][k] = map->dYv[j][k];
     102  int Nx = map->Nx;
     103  int Ny = map->Ny;
     104
     105  int j, k;
     106  for (j = 0; j < Nx; j++) {
     107    for (k = 0; k < Ny; k++) {
     108      tgt->dXv[j + k*Nx] = map->dXv[j + k*Nx];
     109      tgt->dYv[j + k*Nx] = map->dYv[j + k*Nx];
    123110    }
    124111  }
     
    139126  tgt->keep = src->keep;
    140127
    141   int j, k;
    142   for (j = 0; j < tgt->Nx; j++) {
    143     for (k = 0; k < src->Ny; k++) {
    144       tgt->dXv[j][k] = src->dXv[j][k];
    145       tgt->dYv[j][k] = src->dYv[j][k];
     128  int Nx = src->dX;
     129  int Ny = src->dY;
     130
     131  int j, k;
     132  for (j = 0; j < Nx; j++) {
     133    for (k = 0; k < Ny; k++) {
     134      tgt->dXv[j + k*Nx] = src->dXv[j + k*Nx];
     135      tgt->dYv[j + k*Nx] = src->dYv[j + k*Nx];
    146136    }
    147137  }
     
    153143  if (!table) return;
    154144
    155   int i, j;
     145  int i;
    156146  for (i = 0; i < table->Nmap; i++) {
    157     for (j = 0; j < table->map[i][0].Nx; j++) {
    158       free (table->map[i][0].dXv[j]);
    159       free (table->map[i][0].dYv[j]);
    160     }
    161147    if (!table->map[i]) continue;
    162148    FREE (table->map[i][0].dXv);
     
    260246  }
    261247
     248  int Nx = map->Nx;
     249  int Ny = map->Ny;
     250
    262251  fprintf (f, "imageID: %d, tableID: %d (dX: %f, dY: %f), keep: %d\n", map->imageID, map->tableID, map->dX, map->dY, map->keep);
    263252  int ix, iy;
    264253  fprintf (f, "dXv map:\n");
    265   for (ix = 0; ix < map->Nx; ix++) {
    266     for (iy = 0; iy < map->Ny; iy++) {
    267       fprintf (f, "%9.5f ", map->dXv[ix][iy]);
     254  for (ix = 0; ix < Nx; ix++) {
     255    for (iy = 0; iy < Ny; iy++) {
     256      fprintf (f, "%9.5f ", map->dXv[ix + iy*Nx]);
    268257    }
    269258    fprintf (f, "\n");
    270259  }
    271260  fprintf (f, "dYv map:\n");
    272   for (ix = 0; ix < map->Nx; ix++) {
    273     for (iy = 0; iy < map->Ny; iy++) {
    274       fprintf (f, "%9.5f ", map->dYv[ix][iy]);
     261  for (ix = 0; ix < Nx; ix++) {
     262    for (iy = 0; iy < Ny; iy++) {
     263      fprintf (f, "%9.5f ", map->dYv[ix + iy*Nx]);
    275264    }
    276265    fprintf (f, "\n");
  • trunk/Ohana/src/libdvo/src/LoadImages.c

    r38553 r38986  
    8585
    8686  if (table) AstromOffsetTableFree(table);
    87   table = AstromOffsetMapLoad (mapfile, FALSE);
     87  table = AstromOffsetMapLoad (mapfile, 100000, FALSE);
    8888
    8989  // assign images.coords.offsetMap -> table->map[i]
  • trunk/Ohana/src/libdvo/src/dbExtractImages.c

    r37807 r38986  
    233233      value.Flt = image[N].exptime;
    234234      break;
     235
     236    case IMAGE_EXPNAME_AS_INT:
     237      // XXX NOTE this does not handle gpc2 images
     238      if ((image[N].name[0] == 'o') && (image[N].name[5] == 'g') && (image[N].name[10] == 'o')) {
     239        int mjd  = atoi(&image[N].name[1]);
     240        int Nexp = atoi(&image[N].name[6]);
     241        value.Int = mjd * 10000 + Nexp;
     242      }
     243      break;
     244
    235245    case IMAGE_SIDTIME:
    236246      value.Flt = image[N].sidtime;
  • trunk/Ohana/src/libdvo/src/dbExtractMeasures.c

    r38635 r38986  
    241241          break;
    242242
    243         case MAG_OPTION_STDEV:
    244         case MAG_OPTION_CHISQ:
    245         case MAG_OPTION_MIN:
    246         case MAG_OPTION_MAX:
    247         case MAG_OPTION_NCODE:
    248         case MAG_OPTION_NPHOT:
    249         case MAG_OPTION_UC_DIST:
    250         case MAG_OPTION_FLAGS:
     243          // the following are all values which are come from the secfit table
     244        case MAG_OPTION_STDEV:   { value.Flt = PhotMstdev (equiv, average, secfilt, field->magClass, field->magSource); break; }
     245        case MAG_OPTION_CHISQ:   { value.Flt = PhotXm (equiv, average, secfilt); break; }
     246        case MAG_OPTION_MIN:     { value.Flt = PhotMmin (equiv, average, secfilt); break;}
     247        case MAG_OPTION_MAX:     { value.Flt = PhotMmax (equiv, average, secfilt); break;}
     248        case MAG_OPTION_NCODE:   { value.Int = PhotNcode (equiv, average, secfilt); break; }
     249        case MAG_OPTION_NPHOT:   { value.Int = PhotNphot (equiv, average, secfilt, field->magClass, field->magSource); break; }
     250        case MAG_OPTION_UC_DIST: { value.Flt = PhotUCdist (equiv, average, secfilt); break; }
     251        case MAG_OPTION_FLAGS:   { value.Int = PhotSecfiltFlags (equiv, average, secfilt); break; }
     252         
     253          // the following values come from the mean lensobj table
    251254        case MAG_OPTION_X11_SM_OBJ:
    252255        case MAG_OPTION_X12_SM_OBJ:
  • trunk/Ohana/src/libdvo/src/dbFields.c

    r38638 r38986  
    356356    dvoMagSourceType source = GetMagSource (word);
    357357    if (source != MAG_SRC_NONE) {
     358      // if mySource is already set, then we have two 'source' elements (an error)
    358359      if (mySource != MAG_SRC_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
    359360      mySource = source;
     
    364365    dvoMagLevelType level = GetMagLevel (word);
    365366    if (level != MAG_LEVEL_NONE) {
     367      // if myLevel is already set, then we have two 'level' elements (an error)
    366368      if (myLevel != MAG_LEVEL_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
    367369      myLevel = level;
     
    372374    dvoMagClassType class = GetMagClass (word);
    373375    if (class != MAG_CLASS_NONE) {
     376      // if myClass is already set, then we have two 'class' elements (an error)
    374377      if (myClass != MAG_CLASS_NONE) { fprintf (stderr, "invalid selection %s in %s\n", word, fieldName); free (word); return FALSE; }
    375378      myClass = class;
     
    380383    dvoMagOptionType option = GetMagOption (word);
    381384    if (option != MAG_OPTION_NONE) {
    382       // some combinations are OK: mag + err -> err
    383       if ((myOption == MAG_OPTION_MAG) && (option == MAG_OPTION_ERR)) {
     385      // if myClass is already set, then we have two 'class' elements
     386      // this is an error unless the request was of the form mag:value
     387      // if so, then code->type will be PHOT_MAG
     388
     389      if (code->type == PHOT_MAG) {
     390        // mag:err -> magerr
     391        if ((myOption == MAG_OPTION_MAG) && (option == MAG_OPTION_ERR)) {
     392          myOption = MAG_OPTION_ERR;
     393          ptr = skipword (ptr);
     394          continue;
     395        }
     396        // flux:err -> fluxerr
     397        if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_ERR)) {
     398          myOption = MAG_OPTION_FLUX_ERR;
     399          ptr = skipword (ptr);
     400          continue;
     401        }
    384402        myOption = option;
    385         ptr = skipword (ptr);
    386         continue;
    387       }
    388       // some combinations are OK: err + mag -> err
    389       if ((myOption == MAG_OPTION_ERR) && (option == MAG_OPTION_MAG)) {
    390         ptr = skipword (ptr);
    391         continue;
    392       }
    393       // some combinations are OK: flux + err -> FLUX_ERR
    394       if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_ERR)) {
    395         myOption = MAG_OPTION_FLUX_ERR;
    396         ptr = skipword (ptr);
    397         continue;
    398       }
    399       // some combinations are OK: err + flux -> FLUX_ERR
    400       if ((myOption == MAG_OPTION_ERR) && (option == MAG_OPTION_FLUX)) {
    401         myOption = MAG_OPTION_FLUX_ERR;
    402         ptr = skipword (ptr);
    403         continue;
    404       }
    405       // some combinations are OK: flux + fluxerr -> FLUX_ERR
    406       if ((myOption == MAG_OPTION_FLUX) && (option == MAG_OPTION_FLUX_ERR)) {
    407         myOption = MAG_OPTION_FLUX_ERR;
    408         ptr = skipword (ptr);
    409         continue;
    410       }
    411       // some combinations are OK: fluxerr + flux -> FLUX_ERR
    412       if ((myOption == MAG_OPTION_FLUX_ERR) && (option == MAG_OPTION_FLUX)) {
    413         myOption = MAG_OPTION_FLUX_ERR;
    414403        ptr = skipword (ptr);
    415404        continue;
     
    815804  if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  OPIHI_INT);
    816805  if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   OPIHI_FLT);
     806  if (!strcasecmp (fieldName, "expname"  )) ESCAPE (IMAGE_EXPNAME_AS_INT, OPIHI_INT);
    817807  if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   OPIHI_FLT);
    818808
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r38553 r38986  
    200200  average->catID           = 0;
    201201  average->extID           = 0;
    202   average->extIDgc         = 0;
     202
     203  average->uRgal           = NAN;
     204  average->uDgal           = NAN;
    203205}
    204206
     
    600602
    601603  /* pointers for data manipulation */
    602   // catalog[0].X_t = NULL;
    603   // catalog[0].Y_t = NULL;
    604604  catalog[0].nOwn_t = NULL;
    605605  catalog[0].found_t = NULL;
    606   // catalog[0].image_t = NULL;
    607   // catalog[0].mosaic_t = NULL;
    608606  catalog[0].foundWarp_t = NULL;
     607  catalog[0].measureRank = NULL;
    609608}
    610609
     
    922921void dvo_catalog_free (Catalog *catalog) {
    923922
     923  if (!catalog) return;
     924
    924925  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    925926
     
    10441045
    10451046// make a backup of this catalog (including the measure, secfilt, and missing tables as needed)
    1046 int dvo_catalog_backup (Catalog *catalog, int primary) {
     1047int dvo_catalog_backup (Catalog *catalog, char *suffix, int primary) {
    10471048
    10481049  // skip empty cpt files
     
    10521053
    10531054  char tmpfilename[DVO_MAX_PATH];
    1054   int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s~", catalog->filename);
     1055  int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s%s", catalog->filename, suffix);
    10551056  if (status >= DVO_MAX_PATH) {
    10561057    fprintf (stderr, "path name too long: %s\n", catalog->filename);
     
    10671068  }
    10681069
     1070  // play it safe: do not overwrite an existing backup file
     1071  struct stat fileStats;
     1072  status = stat (tmpfilename, &fileStats);
     1073  if (!status) {
     1074    fprintf (stderr, "ERROR: backup file %s already exists, exiting\n", tmpfilename);
     1075    return FALSE;
     1076  }
     1077 
     1078  // some error accessing the file.  there is only one acceptable error: file not found
     1079  if (status && (errno != ENOENT)) {
     1080    perror ("problem with output target");
     1081    return FALSE;
     1082  }
     1083
    10691084  status = rename (catalog->filename, tmpfilename);
    10701085  if (status) {
     
    10851100  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    10861101    if (catalog[0].measure_catalog != NULL) {
    1087       if (!dvo_catalog_backup (catalog[0].measure_catalog, FALSE)) {
     1102      if (!dvo_catalog_backup (catalog[0].measure_catalog, suffix, FALSE)) {
    10881103        return FALSE;
    10891104      }
    10901105    }
    10911106    if (catalog[0].missing_catalog != NULL) {
    1092       if (!dvo_catalog_backup (catalog[0].missing_catalog, FALSE)) {
     1107      if (!dvo_catalog_backup (catalog[0].missing_catalog, suffix, FALSE)) {
    10931108        return FALSE;
    10941109      }
    10951110    }
    10961111    if (catalog[0].secfilt_catalog != NULL) {
    1097       if (!dvo_catalog_backup (catalog[0].secfilt_catalog, FALSE)) {
     1112      if (!dvo_catalog_backup (catalog[0].secfilt_catalog, suffix, FALSE)) {
    10981113        return FALSE;
    10991114      }
     
    11041119        status = dvo_catalog_lock (catalog[0].lensing_catalog, lockmode);
    11051120      } else {
    1106         if (!dvo_catalog_backup (catalog[0].lensing_catalog, FALSE)) {
     1121        if (!dvo_catalog_backup (catalog[0].lensing_catalog, suffix, FALSE)) {
    11071122          return FALSE;
    11081123        }
     
    11141129        status = dvo_catalog_lock (catalog[0].lensobj_catalog, lockmode);
    11151130      } else {
    1116         if (!dvo_catalog_backup (catalog[0].lensobj_catalog, FALSE)) {
     1131        if (!dvo_catalog_backup (catalog[0].lensobj_catalog, suffix, FALSE)) {
    11171132          return FALSE;
    11181133        }
     
    11241139        status = dvo_catalog_lock (catalog[0].starpar_catalog, lockmode);
    11251140      } else {
    1126         if (!dvo_catalog_backup (catalog[0].starpar_catalog, FALSE)) {
     1141        if (!dvo_catalog_backup (catalog[0].starpar_catalog, suffix, FALSE)) {
    11271142          return FALSE;
    11281143        }
     
    11341149        status = dvo_catalog_lock (catalog[0].galphot_catalog, lockmode);
    11351150      } else {
    1136         if (!dvo_catalog_backup (catalog[0].galphot_catalog, FALSE)) {
     1151        if (!dvo_catalog_backup (catalog[0].galphot_catalog, suffix, FALSE)) {
    11371152          return FALSE;
    11381153        }
     
    11441159
    11451160// make a backup of this catalog (including the measure, secfilt, and missing tables as needed)
    1146 int dvo_catalog_unlink_backup (Catalog *catalog, int primary) {
     1161int dvo_catalog_unlink_backup (Catalog *catalog, char *suffix, int primary) {
    11471162
    11481163  if (primary && !catalog->Naverage_disk) {
     
    11521167
    11531168  char tmpfilename[DVO_MAX_PATH];
    1154   int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s~", catalog->filename);
     1169  int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s%s", catalog->filename, suffix);
    11551170  if (status >= DVO_MAX_PATH) {
    11561171    fprintf (stderr, "path name too long: %s\n", catalog->filename);
     
    11681183  if (catalog[0].catmode == DVO_MODE_SPLIT) {
    11691184    if (catalog[0].measure_catalog != NULL) {
    1170       if (!dvo_catalog_unlink_backup (catalog[0].measure_catalog, FALSE)) {
     1185      if (!dvo_catalog_unlink_backup (catalog[0].measure_catalog, suffix, FALSE)) {
    11711186        outStatus = FALSE;
    11721187      }
    11731188    }
    11741189    if (catalog[0].missing_catalog != NULL) {
    1175       if (!dvo_catalog_unlink_backup (catalog[0].missing_catalog, FALSE)) {
     1190      if (!dvo_catalog_unlink_backup (catalog[0].missing_catalog, suffix, FALSE)) {
    11761191        outStatus = FALSE;
    11771192      }
    11781193    }
    11791194    if (catalog[0].secfilt_catalog != NULL) {
    1180       if (!dvo_catalog_unlink_backup (catalog[0].secfilt_catalog, FALSE)) {
     1195      if (!dvo_catalog_unlink_backup (catalog[0].secfilt_catalog, suffix, FALSE)) {
    11811196        outStatus = FALSE;
    11821197      }
    11831198    }
    11841199    if ((catalog[0].lensing_catalog != NULL) && (catalog[0].Nlensing_disk > 0)) {
    1185       if (!dvo_catalog_unlink_backup (catalog[0].lensing_catalog, FALSE)) {
     1200      if (!dvo_catalog_unlink_backup (catalog[0].lensing_catalog, suffix, FALSE)) {
    11861201        outStatus = FALSE;
    11871202      }
    11881203    }
    11891204    if ((catalog[0].lensobj_catalog != NULL) && (catalog[0].Nlensobj_disk > 0)) {
    1190       if (!dvo_catalog_unlink_backup (catalog[0].lensobj_catalog, FALSE)) {
     1205      if (!dvo_catalog_unlink_backup (catalog[0].lensobj_catalog, suffix, FALSE)) {
    11911206        outStatus = FALSE;
    11921207      }
    11931208    }
    11941209    if ((catalog[0].starpar_catalog != NULL) && (catalog[0].Nstarpar_disk > 0)) {
    1195       if (!dvo_catalog_unlink_backup (catalog[0].starpar_catalog, FALSE)) {
     1210      if (!dvo_catalog_unlink_backup (catalog[0].starpar_catalog, suffix, FALSE)) {
    11961211        outStatus = FALSE;
    11971212      }
    11981213    }
    11991214    if ((catalog[0].galphot_catalog != NULL) && (catalog[0].Ngalphot_disk > 0)) {
    1200       if (!dvo_catalog_unlink_backup (catalog[0].galphot_catalog, FALSE)) {
     1215      if (!dvo_catalog_unlink_backup (catalog[0].galphot_catalog, suffix, FALSE)) {
    12011216        outStatus = FALSE;
    12021217      }
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r38553 r38986  
    9292  if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
    9393 
     94  if (!catalog->f) return TRUE;
     95
    9496  /* rewind file pointers and truncate (file is still open) */
    9597  if (fseeko (catalog->f, 0LL, SEEK_SET)) {
     
    98100    return FALSE;
    99101  }
     102
     103  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
    100104
    101105  // write PHU header
     
    118122  gfits_free_matrix (&matrix);
    119123# endif
     124
     125  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
    120126
    121127  FTable *outtable = ftable;
     
    135141    char *compressMode = dvo_catalog_compress_string (catalog->catcompress);
    136142    // I should test how Ntile affects fpack/funpack and speed
    137     if (!gfits_compress_table (ftable, &cmptable, 1000, compressMode)) {
     143    if (!gfits_compress_table (ftable, &cmptable, 10000, compressMode)) {
    138144      fprintf (stderr, "compression failure\n");
    139145      free (compressMode);
     
    548554    }
    549555    /* read Average table data : format is irrelevant here */
    550     if (!gfits_fread_ftable_range (catalog[0].f, FALSE, &ftable, start, Nrows)) {
     556    if (!gfits_fread_ftable_range (catalog[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    551557      if (VERBOSE) fprintf (stderr, "can't read table average data");
    552558      return (FALSE);
     
    578584    }
    579585    /* read Secfilt table data : format is irrelevant here */
    580     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
     586    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start*catalog[0].Nsecfilt, catalog[0].Naverage*catalog[0].Nsecfilt)) {
    581587      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    582588      return (FALSE);
     
    614620    }
    615621    /* read Measure table data : format is irrelevant here */
    616     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     622    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    617623      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    618624      return (FALSE);
     
    645651    }
    646652    /* read Missing table data : format is irrelevant here */
    647     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     653    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    648654      if (VERBOSE) fprintf (stderr, "can't read table missing data");
    649655      return (FALSE);
     
    679685    }
    680686    /* read Lensing table data : format is irrelevant here */
    681     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     687    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    682688      if (VERBOSE) fprintf (stderr, "can't read table lensing data");
    683689      return (FALSE);
     
    710716    }
    711717    /* read Lensobj table data : format is irrelevant here */
    712     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     718    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    713719      if (VERBOSE) fprintf (stderr, "can't read table lensobj data");
    714720      return (FALSE);
     
    741747    }
    742748    /* read StarPar table data : format is irrelevant here */
    743     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     749    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    744750      if (VERBOSE) fprintf (stderr, "can't read table starpar data");
    745751      return (FALSE);
     
    772778    }
    773779    /* read GalPhot table data : format is irrelevant here */
    774     if (!gfits_fread_ftable_range (subcat[0].f, FALSE, &ftable, start, Nrows)) {
     780    if (!gfits_fread_ftable_range (subcat[0].f, FALSE, FALSE, &ftable, start, Nrows)) {
    775781      if (VERBOSE) fprintf (stderr, "can't read table galphot data");
    776782      return (FALSE);
     
    842848  }
    843849
     850  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     851
    844852  Nmeasure_disk_new = MAX (catalog[0].Nmeasure_disk, catalog[0].Nmeasure + catalog[0].Nmeasure_off);
    845853  Nmissing_disk_new = MAX (catalog[0].Nmissing_disk, catalog[0].Nmissing + catalog[0].Nmissing_off);
     
    865873  /* in split mode, we can save only part of the data */
    866874
     875  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     876
    867877  /*** Average Table ***/
    868878  if ((catalog[0].catflags & DVO_LOAD_AVERAGE) && (catalog[0].average != NULL)) {
     
    890900    }
    891901
     902    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     903
    892904    if (!dvo_catalog_save_subcat (catalog, &ftable, start, Nrows, catalog[0].Naverage_disk, Naverage_disk_new)) {
    893905      fprintf (stderr, "failure writing Average table\n");
    894906      goto failure;
    895907    }
     908
     909    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
    896910
    897911    gfits_free_header (&header);
     
    922936    assert (catalog[0].Nmeasure_disk >= catalog[0].Nmeasure_off);
    923937
     938    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     939
    924940    // if we are going to compress, we need to receive unswapped data --
    925941    int swapFromNative = !output_is_compressed (start, Nrows, Nmeasure_disk_new, catalog->catcompress);
     
    930946      goto failure;
    931947    }
     948
     949    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
    932950
    933951    // write out Measure table
     
    937955      goto failure;
    938956    }
     957    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     958
    939959
    940960    gfits_free_header (&header);
     
    9861006    int swapFromNative = !output_is_compressed (start, Nrows, Nsecfilt_disk_new, catalog->catcompress);
    9871007
     1008    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
     1009
    9881010    // convert to external table format
    9891011    if (!SecFiltToFtable (&ftable, &secfilt[first], Nrows, catalog[0].catformat, swapFromNative)) {
     
    9911013      goto failure;
    9921014    }
     1015
     1016    if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
    9931017
    9941018    // write out SecFilt table
     
    10031027
    10041028  /*** Lensing Table ***/
    1005   if ((catalog[0].catflags & DVO_LOAD_LENSING) && (catalog[0].lensing != NULL)) {
     1029  if ((catalog[0].catflags & DVO_LOAD_LENSING) && catalog[0].lensing && Nlensing_disk_new) {
    10061030
    10071031    off_t first  = 0;                    // first row in memory to write
     
    10341058
    10351059  /*** Lensobj Table ***/
    1036   if ((catalog[0].catflags & DVO_LOAD_LENSOBJ) && (catalog[0].lensobj != NULL)) {
     1060  if ((catalog[0].catflags & DVO_LOAD_LENSOBJ) && catalog[0].lensobj && Nlensobj_disk_new) {
    10371061
    10381062    off_t first  = 0;                    // first row in memory to write
     
    10651089
    10661090  /*** StarPar Table ***/
    1067   if ((catalog[0].catflags & DVO_LOAD_STARPAR) && (catalog[0].starpar != NULL)) {
     1091  if ((catalog[0].catflags & DVO_LOAD_STARPAR) && catalog[0].starpar && Nstarpar_disk_new) {
    10681092
    10691093    off_t first  = 0;                    // first row in memory to write
     
    10961120
    10971121  /*** GalPhot Table ***/
    1098   if ((catalog[0].catflags & DVO_LOAD_GALPHOT) && (catalog[0].galphot != NULL)) {
     1122  if ((catalog[0].catflags & DVO_LOAD_GALPHOT) && catalog[0].galphot && Ngalphot_disk_new) {
    10991123
    11001124    off_t first  = 0;                    // first row in memory to write
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r38553 r38986  
    7777    average = Average_PS1_V4alt_ToInternal (tmpAverage, *Naverage);
    7878    free (tmpAverage);
     79    ftable[0].buffer = NULL;
    7980    *format = DVO_FORMAT_PS1_V4;
    8081    return (average);
     
    9192    average = Average_PS1_V5alt_ToInternal (tmpAverage, *Naverage);
    9293    free (tmpAverage);
     94    ftable[0].buffer = NULL;
    9395    *format = DVO_FORMAT_PS1_V5;
    9496    return (average);
    9597  }
    9698
    97 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
    98   if (!strcmp (extname, NAME)) { \
    99     Average_##TYPE *tmpAverage; \
    100       tmpAverage = gfits_table_get_Average_##TYPE (ftable, Naverage, NULL, &nativeBytes); \
    101     if (!tmpAverage) { \
    102       fprintf (stderr, "ERROR: failed to read averages\n"); \
    103       exit (2); \
    104     } \
     99# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
     100  if (!strcmp (extname, NAME)) {                                        \
     101    Average_##TYPE *tmpAverage;                                         \
     102    tmpAverage = gfits_table_get_Average_##TYPE (ftable, Naverage, NULL, &nativeBytes); \
     103    if (!tmpAverage) {                                                  \
     104      fprintf (stderr, "ERROR: failed to read averages\n");             \
     105      exit (2);                                                         \
     106    }                                                                   \
    105107    average = Average_##TYPE##_ToInternal (tmpAverage, *Naverage, primary); \
    106     free (tmpAverage); \
    107     *format = DVO_FORMAT_##FORMAT; \
     108    free (tmpAverage);                                                  \
     109    ftable[0].buffer = NULL;                                            \
     110    *format = DVO_FORMAT_##FORMAT;                                      \
    108111    return (average); }
    109112
     
    141144int AverageToFtable (FTable *ftable, Average *average, off_t Naverage, DVOCatFormat format, SecFilt *primary, int swapFromNative) {
    142145 
    143 # define FORMAT_CASE(FORMAT, TYPE)              \
     146# define FORMAT_CASE(FORMAT, TYPE)                                      \
    144147  case DVO_FORMAT_##FORMAT: {                                           \
    145148    Average_##TYPE *tmpAverage;                                         \
    146       tmpAverage = AverageInternalTo_##TYPE (average, Naverage, primary); \
    147         gfits_table_set_Average_##TYPE (ftable, tmpAverage, Naverage, swapFromNative); \
    148           free (tmpAverage);                                            \
    149           break; }
     149    tmpAverage = AverageInternalTo_##TYPE (average, Naverage, primary); \
     150    gfits_table_set_Average_##TYPE (ftable, tmpAverage, Naverage, swapFromNative); \
     151    free (tmpAverage);                                                  \
     152    break; }
    150153 
    151154  /* convert from the internal format */
     
    195198  if (!strcmp (extname, "DVO_MEASURE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 176)) {
    196199    fprintf (stderr, "reading alt PS1_V4 format\n");
     200    myAssert (!nativeBytes, "need to implement optional swap");
    197201    Measure_PS1_V4alt *tmpMeasure;
    198202    tmpMeasure = gfits_table_get_Measure_PS1_V4alt (ftable, Nmeasure, NULL);
     
    204208    measure = Measure_PS1_V4alt_ToInternal (average, tmpMeasure, *Nmeasure);
    205209    free (tmpMeasure);
     210    ftable[0].buffer = NULL;
    206211    *format = DVO_FORMAT_PS1_V4;
    207212    return (measure);
     
    211216  if (!strcmp (extname, "DVO_MEASURE_PS1_V5") && (ftable[0].header[0].Naxis[0] == 232)) {
    212217    fprintf (stderr, "reading alt PS1_V5 format\n");
     218    myAssert (!nativeBytes, "need to implement optional swap");
    213219    Measure_PS1_V5alt *tmpMeasure;
    214220    tmpMeasure = gfits_table_get_Measure_PS1_V5alt (ftable, Nmeasure, NULL);
     
    220226    measure = Measure_PS1_V5alt_ToInternal (average, tmpMeasure, *Nmeasure);
    221227    free (tmpMeasure);
     228    ftable[0].buffer = NULL;
    222229    *format = DVO_FORMAT_PS1_V5;
    223230    return (measure);
    224231  }
    225232
    226 # define CONVERT_FORMAT(NAME, FORMAT, TYPE, ABS_COORDS)         \
     233# define CONVERT_FORMAT(NAME, FORMAT, TYPE, ABS_COORDS)                 \
    227234  if (!strcmp (extname, NAME)) {                                        \
    228235    Measure_##TYPE *tmpMeasure;                                         \
    229       tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL, &nativeBytes); \
    230         if (!tmpMeasure) {                                              \
    231           fprintf (stderr, "ERROR: failed to read measures\n");         \
    232           exit (2);                                                     \
    233         }                                                               \
    234         myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
     236    tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL, &nativeBytes); \
     237    if (!tmpMeasure) {                                                  \
     238      fprintf (stderr, "ERROR: failed to read measures\n");             \
     239      exit (2);                                                         \
     240    }                                                                   \
     241    myAssert (ABS_COORDS || average, "conversion to internal needs average table"); \
    235242    measure = Measure_##TYPE##_ToInternal (average, tmpMeasure, *Nmeasure); \
    236243    free (tmpMeasure);                                                  \
     244    ftable[0].buffer = NULL;                                            \
    237245    *format = DVO_FORMAT_##FORMAT;                                      \
    238246    return (measure); }
     
    272280int MeasureToFtable (FTable *ftable, Average *average, Measure *measure, off_t Nmeasure, DVOCatFormat format, int swapFromNative) {
    273281
    274 # define FORMAT_CASE(FORMAT, TYPE, ABS_COORDS)          \
    275     case DVO_FORMAT_##FORMAT: { \
    276       Measure_##TYPE *tmpMeasure; \
    277       myAssert (ABS_COORDS || average, "conversion from internal needs average table"); \
    278       tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
    279         gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure, swapFromNative); \
    280       free (tmpMeasure); \
    281       break; }
     282# define FORMAT_CASE(FORMAT, TYPE, ABS_COORDS)                          \
     283  case DVO_FORMAT_##FORMAT: {                                           \
     284    Measure_##TYPE *tmpMeasure;                                         \
     285    myAssert (ABS_COORDS || average, "conversion from internal needs average table"); \
     286    tmpMeasure = MeasureInternalTo_##TYPE (average, measure, Nmeasure); \
     287    gfits_table_set_Measure_##TYPE (ftable, tmpMeasure, Nmeasure, swapFromNative); \
     288    free (tmpMeasure);                                                  \
     289    break; }
    282290
    283291  /* convert from the internal format */
     
    322330  }
    323331
    324 # define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     332# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)                            \
    325333  if (!strcmp (extname, NAME)) {                                        \
    326334    fprintf (stderr, "ERROR: format %s not defined for missing, skipping\n", NAME); \
    327     *Nmissing = 0; \
    328     return NULL; \
    329   }
    330 
    331 # define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     335    *Nmissing = 0;                                                      \
     336    return NULL;                                                        \
     337  }
     338
     339# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
    332340  if (!strcmp (extname, NAME)) {                                        \
    333341    Missing_##TYPE *tmpMissing;                                         \
     
    337345      exit (2);                                                         \
    338346    }                                                                   \
    339     missing = Missing_##TYPE##_ToInternal (tmpMissing, *Nmissing); \
     347    missing = Missing_##TYPE##_ToInternal (tmpMissing, *Nmissing);      \
    340348    free (tmpMissing);                                                  \
     349    ftable[0].buffer = NULL;                                            \
    341350    *format = DVO_FORMAT_##FORMAT;                                      \
    342351    return (missing); }
     
    408417    secfilt = SecFilt_PS1_V5alt_ToInternal (tmpSecFilt, *Nsecfilt);
    409418    free (tmpSecFilt);
     419    ftable[0].buffer = NULL;
    410420    *format = DVO_FORMAT_PS1_V5;
    411421    return (secfilt);
     
    413423
    414424
    415 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
    416   if (!strcmp (extname, NAME)) { \
    417     SecFilt_##TYPE *tmpSecFilt; \
     425# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
     426  if (!strcmp (extname, NAME)) {                                        \
     427    SecFilt_##TYPE *tmpSecFilt;                                         \
    418428    tmpSecFilt = gfits_table_get_SecFilt_##TYPE (ftable, Nsecfilt, NULL, &nativeBytes); \
    419     if (!tmpSecFilt) { \
    420       fprintf (stderr, "ERROR: failed to read secfilts\n"); \
    421       exit (2); \
    422     } \
    423     secfilt = SecFilt_##TYPE##_ToInternal (tmpSecFilt, *Nsecfilt); \
    424     free (tmpSecFilt); \
    425     *format = DVO_FORMAT_##FORMAT; \
     429    if (!tmpSecFilt) {                                                  \
     430      fprintf (stderr, "ERROR: failed to read secfilts\n");             \
     431      exit (2);                                                         \
     432    }                                                                   \
     433    secfilt = SecFilt_##TYPE##_ToInternal (tmpSecFilt, *Nsecfilt);      \
     434    free (tmpSecFilt);                                                  \
     435    ftable[0].buffer = NULL;                                            \
     436    *format = DVO_FORMAT_##FORMAT;                                      \
    426437    return (secfilt); }
    427438
     
    459470int SecFiltToFtable (FTable *ftable, SecFilt *secfilt, off_t Nsecfilt, DVOCatFormat format, int swapFromNative) {
    460471
    461 # define FORMAT_CASE(FORMAT, TYPE) \
    462     case DVO_FORMAT_##FORMAT: { \
    463       SecFilt_##TYPE *tmpSecFilt; \
    464       tmpSecFilt = SecFiltInternalTo_##TYPE (secfilt, Nsecfilt); \
    465         gfits_table_set_SecFilt_##TYPE (ftable, tmpSecFilt, Nsecfilt, swapFromNative); \
    466       free (tmpSecFilt); \
    467       break; }
     472# define FORMAT_CASE(FORMAT, TYPE)                                      \
     473  case DVO_FORMAT_##FORMAT: {                                           \
     474    SecFilt_##TYPE *tmpSecFilt;                                         \
     475    tmpSecFilt = SecFiltInternalTo_##TYPE (secfilt, Nsecfilt);          \
     476    gfits_table_set_SecFilt_##TYPE (ftable, tmpSecFilt, Nsecfilt, swapFromNative); \
     477    free (tmpSecFilt);                                                  \
     478    break; }
    468479
    469480  /* convert from the internal format */
     
    517528    lensing = Lensing_PS1_V5_R0_ToInternal (tmpLensing, *Nlensing);
    518529    free (tmpLensing);                                                 
     530    ftable[0].buffer = NULL;
    519531    *format = DVO_FORMAT_PS1_V5;                                       
    520532    return (lensing); }
     
    529541    lensing = Lensing_PS1_V5_R1_ToInternal (tmpLensing, *Nlensing);
    530542    free (tmpLensing);                                                 
     543    ftable[0].buffer = NULL;
    531544    *format = DVO_FORMAT_PS1_V5;                                       
    532545    return (lensing); }
     
    541554    lensing = Lensing_PS1_V5_R2_ToInternal (tmpLensing, *Nlensing);
    542555    free (tmpLensing);                                                 
     556    ftable[0].buffer = NULL;
    543557    *format = DVO_FORMAT_PS1_V5;                                       
    544558    return (lensing); }
    545559
    546 # define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     560# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)                            \
    547561  if (!strcmp (extname, NAME)) {                                        \
    548562    fprintf (stderr, "ERROR: format %s not defined for lensing, skipping\n", NAME); \
    549     *Nlensing = 0; \
    550     return NULL; \
    551   }
    552 
    553 # define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     563    *Nlensing = 0;                                                      \
     564    return NULL;                                                        \
     565  }
     566
     567# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
    554568  if (!strcmp (extname, NAME)) {                                        \
    555569    Lensing_##TYPE *tmpLensing;                                         \
     
    559573      exit (2);                                                         \
    560574    }                                                                   \
    561     lensing = Lensing_##TYPE##_ToInternal (tmpLensing, *Nlensing); \
     575    lensing = Lensing_##TYPE##_ToInternal (tmpLensing, *Nlensing);      \
    562576    free (tmpLensing);                                                  \
     577    ftable[0].buffer = NULL;                                            \
    563578    *format = DVO_FORMAT_##FORMAT;                                      \
    564579    return (lensing); }
     
    599614int LensingToFtable (FTable *ftable, Lensing *lensing, off_t Nlensing, DVOCatFormat format, int swapFromNative) {
    600615
    601 # define FORMAT_CASE(FORMAT, TYPE)              \
    602     case DVO_FORMAT_##FORMAT: { \
    603       Lensing_##TYPE *tmpLensing; \
    604       tmpLensing = LensingInternalTo_##TYPE (lensing, Nlensing); \
    605         gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing, swapFromNative); \
    606       free (tmpLensing); \
    607       break; }
     616# define FORMAT_CASE(FORMAT, TYPE)                                      \
     617  case DVO_FORMAT_##FORMAT: {                                           \
     618    Lensing_##TYPE *tmpLensing;                                         \
     619    tmpLensing = LensingInternalTo_##TYPE (lensing, Nlensing);          \
     620    gfits_table_set_Lensing_##TYPE (ftable, tmpLensing, Nlensing, swapFromNative); \
     621    free (tmpLensing);                                                  \
     622    break; }
    608623
    609624  /* convert from the internal format */
     
    656671    lensobj = Lensobj_PS1_V5_R0_ToInternal (tmpLensobj, *Nlensobj);
    657672    free (tmpLensobj);                                                 
     673    ftable[0].buffer = NULL;
    658674    *format = DVO_FORMAT_PS1_V5;                                       
    659675    return (lensobj); }
    660676
    661 # define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     677# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)                            \
    662678  if (!strcmp (extname, NAME)) {                                        \
    663679    fprintf (stderr, "ERROR: format %s not defined for lensobj, skipping\n", NAME); \
    664     *Nlensobj = 0; \
    665     return NULL; \
    666   }
    667 
    668 # define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     680    *Nlensobj = 0;                                                      \
     681    return NULL;                                                        \
     682  }
     683
     684# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
    669685  if (!strcmp (extname, NAME)) {                                        \
    670686    Lensobj_##TYPE *tmpLensobj;                                         \
     
    674690      exit (2);                                                         \
    675691    }                                                                   \
    676     lensobj = Lensobj_##TYPE##_ToInternal (tmpLensobj, *Nlensobj); \
     692    lensobj = Lensobj_##TYPE##_ToInternal (tmpLensobj, *Nlensobj);      \
    677693    free (tmpLensobj);                                                  \
     694    ftable[0].buffer = NULL;                                            \
    678695    *format = DVO_FORMAT_##FORMAT;                                      \
    679696    return (lensobj); }
     
    714731int LensobjToFtable (FTable *ftable, Lensobj *lensobj, off_t Nlensobj, DVOCatFormat format, int swapFromNative) {
    715732
    716 # define FORMAT_CASE(FORMAT, TYPE)              \
    717     case DVO_FORMAT_##FORMAT: { \
    718       Lensobj_##TYPE *tmpLensobj; \
    719       tmpLensobj = LensobjInternalTo_##TYPE (lensobj, Nlensobj); \
    720         gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj, swapFromNative); \
    721       free (tmpLensobj); \
    722       break; }
     733# define FORMAT_CASE(FORMAT, TYPE)                                      \
     734  case DVO_FORMAT_##FORMAT: {                                           \
     735    Lensobj_##TYPE *tmpLensobj;                                         \
     736    tmpLensobj = LensobjInternalTo_##TYPE (lensobj, Nlensobj);          \
     737    gfits_table_set_Lensobj_##TYPE (ftable, tmpLensobj, Nlensobj, swapFromNative); \
     738    free (tmpLensobj);                                                  \
     739    break; }
    723740
    724741  /* convert from the internal format */
     
    762779  }
    763780
    764 # define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     781# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)                            \
    765782  if (!strcmp (extname, NAME)) {                                        \
    766783    fprintf (stderr, "ERROR: format %s not defined for starpar, skipping\n", NAME); \
    767     *Nstarpar = 0; \
    768     return NULL; \
    769   }
    770 
    771 # define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     784    *Nstarpar = 0;                                                      \
     785    return NULL;                                                        \
     786  }
     787 
     788# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
    772789  if (!strcmp (extname, NAME)) {                                        \
    773790    StarPar_##TYPE *tmpStarPar;                                         \
     
    777794      exit (2);                                                         \
    778795    }                                                                   \
    779     starpar = StarPar_##TYPE##_ToInternal (tmpStarPar, *Nstarpar); \
     796    starpar = StarPar_##TYPE##_ToInternal (tmpStarPar, *Nstarpar);      \
    780797    free (tmpStarPar);                                                  \
     798    ftable[0].buffer = NULL;                                            \
    781799    *format = DVO_FORMAT_##FORMAT;                                      \
    782800    return (starpar); }
     
    817835int StarParToFtable (FTable *ftable, StarPar *starpar, off_t Nstarpar, DVOCatFormat format, int swapFromNative) {
    818836
    819 # define FORMAT_CASE(FORMAT, TYPE)              \
    820     case DVO_FORMAT_##FORMAT: { \
    821       StarPar_##TYPE *tmpStarPar; \
    822       tmpStarPar = StarParInternalTo_##TYPE (starpar, Nstarpar); \
    823         gfits_table_set_StarPar_##TYPE (ftable, tmpStarPar, Nstarpar, swapFromNative); \
    824       free (tmpStarPar); \
    825       break; }
     837# define FORMAT_CASE(FORMAT, TYPE)                                      \
     838  case DVO_FORMAT_##FORMAT: {                                           \
     839    StarPar_##TYPE *tmpStarPar;                                         \
     840    tmpStarPar = StarParInternalTo_##TYPE (starpar, Nstarpar);          \
     841    gfits_table_set_StarPar_##TYPE (ftable, tmpStarPar, Nstarpar, swapFromNative); \
     842    free (tmpStarPar);                                                  \
     843    break; }
    826844
    827845  /* convert from the internal format */
     
    866884  }
    867885
    868 # define SKIPPING_FORMAT(NAME, FORMAT, TYPE)            \
     886  if (!strcmp (extname, "DVO_GALPHOT_PS1_V5") && (ftable[0].header[0].Naxis[0] == 72)) {
     887    GalPhot_PS1_V5_R0 *tmpGalPhot;                                             
     888    tmpGalPhot = gfits_table_get_GalPhot_PS1_V5_R0 (ftable, Ngalphot, NULL, &nativeBytes);
     889    if (!tmpGalPhot) {                                                 
     890      fprintf (stderr, "ERROR: failed to read galphots\n");             
     891      exit (2);                                                         
     892    }                                                                   
     893    galphot = GalPhot_PS1_V5_R0_ToInternal (tmpGalPhot, *Ngalphot);
     894    free (tmpGalPhot);                                                 
     895    ftable[0].buffer = NULL;
     896    *format = DVO_FORMAT_PS1_V5;                                       
     897    return (galphot);
     898  }
     899
     900# define SKIPPING_FORMAT(NAME, FORMAT, TYPE)                            \
    869901  if (!strcmp (extname, NAME)) {                                        \
    870902    fprintf (stderr, "ERROR: format %s not defined for galphot, skipping\n", NAME); \
    871     *Ngalphot = 0; \
    872     return NULL; \
    873   }
    874 
    875 # define CONVERT_FORMAT(NAME, FORMAT, TYPE)             \
     903    *Ngalphot = 0;                                                      \
     904    return NULL;                                                        \
     905  }
     906
     907# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
    876908  if (!strcmp (extname, NAME)) {                                        \
    877909    GalPhot_##TYPE *tmpGalPhot;                                         \
     
    881913      exit (2);                                                         \
    882914    }                                                                   \
    883     galphot = GalPhot_##TYPE##_ToInternal (tmpGalPhot, *Ngalphot); \
     915    galphot = GalPhot_##TYPE##_ToInternal (tmpGalPhot, *Ngalphot);      \
    884916    free (tmpGalPhot);                                                  \
     917    ftable[0].buffer = NULL;                                            \
    885918    *format = DVO_FORMAT_##FORMAT;                                      \
    886919    return (galphot); }
     
    907940  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V3",          PS1_V3,          PS1_V3);
    908941  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V4",          PS1_V4,          PS1_V4);
    909   CONVERT_FORMAT  ("DVO_GALPHOT_PS1_V5",          PS1_V5,          PS1_V5);
     942  CONVERT_FORMAT  ("DVO_GALPHOT_PS1_V5",          PS1_V5,          PS1_V5_R1);
    910943  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_SIM",         PS1_SIM,         PS1_SIM);
    911944# undef CONVERT_FORMAT
     
    921954int GalPhotToFtable (FTable *ftable, GalPhot *galphot, off_t Ngalphot, DVOCatFormat format, int swapFromNative) {
    922955
    923 # define FORMAT_CASE(FORMAT, TYPE)              \
    924     case DVO_FORMAT_##FORMAT: { \
    925       GalPhot_##TYPE *tmpGalPhot; \
    926       tmpGalPhot = GalPhotInternalTo_##TYPE (galphot, Ngalphot); \
    927         gfits_table_set_GalPhot_##TYPE (ftable, tmpGalPhot, Ngalphot, swapFromNative); \
    928       free (tmpGalPhot); \
    929       break; }
     956# define FORMAT_CASE(FORMAT, TYPE)                                      \
     957  case DVO_FORMAT_##FORMAT: {                                           \
     958    GalPhot_##TYPE *tmpGalPhot;                                         \
     959    tmpGalPhot = GalPhotInternalTo_##TYPE (galphot, Ngalphot);          \
     960    gfits_table_set_GalPhot_##TYPE (ftable, tmpGalPhot, Ngalphot, swapFromNative); \
     961    free (tmpGalPhot);                                                  \
     962    break; }
    930963
    931964  /* convert from the internal format */
     
    946979//    FORMAT_CASE (PS1_V3,          PS1_V3);
    947980//    FORMAT_CASE (PS1_V4,          PS1_V4);
    948       FORMAT_CASE (PS1_V5,          PS1_V5);
     981      FORMAT_CASE (PS1_V5,          PS1_V5_R1);
    949982# undef FORMAT_CASE
    950983
     
    9901023  }
    9911024
    992 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
    993   if (!strcmp (extname, NAME)) { \
    994     Image_##TYPE *tmpimage; \
    995     *format = DVO_FORMAT_##FORMAT; \
     1025# define CONVERT_FORMAT(NAME, FORMAT, TYPE)                             \
     1026  if (!strcmp (extname, NAME)) {                                        \
     1027    Image_##TYPE *tmpimage;                                             \
     1028    *format = DVO_FORMAT_##FORMAT;                                      \
    9961029    tmpimage = gfits_table_get_Image_##TYPE (ftable, &Nimage, NULL, NULL); \
    997     if (!tmpimage) { \
    998       fprintf (stderr, "ERROR: failed to read images\n"); \
    999       exit (2); \
    1000     } \
     1030    if (!tmpimage) {                                                    \
     1031      fprintf (stderr, "ERROR: failed to read images\n");               \
     1032      exit (2);                                                         \
     1033    }                                                                   \
    10011034    off_t Nalloc = gfits_data_pad_size(Nimage*sizeof(Image));           \
    10021035    ftable[0].buffer = (char *) Image_##TYPE##_ToInternal (tmpimage, Nimage, Nalloc); \
    1003     free (tmpimage); \
    1004     gfits_free_header (theader); \
    1005     gfits_table_mkheader_Image (theader); \
    1006     gfits_modify (theader, "NAXIS2", OFF_T_FMT, 1,  Nimage); \
    1007     theader[0].Naxis[1] = Nimage; \
    1008     ftable[0].datasize = gfits_data_size (theader); \
     1036    free (tmpimage);                                                    \
     1037    gfits_free_header (theader);                                        \
     1038    gfits_table_mkheader_Image (theader);                               \
     1039    gfits_modify (theader, "NAXIS2", OFF_T_FMT, 1,  Nimage);            \
     1040    theader[0].Naxis[1] = Nimage;                                       \
     1041    ftable[0].datasize = gfits_data_size (theader);                     \
    10091042    return (TRUE); }
    10101043
     
    10351068  Nimage = theader[0].Naxis[1];
    10361069
    1037 # define FORMAT_CASE(FORMAT, TYPE)              \
    1038   case DVO_FORMAT_##FORMAT: {                   \
     1070# define FORMAT_CASE(FORMAT, TYPE)                                      \
     1071  case DVO_FORMAT_##FORMAT: {                                           \
    10391072    Image_##TYPE *tmpImage;                                             \
    1040       tmpImage = ImageInternalTo_##TYPE ((Image *) ftable[0].buffer, Nimage); \
    1041         free (ftable[0].buffer);                                        \
    1042         gfits_free_header (ftable->header);                             \
    1043         gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage, TRUE);  \
    1044           free (tmpImage);                                              \
    1045           break; }
     1073    tmpImage = ImageInternalTo_##TYPE ((Image *) ftable[0].buffer, Nimage); \
     1074    free (ftable[0].buffer);                                            \
     1075    gfits_free_header (ftable->header);                                 \
     1076    gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage, TRUE);      \
     1077    free (tmpImage);                                                    \
     1078    break; }
    10461079
    10471080  /* convert from the internal format */
    10481081  switch (format) {
    1049       FORMAT_CASE (ELIXIR,          Elixir);
    1050       FORMAT_CASE (LONEOS,          Loneos);
    1051       FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
    1052       FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
    1053       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    1054       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
    1055       FORMAT_CASE (PS1_V1,          PS1_V1);
    1056       FORMAT_CASE (PS1_V2,          PS1_V2);
    1057       FORMAT_CASE (PS1_V3,          PS1_V3);
    1058       FORMAT_CASE (PS1_V4,          PS1_V4);
    1059       FORMAT_CASE (PS1_V5,          PS1_V5);
    1060       FORMAT_CASE (PS1_REF,         PS1_REF);
    1061       FORMAT_CASE (PS1_SIM,         PS1_SIM);
     1082    FORMAT_CASE (ELIXIR,            Elixir);
     1083    FORMAT_CASE (LONEOS,            Loneos);
     1084    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     1085    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     1086    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     1087    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     1088    FORMAT_CASE (PS1_V1,          PS1_V1);
     1089    FORMAT_CASE (PS1_V2,          PS1_V2);
     1090    FORMAT_CASE (PS1_V3,          PS1_V3);
     1091    FORMAT_CASE (PS1_V4,          PS1_V4);
     1092    FORMAT_CASE (PS1_V5,          PS1_V5);
     1093    FORMAT_CASE (PS1_REF,         PS1_REF);
     1094    FORMAT_CASE (PS1_SIM,         PS1_SIM);
    10621095
    10631096# undef FORMAT_CASE
     
    10761109  Nrow = vtable[0].Nrow;
    10771110
    1078 # define FORMAT_CASE(FORMAT, TYPE) \
    1079   case DVO_FORMAT_##FORMAT: { \
    1080       Image_##TYPE *tmpImage; \
    1081       /* convert table rows from internal to external format */ \
    1082       for (i = 0; i < Nrow; i++) { \
    1083           tmpImage = ImageInternalTo_##TYPE ((Image *) vtable[0].buffer[i], 1); \
    1084           gfits_convert_Image_##TYPE (tmpImage, sizeof(Image_##TYPE), 1); \
    1085           free (vtable[0].buffer[i]); \
    1086           vtable[0].buffer[i] = (char *) tmpImage; \
    1087       } \
    1088       /* convert header from old format to new format */ \
    1089       gfits_scan (theader, "NAXIS2", OFF_T_FMT, 1,  &Nimage); \
    1090       gfits_free_header (theader); \
    1091       gfits_table_mkheader_Image_##TYPE (theader); \
    1092       gfits_modify (theader, "NAXIS2", OFF_T_FMT, 1,  Nimage); \
    1093       theader[0].Naxis[1] = Nimage; \
    1094       vtable[0].datasize = gfits_data_size (theader); \
    1095       return (TRUE); }
     1111# define FORMAT_CASE(FORMAT, TYPE)                                      \
     1112  case DVO_FORMAT_##FORMAT: {                                           \
     1113    Image_##TYPE *tmpImage;                                             \
     1114    /* convert table rows from internal to external format */           \
     1115    for (i = 0; i < Nrow; i++) {                                        \
     1116      tmpImage = ImageInternalTo_##TYPE ((Image *) vtable[0].buffer[i], 1); \
     1117      gfits_convert_Image_##TYPE (tmpImage, sizeof(Image_##TYPE), 1);   \
     1118      free (vtable[0].buffer[i]);                                       \
     1119      vtable[0].buffer[i] = (char *) tmpImage;                          \
     1120    }                                                                   \
     1121    /* convert header from old format to new format */                  \
     1122    gfits_scan (theader, "NAXIS2", OFF_T_FMT, 1,  &Nimage);             \
     1123    gfits_free_header (theader);                                        \
     1124    gfits_table_mkheader_Image_##TYPE (theader);                        \
     1125    gfits_modify (theader, "NAXIS2", OFF_T_FMT, 1,  Nimage);            \
     1126    theader[0].Naxis[1] = Nimage;                                       \
     1127    vtable[0].datasize = gfits_data_size (theader);                     \
     1128    return (TRUE); }
    10961129
    10971130
    10981131  /* convert from the internal format */
    10991132  switch (format) {
    1100       FORMAT_CASE (ELIXIR,          Elixir);
    1101       FORMAT_CASE (LONEOS,          Loneos);
    1102       FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
    1103       FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
    1104       FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    1105       FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
    1106       FORMAT_CASE (PS1_V1,          PS1_V1);
    1107       FORMAT_CASE (PS1_V2,          PS1_V2);
    1108       FORMAT_CASE (PS1_V3,          PS1_V3);
    1109       FORMAT_CASE (PS1_V4,          PS1_V4);
    1110       FORMAT_CASE (PS1_V5,          PS1_V5);
    1111       FORMAT_CASE (PS1_REF,         PS1_REF);
    1112       FORMAT_CASE (PS1_SIM,         PS1_SIM);
     1133    FORMAT_CASE (ELIXIR,            Elixir);
     1134    FORMAT_CASE (LONEOS,            Loneos);
     1135    FORMAT_CASE (PANSTARRS_DEV_0, Panstarrs_DEV_0);
     1136    FORMAT_CASE (PANSTARRS_DEV_1, Panstarrs_DEV_1);
     1137    FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
     1138    FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     1139    FORMAT_CASE (PS1_V1,          PS1_V1);
     1140    FORMAT_CASE (PS1_V2,          PS1_V2);
     1141    FORMAT_CASE (PS1_V3,          PS1_V3);
     1142    FORMAT_CASE (PS1_V4,          PS1_V4);
     1143    FORMAT_CASE (PS1_V5,          PS1_V5);
     1144    FORMAT_CASE (PS1_REF,         PS1_REF);
     1145    FORMAT_CASE (PS1_SIM,         PS1_SIM);
    11131146
    11141147# undef FORMAT_CASE
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r38553 r38986  
    218218    out[i].catID         = in[i].catID;
    219219    out[i].extID         = in[i].extID;
    220     out[i].extIDgc       = in[i].extIDgc;
     220
     221    out[i].uRgal         = in[i].uRgal;
     222    out[i].uDgal         = in[i].uDgal;
    221223  }
    222224  return (out);
     
    286288    out[i].catID          = in[i].catID;
    287289    out[i].extID          = in[i].extID;
    288     out[i].extIDgc        = in[i].extIDgc;
     290
     291    out[i].uRgal         = in[i].uRgal;
     292    out[i].uDgal         = in[i].uDgal;
    289293  }
    290294  return (out);
     
    979983}
    980984
    981 GalPhot *GalPhot_PS1_V5_ToInternal (GalPhot_PS1_V5 *in, off_t Nvalues) {
     985GalPhot *GalPhot_PS1_V5_R1_ToInternal (GalPhot_PS1_V5_R1 *in, off_t Nvalues) {
    982986
    983987  off_t i;
     
    10131017}
    10141018
    1015 GalPhot_PS1_V5 *GalPhotInternalTo_PS1_V5 (GalPhot *in, off_t Nvalues) {
    1016 
    1017   off_t i;
    1018   GalPhot_PS1_V5 *out;
    1019 
    1020   ALLOCATE_ZERO (out, GalPhot_PS1_V5, Nvalues);
     1019GalPhot *GalPhot_PS1_V5_R0_ToInternal (GalPhot_PS1_V5_R0 *in, off_t Nvalues) {
     1020
     1021  off_t i;
     1022  GalPhot *out;
     1023
     1024  ALLOCATE_ZERO (out, GalPhot, Nvalues);
     1025
     1026  for (i = 0; i < Nvalues; i++) {
     1027    dvo_galphot_init (&out[i]);
     1028
     1029    out[i].Xfit          = in[i].Xfit;
     1030    out[i].Yfit          = in[i].Yfit;
     1031    out[i].mag           = in[i].mag;
     1032    out[i].magErr        = in[i].magErr;
     1033    out[i].majorAxis     = in[i].majorAxis;
     1034    out[i].minorAxis     = in[i].minorAxis;
     1035    out[i].majorAxisErr  = in[i].majorAxisErr;
     1036    out[i].minorAxisErr  = in[i].minorAxisErr;
     1037    out[i].theta         = in[i].theta;
     1038    out[i].thetaErr      = in[i].thetaErr;
     1039    out[i].index         = in[i].index;
     1040    out[i].chisq         = in[i].chisq;
     1041    out[i].Npix          = in[i].Npix;
     1042    out[i].objID         = in[i].objID;
     1043    out[i].catID         = in[i].catID;
     1044    out[i].detID         = in[i].detID;
     1045    out[i].imageID       = in[i].imageID;
     1046//  out[i].averef        = in[i].averef;
     1047    out[i].photcode      = in[i].photcode;
     1048    out[i].modelType     = in[i].modelType;
     1049  }
     1050  return (out);
     1051}
     1052
     1053GalPhot_PS1_V5_R1 *GalPhotInternalTo_PS1_V5_R1 (GalPhot *in, off_t Nvalues) {
     1054
     1055  off_t i;
     1056  GalPhot_PS1_V5_R1 *out;
     1057
     1058  ALLOCATE_ZERO (out, GalPhot_PS1_V5_R1, Nvalues);
    10211059
    10221060  for (i = 0; i < Nvalues; i++) {
     
    13181356    out[i].catID          = in[i].catID;
    13191357    out[i].extID          = in[i].extID;
    1320     out[i].extIDgc        = in[i].extIDgc;
    13211358  }
    13221359  return (out);
  • trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r38970 r38986  
    205205/* return equivalent photcode.code for given code */
    206206int GetPhotcodeEquivCodebyCode (int code) {
     207  myAssert (photcodes, "photcodes not loaded");
    207208 
    208209  int entry;
     
    218219// returns Nsec if code is PRI/SEC, else -1
    219220int GetPhotcodeNsec (int code) {
     221  myAssert (photcodes, "photcodes not loaded");
    220222 
    221223  int Nsec;
     
    230232/* Nsec of 0 is PRI */
    231233PhotCode *GetPhotcodebyNsec (int Nsec) {
     234  myAssert (photcodes, "photcodes not loaded");
    232235 
    233236  int Ncode;
     
    245248
    246249int GetPhotcodeNsecfilt () {
     250  myAssert (photcodes, "photcodes not loaded");
    247251  return (photcodes[0].Nsecfilt);
    248252}
     
    745749  }
    746750  return (Mstdev);
     751}
     752
     753// return the number of detections in this filter (gpc1)
     754int PhotNcode (PhotCode *code, Average *average, SecFilt *secfilt) {
     755
     756  if (code == NULL) return 0;
     757
     758  int Ns = photcodes[0].hashNsec[code[0].code];
     759  if (Ns == -1) return 0;
     760
     761  return secfilt[Ns].Ncode;
     762}
     763
     764// return the number of detections in this filter (gpc1)
     765int PhotSecfiltFlags (PhotCode *code, Average *average, SecFilt *secfilt) {
     766
     767  if (code == NULL) return 0;
     768
     769  int Ns = photcodes[0].hashNsec[code[0].code];
     770  if (Ns == -1) return 0;
     771
     772  return secfilt[Ns].flags;
    747773}
    748774
Note: See TracChangeset for help on using the changeset viewer.