IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2012, 1:55:31 PM (14 years ago)
Author:
eugene
Message:

working build for parallel setphot / setphot_client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c

    r33227 r33241  
    1 # include "uniphot.h"
     1# include "setphot.h"
    22
    3 typedef struct {
    4   float Mcal;
    5   float dMcal;
    6   unsigned int imageID;
    7   unsigned int photom_map_id;
    8   unsigned int flags;
    9 } ImageSubset;
     3ImageSubset *ImageSubsetLoad(char *filename, off_t *nimage) {
    104
    11 ImageSubset *ImageSubsetLoad(char *filename, int *nimage) {
    12 
    13   int i, Ncol;
     5  int i, Ncol, Ncol2;
    146  off_t Nrow;
    157  Header header;
     
    5345  // this means I need 3 copies in memory at some point.  ugh.
    5446
     47  char type[16];
     48
    5549  // need to create and assign to flat-field correction
    5650  float *Mcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL", type, &Nrow, &Ncol);
     
    5852
    5953  float *dMcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL_ERR", type, &Nrow, &Ncol2);
    60   assert (!strcmp(type, "float"), "wrong column type");
    61   assert (Ncol == Ncol2, "table length mismatch");
     54  myAssert (!strcmp(type, "float"), "wrong column type");
     55  myAssert (Ncol == Ncol2, "table length mismatch");
    6256
    6357  unsigned int *imageID = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol2);
    64   assert (!strcmp(type, "int"), "wrong column type");
    65   assert (Ncol == Ncol2, "table length mismatch");
     58  myAssert (!strcmp(type, "int"), "wrong column type");
     59  myAssert (Ncol == Ncol2, "table length mismatch");
    6660
    6761  unsigned int *map = gfits_get_bintable_column_data (&theader, &ftable, "PHOTOM_MAP", type, &Nrow, &Ncol2);
    68   assert (!strcmp(type, "int"), "wrong column type");
    69   assert (Ncol == Ncol2, "table length mismatch");
     62  myAssert (!strcmp(type, "int"), "wrong column type");
     63  myAssert (Ncol == Ncol2, "table length mismatch");
    7064
    7165  unsigned int *flags = gfits_get_bintable_column_data (&theader, &ftable, "FLAGS", type, &Nrow, &Ncol2);
    72   assert (!strcmp(type, "int"), "wrong column type");
    73   assert (Ncol == Ncol2, "table length mismatch");
     66  myAssert (!strcmp(type, "int"), "wrong column type");
     67  myAssert (Ncol == Ncol2, "table length mismatch");
    7468
    7569  // XXX free the fits table data here
     
    9589}
    9690
    97 int ImageSubsetSave(char *filename, Image *image, int Nimage) {
     91int ImageSubsetSave(char *filename, Image *image, off_t Nimage) {
    9892
    99   int i, Ncol;
    100   off_t Nrow;
     93  int i;
    10194  Header header;
    10295  Header theader;
     
    109102  gfits_create_matrix (&header, &matrix);
    110103
    111   gfits_create_table_header (&theader, "BINTABLE", FITS);
     104  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    112105
    113106  gfits_define_bintable_column (&theader, "E", "MCAL", "zero point offset", "magnitudes", 1.0, 0.0);
     
    122115  gfits_create_table (&theader, &ftable);
    123116
    124   // add the vectors to the output array
    125   ALLOCATE (Mcal, float, Nimage);
     117  float *Mcal, *dMcal;
     118  unsigned int *imageID, *map, *flags;
     119
     120  // create intermediate storage arrays
     121  ALLOCATE (Mcal,  float, Nimage);
    126122  ALLOCATE (dMcal, float, Nimage);
    127123  ALLOCATE (imageID, unsigned int, Nimage);
    128   ALLOCATE (imageID, unsigned int, Nimage);
     124  ALLOCATE (map,     unsigned int, Nimage);
     125  ALLOCATE (flags,   unsigned int, Nimage);
    129126
    130   for
    131   gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements);
    132     } else {
    133       gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements);
    134       }
     127  // assign the storage arrays
     128  for (i = 0; i < Nimage; i++) {
     129    imageID[i] = image[i].imageID;
     130    map[i]     = image[i].photom_map_id;
     131    flags[i]   = image[i].flags;
     132    Mcal[i]    = image[i].Mcal;
     133    dMcal[i]   = image[i].dMcal;
    135134  }
    136135
    137   FILE *f = fopen (filename, "w");
    138   if (!f) {
    139     fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", filename);
    140     return NULL;
    141   }
    142 
    143   /* load in PHU segment (ignore) */
    144   if (!gfits_fread_header (f, &header)) {
    145     if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
    146     fclose (f);
    147     return NULL;
    148   }
    149   if (!gfits_fread_matrix (f, &matrix, &header)) {
    150     if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
    151     gfits_free_header (&header);
    152     fclose (f);
    153     return NULL;
    154   }
    155 
    156   ftable.header = &theader;
    157 
    158   // load data for this header
    159   if (!gfits_load_header (f, &theader)) return (NULL);
    160 
    161   // read the fits table bytes
    162   if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (NULL);
    163  
    164   // XXX close the fits file here
    165 
    166   // a bit annoying : we read the entire block of data (180M), then extract the columns, then set the image structure values.
    167   // this means I need 3 copies in memory at some point.  ugh.
    168 
    169   // need to create and assign to flat-field correction
    170   float *Mcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL", type, &Nrow, &Ncol);
    171   myAssert (!strcmp(type, "float"), "wrong column type");
    172 
    173   float *dMcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL_ERR", type, &Nrow, &Ncol2);
    174   assert (!strcmp(type, "float"), "wrong column type");
    175   assert (Ncol == Ncol2, "table length mismatch");
    176 
    177   unsigned int *imageID = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol2);
    178   assert (!strcmp(type, "int"), "wrong column type");
    179   assert (Ncol == Ncol2, "table length mismatch");
    180 
    181   unsigned int *map = gfits_get_bintable_column_data (&theader, &ftable, "PHOTOM_MAP", type, &Nrow, &Ncol2);
    182   assert (!strcmp(type, "int"), "wrong column type");
    183   assert (Ncol == Ncol2, "table length mismatch");
    184 
    185   unsigned int *flags = gfits_get_bintable_column_data (&theader, &ftable, "FLAGS", type, &Nrow, &Ncol2);
    186   assert (!strcmp(type, "int"), "wrong column type");
    187   assert (Ncol == Ncol2, "table length mismatch");
    188 
    189   // XXX free the fits table data here
    190 
    191   ALLOCATE (image, ImageSubset, Ncol);
    192   for (i = 0; i < Nrow; i++) {
    193     image[i].imageID       = imageID[i];
    194     image[i].photom_map_id = map[i];
    195     image[i].flags         = flags[i];
    196     image[i].Mcal          = Mcal[i];
    197     image[i].dMcal         = dMcal[i];
    198   }
    199   fprintf (stderr, "loaded data for %d images\n", Ncol);
     136  // add the columns to the output array
     137  gfits_set_bintable_column (&theader, &ftable, "MCAL",       Mcal,    Nimage);
     138  gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR",   dMcal,   Nimage);
     139  gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",   imageID, Nimage);
     140  gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP", map,     Nimage);
     141  gfits_set_bintable_column (&theader, &ftable, "FLAGS",      flags,   Nimage);
    200142
    201143  free (Mcal);
     
    205147  free (flags);
    206148
    207   *nimage = Ncol;
    208   return image;
     149  FILE *f = fopen (filename, "w");
     150  if (!f) {
     151    fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", filename);
     152    return FALSE;
     153  }
     154
     155  gfits_fwrite_header  (f, &header);
     156  gfits_fwrite_matrix  (f, &matrix);
     157  gfits_fwrite_Theader (f, &theader);
     158  gfits_fwrite_table  (f, &ftable);
     159
     160  gfits_free_header (&header);
     161  gfits_free_matrix (&matrix);
     162  gfits_free_header (&theader);
     163  gfits_free_table (&ftable);
     164
     165  return TRUE;
    209166}
Note: See TracChangeset for help on using the changeset viewer.