Changeset 4585 for trunk/Ohana/src/opihi/dvo/avextract.c
- Timestamp:
- Jul 20, 2005, 4:27:25 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/avextract.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/avextract.c
r4420 r4585 3 3 int avextract (int argc, char **argv) { 4 4 5 int i, j, m, N, NPTS, param; 6 int Ngraph, Nsec, Nregions, mode; 7 char filename[256], catdir[256], *RegionName, *RegionList, *p; 8 5 9 Catalog catalog; 6 Graphdata graphsky;7 10 RegionFile *regions; 8 11 PhotCode *code; 9 12 Vector *vec; 10 13 11 char filename[256], catdir[256], *p; 12 int i, j, m, N, NPTS, param; 13 int Ngraph, Nsec, Nregions, mode; 14 14 /* defaults */ 15 15 regions = NULL; 16 16 catalog.average = NULL; 17 17 catalog.secfilt = NULL; 18 18 catalog.measure = NULL; 19 RegionName = NULL; 20 RegionList = NULL; 21 code = NULL; 22 mode = MAG_AVE; 19 23 20 24 /* load photcode information */ … … 22 26 Nsec = GetPhotcodeNsecfilt (); 23 27 24 /* load data about plot windows */25 Ngraph = 0;26 if (!GetGraphData (&graphsky, NULL, &Ngraph)) goto escape;27 28 28 /* find CATDIR in config system */ 29 VarConfig ("CATDIR", "%s", catdir); 30 31 /* grab value of photcode, if available */ 32 code = NULL; 33 mode = MAG_AVE; 34 if (N = get_argument (argc, argv, "-photcode")) { 35 remove_argument (N, &argc, argv); 36 code = GetPhotcodebyName (argv[N]); 37 if (code == NULL) { 38 fprintf (stderr, "photcode not found in photcode table\n"); 39 goto usage; 40 } 41 remove_argument (N, &argc, argv); 42 } 29 if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape; 43 30 44 31 /* interpret command-line options */ 45 if (!SetPhotSelections (&argc, argv)) goto usage; 46 if (argc != 3) { goto usage; } 32 SetSelectionParam (0); 33 if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape; 34 if (!SetPhotSelections (&argc, argv, 1)) goto usage; 47 35 48 /* identify selection */ 49 param = GetAverageParam (argv[2]); 36 /* interpret required command-line arguments: mextract (value) */ 37 if (argc != 2) { goto usage; } 38 param = GetAverageParam (argv[1]); 50 39 if (param == AVE_ZERO) { 51 if (!GetPhotcodeInfo (argv[ 2], &code, &mode)) {40 if (!GetPhotcodeInfo (argv[1], &code, &mode)) { 52 41 GetAverageParamHelp (); 53 42 goto escape; 54 43 } 55 44 param = AVE_MAG; 56 for (p = argv[ 2]; *p != 0; p++) {45 for (p = argv[1]; *p != 0; p++) { 57 46 if (*p == '.') *p = ':'; 58 47 } 59 48 } 60 if ( (vec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto escape;49 if (!TestPhotSelections (&code, param)) goto escape; 61 50 62 /* Need valid code for some params: */ 63 switch (param) { 64 case AVE_MAG: 65 case AVE_dMAG: 66 case AVE_Xm: 67 case AVE_TYPE: 68 case AVE_NCODE: 69 case AVE_NPHOT: 70 if (code == NULL) goto escape; 71 if (code[0].type == PHOT_DEP) goto escape; 72 if (code[0].type == PHOT_REF) goto escape; 73 break; 74 default: 75 break; 76 } 77 78 /* determine region-file names */ 79 if (!strcmp (argv[1], "all")) { 80 float Radius; 81 Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax)); 82 regions = find_regions (graphsky.coords.crval1, graphsky.coords.crval2, Radius, &Nregions); 83 if (!SetImageSelection (param, &graphsky, TRUE)) goto escape; 84 /* this is not really used by avextract -- no parameters require images */ 85 } else { 86 Nregions = 1; 87 ALLOCATE (regions, RegionFile, 1); 88 strcpy (regions[0].name, argv[1]); 89 if (!SetImageSelection (param, NULL, FALSE)) goto escape; 90 } 51 /* load region corresponding to selection above */ 52 if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape; 91 53 92 54 /* create storage vector */ 93 55 N = 0; 94 NPTS = 1 000;95 REALLOCATE (vec[0].elements, float, NPTS);56 NPTS = 1; 57 if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape; 96 58 97 59 for (i = 0; i < Nregions; i++) { … … 115 77 vec[0].elements[N] = ExtractAverages (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsec], &catalog.measure[m], param); 116 78 N++; 117 if (N == NPTS - 1) { 118 NPTS += 2000; 119 REALLOCATE (vec[0].elements, float, NPTS); 120 } 79 CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000); 121 80 } 122 81 if (catalog.average != NULL) free (catalog.average); … … 131 90 132 91 if (regions != NULL) free (regions); 133 FreeImageSelection ();134 92 return (TRUE); 135 93 136 94 usage: 137 fprintf (stderr, "USAGE: avextract (from) (value) [options]\n"); 138 fprintf (stderr, " from: cpt name or 'all'\n"); 95 fprintf (stderr, "USAGE: avextract (value) [options]\n"); 139 96 fprintf (stderr, " value: average.parameter or photcode\n"); 140 return (FALSE);141 97 142 98 escape: 143 fprintf (stderr, "error in avextract\n");144 99 if (regions != NULL) free (regions); 145 FreeImageSelection ();146 100 if (catalog.average != NULL) free (catalog.average); 147 101 if (catalog.secfilt != NULL) free (catalog.secfilt); 148 102 if (catalog.measure != NULL) free (catalog.measure); 103 if (RegionName != NULL) free (RegionName); 104 if (RegionList != NULL) free (RegionList); 149 105 return (FALSE); 150 106 }
Note:
See TracChangeset
for help on using the changeset viewer.
