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