IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 12, 2015, 6:18:23 PM (11 years ago)
Author:
eugene
Message:

merge changes from EAM dev branch ohana.20150429

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libfits/table/F_get_column.c

    r37039 r38441  
    1717
    1818void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol) {
     19  void *data = gfits_get_bintable_column_data_raw (header, table, label, type, Nrow, Ncol, FALSE);
     20  return data;
     21}
     22
     23void *gfits_get_bintable_column_data_raw (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder) {
    1924
    2025  off_t Nx, Ny;
     
    7176  }
    7277
    73   /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
     78  // NOTE: we have already copied the data to 'array', so the blocks below
     79  // only need to swap if this is a direct copy
    7480  Pin  = array;
    7581  Pout = array;
     82  int directCopy = (Bzero == 0.0) && (Bscale == 1.0);
     83
     84  /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
    7685  if (!strcmp (type, "char")) {
    7786    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    78       *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     87      if (!directCopy) { *(char *)Pout = *(char *)Pin*Bscale + Bzero; }
    7988    }
    8089  }
    8190  if (!strcmp (type, "byte")) {
    8291    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    83       *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     92      if (!directCopy) { *(char *)Pout = *(char *)Pin*Bscale + Bzero; }
    8493    }
    8594  }
     
    8796    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    8897# ifdef BYTE_SWAP
    89       SWAP_BYTE;
    90 # endif
    91       *(short *)Pout = *(short *)Pin*Bscale + Bzero;
     98      if (!nativeOrder) { SWAP_BYTE; }
     99# endif
     100      if (!directCopy) { *(short *)Pout = *(short *)Pin*Bscale + Bzero; }
    92101    } 
    93102  }
     
    95104    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    96105# ifdef BYTE_SWAP
    97       SWAP_WORD;
    98 # endif
    99       *(int *)Pout = *(int *)Pin*Bscale + Bzero;
     106      if (!nativeOrder) { SWAP_WORD; }
     107# endif
     108      if (!directCopy) { *(int *)Pout = *(int *)Pin*Bscale + Bzero; }
    100109    }
    101110  }
    102111  if (!strcmp (type, "int64_t")) {
    103     if ((Bzero == 0.0) && (Bscale == 1.0)) {
    104       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    105 # ifdef BYTE_SWAP
    106         SWAP_DBLE;
    107 # endif
    108         *(int64_t *)Pout = *(int64_t *)Pin;
    109       }
    110     } else {
    111       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    112 # ifdef BYTE_SWAP
    113         SWAP_DBLE;
    114 # endif
    115         *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
    116       }
     112    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     113# ifdef BYTE_SWAP
     114      if (!nativeOrder) { SWAP_DBLE; }
     115# endif
     116      if (!directCopy) { *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero; }
    117117    }
    118118  }
     
    120120    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    121121# ifdef BYTE_SWAP
    122       SWAP_WORD;
    123 # endif
    124       *(float *)Pout = *(float *)Pin*Bscale + Bzero;
     122      if (!nativeOrder) { SWAP_WORD; }
     123# endif
     124      if (!directCopy) { *(float *)Pout = *(float *)Pin*Bscale + Bzero; }
    125125    }
    126126  }
     
    128128    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    129129# ifdef BYTE_SWAP
    130       SWAP_DBLE;
    131 # endif
    132       *(double *)Pout = *(double *)Pin*Bscale + Bzero;
    133     }
    134   }
     130      if (!nativeOrder) { SWAP_DBLE; }
     131# endif
     132      if (!directCopy) { *(double *)Pout = *(double *)Pin*Bscale + Bzero; }
     133    }
     134  }
     135
     136  // check that we supplied a valid type
    135137
    136138  *Ncol = Nval;
     
    174176  if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE;
    175177  return (TRUE);
     178}
     179
     180/***********************/
     181int gfits_get_bintable_column_raw (Header *header, FTable *table, char *label, void **data, char nativeOrder) {
     182
     183  char type[16];
     184  off_t Nrow;
     185  int Ncol;
     186
     187  char *array = gfits_get_bintable_column_data_raw (header, table, label, type, &Nrow, &Ncol, nativeOrder);
     188  if (array == NULL) return (FALSE);
     189
     190  *data = array;
     191  return TRUE;
    176192}
    177193
Note: See TracChangeset for help on using the changeset viewer.