Changeset 4680 for trunk/Ohana/src/delstar/src/find_matches.c
- Timestamp:
- Jul 30, 2005, 9:14:00 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/delstar/src/find_matches.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/delstar/src/find_matches.c
r2463 r4680 1 1 # include "delstar.h" 2 2 3 find_matches (Catalog *catalog, Image *image, int start, int end) {4 5 int i, j, k, n, m, N, M, found;6 int * N1, *N2, *next, *next_miss, *ave_miss, last, last_miss;7 int Nave, N AVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch, photcode;3 void find_matches (Catalog *catalog, int photcode, int start, int end) { 4 5 int i, j, k, n, m, N, M, drop; 6 int *next, *next_miss, *ave_miss, last, last_miss; 7 int Nave, Nmeas, Nmiss; 8 8 int Nmeasfound, Nsecfilt; 9 9 int this, prev; 10 unsigned int flags;11 10 Measure *tmpmeasure; 12 11 Missing *tmpmissing; 13 Coords tcoords;14 12 15 13 /** allocate local arrays **/ … … 43 41 } 44 42 } 45 photcode = -1; 46 if ((start == 0) && (end == 0)) { 47 start = image[0].tzero; 48 end = image[0].tzero + 1e-4*image[0].NY*image[0].trate; /* trate is in 0.1 msec / row */ 49 photcode = image[0].source; 50 } 51 if (VERBOSE) fprintf (stderr, "deleting for range %d to %d (photcode %d)\n", start, end, photcode); 43 44 if (VERBOSE) fprintf (stderr, "deleting for range %d to %d, photcode %d\n", start, end, photcode); 52 45 Nmeasfound = 0; 53 46 Nsecfilt = catalog[0].Nsecfilt; 54 47 55 /* fprintf (stderr, "fixing the measures...\n"); */ 56 /** find measure in time range of image **/ 48 if (VERBOSE) fprintf (stderr, "fixing measure...\n"); 49 50 /** find measure in time range **/ 57 51 this = prev = -1; 58 52 for (i = 0; (i < Nmeas); i++) { 59 if ((i % 10000) == 0) fprintf (stderr, ". "); 60 if ((catalog[0].measure[i].t >= start) && (catalog[0].measure[i].t <= end) && (photcode == catalog[0].measure[i].source)) { 61 Nmeasfound ++; 62 /* this star is in this image */ 63 this = next[i]; 64 next[i] = -2; /* we delete this one */ 65 if (prev != -1) { next[prev] = this; } 53 if (VERBOSE && !(i % 10000)) fprintf (stderr, ". "); 54 drop = TRUE; 55 drop &= (catalog[0].measure[i].t >= start); 56 drop &= (catalog[0].measure[i].t <= end); 57 drop &= ((photcode == -1) || (photcode == catalog[0].measure[i].source)); 58 if (!drop) { 59 prev = i; 60 continue; 61 } 62 Nmeasfound ++; 63 64 /* this star is in this image */ 65 this = next[i]; 66 next[i] = -2; /* we delete this one */ 67 if (prev != -1) { next[prev] = this; } 68 66 69 # if (0) 67 /* why is this section disabled? */ 70 /* why is this section disabled? */ 71 /* fix the list links: connect the previous valid link to the next valid link */ 72 for (j = i; (j >= 0) && (next[j] == -2); j--); /* find previous entry to fix link */ 73 if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */ 74 if (next[j] != i) { 75 fprintf (stderr, "error? (1) this link seems to have been lost\n"); 76 fprintf (stderr, "j: %d, next[j]: %d, i: %d\n", j, next[j], i); 77 exit (1); 78 } 79 /* find next valid entry to fix link */ 80 for (k = i; (k < Nmeas) && (next[k] == -2); k++); 81 if (k < Nmeas) 82 next[j] = k; 83 else 84 next[j] = -1; /* last link in list gets a -1 */ 85 } 86 # endif 87 88 /*** fix the corresponding average entry ***/ 89 n = catalog[0].measure[i].averef; 90 if (catalog[0].average[n].Nm == 0) { /* this should never happen */ 91 fprintf (stderr, "error? we deleted one too many objects?\n"); 92 exit (1); 93 } 94 catalog[0].average[n].Nm --; 95 /* this was only entry in list: will be deleted below. meanwhile, delete all missing entries*/ 96 if ((catalog[0].average[n].Nm < 1) && (catalog[0].average[n].Nn > 0)) { 97 m = catalog[0].average[n].missing; 98 for (j = 0; j < catalog[0].average[n].Nn; j++) { 99 M = next_miss[m]; 100 next_miss[m] = -2; 101 m = M; 102 } 103 m = catalog[0].average[n].missing; 68 104 /* fix the list links: connect the previous valid link to the next valid link */ 69 for (j = i; (j >= 0) && (next[j] == -2); j--); /* find previous entry to fix link */105 for (j = m; (j >= 0) && (next_miss[j] == -2); j--); /* find previous entry to fix link */ 70 106 if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */ 71 if (next[j] != i) { 72 fprintf (stderr, "error? (1) this link seems to have been lost\n"); 73 fprintf (stderr, "j: %d, next[j]: %d, i: %d\n", j, next[j], i); 74 exit (1); 75 } 76 /* find next valid entry to fix link */ 77 for (k = i; (k < Nmeas) && (next[k] == -2); k++); 78 if (k < Nmeas) 79 next[j] = k; 80 else 81 next[j] = -1; /* last link in list gets a -1 */ 82 } 83 # endif 84 /*** fix the corresponding average entry ***/ 85 n = catalog[0].measure[i].averef; 86 if (catalog[0].average[n].Nm == 0) { /* this should never happen */ 87 fprintf (stderr, "error? we deleted one too many objects?\n"); 88 exit (1); 89 } 90 catalog[0].average[n].Nm --; 91 /* this was only entry in list: will be deleted below. meanwhile, delete all missing entries*/ 92 if ((catalog[0].average[n].Nm < 1) && (catalog[0].average[n].Nn > 0)) { 93 m = catalog[0].average[n].missing; 94 for (j = 0; j < catalog[0].average[n].Nn; j++) { 95 M = next_miss[m]; 96 next_miss[m] = -2; 97 m = M; 98 } 99 m = catalog[0].average[n].missing; 100 /* fix the list links: connect the previous valid link to the next valid link */ 101 for (j = m; (j >= 0) && (next_miss[j] == -2); j--); /* find previous entry to fix link */ 102 if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */ 103 if (next_miss[j] != m) { 104 fprintf (stderr, "error? (2) this link seems to have been lost\n"); 105 fprintf (stderr, "j: %d, next_miss[j]: %d, i: %d\n", j, next_miss[j], i); 106 exit (1); 107 } 108 /* find next valid entry to fix link */ 109 for (k = m; (k < Nmiss) && (next_miss[k] == -2); k++); 110 if (k < Nmiss) 111 next_miss[j] = k; 112 else 113 next_miss[j] = -1; /* last link in list gets a -1 */ 114 } 115 } 116 /* this was first entry in list */ 117 if ((catalog[0].average[n].offset == i) && (catalog[0].average[n].Nm > 0)) { 118 m = catalog[0].average[n].offset; 119 /* find next valid entry -- notice lack of error checking... */ 120 for (j = 0; (j < Nmeas) && (next[m+j] == -2); j++); 121 catalog[0].average[n].offset = m + j; 122 } 123 } else { 124 prev = i; 125 } 126 } 127 fprintf (stderr, "found %d meas to remove\n", Nmeasfound); 128 129 /* fprintf (stderr, "fixing the missing...\n"); */ 130 /** find missing in time range of image **/ 131 for (i = 0; (i < Nmiss); i++) { 132 if ((next_miss[i] != -2) && (catalog[0].missing[i].t >= start) && (catalog[0].missing[i].t <= end)) { 133 /* this star is in this image */ 134 135 next_miss[i] = -2; /* we delete this one */ 136 /* fix the list links: connect the previous valid link to the next valid link */ 137 for (j = i; (j >= 0) && (next_miss[j] == -2); j--); /* find previous entry to fix link */ 138 if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */ 139 if (next_miss[j] != i) { 140 fprintf (stderr, "error? (3) this link seems to have been lost\n"); 107 if (next_miss[j] != m) { 108 fprintf (stderr, "error? (2) this link seems to have been lost\n"); 141 109 fprintf (stderr, "j: %d, next_miss[j]: %d, i: %d\n", j, next_miss[j], i); 142 110 exit (1); 143 111 } 144 112 /* find next valid entry to fix link */ 145 for (k = i; (k < Nmiss) && (next_miss[k] == -2); k++);113 for (k = m; (k < Nmiss) && (next_miss[k] == -2); k++); 146 114 if (k < Nmiss) 147 115 next_miss[j] = k; … … 149 117 next_miss[j] = -1; /* last link in list gets a -1 */ 150 118 } 119 } 120 /* this was first entry in list */ 121 if ((catalog[0].average[n].offset == i) && (catalog[0].average[n].Nm > 0)) { 122 m = catalog[0].average[n].offset; 123 /* find next valid entry -- notice lack of error checking... */ 124 for (j = 0; (j < Nmeas) && (next[m+j] == -2); j++); 125 catalog[0].average[n].offset = m + j; 126 } 127 } 128 fprintf (stderr, "found %d meas to remove\n", Nmeasfound); 129 130 if (VERBOSE) fprintf (stderr, "fixing missing..."); 131 /** find missing in time range of image **/ 132 for (i = 0; (i < Nmiss); i++) { 133 if (next_miss[i] == -2) continue; 134 if (catalog[0].missing[i].t < start) continue; 135 if (catalog[0].missing[i].t > end) continue; 136 137 next_miss[i] = -2; /* we delete this one */ 138 /* fix the list links: connect the previous valid link to the next valid link */ 139 for (j = i; (j >= 0) && (next_miss[j] == -2); j--); /* find previous entry to fix link */ 140 if (j >= 0) { /* if j < 0, there is no previous valid link, ignore this step */ 141 if (next_miss[j] != i) { 142 fprintf (stderr, "error? (3) this link seems to have been lost\n"); 143 fprintf (stderr, "j: %d, next_miss[j]: %d, i: %d\n", j, next_miss[j], i); 144 exit (1); 145 } 146 /* find next valid entry to fix link */ 147 for (k = i; (k < Nmiss) && (next_miss[k] == -2); k++); 148 if (k < Nmiss) 149 next_miss[j] = k; 150 else 151 next_miss[j] = -1; /* last link in list gets a -1 */ 152 } 151 153 152 /* find the corresponding avearge entry 153 found = FALSE; 154 for (n = 0; !found && (n < Nave); n++) { 155 if ((catalog[0].average[n].missing > 0) && (catalog[0].average[n].missing <= i) && (catalog[0].average[n].missing + catalog[0].average[n].Nn > i)) 156 found = TRUE; 157 } 158 n--; */ 159 /*** fix the corresponding average entry ***/ 160 n = ave_miss[i]; 161 if (catalog[0].average[n].Nn == 0) { /* this should never happen */ 162 fprintf (stderr, "error? we deleted one too many missing?\n"); 163 exit (1); 164 } 165 catalog[0].average[n].Nn --; 166 /* this was first entry in list */ 167 if ((catalog[0].average[n].missing == i) && (catalog[0].average[n].Nn > 0)) { 168 m = catalog[0].average[n].missing; 169 for (j = 0; (j < Nmiss) && (next_miss[m+j] == -2); j++); 170 catalog[0].average[n].missing = m + j; 171 } 172 173 } 174 } 175 176 /* currently not worked out, but we will need to delete the references to blended image and cat stars */ 177 # if 0 178 /*** handle multiple stars */ 179 /* this image star matches more than one catalog star */ 180 if (stars[N].found > -1) { 181 catalog[0].measure[stars[N].found].flags |= BLEND_IMAGE; 182 catalog[0].measure[Nmeas].flags |= BLEND_IMAGE; 183 } 184 if (stars[N].found == -2) { /* this image star matches a catalog star on a neighboring catalog */ 185 catalog[0].measure[Nmeas].flags |= BLEND_IMAGE_NEIGHBOR; 186 } 187 if (stars[N].found == -1) { /* this image star matches only this star */ 188 stars[N].found = Nmeas; /* save first match, in case coincidences are found */ 189 } 190 /* this catalog star matches more than one image star */ 191 if (catalog[0].found[n] > -1) { 192 catalog[0].measure[catalog[0].found[n]].flags |= BLEND_CATALOG; 193 catalog[0].measure[Nmeas].flags |= BLEND_CATALOG; 194 } else { 195 catalog[0].found[n] = Nmeas; 196 } 197 # endif 154 /*** fix the corresponding average entry ***/ 155 n = ave_miss[i]; 156 if (catalog[0].average[n].Nn == 0) { /* this should never happen */ 157 fprintf (stderr, "error? we deleted one too many missing?\n"); 158 exit (1); 159 } 160 catalog[0].average[n].Nn --; 161 /* this was first entry in list */ 162 if ((catalog[0].average[n].missing == i) && (catalog[0].average[n].Nn > 0)) { 163 m = catalog[0].average[n].missing; 164 for (j = 0; (j < Nmiss) && (next_miss[m+j] == -2); j++); 165 catalog[0].average[n].missing = m + j; 166 } 167 } 168 169 /* we should delete the references to blended image and cat stars ?? */ 170 /* or drop since we are changing this concept ?? */ 198 171 199 172 /* fix Average list: delete entries with Nm == 0 */ … … 266 239 free (next_miss); 267 240 free (ave_miss); 268 241 return; 269 242 } 270 243
Note:
See TracChangeset
for help on using the changeset viewer.
