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

extract/lib/io.c

Go to the documentation of this file.
00001 /* === Doxygen Comment ======================================= */
00013 /* =========================================================== */
00014 
00015 #include <IFU_io.h>
00016 #include <IFU_math.h>
00017 
00018 #include <data_io.h>
00019 extern IO_Format InputIO, OutputIO;
00020 
00021 /* === Doxygen Comment ======================================= */
00038 /* =========================================================== */
00039 
00040 int get_lenses_col(E3D_file *frame, char *lab_col, void *zlens, int *il)
00041 {
00042   E3Dspec_desc *pt_spec = NULL;
00043   TABLE tbl_lens;
00044 
00045   char errtext[132], table_name[lg_name+1], format[20], unit[lg_unit+1];
00046 
00047   int status=0, found=1;
00048   int i,k, col_no, col_z, specId, dtype;
00049 
00050   if (frame->signal != NULL) pt_spec = frame->signal;
00051   else {
00052     if (frame->noise != NULL) pt_spec = frame->noise;
00053   }
00054   strcpy(table_name,frame->table_name);
00055   append_tbl_extension(table_name,InputIO.basic_io);
00056 
00057   status = open_table(&tbl_lens,table_name,"I");
00058   if (!status) {
00059     col_no = get_col_ref(&tbl_lens,E3D_COL_ID);
00060     col_z  = get_col_ref(&tbl_lens,lab_col);
00061     if (col_no < 0 || col_z < 0) {
00062       status = ERR_NOCOL;
00063       sprintf(errtext,"get_ID_and_column");
00064       Handle_Error(errtext,status);
00065       return(status);
00066     }
00067     if (pt_spec == NULL) {
00068       RD_col(&tbl_lens,col_z,zlens);
00069       for (i=0; i<tbl_lens.row; i++) il[i] = i;
00070     }
00071     else {
00072       get_col_info(&tbl_lens, col_z, &dtype, format, unit);     
00073       for (i=0; i<frame->nbspec && found; i++) {
00074         specId = pt_spec[i].specId;
00075         k = search_in_col(&tbl_lens,col_no,&specId);
00076         if (k < 0) {
00077           found = 0;
00078           status = ERR_NODATA;
00079         }
00080         else {
00081           switch (dtype) {
00082           case CHAR  : RD_tbl(&tbl_lens,k,col_z,((char*)zlens)+i);  break;
00083           case SHORT : RD_tbl(&tbl_lens,k,col_z,((short*)zlens)+i); break;
00084           case INT   : 
00085           case LONG  : RD_tbl(&tbl_lens,k,col_z,((int*)zlens)+i);   break;
00086           case FLOAT : RD_tbl(&tbl_lens,k,col_z,((float*)zlens)+i); break;
00087           case DOUBLE: RD_tbl(&tbl_lens,k,col_z,((double*)zlens)+i);break;
00088           }
00089           il[i] = k;
00090         }
00091       }
00092     }
00093     close_table(&tbl_lens);
00094   }
00095 
00096   if (status) {
00097     sprintf(errtext,"get_lenses_coord");
00098     Handle_Error(errtext,status);
00099   }
00100 
00101   return(status);
00102 }
00103 
00104 /* === Doxygen Comment ======================================= */
00118 /* =========================================================== */
00119 
00120 double RD_frame_interp(IMAGE2D *frame, double x,double y)
00121 {
00122   int i,j, in,jn;
00123   double xpx,ypx, dx,dy, dxn,dyn, I;  
00124 
00125   /* Coordinates [px] */
00126   xpx = (x - frame->startx)/frame->stepx; /* in [-0.5,nx-0.5] */
00127   ypx = (y - frame->starty)/frame->stepy;
00128 
00129   /* Pixel indices */
00130   i = (int)xpx + 0.5;                     /* in <0,nx-1> */
00131   j = (int)ypx + 0.5;
00132 
00133   /* Outside? */
00134   if (i<0 || i>(frame->nx-1) || j<0 || j>(frame->ny-1)) return(MAXDOUBLE);
00135 
00136   /* Offset from pixel center [px] */
00137   dx = (xpx - i);                         /* in [-0.5,0.5] */ 
00138   dy = (ypx - j);  
00139 
00140   /* Closest neighbor X-index */
00141   in = i + ((dx>0)? 1:-1);                /* neighbor index */
00142   dx = ABS(dx);                           /* in [0,0.5] */
00143   if (in<0 || in>(frame->nx-1)) {
00144     dxn = 0; /* no extrapolation: outside = 0 */
00145     in  = 0; /* anywhere inside */
00146   }
00147   else dxn = dx;                          /* neighbor contribution */ 
00148 
00149   /* Closest neighbor Y-index */
00150   jn = j + ((dy>=0)? 1:-1);
00151   dy = ABS(dy);
00152   if (jn<0 || jn>(frame->ny-1)) {
00153     dyn = 0;
00154     jn  = 0;
00155   }
00156   else dyn = dy;
00157 
00158   /* Total intensity */
00159   I = (1-dx)*(1-dy)*RD_frame(frame,i, j)
00160     +    dxn*(1-dy)*RD_frame(frame,in,j) 
00161     + (1-dx)*dyn   *RD_frame(frame,i ,jn) 
00162     +    dxn*dyn   *RD_frame(frame,in,jn);
00163 
00164   return(I);
00165 }
00166 

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