Changeset 24522
- Timestamp:
- Jun 19, 2009, 4:11:25 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/extsrc/gpcsw/gpcsrc/fits/tiltystreak/tiltystreak.c
r24390 r24522 1 /* -*- c-file-style: "Ellemtel" -*- */ 1 2 /* tiltystreak.c - fit and subtract tilted streaks from a row of cells */ 2 3 /* Assumes that biastool has already been run -- zero streakiness near bias */ … … 52 53 static int parabola_streak_fit(int sx, int nx, int ny, int NX, CELL otarow[]); 53 54 int linearfit(int npt, double *y, int nx, double *x, double *param); 55 static void syntax(const char *prog); 54 56 55 57 static int nmedian_buf=0; … … 59 61 int main(int argc, const char* argv[]) 60 62 { 61 int i, row, col, ext;63 int i, j, row, col, ext; 62 64 HeaderUnit ihu = fh_create(); 63 65 HeaderUnit ehu = NULL; … … 66 68 int nextend; 67 69 CELL otarow[NCELL]; 68 int naxis, naxis1, naxis2, naxis3; 70 int naxis, naxis1=0, naxis2=0; 71 int n1, n2; 69 72 int prescan1, ovrscan1, ovrscan2; 70 73 double bzero_d; 71 74 int bzero = 32768, firstime = 1, algo=2; 75 int cellmask[NCELL*NCELL]; 72 76 73 77 if(argc < 2) { 78 syntax(argv[0]); 74 79 fprintf(stderr, "error: syntax: tiltystreak Uncompressed_GPC1_MEF.fits\n"); 75 80 exit(EXIT_FAILURE); … … 77 82 ifilename = argv[1]; 78 83 79 /* Choose different algorithms? */ 80 if(argc > 2 && strncmp(argv[2], "alg=", 4) == 0) { 81 if(strcmp(argv[2]+4, "line") == 0) { 82 algo = 1; 83 } else if(strcmp(argv[2]+4, "parabola") == 0) { 84 algo = 2; 85 } else if(strcmp(argv[2]+4, "bent") == 0) { 86 algo = 3; 84 /* Defaults */ 85 for(i=0; i<NCELL*NCELL; i++) cellmask[i] = 1; /* Use all cells */ 86 algo = 2; /* Default algorithm is a parabola */ 87 88 /* Process arguments */ 89 for(i=2; i<argc; i++) { 90 91 /* Veto cells by a 64 digit mask (0/1 for cells 0-63) */ 92 if(strncmp(argv[i], "mask=", 5) == 0) { /* mask=64_digits */ 93 if(strlen(argv[i]) < 5+NCELL*NCELL) { 94 fprintf(stderr, "\rerror: cannot get mask from `%s'\n", argv[i]); 95 exit(EXIT_FAILURE); 96 } else { 97 for(j=0; j<NCELL*NCELL; j++) cellmask[j] = argv[i][5+j] != '0'; 98 } 99 100 } else if(strncmp(argv[2], "alg=", 4) == 0) { /* Algorithm */ 101 if(strcmp(argv[2]+4, "line") == 0) { 102 algo = 1; 103 } else if(strcmp(argv[2]+4, "parabola") == 0) { 104 algo = 2; 105 } else if(strcmp(argv[2]+4, "bent") == 0) { 106 algo = 3; 107 } else { 108 fprintf(stderr, "error: `%s' is not a valid algorithm\n", argv[2]); 109 exit(EXIT_FAILURE); 110 } 111 112 } else if(strncmp(argv[i], "help", 4) == 0) { /* help output */ 113 syntax(argv[0]); 114 exit(EXIT_SUCCESS); 115 87 116 } else { 88 fprintf(stderr, "error: `%s' is not a valid algorithm\n", argv[2]); 117 fprintf(stderr, "\rerror: unrecognized option `%s'\n", argv[i]); 118 syntax(argv[0]); 89 119 exit(EXIT_FAILURE); 90 120 } 91 121 } 122 92 123 93 124 if (fh_file(ihu, ifilename, FH_FILE_RDWR) != FH_SUCCESS) { … … 139 170 140 171 /* Positioned at the desired cell now */ 141 naxis3 = 1;142 172 if (fh_get_PRESCAN1(ehu, &prescan1) != FH_SUCCESS || 143 173 fh_get_OVRSCAN1(ehu, &ovrscan1) != FH_SUCCESS || 144 174 fh_get_OVRSCAN2(ehu, &ovrscan2) != FH_SUCCESS || 145 175 fh_get_NAXIS(ehu, &naxis) != FH_SUCCESS || 146 fh_get_NAXIS1(ehu, &n axis1) != FH_SUCCESS ||147 fh_get_NAXIS2(ehu, &n axis2) != FH_SUCCESS) {176 fh_get_NAXIS1(ehu, &n1) != FH_SUCCESS || 177 fh_get_NAXIS2(ehu, &n2) != FH_SUCCESS) { 148 178 fprintf(stderr, "error: Cannot get NAXIS* in extension %d row %d col %d\n", ext, row, col); 149 179 exit(EXIT_FAILURE); … … 157 187 /* Make some space now that we finally know the size */ 158 188 if(firstime) { 189 naxis1 = n1; 190 naxis2 = n2; 159 191 firstime = 0; 160 192 for(i=0; i<NCELL; i++) { … … 167 199 Bbuf = (double *)calloc(naxis2, sizeof(double)); 168 200 Xbuf = (double *)calloc(NPOLY*naxis2, sizeof(double)); 201 } 202 else { 203 if(naxis1 != n1 || naxis2 != n2) { 204 fprintf(stderr, "error: All cells must be same size (%dx%d != %dx%d)\n", 205 n1, n2, naxis1, naxis2); 206 exit(EXIT_FAILURE); 207 } 169 208 } 170 209 … … 214 253 #ifdef DEBUG 215 254 for(col=0; col<NCELL; col++) { 216 printf("%1d %1d %3d %3d %6d %6d %6d %6d %8.3f\n",255 printf("%1d %1d %3d %3d 0x%08x %6d %6d %6d %6d %8.3f\n", 217 256 col, row, otarow[col].cell, otarow[col].mefxt, 257 (int)otarow[col].hu, 218 258 otarow[col].bias, otarow[col].sky, otarow[col].rms, 219 259 otarow[col].nsat, otarow[col].ampl); … … 258 298 /* Return to all the cells in the MEF and rewrite the data */ 259 299 for(col=0; col<NCELL; col++) { 300 #ifdef DEBUG 301 printf("Now writing cell %d %d ext %d (hu 0x%08x)\n", 302 col, row, otarow[col].mefxt, (int)otarow[col].hu); 303 #endif 260 304 if(otarow[col].mefxt < 0) continue; 305 /* Skip if cell mask not set */ 306 if(cellmask[col+NCELL*row] != 1) continue; 261 307 /* This seeks back to the start of data from this cell again... */ 262 308 ehu = otarow[col].hu; 263 309 fh_ehu(ehu, 0); 264 310 311 #ifdef DEBUG 312 printf("Now writing cell %d %d ext %d (hu 0x%08x)\n", 313 col, row, otarow[col].mefxt, (int)otarow[col].hu); 314 #endif 265 315 if (fh_write_padded_image(ehu, fh_file_desc(ehu), otarow[col].data, 266 316 naxis1*naxis2*sizeof(short), … … 272 322 } 273 323 274 } 324 } /* Loop over rows */ 275 325 276 326 fh_destroy(ihu); … … 439 489 A = Abuf[j] - (par[0] + j*par[1] + j*j*par[2]); 440 490 #ifdef DEBUG 441 if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f\n", j, Abuf[j], A);491 // if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f\n", j, Abuf[j], A); 442 492 #endif 443 493 for(k=0; k<NCELL; k++) { … … 504 554 B = Bbuf[j] - (Bpar[0] + j*Bpar[1] + j*j*Bpar[2]); 505 555 #ifdef DEBUG 506 if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f %9.3f %9.3f\n",507 j, Abuf[j], A, Bbuf[j], B);556 // if(otarow[3].mefxt == 4) printf("%4d %9.3f %9.3f %9.3f %9.3f\n", 557 // j, Abuf[j], A, Bbuf[j], B); 508 558 #endif 509 559 /* Parabola passes through 0 at i=sx+nx, A at sx+nx/6, B at sx+nx/2 */ … … 590 640 591 641 #ifdef DEBUG 592 if(otarow[3].mefxt == 4) printf("%4d %4d %9.3f %9.3f %9.3f\n",593 j, i0, A, B, C);642 // if(otarow[3].mefxt == 4) printf("%4d %4d %9.3f %9.3f %9.3f\n", 643 // j, i0, A, B, C); 594 644 #endif 595 645 … … 609 659 return(0); 610 660 } 661 662 static void syntax(const char *prog) 663 { 664 printf("Syntax: %s mef_file [options]\n", prog); 665 printf(" where options include:\n\n"); 666 printf(" mask=0101... 64 digits to work on cells 0:63.\n"); 667 printf(" alg=N Use fit algorithm 1=linear, 2=parabola (default)\n"); printf(" 3=bent linear (not yet fully implemented)\n"); 668 }
Note:
See TracChangeset
for help on using the changeset viewer.
