IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 3, 2010, 5:11:47 PM (16 years ago)
Author:
Paul Price
Message:

Add error checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceIO_MatchedRefs.c

    r26893 r27177  
    6767
    6868    if (!table) {
    69         table = psArrayAllocEmpty (0x1000);
    70         pmFPAview *view = pmFPAviewAlloc (0);
     69        table = psArrayAllocEmpty (0x1000);
     70        pmFPAview *view = pmFPAviewAlloc (0);
    7171
    72         // this loop selects the matched stars for all chips
    73         while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
    74             psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    75             if (!chip->process || !chip->file_exists) continue;
     72        // this loop selects the matched stars for all chips
     73        while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
     74            psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     75            if (!chip->process || !chip->file_exists) continue;
    7676
    77             char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");
     77            char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");
    7878
    79             while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    80                 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    81                 if (!cell->process || !cell->file_exists) continue;
     79            while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
     80                psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     81                if (!cell->process || !cell->file_exists) continue;
    8282
    83                 // process each of the readouts
    84                 // XXX there can only be one readout per chip, right?
    85                 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
    86                     if (! readout->data_exists) continue;
     83                // process each of the readouts
     84                // XXX there can only be one readout per chip, right?
     85                while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
     86                    if (! readout->data_exists) continue;
    8787
    88                     // select the raw objects for this readout
    89                     psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
    90                     if (rawstars == NULL) continue;
     88                    // select the raw objects for this readout
     89                    psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
     90                    if (rawstars == NULL) continue;
    9191
    92                     // select the raw objects for this readout
    93                     psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");
    94                     if (refstars == NULL) continue;
    95                     psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n);
     92                    // select the raw objects for this readout
     93                    psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");
     94                    if (refstars == NULL) continue;
     95                    psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n);
    9696
    9797# if (0)
    98                     // XXX test
    99                     FILE *outfile = fopen ("refstars.dat", "w");
    100                     assert (outfile);
    101                     for (int nn = 0; nn < refstars->n; nn++) {
    102                         pmAstromObj *ref = refstars->data[nn];
    103                         fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
    104                     }
    105                     fclose (outfile);
     98                    // XXX test
     99                    FILE *outfile = fopen ("refstars.dat", "w");
     100                    assert (outfile);
     101                    for (int nn = 0; nn < refstars->n; nn++) {
     102                        pmAstromObj *ref = refstars->data[nn];
     103                        fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
     104                    }
     105                    fclose (outfile);
    106106# endif
    107107
    108                     psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH");
    109                     if (matches == NULL) continue;
     108                    psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH");
     109                    if (matches == NULL) continue;
    110110
    111                     for (int i = 0; i < matches->n; i++) {
    112                         pmAstromMatch *match = matches->data[i];
     111                    for (int i = 0; i < matches->n; i++) {
     112                        pmAstromMatch *match = matches->data[i];
    113113
    114                         pmAstromObj *raw = rawstars->data[match->raw];
    115                         pmAstromObj *ref = refstars->data[match->ref];
     114                        pmAstromObj *raw = rawstars->data[match->raw];
     115                        pmAstromObj *ref = refstars->data[match->ref];
    116116
    117                         psMetadata *row = psMetadataAlloc ();
    118                         psMetadataAdd (row, PS_LIST_TAIL, "RA",       PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r);
    119                         psMetadataAdd (row, PS_LIST_TAIL, "DEC",      PS_DATA_F64, "declination (deg, J2000)",     PM_DEG_RAD*ref->sky->d);
    120                         psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP",   PS_DATA_F32, "x coord on chip",              raw->chip->x);
    121                         psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP",   PS_DATA_F32, "y coord on chip",              raw->chip->y);
    122                         psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_FIT",PS_DATA_F32, "x fitted coord on chip",      ref->chip->x);
    123                         psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_FIT",PS_DATA_F32, "y fitted coord on chip",      ref->chip->y);
    124                         psMetadataAdd (row, PS_LIST_TAIL, "X_FPA",    PS_DATA_F32, "x coord on focal plane",       raw->FP->x);
    125                         psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA",    PS_DATA_F32, "y coord on focal plane",       raw->FP->y);
    126                         psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude",       raw->Mag);
    127                         psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF",  PS_DATA_F32, "reference star magnitude",     ref->Mag);
    128                         psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color",         ref->Color);
    129                         psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID",  PS_DATA_STRING, "chip identifier",           chipName);
    130                         // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined.
     117                        psMetadata *row = psMetadataAlloc ();
     118                        psMetadataAdd (row, PS_LIST_TAIL, "RA",       PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r);
     119                        psMetadataAdd (row, PS_LIST_TAIL, "DEC",      PS_DATA_F64, "declination (deg, J2000)",     PM_DEG_RAD*ref->sky->d);
     120                        psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP",   PS_DATA_F32, "x coord on chip",              raw->chip->x);
     121                        psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP",   PS_DATA_F32, "y coord on chip",              raw->chip->y);
     122                        psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_FIT",PS_DATA_F32, "x fitted coord on chip",      ref->chip->x);
     123                        psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_FIT",PS_DATA_F32, "y fitted coord on chip",      ref->chip->y);
     124                        psMetadataAdd (row, PS_LIST_TAIL, "X_FPA",    PS_DATA_F32, "x coord on focal plane",       raw->FP->x);
     125                        psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA",    PS_DATA_F32, "y coord on focal plane",       raw->FP->y);
     126                        psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude",       raw->Mag);
     127                        psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF",  PS_DATA_F32, "reference star magnitude",     ref->Mag);
     128                        psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color",         ref->Color);
     129                        psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID",  PS_DATA_STRING, "chip identifier",           chipName);
     130                        // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined.
    131131
    132                         psArrayAdd (table, 100, row);
    133                         psFree (row);
    134                     }
    135                 }
    136             }
    137         }
    138         psFree (view);
     132                        psArrayAdd (table, 100, row);
     133                        psFree (row);
     134                    }
     135                }
     136            }
     137        }
     138        psFree (view);
    139139
    140         if (table->n == 0) {
    141             psFree(table);
    142             return true;
    143         }
     140        if (table->n == 0) {
     141            psFree(table);
     142            return true;
     143        }
    144144    }
    145145
    146146    if (!psFitsWriteTable(fits, NULL, table, "MATCHED_REFS")) {
    147         psError(PS_ERR_IO, false, "writing MATCHED_REFS\n");
     147        psError(psErrorCodeLast(), false, "writing MATCHED_REFS\n");
    148148        psFree(table);
    149149        return false;
     
    165165    // It is not an error to lack this entry -- psFitsMoveExtNameClean does not raise an error
    166166    if (!psFitsMoveExtNameClean (fits, "MATCHED_REFS")) {
    167         psMetadataAddBool (fpa->analysis, PS_LIST_TAIL, "READ.REFMATCH", PS_META_REPLACE, "attempted to read MATCHED_REFS", true);
    168         return true;
     167        psMetadataAddBool (fpa->analysis, PS_LIST_TAIL, "READ.REFMATCH", PS_META_REPLACE, "attempted to read MATCHED_REFS", true);
     168        return true;
    169169    }
    170    
     170
    171171    // We get the size of the table, and allocate the array of sources first because the table
    172172    // is large and ephemeral --- when the table gets blown away, whatever is allocated after
     
    178178    for (int i = 0; i < numRows; i++) {
    179179        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
    180         rows->data[i] = row;
     180        if (!row) {
     181            psError(psErrorCodeLast(), false, "Unable to read row %d of matched references.", i);
     182            psFree(rows);
     183            return false;
     184        }
     185        rows->data[i] = row;
    181186    }
    182187
Note: See TracChangeset for help on using the changeset viewer.