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

extract/lib/proc_config.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 <snifs_materials.h>
00019 #include <extract.h>
00020 #include <ctype.h>                           /* toupper() */
00021 
00022 /* === Doxygen Comment ======================================= */
00033 /* =========================================================== */
00034 
00035 int read_PSFgeo_param(void *anyfile, double *geo_param[]) 
00036 {
00037   int nggeo;
00038   
00039   if (RD_desc(anyfile,MPUP_NGGEO,INT,1,&nggeo) < 0) {
00040     print_error("Unable to read descriptor %s",MPUP_NGGEO);
00041     nggeo = -1;
00042   }
00043   else {
00044     *geo_param = (double *)malloc(3*nggeo*sizeof(double));
00045     if (RD_desc(anyfile,MPUP_GEOPAR,DOUBLE,3*nggeo,*geo_param) < 0) {
00046       print_error("Unable to read descriptor %s",MPUP_GEOPAR);
00047       free(*geo_param);
00048       nggeo = -1;
00049     }
00050     else
00051       print_msg("   Geometric PSF model: %d component(s)",nggeo);
00052   }
00053   return(nggeo);
00054 }
00055 
00056 /* === Doxygen Comment ======================================= */
00067 /* =========================================================== */
00068 
00069 int read_PSFglobal_param(void *anyfile, double *psf_param[]) 
00070 {
00071   int ngpsf;
00072   
00073   if (RD_desc(anyfile,MPUP_NGPSF,INT,1,&ngpsf) < 0) {
00074     print_error("Unable to read descriptor %s",MPUP_NGPSF);
00075     ngpsf = -1;
00076   }
00077   else {
00078     *psf_param = (double *)malloc((1+2*ngpsf)*sizeof(double));
00079     if (RD_desc(anyfile,MPUP_PSFPAR,DOUBLE,(1+2*ngpsf),*psf_param) < 0) {
00080       print_error("Unable to read descriptor %s",MPUP_PSFPAR);
00081       free(*psf_param);
00082       ngpsf = -1;
00083     }
00084     else {
00085       if (DEBUG) print_msg("   Geometric pupil scale: %8.4f pix", psf_param[0]);
00086       print_msg("   Global PSF model: %d component(s)",ngpsf);
00087     }
00088   }
00089   return(ngpsf);
00090 }
00091 
00092 /* === Doxygen Comment ======================================= */
00099 /* =========================================================== */
00100 
00101 int read_PSFlocal_ng(void *anyfile) 
00102 {
00103   int ngloc;
00104   
00105   if (RD_desc(anyfile,MPUP_NGLOC,INT,1,&ngloc) < 0) {
00106     print_error("Unable to read descriptor %s",MPUP_NGLOC);
00107     ngloc = MAXINT;
00108   }
00109   else
00110     print_msg("   Local PSF model: %d component(s)",ABS(ngloc));
00111 
00112   return(ngloc);
00113 }
00114 
00115 /* === Doxygen Comment ======================================= */
00119 /* =========================================================== */
00120 
00121 float read_lbdaref(void *anyfile) 
00122 {
00123   float lbdaref;
00124   
00125   if (DEBUG)
00126     print_msg("Reading ref. wavelength from descriptor %s in file %s...",
00127               MPUP_LBDAPUP,((Anyfile *)anyfile)->name);
00128 
00129   disable_user_warnings();
00130   if (RD_desc(anyfile,MPUP_LBDAPUP,FLOAT,1,&lbdaref) != 1) {
00131     print_error("Cannot read descriptor %s in file %s",
00132                 MPUP_LBDAPUP,((Anyfile *)anyfile)->name);
00133     lbdaref = 0;
00134   }
00135   else
00136     print_msg("   Ref. wavelength: %.2fA",lbdaref);
00137   restore_user_warnings();
00138 
00139   return(lbdaref);
00140 }
00141 
00142 /* === Doxygen Comment ======================================= */
00146 /* =========================================================== */
00147 
00148 Channel read_channel(void *anyfile) 
00149 {
00150   Channel channel;
00151   char name[lg_ident+1];
00152   
00153   if (DEBUG) 
00154     print_msg("Reading channel from descriptor %s in file %s...",
00155               CHANNEL,((Anyfile *)anyfile)->name);
00156 
00157   /* Read string descriptor */
00158   disable_user_warnings();
00159   if (RD_desc(anyfile,CHANNEL,CHAR,lg_ident+1,&name) <= 0) {
00160     print_warning("Cannot read descriptor %s in file %s",
00161                   CHANNEL,((Anyfile *)anyfile)->name);
00162     return(UNKNOWN_CHANNEL);
00163   }
00164   restore_user_warnings();
00165 
00166   /* Decipher descriptor */
00167   switch (toupper(name[0])) {
00168   case '1':                                  /* Back compatibility */
00169   case 'B': channel = BLUE_CHANNEL;    break;
00170   case '2':                                  /* Back compatibility */
00171   case 'R': channel = RED_CHANNEL;     break;
00172   default:  
00173     print_warning("Channel '%s' does not match any channel",name);
00174     return(UNKNOWN_CHANNEL);
00175     break;
00176   }
00177   print_msg("   Channel: '%s' [identified as %s]",name,channel_names[channel]);
00178 
00179   return(channel);
00180 }
00181 
00182 /* === Doxygen Comment ======================================= */
00192 /* =========================================================== */
00193 
00194 int read_focus(void *anyfile) 
00195 {
00196   static int narc=1;                      /* Frame rank in calling sequence */
00197 
00198   Channel channel;
00199   char focdesc[9];
00200   int specfoc;
00201   
00202   /* Read spectrograph position in descriptor */
00203   channel = read_channel(anyfile);
00204   sprintf(focdesc,"%c%s",toupper(channel_names[channel][0]),SPECFOC);
00205 
00206   disable_user_warnings();
00207   if (channel == UNKNOWN_CHANNEL ||
00208       RD_desc(anyfile,focdesc,INT,1,&specfoc) < 0) {
00209     specfoc = -narc;
00210     print_warning("%s descriptor absent from %s: taking %d",
00211                   focdesc,((Anyfile *)anyfile)->name,ABS(specfoc));
00212   } 
00213   else print_msg("   Focus [%s]: %d",focdesc,specfoc);
00214   restore_user_warnings();
00215 
00216   narc ++;
00217   return(specfoc);
00218 }
00219 
00220 /* === Doxygen Comment ======================================= */
00249 /* =========================================================== */
00250 
00251 int read_default_snifs_config(const Channel channel, SnifsConfig *config) 
00252 {
00253   float l1, l2, l1u, l2u;
00254 
00255   SnifsOptics   *Optics = &(config->optics);
00256   Telescope     *UHT    = &(config->telescope);
00257   SnifsDetector *CCD    = &(config->ccd);
00258 
00259   print_msg("Reading default configuration for %s channel...", 
00260             channel_names[channel]);
00261 
00262   /* ===== Channel-independant settings ============================== */
00263 
00264   /* ----- Optics ------------------------------ */
00265 
00266   /* Channel */
00267   Optics->channel = channel;
00268 
00269   /* Enlarger */
00270   Optics->enlarger.gamma = SNIFS_GAMMA;
00271 
00272   /* Grism */
00273   Optics->grism.set   = 1;  
00274   Optics->grism.tiltx = 0.;
00275   Optics->grism.tilty = 0.;
00276   Optics->grism.rotz  = 0.; /* Red is down, blue is up */
00277 
00278   /* MLA */
00279   Optics->MLA.size = SNIFS_LENS_MM;
00280 
00281   /* ----- Telescope ------------------------------ */
00282 
00283   UHT->aperture            = UHT_DIAM;
00284   UHT->central_obscuration = UHT_COBS; 
00285   UHT->fratio              = UHT_FOCR;
00286   UHT->scale               = UHT_SCALE;
00287 
00288   /* ===== Channel-specific settings ============================== */
00289 
00290   switch (channel) {
00291   case BLUE_CHANNEL:
00292     /* Configuration name */
00293     strcpy(config->name,DFLT_BLU_CFG_NAME);
00294 
00295     /* ----- Optics ------------------------------ */
00296 
00297     /* Collimator */
00298     Optics->collimator.focal                = SNIFSB_COLL_F;
00299     Optics->collimator.distor               = SNIFSB_COLL_E;
00300     Optics->collimator.LateralColor.coef[0] = SNIFSB_COLL_A1;
00301     Optics->collimator.LateralColor.coef[1] = SNIFSB_COLL_A2;
00302     Optics->collimator.LateralColor.coef[2] = SNIFSB_COLL_A3;
00303     Optics->collimator.LateralColor.lbdaref = SNIFSB_LBDA_REF;
00304 
00305     /* Grism */
00306     Optics->grism.prism.id   = SNIFSB_GRISM_GLA;
00307     Optics->grism.A          = SNIFSB_GRISM_ANG * M_PI/180.;
00308     Optics->grism.grating.id = SNIFSB_GRISM_RES;
00309     Optics->grism.g_per_mm   = SNIFSB_GRISM_GRA; 
00310     Optics->grism.blaze      = SNIFSB_GRISM_BLA * M_PI/180.;
00311     Optics->grism.w_disp     = SNIFSB_GRISM_D / (CCDB_PIX/1000.); /* A/mm */
00312 
00313     /* Camera parameters */
00314     Optics->camera.focal                = SNIFSB_CAM_F;
00315     Optics->camera.distor               = SNIFSB_CAM_E;
00316     Optics->camera.LateralColor.coef[0] = SNIFSB_CAM_A1;
00317     Optics->camera.LateralColor.coef[1] = SNIFSB_CAM_A2;
00318     Optics->camera.LateralColor.coef[2] = SNIFSB_CAM_A3;
00319     Optics->camera.LateralColor.lbdaref = SNIFSB_LBDA_REF;
00320 
00321     /* MLA */
00322     Optics->MLA.sizepix = SNIFSB_LENS_PX;
00323     Optics->MLA.angle   = SNIFSB_LENS_AN * M_PI/180.;
00324 
00325     /* Filter */
00326     l1  = SNIFSB_FILT_L; l2  = SNIFSB_FILT_H; /* Total coverage  */
00327     l1u = SNIFSB_FILT_S; l2u = SNIFSB_FILT_E; /* Useful coverage */
00328 
00329     /* ----- Detector ------------------------------ */
00330 
00331     strcpy(CCD->name, CCDB_NAME);
00332     CCD->pixsize = CCDB_PIX; /* in microns */
00333     CCD->gain    = CCDB_GAIN;
00334     CCD->ron     = CCDB_RON;
00335     CCD->dark    = 0.;
00336     CCD->nx      = CCDB_NX;
00337     CCD->ny      = CCDB_NY;
00338 
00339     break;
00340 
00341   case RED_CHANNEL:
00342     /* Configuration name */
00343     strcpy(config->name,DFLT_RED_CFG_NAME);
00344 
00345     /* ----- Optics ------------------------------ */
00346 
00347     /* Collimator */
00348     Optics->collimator.focal                = SNIFSR_COLL_F;
00349     Optics->collimator.distor               = SNIFSR_COLL_E;
00350     Optics->collimator.LateralColor.coef[0] = SNIFSR_COLL_A1;
00351     Optics->collimator.LateralColor.coef[1] = SNIFSR_COLL_A2;
00352     Optics->collimator.LateralColor.coef[2] = SNIFSR_COLL_A3;
00353     Optics->collimator.LateralColor.lbdaref = SNIFSR_LBDA_REF;
00354 
00355     /* Grism */
00356     Optics->grism.prism.id   = SNIFSR_GRISM_GLA;
00357     Optics->grism.A          = SNIFSR_GRISM_ANG * M_PI/180.;
00358     Optics->grism.grating.id = SNIFSR_GRISM_RES;
00359     Optics->grism.g_per_mm   = SNIFSR_GRISM_GRA; 
00360     Optics->grism.blaze      = SNIFSR_GRISM_BLA * M_PI/180.;
00361     Optics->grism.w_disp     = SNIFSR_GRISM_D / (CCDR_PIX/1000.); /* A/mm */
00362 
00363     /* Camera parameters */
00364     Optics->camera.focal                = SNIFSR_CAM_F;
00365     Optics->camera.distor               = SNIFSR_CAM_E;
00366     Optics->camera.LateralColor.coef[0] = SNIFSR_CAM_A1;
00367     Optics->camera.LateralColor.coef[1] = SNIFSR_CAM_A2;
00368     Optics->camera.LateralColor.coef[2] = SNIFSR_CAM_A3;
00369     Optics->camera.LateralColor.lbdaref = SNIFSR_LBDA_REF;
00370 
00371     /* MLA */
00372     Optics->MLA.sizepix = SNIFSR_LENS_PX;
00373     Optics->MLA.angle   = SNIFSR_LENS_AN * M_PI/180.;
00374 
00375     /* Filter */
00376     l1  = SNIFSR_FILT_L; l2  = SNIFSR_FILT_H; /* Total coverage  */
00377     l1u = SNIFSR_FILT_S; l2u = SNIFSR_FILT_E; /* Useful coverage */
00378 
00379     /* ----- Detector ------------------------------ */
00380 
00381     strcpy(CCD->name, CCDR_NAME);
00382     CCD->pixsize = CCDR_PIX; /* in microns */
00383     CCD->gain    = CCDR_GAIN;
00384     CCD->ron     = CCDR_RON;
00385     CCD->dark    = 0.;
00386     CCD->nx      = CCDR_NX;
00387     CCD->ny      = CCDR_NY;
00388 
00389     break;
00390 
00391   default:
00392     print_error("Unknown SNIFS spectroscopic channel (%d)",channel);
00393     return(ERR_NOIMPL);
00394     break;
00395   }
00396 
00397   /* ===== Channel-independant settings ][ ============================== */
00398 
00399   /* Filter parameters */
00400   Optics->filter.inf_total    = l1;
00401   Optics->filter.sup_total    = l2;
00402   Optics->filter.central_total= (l1 + l2)/2.;
00403   Optics->filter.width_total  = ABS(l2 - l1);
00404 
00405   Optics->filter.inf_util     = l1u;
00406   Optics->filter.sup_util     = l2u;
00407   Optics->filter.central_util = (l1u + l2u)/2.;
00408   Optics->filter.width_util   = ABS(l2u - l1u);
00409 
00410   /* Grism parameters */
00411   strcpy(Optics->grism.prism.name,material_names[Optics->grism.prism.id]);
00412   Optics->grism.prism.sellcoeffs = 
00413     material_sellcoeffs[Optics->grism.prism.id];
00414 
00415   strcpy(Optics->grism.grating.name,material_names[Optics->grism.grating.id]);
00416   Optics->grism.grating.sellcoeffs = 
00417     material_sellcoeffs[Optics->grism.grating.id];
00418 
00419   /* Set default value for center of distortion */
00420   Optics->center.xc = CCD->nx/2;
00421   Optics->center.yc = CCD->ny/2;
00422 
00423   return(OK);
00424 }
00425 
00426 /* === Doxygen Comment ======================================= */
00430 /* =========================================================== */
00431 
00432 void optics2dval(const SnifsOptics *Optics, double *dval)
00433 {
00434   dval[ 0] = Optics->enlarger.gamma;                   /* Enlarger */
00435   dval[ 1] = Optics->collimator.focal;                 /* Collimator */
00436   dval[ 2] = Optics->collimator.distor;
00437   dval[ 3] = Optics->collimator.LateralColor.coef[0];
00438   dval[ 4] = Optics->collimator.LateralColor.coef[1];
00439   dval[ 5] = Optics->collimator.LateralColor.coef[2];
00440   dval[ 6] = Optics->collimator.LateralColor.lbdaref;
00441   dval[ 7] = Optics->grism.A;                          /* Grism */
00442   dval[ 8] = Optics->grism.g_per_mm;
00443   dval[ 9] = Optics->grism.blaze;
00444   dval[10] = Optics->grism.w_disp;                                 
00445   dval[11] = Optics->grism.tiltx;                                  
00446   dval[12] = Optics->grism.tilty;                                  
00447   dval[13] = Optics->grism.rotz;                                   
00448   dval[14] = Optics->camera.focal;                     /* Camera */
00449   dval[15] = Optics->camera.distor;                                
00450   dval[16] = Optics->camera.LateralColor.coef[0];                  
00451   dval[17] = Optics->camera.LateralColor.coef[1];                  
00452   dval[18] = Optics->camera.LateralColor.coef[2];                  
00453   dval[19] = Optics->camera.LateralColor.lbdaref;                  
00454   dval[20] = Optics->MLA.size;                         /* MLA */   
00455   dval[21] = Optics->MLA.sizepix;                                  
00456   dval[22] = Optics->MLA.angle;                                    
00457   dval[23] = Optics->filter.inf_util;                  /* Filter */
00458   dval[24] = Optics->filter.sup_util;                              
00459   dval[25] = Optics->filter.central_util;                          
00460   dval[26] = Optics->filter.width_util;                            
00461   dval[27] = Optics->filter.inf_total;                             
00462   dval[28] = Optics->filter.sup_total;                             
00463   dval[29] = Optics->filter.central_total;                         
00464   dval[30] = Optics->filter.width_total;                           
00465   dval[31] = Optics->center.xc;                        /* Center */
00466   dval[32] = Optics->center.yc; 
00467 }
00468 
00469 /* === Doxygen Comment ======================================= */
00473 /* =========================================================== */
00474 
00475 void dval2optics(const double dval[], SnifsOptics *Optics)
00476 {
00477   Optics->enlarger.gamma                   = dval[ 0]; /* Enlarger */
00478   Optics->collimator.focal                 = dval[ 1]; /* Collimator */
00479   Optics->collimator.distor                = dval[ 2];
00480   Optics->collimator.LateralColor.coef[0]  = dval[ 3];
00481   Optics->collimator.LateralColor.coef[1]  = dval[ 4];
00482   Optics->collimator.LateralColor.coef[2]  = dval[ 5];
00483   Optics->collimator.LateralColor.lbdaref  = dval[ 6];
00484   Optics->grism.A                          = dval[ 7]; /* Grism */
00485   Optics->grism.g_per_mm                   = dval[ 8];
00486   Optics->grism.blaze                      = dval[ 9];
00487   Optics->grism.w_disp                     = dval[10];
00488   Optics->grism.tiltx                      = dval[11];
00489   Optics->grism.tilty                      = dval[12];
00490   Optics->grism.rotz                       = dval[13];
00491   Optics->camera.focal                     = dval[14]; /* Camera */
00492   Optics->camera.distor                    = dval[15];             
00493   Optics->camera.LateralColor.coef[0]      = dval[16];             
00494   Optics->camera.LateralColor.coef[1]      = dval[17];             
00495   Optics->camera.LateralColor.coef[2]      = dval[18];             
00496   Optics->camera.LateralColor.lbdaref      = dval[19];             
00497   Optics->MLA.size                         = dval[20]; /* MLA */   
00498   Optics->MLA.sizepix                      = dval[21];             
00499   Optics->MLA.angle                        = dval[22];             
00500   Optics->filter.inf_util                  = dval[23]; /* Filter */
00501   Optics->filter.sup_util                  = dval[24];             
00502   Optics->filter.central_util              = dval[25];             
00503   Optics->filter.width_util                = dval[26];             
00504   Optics->filter.inf_total                 = dval[27];             
00505   Optics->filter.sup_total                 = dval[28];             
00506   Optics->filter.central_total             = dval[29];             
00507   Optics->filter.width_total               = dval[30];             
00508   Optics->center.xc                        = dval[31]; /* Center */
00509   Optics->center.yc                        = dval[32];
00510 }
00511 
00512 /* === Doxygen Comment ======================================= */
00524 /* =========================================================== */
00525 
00526 int write_snifs_config_to_mask(TABLE *mask, SnifsConfig *config)
00527 {
00528 #define ERROR_DESC(s) \
00529   print_error("Unable to write configuration to mask '%s' "\
00530               "(desc. '%s')",mask->name,s); return(ERR_BAD_DESC)
00531 
00532   char back, oldname[lg_ident+1];
00533   int ival[3];
00534   float fval[3];
00535   double dval[33];
00536 
00537   SnifsOptics   *Optics = &(config->optics);
00538   Telescope     *UHT    = &(config->telescope);
00539   SnifsDetector *CCD    = &(config->ccd);
00540 
00541   print_msg("Writing configuration '%s' to mask '%s'...",
00542             config->name,mask->name);
00543 
00544   set_control_level(NONE);
00545   if (RD_desc(mask,CONFIG_NAME,CHAR,lg_ident,oldname) > 0 &&
00546       strcmp(oldname,DFLT_BLU_CFG_NAME) &&
00547       strcmp(oldname,DFLT_RED_CFG_NAME) ) {
00548     /* There's already a non-default configuration stored, ask confirmation */
00549     print_warning("Configuration '%s' is already stored in mask %s",
00550                   oldname,mask->name);
00551     if (ASK) {
00552       printf("   Overwrite it? [Y/N] ");
00553       back = getchar();
00554       if (back == 'N' || back=='n') {
00555         print_warning("Original configuration '%s' will not be overwritten!",
00556                       oldname);
00557         return(OK);
00558       }
00559     }
00560     print_warning("Overwriting configuration '%s'",oldname);
00561   }
00562   set_control_level(FATAL);
00563 
00564   /* Channel & Config Name */
00565   //  if (WR_desc(mask, CHANNEL, INT, 1, &(Optics->channel))) { 
00566   if (WR_desc(mask, CHANNEL, CHAR, lg_ident+1, channel_names[Optics->channel])) { 
00567     ERROR_DESC(CHANNEL); 
00568   }
00569   if (WR_desc(mask, CONFIG_NAME,CHAR,lg_ident,config->name)) { 
00570     ERROR_DESC(CONFIG_NAME); 
00571   }
00572 
00573   /* Optics parameters (DOUBLE) */
00574   optics2dval(Optics,dval);
00575   if (WR_desc(mask,MSK_DOPTPAR, DOUBLE, 33, dval)) { 
00576     ERROR_DESC(MSK_DOPTPAR); 
00577   }
00578 
00579   /* Optics parameters (INT) */
00580   ival[0] = Optics->grism.set;
00581   ival[1] = Optics->grism.prism.id;
00582   ival[2] = Optics->grism.grating.id;
00583   if (WR_desc(mask,MSK_IOPTPAR, LONG, 3, ival)) { 
00584     ERROR_DESC(MSK_IOPTPAR);
00585   }
00586 
00587   /* Telescope parameters */
00588   dval[0] = UHT->aperture;
00589   dval[1] = UHT->central_obscuration;
00590   dval[2] = UHT->scale;
00591   if (WR_desc(mask,MSK_DTELPAR, DOUBLE, 3, dval)) { 
00592     ERROR_DESC(MSK_DTELPAR); 
00593   }
00594 
00595   fval[0] = UHT->fratio;
00596   if (WR_desc(mask,MSK_FTELPAR, FLOAT, 1, fval)) { 
00597     ERROR_DESC(MSK_FTELPAR);
00598   }
00599 
00600   /* Detector parameters */
00601   if (WR_desc(mask,CCD_NAME, CHAR, lg_ident, CCD->name)) { 
00602     ERROR_DESC(CCD_NAME);
00603   }
00604 
00605   ival[0] = CCD->nx;
00606   ival[1] = CCD->ny;
00607   if (WR_desc(mask,MSK_ICCDPAR, LONG, 2, ival)) { 
00608     ERROR_DESC(MSK_ICCDPAR); 
00609   }
00610 
00611   fval[0] = CCD->pixsize;
00612   if (WR_desc(mask,MSK_FCCDPAR, FLOAT, 1, fval)) { 
00613     ERROR_DESC(MSK_FCCDPAR);
00614   }
00615 
00616   dval[0] = CCD->gain;
00617   dval[1] = CCD->ron;
00618   dval[2] = CCD->dark;
00619   if (WR_desc(mask,MSK_DCCDPAR, DOUBLE, 3, dval)) { 
00620     ERROR_DESC(MSK_DCCDPAR);
00621   }
00622 
00623   return(OK);
00624 
00625 #undef ERROR_DESC
00626 }
00627 
00628 /* === Doxygen Comment ======================================= */
00636 /* =========================================================== */
00637 
00638 int read_snifs_config_from_mask(TABLE *mask, SnifsConfig *config)
00639 {
00640 #define ERROR_DESC(s) \
00641   print_error("Unable to read configuration from mask '%s' "\
00642               "(desc. '%s' missing)",mask->name,s); return(ERR_NODESC)
00643 
00644   long ival[5];
00645   float fval[3];
00646   double dval[33];
00647 
00648   SnifsOptics   *Optics = &(config->optics);
00649   Telescope     *UHT    = &(config->telescope);
00650   SnifsDetector *CCD    = &(config->ccd);
00651 
00652   print_msg("Reading configuration from mask '%s'...",mask->name);
00653 
00654   /* Config Name & Channel */
00655   set_control_level(NONE);
00656   if (RD_desc(mask,CONFIG_NAME,CHAR,lg_ident,config->name) <= 0) {
00657     print_error("Unable to read configuration from mask, try option -default",
00658                 mask->name); 
00659     return(ERR_NODESC);
00660   }
00661   else 
00662     print_msg("   Configuration '%s' found",config->name); 
00663   set_control_level(FATAL);
00664 
00665 //  if (RD_desc(mask,CHANNEL,INT,1,&(Optics->channel)) <= 0) { 
00666 //    ERROR_DESC(CHANNEL);
00667 //  }
00668   if (!(Optics->channel=read_channel(mask))) return(ERR_NODESC);
00669 
00670   /* Optics parameters (DOUBLE) */
00671   if (RD_desc(mask,MSK_DOPTPAR,DOUBLE,33,dval) != 33) { 
00672     ERROR_DESC(MSK_DOPTPAR); 
00673   }
00674   dval2optics(dval,Optics); 
00675 
00676   /* Optics parameters (INT) */
00677   if (RD_desc(mask,MSK_IOPTPAR, LONG, 3, ival) != 3) { 
00678     ERROR_DESC(MSK_IOPTPAR); 
00679   }
00680   Optics->grism.set        = ival[0];
00681   Optics->grism.prism.id   = ival[1];
00682   strcpy(Optics->grism.prism.name,material_names[Optics->grism.prism.id]);
00683   Optics->grism.prism.sellcoeffs = 
00684     material_sellcoeffs[Optics->grism.prism.id];
00685   Optics->grism.grating.id = ival[2];
00686   strcpy(Optics->grism.grating.name,material_names[Optics->grism.grating.id]);
00687   Optics->grism.grating.sellcoeffs = 
00688     material_sellcoeffs[Optics->grism.grating.id];
00689 
00690   /* Telescope parameters (DOUBLE) */
00691   if (RD_desc(mask,MSK_DTELPAR,DOUBLE,3,dval) != 3) { 
00692     ERROR_DESC(MSK_DTELPAR); 
00693   } 
00694   UHT->aperture            = dval[0];
00695   UHT->central_obscuration = dval[1];
00696   UHT->scale               = dval[2];
00697 
00698   if (RD_desc(mask,MSK_FTELPAR, FLOAT, 1, fval) != 1) { 
00699     ERROR_DESC(MSK_FTELPAR);
00700   }
00701   UHT->fratio = fval[0];
00702 
00703   /* Detector parameters */
00704   if (RD_desc(mask,CCD_NAME,CHAR,lg_ident,CCD->name) <= 0) {
00705     ERROR_DESC(CCD_NAME);
00706   }
00707 
00708   if (RD_desc(mask,MSK_ICCDPAR, LONG, 2, ival) != 2) { 
00709     ERROR_DESC(MSK_ICCDPAR);
00710   } 
00711   CCD->nx = ival[0];
00712   CCD->ny = ival[1];
00713 
00714   if (RD_desc(mask,MSK_FCCDPAR, FLOAT, 1, fval) !=1 ) { 
00715     ERROR_DESC(MSK_FCCDPAR); 
00716   }
00717   CCD->pixsize = fval[0];
00718 
00719   if (RD_desc(mask,MSK_DCCDPAR,DOUBLE,3,dval) != 3) { 
00720     ERROR_DESC(MSK_DCCDPAR); 
00721   } 
00722   CCD->gain = dval[0];
00723   CCD->ron  = dval[1];
00724   CCD->dark = dval[2];
00725 
00726   return(OK);
00727 
00728 #undef ERROR_DESC
00729 }
00730 
00731 /* === Doxygen Comment ======================================= */
00735 /* =========================================================== */
00736 
00737 void print_snifs_optics(const SnifsOptics *Optics)
00738 {  
00739   print_msg("Channel: %s", channel_names[Optics->channel]);
00740 
00741   print_msg("Enlarger: gamma = %.2f", Optics->enlarger.gamma);
00742 
00743   print_msg("Collimator:\n"
00744             "   Focal length = %.1f mm, Distortion parameter = %g\n"
00745             "   Lateral color [%.1f A] = %g,%g,%g",
00746             Optics->collimator.focal, 
00747             Optics->collimator.distor,
00748             Optics->collimator.LateralColor.lbdaref,
00749             Optics->collimator.LateralColor.coef[0],
00750             Optics->collimator.LateralColor.coef[1],
00751             Optics->collimator.LateralColor.coef[2]);
00752 
00753   print_msg("Grism:\n"
00754             "   Prism:   Glass = %s, Angle = %.2f deg\n"
00755             "   Grating: Glass = %s, Lines/mm = %.1f, Blaze = %.2f deg\n"
00756             "   Tilts [deg]: ax = %.2f, ay = %.2f, az = %.2f\n"
00757             "   Dispersion = %.2f A/mm",
00758             Optics->grism.prism.name, Optics->grism.A*180./M_PI,
00759             Optics->grism.grating.name, Optics->grism.g_per_mm, 
00760             Optics->grism.blaze*180./M_PI,
00761             Optics->grism.tiltx*180./M_PI, 
00762             Optics->grism.tilty*180./M_PI,
00763             Optics->grism.rotz*180./M_PI,
00764             Optics->grism.w_disp);
00765 
00766   print_msg("Camera:\n"
00767             "   Focal length = %.1f mm, Distortion parameter = %g\n"
00768             "   Lateral color [%.1f A] = %g,%g,%g",
00769             Optics->camera.focal, 
00770             Optics->camera.distor,
00771             Optics->camera.LateralColor.lbdaref,
00772             Optics->camera.LateralColor.coef[0],
00773             Optics->camera.LateralColor.coef[1],
00774             Optics->camera.LateralColor.coef[2]);
00775 
00776   print_msg("MLA: Lens size = %.2f mm", Optics->MLA.size);
00777 
00778   print_msg("Filter wavelength range (A):\n"
00779             "   Total = %.1f - %.1f, Useful = %.1f - %.1f",
00780             Optics->filter.inf_total, Optics->filter.sup_total, 
00781             Optics->filter.inf_util, Optics->filter.sup_util);
00782 }
00783 
00784 /* === Doxygen Comment ======================================= */
00788 /* =========================================================== */
00789 
00790 void print_snifs_telescope(const Telescope *UHT)
00791 {
00792   print_msg("Telescope aperture: %.1f mm, Central obscuration: %.1f mm", 
00793             UHT->aperture, UHT->central_obscuration);
00794   print_msg("Telescope f-ratio: %.2f", UHT->fratio);
00795   print_msg("Telescope scale: %.1f micron/arcsec", UHT->scale);
00796 }
00797 
00798 /* === Doxygen Comment ======================================= */
00802 /* =========================================================== */
00803 
00804 void print_snifs_detector(const SnifsDetector *CCD)
00805 {
00806   print_msg("CCD %s (default values):\n"
00807             "   Format = %dx%d pixels of %.1f microns\n"
00808             "   Gain = %.1f e-/ADU, RoN = %.1f e-, Dark = %.1f e-/h",
00809             CCD->name,CCD->nx,CCD->ny,CCD->pixsize,
00810             CCD->gain,CCD->ron,CCD->dark);
00811 } 
00812 
00813 /* === Doxygen Comment ======================================= */
00817 /* =========================================================== */
00818 
00819 void print_snifs_config(const SnifsConfig *config)
00820 {
00821   print_msg("\n===== Configuration ==============================");
00822   print_msg("Configuration name: '%s'", config->name);
00823   print_msg("----- OPTICS -------------------------------------");
00824   print_snifs_optics(&(config->optics));
00825   print_msg("----- TELESCOPE ----------------------------------");
00826   print_snifs_telescope(&(config->telescope));
00827   print_msg("----- CCD ----------------------------------------");
00828   print_snifs_detector(&(config->ccd));
00829   print_msg("==================================================\n");
00830 }
00831 
00832 /* 
00833 ;;; Local Variables: ***
00834 ;;; eval: (add-to-list 'c-font-lock-extra-types "Channel") ***
00835 ;;; eval: (add-to-list 'c-font-lock-extra-types "SnifsConfig") ***
00836 ;;; End: ***
00837 */

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