IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2012, 5:19:48 PM (14 years ago)
Author:
mhuber
Message:

merging latest r33407 trunk changes to meh_branches/ppstack_test

Location:
branches/meh_branches/ppstack_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/ppTranslate/src/ppMopsWrite.c

    r29567 r33415  
    99#include "ppTranslateVersion.h"
    1010
    11 bool ppMopsWrite(const ppMopsDetections *det, const ppMopsArguments *args)
     11static bool addOutputColumn(psMetadata *table, const psArray *detections, long total, char *outColName, char *inColName, bool convertTo32);
     12static bool addSkyfileIDColumn(psMetadata *table, const psArray *detections, long total, char *colName);
     13
     14bool ppMopsWrite(const psArray *detections, const ppMopsArguments *args)
    1215{
    13     psTrace("ppMops.write", 1, "Writing %ld rows to %s", det->num, args->output);
    1416
    1517    psFits *fits = psFitsOpen(args->output, "w"); // FITS file
     
    3638    psMetadataAddBool(header, PS_LIST_TAIL, "DIFF_POS", 0, "Positive subtraction?", args->positive);
    3739
    38     psMetadataAddF64(header, PS_LIST_TAIL, "MJD-OBS", 0, "MJD of exposure midpoint", det->mjd);
    39     psMetadataAddStr(header, PS_LIST_TAIL, "RA", 0, "Right Ascension of boresight", det->raBoresight);
    40     psMetadataAddStr(header, PS_LIST_TAIL, "DEC", 0, "Declination of boresight", det->decBoresight);
    41     psMetadataAddF64(header, PS_LIST_TAIL, "TEL_ALT", 0, "Telescope altitude", det->alt);
    42     psMetadataAddF64(header, PS_LIST_TAIL, "TEL_AZ", 0, "Telescope azimuth", det->az);
    43     psMetadataAddF64(header, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (sec)", det->exptime);
    44     psMetadataAddF64(header, PS_LIST_TAIL, "ROTANGLE", 0, "Rotator position angle", det->posangle);
    45     psMetadataAddStr(header, PS_LIST_TAIL, "FILTER", 0, "Filter name", det->filter);
    46     psMetadataAddF32(header, PS_LIST_TAIL, "AIRMASS", 0, "Airmass of exposure", det->airmass);
     40    // Get these header words from the first input non null input
     41    ppMopsDetections *det = NULL;
     42    for (int d = 0; d < detections->n && det == NULL; d++) {
     43        det = detections->data[d];
     44    }
     45    if (det != NULL) {
     46        psMetadataAddF64(header, PS_LIST_TAIL, "MJD-OBS", 0, "MJD of exposure midpoint", det->mjd);
     47        psMetadataAddStr(header, PS_LIST_TAIL, "RA", 0, "Right Ascension of boresight", det->raBoresight);
     48        psMetadataAddStr(header, PS_LIST_TAIL, "DEC", 0, "Declination of boresight", det->decBoresight);
     49        psMetadataAddF64(header, PS_LIST_TAIL, "TEL_ALT", 0, "Telescope altitude", det->alt);
     50        psMetadataAddF64(header, PS_LIST_TAIL, "TEL_AZ", 0, "Telescope azimuth", det->az);
     51        psMetadataAddF64(header, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (sec)", det->exptime);
     52        psMetadataAddF64(header, PS_LIST_TAIL, "ROTANGLE", 0, "Rotator position angle", det->posangle);
     53        psMetadataAddStr(header, PS_LIST_TAIL, "FILTER", 0, "Filter name", det->filter);
     54        psMetadataAddF32(header, PS_LIST_TAIL, "AIRMASS", 0, "Airmass of exposure", det->airmass);
     55        psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", det->seeing);
     56    } else {
     57        psWarning("no inputs with surviving detections. output header will be incomplete");
     58    }
    4759    psMetadataAddStr(header, PS_LIST_TAIL, "OBSCODE", 0, "IAU Observatory code", OBSERVATORY_CODE);
    48     psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", det->seeing);
    4960    psMetadataAddF32(header, PS_LIST_TAIL, "MAGZP", 0, "Magnitude zero point", args->zp);
    5061    psMetadataAddF32(header, PS_LIST_TAIL, "MAGZPERR", 0, "Error in magnitude zero point", args->zpErr);
    5162    psMetadataAddF32(header, PS_LIST_TAIL, "ASTRORMS", 0, "RMS of astrometric fit", args->rmsAstrom);
    52     //New field in header that tells about the CMF version
     63
     64    //field in header that tells about the CMF version
    5365    char cmfVersion[8];
    5466    sprintf(cmfVersion, PS1_DV_FORMAT, args->version);
    5567    psMetadataAddStr(header, PS_LIST_TAIL, "CMFVERSION", 0, "CMF version", cmfVersion);
    5668
    57     if (det->num == 0) {
     69    // Find the total number of detections
     70
     71    long total = 0;
     72    for (long i=0; i<detections->n; i++) {
     73        ppMopsDetections *det = detections->data[i];
     74        if (!det) {
     75            continue;
     76        }
     77        total += det->num;
     78    }
     79
     80    psTrace("ppMops.write", 1, "Writing %ld rows to %s", total, args->output);
     81
     82    if (total == 0) {
    5883        // Write dummy table
    5984        psMetadata *row = psMetadataAlloc(); // Output row
     
    85110        psMetadataAddF32(row, PS_LIST_TAIL, "RATIO_ALL", 0, "Ratio of positive pixels to all", NAN);
    86111
    87             if (args->version == 2) {
     112        if (args->version == 2) {
    88113              // Write data of version 2 (see ICD)
    89114              psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET",         PS_DATA_U32, "IPP detection identifier index",
     
    141166              psMetadataAdd (row, PS_LIST_TAIL, "PADDING",          PS_DATA_S16, "padding",
    142167                             0);
    143             }
     168        }
    144169
    145170        if (!psFitsWriteTableEmpty(fits, header, row, OUT_EXTNAME)) {
     
    151176        psFree(row);
    152177    } else {
    153         psArray *table = psArrayAlloc(det->num); // Table to write
    154         for (long i = 0; i < det->num; i++) {
    155             psMetadata *row = psMetadataAlloc(); // Output row
    156             psMetadataAddF64(row, PS_LIST_TAIL, "RA", 0, "Right ascension (degrees)",
    157                              RAD_TO_DEG(det->ra->data.F64[i]));
    158             psMetadataAddF64(row, PS_LIST_TAIL, "RA_ERR", 0, "Right ascension error (degrees)",
    159                              det->raErr->data.F64[i]);
    160             psMetadataAddF64(row, PS_LIST_TAIL, "DEC", 0, "Declination (degrees)",
    161                              RAD_TO_DEG(det->dec->data.F64[i]));
    162             psMetadataAddF64(row, PS_LIST_TAIL, "DEC_ERR", 0, "Declination error (degrees)",
    163                              det->decErr->data.F64[i]);
    164             psMetadataAddF32(row, PS_LIST_TAIL, "MAG", 0, "Magnitude", det->mag->data.F32[i]);
    165             psMetadataAddF32(row, PS_LIST_TAIL, "MAG_ERR", 0, "Magnitude error", det->magErr->data.F32[i]);
    166             psMetadataAddF32(row, PS_LIST_TAIL, "PSF_CHI2", 0, "chi^2 of PSF fit", det->chi2->data.F32[i]);
    167             psMetadataAddS32(row, PS_LIST_TAIL, "PSF_DOF", 0, "Degrees of freedom of PSF fit",
    168                              det->dof->data.S32[i]);
    169             psMetadataAddF32(row, PS_LIST_TAIL, "CR_SIGNIFICANCE", 0, "Significance of CR",
    170                              det->cr->data.F32[i]);
    171             psMetadataAddF32(row, PS_LIST_TAIL, "EXT_SIGNIFICANCE", 0, "Significance of extendedness",
    172                              det->extended->data.F32[i]);
    173             psMetadataAddF32(row, PS_LIST_TAIL, "PSF_MAJOR", 0, "PSF major axis (pixels)", det->psfMajor->data.F32[i]);
    174             psMetadataAddF32(row, PS_LIST_TAIL, "PSF_MINOR", 0, "PSF minor axis (pixels)", det->psfMinor->data.F32[i]);
    175             psMetadataAddF32(row, PS_LIST_TAIL, "PSF_THETA", 0, "PSF position angle (deg on chip)",
    176                              det->psfTheta->data.F32[i]);
    177             psMetadataAddF32(row, PS_LIST_TAIL, "PSF_QUALITY", 0, "PSF quality factor",
    178                              det->quality->data.F32[i]);
    179             psMetadataAddS32(row, PS_LIST_TAIL, "PSF_NPIX", 0, "Number of pixels in PSF",
    180                              det->numPix->data.S32[i]);
    181             psMetadataAddF32(row, PS_LIST_TAIL, "MOMENTS_XX", 0, "xx moment", det->xxMoment->data.F32[i]);
    182             psMetadataAddF32(row, PS_LIST_TAIL, "MOMENTS_XY", 0, "xy moment", det->xyMoment->data.F32[i]);
    183             psMetadataAddF32(row, PS_LIST_TAIL, "MOMENTS_YY", 0, "yy moment", det->yyMoment->data.F32[i]);
    184             psMetadataAddS32(row, PS_LIST_TAIL, "N_POS", 0, "Number of positive pixels",
    185                              det->nPos->data.S32[i]);
    186             psMetadataAddF32(row, PS_LIST_TAIL, "F_POS", 0, "Fraction of positive pixels",
    187                              det->fPos->data.F32[i]);
    188             psMetadataAddF32(row, PS_LIST_TAIL, "RATIO_BAD", 0, "Ratio of positive pixels to negative",
    189                              det->nRatioBad->data.F32[i]);
    190             psMetadataAddF32(row, PS_LIST_TAIL, "RATIO_MASK", 0, "Ratio of positive pixels to masked",
    191                              det->nRatioMask->data.F32[i]);
    192             psMetadataAddF32(row, PS_LIST_TAIL, "RATIO_ALL", 0, "Ratio of positive pixels to all",
    193                              det->nRatioAll->data.F32[i]);
    194             psMetadataAddU32(row, PS_LIST_TAIL, "FLAGS", 0, "Detection bit flags", det->flags->data.U32[i]);
    195             psMetadataAddS64(row, PS_LIST_TAIL, "DIFF_SKYFILE_ID", 0, "Identifier for diff skyfile",
    196                              det->diffSkyfileId->data.S64[i]);
    197 
    198             if (args->version == 2) {
    199               // Write data of version 2 (see ICD)
    200               psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET",         PS_DATA_U32, "IPP detection identifier index",
    201                              det->ippIdet->data.U32[i]);
    202               psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",
    203                              det->psfInstFlux->data.F32[i]);
    204               psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",
    205                              det->psfInstFluxSig->data.F32[i]);
    206               psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",
    207                              det->apMag->data.F32[i]);
    208               psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in real aperture",
    209                              det->apMagRaw->data.F32[i]);
    210               psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",
    211                              det->apMagRadius->data.F32[i]);
    212               psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX",          PS_DATA_F32, "instrumental flux in standard aperture",
    213                              det->apFlux->data.F32[i]);
    214               psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG",      PS_DATA_F32, "aperture flux error",
    215                              det->apFluxSig->data.F32[i]);
    216               psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",
    217                              det->peakFluxAsMag->data.F32[i]);
    218               psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "PSF Magnitude using supplied calibration",
    219                              det->calPsfMag->data.F32[i]);
    220               psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG",  PS_DATA_F32, "measured scatter of zero point calibration",
    221                              det->calPsfMagSig->data.F32[i]);
    222               psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",
    223                              det->sky->data.F32[i]);
    224               psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA",        PS_DATA_F32, "Sigma of sky level",
    225                              det->skySig->data.F32[i]);
    226               psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT",   PS_DATA_F32, "PSF coverage/quality factor (poor)",
    227                              det->qualityPerfect->data.F32[i]);
    228               psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1",       PS_DATA_F32, "first radial moment",
    229                              det->momentsR1->data.F32[i]);
    230               psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_RH",       PS_DATA_F32, "half radial moment",
    231                              det->momentsRH->data.F32[i]);
    232               psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX",        PS_DATA_F32, "Kron Flux (in 2.5 R1)",
    233                              det->kronFlux->data.F32[i]);
    234               psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_ERR",    PS_DATA_F32, "Kron Flux Error",
    235                              det->kronFluxErr->data.F32[i]);
    236               psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 1.0 R1)",
    237                              det->kronFluxInner->data.F32[i]);
    238               psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER",  PS_DATA_F32, "Kron Flux (in 4.0 R1)",
    239                              det->kronFluxOuter->data.F32[i]);
    240               psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_P",         PS_DATA_F32, "distance to positive match source",
    241                              det->diffRP->data.F32[i]);
    242               psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_P",        PS_DATA_F32, "signal-to-noise of pos match src",
    243                              det->diffSnP->data.F32[i]);
    244               psMetadataAdd (row, PS_LIST_TAIL, "DIFF_R_M",         PS_DATA_F32, "distance to negative match source",
    245                              det->diffRM->data.F32[i]);
    246               psMetadataAdd (row, PS_LIST_TAIL, "DIFF_SN_M",        PS_DATA_F32, "signal-to-noise of neg match src",
    247                              det->diffSnM->data.F32[i]);
    248               psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2",           PS_DATA_U32, "psphot analysis flags (group 2)",
    249                              det->flags2->data.U32[i]);
    250               psMetadataAdd (row, PS_LIST_TAIL, "N_FRAMES",         PS_DATA_U16, "Number of frames overlapping source center",
    251                              det->nFrames->data.U16[i]);
    252               psMetadataAdd (row, PS_LIST_TAIL, "PADDING",          PS_DATA_S16, "padding",
    253                              det->padding->data.S16[i]);
    254             }
    255 
    256             //Update with the table with the current row
    257             table->data[i] = row;
    258         }
    259         if (!psFitsWriteTable(fits, header, table, OUT_EXTNAME)) {
    260             psErrorStackPrint(stderr, "Unable to write table.");
    261             psFree(header);
    262             psFree(table);
     178
     179#define addColumn(_outName, _inName, _convertTo32) \
     180        if (!addOutputColumn(table, detections, total, _outName, _inName, _convertTo32)) { \
     181            psError(PS_ERR_UNKNOWN, false, "Failed to add column %s", _outName); \
     182            return false; \
     183        }
     184
     185        // Allocate the output table
     186        psMetadata *table = psMetadataAlloc();
     187        addColumn("RA", "RA_PSF", 0);
     188        addColumn("RA_ERR", NULL, 0);      // calculated from various parameters including X_PSF_SIG Y_PSF_SIG and POSANG
     189        addColumn("DEC", "DEC_PSF", 0);
     190        addColumn("DEC_ERR", NULL, 0);     // calculated from various parameters including X_PSF_SIG Y_PSF_SIG and POSANG
     191        addColumn("MAG", "PSF_INST_MAG", 0);
     192        addColumn("MAG_ERR", "PSF_INST_MAG_SIG", 0);
     193        addColumn("PSF_CHI2", "PSF_CHISQ", 0);
     194        addColumn("PSF_DOF", "PSF_NDOF", 1);
     195        addColumn("CR_SIGNIFICANCE", "CR_NSIGMA", 0);
     196        addColumn("EXT_SIGNIFICANCE", "EXT_NSIGMA", 0);
     197        addColumn("PSF_MAJOR", NULL, 0);
     198        addColumn("PSF_MINOR", NULL, 0);     
     199        addColumn("PSF_THETA", NULL, 0);   
     200        addColumn("PSF_QUALITY", "PSF_QF", 0);
     201        addColumn("PSF_NPIX", NULL, 1);       
     202        addColumn("MOMENTS_XX", NULL, 0);
     203        addColumn("MOMENTS_XY", NULL, 0);
     204        addColumn("MOMENTS_YY", NULL, 0);
     205        addColumn("N_POS", "DIFF_NPOS", 1);
     206        addColumn("F_POS", "DIFF_FRATIO", 0);
     207        addColumn("RATIO_BAD", "DIFF_NRATIO_BAD", 0);
     208        addColumn("RATIO_MASK", "DIFF_NRATIO_MASK", 0);
     209        addColumn("RATIO_ALL", "DIFF_NRATIO_ALL", 0);
     210        addColumn("FLAGS", "FLAGS", 1);
     211        addSkyfileIDColumn(table, detections, total, "DIFF_SKYFILE_ID");
     212        if (args->version == 2) {
     213            addColumn("IPP_IDET", NULL, 1);
     214            addColumn("PSF_INST_FLUX", NULL, 0);
     215            addColumn("PSF_INST_FLUX_SIG", NULL, 0);
     216            addColumn("AP_MAG", NULL, 0);
     217            addColumn("AP_MAG_RAW", NULL, 0);
     218            addColumn("AP_MAG_RADIUS", NULL, 0);
     219            addColumn("AP_FLUX", NULL, 0);
     220            addColumn("AP_FLUX_SIG", NULL, 0);
     221            addColumn("PEAK_FLUX_AS_MAG", NULL, 0);
     222            addColumn("CAL_PSF_MAG", NULL, 0);
     223            addColumn("CAL_PSF_MAG_SIG", NULL, 0);
     224            addColumn("SKY", NULL, 0);
     225            addColumn("SKY_SIGMA", NULL, 0);
     226            addColumn("PSF_QF_PERFECT", NULL, 0);
     227            addColumn("MOMENTS_R1", NULL, 0);
     228            addColumn("MOMENTS_RH", NULL, 0);
     229            addColumn("KRON_FLUX", NULL, 0);
     230            addColumn("KRON_FLUX_ERR", NULL, 0);
     231            addColumn("KRON_FLUX_INNER", NULL, 0);
     232            addColumn("KRON_FLUX_OUTER", NULL, 0);
     233            addColumn("DIFF_R_P", NULL, 0);
     234            addColumn("DIFF_SN_P", NULL, 0);
     235            addColumn("DIFF_R_M", NULL, 0);
     236            addColumn("DIFF_SN_M", NULL, 0);
     237            addColumn("FLAGS2", NULL, 1);
     238            addColumn("IPP_IDET", NULL, 0);
     239            addColumn("N_FRAMES", NULL, 0);
     240            addColumn("PADDING", NULL, 0);
     241        }
     242        if (!psFitsWriteTableAllColumns(fits, header, table, OUT_EXTNAME)) {
     243            psError(psErrorCodeLast(), false, "Unable to write table");
    263244            return false;
    264245        }
     
    273254    return true;
    274255}
     256
     257static bool addOutputColumn(psMetadata *table, const psArray *detections, long outputSize, char *outColumnName, char *inColumnName, bool convertTo32)
     258{
     259    if (inColumnName == NULL) {
     260        inColumnName = outColumnName;
     261    }
     262
     263    psVector *out = NULL;
     264    if (convertTo32) {
     265        // psFitsReadTableAllColumns reads columns of cfitsio type LONG and ULONG into a 64 bit integers
     266        // We want to write 32 bits to the output.
     267        int next = 0;
     268        for (long i=0; i<detections->n; i++) {
     269            ppMopsDetections *det = detections->data[i];
     270            if (!det || det->num == 0) {
     271                // no detections survived for this input
     272                continue;
     273            }
     274            psVector *in = psMetadataLookupVector(NULL, det->table, inColumnName);
     275            if (!in) {
     276                psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s", inColumnName);
     277                return false;
     278            }
     279            if (in->type.type != PS_TYPE_S64 && in->type.type != PS_TYPE_U64) {
     280                psError(PS_ERR_PROGRAMMING, true, "input column to convert is not S64 or U64: %s %d",
     281                    inColumnName, in->type.type);
     282                return false;
     283            }
     284            if (out == NULL) {
     285                // First time through set up the output vector and the copy parameters
     286                if (in->type.type == PS_TYPE_S64) {
     287                    out = psVectorAlloc(outputSize, PS_TYPE_S32);
     288                } else {
     289                    out = psVectorAlloc(outputSize, PS_TYPE_U32);
     290                }
     291            }
     292            for (long d=0; d < det->num; d++) {
     293                if (in->type.type == PS_TYPE_S64) {
     294                    out->data.S32[next++] = in->data.S64[d];
     295                } else {
     296                    out->data.U32[next++] = in->data.U64[d];
     297                }
     298            }
     299        }
     300    } else {
     301        void *next = NULL;
     302        int elementSize = 0;    // size of elements in vector... We are making assumptions here about the organization of primitives in memory so we can use memcopy
     303        for (long i=0; i<detections->n; i++) {
     304            ppMopsDetections *det = detections->data[i];
     305            if (!det || det->num == 0) {
     306                // no detections survived for this input
     307                continue;
     308            }
     309            psVector *in = psMetadataLookupVector(NULL, det->table, inColumnName);
     310            if (!in) {
     311                psError(PS_ERR_PROGRAMMING, true, "failed to find input column: %s", inColumnName);
     312                return false;
     313            }
     314            if (out == NULL) {
     315                // First time through set up the output vector and the copy parameters
     316                out = psVectorAlloc(outputSize, in->type.type);
     317                next = (void *) out->data.U8;
     318                switch (in->type.type) {
     319                    case PS_TYPE_S8:
     320                    elementSize = sizeof(psS8);
     321                    break;
     322                case PS_TYPE_U8:
     323                    elementSize = sizeof(psU8);
     324                    break;
     325                case PS_TYPE_S16:
     326                    elementSize = sizeof(psS16);
     327                    break;
     328                case PS_TYPE_U16:
     329                    elementSize = sizeof(psU16);
     330                    break;
     331                case PS_TYPE_S32:
     332                    elementSize = sizeof(psS32);
     333                    break;
     334                case PS_TYPE_U32:
     335                    elementSize = sizeof(psU32);
     336                    break;
     337                case PS_TYPE_S64:
     338                    elementSize = sizeof(psS64);
     339                    break;
     340                case PS_TYPE_U64:
     341                    elementSize = sizeof(psU64);
     342                    break;
     343                case PS_TYPE_F32:
     344                    elementSize = sizeof(psF32);
     345                    break;
     346                case PS_TYPE_F64:
     347                    elementSize = sizeof(psF64);
     348                    break;
     349                default:
     350                    psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unknown vector type %d", in->type.type);
     351                    return false;
     352
     353                }
     354            }
     355            // We are doing nasty things here so we can use memcpy.
     356            // It would be safer to do a proper loop over the elements.
     357            long toCopy = det->num * elementSize;
     358            memcpy(next, in->data.U8, toCopy);
     359            next += toCopy;
     360        }
     361    }
     362
     363    // Finally add the new column to the output table
     364    psMetadataAddVector(table, PS_LIST_TAIL, outColumnName, 0, NULL, out);
     365    psFree(out);    // drop reference
     366
     367    return true;
     368}
     369static bool addSkyfileIDColumn(psMetadata *table, const psArray *detections, long total, char *colName)
     370{
     371    psVector *out = psVectorAlloc(total, PS_TYPE_S64);
     372    long next = 0;
     373    for (long i = 0; i<detections->n; i++) {
     374        ppMopsDetections *det = detections->data[i];
     375        if (!det) {
     376            continue;
     377        }
     378        psS64 diffSkyfileId = det->diffSkyfileId;
     379        for (long j = 0; j < det->num; j++) {
     380            out->data.S64[next++] = diffSkyfileId;
     381        }
     382    }
     383    psMetadataAddVector(table, PS_LIST_TAIL, colName, 0, NULL, out);
     384    psFree(out);
     385    return true;
     386}
Note: See TracChangeset for help on using the changeset viewer.