IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 12:49:05 PM (16 years ago)
Author:
eugene
Message:

merging changes from trunk into branches/pap

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ppSim/src/ppSimSequence.c

    r23259 r28003  
    11# include "ppSimSequence.h"
    22# include <sys/stat.h>
    3 
    4 // XXX Memory leaks in string variables
    53
    64int main (int argc, char **argv) {
     
    135133    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
    136134
    137     psMetadataItem *item = psMetadataLookup (config, "SEQUENCE");
    138     if (item == NULL) {
    139         psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");
    140         exit (PS_EXIT_CONFIG_ERROR);
    141     }
    142 
     135    // global camera option (if not set, we look in each sequence)
     136    if (camera == NULL) {
     137        camera = psMetadataLookupStr (&status, config, "CAMERA");
     138    }
     139
     140    psArray *files = NULL;
    143141    psArray *sequences = NULL;
    144     if (item->type == PS_DATA_METADATA) {
    145         sequences = psArrayAlloc(1);
    146         sequences->data[0] = psMemIncrRefCounter (item->data.V);
    147     } else {
    148         if (item->type != PS_DATA_METADATA_MULTI)  {
    149             psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");
    150             exit (1);
    151         }
    152         sequences = psListToArray (item->data.list);
     142
     143    { // find the FILERULE (if it exists) to set the file extension (.fits is default)
     144        psMetadataItem *filerule = psMetadataLookup (config, "FILERULE");
     145        if (filerule == NULL) {
     146            psLogMsg ("ppSimSequence", PS_LOG_INFO, "no FILERULE, assuming .fits ending");
     147            files = psArrayAlloc(1);
     148            files->data[0] = psStringCopy("fits");
     149            goto sequence;
     150        }
     151        if (filerule->type == PS_DATA_METADATA_MULTI) {
     152            psArray *rules = psListToArray (filerule->data.list);
     153            psAssert (rules, "failed to get array from list?");
     154            psAssert (rules->n > 1, "supposed to be multiple entries in the list?");
     155            files = psArrayAllocEmpty(rules->n);
     156            for (int i = 0; i < rules->n; i++) {
     157                psMetadataItem *item = rules->data[i];
     158                if (item->type != PS_DATA_STRING) {
     159                    psLogMsg ("ppSimSequence", PS_LOG_WARN, "invalid FILERULE type");
     160                    exit (PS_EXIT_CONFIG_ERROR);
     161                }
     162                psArrayAdd (files, 16, item->data.str);
     163            }
     164            goto sequence;
     165        }
     166        if (filerule->type == PS_DATA_STRING) {
     167            files = psArrayAlloc(1);
     168            files->data[0] = psStringCopy(filerule->data.str);
     169            goto sequence;
     170        }
     171        psLogMsg ("ppSimSequence", PS_LOG_WARN, "invalid FILERULE type");
     172        exit (PS_EXIT_CONFIG_ERROR);
     173    }
     174
     175sequence:
     176    { // find the set of sequences which define the ppSim data to be produced
     177        psMetadataItem *item = psMetadataLookup (config, "SEQUENCE");
     178        if (item == NULL) {
     179            psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");
     180            exit (PS_EXIT_CONFIG_ERROR);
     181        }
     182
     183        if (item->type == PS_DATA_METADATA) {
     184            sequences = psArrayAlloc(1);
     185            sequences->data[0] = psMemIncrRefCounter (item->data.V);
     186        } else {
     187            if (item->type != PS_DATA_METADATA_MULTI)  {
     188                psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");
     189                exit (1);
     190            }
     191            sequences = psListToArray (item->data.list);
     192        }
    153193    }
    154194
     
    172212            camera = psMetadataLookupStr (&status, sequence, "CAMERA");
    173213        }
     214        if (!camera) {
     215            psLogMsg ("ppSimSequence", PS_LOG_WARN, "CAMERA is not defined");
     216            exit (1);
     217        }
    174218
    175219        psString injectCommandReal = NULL;
     
    180224
    181225        if (!strcasecmp (type, "BIAS")) {
    182             ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     226            ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     227            psFree (injectCommandReal);
     228            psFree (ppSimCommandReal);
    183229            continue;
    184230        }
    185231        if (!strcasecmp (type, "DARK")) {
    186             ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     232            ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     233            psFree (injectCommandReal);
     234            psFree (ppSimCommandReal);
    187235            continue;
    188236        }
    189237        if (!strcasecmp (type, "FLAT")) {
    190             ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     238            ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     239            psFree (injectCommandReal);
     240            psFree (ppSimCommandReal);
    191241            continue;
    192242        }
    193243        if (!strcasecmp (type, "OBJECT")) {
    194             ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal);
     244            ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, ppSimCommandReal, injectCommandReal, files);
     245            psFree (injectCommandReal);
     246            psFree (ppSimCommandReal);
    195247            continue;
    196248        }
Note: See TracChangeset for help on using the changeset viewer.