IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2010, 11:22:25 AM (16 years ago)
Author:
eugene
Message:

large update merging in changes for Ohana to support large files

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

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

    r16139 r27435  
    99/*********************** fits read matrix ***********************************/
    1010/** the result of this function is a matrix with dimension Npix * 1 **/
    11 int gfits_read_portion (char *filename, Matrix *matrix, int Nskip, int Npix) {
     11int gfits_read_portion (char *filename, Matrix *matrix, off_t Nskip, off_t Npix) {
    1212
    1313  FILE *f;
    1414  Header header;
    15   int status, nbytes, Nbytes, Nrec;
     15  int status;
     16  off_t nbytes, Nbytes, Nrec;
    1617
    1718  status = gfits_read_header (filename, &header);
     
    3738    Nbytes = FT_RECORD_SIZE * Nrec;
    3839  }
    39   matrix[0].size = Nbytes;
     40  matrix[0].datasize = Nbytes;
    4041  ALLOCATE (matrix[0].buffer, char, Nbytes);
    4142
     
    4344  f = fopen (filename, "r");
    4445  if (f == NULL) return (FALSE);
    45   fseek (f, header.size + Nskip, SEEK_SET);
     46  fseeko (f, header.datasize + Nskip, SEEK_SET);
    4647  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
    4748  if (nbytes != Nbytes) {
     
    5253
    5354# ifdef BYTE_SWAP 
    54  {
    55   int i, perpix;
    56   unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
     55  {
     56    off_t i;
     57    int perpix;
     58    unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
    5759
    58   perpix = abs(header.bitpix) / 8;
    59   if (perpix > 1) {
    60     byte0 = (unsigned char *) matrix[0].buffer;
    61     byte1 = (unsigned char *) matrix[0].buffer + 1;
    62     byte2 = (unsigned char *) matrix[0].buffer + 2;
    63     byte3 = (unsigned char *) matrix[0].buffer + 3;
    64     byte4 = (unsigned char *) matrix[0].buffer + 4;
    65     byte5 = (unsigned char *) matrix[0].buffer + 5;
    66     byte6 = (unsigned char *) matrix[0].buffer + 6;
    67     byte7 = (unsigned char *) matrix[0].buffer + 7;
    68     if (perpix == 2) {
    69       for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
    70         ctmp = *byte0;
    71         *byte0 = *byte1;
    72         *byte1 = ctmp;
     60    perpix = abs(header.bitpix) / 8;
     61    if (perpix > 1) {
     62      byte0 = (unsigned char *) matrix[0].buffer;
     63      byte1 = (unsigned char *) matrix[0].buffer + 1;
     64      byte2 = (unsigned char *) matrix[0].buffer + 2;
     65      byte3 = (unsigned char *) matrix[0].buffer + 3;
     66      byte4 = (unsigned char *) matrix[0].buffer + 4;
     67      byte5 = (unsigned char *) matrix[0].buffer + 5;
     68      byte6 = (unsigned char *) matrix[0].buffer + 6;
     69      byte7 = (unsigned char *) matrix[0].buffer + 7;
     70      if (perpix == 2) {
     71        for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
     72          ctmp = *byte0;
     73          *byte0 = *byte1;
     74          *byte1 = ctmp;
     75        }
    7376      }
    74     }
    75     if (perpix == 4) {
    76       for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
    77         ctmp = *byte0;
    78         *byte0 = *byte3;
    79         *byte3 = ctmp;
    80         ctmp = *byte1;
    81         *byte1 = *byte2;
    82         *byte2 = ctmp;
     77      if (perpix == 4) {
     78        for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
     79          ctmp = *byte0;
     80          *byte0 = *byte3;
     81          *byte3 = ctmp;
     82          ctmp = *byte1;
     83          *byte1 = *byte2;
     84          *byte2 = ctmp;
     85        }
    8386      }
    84     }
    85     if (perpix == 8) {
    86       for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
    87         ctmp = *byte0;
    88         *byte0 = *byte7;
    89         *byte7 = ctmp;
    90         ctmp = *byte1;
    91         *byte1 = *byte6;
    92         *byte6 = ctmp;
    93         ctmp = *byte1;
    94         *byte2 = *byte5;
    95         *byte5 = ctmp;
    96         ctmp = *byte1;
    97         *byte3 = *byte4;
    98         *byte4 = ctmp;
     87      if (perpix == 8) {
     88        for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
     89          ctmp = *byte0;
     90          *byte0 = *byte7;
     91          *byte7 = ctmp;
     92          ctmp = *byte1;
     93          *byte1 = *byte6;
     94          *byte6 = ctmp;
     95          ctmp = *byte1;
     96          *byte2 = *byte5;
     97          *byte5 = ctmp;
     98          ctmp = *byte1;
     99          *byte3 = *byte4;
     100          *byte4 = ctmp;
     101        }
    99102      }
    100103    }
    101104  }
    102  }
    103105# endif
    104106
     
    106108
    107109  if (nbytes < Nbytes - 2880) {  /* this is a bad FITS error: image is not OK */
    108     fprintf (stderr, "error reading in matrix data from FITS file %s (%d < %d - 2880)\n", filename, nbytes, Nbytes);
     110    fprintf (stderr, "error reading in matrix data from FITS file %s (%lld < %lld - 2880)\n", filename, (long long) nbytes, (long long) Nbytes);
    109111    return (FALSE);
    110112  }
    111113  if (nbytes != Nbytes) {  /* this is a FITS error, but often the image is OK */
    112     fprintf (stderr, "incomplete block in %s: (%d, %d)\n", filename, nbytes, Nbytes);
     114    fprintf (stderr, "incomplete block in %s: (%lld, %lld)\n", filename, (long long) nbytes, (long long) Nbytes);
    113115    return (TRUE);
    114116  }
Note: See TracChangeset for help on using the changeset viewer.