- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/Ohana
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/Ohana merged eligible /branches/eam_branches/Ohana.20100407 27635-27772 /branches/pap_delete/Ohana 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/Ohana/src/addstar/src/find_matches_refstars.c
r21508 r27838 1 1 # include "addstar.h" 2 2 3 int find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {4 5 int i, j, k, n, m, N, J;3 int find_matches_refstars (SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options) { 4 5 off_t i, j, n, N, J; 6 6 double RADIUS, RADIUS2; 7 7 double *X1, *Y1, *X2, *Y2; 8 8 double dX, dY, dR; 9 int *N1, *N2, *next, *next_miss, last, last_miss;10 int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;9 off_t *N1, *N2, *next_meas; 10 off_t Nave, NAVE, Nmeas, NMEAS, Nmatch; 11 11 unsigned int objID, catID; 12 Measure *tmpmeasure;13 Missing *tmpmissing;14 12 Coords tcoords; 15 13 int Nsecfilt; … … 26 24 ALLOCATE (X1, double, Nstars); 27 25 ALLOCATE (Y1, double, Nstars); 28 ALLOCATE (N1, int,Nstars);26 ALLOCATE (N1, off_t, Nstars); 29 27 30 28 /** allocate local arrays (catalog) **/ … … 33 31 ALLOCATE (X2, double, NAVE); 34 32 ALLOCATE (Y2, double, NAVE); 35 ALLOCATE (N2, int,NAVE);36 ALLOCATE (catalog[0].found, int, NAVE);33 ALLOCATE (N2, off_t, NAVE); 34 ALLOCATE (catalog[0].found, off_t, NAVE); 37 35 REALLOCATE (catalog[0].average, Average, NAVE); 38 36 REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt); … … 40 38 41 39 Nmatch = 0; 42 Nmeas = catalog[0].Nmeasure; 43 NMEAS = Nmeas + 1000; 44 ALLOCATE (next, int, NMEAS); 45 REALLOCATE (catalog[0].measure, Measure, NMEAS); 46 47 Nmiss = catalog[0].Nmissing; 48 NMISS = Nmiss + 1000; 49 if ((NMISS < 1) || (NMISS > 1e10)) { 50 fprintf (stderr, "weird value for NMISS: %d\n", NMISS); 51 } 52 ALLOCATE (next_miss, int, NMISS); 53 REALLOCATE (catalog[0].missing, Missing, NMISS); 40 NMEAS = Nmeas = catalog[0].Nmeasure; 54 41 55 42 // current max obj ID for this catalog … … 82 69 83 70 /* set up pointers for linked list of measurements */ 84 for (i = 0; i < Nmeas - 1; i++) { 85 next[i] = i+1; 86 } 87 next[i] = -1; 88 last = i; 89 90 for (i = 0; i < Nmiss - 1; i++) { 91 next_miss[i] = i+1; 92 } 93 next_miss[i] = -1; 94 last_miss = i; 71 if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) { 72 // this version is only valid if we have done a full catalog load, and if the catalog 73 // is sorted while processed 74 next_meas = init_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas); 75 } else { 76 next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas); 77 } 95 78 96 79 /* choose a radius for matches */ … … 105 88 // XXX could use NREFSTAR_GROUP to do this match more quicky 106 89 for (i = j = 0; (i < Nstars) && (j < Nave); ) { 90 if (!finite(X1[i]) || !finite(Y1[i])) { 91 i++; 92 continue; 93 } 94 if (!finite(X2[j]) || !finite(Y2[j])) { 95 j++; 96 continue; 97 } 107 98 108 99 dX = X1[i] - X2[j]; 109 if (dX <= - 2*RADIUS) {100 if (dX <= -1.02*RADIUS) { 110 101 i++; 111 102 continue; 112 103 } 113 if (dX >= 2*RADIUS) {104 if (dX >= 1.02*RADIUS) { 114 105 j++; 115 106 continue; … … 117 108 118 109 /* negative dX: j is too large, positive dX, i is too large */ 119 for (J = j; (dX > - 2*RADIUS) && (J < Nave); J++) {110 for (J = j; (dX > -1.02*RADIUS) && (J < Nave); J++) { 120 111 dX = X1[i] - X2[J]; 121 112 dY = Y1[i] - Y2[J]; … … 123 114 if (dR > RADIUS2) continue; 124 115 116 /*** a match is found, add to average, measure ***/ 125 117 Nmatch ++; 126 118 n = N2[J]; 127 119 N = N1[i]; 128 m = catalog[0].average[n].measureOffset;129 120 130 121 /** in replace mode, search for entry and replace values M, dM, R, D */ 131 if (options.replace && replace_match (&catalog[0].average[n], &catalog[0].measure[m], stars[N])) continue; 132 133 /** insert star in measurement list */ 134 /* find last measurement of this star */ 135 for (k = 0; k < catalog[0].average[n].Nmeasure - 1; k++) m = next[m]; 136 137 /* set up references */ 138 next[Nmeas] = next[m]; 139 next[m] = Nmeas; 140 141 /* last just was moved */ 142 if (next[Nmeas] == -1) last = Nmeas; 122 if (options.replace && replace_match (&catalog[0].average[n], catalog[0].measure, stars[N])) continue; 123 124 if (Nmeas == NMEAS) { 125 NMEAS = Nmeas + 1000; 126 REALLOCATE (next_meas, off_t, NMEAS); 127 REALLOCATE (catalog[0].measure, Measure, NMEAS); 128 } 129 130 /* add to end of measurement list */ 131 add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS); 143 132 144 133 /** add measurements for this star **/ … … 150 139 catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R); 151 140 catalog[0].measure[Nmeas].dD = 3600.0*(catalog[0].average[n].D - stars[N][0].average.D); 141 catalog[0].measure[Nmeas].dbFlags = 0; 142 catalog[0].measure[Nmeas].averef = n; 143 catalog[0].measure[Nmeas].objID = catalog[0].average[n].objID; 144 catalog[0].measure[Nmeas].catID = catalog[0].catID; 152 145 153 146 // rationalize dR: … … 162 155 catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R); 163 156 } 164 165 catalog[0].measure[Nmeas].averef = n;166 catalog[0].measure[Nmeas].dbFlags = 0;167 catalog[0].measure[Nmeas].objID = catalog[0].average[n].objID;168 catalog[0].measure[Nmeas].catID = catalog[0].catID;169 157 170 158 catalog[0].measure[Nmeas].t = (TIMEREF == 0) ? stars[N][0].measure.t : TIMEREF; /** careful : time_t vs e_time **/ … … 204 192 catalog[0].average[n].Nmeasure ++; 205 193 Nmeas ++; 206 if (Nmeas == NMEAS) { 207 NMEAS = Nmeas + 1000; 208 REALLOCATE (next, int, NMEAS); 209 REALLOCATE (catalog[0].measure, Measure, NMEAS); 210 } 211 212 update_coords (&catalog[0].average[n], &catalog[0].measure[0], next); 194 195 // update_coords (&catalog[0].average[n], &catalog[0].measure[0], next_meas); 213 196 } 214 197 i++; … … 224 207 225 208 for (i = 0; (i < Nstars) && !options.only_match; i+=NREFSTAR_GROUP) { 209 if (Nmeas >= NMEAS - NREFSTAR_GROUP) { 210 NMEAS = Nmeas + 1000; 211 REALLOCATE (next_meas, off_t, NMEAS); 212 REALLOCATE (catalog[0].measure, Measure, NMEAS); 213 } 214 if (Nave == NAVE) { 215 NAVE = Nave + 1000; 216 REALLOCATE (catalog[0].average, Average, NAVE); 217 REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt); 218 } 219 226 220 N = N1[i]; 227 221 if (stars[N][0].found > -1) continue; 222 if (!IN_REGION (stars[N][0].average.R, stars[N][0].average.D)) continue; 228 223 229 224 catalog[0].average[Nave].R = stars[N][0].average.R; … … 260 255 261 256 catalog[0].average[Nave].Xp = 0; 262 catalog[0].average[Nave].ChiSq = 0.0; 257 catalog[0].average[Nave].ChiSqAve = 0.0; 258 catalog[0].average[Nave].ChiSqPM = 0.0; 259 catalog[0].average[Nave].ChiSqPar = 0.0; 260 catalog[0].average[Nave].Tmean = 0; 261 catalog[0].average[Nave].Trange = 0; 263 262 catalog[0].average[Nave].Npos = 0; 264 263 … … 266 265 catalog[0].average[Nave].catID = catID; 267 266 catalog[0].average[Nave].flags = 0; 267 if (PSPS_ID) { 268 catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R, 269 catalog[0].average[Nave].D); 270 } else { 271 catalog[0].average[Nave].extID = 0; 272 } 273 268 274 269 275 objID ++; … … 295 301 296 302 stars[N][0].found = Nmeas; 297 next[last] = Nmeas; 298 next[Nmeas] = -1; 299 last = Nmeas; 300 Nmeas ++; 301 if (Nmeas == NMEAS) { 302 NMEAS = Nmeas + 1000; 303 REALLOCATE (next, int, NMEAS); 304 REALLOCATE (catalog[0].measure, Measure, NMEAS); 305 } 306 } 307 303 next_meas[Nmeas] = -1; // initial value here, update below 304 Nmeas ++; 305 } 306 307 for (j = 0; j < NREFSTAR_GROUP - 1; j++) { 308 next_meas[Nmeas - NREFSTAR_GROUP + j] = Nmeas - NREFSTAR_GROUP + j + 1; 309 } 308 310 Nave ++; 309 if (Nave == NAVE) {310 NAVE = Nave + 1000;311 REALLOCATE (catalog[0].average, Average, NAVE);312 REALLOCATE (catalog[0].secfilt, SecFilt, NAVE*catalog[0].Nsecfilt);313 }314 311 } 315 312 316 free (catalog[0].found);317 313 REALLOCATE (catalog[0].average, Average, Nave); 318 314 319 /* fix order of Measure (memory intensive, but fast) */ 320 N = 0; 321 ALLOCATE (tmpmeasure, Measure, Nmeas); 322 for (i = 0; i < Nave; i++) { 323 n = catalog[0].average[i].measureOffset; 324 catalog[0].average[i].measureOffset = N; 325 for (k = 0; k < catalog[0].average[i].Nmeasure; k++, N++) { 326 tmpmeasure[N] = catalog[0].measure[n]; 327 tmpmeasure[N].averef = i; 328 n = next[n]; 329 } 330 } 331 free (catalog[0].measure); 332 catalog[0].measure = tmpmeasure; 333 334 /* fix order of Missing (memory intensive, but fast) */ 335 N = 0; 336 ALLOCATE (tmpmissing, Missing, Nmiss); 337 for (i = 0; i < Nave; i++) { 338 if (catalog[0].average[i].Nmissing > 0) { 339 n = catalog[0].average[i].missingOffset; 340 catalog[0].average[i].missingOffset = N; 341 for (k = 0; k < catalog[0].average[i].Nmissing; k++, N++) { 342 tmpmissing[N] = catalog[0].missing[n]; 343 n = next_miss[n]; 344 } 345 } 346 } 347 free (catalog[0].missing); 348 catalog[0].missing = tmpmissing; 315 // XXX allow for unsorted output? 316 catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas); 349 317 350 318 /* note stars which have been found in this catalog */ … … 357 325 } 358 326 327 catalog[0].objID = objID; // new max value, save on catalog close 328 catalog[0].Naverage = Nave; 329 catalog[0].Nmeasure = Nmeas; 330 catalog[0].Nsecf_mem = Nave*Nsecfilt; 331 if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %lld %lld %lld, (%lld matches)\n", (long long) Nstars, (long long) Nave, (long long) Nmeas, (long long) Nmatch); 332 333 free (catalog[0].found); 359 334 free (X1); 360 335 free (Y1); … … 363 338 free (Y2); 364 339 free (N2); 365 free (next); 366 free (next_miss); 367 368 catalog[0].objID = objID; // new max value, save on catalog close 369 catalog[0].Naverage = Nave; 370 catalog[0].Nmeasure = Nmeas; 371 catalog[0].Nmissing = Nmiss; 372 catalog[0].Nsecf_mem = Nave*Nsecfilt; 373 if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmiss, Nmatch); 340 free (next_meas); 341 374 342 return (Nmatch); 375 343 }
Note:
See TracChangeset
for help on using the changeset viewer.
