IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38330


Ignore:
Timestamp:
May 28, 2015, 8:28:24 PM (11 years ago)
Author:
eugene
Message:

adding compression option to wd and write

Location:
branches/eam_branches/ohana.20150429/src/opihi
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/opihi/cmd.data/wd.c

    r38062 r38330  
    33int wd (int argc, char **argv) {
    44 
    5   int N, Extend;
     5  int N, Extend, Compress;
    66  int newUnsign, newBitpix, newScale, newZero;
    77  int outUnsign, outBitpix;
     
    1616    remove_argument (N, &argc, argv);
    1717    Extend  = TRUE;
     18  }
     19
     20  Compress = FALSE;
     21  if ((N = get_argument (argc, argv, "-compress"))) {
     22    remove_argument (N, &argc, argv);
     23    Compress = TRUE;
    1824  }
    1925
     
    162168  }
    163169 
     170  // not compatible with extend
     171  if (Compress) {
     172    Header myHeader;
     173    Matrix myMatrix;
     174
     175    FILE *f = fopen (argv[2], "w");
     176    if (!f) {
     177      fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", argv[2]);
     178      return FALSE;
     179    }
     180   
     181    gfits_init_header (&myHeader);
     182    myHeader.extend = TRUE;
     183    gfits_create_header (&myHeader);
     184    gfits_create_matrix (&myHeader, &myMatrix);
     185    gfits_fwrite_header  (f, &myHeader);
     186    gfits_fwrite_matrix  (f, &myMatrix);
     187    gfits_free_header (&myHeader);
     188    gfits_free_matrix (&myMatrix);
     189
     190    FTable ftable;
     191    Header theader;
     192
     193    ftable.header = &theader;
     194
     195    gfits_compress_image (&temp_header, &temp_matrix, &ftable, NULL, "GZIP_1");
     196    gfits_byteswap_varlength_column (&ftable, 1);
     197   
     198    gfits_fwrite_Theader (f, &theader);
     199    gfits_fwrite_table  (f, &ftable);
     200    fclose (f);
     201
     202    gfits_free_header (&theader);
     203    gfits_free_table (&ftable);
     204    return (TRUE);
     205  }
     206
    164207  /* the actual write-to-disk goes here */
    165208  if (!gfits_write_header (argv[2], &temp_header)) {
  • branches/eam_branches/ohana.20150429/src/opihi/cmd.data/write_vectors.c

    r35109 r38330  
    33int write_vectors (int argc, char **argv) {
    44 
    5   int append;
    65  int i, j, Nvec, Ne, N;
    76  FILE *f;
    87  char **fmtlist, *fmttype;
    9   char *p0, *p1, *p2, *format, *FITS;
     8  char *p0, *p1, *p2, *format;
    109  Vector **vec;
    1110
     
    3433
    3534  /* option generate a FITS output table */
    36   FITS = NULL;
     35  char *FITS = NULL;
    3736  if ((N = get_argument (argc, argv, "-fits"))) {
    3837    remove_argument (N, &argc, argv);
     
    5857  }
    5958
    60   append = FALSE;
     59  int append = FALSE;
    6160  if ((N = get_argument (argc, argv, "-append"))) {
    6261    remove_argument (N, &argc, argv);
    6362    append = TRUE;
     63  }
     64
     65  int compress = FALSE;
     66  if ((N = get_argument (argc, argv, "-compress"))) {
     67    remove_argument (N, &argc, argv);
     68    compress = TRUE;
     69    if (!FITS) {
     70      fprintf (stderr, "NOTE: write_vectors -compress has no effect on non-FITS\n");
     71    }
    6472  }
    6573
     
    105113
    106114  if (FITS) {
    107     int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, format);
     115    int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format);
    108116    free (vec);
    109117    return status;
  • branches/eam_branches/ohana.20150429/src/opihi/dvo/avextract.c

    r38062 r38330  
    256256  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    257257  if (RESULT_FILE && !SKIP_RESULTS) {
    258     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, NULL);
     258    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL);
    259259    if (!status) {
    260260      goto escape;
  • branches/eam_branches/ohana.20150429/src/opihi/dvo/avmatch.c

    r37807 r38330  
    115115
    116116      CoordsFile = abspath("coords.fits", 1024);
    117       int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     117      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL);
    118118      if (!status) goto escape;
    119119    }
     
    302302      vec[i][0].Nelements = Nfound;
    303303    }
    304     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, NULL);
     304    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, FALSE, NULL);
    305305    free (vec[Nfields]->elements.Int);
    306306    free (vec[Nfields]);
  • branches/eam_branches/ohana.20150429/src/opihi/dvo/dvo_host_utils.c

    r37807 r38330  
    230230  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    231231  if (ResultFile) {
    232     int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, NULL);
     232    int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, FALSE, NULL);
    233233    if (!status) {
    234234      gprint (GP_ERR, "failed to write result file %s\n", ResultFile);
  • branches/eam_branches/ohana.20150429/src/opihi/dvo/mextract.c

    r37807 r38330  
    317317  // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere)
    318318  if (RESULT_FILE && !SKIP_RESULTS) {
    319     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, NULL);
     319    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL);
    320320    if (!status) goto escape;
    321321  }
  • branches/eam_branches/ohana.20150429/src/opihi/dvo/mmatch.c

    r37807 r38330  
    150150      // XXX this is now set for both cases...
    151151      CoordsFile = abspath("coords.fits", 1024);
    152       int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     152      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL);
    153153      if (!status) goto escape;
    154154    }
     
    349349      vec[Nfields-1] = IDXvec;
    350350    }
    351     int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, NULL);
     351    int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, FALSE, NULL);
    352352    if (!status) goto escape;
    353353  }
  • branches/eam_branches/ohana.20150429/src/opihi/include/dvomath.h

    r38062 r38330  
    167167
    168168/* vector IO functions */
    169 int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *format));
     169int           WriteVectorTableFITS  PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, int compress, char *format));
    170170Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
    171171
  • branches/eam_branches/ohana.20150429/src/opihi/lib.shell/VectorIO.c

    r37049 r38330  
    11# include "opihi.h"
    22 
    3 // write a set of vectors to a FITS file (vectors names become fits column names)
    4 int WriteVectorTable (Header *theader, FTable *ftable, char *extname, Vector **vec, int Nvec, char *format) {
     3// write a set of vectors to a FITS FTable structure (vectors names become fits column names)
     4static int WriteVectorTable (FTable *ftable, char *extname, Vector **vec, int Nvec, char *format) {
    55 
    66  int j;
     
    88  char *tformat = NULL;
    99
     10  Header *theader = ftable->header;
    1011  gfits_create_table_header (theader, "BINTABLE", extname);
    1112
     
    7172 
    7273// write a set of vectors to a FITS file (vectors names become fits column names)
    73 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *format) {
    74  
    75   Header header;
    76   Matrix matrix;
    77   Header theader;
    78   FTable ftable;
     74int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, int compress, char *format) {
     75 
     76  Header rawheader;
     77  Header cmpheader;
     78  FTable rawtable;
     79  FTable cmptable;
    7980
    8081  FILE *f = NULL;
     
    9192  }
    9293
    93   if (!WriteVectorTable (&theader, &ftable, extname, vec, Nvec, format)) goto escape;
     94  // init so free below does not fail if table is not created
     95  gfits_init_header (&rawheader);
     96  gfits_init_header (&cmpheader);
     97  gfits_init_table (&rawtable);
     98  gfits_init_table (&cmptable);
     99
     100  rawtable.header = &rawheader;
     101  if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format)) goto escape;
     102
     103  FTable *outtable = &rawtable;
     104  Header *outheader = &rawheader;
     105
     106  if (compress) {
     107    cmptable.header = &cmpheader;
     108    if (!gfits_compress_table (&rawtable, &cmptable, 10, "GZIP_1")) goto escape;
     109    outtable = &cmptable;
     110    outheader = &cmpheader;
     111  }
    94112
    95113  if (!append) {
     114    Header header;
     115    Matrix matrix;
    96116    gfits_init_header (&header);
     117    gfits_init_matrix (&matrix);
    97118    header.extend = TRUE;
    98119    gfits_create_header (&header);
     
    103124    gfits_free_matrix (&matrix);
    104125  }
    105   gfits_fwrite_Theader (f, &theader);
    106   gfits_fwrite_table  (f, &ftable);
    107 
    108   gfits_free_header (&theader);
    109   gfits_free_table (&ftable);
     126
     127  // write the actual table data
     128  gfits_fwrite_Theader (f, outheader);
     129  gfits_fwrite_table  (f, outtable);
     130
     131  gfits_free_header (&rawheader);
     132  gfits_free_table (&rawtable);
     133
     134  if (compress) {
     135    gfits_free_header (&cmpheader);
     136    gfits_free_table (&cmptable);
     137  }
    110138
    111139  fclose (f);
     
    114142
    115143 escape:
    116   if (!append) {
    117     gfits_free_header (&header);
    118     gfits_free_matrix (&matrix);
    119   }
    120   gfits_free_header (&theader);
    121   gfits_free_table (&ftable);
     144  gfits_free_header (&rawheader);
     145  gfits_free_table (&rawtable);
     146
     147  if (compress) {
     148    gfits_free_header (&cmpheader);
     149    gfits_free_table (&cmptable);
     150  }
    122151
    123152  fclose (f);
Note: See TracChangeset for help on using the changeset viewer.