Changeset 20936 for trunk/Ohana/src/opihi/dvo/mmextract.c
- Timestamp:
- Dec 7, 2008, 3:31:01 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/mmextract.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/mmextract.c
r20819 r20936 8 8 int Nsecfilt, VERBOSE, loadImages, mosaicMode; 9 9 char **cstack1, **cstack2, name1[1024], name2[1024]; 10 float*values, **table1, **table2;10 dbValue *values, **table1, **table2; 11 11 void *Signal; 12 12 13 13 Catalog catalog; 14 14 SkyList *skylist; 15 PhotCode *code;16 15 Vector **vec; 17 16 dbField *fields; … … 21 20 22 21 /* defaults */ 23 skylist = NULL; 24 code = NULL; 25 fields = NULL; 22 vec = NULL; 26 23 stack1 = NULL; 27 24 stack2 = NULL; 25 fields = NULL; 26 values = NULL; 27 skylist = NULL; 28 selection = NULL; 28 29 29 30 if ((N = get_argument (argc, argv, "-h"))) goto help; … … 57 58 // parse the fields to be extracted and returned : last points to end, or first 'where' or 'matched' 58 59 fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields); 59 if (fields == NULL) return (FALSE); 60 if (fields == NULL) goto escape; 61 if (Nfields == 0) { 62 FreeSkyRegionSelection (selection); 63 dbFreeFields (fields, Nfields); 64 dvo_catalog_free (&catalog); 65 goto help; 66 } 60 67 61 68 // examine line for 'where' and 'match to'. neither is required, but order is fixed … … 139 146 140 147 /* create storage vector */ 141 ALLOCATE (values, float, Nfields);148 ALLOCATE (values, dbValue, Nfields); 142 149 ALLOCATE (vec, Vector *, Nreturn); 143 150 … … 152 159 if ((vec[2*i+0] = SelectVector (name1, ANYVECTOR, TRUE)) == NULL) goto escape; 153 160 if ((vec[2*i+1] = SelectVector (name2, ANYVECTOR, TRUE)) == NULL) goto escape; 161 ResetVector (vec[2*i+0], fields[i].type, fields[i].type); 162 ResetVector (vec[2*i+1], fields[i].type, fields[i].type); 154 163 } 155 164 … … 158 167 159 168 // we save the selected measures for each average to temporary tables 1 and 2 169 // XXX need to deal with the INT / DBL difference here... 160 170 NTABLE = 100; 161 ALLOCATE (table1, float*, Nreturn_base);162 ALLOCATE (table2, float*, Nreturn_base);171 ALLOCATE (table1, dbValue *, Nreturn_base); 172 ALLOCATE (table2, dbValue *, Nreturn_base); 163 173 for (i = 0; i < Nreturn_base; i++) { 164 ALLOCATE (table1[i], float, NTABLE);165 ALLOCATE (table2[i], float, NTABLE);174 ALLOCATE (table1[i], dbValue, NTABLE); 175 ALLOCATE (table2[i], dbValue, NTABLE); 166 176 } 167 177 … … 194 204 NTABLE = catalog.average[j].Nmeasure; 195 205 for (n = 0; n < Nreturn_base; n++) { 196 REALLOCATE (table1[n], float, NTABLE);197 REALLOCATE (table2[n], float, NTABLE);206 REALLOCATE (table1[n], dbValue, NTABLE); 207 REALLOCATE (table2[n], dbValue, NTABLE); 198 208 } 199 209 } … … 206 216 dbExtractMeasuresInitMeas (); // reset counters for saved fields 207 217 for (n = 0; n < Nfields; n++) { 218 // values needs to be a pointer to a type with FLT and INT (with a union, we would save a bit of memory...) 208 219 values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]); 209 220 } … … 232 243 for (n2 = 0; n2 < Nt2; n2++) { 233 244 for (n = 0; n < Nreturn_base; n++) { 234 vec[2*n+0][0].elements[Npts] = table1[n][n1]; 235 vec[2*n+1][0].elements[Npts] = table2[n][n2]; 245 if (vec[2*n+0][0].type == OPIHI_FLT) { 246 vec[2*n+0][0].elements.Flt[Npts] = table1[n][n1].Flt; 247 vec[2*n+1][0].elements.Flt[Npts] = table2[n][n2].Flt; 248 } else { 249 vec[2*n+0][0].elements.Int[Npts] = table1[n][n1].Int; 250 vec[2*n+1][0].elements.Int[Npts] = table2[n][n2].Int; 251 } 236 252 } 237 253 Npts++; … … 239 255 NPTS += 2000; 240 256 for (n = 0; n < Nreturn; n++) { 241 REALLOCATE (vec[n][0].elements, float, NPTS); 257 if (vec[n][0].type == OPIHI_FLT) { 258 REALLOCATE (vec[n][0].elements.Flt, opihi_flt, NPTS); 259 } else { 260 REALLOCATE (vec[n][0].elements.Int, opihi_int, NPTS); 261 } 242 262 } 243 263 } … … 255 275 interrupt = FALSE; 256 276 277 // free excess memory 257 278 for (n = 0; n < Nreturn; n++) { 258 279 vec[n][0].Nelements = Npts; 259 REALLOCATE (vec[n][0].elements, float, MAX(1,Npts)); 280 if (vec[n][0].type == OPIHI_FLT) { 281 REALLOCATE (vec[n][0].elements.Flt, opihi_flt, MAX(1,Npts)); 282 } else { 283 REALLOCATE (vec[n][0].elements.Int, opihi_int, MAX(1,Npts)); 284 } 260 285 } 261 286 … … 280 305 281 306 escape: 307 if (vec) free (vec); 308 if (values) free (values); 282 309 dbFreeFields (fields, Nfields); 283 310 dbFreeStack (stack1, Nstack1); … … 292 319 293 320 help: 294 gprint (GP_ERR, "USAGE: mextract field[,field,field...] where (expression)\n"); 321 gprint (GP_ERR, "USAGE: mmextract field[,field,field...] where (expression) match to (expression)\n"); 322 gprint (GP_ERR, " pairs of fields are returned: the first set are restricted by the 'where' expression, the second by the 'match to' expression\n"); 295 323 296 324 if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) { … … 344 372 return (FALSE); 345 373 } 346 gprint (GP_ERR, " m extract --help fields : for a complete listing of allowed fields\n");374 gprint (GP_ERR, " mmextract --help fields : for a complete listing of allowed fields\n"); 347 375 return (FALSE); 348 376 }
Note:
See TracChangeset
for help on using the changeset viewer.
