Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

extract/source/check_optics.c

Go to the documentation of this file.
00001 /* === Doxygen Comment ======================================= */
00013 /* =========================================================== */
00014 
00015 #include <IFU_io.h>
00016 #include <IFU_math.h>
00017 #include <snifs.h>
00018 #include <extract.h>
00019 
00020 #ifdef HAVE_LIBDISLIN
00021 #include <dislin.h>
00022 #endif
00023 
00024 /* === Doxygen Comment ======================================= */
00041 /* =========================================================== */
00042 
00043 int main(int argc, char **argv)
00044 {
00045   SnifsConfig config;
00046   SnifsOptics optics;
00047 
00048   TABLE mask,table;
00049 
00050   char **argval, **arglabel;
00051   char *maskname, *tabname, *devname;
00052   char labcol[lg_label+1];
00053 
00054   int *nopup;
00055   int *colxb,*colyb,*colxc,*colyc;
00056   int i,order,line;
00057   int DEFAULT,DEV;
00058   int minorder,maxorder,singlelens,status;
00059   int colno,colxd,colyd,colxp,colyp,colxo,colyo;
00060   
00061   float *xppup,*yppup;
00062   float lambda,lbdaref;
00063   float val;
00064   
00065   double *xccd, *yccd, *xpccd, *ypccd;
00066   double *xpup,*ypup,*xmla,*ymla;
00067   double lbda_inf,lbda_sup,xc,yc,pixsize;
00068   double xblue,yblue,xred,yred;
00069 
00070 #ifdef HAVE_LIBDISLIN
00071   char title[4*lg_ident+1];
00072   int color,symbol;
00073 #endif
00074 
00075   /* ##### INTRODUCTION ############################## */
00076 
00077   set_purpose("Test-program for the optical and configuration procedures");
00078   set_arglist("-mask mask -out snifs_optics -lambda 0 -default "
00079               "-orders 0,2 -lens 0 -dev NULL");
00080 
00081   init_snifs("$Name:  $");
00082   init_session(argv,argc,&arglabel,&argval);
00083 
00084   if (DEBUG) {
00085     print_msg("$Id: check_optics.c,v 1.14 2004/11/09 18:01:27 ycopin Exp $");
00086     print_msg("Compilation: %s, %s",__DATE__,__TIME__);
00087   }
00088 
00089   /* ===== Parameters ============================== */
00090 
00091   maskname = argval[0];                               /* 0 Input mask      */
00092   tabname  = argval[1];                               /* 1 Output table    */
00093   get_argval(2,"%f",&lambda);                         /* 2 Input lambda    */
00094   DEFAULT = is_true(argval[3]);                       /* 3 Configuration   */
00095   if (sscanf(argval[4], "%d,%d",&minorder,&maxorder) != 2) { /* 4 Orders   */
00096     print_error("Invalid option -orders min_order,max_order (has '%s')",
00097                 argval[4]);
00098     exit_session(ERR_BAD_PARAM);
00099   }
00100   get_argval(5,"%d",&singlelens);                     /* 5 Single lens     */
00101   if ((DEV = is_set(argval[6]))) devname = argval[6]; /* 6 Output device   */
00102 
00103   print_msg("o Input mask: %s",maskname);
00104   print_msg("o Output table: %s",tabname);
00105   if (lambda==0) print_msg("o Test at mpup wavelength");
00106   else           print_msg("o Test at %.2f AA",lambda);
00107   if (DEFAULT) print_msg("o Default configuration used");
00108   else         print_msg("o Reading configuration from mask");
00109   print_msg("o Orders: %d to %d",minorder,maxorder);
00110   if (singlelens) print_msg("o Testing single lens #%d",singlelens);
00111   if (DEV) {
00112 #ifdef HAVE_LIBDISLIN
00113     print_msg("o Output DISLIN device: %s",devname);
00114 #else
00115     print_error("DISLIN output not supported in current executable");
00116     exit_session(ERR_BAD_PARAM);
00117 #endif
00118   }
00119 
00120   /* ===== Mask ============================== */
00121 
00122   if ((status = open_mask(maskname,&mask,"IO"))) exit_session(status);
00123   handle_select_flag(&mask,'W',NULL);
00124 
00125   /* ===== Configuration ============================== */
00126 
00127   /* ----- Channel ------------------------------ */
00128 
00129   lbdaref = read_lbdaref(&mask);
00130 
00131   /* ----- Configuration ------------------------------ */
00132 
00133   if (DEFAULT) {
00134     Channel channel;
00135 
00136     if (!(channel = read_channel(&mask))) exit_session(channel);
00137     read_default_snifs_config(channel,&config);
00138 
00139     if (write_snifs_config_to_mask(&mask,&config)) 
00140       exit_session(ERR_BAD_DESC);
00141   }
00142   else if (read_snifs_config_from_mask(&mask,&config))
00143     exit_session(ERR_NODESC);
00144 
00145   print_snifs_config(&config);
00146 
00147   optics = config.optics;
00148 
00149   /* ----- Variables ------------------------------ */
00150 
00151   lbda_inf = optics.filter.inf_util;         /* Wavelength coverage */
00152   lbda_sup = optics.filter.sup_util;
00153   xc       = optics.center.xc;               /* Center of distortion */
00154   yc       = optics.center.yc;
00155 
00156   pixsize  = config.ccd.pixsize*1e-3;        /* Pixel size [mm] */
00157 
00158   /* ===== Mpup coordinates ============================== */
00159 
00160   print_msg("Reading mpup coordinates (%.1f A) from mask...",lbdaref);
00161 
00162   colno = get_col_ref(&mask,LAB_COL_NO);
00163   colxd = get_col_ref(&mask,LAB_COL_XLD);
00164   colyd = get_col_ref(&mask,LAB_COL_YLD);
00165   if (colno<0 || colxd<0 || colyd<0) {
00166     print_error("Cannot read specific mask columns in %s",maskname);
00167     exit_session(ERR_NOCOL);
00168   }
00169 
00170   nopup =   (int *)malloc(mask.row*sizeof(int));    /* Mpup number */
00171   xppup = (float *)malloc(mask.row*sizeof(float));  /* Mpup position [px] */
00172   yppup = (float *)malloc(mask.row*sizeof(float)); 
00173 
00174   /* [CCD/px] */
00175   RD_col(&mask,colno,nopup);
00176   RD_col(&mask,colxd,xppup);
00177   RD_col(&mask,colyd,yppup);
00178 
00179   print_msg("   %d (1st-order) mpups",mask.row);
00180 
00181   close_table(&mask);
00182 
00183   /* ===== Input wavelength ============================== */
00184 
00185   if (lambda==0) lambda = lbdaref;
00186 
00187   print_msg("Single wavelength test: %.1f AA",lambda);
00188 
00189   /* ===== Output table ============================== */
00190 
00191   if (!singlelens) {
00192     print_msg("Creating output table %s...",tabname);
00193 
00194     if (create_table(&table,tabname,-1,-1,'Q',"Optics checks") < 0) {
00195       print_error("Unable to create table %s",tabname);
00196       exit_session(ERR_CREAT);
00197     }
00198 
00199     colno = create_col(&table,LAB_COL_NO, INT,  'R',"I4","");
00200     colxd = create_col(&table,LAB_COL_XLD,FLOAT,'R',"F9.6","px");
00201     colyd = create_col(&table,LAB_COL_YLD,FLOAT,'R',"F9.6","px");
00202     colxp = create_col(&table,"XPUP",     FLOAT,'R',"F9.6","mm");
00203     colyp = create_col(&table,"YPUP",     FLOAT,'R',"F9.6","mm");
00204     colxo = create_col(&table,"XMLA",     FLOAT,'R',"F9.6","mm");
00205     colyo = create_col(&table,"YMLA",     FLOAT,'R',"F9.6","mm");
00206 
00207     colxb = (int *)malloc((maxorder-minorder+1)*sizeof(int));
00208     colyb = (int *)malloc((maxorder-minorder+1)*sizeof(int));
00209     colxc = (int *)malloc((maxorder-minorder+1)*sizeof(int));
00210     colyc = (int *)malloc((maxorder-minorder+1)*sizeof(int));
00211 
00212     for (order=minorder; order<=maxorder; order++) {
00213       sprintf(labcol,"XDET%.1d",order);
00214       colxb[order] = create_col(&table,labcol,FLOAT,'R',"F9.6","mm");
00215       sprintf(labcol,"YDET%.1d",order);
00216       colyb[order] = create_col(&table,labcol,FLOAT,'R',"F9.6","mm");
00217       sprintf(labcol,"XCCD%.1d",order);
00218       colxc[order] = create_col(&table,labcol,FLOAT,'R',"F9.6","px");
00219       sprintf(labcol,"YCCD%.1d",order);
00220       colyc[order] = create_col(&table,labcol,FLOAT,'R',"F9.6","px");
00221     }
00222   }
00223   
00224   /* ##### OPTICS ############################## */
00225 
00226   /* ===== Simple tests ============================== */
00227 
00228   if (DEBUG) {
00229 
00230     /* ----- Null deviation wavelength ------------------------------ */
00231 
00232     snifs_optics_test_forward(&optics, 0., 0., &xblue, &yblue, 4300., 1);
00233     xblue /= pixsize; yblue /= pixsize;
00234     print_msg("Central position (O%d): xccd,yccd = %g px, %g px\n",
00235               1,xblue,yblue);
00236     snifs_optics_forward(&optics, 0., 0., &xblue, &yblue, 4300., 0);
00237     xblue /= pixsize; yblue /= pixsize;
00238     print_msg("Central position (O%d): xccd,yccd = %g px, %g px",
00239               0,xblue,yblue);
00240     snifs_optics_forward(&optics, 0., 0., &xblue, &yblue, 4300., 2);
00241     xblue /= pixsize; yblue /= pixsize;
00242     print_msg("Central position (O%d): xccd,yccd = %g px, %g px\n",
00243               2,xblue,yblue);
00244 
00245     /* ----- Dispersion by pixel ------------------------------ */
00246 
00247     snifs_optics_forward(&optics, 0., 0., &xblue, &yblue, 
00248                               optics.filter.inf_util, 1);
00249     xblue /= pixsize; yblue /= pixsize;
00250     print_msg("Central position (%.1f A): xccd,yccd = %g px, %g px",
00251               optics.filter.inf_util,xblue,yblue);
00252     snifs_optics_forward(&optics, 0., 0., &xred, &yred, 
00253                               optics.filter.sup_util, 1);
00254     xred /= pixsize; yred /= pixsize;
00255     print_msg("Central position (%.1f A): xccd,yccd = %g px, %g px",
00256               optics.filter.sup_util,xred,yred);
00257 
00258     print_msg("Dispersion [AA/px]: def. = %f, comp. = %f",
00259               optics.grism.w_disp*pixsize,
00260               ABS(optics.filter.width_util/(yred - yblue)));
00261     print_msg("Dispersion orientation: def. = '%s', comp. = '%s'",
00262               (optics.grism.rotz<M_PI_2)? "red is down":"red is up",
00263               (yblue>yred)? "red is down":"red is up");
00264   }
00265   
00266   /* ===== Optics simulation ============================== */
00267 
00268   xpup = (double *)malloc(mask.row*sizeof(double)); /* Mpup position [mm] */
00269   ypup = (double *)malloc(mask.row*sizeof(double));
00270   xmla = (double *)malloc(mask.row*sizeof(double)); /* Lens position [mm] */
00271   ymla = (double *)malloc(mask.row*sizeof(double));
00272 
00273   xccd = (double *)malloc(mask.row*sizeof(double)); /* CCD position [mm] */
00274   yccd = (double *)malloc(mask.row*sizeof(double));
00275   xpccd= (double *)malloc(mask.row*sizeof(double)); /* CCD position [px] */
00276   ypccd= (double *)malloc(mask.row*sizeof(double));
00277 
00278 #ifdef HAVE_LIBDISLIN
00279   if (DEV) {
00280     metafl(devname);  /* Output device */
00281     filmod("delete"); /* overwrite */
00282     setpag("DA4P");   /* portrait */
00283 
00284     disini();
00285     errmod("CHECK","OFF"); /* No check on boundaries */
00286 
00287     if (DEBUG) 
00288       paghdr("$Id: check_optics.c,v 1.14 2004/11/09 18:01:27 ycopin Exp $",
00289              "",4,0); /* Technical header */
00290 
00291     axspos(250,2700); /* Use center(); to center axes */
00292     axslen(1700,2400); /* Axe lengthes */
00293     labtyp("VERT","Y");
00294     intax(); /* Integer labels */
00295     ticpos("REVERS", "XY"); /* Ticks inward */
00296     name("x [px]","x"); name("y [px]","y");
00297 
00298     setvlt("SPEC"); /* Another brighter LUT */
00299     hsymbl(10); /* symbol size (default: 35) */
00300     /* Fonts: disalf,simplx,complx,duplx,triplx,gothic,serif,helve,helves */
00301     complx(); 
00302 
00303     graf(0,config.ccd.nx,500,500,0,config.ccd.ny,500,500); /* start,end,1st_lab,lab_step */
00304 
00305     sprintf(title,"SNIFS optical test\n\nMask: %s ",maskname);
00306     plot_title(title);
00307   }
00308 #endif
00309 
00310   for (line=i=0; i<mask.row; i++) {
00311     if (singlelens && nopup[i]!=singlelens) continue;
00312 
00313     print_msg("Processing lens #%d (%6.1fx%6.1f)",nopup[i],xppup[i],yppup[i]);
00314 
00315     /* [CCD/mm] */
00316     xpup[i] = (xppup[i] - xc)*pixsize;
00317     ypup[i] = (yppup[i] - yc)*pixsize;
00318 
00319     /* [MLA/mm] */
00320     snifs_optics_backward(&optics, xpup[i],ypup[i], xmla+i,ymla+i, lbdaref,1);
00321 
00322     /* Output storage */
00323     if (!singlelens) {
00324       WR_tbl(&table,line,colno,&(nopup[i]));
00325       WR_tbl(&table,line,colxd,&(xppup[i]));
00326       WR_tbl(&table,line,colyd,&(yppup[i]));
00327       val = xpup[i]; WR_tbl(&table,line,colxp,&val);
00328       val = ypup[i]; WR_tbl(&table,line,colyp,&val);
00329       val = xmla[i]; WR_tbl(&table,line,colxo,&val);
00330       val = ymla[i]; WR_tbl(&table,line,colyo,&val);
00331     }
00332     
00333     for (order=minorder; order<=maxorder; order++) {
00334       /* [CCD/mm] */
00335       if (singlelens && DEBUG) {
00336         snifs_optics_test_forward(&optics, xmla[i],ymla[i],
00337                                   xccd+i,yccd+i,lambda,order);
00338       }
00339       else {
00340         snifs_optics_forward(&optics, xmla[i],ymla[i], 
00341                              xccd+i,yccd+i,lambda,order);
00342       }
00343         
00344       /* [CCD/px] */
00345       xpccd[i] = xccd[i]/pixsize + xc;
00346       ypccd[i] = yccd[i]/pixsize + yc;
00347 
00348       if (DEBUG) print_msg("   O%d[%.1f A]: %6.1fx%6.1f",
00349                            order,lambda,xpccd[i],ypccd[i]);
00350 
00351 #ifdef HAVE_LIBDISLIN
00352       if (DEV) { /* plotting current mpup data */
00353         color = 10*i%255 + 1;
00354         switch (order) {
00355         case 0: symbol = 3;  break; /* +  */
00356         case 1: symbol = 16; break; /* [] */
00357         case 2: symbol = 15; break; /* 0  */
00358         }
00359         setclr(color);
00360         rlsymb(symbol,xpccd[i],ypccd[i]);
00361       }
00362 #endif
00363       
00364       /* Output storage */
00365       if (!singlelens) {
00366         val = xccd[i];  WR_tbl(&table,line,colxb[order],&val);
00367         val = yccd[i];  WR_tbl(&table,line,colyb[order],&val);
00368         val = xpccd[i]; WR_tbl(&table,line,colxc[order],&val);
00369         val = ypccd[i]; WR_tbl(&table,line,colyc[order],&val);
00370       }
00371     } /* loop over orders (order) */
00372 
00373     line ++;
00374   } /* loop over mpups (i) */
00375   
00376 #ifdef HAVE_LIBDISLIN
00377   if (DEV) { /* Graphic output conclusion */
00378     disfin();
00379   }
00380 #endif
00381 
00382   free(nopup); free(xppup); free(yppup);
00383   
00384   free(xpup); free(ypup); free(xmla);  free(ymla);
00385   free(xccd); free(yccd); free(xpccd); free(ypccd);
00386   
00387   if (!singlelens) {
00388     free(colxb); free(colyb); free(colxc); free(colyc);
00389 
00390     close_table(&table);
00391   }
00392     
00393   exit_session(OK);
00394   return(OK);
00395 }
00396 

Generated on Tue Nov 23 18:04:19 2004 for Snifs by doxygen 1.3.3