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