IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33648


Ignore:
Timestamp:
Apr 1, 2012, 2:22:08 PM (14 years ago)
Author:
eugene
Message:

fix byteswap error for 64bit tables (simplify byteswap code generally to clean up); add function to get type of specified column by seq number; defaults for Bzero and Bscale in tables without temp (0.0,1.0); function to set a bintable column from a vector of different type; better error handling for F_print,F_modify

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

Legend:

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

    r28246 r33648  
    7070  /* string value.  Quotes must be at least 18 chars apart */
    7171  if (!strcmp (mode, "%s")) {
    72     strncpy (data, va_arg (argp, char *), 68);
     72    char *ptr = va_arg (argp, char *);
     73    if (!ptr) goto invalid;
     74    strncpy (data, ptr, 68);
    7375    snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment);
    7476    goto found_it;
     
    7678
    7779  /* failed to find mode */
     80invalid:
     81  va_end (argp);
    7882  return (FALSE);
    7983
     
    8286  va_end (argp);
    8387  return (TRUE);
    84 
    8588}
    8689
     
    143146  /* comment type of value.  */
    144147  if (!strcmp (mode, "%S")) {
    145     strncpy (data, va_arg (argp, char *), 71);
     148    char *ptr = va_arg (argp, char *);
     149    if (!ptr) goto invalid;
     150    strncpy (data, ptr, 71);
    146151    snprintf (string, 81, "%-8s %-71s", field, data);
    147152  } 
     
    157162
    158163    strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
    159     strncpy (comment, va_arg (argp, char *), 80);
     164
     165    char *ptr = va_arg (argp, char *);
     166    if (!ptr) goto invalid;
     167    strncpy (comment, ptr, 80);
    160168    gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
    161169    snprintf (string, 81, "%-8s= %s / %-s", field, data, comment);
     
    167175  return (TRUE);
    168176
     177invalid:
     178  va_end (argp);
     179  return (FALSE);
    169180}
    170181
  • trunk/Ohana/src/libfits/header/F_print.c

    r28246 r33648  
    6565  /* string value.  Quotes must be at least 18 chars apart.  Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */
    6666  if (!strcmp (mode, "%s")) {
    67     strcpy (line, va_arg (argp, char *));
     67    char *ptr = va_arg (argp, char *);
     68    if (!ptr) goto invalid;
     69    strcpy (line, ptr);
    6870    line[68] = 0;
    6971    snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank);
    7072    goto found_it;
    7173  }
     74
     75invalid:
     76  va_end (argp);
    7277  return (FALSE);
    7378
     
    7681  va_end (argp);
    7782  return (TRUE);
    78 
    7983}
    8084
     
    130134  if (!strcmp (mode, "%S")) {
    131135    /* we are forcing the entry to be <= 69 char long */
    132     strcpy (line, va_arg (argp, char *));
    133     line[71] = 0;
     136    char *ptr = va_arg (argp, char *);
     137    if (!ptr) goto invalid;
     138    bzero (line, 80);
     139    strncpy (line, ptr, 71);
    134140    snprintf (string, 81, "%-8s %-71s", field, line);
    135141  } 
     
    146152
    147153  /* can't write the comment in gfits_print - use gfits_modify */
    148   if (!strcmp (mode, "%C")) return (FALSE);
     154  if (!strcmp (mode, "%C")) goto invalid;
    149155
    150156  strncpy (p, string, 80);
     
    153159  return (TRUE);
    154160
     161invalid:
     162  va_end (argp);
     163  return (FALSE);
    155164}
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r31663 r33648  
    184184int     gfits_get_bintable_column      PROTO((Header *header, FTable *table, char *label, void **data));
    185185int     gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval));
     186int     gfits_get_bintable_column_type_by_N  PROTO((Header *header, int N, char *type, int *Nval));
    186187void   *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));
    187188int     gfits_get_table_column         PROTO((Header *header, FTable *table, char *label, void **data));
     
    190191int     gfits_read_table               PROTO((char *filename, FTable *ftable));
    191192int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
     193int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow));
    192194int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    193195int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
  • trunk/Ohana/src/libfits/matrix/F_compress_M.c

    r28241 r33648  
    424424int gfits_byteswap_zdata (char *zdata, int Nzdata, int pixsize) {
    425425
     426# define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
     427
    426428# ifdef BYTE_SWAP
    427429
    428430  int i;
    429   char tmp;
    430431
    431432  switch (pixsize) {
     
    435436    case 2:
    436437      for (i = 0; i < 2*Nzdata; i+=2) {
    437         tmp = zdata[i];
    438         zdata[i] = zdata[i+1];
    439         zdata[i+1] = tmp;
     438        DOSWAP (zdata[i+0], zdata[i+1]);
    440439      }
    441440      break;
     
    443442    case 4:
    444443      for (i = 0; i < 4*Nzdata; i+=4) {
    445         tmp = zdata[i+1];
    446         zdata[i+1] = zdata[i+2];
    447         zdata[i+2] = tmp;
    448         tmp = zdata[i];
    449         zdata[i] = zdata[i+3];
    450         zdata[i+3] = tmp;
     444        DOSWAP (zdata[i+0], zdata[i+3]);
     445        DOSWAP (zdata[i+1], zdata[i+2]);
    451446      }
    452447      break;
     
    454449    case 8:
    455450      for (i = 0; i < 8*Nzdata; i+=8) {
    456         tmp = zdata[i+0];
    457         zdata[i+0] = zdata[i+7];
    458         zdata[i+7] = tmp;
    459         tmp = zdata[i+1];
    460         zdata[i+1] = zdata[i+6];
    461         zdata[i+6] = tmp;
    462         tmp = zdata[i+2];
    463         zdata[i+2] = zdata[i+5];
    464         zdata[i+5] = tmp;
    465         tmp = zdata[i+3];
    466         zdata[i+3] = zdata[i+4];
    467         zdata[i+4] = tmp;
     451        DOSWAP (zdata[i+0], zdata[i+7]);
     452        DOSWAP (zdata[i+1], zdata[i+6]);
     453        DOSWAP (zdata[i+2], zdata[i+5]);
     454        DOSWAP (zdata[i+3], zdata[i+4]);
    468455      }
    469456      break;
  • trunk/Ohana/src/libfits/matrix/F_load_M.c

    r28241 r33648  
    3838  }
    3939
     40# define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
     41
    4042# ifdef BYTE_SWAP 
    4143 {
    4244  int perpix;
    43   unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     45  unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7;
    4446
    4547  perpix = abs(header[0].bitpix) / 8;
     
    5557    if (perpix == 2) {
    5658      for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
    57         tmp = *byte0;
    58         *byte0 = *byte1;
    59         *byte1 = tmp;
     59        DOSWAP(*byte0, *byte1);
    6060      }
    6161    }
    6262    if (perpix == 4) {
    6363      for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
    64         tmp = *byte0;
    65         *byte0 = *byte3;
    66         *byte3 = tmp;
    67         tmp = *byte1;
    68         *byte1 = *byte2;
    69         *byte2 = tmp;
     64        DOSWAP (*byte0, *byte3);
     65        DOSWAP (*byte1, *byte2);
    7066      }
    7167    }
    7268    if (perpix == 8) {
    7369      for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
    74         tmp = *byte0;
    75         *byte0 = *byte7;
    76         *byte7 = tmp;
    77         tmp = *byte1;
    78         *byte1 = *byte6;
    79         *byte6 = tmp;
    80         tmp = *byte1;
    81         *byte2 = *byte5;
    82         *byte5 = tmp;
    83         tmp = *byte1;
    84         *byte3 = *byte4;
    85         *byte4 = tmp;
     70        DOSWAP (*byte0, *byte7);
     71        DOSWAP (*byte1, *byte6);
     72        DOSWAP (*byte2, *byte5);
     73        DOSWAP (*byte3, *byte4);
    8674      }
    8775    }
  • trunk/Ohana/src/libfits/matrix/F_read_portion.c

    r28241 r33648  
    5252  fclose (f);
    5353
     54# define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
     55
    5456# ifdef BYTE_SWAP 
    5557  {
    5658    off_t i;
    5759    int perpix;
    58     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
    59 
     60    unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7;
     61   
    6062    perpix = abs(header.bitpix) / 8;
    6163    if (perpix > 1) {
     
    7072      if (perpix == 2) {
    7173        for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
    72           ctmp = *byte0;
    73           *byte0 = *byte1;
    74           *byte1 = ctmp;
     74          DOSWAP(*byte0, *byte1);
    7575        }
    7676      }
    7777      if (perpix == 4) {
    7878        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;
     79          DOSWAP (*byte0, *byte3);
     80          DOSWAP (*byte1, *byte2);
    8581        }
    8682      }
    8783      if (perpix == 8) {
    8884        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;
     85          DOSWAP (*byte0, *byte7);
     86          DOSWAP (*byte1, *byte6);
     87          DOSWAP (*byte2, *byte5);
     88          DOSWAP (*byte3, *byte4);
    10189        }
    10290      }
  • trunk/Ohana/src/libfits/matrix/F_read_segment.c

    r28241 r33648  
    9595  matrix[0].datasize = Nbytes;
    9696
     97# define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
     98
    9799# ifdef BYTE_SWAP 
    98100 {
    99   unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, ctmp;
     101  unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7;
    100102  int perpix;
    101103
     
    112114    if (perpix == 2) {
    113115      for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
    114         ctmp = *byte0;
    115         *byte0 = *byte1;
    116         *byte1 = ctmp;
     116        DOSWAP(*byte0, *byte1);
    117117      }
    118118    }
    119119    if (perpix == 4) {
    120120      for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
    121         ctmp = *byte0;
    122         *byte0 = *byte3;
    123         *byte3 = ctmp;
    124         ctmp = *byte1;
    125         *byte1 = *byte2;
    126         *byte2 = ctmp;
     121        DOSWAP (*byte0, *byte3);
     122        DOSWAP (*byte1, *byte2);
    127123      }
    128124    }
    129125    if (perpix == 8) {
    130126      for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
    131         ctmp = *byte0;
    132         *byte0 = *byte7;
    133         *byte7 = ctmp;
    134         ctmp = *byte1;
    135         *byte1 = *byte6;
    136         *byte6 = ctmp;
    137         ctmp = *byte1;
    138         *byte2 = *byte5;
    139         *byte5 = ctmp;
    140         ctmp = *byte1;
    141         *byte3 = *byte4;
    142         *byte4 = ctmp;
     127        DOSWAP (*byte0, *byte7);
     128        DOSWAP (*byte1, *byte6);
     129        DOSWAP (*byte2, *byte5);
     130        DOSWAP (*byte3, *byte4);
    143131      }
    144132    }
  • trunk/Ohana/src/libfits/matrix/F_write_M.c

    r27435 r33648  
    3636    nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE));
    3737
     38# define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; }
     39
    3840  /* this is a bit cumbersome: swap all words, write out file, then swap back... */
    3941# ifdef BYTE_SWAP 
    4042  {
    4143    off_t i;
    42     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     44    unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7;
    4345    int perpix;
    4446
     
    5557      if (perpix == 2) {
    5658        for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
    57           tmp = *byte0;
    58           *byte0 = *byte1;
    59           *byte1 = tmp;
     59          DOSWAP(*byte0, *byte1);
    6060        }
    6161      }
    6262      if (perpix == 4) {
    6363        for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
    64           tmp = *byte0;
    65           *byte0 = *byte3;
    66           *byte3 = tmp;
    67           tmp = *byte1;
    68           *byte1 = *byte2;
    69           *byte2 = tmp;
     64          DOSWAP (*byte0, *byte3);
     65          DOSWAP (*byte1, *byte2);
    7066        }
    7167      }
    7268      if (perpix == 8) {
    7369        for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
    74           tmp = *byte0;
    75           *byte0 = *byte7;
    76           *byte7 = tmp;
    77           tmp = *byte1;
    78           *byte1 = *byte6;
    79           *byte6 = tmp;
    80           tmp = *byte1;
    81           *byte2 = *byte5;
    82           *byte5 = tmp;
    83           tmp = *byte1;
    84           *byte3 = *byte4;
    85           *byte4 = tmp;
     70          DOSWAP (*byte0, *byte7);
     71          DOSWAP (*byte1, *byte6);
     72          DOSWAP (*byte2, *byte5);
     73          DOSWAP (*byte3, *byte4);
    8674        }
    8775      }
     
    9886  {
    9987    off_t i;
    100     unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7, tmp;
     88    unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7;
    10189    int perpix;
    10290
     
    113101      if (perpix == 2) {
    114102        for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) {
    115           tmp = *byte0;
    116           *byte0 = *byte1;
    117           *byte1 = tmp;
     103          DOSWAP(*byte0, *byte1);
    118104        }
    119105      }
    120106      if (perpix == 4) {
    121107        for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) {
    122           tmp = *byte0;
    123           *byte0 = *byte3;
    124           *byte3 = tmp;
    125           tmp = *byte1;
    126           *byte1 = *byte2;
    127           *byte2 = tmp;
     108          DOSWAP (*byte0, *byte3);
     109          DOSWAP (*byte1, *byte2);
    128110        }
    129111      }
    130112      if (perpix == 8) {
    131113        for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) {
    132           tmp = *byte0;
    133           *byte0 = *byte7;
    134           *byte7 = tmp;
    135           tmp = *byte1;
    136           *byte1 = *byte6;
    137           *byte6 = tmp;
    138           tmp = *byte1;
    139           *byte2 = *byte5;
    140           *byte5 = tmp;
    141           tmp = *byte1;
    142           *byte3 = *byte4;
    143           *byte4 = tmp;
     114          DOSWAP (*byte0, *byte7);
     115          DOSWAP (*byte1, *byte6);
     116          DOSWAP (*byte2, *byte5);
     117          DOSWAP (*byte3, *byte4);
    144118        }
    145119      }
  • trunk/Ohana/src/libfits/table/F_define_column.c

    r28241 r33648  
    44/***********************/
    55int gfits_define_bintable_column (Header *header, char *format, char *label, char *comment, char *unit, double bscale, double bzero) {
     6
     7  assert (label);
     8  assert (format);
    69
    710  off_t Naxis1;
  • trunk/Ohana/src/libfits/table/F_get_column.c

    r31371 r33648  
    126126
    127127/***********************/
     128int gfits_get_bintable_column_type_by_N (Header *header, int N, char *type, int *Nval) {
     129
     130  int Nbytes;
     131  char field[80], format[80];
     132
     133  assert (N > 0);
     134
     135  sprintf (field, "TFORM%d", N);
     136  if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
     137  if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE);
     138  return (TRUE);
     139}
     140
     141/***********************/
    128142int gfits_get_bintable_column_type (Header *header, char *label, char *type, int *Nval) {
    129143
    130   int i, N, Nfields, Nbytes;
    131   char tlabel[80], field[80], format[80];
     144  int i, N, Nfields;
     145  char tlabel[80], field[80];
    132146
    133147  if (label == (char *) NULL) return (FALSE);
     
    144158  N = i - 1;
    145159
    146   sprintf (field, "TFORM%d", N);
    147   gfits_scan (header, field, "%s", 1, format);
    148 
    149   if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE);
     160  if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE;
    150161  return (TRUE);
    151162}
  • trunk/Ohana/src/libfits/table/F_set_column.c

    r31371 r33648  
    4040  /* interpret format */
    4141  sprintf (field, "TSCAL%d", N);
    42   gfits_scan (header, field, "%lf", 1, &Bscale);
     42  if (!gfits_scan (header, field, "%lf", 1, &Bscale)) {
     43    Bscale = 1.0;
     44  }
    4345  sprintf (field, "TZERO%d", N);
    44   gfits_scan (header, field, "%lf", 1, &Bzero);
     46  if (!gfits_scan (header, field, "%lf", 1, &Bzero)) {
     47    Bzero = 0.0;
     48  }
    4549  sprintf (field, "TFORM%d", N);
    4650  gfits_scan (header, field, "%s", 1, format);
     
    126130  for (i = 0; i < Nrow; i++, Pout += Nx, Pin += Nval*Nbytes) {
    127131    memcpy (Pout, Pin, Nval*Nbytes);
     132  }
     133
     134  free (array);
     135  return (TRUE);
     136}
     137
     138/***********************/
     139int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow) {
     140
     141  off_t Nx, Ny, nbytes;
     142  int i, N, Nfields;
     143  int Nval, NbytesOut, Nstart, Nv, Nb;
     144  char tlabel[80], field[80], format[80], outtype[16], tmpline[16];
     145  char *Pin, *Pout, *array;
     146  double Bscale, Bzero;
     147
     148  if (label == (char *) NULL) return (FALSE);
     149  if (label[0] == 0) return (FALSE);
     150
     151  /* find label in header */
     152  tlabel[0] = 0;
     153  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
     154  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
     155    sprintf (field, "TTYPE%d", i);
     156    gfits_scan (header, field, "%s", 1, tlabel);
     157  }
     158  if (strcasecmp (label, tlabel)) return (FALSE);
     159  N = i - 1;
     160
     161  /* interpret format */
     162  sprintf (field, "TSCAL%d", N);
     163  if (!gfits_scan (header, field, "%lf", 1, &Bscale)) {
     164    Bscale = 1.0;
     165  }
     166  sprintf (field, "TZERO%d", N);
     167  if (!gfits_scan (header, field, "%lf", 1, &Bzero)) {
     168    Bzero = 0.0;
     169  }
     170  sprintf (field, "TFORM%d", N);
     171  gfits_scan (header, field, "%s", 1, format);
     172
     173  if (!gfits_bintable_format (format, outtype, &Nval, &NbytesOut)) return (FALSE);
     174 
     175  /* check existing table dimensions */
     176  gfits_scan (header, "NAXIS1", OFF_T_FMT, 1,  &Nx);
     177  gfits_scan (header, "NAXIS2", OFF_T_FMT, 1,  &Ny);
     178  if (Ny == 0) {
     179    Ny = Nrow;
     180    header[0].Naxis[1] = Ny;
     181    gfits_modify (header, "NAXIS2", OFF_T_FMT, 1,  Ny);
     182
     183    nbytes = gfits_data_size (header);
     184    REALLOCATE (table[0].buffer, char, MAX (nbytes, 1));
     185    bzero (table[0].buffer, nbytes);
     186    table[0].datasize = nbytes;
     187  }
     188  if (Ny != Nrow) return (FALSE);
     189
     190  /* scan columns to find insert point */
     191  Nstart = 0;
     192  for (i = 1; i < N; i++) {
     193    sprintf (field, "TFORM%d", i);
     194    gfits_scan (header, field, "%s", 1, format);
     195    gfits_bintable_format (format, tmpline, &Nv, &Nb);
     196    Nstart += Nv*Nb;
     197  }
     198
     199  /* make duplicate of data with correct type
     200     byte swap and Bzero/Bscale */
     201  ALLOCATE (array, char, NbytesOut*Nval*Nrow);
     202  Pin = data;
     203  Pout = array;
     204
     205  /** input == char **/
     206  if (!strcmp (outtype, "char") && !strcmp (intype, "char")) {
     207    int NbytesIn = 1;
     208    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     209      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     210    }
     211  }
     212  if (!strcmp (outtype, "short") && !strcmp (intype, "char")) {
     213    int NbytesIn = 1;
     214    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     215      *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
     216# ifdef BYTE_SWAP
     217      SWAP_BYTE;
     218# endif
     219    } 
     220  }
     221  if (!strcmp (outtype, "int") && !strcmp (intype, "char")) {
     222    int NbytesIn = 1;
     223    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     224      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
     225# ifdef BYTE_SWAP
     226      SWAP_WORD;
     227# endif
     228    }
     229  }
     230  if (!strcmp (outtype, "float") && !strcmp (intype, "char")) {
     231    int NbytesIn = 1;
     232    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     233      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
     234# ifdef BYTE_SWAP
     235      SWAP_WORD;
     236# endif
     237    }
     238  }
     239  if (!strcmp (outtype, "double") && !strcmp (intype, "char")) {
     240    int NbytesIn = 1;
     241    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     242      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
     243# ifdef BYTE_SWAP
     244      SWAP_DBLE;
     245# endif
     246    }
     247  }
     248
     249  /** input == short **/
     250  if (!strcmp (outtype, "char") && !strcmp (intype, "short")) {
     251    int NbytesIn = 2;
     252    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     253      *(char *)Pout = (*(short *)Pin - Bzero) / Bscale;
     254    }
     255  }
     256  if (!strcmp (outtype, "short") && !strcmp (intype, "short")) {
     257    int NbytesIn = 2;
     258    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     259      *(short *)Pout = (*(short *)Pin - Bzero) / Bscale;
     260# ifdef BYTE_SWAP
     261      SWAP_BYTE;
     262# endif
     263    } 
     264  }
     265  if (!strcmp (outtype, "int") && !strcmp (intype, "short")) {
     266    int NbytesIn = 2;
     267    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     268      *(int *)Pout = (*(short *)Pin - Bzero) / Bscale;
     269# ifdef BYTE_SWAP
     270      SWAP_WORD;
     271# endif
     272    }
     273  }
     274  if (!strcmp (outtype, "float") && !strcmp (intype, "short")) {
     275    int NbytesIn = 2;
     276    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     277      *(float *)Pout = (*(short *)Pin - Bzero) / Bscale;
     278# ifdef BYTE_SWAP
     279      SWAP_WORD;
     280# endif
     281    }
     282  }
     283  if (!strcmp (outtype, "double") && !strcmp (intype, "short")) {
     284    int NbytesIn = 2;
     285    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     286      *(double *)Pout = (*(short *)Pin - Bzero) / Bscale;
     287# ifdef BYTE_SWAP
     288      SWAP_DBLE;
     289# endif
     290    }
     291  }
     292
     293  /** input == int **/
     294  if (!strcmp (outtype, "char") && !strcmp (intype, "int")) {
     295    int NbytesIn = 4;
     296    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     297      *(char *)Pout = (*(int *)Pin - Bzero) / Bscale;
     298    }
     299  }
     300  if (!strcmp (outtype, "short") && !strcmp (intype, "int")) {
     301    int NbytesIn = 4;
     302    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     303      *(short *)Pout = (*(int *)Pin - Bzero) / Bscale;
     304# ifdef BYTE_SWAP
     305      SWAP_BYTE;
     306# endif
     307    } 
     308  }
     309  if (!strcmp (outtype, "int") && !strcmp (intype, "int")) {
     310    int NbytesIn = 4;
     311    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     312      *(int *)Pout = (*(int *)Pin - Bzero) / Bscale;
     313# ifdef BYTE_SWAP
     314      SWAP_WORD;
     315# endif
     316    }
     317  }
     318  if (!strcmp (outtype, "float") && !strcmp (intype, "int")) {
     319    int NbytesIn = 4;
     320    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     321      *(float *)Pout = (*(int *)Pin - Bzero) / Bscale;
     322# ifdef BYTE_SWAP
     323      SWAP_WORD;
     324# endif
     325    }
     326  }
     327  if (!strcmp (outtype, "double") && !strcmp (intype, "int")) {
     328    int NbytesIn = 4;
     329    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     330      *(double *)Pout = (*(int *)Pin - Bzero) / Bscale;
     331# ifdef BYTE_SWAP
     332      SWAP_DBLE;
     333# endif
     334    }
     335  }
     336
     337  /** input == float **/
     338  if (!strcmp (outtype, "char") && !strcmp (intype, "float")) {
     339    int NbytesIn = 4;
     340    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     341      *(char *)Pout = (*(float *)Pin - Bzero) / Bscale;
     342    }
     343  }
     344  if (!strcmp (outtype, "short") && !strcmp (intype, "float")) {
     345    int NbytesIn = 4;
     346    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     347      *(short *)Pout = (*(float *)Pin - Bzero) / Bscale;
     348# ifdef BYTE_SWAP
     349      SWAP_BYTE;
     350# endif
     351    } 
     352  }
     353  if (!strcmp (outtype, "int") && !strcmp (intype, "float")) {
     354    int NbytesIn = 4;
     355    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     356      *(int *)Pout = (*(float *)Pin - Bzero) / Bscale;
     357# ifdef BYTE_SWAP
     358      SWAP_WORD;
     359# endif
     360    }
     361  }
     362  if (!strcmp (outtype, "float") && !strcmp (intype, "float")) {
     363    int NbytesIn = 4;
     364    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     365      *(float *)Pout = (*(float *)Pin - Bzero) / Bscale;
     366# ifdef BYTE_SWAP
     367      SWAP_WORD;
     368# endif
     369    }
     370  }
     371  if (!strcmp (outtype, "double") && !strcmp (intype, "float")) {
     372    int NbytesIn = 4;
     373    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     374      *(double *)Pout = (*(float *)Pin - Bzero) / Bscale;
     375# ifdef BYTE_SWAP
     376      SWAP_DBLE;
     377# endif
     378    }
     379  }
     380
     381  /** input == double **/
     382  if (!strcmp (outtype, "char") && !strcmp (intype, "double")) {
     383    int NbytesIn = 8;
     384    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     385      *(char *)Pout = (*(double *)Pin - Bzero) / Bscale;
     386    }
     387  }
     388  if (!strcmp (outtype, "short") && !strcmp (intype, "double")) {
     389    int NbytesIn = 8;
     390    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     391      *(short *)Pout = (*(double *)Pin - Bzero) / Bscale;
     392# ifdef BYTE_SWAP
     393      SWAP_BYTE;
     394# endif
     395    } 
     396  }
     397  if (!strcmp (outtype, "int") && !strcmp (intype, "double")) {
     398    int NbytesIn = 8;
     399    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     400      *(int *)Pout = (*(double *)Pin - Bzero) / Bscale;
     401# ifdef BYTE_SWAP
     402      SWAP_WORD;
     403# endif
     404    }
     405  }
     406  if (!strcmp (outtype, "float") && !strcmp (intype, "double")) {
     407    int NbytesIn = 8;
     408    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     409      *(float *)Pout = (*(double *)Pin - Bzero) / Bscale;
     410# ifdef BYTE_SWAP
     411      SWAP_WORD;
     412# endif
     413    }
     414  }
     415  if (!strcmp (outtype, "double") && !strcmp (intype, "double")) {
     416    int NbytesIn = 8;
     417    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     418      *(double *)Pout = (*(double *)Pin - Bzero) / Bscale;
     419# ifdef BYTE_SWAP
     420      SWAP_DBLE;
     421# endif
     422    }
     423  }
     424
     425  /* check array space */
     426  if (Nx*Ny < Nx*(Nrow - 1) + Nstart + Nval*NbytesOut) {
     427    fprintf (stderr, "mismatch in array sizes\n");
     428    return (FALSE);
     429  }
     430
     431  /* insert bytes from array into appropriate section of buffer */
     432  Pout = table[0].buffer + Nstart;
     433  Pin  = array;
     434  for (i = 0; i < Nrow; i++, Pout += Nx, Pin += Nval*NbytesOut) {
     435    memcpy (Pout, Pin, Nval*NbytesOut);
    128436  }
    129437
Note: See TracChangeset for help on using the changeset viewer.