Changeset 27967 for trunk/ppSim/src/ppSimSequence.c
- Timestamp:
- May 16, 2010, 1:00:37 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimSequence.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimSequence.c
r23259 r27967 1 1 # include "ppSimSequence.h" 2 2 # include <sys/stat.h> 3 4 // XXX Memory leaks in string variables5 3 6 4 int main (int argc, char **argv) { … … 135 133 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 136 134 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; 143 141 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 175 sequence: 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 } 153 193 } 154 194 … … 172 212 camera = psMetadataLookupStr (&status, sequence, "CAMERA"); 173 213 } 214 if (!camera) { 215 psLogMsg ("ppSimSequence", PS_LOG_WARN, "CAMERA is not defined"); 216 exit (1); 217 } 174 218 175 219 psString injectCommandReal = NULL; … … 180 224 181 225 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); 183 229 continue; 184 230 } 185 231 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); 187 235 continue; 188 236 } 189 237 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); 191 241 continue; 192 242 } 193 243 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); 195 247 continue; 196 248 }
Note:
See TracChangeset
for help on using the changeset viewer.
