IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38425


Ignore:
Timestamp:
Jun 7, 2015, 11:42:53 AM (11 years ago)
Author:
eugene
Message:

add some more error checking and a timing test

Location:
branches/eam_branches/ohana.20150429/src/libfits
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/Makefile

    r38418 r38425  
    2727
    2828# zlib
    29 TESTPROG = imagecomp tablecomp ricetest
     29TESTPROG = imagecomp tablecomp tcomptiming ricetest
    3030$(TESTPROG) : % : $(TESTBIN)/%
    3131test: $(TESTPROG)
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_matrix.c

    r38329 r38425  
    11# include <ohana.h>
    22# include <gfitsio.h>
    3 
    4 off_t gfits_data_size (Header *header) {
    5  
    6   int i;
    7   off_t Nrec, size;
    8 
    9   if (header[0].Naxes == 0) return (0);
    10 
    11   size = abs(header[0].bitpix / 8);
    12 
    13   for (i = 0; i < header[0].Naxes; i++)
    14     size *= header[0].Naxis[i];
    15 
    16   // XXX do I multiply this times gcount?
    17   size += header[0].pcount;
    18 
    19   /* round up to next complete block */
    20   if (size % FT_RECORD_SIZE) {
    21     Nrec = 1 + (int) (size / FT_RECORD_SIZE);
    22     size = FT_RECORD_SIZE * Nrec;
    23   }
    24 
    25   return (size);
    26 }
    273
    284off_t gfits_heap_start (Header *header) {
     
    4319off_t gfits_data_min_size (Header *header) {
    4420 
    45   int i;
    46   off_t size;
     21  off_t size = gfits_heap_start (header);
     22  size += header[0].pcount;
    4723
    48   if (header[0].Naxes == 0) return (0);
    49 
    50   size = abs(header[0].bitpix / 8);
    51 
    52   for (i = 0; i < header[0].Naxes; i++)
    53     size *= header[0].Naxis[i];
    54 
    55   // XXX do I multiply this times gcount?
    56   size += header[0].pcount;
     24  // XXX what do I do with gcount?
    5725
    5826  return (size);
     
    6129off_t gfits_data_pad_size (off_t rawsize) {
    6230 
    63   off_t Nrec, size;
    64 
    65   size = rawsize;
     31  off_t size = rawsize;
    6632
    6733  /* round up to next complete block */
    6834  if (rawsize % FT_RECORD_SIZE) {
    69     Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE);
     35    off_t Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE);
    7036    size = FT_RECORD_SIZE * Nrec;
    7137  }
     
    7339  return (size);
    7440}
     41
     42off_t gfits_data_size (Header *header) {
     43  off_t rawsize = gfits_data_min_size(header);
     44  off_t size = gfits_data_pad_size (rawsize);
     45
     46  return (size);
     47}
     48
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_table_varlength.c

    r38342 r38425  
    157157
    158158  // extend the buffer size to add the new data
    159   off_t Nbytes = heap_offset + Ndata;
     159  off_t Nbytes = gfits_data_pad_size (heap_offset + Ndata);
    160160  REALLOCATE (table->buffer, char, Nbytes);
    161161
     
    198198  table->header->pcount = pcount;
    199199  table->datasize = gfits_data_size (table->header);
     200  myAssert (table->datasize == Nbytes, "inconsistent header and data");
    200201
    201202  return TRUE;
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c

    r38418 r38425  
    179179
    180180  // allocate the intermediate storage buffers
    181   int Nraw_alloc = max_width*ztilelen + 100;
     181  int Nraw_alloc = max_width*ztilelen + 1000;
    182182  ALLOCATE (raw,   char, Nraw_alloc);
    183183  ALLOCATE (zdata, char, max_width*ztilelen);
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_write_T.c

    r38329 r38425  
    1414 
    1515  status = fseeko (f, 0LL, SEEK_END);  /* write table to end of file! */
     16  if (status) { perror ("fseeko: "); return (FALSE);  }
    1617  status = gfits_fwrite_table (f, table);
    1718
     
    2627 
    2728  Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].datasize, f);
    28  
    29   if (Nbytes != table[0].datasize) return (FALSE);
     29  if (Nbytes != table[0].datasize) { perror ("fwrite: "); return (FALSE);  }
    3030  return (TRUE);
    3131}       
     
    4545  /* file pointer is at beginning of desired table data */
    4646  start = ftello (f);
     47  if (start < 0) { perror ("ftello: "); return FALSE; }
    4748 
    4849  for (i = 0; i < Nrow; i++) {
     
    5051    fseeko (f, offset, SEEK_SET);
    5152    Nbytes = fwrite (table[0].buffer[i], sizeof (char), Nx, f);
    52     if (Nbytes != Nx) { return (FALSE); }
     53    if (Nbytes != Nx) { perror ("fwrite: "); return (FALSE); }
    5354  }
    5455 
     
    5859
    5960  offset = start + Nx*Ny;
    60   fseeko (f, offset, SEEK_SET);
     61  int status = fseeko (f, offset, SEEK_SET);
     62  if (status) { perror ("fseeko: "); return FALSE; }
     63
    6164  Nbytes = fwrite (pad, sizeof (char), Npad, f);
    62   if (Nbytes != Npad) { return (FALSE); }
     65  if (Nbytes != Npad) { perror ("fwrite: "); return (FALSE); }
    6366  free (pad);
    6467
     
    97100  // cursor must be at start of the table (after table header)
    98101  if (fseeko (f, Nskip, SEEK_CUR)) {
     102    perror ("fseeko: ");
    99103    fprintf (stderr, "can't seek table start\n");
    100104    return (FALSE);
     
    102106
    103107  Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
    104   if (Nwrite != Nbytes) {
    105     return (FALSE);
    106   }
     108  if (Nwrite != Nbytes) { perror ("fwrite: "); return (FALSE); }
    107109
    108110  if (Ntotal >= Ndisk) {
     
    113115    free (pad);
    114116
    115     if (Nbytes != Npad) return (FALSE);
     117    if (Nbytes != Npad) { perror ("fwrite: "); return (FALSE);  }
    116118  }
    117119
  • branches/eam_branches/ohana.20150429/src/libfits/table/F_write_TH.c

    r27435 r38425  
    1414 
    1515  status = fseeko (f, 0LL, SEEK_END);  /* write header to end of file! */
     16  if (status) { perror ("fseeko: "); return (FALSE);  }
    1617  status = gfits_fwrite_Theader (f, header);
    1718
     
    2627 
    2728  Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f);
     29  if (Nbytes != header[0].datasize) { perror ("fwrite: "); return (FALSE);  }
    2830
    29   if (Nbytes != header[0].datasize) return (FALSE);
    3031  return (TRUE);
    3132}       
  • branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh

    r38418 r38425  
    11input tap.dvo
     2
     3macro tests
     4  test_image_all
     5  test_table_all_rnd
     6end
    27
    38macro test_image_all
     
    308313end
    309314
    310 
    311315macro test_table_all_rnd
    312316
     
    334338 # lrnd generates rnd int between 0 and 0x7fffff (2^31 - 1 inclusive)
    335339
    336  $NPT = 1000
     340 $NPT = 1000000
    337341 # $NPT = 30
    338342 create ni 0 $NPT -int
Note: See TracChangeset for help on using the changeset viewer.