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

Location:
trunk/Ohana/src/libfits
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/header/F_read_H.c

    r15487 r15743  
    3434    Nbytes = fread (&header[0].buffer[i*FT_RECORD_SIZE],
    3535                    sizeof(char), FT_RECORD_SIZE, f);
     36    if (Nbytes != FT_RECORD_SIZE) {
     37      perror ("fits read error");
     38    }
     39   
    3640    header[0].size += Nbytes;
    3741    if (Nbytes != FT_RECORD_SIZE) {
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r15656 r15743  
    22
    33# include <assert.h>
     4# include <errno.h>
    45
    56# ifndef GFITSIO
     
    172173int     gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname));
    173174int     gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable));
     175int     gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, int start, int Nrows));
    174176int     gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, int Nrow, int *row));
    175177int     gfits_fread_vtable_range       PROTO((FILE *f, VTable *vtable, int start, int Nrows));
     
    178180int     gfits_fwrite_table             PROTO((FILE *f, FTable *table));
    179181int     gfits_fwrite_vtable            PROTO((FILE *f, VTable *table));
     182int     gfits_fwrite_ftable_range      PROTO((FILE *f, FTable *table, int start, int Nrows, int Ndisk, int Ntotal));
    180183int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
    181184int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
  • trunk/Ohana/src/libfits/matrix/F_load_M.c

    r15487 r15743  
    3030
    3131  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
     32  if (nbytes != Nbytes) {
     33    perror ("fits matrix read error");
     34  }
    3235
    3336# ifdef BYTE_SWAP 
  • trunk/Ohana/src/libfits/matrix/F_read_portion.c

    r7054 r15743  
    4747  fseek (f, header.size + Nskip, SEEK_SET);
    4848  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
     49  if (nbytes != Nbytes) {
     50    perror ("fits matrix read error");
     51  }
     52
    4953  fclose (f);
    5054
  • trunk/Ohana/src/libfits/matrix/F_read_segment.c

    r13039 r15743  
    9090  fseek (f, Nskip, SEEK_CUR);
    9191  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
     92  if (nbytes != Nbytes) {
     93    perror ("fits matrix read error");
     94  }
     95
    9296  matrix[0].size = Nbytes;
    9397
  • 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
  • trunk/Ohana/src/libfits/table/F_read_TH.c

    r15487 r15743  
    4646    Nbytes = fread (&Theader[0].buffer[i*FT_RECORD_SIZE],
    4747                    sizeof(char), FT_RECORD_SIZE, f);
     48    if (Nbytes != FT_RECORD_SIZE) {
     49      perror ("fits matrix read error");
     50    }
     51
    4852    Theader[0].size += Nbytes;
    4953    if (Nbytes != FT_RECORD_SIZE)
  • trunk/Ohana/src/libfits/table/F_write_T.c

    r7054 r15743  
    6969/* this will add data beyond the end of the table in the file if needed,
    7070   filling intervening gap with 0 */
     71
     72/*********************** fits read ftable data ***********************************/
     73int gfits_fwrite_ftable_range (FILE *f, FTable *ftable, int start, int Nrows, int Ndisk, int Ntotal) {
     74
     75  int Nbytes, Nwrite, Nskip, Nx, Npad;
     76  char *pad;
     77
     78  if (start < 0) return (FALSE);
     79 
     80  /* modify vtable to represent full disk table */
     81  gfits_modify (ftable[0].header, "NAXIS2", "%d", 1, Ntotal);
     82  ftable[0].header[0].Naxis[1] = Ntotal;
     83
     84  Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk
     85  ftable[0].size = gfits_data_size (ftable[0].header);
     86
     87  Nskip = start * Nx;
     88  Nbytes = Nrows * Nx;
     89
     90  // cursor must be at start of the table header
     91  if (!gfits_fwrite_Theader (f, ftable[0].header)) {
     92    fprintf (stderr, "can't write table header");
     93    return (FALSE);
     94  }
     95
     96  // cursor must be at start of the table (after table header)
     97  fseek (f, Nskip, SEEK_CUR);
     98  Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f);
     99  if (Nwrite != Nbytes) {
     100    return (FALSE);
     101  }
     102
     103  if (Ntotal >= Ndisk) {
     104    Npad = ftable[0].size - Nx*Ntotal;
     105    ALLOCATE (pad, char, Npad);
     106    bzero (pad, Npad);
     107    Nbytes = fwrite (pad, sizeof (char), Npad, f);
     108    free (pad);
     109
     110    if (Nbytes != Npad) return (FALSE);
     111  }
     112
     113  return (TRUE);
     114}       
     115
Note: See TracChangeset for help on using the changeset viewer.