#include #include #include #include #include "comphys.h" #include "comphys.c" void sort(unsigned long n, float arr[]); float *scany,*scanx,*factorx,*factory; float *t; float fx(float x[]); float fy(float x[]); /* Note: Codes 0 = blank image, 1 = star found, but not on slit, 2 = star found and it is on (but may be decentered) the slit. */ int main(int argc, char *argv[]) { float **array; float *stat,*tempy,*backx,*backy; float median,max,maxm1,sumx,sumy,sumM,cx,cy,smax,smax2,xmax2,xmin,xav; int xmax; float medianx,mediany; float smay,ymax,ymax2; float *p,**xi,fret; float xcoord,ycoord; int iter,k; float A,B,C,D,ypos; float threshold = 1500.0; int i,j,l,I,J,fwhm,err,a,b,c,m,n; int bx,by; int minfound = 0; char buffer[5000],buf[5000],*tmp,infile[80]; FILE *in,*out,*outy,*bad; double miny = 1.0e+30; int slitj; array = matrix(1,382,1,255); scany = vector(1,255); tempy = vector(1,255); factory = vector(1,255); stat = vector(1,97410); outy = fopen("scany.out","w"); strcpy(infile,argv[1]); sprintf(buf,"imlist %s > temp.dat",infile); err = system(buf); in = fopen("temp.dat","r"); if(in == NULL) { printf("Cannot open temp.dat\n"); exit(1); } fgets(buf,4000,in); fgets(buf,4000,in); for(j=255;j>=1;j--) { fgets(buffer,4000,in); tmp = strtok(buffer," "); for(i=1;i<=382;i++) { tmp = strtok(NULL," "); array[i][j] = atof(tmp); } } fclose(in); /* Correct for badpixels by reading badpix.dat file. Skip if it can't find the file */ /* Get y-direction scan by adding up rows in x-direction. This scans over the entire chip. We may want to change that if we can routinely get the star within, say, 100 pixels of the slit, so that if there are other stars in the field there is less chance of confusion */ for(j=1;j<=255;j++) tempy[j] = 0.0; for(j=1;j<=255;j++) { tempy[j] = 0.0; for(i=1;i<=382;i++) { tempy[j] += array[i][j]; } } /* for(i=1;i<=255;i++) fprintf(outy,"%d %f\n",i,tempy[i]); fclose(outy); */ slitj = 0; for(j=70;j<160;j++) { if(miny > tempy[j]) { miny = tempy[j]; slitj = j; } } printf("%d\n",slitj); return(0); }