Changeset 3416 for trunk/Ohana/src/addstar/src/gstars.c
- Timestamp:
- Mar 14, 2005, 12:46:02 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/addstar/src/gstars.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/src/gstars.c
r3402 r3416 1 1 # include "addstar.h" 2 # define D_NSTARS 10003 # define BYTES_STAR 664 # define BLOCK 10005 2 6 3 Stars *gstars (char *file, int *NSTARS, Image *image) { … … 8 5 FILE *f; 9 6 Header header; 10 int j, N, Ninstar ;7 int j, N, Ninstar, extend; 11 8 int nbytes, Nbytes; 12 Stars *stars ;9 Stars *stars, *rdstars; 13 10 char *buffer, *c, *c2, photcode[64]; 14 11 double tmp; … … 22 19 exit (1); 23 20 } 24 25 /* open file */26 f = fopen (file, "r");27 if (f == NULL) {28 fprintf (stderr, "ERROR: can't read data from %s\n", file);29 exit (1);30 }31 fseek (f, header.size, SEEK_SET);32 21 33 22 /* find image rootname */ … … 147 136 exit (1); 148 137 } 149 ALLOCATE (stars, Stars, image[0].nstar);150 138 151 139 /* this is really lame. get sky background from Flips data */ … … 170 158 } 171 159 172 /* load in stars by blocks of 1000 */ 173 N = 0; 174 ALLOCATE (buffer, char, (BLOCK*BYTES_STAR) + 1); 175 buffer[BLOCK*BYTES_STAR] = 0; 176 Nextra = 0; 177 doneread = FALSE; 178 while (!doneread) { 179 Nbytes = BYTES_STAR * BLOCK - Nextra; 180 nbytes = Fread (&buffer[Nextra], 1, Nbytes, f, "char"); 181 if (nbytes == 0) { 182 doneread = TRUE; 183 continue; 160 /* read in data section */ 161 f = fopen (file, "r"); 162 if (f == NULL) { 163 fprintf (stderr, "ERROR: can't read data from %s\n", file); 164 exit (1); 165 } 166 fseek (f, header.size, SEEK_SET); 167 168 extend = FALSE; 169 fits_scan (&header, "EXTEND", "%t", 1, &extend); 170 if (extend) { 171 Nbytes = fits_matrix_size (&header); 172 fseek (f, Nbytes, SEEK_CUR); 173 rdstars = rfits (f, &image[0].nstar); 174 } else { 175 rdstars = rtext (f, &image[0].nstar); 176 } 177 fclose (f); 178 179 /* modify resulting star list */ 180 ALLOCATE (stars, Stars, image[0].nstar); 181 for (N = j = 0; j < image[0].nstar; j++) { 182 /* allow for some dynamic filtering of star list */ 183 if (rdstars[j].dM > 1000.0 / SNLIMIT) continue; 184 if (XMAX && (rdstars[j].X > XMAX)) continue; 185 if (XMIN && (rdstars[j].X < XMIN)) continue; 186 if (YMAX && (rdstars[j].Y > YMAX)) continue; 187 if (YMIN && (rdstars[j].Y < YMIN)) continue; 188 stars[N] = rdstars[j]; 189 190 XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords); 191 while (stars[N].R < 0.0) stars[N].R += 360.0; 192 while (stars[N].R >= 360.0) stars[N].R -= 360.0; 193 stars[N].found = -1; 194 stars[N].code = thiscode[0].code; 195 196 if (SKYPROBE) { 197 dMs = get_subpix (stars[N].X, stars[N].Y); 198 stars[N].M -= dMs; 199 stars[N].Mgal -= dMs; 200 stars[N].Map -= dMs; 201 dMs = 1000.0*scat_subpix (stars[N].X, stars[N].Y); 202 stars[N].dM = hypot (stars[N].dM, dMs); 184 203 } 185 nbytes += Nextra; 186 /* check line-by-line integrity */ 187 c = buffer; 188 done = FALSE; 189 while ((c < buffer + nbytes) && (!done)) { 190 for (c2 = c; *c2 == '\n'; c2++); 191 if (c2 > c) { /* extra return chars */ 192 memmove (c, c2, (int)(buffer + nbytes - c2)); 193 Nskip = c2 - c; 194 nbytes -= Nskip; 195 bzero (buffer + nbytes, Nskip); 196 if (VERBOSE) fprintf (stderr, "deleted %d extra return chars\n", Nskip); 197 } 198 c2 = strchr (c, '\n'); 199 if (c2 == (char *) NULL) { 200 done = TRUE; 201 continue; 202 } 203 c2++; 204 if ((c2 - c) != BYTES_STAR) { /* bad line, delete it */ 205 memmove (c, c2, (int)(buffer + nbytes - c2)); 206 Nskip = c2 - c; 207 nbytes -= Nskip; 208 bzero (buffer + nbytes, Nskip); 209 if (VERBOSE) fprintf (stderr, "deleted line, %d extra chars\n", Nskip); 210 } else { 211 c = c2; 212 } 213 } 214 Ninstar = nbytes / BYTES_STAR; 215 Nextra = nbytes % BYTES_STAR; 216 for (j = 0; j < Ninstar; j++, N++) { 217 dparse (&stars[N].X, 1, &buffer[j*BYTES_STAR]); 218 dparse (&stars[N].Y, 2, &buffer[j*BYTES_STAR]); 219 dparse (&stars[N].M, 3, &buffer[j*BYTES_STAR]); 220 221 /* cmp files carry dM in millimags */ 222 dparse (&tmp, 4, &buffer[j*BYTES_STAR]); 223 stars[N].dM = 0.001*tmp; 224 225 /* allow for some dynamic filtering of star list */ 226 if (stars[N].dM > 1000.0 / SNLIMIT) { N--; continue; } 227 if (XMAX && (stars[N].X > XMAX)) { N--; continue; } 228 if (XMIN && (stars[N].X < XMIN)) { N--; continue; } 229 if (YMAX && (stars[N].Y > YMAX)) { N--; continue; } 230 if (YMIN && (stars[N].Y < YMIN)) { N--; continue; } 231 232 dparse (&tmp, 5, &buffer[j*BYTES_STAR]); 233 stars[N].dophot = tmp; 234 235 dparse (&stars[N].Mgal, 7, &buffer[j*BYTES_STAR]); 236 dparse (&stars[N].Map, 8, &buffer[j*BYTES_STAR]); 237 dparse (&stars[N].fx, 9, &buffer[j*BYTES_STAR]); 238 dparse (&stars[N].fy, 10, &buffer[j*BYTES_STAR]); 239 dparse (&stars[N].df, 11, &buffer[j*BYTES_STAR]); 240 241 XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords); 242 while (stars[N].R < 0.0) stars[N].R += 360.0; 243 while (stars[N].R >= 360.0) stars[N].R -= 360.0; 244 stars[N].found = -1; 245 stars[N].code = thiscode[0].code; 246 247 if (SKYPROBE) { 248 dMs = get_subpix (stars[N].X, stars[N].Y); 249 stars[N].M -= dMs; 250 stars[N].Mgal -= dMs; 251 stars[N].Map -= dMs; 252 dMs = 1000.0*scat_subpix (stars[N].X, stars[N].Y); 253 stars[N].dM = hypot (stars[N].dM, dMs); 254 } 255 } 256 } 257 204 N ++; 205 } 258 206 image[0].nstar = N; 259 207 REALLOCATE (stars, Stars, image[0].nstar); 208 free (rdstars); 209 260 210 if (VERBOSE) fprintf (stderr, "read %d stars from target file\n", image[0].nstar); 261 211 *NSTARS = image[0].nstar;
Note:
See TracChangeset
for help on using the changeset viewer.
