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 int dump_dbgArray(void *array, int type, int npts, char *dbgname, 
00019                   SPECTRUM *refspec)
00020 {
00021   SPECTRUM dbgspec;
00022   int i;
00023 
00024   if (npts != refspec->npts) 
00025     print_warning("Input array and ref. spectrum have diff. lengthes (%d/%d)",
00026                   npts, refspec->npts);
00027 
00028   disable_erase_flag();
00029   create_spec(&dbgspec, dbgname, npts, refspec->start, refspec->step, 
00030               refspec->data_type, refspec->ident, refspec->cunit);
00031   switch(type) {
00032   case(FLOAT): 
00033     for (i=0; i<npts; i++) WR_spec(&dbgspec, i, ((float *)array)[i]);
00034     break;
00035   case(DOUBLE): 
00036     for (i=0; i<npts; i++) WR_spec(&dbgspec, i, ((double *)array)[i]);
00037     break;
00038   default:
00039     print_error("Unimplemented type '%c' in %s", __func__);
00040     close_spec(&dbgspec);
00041     return(ERR_NOIMPL);
00042   }
00043   write_file_class(&dbgspec, DEBUG_FILE);
00044   close_spec(&dbgspec);
00045   restore_erase_flag();
00046 
00047   return(OK);
00048 }
00049 
00050 /* === Doxygen Comment ======================================= */
00061 /* =========================================================== */
00062 
00063 int dump_spec_mem(SPECTRUM *spectrum, char *name, char *ident, char *unit, 
00064                   int fclass)
00065 {
00066   SPECTRUM tmp;
00067   int status=0;
00068 
00069   /* Creation of the disk spectrum according to the memory spectrum 
00070      specifications */
00071   status = create_spec(&tmp, name, spectrum->npts, spectrum->start, 
00072                        spectrum->step, spectrum->data_type, ident, unit);
00073   if (status) print_warning("Cannot dump spectrum %s to disk", name);
00074   else {
00075     /* Copy of the spectrum content */
00076     memcpy(tmp.data.d_data, spectrum->data.d_data, 
00077            sizeof_item(spectrum->data_type)*spectrum->npts);
00078     /* Write the file class */
00079     write_file_class(&tmp, fclass);
00080     /* Close the disk spectrum */
00081     status = close_spec(&tmp);
00082     if (status) print_warning("Cannot close spectrum %s", name);
00083   }
00084   return(status);
00085 }
00086 
00087 /* === Doxygen Comment ======================================= */
00106 /* =========================================================== */
00107 
00108 void put_tiger_arrays(TIGERfile *frame, int no_lens, 
00109                       void *signal, void *noise, int data_type, 
00110                       int npix, double start)
00111 {
00112   int i;
00113   SPECTRUM sp_signal, sp_noise;
00114 
00115   if (signal != NULL) { /* Store signal array if any */
00116     init_new_tiger_spec(frame,&sp_signal,npix,start);
00117     switch (data_type) {
00118     case SHORT : 
00119       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((short *)signal)[i]); break; 
00120     case LONG  :
00121     case INT   : 
00122       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((int *)signal)[i]);   break; 
00123     case FLOAT : 
00124       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((float *)signal)[i]); break; 
00125     case DOUBLE: 
00126       for (i=0;i<npix;i++) WR_spec(&sp_signal,i,((double *)signal)[i]);break; 
00127     }
00128   }
00129 
00130   if (noise != NULL) { /* Store noise array if any */
00131     init_new_tiger_spec(frame,&sp_noise,npix,start);
00132     switch (data_type) {
00133     case SHORT : 
00134       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((short *)noise)[i]);  break; 
00135     case LONG  :
00136     case INT   : 
00137       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((int *)noise)[i]);    break; 
00138     case FLOAT : 
00139       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((float *)noise)[i]);  break; 
00140     case DOUBLE: 
00141       for (i=0;i<npix;i++) WR_spec(&sp_noise,i,((double *)noise)[i]); break; 
00142     }
00143   }
00144   
00145   if (signal != NULL && noise != NULL)
00146     put_tiger_spec(frame,&sp_signal,&sp_noise,no_lens);
00147   else if (signal != NULL)
00148     put_tiger_spec(frame,&sp_signal,NULL,no_lens);
00149   else if (noise != NULL)
00150     put_tiger_spec(frame,NULL,&sp_noise,no_lens);
00151   else
00152     print_error("put_tiger_arrays (%s:%d): at least *one* of the arrays "
00153                 "should be non-NULL!",__FILE__,__LINE__);
00154 }
00155 
00156 /* === Doxygen Comment ======================================= */
00171 /* =========================================================== */
00172 
00173 int dump_2Darray(void **array, int data_type, int npix[], char *name)
00174 {
00175   IMAGE2D frame;
00176   int i,j, status;
00177   double start[2]={0,0}, step[2]={1,1};
00178 
00179   status = create_frame(&frame,name,npix,start,step,data_type,"","");
00180   switch (data_type) {
00181   case SHORT : 
00182     for (j=0; j<npix[1]; j++)   /* Image-oriented loop (i running faster) */
00183       for (i=0; i<npix[0]; i++) 
00184         WR_frame(&frame, i, j, ((short **)array)[i][j]); break;
00185   case LONG  :
00186   case INT   : 
00187     for (j=0; j<npix[1]; j++) 
00188       for (i=0; i<npix[0]; i++) 
00189         WR_frame(&frame, i, j, ((int **)array)[i][j]); break;
00190   case FLOAT : 
00191     for (j=0; j<npix[1]; j++) 
00192       for (i=0; i<npix[0]; i++) 
00193         WR_frame(&frame, i, j, ((float **)array)[i][j]); break;
00194   case DOUBLE: 
00195     for (j=0; j<npix[1]; j++) 
00196       for (i=0; i<npix[0]; i++) 
00197         WR_frame(&frame, i, j, ((double **)array)[i][j]); break;
00198   }
00199   write_file_class(&frame,DEBUG_FILE); 
00200   close_frame(&frame);
00201 
00202   return(status);
00203 }

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