IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 27, 2005, 4:39:46 PM (21 years ago)
Author:
eugene
Message:

converted to autocode SMPData

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/gastro2/src/rfits.c

    r3413 r3520  
    11# include "gastro2.h"
    2 int ConvertStars (Stars *data, int size, int nitems);
    32
    4 StarData *rfits (char *filename, Header *header, int *nstars) {
     3StarData *rfits (FILE *f, int *nstars) {
    54
    6   int i, N, Nx, Ny, Nstars;
    7   FILE *f;
     5  int i, N, Nstars;
    86  Matrix matrix;
    97  Header theader;
    108  FTable table;
    11   Stars *stars;
     9  SMPData *stars;
    1210  StarData *stardata;
    13 
    14   /* open file for stars */
    15   f = fopen (filename, "r");
    16   if (f == NULL) {
    17     fprintf (stderr, "ERROR: can't open file to load stars\n");
    18     exit (1);
    19   }
    20   fseek (f, header[0].size, SEEK_SET);
    2111
    2212  /* init & load in table data */
    2313  table.header   = &theader;
    24   if (!fits_fread_matrix (f, &matrix, header))          goto escape;
    2514  if (!fits_fread_ftable (f, &table, "SMPFILE")) goto escape;
    2615
    27   /* convert to internal format */
    28   stars = (Stars *) table.buffer;
    29   fits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
    30   fits_scan (table.header, "NAXIS2", "%d", 1, &Ny);
    31   Nstars = Ny;
    32 
    33   if (!ConvertStars (stars, sizeof (Stars), Nstars)) goto escape;
     16  stars = fits_table_get_SMPData (&table, &Nstars);
    3417
    3518  ALLOCATE (stardata, StarData, Nstars);
     
    6346  exit (1);
    6447}
    65 
    66 # define SWAP_BYTE(X) \
    67   tmp = byte[X+0]; byte[X+0] = byte[X+1]; byte[X+1] = tmp;
    68 # define SWAP_WORD(X) \
    69   tmp = byte[X+0]; byte[X+0] = byte[X+3]; byte[X+3] = tmp; \
    70   tmp = byte[X+1]; byte[X+1] = byte[X+2]; byte[X+2] = tmp;
    71 # define SWAP_DBLE(X) \
    72   tmp = byte[X+0]; byte[X+0] = byte[X+7]; byte[X+7] = tmp; \
    73   tmp = byte[X+1]; byte[X+1] = byte[X+6]; byte[X+6] = tmp; \
    74   tmp = byte[X+2]; byte[X+2] = byte[X+5]; byte[X+5] = tmp; \
    75   tmp = byte[X+3]; byte[X+3] = byte[X+4]; byte[X+4] = tmp;
    76 
    77 # ifdef linux
    78 # define BYTE_SWAP
    79 # endif
    80 
    81 # ifdef sid
    82 # define BYTE_SWAP
    83 # endif
    84 
    85 # ifdef dec
    86 # define BYTE_SWAP
    87 # endif
    88 
    89 # define STARS_SIZE 44
    90 
    91 int ConvertStars (Stars *data, int size, int nitems) {
    92 
    93   int i;
    94   unsigned char *byte, tmp;
    95 
    96 # ifdef BYTE_SWAP
    97 
    98   if (size != STARS_SIZE) {
    99     fprintf (stderr, "mismatch in type sizes (Stars) %d vs %d\n", size, STARS_SIZE);
    100     return (FALSE);
    101   }
    102 
    103   byte = (char *) data;
    104   for (i = 0; i < nitems; i++, byte += size) {
    105     SWAP_WORD (0);   /* R */
    106     SWAP_WORD (4);   /* Y */
    107     SWAP_WORD (8);   /* M */
    108     SWAP_WORD (12);  /* dM */
    109     SWAP_WORD (16);  /* Mgal */
    110     SWAP_WORD (20);  /* Map */
    111     SWAP_WORD (24);  /* sky */
    112     SWAP_WORD (28);  /* fx */
    113     SWAP_WORD (32);  /* fy */
    114     SWAP_WORD (36);  /* df */
    115   }
    116   return (TRUE);
    117 
    118 # else
    119   return (TRUE);
    120 # endif 
    121 }
    122 
Note: See TracChangeset for help on using the changeset viewer.