Changeset 18849
- Timestamp:
- Aug 1, 2008, 8:46:17 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppSim/src/ppSimSequence.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSim/src/ppSimSequence.c
r17617 r18849 1 1 # include "ppSimSequence.h" 2 2 # include <sys/stat.h> 3 4 // XXX Memory leaks in string variables 3 5 4 6 int main (int argc, char **argv) { … … 6 8 bool status; 7 9 int argNum; 8 char line[1024];9 10 unsigned int nFail; 10 11 … … 12 13 13 14 char *dbname = NULL; 14 if ((argNum = psArgumentGet (argc, argv, "-dbname"))) { 15 if ((argNum = psArgumentGet (argc, argv, "-dbname"))) { 15 16 psArgumentRemove(argNum, &argc, argv); 16 dbname = psStringCopy (argv[argNum]);17 dbname = psStringCopy (argv[argNum]); 17 18 psArgumentRemove(argNum, &argc, argv); 18 19 } 19 20 20 21 char *path = NULL; 21 if ((argNum = psArgumentGet (argc, argv, "-path"))) { 22 if ((argNum = psArgumentGet (argc, argv, "-path"))) { 22 23 psArgumentRemove(argNum, &argc, argv); 23 path = psStringCopy (argv[argNum]);24 path = psStringCopy (argv[argNum]); 24 25 psArgumentRemove(argNum, &argc, argv); 25 sprintf (line, "mkdir -p %s", path); 26 system (line); 26 psString line = NULL; // Line to execute 27 psStringAppend("mkdir -p %s", path); 28 if (!system(line)) { 29 psWarning("Unable to create directory %s", path); 30 } 31 psFree(line); 27 32 } 28 33 29 34 char *workdir = NULL; 30 if ((argNum = psArgumentGet (argc, argv, "-workdir"))) { 35 if ((argNum = psArgumentGet (argc, argv, "-workdir"))) { 31 36 psArgumentRemove(argNum, &argc, argv); 32 workdir = psStringCopy (argv[argNum]);37 workdir = psStringCopy (argv[argNum]); 33 38 psArgumentRemove(argNum, &argc, argv); 34 39 } 35 40 36 41 char *dvodb = NULL; 37 if ((argNum = psArgumentGet (argc, argv, "-dvodb"))) { 42 if ((argNum = psArgumentGet (argc, argv, "-dvodb"))) { 38 43 psArgumentRemove(argNum, &argc, argv); 39 dvodb = psStringCopy (argv[argNum]);44 dvodb = psStringCopy (argv[argNum]); 40 45 psArgumentRemove(argNum, &argc, argv); 41 46 } 42 47 43 48 char *tess_id = NULL; 44 if ((argNum = psArgumentGet (argc, argv, "-tess_id"))) { 49 if ((argNum = psArgumentGet (argc, argv, "-tess_id"))) { 45 50 psArgumentRemove(argNum, &argc, argv); 46 tess_id = psStringCopy (argv[argNum]);51 tess_id = psStringCopy (argv[argNum]); 47 52 psArgumentRemove(argNum, &argc, argv); 48 53 } 49 54 50 55 char *basename = NULL; 51 if ((argNum = psArgumentGet (argc, argv, "-basename"))) { 56 if ((argNum = psArgumentGet (argc, argv, "-basename"))) { 52 57 psArgumentRemove(argNum, &argc, argv); 53 basename = psStringCopy (argv[argNum]);58 basename = psStringCopy (argv[argNum]); 54 59 psArgumentRemove(argNum, &argc, argv); 55 60 } else { 56 basename = psStringCopy ("simtest");61 basename = psStringCopy ("simtest"); 57 62 } 58 63 59 64 char *label = NULL; 60 if ((argNum = psArgumentGet (argc, argv, "-label"))) { 65 if ((argNum = psArgumentGet (argc, argv, "-label"))) { 61 66 psArgumentRemove(argNum, &argc, argv); 62 label = psStringCopy (argv[argNum]);67 label = psStringCopy (argv[argNum]); 63 68 psArgumentRemove(argNum, &argc, argv); 64 69 } 65 70 66 71 if (argc != 4) { 67 fprintf (stderr, "USAGE: ppSimSequence (sequence) (simulate) (inject) [options]\n");68 fprintf (stderr, "generates a set of simulated data defined by the sequence file\n");69 fprintf (stderr, " (sequence) : a mdc-file describing the desired image sequences\n");70 fprintf (stderr, " (simulate) : an output file with commands to generate the images\n");71 fprintf (stderr, " (inject) : an output file with commands to inject the images into the pipeline\n");72 fprintf (stderr, "options:\n");73 fprintf (stderr, " -dbname (dbname)\n");74 fprintf (stderr, " -path (path)\n");75 fprintf (stderr, " -workdir (workdir)\n");76 fprintf (stderr, " -basename (basename)\n");77 fprintf (stderr, " -label (label)\n");78 fprintf (stderr, " -dvodb (dvodb)\n");79 fprintf (stderr, " -tess_id (tess_id)\n");80 exit (2);72 fprintf (stderr, "USAGE: ppSimSequence (sequence) (simulate) (inject) [options]\n"); 73 fprintf (stderr, "generates a set of simulated data defined by the sequence file\n"); 74 fprintf (stderr, " (sequence) : a mdc-file describing the desired image sequences\n"); 75 fprintf (stderr, " (simulate) : an output file with commands to generate the images\n"); 76 fprintf (stderr, " (inject) : an output file with commands to inject the images into the pipeline\n"); 77 fprintf (stderr, "options:\n"); 78 fprintf (stderr, " -dbname (dbname)\n"); 79 fprintf (stderr, " -path (path)\n"); 80 fprintf (stderr, " -workdir (workdir)\n"); 81 fprintf (stderr, " -basename (basename)\n"); 82 fprintf (stderr, " -label (label)\n"); 83 fprintf (stderr, " -dvodb (dvodb)\n"); 84 fprintf (stderr, " -tess_id (tess_id)\n"); 85 exit (2); 81 86 } 82 87 … … 84 89 psMetadata *config = psMetadataConfigRead (NULL, &nFail, argv[1], false); 85 90 if (!config) { 86 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to read sequence description from %s", argv[1]);87 exit (1);91 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to read sequence description from %s", argv[1]); 92 exit (1); 88 93 } 89 94 90 95 FILE *simfile = fopen (argv[2], "w"); 91 96 if (!simfile) { 92 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[2]);93 exit (1);97 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[2]); 98 exit (1); 94 99 } 95 100 96 101 FILE *inject = fopen (argv[3], "w"); 97 102 if (!inject) { 98 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[3]);99 exit (1);103 psLogMsg ("ppSimSequence", PS_LOG_WARN, "unable to open %s for output", argv[3]); 104 exit (1); 100 105 } 101 106 … … 114 119 psMetadataItem *item = psMetadataLookup (config, "SEQUENCE"); 115 120 if (item == NULL) { 116 psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description");117 exit (1);121 psLogMsg ("ppSimSequence", PS_LOG_WARN, "missing SEQUENCE description"); 122 exit (1); 118 123 } 119 124 120 125 psArray *sequences = NULL; 121 126 if (item->type == PS_DATA_METADATA) { 122 sequences = psArrayAlloc(1);123 sequences->data[0] = psMemIncrRefCounter (item->data.V);127 sequences = psArrayAlloc(1); 128 sequences->data[0] = psMemIncrRefCounter (item->data.V); 124 129 } else { 125 if (item->type != PS_DATA_METADATA_MULTI) {126 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA");127 exit (1);128 }129 sequences = psListToArray (item->data.list);130 if (item->type != PS_DATA_METADATA_MULTI) { 131 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE is not MULTI or METADATA"); 132 exit (1); 133 } 134 sequences = psListToArray (item->data.list); 130 135 } 131 136 132 137 for (int i = 0; i < sequences->n; i++) { 133 138 134 // XXX this is not obvious: the entry on the list is a metadata item 135 // containing the psMetadata :: why is this not just a metadata? 136 psMetadataItem *item = sequences->data[i]; 137 psMetadata *sequence = item->data.V; 138 // double check item type? 139 140 // determine the sequence type 141 char *type = psMetadataLookupStr (&status, sequence, "OBSTYPE"); 142 if (!status) { 143 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d is missing a type", i); 144 exit (1); 145 } 139 // XXX this is not obvious: the entry on the list is a metadata item 140 // containing the psMetadata :: why is this not just a metadata? 141 psMetadataItem *item = sequences->data[i]; 142 psMetadata *sequence = item->data.V; 143 // double check item type? 146 144 147 if (!strcasecmp (type, "BIAS")) { 148 ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, injectCommand); 149 continue; 150 } 151 if (!strcasecmp (type, "DARK")) { 152 ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, injectCommand); 153 continue; 154 } 155 if (!strcasecmp (type, "FLAT")) { 156 ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, injectCommand); 157 continue; 158 } 159 if (!strcasecmp (type, "OBJECT")) { 160 ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, injectCommand); 161 continue; 162 } 145 // determine the sequence type 146 char *type = psMetadataLookupStr (&status, sequence, "OBSTYPE"); 147 if (!status) { 148 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d is missing a type", i); 149 exit (1); 150 } 163 151 164 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d has an unknown type: %s", i, type); 165 exit (1); 152 if (!strcasecmp (type, "BIAS")) { 153 ppSimSequenceBias (simfile, inject, sequence, i, rng, path, basename, injectCommand); 154 continue; 155 } 156 if (!strcasecmp (type, "DARK")) { 157 ppSimSequenceDark (simfile, inject, sequence, i, rng, path, basename, injectCommand); 158 continue; 159 } 160 if (!strcasecmp (type, "FLAT")) { 161 ppSimSequenceFlat (simfile, inject, sequence, i, rng, path, basename, injectCommand); 162 continue; 163 } 164 if (!strcasecmp (type, "OBJECT")) { 165 ppSimSequenceObject (simfile, inject, sequence, i, rng, path, basename, injectCommand); 166 continue; 167 } 168 169 psLogMsg ("ppSimSequence", PS_LOG_WARN, "SEQUENCE %d has an unknown type: %s", i, type); 170 exit (1); 166 171 } 167 172
Note:
See TracChangeset
for help on using the changeset viewer.
