- Timestamp:
- Jun 19, 2012, 5:24:19 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
Ohana/src/opihi/dvo/avmatch.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/Ohana/src/opihi/dvo/avmatch.c
r28241 r34041 14 14 15 15 off_t i, j, n, m, *index; 16 int N, Ncat, Npts, NPTS, last, Nfields, Nsecfilt ;16 int N, Ncat, Npts, NPTS, last, Nfields, Nsecfilt, Ninvec; 17 17 int VERBOSE; 18 char name[1024] ;18 char name[1024], *found; 19 19 void *Signal; 20 20 float RADIUS; … … 22 22 Catalog catalog; 23 23 24 Vector **vec, * RAvec, *DECvec;24 Vector **vec, **invec, *RAvec, *DECvec; 25 25 dbField *fields; 26 26 dbValue *values; … … 29 29 /* defaults */ 30 30 vec = NULL; 31 invec = NULL; 31 32 fields = NULL; 32 33 values = NULL; 33 34 skylist = NULL; 35 Ninvec = 0; 34 36 35 37 if ((N = get_argument (argc, argv, "-h"))) goto help; 36 38 if ((N = get_argument (argc, argv, "--help"))) goto help; 37 if (argc < 5) goto help;38 39 39 40 VERBOSE = FALSE; … … 43 44 } 44 45 46 int PARALLEL = FALSE; 47 if ((N = get_argument (argc, argv, "-parallel"))) { 48 remove_argument (N, &argc, argv); 49 PARALLEL = TRUE; 50 } 51 52 // dump results directly to fits file (esp for parallel dvo) 53 char *CoordsFile = NULL; 54 if ((N = get_argument (argc, argv, "-coords"))) { 55 remove_argument (N, &argc, argv); 56 CoordsFile = strcreate(argv[N]); 57 remove_argument (N, &argc, argv); 58 } 59 60 if (!CoordsFile && (argc < 5)) goto help; 61 if ( CoordsFile && (argc < 3)) goto help; 62 45 63 dvo_catalog_init (&catalog, TRUE); 46 64 … … 49 67 Nsecfilt = GetPhotcodeNsecfilt (); 50 68 69 // init locally static variables (time refs) 70 dbExtractAveragesInit (); 71 72 // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results 73 RAvec = NULL; 74 DECvec = NULL; 75 if (PARALLEL && !HOST_ID) { 76 if (!CoordsFile) { 77 // get vectors corresponding to coordinates of interest 78 if ((RAvec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help; 79 if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help; 80 81 ALLOCATE (vec, Vector *, 2); 82 vec[0] = RAvec; 83 vec[1] = DECvec; 84 85 CoordsFile = abspath("coords.fits", 1024); 86 int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL); 87 if (!status) goto escape; 88 } 89 90 char *targv1 = argv[1]; 91 char *targv2 = argv[2]; 92 argv[1] = strcreate ("-coords"); 93 argv[2] = strcreate (CoordsFile); 94 free (CoordsFile); 95 96 // I need to pass the RA & DEC vectors to the remote clients... 97 int status = HostTableParallelOps (argc, argv, RESULT_FILE, RAvec->Nelements, VERBOSE); 98 if (vec) free (vec); 99 100 free (argv[1]); 101 free (argv[2]); 102 argv[1] = targv1; 103 argv[2] = targv2; 104 105 return status; 106 } 107 51 108 // get vectors corresponding to coordinates of interest 52 if ((RAvec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help; 53 if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help; 54 RADIUS = atof (argv[3]); 55 56 // strip off RA, DEC, RADIUS arguments 57 remove_argument (1, &argc, argv); 58 remove_argument (1, &argc, argv); 109 if (CoordsFile) { 110 // read RAvec, DECvec from coords file (1st 2 fields?) 111 Ninvec = 0; 112 invec = ReadVectorTableFITS (CoordsFile, "COORDS", &Ninvec); 113 RAvec = invec[0]; 114 DECvec = invec[1]; 115 } else { 116 if ((RAvec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help; 117 if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help; 118 // strip off RA & DEC 119 remove_argument (1, &argc, argv); 120 remove_argument (1, &argc, argv); 121 } 122 RADIUS = atof (argv[1]); 59 123 remove_argument (1, &argc, argv); 60 124 … … 66 130 dvo_catalog_free (&catalog); 67 131 goto help; 132 } 133 134 // check the requested fields : are all average/secfilt entries, or do we need measures? 135 int needMeasures = FALSE; 136 for (i = 0; !needMeasures && (i < Nfields); i++) { 137 if (fields[i].magMode == MAG_NONE) continue; 138 if (fields[i].photcode == NULL) continue; // assert this? 139 if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE; 140 if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE; 68 141 } 69 142 … … 92 165 } 93 166 ALLOCATE (index, off_t, NPTS); 167 ALLOCATE (found, char, NPTS); 168 memset (found, 0, NPTS*sizeof(char)); 94 169 95 170 // grab data from all selected sky regions … … 97 172 interrupt = FALSE; 98 173 for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) { 174 175 // does this host ID match the desired location for the table? 176 if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue; 177 99 178 /* lock, load, unlock catalog */ 100 catalog.filename = skylist[0].filename[i]; 101 catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF; 179 char hostfile[1024]; 180 snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name); 181 catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i]; 182 catalog.catflags = LOAD_AVES | LOAD_SECF; 183 catalog.catflags |= needMeasures ? LOAD_MEAS : SKIP_MEAS; 102 184 catalog.Nsecfilt = 0; 103 185 … … 124 206 if (Ncat == -2) continue; 125 207 126 // XXX set a 'found' vector to double check we catch everything?127 208 m = catalog.average[Ncat].measureOffset; 128 209 129 210 // reset counters for saved fields, extract fields 130 dbExtractAveragesInit ();211 dbExtractAveragesInitAve (); 131 212 for (n = 0; n < Nfields; n++) { 132 213 values[n] = dbExtractAverages (&catalog.average[Ncat], &catalog.secfilt[Ncat*Nsecfilt], &catalog.measure[m], &fields[n]); … … 141 222 } 142 223 } 224 found[Npts] = TRUE; 143 225 } 144 226 dvo_catalog_free (&catalog); … … 147 229 interrupt = FALSE; 148 230 231 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 232 // only write the fields which were in a valid catalog 233 if (RESULT_FILE) { 234 // extend the array by one to hold index array 235 REALLOCATE (vec, Vector *, Nfields + 1); 236 vec[Nfields] = InitVector(); 237 strcpy (vec[Nfields]->name, "index"); 238 ResetVector (vec[Nfields], OPIHI_INT, NPTS); 239 Vector *idxVec = vec[Nfields]; 240 241 // only write out the rows which were found 242 Npts = 0; 243 for (i = 0; i < NPTS; i++) { 244 if (!found[i]) continue; 245 idxVec->elements.Int[Npts] = i; 246 Npts ++; 247 } 248 int Nfound = Npts; 249 idxVec->Nelements = Nfound; 250 251 fprintf (stderr, "found %d of %d pts\n", Nfound, NPTS); 252 253 for (i = 0; i < Nfields; i++) { 254 if (vec[i][0].type == OPIHI_FLT) { 255 opihi_flt *tmp = NULL; 256 ALLOCATE (tmp, opihi_flt, Nfound); 257 Npts = 0; 258 for (j = 0; j < NPTS; j++) { 259 if (!found[j]) continue; 260 tmp[Npts] = vec[i][0].elements.Flt[j]; 261 Npts++; 262 } 263 free (vec[i][0].elements.Flt); 264 vec[i][0].elements.Flt = tmp; 265 } else { 266 opihi_int *tmp = NULL; 267 ALLOCATE (tmp, opihi_int, Nfound); 268 Npts = 0; 269 for (j = 0; j < NPTS; j++) { 270 if (!found[j]) continue; 271 tmp[Npts] = vec[i][0].elements.Int[j]; 272 Npts++; 273 } 274 free (vec[i][0].elements.Int); 275 vec[i][0].elements.Int = tmp; 276 } 277 vec[i][0].Nelements = Nfound; 278 } 279 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL); 280 free (vec[Nfields]->elements.Int); 281 free (vec[Nfields]); 282 if (!status) goto escape; 283 } 284 149 285 if (vec) free (vec); 150 286 if (values) free (values); 287 if (invec) FreeVectorArray (invec, Ninvec); 151 288 dbFreeFields (fields, Nfields); 152 289 SkyListFree (skylist); … … 156 293 if (vec) free (vec); 157 294 if (values) free (values); 295 if (invec) FreeVectorArray (invec, Ninvec); 158 296 dbFreeFields (fields, Nfields); 159 297 SkyListFree (skylist); … … 162 300 help: 163 301 gprint (GP_ERR, "USAGE: avmatch (RA) (DEC) (RADIUS) field[,field,field...]\n"); 302 gprint (GP_ERR, " OR: avmatch -coords (filename.fits) (RADIUS) field[,field,field...]\n"); 164 303 165 304 if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
Note:
See TracChangeset
for help on using the changeset viewer.
