Main Page   Modules   Data Structures   File List   Data Fields   Globals  

C_libs/io/std_io/convert.c

Go to the documentation of this file.
00001 /* === Doxygen File Comment ============================== */
00010 /* ======================================================= */
00011 
00012 #include <IFU_io.h>
00013 #include <data_io.h>
00014 
00015 /* --- Doxygen Function Comment -------------------------- */
00019                 /* @{ ***** Starting group13 ***** */
00027 /* ------------------------------------------------------- */
00028 
00029 void copy_col(TABLE *src,TABLE *dst,int col)
00030 {
00031   char name[20];
00032   int type;
00033   char format[20];
00034   char unit[20];
00035   int id,i;
00036   
00037   get_col_name(src,col,name);
00038 
00039   get_col_info(src,col,&type,format,unit);
00040   
00041   id = create_col(dst,name,(short)type,'N',format,unit);
00042 
00043   switch(type)
00044     {
00045     case SHORT:
00046       {
00047         short value;
00048 
00049         for(i=0;i<src->row;i++)
00050           {
00051             RD_tbl(src,i,col,&value);
00052             WR_tbl(dst,i,id,&value);
00053           }
00054         
00055         break;
00056       }
00057     case INT:
00058       {
00059         int value;
00060         
00061         for(i=0;i<src->row;i++)
00062           {
00063             RD_tbl(src,i,col,&value);
00064             WR_tbl(dst,i,id,&value);
00065           }
00066         
00067         break;
00068       }
00069     case LONG:
00070       {
00071         long value;
00072         
00073         for(i=0;i<src->row;i++)
00074           {
00075             RD_tbl(src,i,col,&value);
00076             WR_tbl(dst,i,id,&value);
00077           }
00078 
00079         break;
00080       }
00081     case FLOAT:
00082       {
00083         float value;
00084         
00085         for(i=0;i<src->row;i++)
00086           {
00087             RD_tbl(src,i,col,&value);
00088             WR_tbl(dst,i,id,&value);
00089           }
00090 
00091         break;
00092       }
00093     case DOUBLE:
00094       {
00095         double value;
00096         
00097         for(i=0;i<src->row;i++)
00098           {
00099             RD_tbl(src,i,col,&value);
00100             WR_tbl(dst,i,id,&value);
00101           }
00102 
00103         break;
00104       }
00105     }
00106 }
00107 
00108 /* --- Doxygen Function Comment -------------------------- */
00115 /* ------------------------------------------------------- */
00116 
00117 void convert_spec(char *in,char *out)
00118 {
00119   SPECTRUM src,dst;
00120 
00121   if(open_spec(&src,in,"I")<0) {
00122     print_error("Cannot open the input file");
00123     exit_session(-1);
00124   }
00125   else
00126     if(create_spec(&dst,out,src.npts,src.start,src.step,src.data_type,
00127                    src.ident,src.cunit)<0) {
00128       close_spec(&src);
00129       print_error("Cannot create the output file");
00130       exit_session(-1);
00131     }
00132     else {
00133       int i;
00134 
00135       for(i=0;i<src.npts;i++)
00136         WR_spec(&dst,i,RD_spec(&src,i));
00137 
00138       CP_non_std_desc(&src,&dst);
00139       close_spec(&dst);
00140       close_spec(&src);
00141     }
00142 }
00143 
00144 /* --- Doxygen Function Comment -------------------------- */
00151 /* ------------------------------------------------------- */
00152 
00153 void convert_table(char *in,char *out)
00154 {
00155   TABLE src,dst;
00156   int i;
00157 
00158   if(open_table(&src,in,"I")<0)
00159     {
00160       print_error("Cannot open the input file");
00161       exit_session(-1);
00162     }
00163   else
00164         handle_select_flag(&src,'Q',NULL);
00165 
00166     if(create_table(&dst,out,src.row,src.col,'W',src.ident)<0)
00167       {
00168         close_table(&src);
00169         print_error("Cannot create the output file");
00170         exit_session(-1);
00171       }
00172     else
00173       {
00174         print_progress("", 0, -1);
00175         for(i=1;i<=src.col;i++) {
00176           print_progress("Convert table: ", (int)((100*i)/src.col),1);
00177           copy_col(&src,&dst,i);
00178         }
00179         
00180         CP_non_std_desc(&src,&dst);
00181         
00182         close_table(&dst);
00183         close_table(&src);
00184       }
00185 }
00186 
00187 
00188 /* --- Doxygen Function Comment -------------------------- */
00195 /* ------------------------------------------------------- */
00196 
00197 void convert_image(char *in,char *out)
00198 {
00199   IMAGE2D src,dst;
00200   int npix[2];
00201   double start[2],step[2];
00202 
00203   if(open_frame(&src,in,"I")<0)
00204     {
00205       print_error("Cannot open the input file");
00206       exit_session(-1);
00207     }
00208   else
00209     {
00210       npix[0]=src.nx;
00211       npix[1]=src.ny;
00212       start[0]=src.startx;
00213       start[1]=src.starty;
00214       step[0]=src.stepx;
00215       step[1]=src.stepy;
00216 
00217       if(create_frame(&dst,out,npix,start,step,src.data_type,src.ident,src.cunit)<0)
00218         {
00219           close_frame(&src);
00220           print_error("Cannot create the output file");
00221           exit_session(-1);
00222         }
00223       else
00224         {
00225           int i,j;
00226 
00227           for(i=0;i<src.nx;i++)
00228             for(j=0;j<src.ny;j++)
00229               WR_frame(&dst,i,j,RD_frame(&src,i,j));
00230           
00231           CP_non_std_desc(&src,&dst);
00232 
00233           close_frame(&dst);
00234           close_frame(&src);
00235         }
00236     }
00237         printf("\n");
00238 }
00239 
00240 /* --- Doxygen Function Comment -------------------------- */
00247 /* ------------------------------------------------------- */
00248 
00249 void convert_datacube(char *in,char *out)
00250 {
00251   E3D_file src,dst;
00252   SPECTRUM sig, noise, *rms, *signal;
00253   SPAXEL *spaxels;
00254   E3Dspec_desc *ptdesc;
00255   int i, specId, nbspax;
00256   char extname[lg_name+1], tablename[lg_name+1];
00257 
00258   if(open_E3D_file(&src,in,"I")<0)
00259     {
00260       print_error("Cannot open the input file");
00261       exit_session(ERR_OPEN);
00262     }
00263   else
00264     {
00265         if (create_E3D_file(&dst,out,-1,-1,src.step,src.data_type,src.ident,src.cunit) < 0) {
00266           close_E3D_file(&src);
00267           print_error("Cannot create the output file");
00268           exit_session(ERR_CREAT);
00269         }
00270         else {
00271                 signal = NULL;
00272                 rms = NULL;
00273                 ptdesc = NULL;
00274                 if (src.signal != NULL) {
00275                         signal = &sig;
00276                         ptdesc = src.signal;
00277                 } else {
00278                         if (src.noise != NULL) {
00279                                 rms = &noise;
00280                                 ptdesc = src.noise;
00281                         }
00282                         else {
00283                                 close_E3D_file(&src);
00284                                 print_error("Inconsistant input file (no spectra inside)");
00285                                 exit_session(ERR_BAD_PARAM);
00286                         }
00287                 }
00288 
00289                 print_progress("", 0, -1);
00290                 for(i=0;i<src.nbspec;i++) {
00291                         print_progress("Convert datacube: ", (int)((100*i)/src.nbspec),1);
00292                         specId = ptdesc[i].specId;
00293                         get_E3D_spec(&src,signal,rms,specId);
00294                         put_E3D_spec(&dst,signal,rms,specId);
00295                         nbspax = get_E3D_spaxels(&src,specId,&spaxels);
00296                         put_E3D_spaxels(&dst,specId,nbspax,spaxels);
00297                 }
00298                 put_E3D_groups(&dst,src.ngroups,src.groups);
00299                 print_progress("Convert datacube: ", (int)100,1);
00300           
00301                 CP_non_std_desc(&src,&dst);
00302 
00303                 close_E3D_file(&dst);
00304                 close_E3D_file(&src);
00305 
00306                 printf("\n");
00307 
00308                 if (src.data_format == TIGER_FORMAT) {  /* save table in special extension */
00309                         get_assoc_table_name(in,tablename);
00310                         sprintf(extname,"%s[%s]",out,E3D_TIGER_EXT);
00311                         convert_table(tablename,extname);
00312                 }
00313         }
00314     }
00315 }
00316 
00317 

Generated on Tue Jul 1 17:35:44 2003 for IFU_C_iolibs by doxygen1.3