Changeset 13479 for trunk/Ohana/src/opihi/dvo/mextract.c
- Timestamp:
- May 22, 2007, 12:23:09 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/mextract.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/mextract.c
r12332 r13479 3 3 int mextract (int argc, char **argv) { 4 4 5 int i, j, k, m, N, N1, NPTS;5 int i, j, k, m, n, N, N1, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack; 6 6 int param, mode, Nsecfilt; 7 7 char *RegionName, *RegionList, *p; 8 8 double *M1; 9 char **cstack; 10 float *values; 9 11 10 PhotCode *code;11 12 Catalog catalog; 12 13 SkyList *skylist; 13 Vector *vec; 14 PhotCode *code; 15 Vector **vec; 16 17 dbField *fields; 18 dbStack *stack; 14 19 15 20 /* defaults */ … … 24 29 if (!InitPhotcodes ()) goto escape; 25 30 Nsecfilt = GetPhotcodeNsecfilt (); 31 32 // init locally static variables (time refs) 33 dbExtractMeasuresInit(); 26 34 27 / * interpret command-line options */28 SetSelectionParam (0);35 // remove skyregion options 36 // XXX this needs to explicitly handle -qregion and -skyregion 29 37 if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape; 30 if (!SetPhotSelections (&argc, argv, 1)) goto usage;31 38 32 /* interpret required command-line arguments: mextract (value) */ 33 if (argc != 2) goto usage; 34 param = GetMeasureParam (argv[1]); 35 if (param == MEAS_ZERO) { 36 if (!GetPhotcodeInfo (argv[1], &code, &mode)) { 37 GetMeasureParam ("help"); 38 goto escape; 39 } 40 param = MEAS_MAG; 41 for (p = argv[1]; *p != 0; p++) { 42 if (*p == '.') *p = ':'; 43 } 44 } 45 if (!TestPhotSelections (&code, &mode, MEAS_ZERO)) goto escape; 39 // command-line is of the form: avextract field,field, field [where (field op value)...] 40 41 // parse the fields to be extracted and returned 42 fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields); 43 if (fields == NULL) return (FALSE); 44 45 // parse the remainder of the line as a boolean math expression 46 cstack = isolate_elements (argc-last, &argv[last], &Ncstack); 47 48 // construct the db Boolean math stack (frees cstack) 49 stack = dbRPN (Ncstack, cstack, &Nstack); 50 51 Nreturn = Nfields; 52 dbCheckStack (stack, Nstack, DVO_TABLE_MEASURE, &fields, &Nfields); 53 // XXX handle errors 46 54 47 55 /* load region corresponding to selection above */ 48 56 if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape; 49 if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape; 57 58 // XXX is this still needed? 59 // if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape; 50 60 51 61 /* create storage vector */ 52 N = 0; 62 ALLOCATE (values, float, Nfields); 63 ALLOCATE (vec, Vector *, Nreturn); 64 for (i = 0; i < Nreturn; i++) { 65 if ((vec[i] = SelectVector (fields[i].name, ANYVECTOR, TRUE)) == NULL) goto escape; 66 } 67 68 Npts = 0; 53 69 NPTS = 1; 54 if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;55 70 71 // XXX need to add interrupt test to this loop 56 72 for (i = 0; i < skylist[0].Nregions; i++) { 73 /* lock, load, unlock catalog */ 57 74 catalog.filename = skylist[0].filename[i]; 58 75 catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF; … … 69 86 70 87 for (j = 0; j < catalog.Naverage; j++) { 71 M1 = NULL;72 88 m = catalog.average[j].offset; 73 M1 = ExtractMeasures (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &N1, param); 74 for (k = 0; k < N1; k++) { 75 vec[0].elements[N] = M1[k]; 76 N++; 77 CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000); 89 for (k = 0; k < catalog.average[j].Nm; k++, m++) { 90 91 // extract the relevant values for this measurement 92 for (n = 0; n < Nfields; n++) { 93 values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]); 94 } 95 96 // test the conditional statement 97 if (!dbBooleanCond (stack, Nstack, values)) continue; 98 for (n = 0; n < Nreturn; n++) { 99 vec[n][0].elements[Npts] = values[n]; 100 } 101 Npts++; 102 if (Npts >= NPTS) { 103 NPTS += 2000; 104 for (n = 0; n < Nreturn; n++) { 105 REALLOCATE (vec[n][0].elements, float, NPTS); 106 } 107 } 78 108 } 79 if (M1 != NULL) free (M1);80 109 } 81 110 dvo_catalog_free (&catalog); 82 111 } 83 vec[0].Nelements = N; 84 REALLOCATE (vec[0].elements, float, MAX(1,N)); 112 for (n = 0; n < Nreturn; n++) { 113 vec[n][0].Nelements = Npts; 114 REALLOCATE (vec[n][0].elements, float, MAX(1,Npts)); 115 } 116 117 // XXX free fields and stack 85 118 86 119 FreeImageSelection ();
Note:
See TracChangeset
for help on using the changeset viewer.
