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

extract/lib/proc_spectra.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 /* === Doxygen Comment ======================================= */
00028 /* =========================================================== */
00029 
00030 int read_spectra_refcoord(TABLE *mask, SpectrumCCD spectra[])
00031 {
00032   int i,nlens, colno, colx, coly, coli, colj;
00033   int *no, *I, *J;
00034   float *x, *y;
00035   
00036   if ((colno = get_col_ref(mask,LAB_COL_NO))  < 0 || 
00037       (colx  = get_col_ref(mask,LAB_COL_XLD)) < 0 || 
00038       (coly  = get_col_ref(mask,LAB_COL_YLD)) < 0 || 
00039       (coli  = get_col_ref(mask,LAB_COL_I))   < 0 || 
00040       (colj  = get_col_ref(mask,LAB_COL_J))   < 0) {
00041     print_error("Cannot read reference coordinates columns from mask");
00042     return(ERR_BAD_COL);
00043   }
00044 
00045   nlens = mask->row;
00046 
00047   no=   (int *)malloc(nlens*sizeof(int));
00048   x = (float *)malloc(nlens*sizeof(float));
00049   y = (float *)malloc(nlens*sizeof(float));
00050   I =   (int *)malloc(nlens*sizeof(int));
00051   J =   (int *)malloc(nlens*sizeof(int));
00052 
00053   RD_col(mask,colno,no);
00054   RD_col(mask,colx, x);
00055   RD_col(mask,coly, y);
00056   RD_col(mask,coli, I);
00057   RD_col(mask,colj, J);
00058 
00059   /* Transfer to spectra array */
00060   for (i=0; i<nlens; i++) {
00061     spectra[i].no  = no[i];
00062     spectra[i].xref= x[i];
00063     spectra[i].yref= y[i];
00064     spectra[i].I   = I[i];
00065     spectra[i].J   = J[i];    
00066   }
00067 
00068   free(no); free(x); free(y); free(I); free(J);
00069 
00070   return(OK);
00071 }
00072 
00073 /* === Doxygen Comment ======================================= */
00084 /* =========================================================== */
00085 
00086 int read_spectra_chromatic_model(TABLE *mask, int flag, SpectrumCCD spectra[])
00087 {
00088   char tmpname[lg_ident+1], desc[lg_label], pref[lg_label+1];
00089   int nc;                 /* Nb of coefficients in local adjustment */
00090   int i,j, col, nlens;
00091   float *farr;
00092 
00093   switch(flag) {
00094   case 1: 
00095     print_msg("Reading local adjustment to mask positions..."); 
00096     strcpy(desc,MSK_DXNC);
00097     strcpy(pref,"DX");
00098     break;
00099   case 2:
00100     print_msg("Reading cross-dispersion chromatic model from max analysis...");
00101     strcpy(desc,MSK_SIGNC);
00102     strcpy(pref,"SIG");
00103     break;
00104   default:
00105     print_error("What are you talking about?...");
00106     return(ERR_NOIMPL);
00107   }
00108 
00109   if (RD_desc(mask,desc,INT,1,&nc) < 0) {
00110     print_error("Cannot read descriptor %s in mask",desc);
00111     return(ERR_NODESC);
00112   }
00113   print_msg("   %s(lambda): %d coefficients",pref,nc);
00114 
00115   if (nc <= 0) {
00116     print_error("Invalid number of coefficients");
00117     return(ERR_BAD_SIZE);
00118   }
00119 
00120   nlens = mask->row;
00121   farr = (float *)malloc(nlens*sizeof(float)); /* Temporary float array */
00122   switch(flag) {
00123   case 1:
00124     for (j=0; j<nlens; j++) {
00125       spectra[j].dx.ncoeff = nc;
00126       spectra[j].dx.coeff = (double *)malloc(nc*sizeof(double));
00127     }
00128     break;
00129   case 2:
00130     for (j=0; j<nlens; j++) {
00131       spectra[j].sig.ncoeff = nc;
00132       spectra[j].sig.coeff = (double *)malloc(nc*sizeof(double));
00133     }
00134     break;
00135   }
00136   
00137   for (i=0; i<nc; i++) {                     /* xx0,xx1,... columns */
00138     sprintf(tmpname,"%s%d",pref,i);
00139     if ((col = get_col_ref(mask,tmpname)) < 0) {
00140       print_error("Cannot read column %s from mask",tmpname);
00141       return(ERR_BAD_COL);
00142     }
00143     RD_col(mask,col,farr);                   /* Read the float column */
00144     switch(flag) {
00145     case 1:
00146       for (j=0; j<nlens; j++) spectra[j].dx.coeff[i] = farr[j];
00147       break;
00148     case 2:
00149       for (j=0; j<nlens; j++) spectra[j].sig.coeff[i] = farr[j];
00150       break;
00151     }
00152   }
00153   free(farr);
00154 
00155   return(nc);
00156 }
00157 

Generated on Wed Oct 26 23:59:39 2005 for Snifs by doxygen 1.3.5