IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 5, 2007, 3:29:29 PM (19 years ago)
Author:
eugene
Message:

importing updates from eam_branch_20071130

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/table/F_read_T.c

    r15487 r15743  
    5959  Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
    6060  if (Nread != Nbytes) {
     61    perror ("fits read error");
    6162    gfits_free_table  (table);
    6263    return (FALSE);
    6364  }
    6465  table[0].size = Nbytes;
     66  return (TRUE);
     67}       
     68
     69/*********************** fits read ftable data ***********************************/
     70int gfits_fread_ftable_range (FILE *f, FTable *table, int start, int Nrows) {
     71
     72  int Nbytes, Nread, Nskip, Nx, Ny;
     73
     74  /* find disk table size */
     75  Nx = table[0].header[0].Naxis[0];
     76  Ny = table[0].header[0].Naxis[1];
     77
     78  // it is an error to ask for data starting out-of-bounds
     79  if (start < 0) return (FALSE);
     80  if (start >= Ny) return (FALSE);
     81 
     82  // if we request more data than is available, we will stop at the table end.
     83  Nrows = MIN (Nrows, Ny - start);
     84
     85  Nskip = start * Nx;
     86  Nbytes = Nrows * Nx;
     87  ALLOCATE (table[0].buffer, char, MAX (Nbytes, 1));
     88
     89  fseek (f, Nskip, SEEK_CUR);
     90
     91  Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
     92  if (Nread != Nbytes) {
     93    if (ferror (f)) {
     94      perror ("fits read error");
     95    } else {
     96      fprintf (stderr, "unexpected eof\n");
     97    }     
     98    free (table[0].buffer);
     99    return (FALSE);
     100  }
     101
     102  /* modify structure and header to match actual read rows Ny */
     103  table[0].header[0].Naxis[1] = Nrows;
     104  gfits_modify (table[0].header, "NAXIS2",  "%d", 1, Nrows);
     105  table[0].size = gfits_data_size (table[0].header);
     106
    65107  return (TRUE);
    66108}       
     
    88130  Nread = fread (buffer, sizeof (char), Nbytes, f);
    89131  if (Nread != Nbytes) {
     132    perror ("fits read error");
    90133    free (buffer);
    91134    return (FALSE);
     
    146189      fseek (f, offset, SEEK_SET);
    147190      Nread = fread (table[0].buffer[i], sizeof (char), Nx, f);
    148       if (Nread != Nx) { return (FALSE); }
     191      if (Nread != Nx) {
     192        perror ("fits read error");
     193        return (FALSE);
     194      }
    149195    }
    150196
Note: See TracChangeset for help on using the changeset viewer.