Changeset 33662 for trunk/Ohana/src/opihi/dvo/avmatch.c
- Timestamp:
- Apr 1, 2012, 3:24:39 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/avmatch.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/avmatch.c
r28241 r33662 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 // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results 70 RAvec = NULL; 71 DECvec = NULL; 72 if (PARALLEL && !HOST_ID) { 73 if (!CoordsFile) { 74 // get vectors corresponding to coordinates of interest 75 if ((RAvec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help; 76 if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help; 77 78 ALLOCATE (vec, Vector *, 2); 79 vec[0] = RAvec; 80 vec[1] = DECvec; 81 82 CoordsFile = abspath("coords.fits", 1024); 83 int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL); 84 if (!status) goto escape; 85 } 86 87 char *targv1 = argv[1]; 88 char *targv2 = argv[2]; 89 argv[1] = strcreate ("-coords"); 90 argv[2] = strcreate (CoordsFile); 91 free (CoordsFile); 92 93 // I need to pass the RA & DEC vectors to the remote clients... 94 int status = HostTableParallelOps (argc, argv, RESULT_FILE, RAvec->Nelements, VERBOSE); 95 if (vec) free (vec); 96 97 free (argv[1]); 98 free (argv[2]); 99 argv[1] = targv1; 100 argv[2] = targv2; 101 102 return status; 103 } 104 51 105 // 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); 106 if (CoordsFile) { 107 // read RAvec, DECvec from coords file (1st 2 fields?) 108 Ninvec = 0; 109 invec = ReadVectorTableFITS (CoordsFile, "COORDS", &Ninvec); 110 RAvec = invec[0]; 111 DECvec = invec[1]; 112 } else { 113 if ((RAvec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help; 114 if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help; 115 // strip off RA & DEC 116 remove_argument (1, &argc, argv); 117 remove_argument (1, &argc, argv); 118 } 119 RADIUS = atof (argv[1]); 59 120 remove_argument (1, &argc, argv); 60 121 … … 92 153 } 93 154 ALLOCATE (index, off_t, NPTS); 155 ALLOCATE (found, char, NPTS); 156 memset (found, 0, NPTS*sizeof(char)); 94 157 95 158 // grab data from all selected sky regions … … 97 160 interrupt = FALSE; 98 161 for (i = 0; (i < skylist[0].Nregions) && !interrupt; i++) { 162 163 // does this host ID match the desired location for the table? 164 if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue; 165 99 166 /* lock, load, unlock catalog */ 100 catalog.filename = skylist[0].filename[i]; 167 char hostfile[1024]; 168 snprintf (hostfile, 1024, "%s/%s.cpt", HOSTDIR, skylist[0].regions[i]->name); 169 catalog.filename = HOST_ID ? hostfile : skylist[0].filename[i]; 101 170 catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF; 102 171 catalog.Nsecfilt = 0; … … 124 193 if (Ncat == -2) continue; 125 194 126 // XXX set a 'found' vector to double check we catch everything?127 195 m = catalog.average[Ncat].measureOffset; 128 196 … … 141 209 } 142 210 } 211 found[Npts] = TRUE; 143 212 } 144 213 dvo_catalog_free (&catalog); … … 147 216 interrupt = FALSE; 148 217 218 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 219 // only write the fields which were in a valid catalog 220 if (RESULT_FILE) { 221 // extend the array by one to hold index array 222 REALLOCATE (vec, Vector *, Nfields + 1); 223 vec[Nfields] = InitVector(); 224 strcpy (vec[Nfields]->name, "index"); 225 ResetVector (vec[Nfields], OPIHI_INT, NPTS); 226 Vector *idxVec = vec[Nfields]; 227 228 // only write out the rows which were found 229 Npts = 0; 230 for (i = 0; i < NPTS; i++) { 231 if (!found[i]) continue; 232 idxVec->elements.Int[Npts] = i; 233 Npts ++; 234 } 235 int Nfound = Npts; 236 idxVec->Nelements = Nfound; 237 238 fprintf (stderr, "found %d of %d pts\n", Nfound, NPTS); 239 240 for (i = 0; i < Nfields; i++) { 241 if (vec[i][0].type == OPIHI_FLT) { 242 opihi_flt *tmp = NULL; 243 ALLOCATE (tmp, opihi_flt, Nfound); 244 Npts = 0; 245 for (j = 0; j < NPTS; j++) { 246 if (!found[j]) continue; 247 tmp[Npts] = vec[i][0].elements.Flt[j]; 248 Npts++; 249 } 250 free (vec[i][0].elements.Flt); 251 vec[i][0].elements.Flt = tmp; 252 } else { 253 opihi_int *tmp = NULL; 254 ALLOCATE (tmp, opihi_int, Nfound); 255 Npts = 0; 256 for (j = 0; j < NPTS; j++) { 257 if (!found[j]) continue; 258 tmp[Npts] = vec[i][0].elements.Int[j]; 259 Npts++; 260 } 261 free (vec[i][0].elements.Int); 262 vec[i][0].elements.Int = tmp; 263 } 264 vec[i][0].Nelements = Nfound; 265 } 266 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL); 267 free (vec[Nfields]->elements.Int); 268 free (vec[Nfields]); 269 if (!status) goto escape; 270 } 271 149 272 if (vec) free (vec); 150 273 if (values) free (values); 274 if (invec) FreeVectorArray (invec, Ninvec); 151 275 dbFreeFields (fields, Nfields); 152 276 SkyListFree (skylist); … … 156 280 if (vec) free (vec); 157 281 if (values) free (values); 282 if (invec) FreeVectorArray (invec, Ninvec); 158 283 dbFreeFields (fields, Nfields); 159 284 SkyListFree (skylist); … … 162 287 help: 163 288 gprint (GP_ERR, "USAGE: avmatch (RA) (DEC) (RADIUS) field[,field,field...]\n"); 289 gprint (GP_ERR, " OR: avmatch -coords (filename.fits) (RADIUS) field[,field,field...]\n"); 164 290 165 291 if ((argc > N + 1) && !strcasecmp (argv[N+1], "fields")) {
Note:
See TracChangeset
for help on using the changeset viewer.
