utilities.c

00001 #include "utilities.h"
00002 
00003     void insert_cube( OneCube ** list, OneCube * cube, int i )
00004     {
00005         list[i] = cube ;
00006     }
00007     void destroy_cube_list ( OneCube ** list )
00008     {
00009         cpl_free (list) ;
00010     }
00011     OneCube ** new_cube_list( int n_cubes )
00012     {
00013         OneCube ** cubelist ;
00014  
00015         cubelist = (OneCube**) cpl_calloc (n_cubes, sizeof(OneCube*)) ;
00016         return cubelist ;
00017     }
00018     void array_set_value( float * array, float value, int i )
00019     {
00020         array[i] = value ;
00021     }
00022     float array_get_value( float * array, int i )
00023     {
00024         return array[i] ;
00025     }
00026 
00027     OneImage ** new_image_list( int n_images )
00028     {
00029         OneImage ** imagelist ;
00030  
00031         imagelist = (OneImage**) cpl_calloc (n_images, sizeof(OneImage*)) ;
00032         return imagelist ;
00033     }
00034     void insert_image( OneImage ** list, OneImage * im, int i )
00035     {
00036         list[i] = im ;
00037     }
00038     void destroy_list ( OneImage ** list )
00039     {
00040         cpl_free (list) ;
00041     }
00042     void destroy_array(float * array)
00043     {
00044         cpl_free( array ) ;
00045     }
00046 
00047     void destroy_stringarray(char ** array, int size_x)
00048     {
00049         int i ;
00050       
00051         for ( i = 0 ; i < size_x ; i++ )
00052         {
00053             cpl_free( array[i] ) ;
00054         }
00055         cpl_free( array ) ;
00056     }
00057 
00058 
00059     void destroy_2Dintarray(int ** array, int size_x)
00060     {
00061         int i ;
00062    
00063         for ( i = 0 ; i < size_x ; i++ )
00064         {
00065             cpl_free( array[i]) ;
00066         }
00067         cpl_free( array ) ;
00068     }
00069 
00070     void intarray_set_value( int * array, int value, int i )
00071     {
00072         array[i] = value ;
00073     }
00074     float array2D_get_value( float ** array, int x, int y )
00075     {
00076         return array[x][y] ;
00077     }
00078     int ** new_2Dint_array( int size_x, int size_y)
00079     {
00080         int ** retVal ;
00081         int i ;
00082 
00083         retVal = (int **) cpl_calloc( size_x, sizeof (int*) ) ;
00084         for ( i = 0 ; i < size_x ; i++ )
00085         {
00086             retVal[i] = (int *) cpl_calloc( size_y, sizeof (int)) ;
00087         }
00088         return retVal ;
00089     }
00090 
00091     float * new_float_array( int size)
00092     {
00093         return (float *) cpl_calloc( size, sizeof (float) ) ;
00094     }
00095 
00096     void destroy_2Darray(float ** array, int size_x)
00097     {
00098         int i ;
00099 
00100         for ( i = 0 ; i < size_x ; i++ )
00101         {
00102             cpl_free( array[i] );
00103         }
00104         cpl_free( array ) ;
00105     }
00106     void array2D_set_value( float ** array, float value, int x, int y )
00107     {
00108         array[x][y] = value ;
00109     }
00110 
00111     double doublearray_get_value( double * array, int i )
00112     {
00113         return array[i] ;
00114     }
00115     void doublearray_set_value( double * array, double value, int i )
00116     {
00117         array[i] = value ;
00118     }
00119 
00120    void destroy_doublearray(double * array)
00121     {
00122         cpl_free( array ) ;
00123     }
00124     double * new_double_array( int size)
00125     {
00126         return (double *) cpl_calloc( size, sizeof (double) ) ;
00127     }
00128     float ** new_2Dfloat_array( int size_x, int size_y)
00129     {
00130         float ** retVal ;
00131         int i ;
00132 
00133         retVal = (float **) cpl_calloc( size_x, sizeof (float*) ) ;
00134         for ( i = 0 ; i < size_x ; i++ )
00135         {
00136             retVal[i] = (float *) cpl_calloc( size_y, sizeof (float)) ;
00137         }
00138         return retVal ;
00139     }
00140     int * new_int_array( int size)
00141     {
00142         return (int *) cpl_calloc( size, sizeof (int) ) ;
00143     }
00144     void destroy_intarray(int * array)
00145     {
00146         cpl_free( array ) ;
00147     }
00148 
00149     int intarray_get_value( int * array, int i )
00150     {
00151         return array[i] ;
00152     }
00153 
00154     float Stats_get_cleanstdev(Stats * stats)
00155     {
00156         return stats -> cleanstdev ;
00157     }
00158     float Stats_get_cleanmean(Stats * stats)
00159     {
00160         return stats -> cleanmean ;
00161     }
00162 
00163 char * get_basename(const char *filename)
00164 {
00165   char *p ;
00166   p = strrchr (filename, '/');
00167   return p ? p + 1 : (char *) filename;
00168 }
00169 
00170 
00171 
00172 char * get_rootname(char * filename)
00173 {
00174     static char path[MAX_NAME_SIZE+1];
00175     char * lastdot ;
00176 
00177     if (strlen(filename)>MAX_NAME_SIZE) return NULL ;
00178     memset(path, MAX_NAME_SIZE, 0);
00179     strcpy(path, filename);
00180     lastdot = strrchr(path, '.');
00181     if (lastdot == NULL) return path ;
00182     if ((!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".FITS")) ||
00183         (!strcmp(lastdot, ".paf")) || (!strcmp(lastdot, ".PAF")) ||
00184         (!strcmp(lastdot, ".dat")) || (!strcmp(lastdot, ".DAT")) ||
00185         (!strcmp(lastdot, ".tfits")) || (!strcmp(lastdot, ".TFITS")) ||
00186         (!strcmp(lastdot, ".ascii")) || (!strcmp(lastdot, ".ASCII")))
00187     {
00188         lastdot[0] = (char)0;
00189     }
00190     return path ;
00191 }
00192 
00193 
00194 
00195 /*----------------------------------------------------------------------------*/
00203 /*----------------------------------------------------------------------------*/
00204 cpl_imagelist * sinfoni_frameset_to_iset(cpl_frameset * fset)
00205 {
00206     const char  *   fctid = "sinfoni_frameset_to_iset" ;
00207     cpl_imagelist   *   iset=NULL ;
00208     char        **  filenames ;
00209     int             nfiles=0 ;
00210 
00211     /* Test entries */
00212     if (fset == NULL) return NULL ;
00213 
00214     /* Get the filenames */
00215     if ((filenames = my_frameset_to_filenames(fset, &nfiles)) == NULL) {
00216         cpl_msg_error(fctid, "Cannot get the files names") ;
00217         return NULL ;
00218     }
00219     /* Load image set */
00220     if ((iset = sinfoni_imagelist_load_frameset(fset, CPL_TYPE_FLOAT, 0, 0)) == NULL) {
00221         cpl_msg_error(fctid, "Cannot load *** the image set") ;
00222         cpl_msg_error(fctid,(char* ) cpl_error_get_message());
00223 
00224         cpl_free(filenames) ;
00225         return NULL ;
00226     }
00227 
00228     /* Free and Return  */
00229     cpl_free(filenames) ;
00230     return iset ;
00231 }
00232 #include "cpl_imagelist_io.h"
00233 
00234 /*----------------------------------------------------------------------------*/
00244 /*----------------------------------------------------------------------------*/
00245 cpl_imagelist * sinfoni_imagelist_load_frameset(const cpl_frameset * frameset,
00246                                             cpl_type type, int pnum,
00247                                             int extnum)
00248 {
00249     const char * fctid     = "sinfoni_imagelist_load_frameset";
00250     cpl_image  * image     = NULL;
00251     cpl_imagelist  * imagelist = NULL;
00252     cpl_frame  * frame     = cpl_frameset_get_first(frameset);
00253     const int nz = cpl_frameset_get_size(frameset);
00254     int       i;
00255 
00256     /* Require imagelist to contain at least one image */
00257     cpl_assure(nz > 0, CPL_ERROR_DATA_NOT_FOUND, fctid, NULL);
00258 
00259     for (i = 0; frame != NULL; i++, frame = cpl_frameset_get_next(frameset)) {
00260 
00261         const char * name = cpl_frame_get_filename(frame);
00262         if (name == NULL) break; /* Error check */
00263 
00264 
00265         image = cpl_image_load(name, type, pnum, extnum);
00266 
00267         if (image == NULL) break; /* Error check */
00268 
00269         if (i == 0) {
00270             const int nx = cpl_image_get_size_x(image);
00271             const int ny = cpl_image_get_size_y(image);
00272 
00273             if (nx < 1 || ny < 1) break; /* Error check */
00274 
00275             imagelist = cpl_imagelist_new(nx, ny, nz, type);
00276             if (imagelist == NULL) break; /* Error check */
00277         }
00278 
00279         if (cpl_imagelist_set(imagelist, image, i)) break;
00280         image = NULL; /* Image is now part of the imagelist */
00281 
00282     }
00283 
00284     if (i != nz) {
00285         /* Error handling */
00286         cpl_image_delete(image);
00287         cpl_imagelist_delete(imagelist);
00288         imagelist = NULL;
00289     }
00290     return imagelist;
00291 
00292 }
00293 
00304 char **
00305 my_frameset_to_filenames(cpl_frameset *set, int *nfiles)
00306 {
00307     char **filenames=NULL;
00308 
00309     int nbframes=0;
00310     int i=0;
00311 
00312     cpl_frame *curr_frame;
00313 
00314     if (set == NULL) {
00315         return NULL;
00316     }
00317 
00318     nbframes = cpl_frameset_get_size(set);
00319 
00320     if (nbframes < 1) {
00321         return NULL;
00322     }
00323     /*
00324      * Create the list of filenames and fill it
00325      */
00326     filenames = cpl_malloc(nbframes * sizeof(char *));
00327 
00328     curr_frame = cpl_frameset_get_first(set);
00329     for (i = 0; i < nbframes; i++) {
00330        filenames[i]=(char*) cpl_frame_get_filename(curr_frame);
00331         curr_frame = cpl_frameset_get_next(set);
00332     }
00333 
00334 
00335     /*
00336      * Set the number of files found
00337      */
00338     *nfiles = nbframes;
00339 
00340     return filenames;
00341 
00342 }
00343 
00344 
00355 char **
00356 my_frameset_to_tags(cpl_frameset *set, int *ntags)
00357 {
00358     cxchar **tags;
00359     cxchar *curr_tag;
00360 
00361     cxint nbframes;
00362     cxint i;
00363 
00364     cpl_frame *curr_frame;
00365 
00366 
00367     if (set == NULL) {
00368         return NULL;
00369     }
00370 
00371     nbframes = cpl_frameset_get_size(set);
00372     if (nbframes < 1) {
00373         return NULL;
00374     }
00375 
00376 
00377     /*
00378      * Create the list of tags and fill it
00379      */
00380 
00381     tags = cx_malloc(nbframes * sizeof(cxchar *));
00382 
00383     curr_frame = cpl_frameset_get_first(set);
00384     for (i = 0; i < nbframes; i++) {
00385         curr_tag = (cxchar *)cpl_frame_get_tag(curr_frame);
00386         tags[i] = cx_strdup(curr_tag);
00387         curr_frame = cpl_frameset_get_next(set);
00388     }
00389 
00390 
00391     /*
00392      * Set the number of tags found
00393      */
00394 
00395     *ntags = nbframes;
00396 
00397     return tags;
00398 
00399 }

Generated on Wed Oct 26 13:08:56 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001