Changeset 27967 for trunk/ppSim
- Timestamp:
- May 16, 2010, 1:00:37 PM (16 years ago)
- Location:
- trunk/ppSim/src
- Files:
-
- 6 edited
-
ppSimSequence.c (modified) (4 diffs)
-
ppSimSequence.h (modified) (1 diff)
-
ppSimSequenceBias.c (modified) (3 diffs)
-
ppSimSequenceDark.c (modified) (3 diffs)
-
ppSimSequenceFlat.c (modified) (3 diffs)
-
ppSimSequenceObject.c (modified) (7 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 } -
trunk/ppSim/src/ppSimSequence.h
r19315 r27967 12 12 #include <psastro.h> 13 13 14 bool ppSimSequenceBias (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand );15 bool ppSimSequenceDark (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand );16 bool ppSimSequenceFlat (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand );17 bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand );14 bool ppSimSequenceBias (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files); 15 bool ppSimSequenceDark (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files); 16 bool ppSimSequenceFlat (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files); 17 bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files); 18 18 19 19 #endif -
trunk/ppSim/src/ppSimSequenceBias.c
r19315 r27967 1 1 # include "ppSimSequence.h" 2 2 3 bool ppSimSequenceBias (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand ) {3 bool ppSimSequenceBias (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) { 4 4 5 5 bool status, setLevel, setRange; … … 14 14 int nImage = 0; 15 15 for (int i = 0; i < nImages; i++) { 16 16 17 17 // define the output filename 18 18 psString filename = NULL; … … 30 30 if (setLevel) psStringAppend (&command, " -biaslevel %f", level); 31 31 if (setRange) psStringAppend (&command, " -biasrange %f", range); 32 32 33 33 psStringAppend (&command, " %s", filename); 34 34 35 35 fprintf (simfile, "%s\n", command); 36 36 psFree (command); 37 37 38 38 // define the inject command 39 39 // path should be dirname/filename 40 command = psStringCopy (injectCommand); 41 psStringAppend (&command, " %s*.fits", filename); 42 fprintf (inject, "%s\n", command); 43 psFree (command); 40 41 // we use the filename above (really the file root) to construct the filenames 42 for (int i = 0; i < files->n; i++) { 43 command = psStringCopy (injectCommand); 44 psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]); 45 fprintf (inject, "%s\n", command); 46 psFree (command); 47 } 48 44 49 psFree (filename); 45 46 nImage ++; 50 nImage ++; 47 51 } 48 52 return true; -
trunk/ppSim/src/ppSimSequenceDark.c
r19315 r27967 1 1 # include "ppSimSequence.h" 2 2 3 bool ppSimSequenceDark (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand ) {3 bool ppSimSequenceDark (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) { 4 4 5 5 bool status, setRate; … … 39 39 40 40 psStringAppend (&command, "%s -type DARK", ppSimCommand); 41 41 42 42 if (setRate) { 43 43 double frnd = psRandomUniform(rng); … … 52 52 fprintf (simfile, "%s\n", command); 53 53 psFree (command); 54 54 55 55 // define the inject command 56 56 // path should be dirname/filename 57 command = psStringCopy (injectCommand); 58 psStringAppend (&command, " %s*.fits", filename); 59 fprintf (inject, "%s\n", command); 60 psFree (command); 61 psFree (filename); 57 58 // we use the filename above (really the file root) to construct the filenames 59 for (int i = 0; i < files->n; i++) { 60 command = psStringCopy (injectCommand); 61 psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]); 62 fprintf (inject, "%s\n", command); 63 psFree (command); 64 } 62 65 63 nImage ++; 64 } 66 psFree (filename); 67 nImage ++; 68 } 65 69 } 66 70 return true; -
trunk/ppSim/src/ppSimSequenceFlat.c
r19315 r27967 1 1 # include "ppSimSequence.h" 2 2 3 bool ppSimSequenceFlat (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand ) {3 bool ppSimSequenceFlat (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) { 4 4 5 5 bool status; … … 26 26 // loop over the filters & exposure times 27 27 for (int j = 0; j < nSetup; j++) { 28 28 29 29 // define the output filename 30 30 psString filename = NULL; … … 50 50 // define the inject command 51 51 // path should be dirname/filename 52 command = psStringCopy (injectCommand); 53 psStringAppend (&command, " %s*.fits", filename); 54 fprintf (inject, "%s\n", command); 55 psFree (command); 56 psFree (filename); 52 53 // we use the filename above (really the file root) to construct the filenames 54 for (int i = 0; i < files->n; i++) { 55 command = psStringCopy (injectCommand); 56 psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]); 57 fprintf (inject, "%s\n", command); 58 psFree (command); 59 } 57 60 58 nImage ++; 61 psFree (filename); 62 nImage ++; 59 63 } 60 64 } -
trunk/ppSim/src/ppSimSequenceObject.c
r24099 r27967 1 1 # include "ppSimSequence.h" 2 2 3 bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand ) {3 bool ppSimSequenceObject (FILE *simfile, FILE *inject, psMetadata *sequence, int nSeq, psRandom *rng, const char *path, const char *basename, const char *ppSimCommand, const char *injectCommand, psArray *files) { 4 4 5 5 bool status; … … 34 34 // loop over the filters & exposure times 35 35 for (int i = 0; i < filters->n; i++) { 36 36 37 37 // offset parameters 38 38 float dR = psMetadataLookupF32 (&status, sequence, "OFFSET.RA"); 39 39 float dD = psMetadataLookupF32 (&status, sequence, "OFFSET.DEC"); 40 40 41 41 int nR = psMetadataLookupS32 (&status, sequence, "OFFSET.NR"); 42 42 int nD = psMetadataLookupS32 (&status, sequence, "OFFSET.ND"); 43 43 44 44 // loop over the offset sequence 45 45 for (int iR = 0; iR < nR; iR++) { … … 50 50 float R = Ro + dR*(iR - 0.5*nR + 0.5) / cos (RAD_DEG*Do) / 3600.0; 51 51 float D = Do + dD*(iD - 0.5*nD + 0.5) / 3600.0; 52 52 53 53 // dither parameters 54 54 float dr = psMetadataLookupF32 (&status, sequence, "DITHER.RA"); 55 55 float dd = psMetadataLookupF32 (&status, sequence, "DITHER.DEC"); 56 56 57 57 int nr = psMetadataLookupS32 (&status, sequence, "DITHER.NR"); 58 58 int nd = psMetadataLookupS32 (&status, sequence, "DITHER.ND"); 59 59 60 60 // loop over the dither sequence 61 61 for (int ir = 0; ir < nr; ir++) { … … 65 65 float ra = R + dr*(ir - 0.5*nr + 0.5) / cos (RAD_DEG*D) / 3600.0; 66 66 float dec = D + dd*(id - 0.5*nd + 0.5) / 3600.0; 67 67 68 68 // rotation sequence parameters 69 69 float pos_min = psMetadataLookupF32 (&status, sequence, "POS_MIN"); … … 72 72 assert (pos_delta > 0.0); 73 73 assert (pos_max >= pos_min); 74 74 75 75 // loop over rotation sequence 76 76 for (float pos = pos_min; pos <= pos_max; pos += pos_delta) { 77 77 78 78 // define the output filename 79 79 psString filename = NULL; … … 95 95 psStringAppend (&command, " -dec %f", dec); 96 96 psStringAppend (&command, " -pa %f", pos); 97 psStringAppend (&command, " -obs_mode OBJECT.%s", (char *) filters->data[i]);97 psStringAppend (&command, " -obs_mode OBJECT.%s", (char *) filters->data[i]); 98 98 99 99 double frnd = psRandomUniform(rng); 100 100 float seeing = IQmin + (IQmax - IQmin)*frnd; 101 101 102 102 psStringAppend (&command, " -seeing %f", seeing); 103 103 … … 106 106 fprintf (simfile, "%s\n", command); 107 107 psFree (command); 108 108 109 109 // define the inject command 110 110 // path should be dirname/filename 111 command = psStringCopy (injectCommand); 112 psStringAppend (&command, " %s*.fits", filename); 113 fprintf (inject, "%s\n", command); 114 psFree (command); 111 112 // we use the filename above (really the file root) to construct the filenames 113 for (int i = 0; i < files->n; i++) { 114 command = psStringCopy (injectCommand); 115 psStringAppend (&command, " %s.%s", filename, (char *) files->data[i]); 116 fprintf (inject, "%s\n", command); 117 psFree (command); 118 } 119 115 120 psFree (filename); 116 117 121 nImage ++; 118 122 }
Note:
See TracChangeset
for help on using the changeset viewer.
