IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41136


Ignore:
Timestamp:
Nov 25, 2019, 4:39:53 PM (7 years ago)
Author:
eugene
Message:

extend fits vector output to allow for multi-value fields

Location:
branches/eam_branches/ipp-20191011/Ohana/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011/Ohana/src/libfits/include/gfitsio.h

    r39460 r41136  
    259259int     gfits_read_table               PROTO((char *filename, FTable *ftable));
    260260int     gfits_set_bintable_column      PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    261 int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder));
     261int     gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, int element, char nativeOrder));
    262262int     gfits_set_table_column         PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow));
    263263int     gfits_table_column             PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4);
  • branches/eam_branches/ipp-20191011/Ohana/src/libfits/table/F_define_column.c

    r38553 r41136  
    5656  char type[64], field[64];
    5757 
     58  // this call supported multiple columns per named field
    5859  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
    5960 
  • branches/eam_branches/ipp-20191011/Ohana/src/libfits/table/F_set_column.c

    r39993 r41136  
    253253/***********************/
    254254// convert the input data array (of the specified intype) to the desired table data type. swap unless nativeOrder is requested
    255 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder) {
     255int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, int element, char nativeOrder) {
    256256
    257257  off_t Nx, Ny;
     
    288288
    289289  if (!gfits_bintable_format (format, outtype, &Nval, &NbytesOut)) return (FALSE);
     290  if (element >= Nval) {
     291    fprintf (stderr, "programming error: element >= Nval for field %s, format %s\n", label, format);
     292    return FALSE;
     293  }
    290294 
    291295  /* check existing table dimensions */
     
    307311  }
    308312
     313  // NOTE: we are inserting a single column into the output
     314  // table.  If the output field is multi-value, the resulting
     315  // array is inserted into the appropriate bytes in that output field
     316
    309317  /* make duplicate of data with correct type
    310318     byte swap and Bzero/Bscale */
    311   ALLOCATE (array, char, NbytesOut*Nval*Nrow);
     319  ALLOCATE (array, char, NbytesOut*Nrow);
    312320  Pin = data;
    313   Pout = array;
     321  Pout = array; //
    314322
    315323  // # define ASSIGN_DATA(ITYPE,INAME,ISIZE,OTYPE,ONAME)
     
    321329  if (!strcmp (outtype, OUTNAME) && !strcmp (intype, INNAME)) {         \
    322330    int NbytesIn = NBYTES_IN;                                           \
    323     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { \
     331    for (i = 0; i < Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { \
    324332      if (directCopy) {                                                 \
    325333        *(OUTTYPE *)Pout = *(INTYPE *)Pin;                              \
     
    385393  SET_VALUES("double",   double, "double", double, SWAP_DBLE, 8);
    386394
    387 # if (0)
    388   /** input == char **/
    389   if (!strcmp (outtype, "char") && !strcmp (intype, "char")) {
    390     int NbytesIn = 1;
    391     for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
    392       if (directCopy) { *(char *)Pout = *(char *)Pin; } else {
    393         *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
    394       }
    395     }
    396   }
    397   if (!strcmp (outtype, "byte") && !strcmp (intype, "char")) {
    398     int NbytesIn = 1;
    399     for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
    400       if (directCopy) { *(char *)Pout = *(char *)Pin; } else {
    401         *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
    402       }
    403     }
    404   }
    405   if (!strcmp (outtype, "short") && !strcmp (intype, "char")) {
    406     int NbytesIn = 1;
    407     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    408       if (directCopy) { *(short *)Pout = *(char *)Pin; } else {
    409         *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
    410       }
    411 # ifdef BYTE_SWAP
    412       if (!nativeOrder) { SWAP_BYTE; }
    413 # endif
    414     } 
    415   }
    416   if (!strcmp (outtype, "int") && !strcmp (intype, "char")) {
    417     int NbytesIn = 1;
    418     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    419       *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
    420 # ifdef BYTE_SWAP
    421       if (!nativeOrder) { SWAP_WORD; }
    422 # endif
    423     }
    424   }
    425   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) {
    426     int NbytesIn = 1;
    427     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    428       *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
    429 # ifdef BYTE_SWAP
    430       if (!nativeOrder) { SWAP_DBLE; }
    431 # endif
    432     }
    433   }
    434   if (!strcmp (outtype, "float") && !strcmp (intype, "char")) {
    435     int NbytesIn = 1;
    436     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    437       *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
    438 # ifdef BYTE_SWAP
    439       if (!nativeOrder) { SWAP_WORD; }
    440 # endif
    441     }
    442   }
    443   if (!strcmp (outtype, "double") && !strcmp (intype, "char")) {
    444     int NbytesIn = 1;
    445     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    446       *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
    447 # ifdef BYTE_SWAP
    448       if (!nativeOrder) { SWAP_DBLE; }
    449 # endif
    450     }
    451   }
    452 
    453   /** input == byte **/
    454   if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) {
    455     int NbytesIn = 1;
    456     for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
    457       *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
    458     }
    459   }
    460   if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) {
    461     int NbytesIn = 1;
    462     for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
    463       *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
    464     }
    465   }
    466   if (!strcmp (outtype, "short") && !strcmp (intype, "byte")) {
    467     int NbytesIn = 1;
    468     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    469       *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
    470 # ifdef BYTE_SWAP
    471       if (!nativeOrder) { SWAP_BYTE; }
    472 # endif
    473     } 
    474   }
    475   if (!strcmp (outtype, "int") && !strcmp (intype, "byte")) {
    476     int NbytesIn = 1;
    477     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    478       *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
    479 # ifdef BYTE_SWAP
    480       if (!nativeOrder) { SWAP_WORD; }
    481 # endif
    482     }
    483   }
    484   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "byte")) {
    485     int NbytesIn = 1;
    486     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    487       *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
    488 # ifdef BYTE_SWAP
    489       if (!nativeOrder) { SWAP_DBLE; }
    490 # endif
    491     }
    492   }
    493   if (!strcmp (outtype, "float") && !strcmp (intype, "byte")) {
    494     int NbytesIn = 1;
    495     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    496       *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
    497 # ifdef BYTE_SWAP
    498       if (!nativeOrder) { SWAP_WORD; }
    499 # endif
    500     }
    501   }
    502   if (!strcmp (outtype, "double") && !strcmp (intype, "byte")) {
    503     int NbytesIn = 1;
    504     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    505       *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
    506 # ifdef BYTE_SWAP
    507       if (!nativeOrder) { SWAP_DBLE; }
    508 # endif
    509     }
    510   }
    511 
    512   /** input == short **/
    513   if (!strcmp (outtype, "char") && !strcmp (intype, "short")) {
    514     int NbytesIn = 2;
    515     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    516       *(char *)Pout = (*(short *)Pin - Bzero) / Bscale;
    517     }
    518   }
    519   if (!strcmp (outtype, "byte") && !strcmp (intype, "short")) {
    520     int NbytesIn = 2;
    521     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    522       *(char *)Pout = (*(short *)Pin - Bzero) / Bscale;
    523     }
    524   }
    525   if (!strcmp (outtype, "short") && !strcmp (intype, "short")) {
    526     int NbytesIn = 2;
    527     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    528       *(short *)Pout = (*(short *)Pin - Bzero) / Bscale;
    529 # ifdef BYTE_SWAP
    530       if (!nativeOrder) { SWAP_BYTE; }
    531 # endif
    532     } 
    533   }
    534   if (!strcmp (outtype, "int") && !strcmp (intype, "short")) {
    535     int NbytesIn = 2;
    536     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    537       *(int *)Pout = (*(short *)Pin - Bzero) / Bscale;
    538 # ifdef BYTE_SWAP
    539       if (!nativeOrder) { SWAP_WORD; }
    540 # endif
    541     }
    542   }
    543   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "short")) {
    544     int NbytesIn = 2;
    545     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    546       *(int64_t *)Pout = (*(short *)Pin - Bzero) / Bscale;
    547 # ifdef BYTE_SWAP
    548       if (!nativeOrder) { SWAP_DBLE; }
    549 # endif
    550     }
    551   }
    552   if (!strcmp (outtype, "float") && !strcmp (intype, "short")) {
    553     int NbytesIn = 2;
    554     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    555       *(float *)Pout = (*(short *)Pin - Bzero) / Bscale;
    556 # ifdef BYTE_SWAP
    557       if (!nativeOrder) { SWAP_WORD; }
    558 # endif
    559     }
    560   }
    561   if (!strcmp (outtype, "double") && !strcmp (intype, "short")) {
    562     int NbytesIn = 2;
    563     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    564       *(double *)Pout = (*(short *)Pin - Bzero) / Bscale;
    565 # ifdef BYTE_SWAP
    566       if (!nativeOrder) { SWAP_DBLE; }
    567 # endif
    568     }
    569   }
    570 
    571   /** input == int **/
    572   if (!strcmp (outtype, "char") && !strcmp (intype, "int")) {
    573     int NbytesIn = 4;
    574     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    575       *(char *)Pout = (*(int *)Pin - Bzero) / Bscale;
    576     }
    577   }
    578   if (!strcmp (outtype, "byte") && !strcmp (intype, "int")) {
    579     int NbytesIn = 4;
    580     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    581       *(char *)Pout = (*(int *)Pin - Bzero) / Bscale;
    582     }
    583   }
    584   if (!strcmp (outtype, "short") && !strcmp (intype, "int")) {
    585     int NbytesIn = 4;
    586     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    587       *(short *)Pout = (*(int *)Pin - Bzero) / Bscale;
    588 # ifdef BYTE_SWAP
    589       if (!nativeOrder) { SWAP_BYTE; }
    590 # endif
    591     } 
    592   }
    593   if (!strcmp (outtype, "int") && !strcmp (intype, "int")) {
    594     int NbytesIn = 4;
    595     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    596       *(int *)Pout = (*(int *)Pin - Bzero) / Bscale;
    597 # ifdef BYTE_SWAP
    598       if (!nativeOrder) { SWAP_WORD; }
    599 # endif
    600     }
    601   }
    602   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "int")) {
    603     int NbytesIn = 4;
    604     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    605       *(int64_t *)Pout = (*(int *)Pin - Bzero) / Bscale;
    606 # ifdef BYTE_SWAP
    607       if (!nativeOrder) { SWAP_DBLE; }
    608 # endif
    609     }
    610   }
    611   if (!strcmp (outtype, "float") && !strcmp (intype, "int")) {
    612     int NbytesIn = 4;
    613     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    614       *(float *)Pout = (*(int *)Pin - Bzero) / Bscale;
    615 # ifdef BYTE_SWAP
    616       if (!nativeOrder) { SWAP_WORD; }
    617 # endif
    618     }
    619   }
    620   if (!strcmp (outtype, "double") && !strcmp (intype, "int")) {
    621     int NbytesIn = 4;
    622     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    623       *(double *)Pout = (*(int *)Pin - Bzero) / Bscale;
    624 # ifdef BYTE_SWAP
    625       if (!nativeOrder) { SWAP_DBLE; }
    626 # endif
    627     }
    628   }
    629 
    630   /** input == int64_t **/
    631   if (!strcmp (outtype, "char") && !strcmp (intype, "int64_t")) {
    632     int NbytesIn = 8;
    633     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    634       *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    635     }
    636   }
    637   if (!strcmp (outtype, "byte") && !strcmp (intype, "int64_t")) {
    638     int NbytesIn = 8;
    639     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    640       *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    641     }
    642   }
    643   if (!strcmp (outtype, "short") && !strcmp (intype, "int64_t")) {
    644     int NbytesIn = 8;
    645     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    646       *(short *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    647 # ifdef BYTE_SWAP
    648       if (!nativeOrder) { SWAP_BYTE; }
    649 # endif
    650     } 
    651   }
    652   if (!strcmp (outtype, "int") && !strcmp (intype, "int64_t")) {
    653     int NbytesIn = 8;
    654     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    655       *(int *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    656 # ifdef BYTE_SWAP
    657       if (!nativeOrder) { SWAP_WORD; }
    658 # endif
    659     }
    660   }
    661   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "int64_t")) {
    662     int NbytesIn = 8;
    663     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    664       *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    665 # ifdef BYTE_SWAP
    666       if (!nativeOrder) { SWAP_DBLE; }
    667 # endif
    668     }
    669   }
    670   if (!strcmp (outtype, "float") && !strcmp (intype, "int64_t")) {
    671     int NbytesIn = 8;
    672     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    673       *(float *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    674 # ifdef BYTE_SWAP
    675       if (!nativeOrder) { SWAP_WORD; }
    676 # endif
    677     }
    678   }
    679   if (!strcmp (outtype, "double") && !strcmp (intype, "int64_t")) {
    680     int NbytesIn = 8;
    681     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    682       *(double *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    683 # ifdef BYTE_SWAP
    684       if (!nativeOrder) { SWAP_DBLE; }
    685 # endif
    686     }
    687   }
    688 
    689   /** input == float **/
    690   if (!strcmp (outtype, "char") && !strcmp (intype, "float")) {
    691     int NbytesIn = 4;
    692     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    693       *(char *)Pout = (*(float *)Pin - Bzero) / Bscale;
    694     }
    695   }
    696   if (!strcmp (outtype, "byte") && !strcmp (intype, "float")) {
    697     int NbytesIn = 4;
    698     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    699       *(char *)Pout = (*(float *)Pin - Bzero) / Bscale;
    700     }
    701   }
    702   if (!strcmp (outtype, "short") && !strcmp (intype, "float")) {
    703     int NbytesIn = 4;
    704     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    705       *(short *)Pout = (*(float *)Pin - Bzero) / Bscale;
    706 # ifdef BYTE_SWAP
    707       if (!nativeOrder) { SWAP_BYTE; }
    708 # endif
    709     } 
    710   }
    711   if (!strcmp (outtype, "int") && !strcmp (intype, "float")) {
    712     int NbytesIn = 4;
    713     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    714       *(int *)Pout = (*(float *)Pin - Bzero) / Bscale;
    715 # ifdef BYTE_SWAP
    716       if (!nativeOrder) { SWAP_WORD; }
    717 # endif
    718     }
    719   }
    720   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "float")) {
    721     int NbytesIn = 4;
    722     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    723       *(int64_t *)Pout = (*(float *)Pin - Bzero) / Bscale;
    724 # ifdef BYTE_SWAP
    725       if (!nativeOrder) { SWAP_DBLE; }
    726 # endif
    727     }
    728   }
    729   if (!strcmp (outtype, "float") && !strcmp (intype, "float")) {
    730     int NbytesIn = 4;
    731     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    732       *(float *)Pout = (*(float *)Pin - Bzero) / Bscale;
    733 # ifdef BYTE_SWAP
    734       if (!nativeOrder) { SWAP_WORD; }
    735 # endif
    736     }
    737   }
    738   if (!strcmp (outtype, "double") && !strcmp (intype, "float")) {
    739     int NbytesIn = 4;
    740     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    741       *(double *)Pout = (*(float *)Pin - Bzero) / Bscale;
    742 # ifdef BYTE_SWAP
    743       if (!nativeOrder) { SWAP_DBLE; }
    744 # endif
    745     }
    746   }
    747 
    748   /** input == double **/
    749   if (!strcmp (outtype, "char") && !strcmp (intype, "double")) {
    750     int NbytesIn = 8;
    751     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    752       *(char *)Pout = (*(double *)Pin - Bzero) / Bscale;
    753     }
    754   }
    755   if (!strcmp (outtype, "byte") && !strcmp (intype, "double")) {
    756     int NbytesIn = 8;
    757     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    758       *(char *)Pout = (*(double *)Pin - Bzero) / Bscale;
    759     }
    760   }
    761   if (!strcmp (outtype, "short") && !strcmp (intype, "double")) {
    762     int NbytesIn = 8;
    763     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    764       *(short *)Pout = (*(double *)Pin - Bzero) / Bscale;
    765 # ifdef BYTE_SWAP
    766       if (!nativeOrder) { SWAP_BYTE; }
    767 # endif
    768     } 
    769   }
    770   if (!strcmp (outtype, "int") && !strcmp (intype, "double")) {
    771     int NbytesIn = 8;
    772     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    773       *(int *)Pout = (*(double *)Pin - Bzero) / Bscale;
    774 # ifdef BYTE_SWAP
    775       if (!nativeOrder) { SWAP_WORD; }
    776 # endif
    777     }
    778   }
    779   if (!strcmp (outtype, "int64_t") && !strcmp (intype, "double")) {
    780     int NbytesIn = 8;
    781     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    782       *(int64_t *)Pout = (*(double *)Pin - Bzero) / Bscale;
    783 # ifdef BYTE_SWAP
    784       if (!nativeOrder) { SWAP_DBLE; }
    785 # endif
    786     }
    787   }
    788   if (!strcmp (outtype, "float") && !strcmp (intype, "double")) {
    789     int NbytesIn = 8;
    790     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    791       *(float *)Pout = (*(double *)Pin - Bzero) / Bscale;
    792 # ifdef BYTE_SWAP
    793       if (!nativeOrder) { SWAP_WORD; }
    794 # endif
    795     }
    796   }
    797   if (!strcmp (outtype, "double") && !strcmp (intype, "double")) {
    798     int NbytesIn = 8;
    799     for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    800       *(double *)Pout = (*(double *)Pin - Bzero) / Bscale;
    801 # ifdef BYTE_SWAP
    802       if (!nativeOrder) { SWAP_DBLE; }
    803 # endif
    804     }
    805   }
    806 # endif
    807 
    808395  /* check array space */
    809396  if (Nx*Ny < Nx*(Nrow - 1) + Nstart + Nval*NbytesOut) {
     
    813400
    814401  /* insert bytes from array into appropriate section of buffer */
    815   Pout = table[0].buffer + Nstart;
     402  Pout = table[0].buffer + Nstart + element*NbytesOut;
    816403  Pin  = array;
    817   for (i = 0; i < Nrow; i++, Pout += Nx, Pin += Nval*NbytesOut) {
    818     memcpy (Pout, Pin, Nval*NbytesOut);
     404  for (i = 0; i < Nrow; i++, Pout += Nx, Pin += NbytesOut) {
     405    memcpy (Pout, Pin, NbytesOut);
    819406  }
    820407
  • branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.data/SplineOps.c

    r38441 r41136  
    179179
    180180  // NOTE: if we want to compress the output table, use native byte order here (last element)
    181   gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots, FALSE);
    182   gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots, FALSE);
    183   gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots, FALSE);
     181  gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots, 0, FALSE);
     182  gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots, 0, FALSE);
     183  gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots, 0, FALSE);
    184184
    185185  if (!append) {
  • branches/eam_branches/ipp-20191011/Ohana/src/opihi/lib.shell/VectorIO.c

    r40291 r41136  
    77  int j;
    88
    9   char *tformat = NULL;
    10 
    119  Header *theader = ftable->header;
    1210  gfits_create_table_header (theader, "BINTABLE", extname);
    1311
    14   ALLOCATE (tformat, char, 2*Nvec);
     12  // allocate an array of strings to represent the format for each output field
     13  // formats include single column formats (BIJKDE) and multi-column formats (e.g., 2I)
     14  // we will have no more than Nvec fields (but we can have fewer)
     15  int Nfield = 0;
     16  ALLOCATE_PTR (tformat, char *, Nvec);
     17  ALLOCATE_PTR (Nelement, int, Nvec);
     18
    1519  if (format) {
    16     // the bintable format string can only define the byte-width of each field.  valid output columns are currently:
     20    // the bintable format string can defines the byte-width of each field and number of elements (columns per field).
     21    // valid output columns are currently:
    1722    // B (char), I (16 bit short), J (32 bit int), E (32 bit float), D (64 bit double).
    18     // the format string is just the sequence of types, eg: LIIJEED
    19     // validate the format string
     23    // the format string is just the sequence of types, eg: LIIJEED.
     24    // it may have spaces or integer element counts:
     25    // "2D 4I EEJ"
     26
     27    // *** validate the format string
     28
     29    // as I parse each elements, if it is a digit, I need parse that value
     30
    2031    char *ptr = format;
    21     for (j = 0; j < Nvec; j++) {
     32    for (j = 0; j < Nvec; ) {
    2233      while (*ptr && OHANA_WHITESPACE (*ptr)) ptr++;
    2334      if (*ptr == 0) {
     
    2536        goto escape;
    2637      }
     38
     39      // is there a leading integer?
     40      char *endptr;
     41      Nelement[Nfield] = strtol (ptr, &endptr, 10);
     42      if (endptr == ptr) {
     43        Nelement[Nfield] = 1;
     44      }
     45      ptr = endptr; // this should now point at the letter that is the format type
    2746      if ((*ptr != 'B') && (*ptr != 'I') && (*ptr != 'J') && (*ptr != 'K') && (*ptr != 'D') && (*ptr != 'E')) {
    2847        gprint (GP_ERR, "error in binary table format %s: invalid character %c\n", format, *ptr);
    2948        goto escape;
    3049      }
    31       tformat[2*j + 0] = *ptr;
    32       tformat[2*j + 1] = 0; // a bit sleazy : use a 2xN string to store N 1-byte strings
     50
     51      int Nchar = snprintf (tformat[Nfield], 0, "%d%c", Nelement[Nfield], *ptr);
     52      ALLOCATE (tformat[Nfield], char, Nchar + 1);
     53      int Nout = snprintf (tformat[Nfield], Nchar + 1, "%d%c", Nelement[Nfield], *ptr);
     54      myAssert (Nout <= Nchar, "oops");
     55
     56      // tformat[2*j + 0] = *ptr;
     57      // tformat[2*j + 1] = 0; // a bit sleazy : use a 2xN string to store N 1-byte strings
     58
     59      j += Nelement[Nfield]; // advance past
     60      if (j > Nvec) {
     61        gprint (GP_ERR, "error in binary table format %s (too few vectors for listed field)\n", format);
     62        goto escape;
     63      }
     64
    3365      ptr ++;
     66      Nfield ++;
    3467    }
    3568    while (*ptr && OHANA_WHITESPACE (*ptr)) ptr++;
     
    4174    for (j = 0; j < Nvec; j++) {
    4275      // if the format is not defined, just use the native byte-widths
    43       tformat[2*j + 0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'K'; // this depends on opihi_int == int64_t for Int
    44       tformat[2*j + 1] = 0;
    45     }
     76      ALLOCATE (tformat[j], char, 2);
     77      tformat[j][0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'K'; // this depends on opihi_int == int64_t for Int
     78      tformat[j][1] = 0;
     79      Nelement[j] = 1;
     80    }
     81    Nfield = Nvec;
    4682  }
    4783
     
    4985  // output table (because the data goes to the named column below).  need to enforce
    5086  // this somehow
    51   for (j = 0; j < Nvec; j++) {
    52     gfits_define_bintable_column (theader, &tformat[2*j], vec[j][0].name, NULL, NULL, 1.0, 0.0);
     87  int ivec = 0;
     88  for (j = 0; j < Nfield; j++) {
     89    // XX need to loop over fields, and skip the additional vectors that are part of a field
     90    // this call supported multiple columns per named field
     91    gfits_define_bintable_column (theader, tformat[j], vec[ivec][0].name, NULL, NULL, 1.0, 0.0);
     92    ivec += Nelement[j];
     93  }
     94
     95  // need to free the array
     96  for (j = 0; j < Nfield; j++) {
     97    free (tformat[j]);
    5398  }
    5499  free (tformat);
     
    57102  gfits_create_table (theader, ftable);
    58103
     104  // I need to add each vector in order, but I need to
     105  // track which field it corresponds to.
     106
    59107  // add the vectors to the output array
    60   for (j = 0; j < Nvec; j++) {
    61     if (vec[j][0].type == OPIHI_FLT) {
    62       gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double",  vec[j][0].elements.Flt, vec[j][0].Nelements, nativeOrder);
    63     } else {
    64 //    gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int",     vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
    65       gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int64_t", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
     108  for (ivec = 0, j = 0; j < Nfield; j++) {
     109    // the first vector provides the name for the field
     110    char *fieldname = vec[ivec][0].name;
     111    for (int k = 0; k < Nelement[j]; k++, ivec++) {
     112      Vector *thisvec = vec[ivec];
     113      if (thisvec->type == OPIHI_FLT) {
     114        gfits_set_bintable_column_reformat (theader, ftable, fieldname, "double",  thisvec->elements.Flt, thisvec->Nelements, k, nativeOrder);
     115      } else {
     116        gfits_set_bintable_column_reformat (theader, ftable, fieldname, "int64_t", thisvec->elements.Int, thisvec->Nelements, k, nativeOrder);
     117      }
    66118    }
    67119  }
Note: See TracChangeset for help on using the changeset viewer.