extern void ReadMatchinFiles(char *FN, StarCatRec *PStarCatProp, float HDR_DX, float HDR_DY, float HDR_ROT) { float **PX; int NL,I; strcpy(PStarCatProp->FN,FN); PStarCatProp->HDR_DX = HDR_DX; PStarCatProp->HDR_DY = HDR_DY; PStarCatProp->HDR_ROT = HDR_ROT; ReadASCIITable(&NL,4,&PX,FN); PStarCatProp->NObj = NL; PStarCatProp->PX = (float *)calloc(NL,sizeof(float)); PStarCatProp->PY = (float *)calloc(NL,sizeof(float)); PStarCatProp->PM = (float *)calloc(NL,sizeof(float)); for (I=0;I<NL;I++) { PStarCatProp->PX[I] = PX[I][1]; PStarCatProp->PY[I] = PX[I][2]; PStarCatProp->PM[I] = PX[I][3]; } freeFloatArray(PX,4,NL); }
int main(int argc, char *argv[]) { int a, i; int N1old = 0, N2old = 0, N1, N2; int nimages = 0; float **f = NULL; /* holds pixel data of input images */ fstatsrec srec; fitsheader *fits; FILE *ipf, *opf = stdout; float lo_rej = -60000.0; /* low pixel reject. threshhold for statistics */ float hi_rej = 60000.0; /* high pixel reject. threshhold for statistics */ int ndecimals = 2; /* number of decimal points in output numbers */ int xmin = 0, xmax = 0; /* x-range for statistic estimation */ int ymin = 0, ymax = 0; /* y-range for statistic estimation */ int rangespec = 0; /* was a x and y-range specified ? */ char imagenames[MAXIMAGE][MAXCHAR]; char inputimagelist[MAXCHAR] = ""; char outfilename[MAXCHAR] = ""; char tmpstring[MAXCHAR]; char *tmpchar; char formatstring[MAXCHAR]; char *str; /* read comand line arguments */ if (argc < 2) { printUsage(); exit(0); } for (a = 1; a < argc; a++) { if (argv[a][0] == '-') { switch ((int)tolower((int)argv[a][1])) { /*-------- Config filename */ case 'h': printUsage(); exit(0); break; case 'd': if (a < (argc - 1)) { ndecimals = atoi(argv[++a]); } else { printUsage(); exit(1); } break; case 'i': if (a < (argc - 1)) { strncpy(inputimagelist, argv[++a], MAXCHAR - 1); } else { printUsage(); exit(1); } break; case 'o': if (a < (argc - 1)) { strncpy(outfilename, argv[++a], MAXCHAR - 1); } else { printUsage(); exit(1); } break; case 's': if (a < (argc - 4)) { xmin = atoi(argv[++a]); xmax = atoi(argv[++a]); ymin = atoi(argv[++a]); ymax = atoi(argv[++a]); rangespec = 1; } else { printUsage(); exit(1); } break; case 't': if (a < (argc - 2)) { lo_rej = atof(argv[++a]); hi_rej = atof(argv[++a]); } else { printUsage(); exit(1); } break; default: printUsage(); exit(1); break; } } else { /*---- The input image filename(s) */ for (; (a < argc) && (*argv[a] != '-'); a++) { for (str = NULL; (str = strtok(str ? NULL : argv[a], notokstr)); nimages++) { if (nimages < MAXIMAGE) { strncpy(imagenames[nimages], str, MAXCHAR - 1); } else { snprintf(tmpstring, MAXCHAR - 1, "*Error*: Too many input images (more than %d)\n", MAXIMAGE); error_exit(tmpstring); } } } a--; } } /* test if we have a file containing input images if yes, read files and add them to the image list */ if(strcmp(inputimagelist, "") != 0) { if ((ipf = fopen(inputimagelist, "r")) != NULL) { /* Todo: make the file reading more robust to filenames having spaces at the beginning and the end of their names */ while((tmpchar = fgets(imagenames[nimages], MAXCHAR, ipf)) && (nimages < MAXIMAGE)) { /* remove possible 'newline' in filenames */ if((tmpchar = strchr(imagenames[nimages], '\n')) != NULL) { *tmpchar = '\0'; } nimages++; } fclose(ipf); if(nimages == MAXIMAGE && tmpchar != NULL) { snprintf(tmpstring, MAXCHAR - 1, "*Error*: Too many input images (more than %d)\n", MAXIMAGE); error_exit(tmpstring); } } else { snprintf(tmpstring, MAXCHAR - 1, "could not open file %s: aborting\n", inputimagelist); error_exit(tmpstring); } } if (strcmp(outfilename, "") != 0) { if ((opf = fopen(outfilename, "w")) == NULL) { snprintf(tmpstring, MAXCHAR - 1, "could not open %s for output: aborting\n", outfilename); error_exit(tmpstring); } } if (ndecimals < 0) { ndecimals = 2; } /* Welcome message */ fprintf(opf, "# imstats: %s\n", __PIPEVERS__); fprintf(opf, "# imstats: called at %s\n", get_datetime_iso8601()); fprintf(opf, "# imstats: estimating statistics in\n"); if (xmax == 0 || ymax == 0) { fprintf(opf, "# the whole frames within %f < pixvalue < %f\n", lo_rej, hi_rej); } else { fprintf(opf, "# %d < x < %d, %d < y < %d within %f < pixvalue < %f\n", xmin, xmax, ymin, ymax, lo_rej, hi_rej); } fprintf(opf, "#\n"); fprintf(opf, "# imstats: filename\tmode\tlquartile\tmedian\tuquartile\tmean\tsigma\tmin\tmax\tgoodpix\tgoodpix/percent\n"); for (i = 0; i < nimages; i++) { if ((ipf = fopen(imagenames[i], "r")) == NULL) { snprintf(tmpstring, MAXCHAR - 1, "could not open file %s: aborting!!\n", imagenames[i]); error_exit(tmpstring); } /* read in FITS image header */ fits = readfitsheader(ipf); N1 = fits->n[0]; N2 = fits->n[1]; if ((N1 != N1old) || (N2 != N2old)) { freeFloatArray(f); allocFloatArray(&f, N1, N2); N1old = N1; N2old = N2; } /* read in FITS image pixel data */ readfitsplane((void **)f, fits); /* if limits have not been given we take the whole frame */ if (0 == rangespec) { xmin = ymin = 0; xmax = N1; ymax = N2; } fdo_stats(f, N1, N2, xmin, xmax, ymin, ymax, lo_rej, hi_rej, &srec); snprintf(formatstring, MAXCHAR - 1, "%%s\t%%6.%df\t%%6.%df\t%%6.%df\t%%6.%df\t%%6.%df\t%%6.%df\t%%6.%df\t%%6.%df\t%%ld\t%%6.%df\n", ndecimals, ndecimals, ndecimals, ndecimals, ndecimals, ndecimals, ndecimals, ndecimals, ndecimals); fprintf(opf, formatstring, imagenames[i], srec.fmode, srec.flowerquartile, srec.fmedian, srec.fupperquartile, srec.fmean, srec.sigma, srec.fmin, srec.fmax, srec.goodpix, (float)srec.goodpix * 100. / ((xmax - xmin) * (ymax - ymin))); delfitsheader(fits); if (0 != fclose(ipf)) { snprintf(tmpstring, MAXCHAR - 1, "could not close %s: aborting", imagenames[i]); error_exit(tmpstring); } } freeFloatArray(f); if (strcmp(outfilename, "") != 0) { fclose(opf); } #ifdef MEMORY_DEBUG xmemory_status(); #endif return(0); }