IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18726


Ignore:
Timestamp:
Jul 24, 2008, 4:01:54 PM (18 years ago)
Author:
eugene
Message:

mods from HEAD by PAP (correctly copy components of fpa)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/psModules/src/camera/pmFPACopy.c

    r16861 r18726  
    4747
    4848// copy one of the psImage components of the readout
    49 static void readoutCopyComponent (psImage **target, psImage *source, psImageBinning *binning, bool xFlip, bool yFlip, bool pixels) {
    50 
     49static void readoutCopyComponent(psImage **target, // Image to which to copy
     50                                 const psImage *source, // Image from which to copy
     51                                 psImageBinning *binning, // New binning
     52                                 bool xFlip, bool yFlip, // Flip in x or y?
     53                                 bool pixels // Copy the pixels?
     54                                 )
     55{
    5156    if (!source) return;
    5257
     
    6671    return;
    6772}
     73
     74// Update the output analysis metadata, adding stuff in the input
     75//
     76// This is probably very similar to psMetadataCopy, but we want to explicitly deal with arrays (especially
     77// since astronomical sources live in them)
     78static psMetadata *updateAnalysis(psMetadata *out, psMetadata *in)
     79{
     80    psAssert(in, "Require input");
     81    if (!out) {
     82        out = psMetadataAlloc();
     83    }
     84
     85    psMetadataIterator *iter = psMetadataIteratorAlloc(in, PS_LIST_HEAD, NULL); // Iterator
     86    psMetadataItem *item;               // Item from iteration
     87    while ((item = psMetadataGetAndIncrement(iter))) {
     88        psMetadataItem *original = psMetadataLookup(in, item->name); // Checking for MULTI
     89        psMetadataItem *extant = psMetadataLookup(out, item->name); // Existing item?
     90        if ((original && original->type == PS_DATA_METADATA_MULTI) ||
     91            (extant && extant->type == PS_DATA_METADATA_MULTI)) {
     92            psMetadataAddItem(out, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK);
     93            continue;
     94        }
     95
     96        switch (item->type) {
     97          case PS_DATA_ARRAY: {
     98              // Concatenate arrays if they already exist
     99              psMetadataItem *extant = psMetadataLookup(out, item->name); // Existing array?
     100              if (extant && extant->type == PS_DATA_ARRAY) {
     101                  psArray *new = item->data.V; // New array
     102                  psArray *old = extant->data.V; // Old array
     103                  long numNew = new->n, numOld = old->n; // Number of values in each
     104                  extant->data.V = old = psArrayRealloc(old, old->n + numNew);
     105                  for (long i = 0; i < numNew; i++) {
     106                      old->data[numOld + i] = psMemIncrRefCounter(new->data[i]);
     107                  }
     108                  old->n = numOld + numNew;
     109              } else {
     110                  psMetadataAddItem(out, item, PS_LIST_TAIL, PS_META_REPLACE);
     111              }
     112              break;
     113            default:
     114              // If in doubt, there's not much we can do except replace
     115              psMetadataAddItem(out, item, PS_LIST_TAIL, PS_META_REPLACE);
     116              break;
     117          }
     118        }
     119    }
     120    psFree(iter);
     121
     122    return out;
     123}
     124
    68125
    69126//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    95152    }
    96153
    97     // the binning structure carries the information no how to rebin the images if needed
     154    // the binning structure carries the information on how to rebin the images if needed
    98155    psImageBinning *binning = psImageBinningAlloc();
    99156    binning->nXbin = xBin;
     
    164221
    165222        // Copy all three image components (image, mask, weight)
    166         readoutCopyComponent (&targetReadout->image,  sourceReadout->image,  binning, xFlip, yFlip, pixels);
    167         readoutCopyComponent (&targetReadout->mask,   sourceReadout->mask,   binning, xFlip, yFlip, pixels);
    168         readoutCopyComponent (&targetReadout->weight, sourceReadout->weight, binning, xFlip, yFlip, pixels);
     223        readoutCopyComponent(&targetReadout->image,  sourceReadout->image,  binning, xFlip, yFlip, pixels);
     224        readoutCopyComponent(&targetReadout->mask,   sourceReadout->mask,   binning, xFlip, yFlip, pixels);
     225        readoutCopyComponent(&targetReadout->weight, sourceReadout->weight, binning, xFlip, yFlip, pixels);
    169226
    170227        // Copy bias
     
    183240        }
    184241        psFree(biasIter);
     242
     243        // Copy the analysis metadata
     244        targetReadout->analysis = updateAnalysis(targetReadout->analysis, sourceReadout->analysis);
    185245
    186246        targetReadout->data_exists = true;
     
    312372    binItem->data.S32 *= yBin;
    313373
     374    // Update the analysis metadata
     375    target->analysis = updateAnalysis(target->analysis, source->analysis);
     376
    314377    // Copy any headers
    315378    pmHDU *targetHDU = pmHDUFromCell(target); // The target HDU
     
    376439        }
    377440    }
     441
     442    // Update the analysis metadata
     443    target->analysis = updateAnalysis(target->analysis, source->analysis);
    378444
    379445    // Update the concepts
     
    419485    }
    420486
     487    // Update the analysis metadata
     488    targetChip->analysis = updateAnalysis(targetChip->analysis, sourceChip->analysis);
     489
    421490    // Update the concepts
    422491    psMetadataCopy(targetChip->concepts, sourceChip->concepts);
     
    463532    }
    464533
     534    // Update the analysis metadata
     535    target->analysis = updateAnalysis(target->analysis, source->analysis);
     536
    465537    // Update the concepts
    466538    psMetadataCopy(target->concepts, source->concepts);
Note: See TracChangeset for help on using the changeset viewer.