Changeset 33135
- Timestamp:
- Jan 23, 2012, 12:09:26 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/addstar/src/mkcmf.c
r27582 r33135 19 19 void writeStars_PS1_DEV_0 (FTable *ftable, double *X, double *Y, double *M, int Nstars); 20 20 21 int ADDNOISE = TRUE; 22 21 23 int main (int argc, char **argv) { 22 24 … … 34 36 Coords coords; 35 37 38 static char *photcode = "SIMTEST.r.Chip"; 39 if ((N = get_argument (argc, argv, "-photcode"))) { 40 remove_argument (N, &argc, argv); 41 photcode = strcreate (argv[N]); 42 remove_argument (N, &argc, argv); 43 } 44 45 static double mjd = NAN; 46 if ((N = get_argument (argc, argv, "-mjd"))) { 47 remove_argument (N, &argc, argv); 48 mjd = strtod (argv[N], NULL); 49 remove_argument (N, &argc, argv); 50 } 51 36 52 static char *date = "2001-01-01"; 37 53 if ((N = get_argument (argc, argv, "-date"))) { … … 66 82 } 67 83 84 // add support for all cmf types 85 int FROM_COORDS = FALSE; 86 if ((N = get_argument (argc, argv, "-coords"))) { 87 remove_argument (N, &argc, argv); 88 FROM_COORDS = TRUE; 89 } 90 91 // add support for all cmf types 92 ADDNOISE = TRUE; 93 if ((N = get_argument (argc, argv, "-no-noise"))) { 94 remove_argument (N, &argc, argv); 95 ADDNOISE = FALSE; 96 } 97 68 98 if (argc != 3) { 69 99 fprintf (stderr, "USAGE mkcmf (input) (output) [-date date] [-time time] [-radec ra dec] [-cmftype type]\n"); 70 100 exit (2); 71 101 } 72 73 f = fopen (argv[1], "r");74 if (f == NULL) {75 fprintf (stderr, "unable to open input file %s\n", argv[1]);76 exit (1);77 }78 79 // load test stars from a file:80 Nstars = 0;81 NSTARS = 100;82 ALLOCATE (X, double, NSTARS);83 ALLOCATE (Y, double, NSTARS);84 ALLOCATE (M, double, NSTARS);85 86 Xmax = Ymax = 0;87 while (fscanf (f, "%lf %lf %lf", &X[Nstars], &Y[Nstars], &M[Nstars]) != EOF) {88 Xmax = MAX(Xmax, X[Nstars]);89 Ymax = MAX(Ymax, Y[Nstars]);90 91 if (Nstars == NSTARS - 1) {92 NSTARS += 100;93 REALLOCATE (X, double, NSTARS);94 REALLOCATE (Y, double, NSTARS);95 REALLOCATE (M, double, NSTARS);96 }97 Nstars ++;98 }99 100 // create primary header101 gfits_init_header (&header);102 header.extend = TRUE;103 gfits_create_header (&header);104 gfits_create_matrix (&header, &matrix);105 gfits_print (&header, "NEXTEND", "%d", 1, 1);106 107 // XXX add minimum needed header fields108 gfits_print (&header, "IMNAXIS1", "%d", 1, (int)(Xmax + 50));109 gfits_print (&header, "IMNAXIS2", "%d", 1, (int)(Ymax + 50));110 111 gfits_modify (&header, "NSTARS", "%d", 1, Nstars);112 gfits_modify (&header, "PHOTCODE", "%s", 1, "SIMTEST.r.Chip");113 gfits_modify (&header, "DATE-OBS", "%s", 1, date);114 gfits_modify (&header, "UTC-OBS", "%s", 1, time);115 gfits_modify (&header, "ZERO_PT", "%lf", 1, 25.0);116 gfits_modify (&header, "EXPTIME", "%lf", 1, 1.0);117 gfits_modify (&header, "AIRMASS", "%lf", 1, 1.0);118 gfits_modify (&header, "NASTRO", "%d", 1, 10);119 120 gfits_modify (&header, "IMAGEID", "%d", 1, (int)(1000*drand48()));121 gfits_modify (&header, "SOURCEID", "%d", 1, (int)(100*drand48()));122 102 123 103 /* bore site center guess */ … … 137 117 coords.Npolyterms = 1; 138 118 119 // load stars and generate complete output fields 120 f = fopen (argv[1], "r"); 121 if (f == NULL) { 122 fprintf (stderr, "unable to open input file %s\n", argv[1]); 123 exit (1); 124 } 125 126 // load test stars from a file: 127 Nstars = 0; 128 NSTARS = 100; 129 ALLOCATE (X, double, NSTARS); 130 ALLOCATE (Y, double, NSTARS); 131 ALLOCATE (M, double, NSTARS); 132 133 Xmax = Ymax = 0; 134 while (1) { 135 int status; 136 if (FROM_COORDS) { 137 double ra, dec, mag, xraw, yraw, mraw; 138 status = fscanf (f, "%lf %lf %lf %lf %lf %lf", &ra, &dec, &mag, &xraw, &yraw, &mraw); 139 if (status != EOF) { 140 RD_to_XY (&X[Nstars], &Y[Nstars], ra, dec, &coords); 141 } 142 M[Nstars] = mraw; 143 } else { 144 status = fscanf (f, "%lf %lf %lf", &X[Nstars], &Y[Nstars], &M[Nstars]); 145 } 146 if (status == EOF) break; 147 148 Xmax = MAX(Xmax, X[Nstars]); 149 Ymax = MAX(Ymax, Y[Nstars]); 150 151 if (Nstars == NSTARS - 1) { 152 NSTARS += 100; 153 REALLOCATE (X, double, NSTARS); 154 REALLOCATE (Y, double, NSTARS); 155 REALLOCATE (M, double, NSTARS); 156 } 157 Nstars ++; 158 } 159 160 // create primary header 161 gfits_init_header (&header); 162 header.extend = TRUE; 163 gfits_create_header (&header); 164 gfits_create_matrix (&header, &matrix); 165 gfits_print (&header, "NEXTEND", "%d", 1, 1); 166 167 // XXX add minimum needed header fields 168 gfits_print (&header, "IMNAXIS1", "%d", 1, (int)(Xmax + 50)); 169 gfits_print (&header, "IMNAXIS2", "%d", 1, (int)(Ymax + 50)); 170 171 gfits_modify (&header, "NSTARS", "%d", 1, Nstars); 172 gfits_modify (&header, "PHOTCODE", "%s", 1, photcode); 173 if (isfinite(mjd)) { 174 gfits_modify (&header, "MJD-OBS", "%lf", 1, mjd); 175 } else { 176 gfits_modify (&header, "DATE-OBS", "%s", 1, date); 177 gfits_modify (&header, "UTC-OBS", "%s", 1, time); 178 } 179 gfits_modify (&header, "ZERO_PT", "%lf", 1, 25.0); 180 gfits_modify (&header, "EXPTIME", "%lf", 1, 1.0); 181 gfits_modify (&header, "AIRMASS", "%lf", 1, 1.0); 182 gfits_modify (&header, "NASTRO", "%d", 1, 10); 183 184 gfits_modify (&header, "IMAGEID", "%d", 1, (int)(1000*drand48())); 185 gfits_modify (&header, "SOURCEID", "%d", 1, (int)(100*drand48())); 186 139 187 PutCoords (&coords, &header); 140 188 gfits_modify (&header, "EXTNAME", "%s", 1, "Chip.hdr"); … … 273 321 fSN = 1.0 / sqrt(flux); 274 322 275 stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0); 276 stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0); 277 stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0); 323 stars[i].X = X[i]; 324 stars[i].Y = Y[i]; 325 stars[i].M = M[i]; 326 327 if (ADDNOISE) { 328 stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0); 329 stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0); 330 stars[i].M += fSN*rnd_gauss(0.0, 1.0); 331 } 278 332 279 333 stars[i].dX = FX * fSN; … … 312 366 fSN = 1.0 / sqrt(flux); 313 367 314 stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0); 315 stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0); 316 stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0); 368 stars[i].X = X[i]; 369 stars[i].Y = Y[i]; 370 stars[i].M = M[i]; 371 372 if (ADDNOISE) { 373 stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0); 374 stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0); 375 stars[i].M += fSN*rnd_gauss(0.0, 1.0); 376 } 317 377 318 378 stars[i].dX = FX * fSN; … … 354 414 fSN = 1.0 / sqrt(flux); 355 415 356 stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0); 357 stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0); 358 stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0); 416 stars[i].X = X[i]; 417 stars[i].Y = Y[i]; 418 stars[i].M = M[i]; 419 420 if (ADDNOISE) { 421 stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0); 422 stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0); 423 stars[i].M += fSN*rnd_gauss(0.0, 1.0); 424 } 359 425 360 426 stars[i].dX = FX * fSN; … … 396 462 fSN = 1.0 / sqrt(flux); 397 463 398 stars[i].X = X[i] + FX * fSN * rnd_gauss(0.0, 1.0); 399 stars[i].Y = Y[i] + FY * fSN * rnd_gauss(0.0, 1.0); 400 stars[i].M = M[i] + fSN*rnd_gauss(0.0, 1.0); 464 stars[i].X = X[i]; 465 stars[i].Y = Y[i]; 466 stars[i].M = M[i]; 467 468 if (ADDNOISE) { 469 stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0); 470 stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0); 471 stars[i].M += fSN*rnd_gauss(0.0, 1.0); 472 } 401 473 402 474 stars[i].dX = FX * fSN;
Note:
See TracChangeset
for help on using the changeset viewer.
