Changeset 16499 for trunk/ppSim/src/ppSimSequence.c
- Timestamp:
- Feb 15, 2008, 9:33:56 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimSequence.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimSequence.c
r16393 r16499 1 # include "ppSim .h"1 # include "ppSimSequence.h" 2 2 3 int main(int argc, char *argv[]) 4 { 3 int main (int argc, char **argv) { 4 5 int argNum; 6 bool status; 7 unsigned int nFail; 8 5 9 psLibInit(NULL); 6 10 7 if (argc != 2) { 8 fprintf (stderr, "USAGE: ppSimSequence (seq.config)\n"); 9 fprintf (stderr, "generates a set of simulated data defined by the sequence file\n"); 10 exit (2); 11 char *dbname = NULL; 12 if ((argNum = psArgumentGet (argc, argv, "-dbname"))) { 13 psArgumentRemove(argNum, &argc, argv); 14 dbname = psStringCopy (argv[argNum]); 15 psArgumentRemove(argNum, &argc, argv); 16 } 17 18 char *path = NULL; 19 if (psArgumentGet (argc, argv, "-path")) { 20 psArgumentRemove(argNum, &argc, argv); 21 path = psStringCopy (argv[argNum]); 22 psArgumentRemove(argNum, &argc, argv); 23 } 24 25 char *workdir = NULL; 26 if (psArgumentGet (argc, argv, "-workdir")) { 27 psArgumentRemove(argNum, &argc, argv); 28 workdir = psStringCopy (argv[argNum]); 29 psArgumentRemove(argNum, &argc, argv); 30 } 31 32 char *basename = NULL; 33 if (psArgumentGet (argc, argv, "-basename")) { 34 psArgumentRemove(argNum, &argc, argv); 35 basename = psStringCopy (argv[argNum]); 36 psArgumentRemove(argNum, &argc, argv); 37 } else { 38 basename = psStringCopy ("simtest"); 39 } 40 41 if (argc != 4) { 42 fprintf (stderr, "USAGE: ppSimSequence (sequence) (simulate) (inject)\n"); 43 fprintf (stderr, "generates a set of simulated data defined by the sequence file\n"); 44 fprintf (stderr, " (sequence) : a mdc-file describing the desired image sequences\n"); 45 fprintf (stderr, " (simulate) : an output file with commands to generate the images\n"); 46 fprintf (stderr, " (inject) : an output file with commands to inject the images into the pipeline\n"); 47 fprintf (stderr, "\n"); 48 exit (2); 11 49 } 12 50 13 51 // load the sequence description 14 52 psMetadata *config = psMetadataConfigRead (NULL, &nFail, argv[1], false); 53 if (!config) { 54 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to read sequence description from %s", argv[1]); 55 exit (1); 56 } 15 57 58 FILE *simfile = fopen (argv[2], "w"); 59 if (!simfile) { 60 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[2]); 61 exit (1); 62 } 63 64 FILE *inject = fopen (argv[3], "w"); 65 if (!inject) { 66 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[3]); 67 exit (1); 68 } 69 70 // build the base injectCommand string 71 psString injectCommand = psStringCopy ("ipp_inject_fileset.pl --telescope SIMTEST"); 72 if (dbname) psStringAppend (&injectCommand, " --dbname %s", dbname); 73 if (workdir) psStringAppend (&injectCommand, " --workdir %s", workdir); 74 75 unsigned long seed = psMetadataLookupS32 (&status, config, "RND_SEED"); 76 if (!status) seed = 0; 77 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, seed); 78 16 79 psMetadataItem *item = psMetadataLookup (config, "SEQUENCE"); 17 80 if (item == NULL) { 18 psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");19 exit (1);81 psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description"); 82 exit (1); 20 83 } 21 84 85 psArray *sequences = NULL; 22 86 if (item->type == PS_DATA_METADATA) { 23 sequences = psArrayAlloc(1);24 sequences->data[0] = psMemIncrRefCounter (item->data.V);87 sequences = psArrayAlloc(1); 88 sequences->data[0] = psMemIncrRefCounter (item->data.V); 25 89 } else { 26 if (item->type != PS_DATA_METADATA_MULTI) {27 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");28 exit (1);29 }30 sequences = psListToArray (item->data.list);90 if (item->type != PS_DATA_METADATA_MULTI) { 91 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA"); 92 exit (1); 93 } 94 sequences = psListToArray (item->data.list); 31 95 } 32 96 33 97 for (int i = 0; i < sequences->n; i++) { 34 98 35 // a OBJECT sequence is described by a center position and a set of offsets at each 36 // offset, we perform a set of dithers for each pointing, we have a set of filters 37 // and exposure times 99 // XXX this is not obvious: the entry on the list is a metadata item 100 // containing the psMetadata :: why is this not just a metadata? 101 psMetadataItem *item = sequences->data[i]; 102 psMetadata *sequence = item->data.V; 103 // double check item type? 104 105 // determine the sequence type 106 char *type = psMetadataLookupStr (&status, sequence, "OBSTYPE"); 107 if (!status) { 108 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d is missing a type", i); 109 exit (1); 110 } 38 111 39 // a non-OBJECT sequence consists of a number of a given type 112 if (!strcasecmp (type, "BIAS")) { 113 ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, injectCommand); 114 continue; 115 } 116 if (!strcasecmp (type, "DARK")) { 117 ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, injectCommand); 118 continue; 119 } 120 if (!strcasecmp (type, "FLAT")) { 121 ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, injectCommand); 122 continue; 123 } 124 if (!strcasecmp (type, "OBJECT")) { 125 ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, injectCommand); 126 continue; 127 } 40 128 41 // create files with ppSim: 42 // ppSim -camera CAMERA -type TYPE filename 43 44 // inject --camera 45 46 psMetadata *sequence = sequences->data[i]; 47 48 // determine the sequence type 49 char *type = psMetadataLookupStr (&status, sequence, "TYPE"); 50 if (!status) { 51 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d is missing a type", i); 129 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d has an unknown type: %s", i, type); 52 130 exit (1); 53 }54 55 if (!strcasecmp (type, "BIAS")) {56 ppSimSequenceBias (sequence);57 continue;58 }59 if (!strcasecmp (type, "DARK")) {60 ppSimSequenceDark (sequence);61 continue;62 }63 if (!strcasecmp (type, "FLAT")) {64 ppSimSequenceFlat (sequence);65 continue;66 }67 if (!strcasecmp (type, "OBJECT")) {68 ppSimSequenceObject (sequence);69 continue;70 }71 131 } 132 exit (0); 72 133 }
Note:
See TracChangeset
for help on using the changeset viewer.
