IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 3, 2021, 3:05:40 PM (5 years ago)
Author:
eugene
Message:

plug various leaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpUpdateMetadata.c

    r40354 r41510  
    2323
    2424    if ((output)&&(output->analysis)) {   
    25       psMetadataItem *refItem = psMetadataLookup(output->analysis, "REFERENCE_CATALOG");
    26       if (refItem) {
    27         refcat = psMetadataLookupStr (NULL, output->analysis, "REFERENCE_CATALOG");
    28       }
     25        psMetadataItem *refItem = psMetadataLookup(output->analysis, "REFERENCE_CATALOG");
     26        if (refItem) {
     27            refcat = psMetadataLookupStr (NULL, output->analysis, "REFERENCE_CATALOG");
     28        }
    2929    }
    3030    pmChip *chip;
     
    4747            pmReadout *readout;
    4848            while ((readout = pmFPAviewNextReadout(view, output, 1)) != NULL) {
    49               // skip empty output readouts
     49                // skip empty output readouts
    5050                if (!readout->data_exists) continue;
    5151   
     
    5757                    psArray *covars = psListToArray(covariances); // Array of covariance matrices
    5858                    if (covars->n) {
    59                       psKernel *covar = psImageCovarianceAverage(covars);
    60                       psMetadataRemoveKey(readout->analysis, PSWARP_ANALYSIS_COVARIANCES);
     59                        psKernel *covar = psImageCovarianceAverage(covars);
     60                        psMetadataRemoveKey(readout->analysis, PSWARP_ANALYSIS_COVARIANCES);
    6161
    62                       // Correct covariance matrix scale for the mean (square root of the) Jacobian
    63                       double jacobian = psMetadataLookupF64(NULL, readout->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian
    64                       int goodPixels = psMetadataLookupS32(NULL, readout->analysis, PSWARP_ANALYSIS_GOODPIX);   // Good pixels
    65                       jacobian /= goodPixels;
    66                       readout->covariance = psImageCovarianceScale(covar, jacobian);
    67                       psFree(covar);
     62                        // Correct covariance matrix scale for the mean (square root of the) Jacobian
     63                        double jacobian = psMetadataLookupF64(NULL, readout->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian
     64                        int goodPixels = psMetadataLookupS32(NULL, readout->analysis, PSWARP_ANALYSIS_GOODPIX);   // Good pixels
     65                        jacobian /= goodPixels;
     66                        readout->covariance = psImageCovarianceScale(covar, jacobian);
     67                        psFree(covar);
    6868
    69                       if (readout->variance) {
    70                         psImageCovarianceTransfer(readout->variance, readout->covariance);
    71                       }
     69                        if (readout->variance) {
     70                            psImageCovarianceTransfer(readout->variance, readout->covariance);
     71                        }
    7272
    73                       psFree(covars);
     73                        psFree(covars);
    7474                    }
    7575                }
     
    9494                psArray *chipnames = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_CHIPNAMES);
    9595                for (int i = 0; chipnames && (i < chipnames->n); i++) {
    96                   psStringAppend (&keyword, "SRC_%04d", i);
    97                   psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", chipnames->data[i]);
    98                   psFree (keyword);
     96                    psStringAppend (&keyword, "SRC_%04d", i);
     97                    psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", chipnames->data[i]);
     98                    psFree (keyword);
    9999                }
    100100
     
    102102                psArray *chipRegions = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_CHIPREGIONS);
    103103                for (int i = 0; chipRegions && (i < chipRegions->n); i++) {
    104                   psStringAppend (&keyword, "SEC_%04d", i);
    105                   psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", chipRegions->data[i]);
    106                   psFree (keyword);
     104                    psStringAppend (&keyword, "SEC_%04d", i);
     105                    psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", chipRegions->data[i]);
     106                    psFree (keyword);
    107107                }
    108108
     
    110110                psArray *backmaps  = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_BACKMAPS); //
    111111                for (int i = 0; backmaps && (i < backmaps->n); i++) {
    112                   psPlaneTransform *map = backmaps->data[i];             
    113                   psStringAppend (&keyword, "MPX_%04d", i);
    114                   psStringAppend (&mapstring, "[%8.2f,%8.4f,%8.4f]", map->x->coeff[0][0], map->x->coeff[1][0], map->x->coeff[0][1]);
    115                   psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "warp to image map", mapstring);
    116                   psFree (keyword);
    117                   psFree (mapstring);
    118                   psStringAppend (&keyword, "MPY_%04d", i);
    119                   psStringAppend (&mapstring, "[%8.2f,%8.4f,%8.4f]", map->y->coeff[0][0], map->y->coeff[1][0], map->y->coeff[0][1]);
    120                   psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "warp to image map", mapstring);
    121                   psFree (keyword);
    122                   psFree (mapstring);
     112                    psPlaneTransform *map = backmaps->data[i];           
     113                    psStringAppend (&keyword, "MPX_%04d", i);
     114                    psStringAppend (&mapstring, "[%8.2f,%8.4f,%8.4f]", map->x->coeff[0][0], map->x->coeff[1][0], map->x->coeff[0][1]);
     115                    psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "warp to image map", mapstring);
     116                    psFree (keyword);
     117                    psFree (mapstring);
     118                    psStringAppend (&keyword, "MPY_%04d", i);
     119                    psStringAppend (&mapstring, "[%8.2f,%8.4f,%8.4f]", map->y->coeff[0][0], map->y->coeff[1][0], map->y->coeff[0][1]);
     120                    psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "warp to image map", mapstring);
     121                    psFree (keyword);
     122                    psFree (mapstring);
    123123                }
    124124            }
     
    164164    if (!psMetadataCopy(output->concepts, input->concepts)) {
    165165        psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");
     166        psFree(view);
    166167        return false;
    167168    }
     
    174175
    175176    if (refcat) {
    176       if ((output)&&(output->hdu)&&(output->hdu->header)) {
    177         psMetadataAddStr(output->hdu->header, PS_LIST_TAIL, "PSREFCAT", PS_META_REPLACE,
    178                          "Reference catalog used for calibration", refcat);
    179       }
     177        if ((output)&&(output->hdu)&&(output->hdu->header)) {
     178            psMetadataAddStr(output->hdu->header, PS_LIST_TAIL, "PSREFCAT", PS_META_REPLACE,
     179                             "Reference catalog used for calibration", refcat);
     180        }
    180181    }
    181182   
     
    193194    }
    194195
     196    psFree(view);
    195197    return true;
    196198}
Note: See TracChangeset for help on using the changeset viewer.