Changeset 9433 for trunk/psModules/src/detrend/pmDetrendDB.c
- Timestamp:
- Oct 9, 2006, 3:02:25 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmDetrendDB.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmDetrendDB.c
r9290 r9433 8 8 #include "pmFPA.h" 9 9 #include "pmDetrendDB.h" 10 #include "psPipe.h" 11 #include "psIOBuffer.h" 10 12 11 13 // ************* detrend select functions ************** … … 25 27 26 28 // define basic options for a new detrend database query 27 pmDetrendSelectOptions *pmDetrendSelectOptionsAlloc(c har *camera, psTime time, pmDetrendType type)29 pmDetrendSelectOptions *pmDetrendSelectOptionsAlloc(const char *camera, psTime time, pmDetrendType type) 28 30 { 29 31 … … 32 34 33 35 // basic options required by every query 34 options->camera = ps MemIncrRefCounter(camera);36 options->camera = psStringCopy (camera); 35 37 options->time = time; 36 38 options->type = type; 37 39 38 40 // these other options depend on the type of detrend data 39 options->filter = NULL; 40 options->exptime = 0.0;41 options->airmass = 0.0;41 options->filter = NULL; // 42 options->exptime = -1.0; // the undefined value (safe since exptime >= 0) 43 options->airmass = -1.0; // the undefined value (safe since airmass >= 1) 42 44 43 45 return options; … … 90 92 // detselect -camera (camera) -time (time) -type (type) [others] 91 93 // returns: (type) (class) (exp_flag) DONE 92 pmDetrendSelectResults *pmDetrendSelect ( pmDetrendSelectOptions *options)93 { 94 boolstatus;94 pmDetrendSelectResults *pmDetrendSelect (const pmDetrendSelectOptions *options) 95 { 96 int status, exit_status; 95 97 char *line = NULL; 96 97 98 char *time = psTimeToISO (&options->time); 98 99 char *type = pmDetrendTypeToString (options->type); 99 100 101 psArray *array = NULL; 102 pmDetrendSelectResults *results = pmDetrendSelectResultsAlloc(); 103 100 104 // generate the detselect command 101 psStringAppend (&line, "detselect -camera %s -time %s -type %s", options->camera, time, type); 102 psFree (time); 103 psFree (type); 105 // psStringAppend (&line, "detselect -inst %s -time %s -det_type %s", options->camera, time, type); 106 // XXX we need to put in the filter and other restrictions based on the recipe 107 // detselect -search -simple returns: DET_ID ITERATION CLASS TYPE 108 psStringAppend (&line, "detselect -search -simple -inst %s -det_type %s", options->camera, type); 109 if (options->filter) { 110 psStringAppend (&line, " -filter %s", options->filter); 111 } 112 if (options->exptime > -1.0) { 113 psStringAppend (&line, " -exptime %f", options->exptime); 114 } 115 if (options->airmass > -1.0) { 116 psStringAppend (&line, " -airmass %f", options->airmass); 117 } 118 119 psTrace("psModules.detrend", 5, "running %s", line); 104 120 105 121 // use psPipe to exec the command, wait for response 106 122 psIOBuffer *buffer = psIOBufferAlloc (512); 107 123 psPipe *pipe = psPipeOpen (line); 124 if (!pipe) { 125 psError (PS_ERR_IO, false, "error calling command %s", line); 126 goto failure; 127 } 128 108 129 status = psIOBufferReadEmpty (buffer, 100, pipe->stdout); 109 130 if (!status) { 110 131 psError (PS_ERR_IO, false, "detselect is not responding"); 111 psFree (buffer); 112 psFree (pipe); 113 psFree (line); 114 return NULL; 115 } 116 psPipeClose (pipe); 117 psFree (pipe); 118 psFree (line); 132 goto failure; 133 } 134 exit_status = psPipeClose (pipe); 135 if (exit_status) { 136 psError (PS_ERR_IO, false, "error running detselect"); 137 goto failure; 138 } 139 140 psTrace("psModules.detrend", 5, "got answer: %s\n", buffer->data); 119 141 120 142 // XXX need to parse the response more robustly 121 143 // XXX for now, assume a single line 122 psArray *array = psStringSplitArray (buffer->data, " ", false); 123 psFree (buffer); 124 125 if (!array) 126 return NULL; 127 if (!array->n) 128 return NULL; 129 if (!strcasecmp(array->data[0], "ERROR")) 130 return NULL; 131 132 pmFPALevel level = pmFPALevelFromName (array->data[1]); 133 if (level == PM_FPA_LEVEL_NONE) 134 return NULL; 135 136 pmDetrendSelectResults *results = pmDetrendSelectResultsAlloc(); 144 array = psStringSplitArray (buffer->data, " ", false); 145 146 if (!array) { 147 psError(PS_ERR_IO, false, "failed to split detselect answer %s\n", buffer->data); 148 goto failure; 149 } 150 if (array->n != 4) { 151 psError(PS_ERR_IO, false, "invalid number of fields in detselect answer %s (%ld)\n", buffer->data, array->n); 152 goto failure; 153 } 154 155 pmFPALevel level = pmFPALevelFromName (array->data[2]); 156 if (level == PM_FPA_LEVEL_NONE) { 157 psError(PS_ERR_IO, false, "invalid file level (%s) from detselect\n", (char *)array->data[2]); 158 goto failure; 159 } 160 137 161 results->level = level; 138 results->detID = psStringCopy (array->data[2]); 139 140 psFree (array); 162 psStringAppend (&results->detID, " -det_id %s -iteration %s ", (char *)array->data[0], (char *)array->data[1]); 163 164 psTrace("psModules.detrend", 5, "generated detID %s\n", results->detID); 165 psTrace("psModules.detrend", 5, "fileLevel is %d (%s)\n", results->level, (char *)array->data[2]); 166 psTrace("psModules.detrend", 5, "selected type is %s\n", (char *)array->data[3]); 167 168 psFree (array); 169 psFree (pipe); 170 psFree (buffer); 171 psFree (line); 172 psFree (type); 173 psFree (time); 141 174 return results; 175 176 failure: 177 psFree (array); 178 psFree (results); 179 psFree (pipe); 180 psFree (buffer); 181 psFree (line); 182 psFree (type); 183 psFree (time); 184 return NULL; 142 185 } 143 186 … … 146 189 // detselect -select -detID (detID) -classID (classID) 147 190 // returns: (detID) (classID) (filename) DONE 148 char *pmDetrendFile (char *detID, char *classID) 149 { 191 char *pmDetrendFile (const char *detID, const char *classID) 192 { 193 PS_ASSERT_PTR_NON_NULL(detID, NULL); 194 PS_ASSERT_PTR_NON_NULL(classID, NULL); 195 150 196 bool status; 151 197 char *line = NULL; 198 psArray *array = NULL; 152 199 153 200 // generate the detselect command 154 psStringAppend (&line, "detselect -select -detID %s -classID %s", detID, classID); 201 psStringAppend (&line, "detselect -select -simple %s -class_id %s", detID, classID); 202 psTrace("psModules.detrend", 5, "running %s", line); 155 203 156 204 // use psPipe to exec the command, wait for response 157 205 psIOBuffer *buffer = psIOBufferAlloc (512); 158 206 psPipe *pipe = psPipeOpen (line); 207 if (!pipe) { 208 psError (PS_ERR_IO, false, "error calling command %s", line); 209 goto failure; 210 } 159 211 status = psIOBufferReadEmpty (buffer, 100, pipe->stdout); 160 212 if (!status) { 161 213 psError (PS_ERR_IO, false, "detselect is not responding"); 162 psFree (buffer); 163 psFree (pipe); 164 psFree (line); 165 return NULL; 166 } 167 psPipeClose (pipe); 168 psFree (pipe); 169 psFree (line); 214 goto failure; 215 } 216 status = psPipeClose (pipe); 217 if (status) { 218 psError (PS_ERR_IO, false, "error running detselect"); 219 goto failure; 220 } 221 222 psTrace("psModules.detrend", 5, "got answer: %s\n", buffer->data); 170 223 171 224 // XXX need to parse the response more robustly 172 225 // XXX for now, assume a single line 173 psArray *array = psStringSplitArray (buffer->data, " ", false); 174 psFree (buffer); 175 176 if (!array) 177 return NULL; 178 if (!array->n) 179 return NULL; 180 if (!strcasecmp(array->data[0], "ERROR")) 181 return NULL; 182 183 char *result = psStringCopy (array->data[2]); 184 185 psFree (array); 226 array = psStringSplitArray (buffer->data, " ", false); 227 228 if (!array) { 229 psError(PS_ERR_IO, false, "failed to split detselect answer %s\n", buffer->data); 230 goto failure; 231 } 232 if (array->n == 0) { 233 psError(PS_ERR_IO, true, "empty result set from detselect\n"); 234 goto failure; 235 } 236 if (array->n < 5) { 237 psError(PS_ERR_IO, true, "invalid result set from detselect %s\n", buffer->data); 238 goto failure; 239 } 240 241 char *result = psStringCopy (array->data[4]); 242 psTrace("psModules.detrend", 5, "detrend file: %s\n", result); 243 244 psFree (array); 245 psFree (pipe); 246 psFree (buffer); 247 psFree (line); 186 248 return result; 187 } 249 250 failure: 251 psFree (array); 252 psFree (pipe); 253 psFree (buffer); 254 psFree (line); 255 return NULL; 256 }
Note:
See TracChangeset
for help on using the changeset viewer.
