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

extract/lib/dump.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 /* === Doxygen Comment ======================================= */
00029 /* =========================================================== */
00030 
00031 int dump_spec_mem(SPECTRUM *spectrum, char *name, char *ident, char *unit, 
00032                   int fclass)
00033 {
00034   SPECTRUM tmp;
00035   int status=0;
00036 
00037   /* Creation of the disk spectrum according to the memory spectrum 
00038      specifications */
00039   status = create_spec(&tmp, name, spectrum->npts, spectrum->start, 
00040                        spectrum->step, spectrum->data_type, ident, unit);
00041   if (status) print_warning("Unable to dump spectrum %s to disk...", name);
00042   else {
00043     /* Copy of the spectrum content */
00044     memcpy(tmp.data.d_data, spectrum->data.d_data, 
00045            sizeof_item(spectrum->data_type)*spectrum->npts);
00046     /* Write the file class */
00047     write_file_class(&tmp, fclass);
00048     /* Close the disk spectrum */
00049     status = close_spec(&tmp);
00050     if (status) print_warning("Unable to close disk spectrum %s...", name);
00051   }
00052   return(status);
00053 }
00054 
00055 /* === Doxygen Comment ======================================= */
00074 /* =========================================================== */
00075 
00076 void put_tiger_arrays(TIGERfile *frame, int no_lens, 
00077                       void *signal, void *noise, int data_type, 
00078                       int npix, double start)
00079 {
00080   int i;
00081   SPECTRUM sp_signal, sp_noise;
00082 
00083   if (signal != NULL) { /* Store signal array if any */
00084     init_new_tiger_spec(frame,&sp_signal,npix,start);
00085     switch (data_type) {
00086     case SHORT : 
00087       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((short *)signal)[i]); break; 
00088     case LONG  :
00089     case INT   : 
00090       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((int *)signal)[i]);   break; 
00091     case FLOAT : 
00092       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((float *)signal)[i]); break; 
00093     case DOUBLE: 
00094       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((double *)signal)[i]);break; 
00095     }
00096   }
00097 
00098   if (noise != NULL) { /* Store noise array if any */
00099     init_new_tiger_spec(frame,&sp_noise,npix,start);
00100     switch (data_type) {
00101     case SHORT : 
00102       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((short *)noise)[i]);  break; 
00103     case LONG  :
00104     case INT   : 
00105       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((int *)noise)[i]);    break; 
00106     case FLOAT : 
00107       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((float *)noise)[i]);  break; 
00108     case DOUBLE: 
00109       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((double *)noise)[i]); break; 
00110     }
00111   }
00112   
00113   if (signal != NULL && noise != NULL)
00114     put_tiger_spec(frame,&sp_signal,&sp_noise,no_lens);
00115   else if (signal != NULL)
00116     put_tiger_spec(frame,&sp_signal,NULL,no_lens);
00117   else if (noise != NULL)
00118     put_tiger_spec(frame,NULL,&sp_noise,no_lens);
00119   else
00120     print_error("put_tiger_arrays (%s:%d): at least *one* of the arrays "
00121                 "should be non-NULL!",__FILE__,__LINE__);
00122 }
00123 
00124 /* === Doxygen Comment ======================================= */
00139 /* =========================================================== */
00140 
00141 int dump_2Darray(void **array, int data_type, int npix[], char *name)
00142 {
00143   IMAGE2D frame;
00144   int i,j, status;
00145   double start[2]={0,0}, step[2]={1,1};
00146 
00147   status = create_frame(&frame,name,npix,start,step,data_type,"","");
00148   switch (data_type) {
00149   case SHORT : 
00150     for (i=0;i<npix[0];i++) 
00151       for (j=0;j<npix[1];j++) 
00152         WR_frame(&frame, i, j, ((short **)array)[i][j]); break;
00153   case LONG  :
00154   case INT   : 
00155     for (i=0;i<npix[0];i++) 
00156       for (j=0;j<npix[1];j++) 
00157         WR_frame(&frame, i, j, ((int **)array)[i][j]); break;
00158   case FLOAT : 
00159     for (i=0;i<npix[0];i++) 
00160       for (j=0;j<npix[1];j++) 
00161         WR_frame(&frame, i, j, ((float **)array)[i][j]); break;
00162   case DOUBLE: 
00163     for (i=0;i<npix[0];i++) 
00164       for (j=0;j<npix[1];j++) 
00165         WR_frame(&frame, i, j, ((double **)array)[i][j]); break;
00166   }
00167   write_file_class(&frame,DEBUG_FILE); 
00168   close_frame(&frame);
00169 
00170   return(status);
00171 }

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