IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2016, 10:23:42 PM (10 years ago)
Author:
eugene
Message:

modify to pass with extremely pedantic build; force consistency for signed vs unsigned and int sizes; various relastro updates

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libfits/matrix/F_compress_M.c

    r38441 r39457  
    44# define VERBOSE_DUMP 0
    55
    6 int gfits_collect_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero);
     6int gfits_collect_gzp2 (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero);
    77
    88// the user needs to specify the various compression options:
     
    2323# define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; }
    2424
    25 int gfits_compress_image (Header *header, Matrix *matrix, FTable *ftable, int *Ztile, char *zcmptype) {
     25int gfits_compress_image (Header *header, Matrix *matrix, FTable *ftable, unsigned long int *Ztile, char *zcmptype) {
    2626
    2727  int i;
     
    3333  char *zdata = NULL;
    3434
    35   int *ztile = Ztile;
     35  unsigned long int *ztile = Ztile;
    3636
    3737  Header *theader = ftable->header;
     
    4141  // determine the number of tiles (from ztile[] and image size)
    4242  if (!ztile) {
    43     ALLOCATE (ztile, int, matrix->Naxes);
     43    ALLOCATE (ztile, unsigned long int, matrix->Naxes);
    4444    ztile[0] = matrix->Naxis[0];
    4545    for (i = 1; i < matrix->Naxes; i++) ztile[i] = 1;
     
    9999  for (i = 0; i < header->Naxes; i++) {
    100100    snprintf (keyword, 10, "ZTILE%d", i + 1);
    101     if (!gfits_modify (theader, keyword, "%d", 1, ztile[i])) ESCAPE;
     101    if (!gfits_modify (theader, keyword, "%lu", 1, ztile[i])) ESCAPE;
    102102  }
    103103
     
    157157
    158158  // size (in pixels) of the largest tile
    159   int max_tile_size = gfits_imtile_maxsize (matrix, ztile);
     159  unsigned long int max_tile_size = gfits_imtile_maxsize (matrix, ztile);
    160160
    161161  // size of a pixel in the raw pixel buffer (before compression)
     
    179179
    180180  // allocate the buffer for compression work
    181   int Nzdata_alloc = raw_pixsize*max_tile_size + 100;
     181  unsigned long int Nzdata_alloc = raw_pixsize*max_tile_size + 100;
    182182  ALLOCATE (raw,   char, raw_pixsize*max_tile_size);
    183183  ALLOCATE (zdata, char, Nzdata_alloc);
     
    191191
    192192    // size of the current tile in pixels
    193     int Nraw = gfits_tile_size (matrix, otile, ztile);
     193    unsigned long int Nraw = gfits_tile_size (matrix, otile, ztile);
    194194
    195195    // copy the raw pixels from their native matrix locations to the temporary output buffer
     
    216216      if (!gfits_byteswap_zdata (raw, Nraw * raw_pixsize, raw_pixsize)) ESCAPE;
    217217    }
    218     int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
     218    unsigned long int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression
    219219
    220220    if (VERBOSE_DUMP && (i == 0)) {
     
    223223      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", raw[k]); if (k % 4 == 3) fprintf (stderr, " "); }
    224224      fprintf (stderr, "\n");
    225       fprintf (stderr, "Nzdata: %d -> ", Nzdata);
     225      fprintf (stderr, "Nzdata: %lu -> ", Nzdata);
    226226    }
    227227
     
    231231    if (VERBOSE_DUMP && (i == 0)) {
    232232      int k;
    233       fprintf (stderr, "%d\n", Nzdata);
     233      fprintf (stderr, "%lu\n", Nzdata);
    234234      fprintf (stderr, "cmp SWP: ");
    235235      for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); }
     
    290290
    291291int gfits_copy_keywords_compress (Header *srchead, Header *tgthead) {
    292 
     292  OHANA_UNUSED_PARAM(tgthead);
     293  OHANA_UNUSED_PARAM(srchead);
     294
     295# if (0)
    293296  int i;
    294297
    295298  for (i = 0; i < srchead->datasize; i += FT_LINE_LENGTH) {
    296299  }
     300# endif
     301
    297302  return TRUE;
    298303}
     
    303308// * ztile gives the size of the i-th dimension of the current tile
    304309// * raw_bitpix defines the size and type of the raw buffer
    305 int gfits_collect_data (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) {
    306 
    307   int i, j, start, offset, coord, Nline;
    308   int *counter = NULL;
    309   int *Ztile = NULL;
    310 
    311   ALLOCATE (counter, int, matrix->Naxes); // counter for current row in tile to copy
    312   ALLOCATE (Ztile, int, matrix->Naxes); // true sizes of this tile (in pixels)
     310int gfits_collect_data (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) {
     311
     312  int i, k, start, offset, coord, Nline;
     313  unsigned int *counter = NULL;
     314  unsigned long int *Ztile = NULL;
     315
     316  ALLOCATE (counter, unsigned int, matrix->Naxes); // counter for current row in tile to copy
     317  ALLOCATE (Ztile, unsigned long int, matrix->Naxes); // true sizes of this tile (in pixels)
    313318 
    314319  for (i = 0; i < matrix->Naxes; i++) {
     
    343348  // this macro is used at the inner switch to run the actual loop
    344349# define SCALE_AND_DIST_INT_PRINT(TYPE, SIZE, INTYPE) {                 \
     350    unsigned long int j;                                                \
    345351    TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)];    \
    346352    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     
    356362  // this macro is used at the inner switch to run the actual loop
    357363# define SCALE_AND_DIST_INT(OTYPE, OSIZE) {                             \
     364    unsigned long int j;                                                \
    358365    OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \
    359366    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     
    370377  // this macro is used at the inner switch to run the actual loop
    371378# define SCALE_AND_DIST_FLOAT(OTYPE, OSIZE) {                           \
     379    unsigned long int j;                                                \
    372380    OTYPE *TILEptr = (OTYPE *) &matrix->buffer[OSIZE*(offset + start)]; \
    373381    for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) {               \
     
    419427
    420428    // update the counters, carrying to the next dimension if needed
    421     for (j = 1; j < matrix->Naxes; j++) {
    422       counter[j] ++;
    423       if (counter[j] == Ztile[j]) {
    424         counter[j] = 0;
     429    for (k = 1; k < matrix->Naxes; k++) {
     430      counter[k] ++;
     431      if (counter[k] == Ztile[k]) {
     432        counter[k] = 0;
    425433      } else {
    426434        break;
    427435      }
    428436    }
    429     if (j == matrix->Naxes) assert (i == Nline - 1); // we should be done here...
     437    if (k == matrix->Naxes) assert (i == Nline - 1); // we should be done here...
    430438
    431439    // Naxes = 3
     
    435443    // determine the offset of the next line relative to the start position
    436444    offset = counter[matrix->Naxes - 1];
    437     for (j = matrix->Naxes - 2; j >= 0; j--) {
    438       offset = offset*matrix->Naxis[j] + counter[j];
     445    for (k = matrix->Naxes - 2; k >= 0; k--) {
     446      offset = offset*matrix->Naxis[k] + counter[k];
    439447    }     
    440448  }
     
    453461// * ztile gives the size of the i-th dimension of the current tile
    454462// * raw_bitpix defines the size and type of the raw buffer
    455 int gfits_collect_gzp2 (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) {
    456 
    457   int i, j, k;
    458   int *counter = NULL;
    459   int *Ztile = NULL;
    460 
    461   ALLOCATE (counter, int, matrix->Naxes); // counter for current row in tile to copy
    462   ALLOCATE (Ztile, int, matrix->Naxes); // true sizes of this tile (in pixels)
     463int gfits_collect_gzp2 (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) {
     464  OHANA_UNUSED_PARAM(oblank);
     465  OHANA_UNUSED_PARAM(zblank);
     466  OHANA_UNUSED_PARAM(zzero);
     467  OHANA_UNUSED_PARAM(zscale);
     468
     469  unsigned long int i, j;
     470  unsigned int *counter = NULL;
     471  unsigned long int *Ztile = NULL;
     472
     473  ALLOCATE (counter, unsigned int, matrix->Naxes); // counter for current row in tile to copy
     474  ALLOCATE (Ztile, unsigned long int, matrix->Naxes); // true sizes of this tile (in pixels)
    463475 
    464   for (i = 0; i < matrix->Naxes; i++) {
    465     counter[i] = 0;
    466     Ztile[i] = MIN ((matrix->Naxis[i] - otile[i]*ztile[i]), ztile[i]);
     476  int k;
     477  for (k = 0; k < matrix->Naxes; k++) {
     478    counter[k] = 0;
     479    Ztile[k] = MIN ((matrix->Naxis[k] - otile[k]*ztile[k]), ztile[k]);
    467480  }
    468481
    469482  // number of lines in the tile (in pixels)
    470   int Nline = 1;
    471   int Npix = matrix->Naxis[0];
    472   for (i = 1; i < matrix->Naxes; i++) {
    473     Nline *= Ztile[i];
    474     Npix  *= matrix->Naxis[i];
     483  unsigned long int Nline = 1;
     484  unsigned long int Npix = matrix->Naxis[0];
     485  for (k = 1; k < matrix->Naxes; k++) {
     486    Nline *= Ztile[k];
     487    Npix  *= matrix->Naxis[k];
    475488  }
    476489
     
    482495  // start = otile[0]*ztile[0] + Naxis[0]*(otile[1]*ztile[1] + Naxis[1]*(otile[2]*ztile[2] + ...));
    483496  int start = otile[matrix->Naxes-1]*ztile[matrix->Naxes-1];
    484   for (i = matrix->Naxes - 2; i >= 0; i--) {
    485     int coord = otile[i]*ztile[i];
    486     start = start*matrix->Naxis[i] + coord;
     497  for (k = matrix->Naxes - 2; k >= 0; k--) {
     498    unsigned long int coord = otile[k]*ztile[k];
     499    start = start*matrix->Naxis[k] + coord;
    487500  }
    488501 
     
    519532
    520533      // update the counters, carrying to the next dimension if needed
    521       for (j = 1; j < matrix->Naxes; j++) {
    522         counter[j] ++;
    523         if (counter[j] == Ztile[j]) {
    524           counter[j] = 0;
     534      int axis;
     535      for (axis = 1; axis < matrix->Naxes; axis++) {
     536        counter[axis] ++;
     537        if (counter[axis] == Ztile[axis]) {
     538          counter[axis] = 0;
    525539        } else {
    526540          break;
    527541        }
    528542      }
    529       if (j == matrix->Naxes) assert (i == Nline - 1); // we should be done here...
     543      if (axis == matrix->Naxes) assert (i == Nline - 1); // we should be done here...
    530544
    531545      // Naxes = 3
     
    535549      // determine the offset of the next line relative to the start position
    536550      offset = counter[matrix->Naxes - 1];
    537       for (j = matrix->Naxes - 2; j >= 0; j--) {
    538         offset = offset*matrix->Naxis[j] + counter[j];
     551      for (axis = matrix->Naxes - 2; axis >= 0; axis--) {
     552        offset = offset*matrix->Naxis[axis] + counter[axis];
    539553      }     
    540554    }
Note: See TracChangeset for help on using the changeset viewer.