Changeset 38363
- Timestamp:
- Jun 4, 2015, 8:49:25 AM (11 years ago)
- Location:
- branches/eam_branches/ohana.20150429/src
- Files:
-
- 7 edited
-
libfits/matrix/F_compress_M.c (modified) (3 diffs)
-
libfits/matrix/F_uncompress_M.c (modified) (1 diff)
-
libfits/table/F_compress_T.c (modified) (13 diffs)
-
libfits/table/F_uncompress_T.c (modified) (13 diffs)
-
libfits/test/compress.sh (modified) (4 diffs)
-
libfits/test/tablecomp.c (modified) (1 diff)
-
opihi/cmd.data/rd.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c
r38362 r38363 173 173 174 174 // size of a pixel in the image tile -- this is probably not needed 175 // int tile_pixsize = abs(header[0].bitpix) / 8; 176 // fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix); 175 # if VERBOSE_DUMP 176 int tile_pixsize = abs(header[0].bitpix) / 8; 177 fprintf (stderr, "raw_pixsize: %d, cmp_pixsize: %d, tile_pixsize: %d, raw_bitpix: %d\n", raw_pixsize, cmp_pixsize, tile_pixsize, raw_bitpix); 178 # endif 177 179 178 180 // allocate the buffer for compression work … … 210 212 211 213 // gzip compresses bytes which are in BIG-ENDIAN order 214 // Nraw is number of pixels 212 215 if (!strcasecmp(zcmptype, "GZIP_1")) { 213 // Nraw is number of pixels214 216 if (!gfits_byteswap_zdata (raw, Nraw * raw_pixsize, raw_pixsize)) ESCAPE; 215 217 } … … 238 240 // compression modes require swapping after compression (compresssion & decompression 239 241 // operate on native ENDIAN) 240 if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2") ) {242 if (strcasecmp(zcmptype, "GZIP_1") && strcasecmp(zcmptype, "GZIP_2") && strcasecmp(zcmptype, "RICE_1")) { 241 243 // Nzdata is number of bytes 242 244 if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE; -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c
r38362 r38363 284 284 } 285 285 286 if (strcasecmp(cmptype, "GZIP_1") ) {286 if (strcasecmp(cmptype, "GZIP_1") && strcasecmp(cmptype, "GZIP_2") && strcasecmp(cmptype, "RICE_1")) { 287 287 // Nzdata is number of bytes 288 288 if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE; -
branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c
r38356 r38363 18 18 // we do not try to support compression of an image with an associated table (not valid) 19 19 20 # define ESCAPE(A) { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; } 21 22 int gfits_collect_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize); 20 # define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; } 21 22 int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows); 23 int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows); 23 24 24 25 int gfits_compress_table (FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype) { … … 50 51 51 52 // creates an empty (Naxes = 2, Naxis[i] = 0) table header with XTENSION = BINTABLE, EXTNAME = COMPRESSED_TABLE 52 if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE (A);53 if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE; 53 54 54 55 int Nfields; 55 if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE (A);56 if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE; 56 57 57 58 TableField *fields = NULL; … … 59 60 for (i = 0; i < Nfields; i++) { 60 61 snprintf (keyword, 80, "TTYPE%d", i+1); 61 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE (A);62 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE (A);62 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE; 63 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE; 63 64 64 65 // TUNIT is not mandatory … … 67 68 fields[i].tunit[0] = 0; 68 69 } else { 69 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE (A);70 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE; 70 71 } 71 72 72 73 snprintf (keyword, 80, "TFORM%d", i+1); 73 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE (A);74 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE (A);74 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE; 75 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE; 75 76 76 77 // XXX this should depend on the field type, but for now just use a single type (GZIP_1) … … 78 79 79 80 // by using "P" format, we are limited to 32bit pointers (2GB heap) 80 if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE (A);81 if (!gfits_define_bintable_column (tgtheader, "1QB(0)", fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE; 81 82 } 82 83 83 84 // allocates the default data array (tgttable->buffer) 84 if (!gfits_create_table (tgtheader, tgttable)) ESCAPE (A);85 if (!gfits_create_table (tgtheader, tgttable)) ESCAPE; 85 86 86 87 // copy original header to output header (XXX this needs to be finished) 87 if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE (A);88 if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE; 88 89 89 90 // this allocates the pointer data array for the full set of tiles (NOT the heap) … … 91 92 ALLOCATE_ZERO (tmpbuffer, char, 16*Ntile); // need space for Ntile entries, each of width 16 bytes (2 long) 92 93 for (i = 0; i < Nfields; i++) { 93 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ntile)) ESCAPE (A);94 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ntile)) ESCAPE; 94 95 } 95 96 free (tmpbuffer); 96 97 97 98 // add ZIMAGE from output header 98 if (!gfits_modify_alt (tgtheader, "ZTABLE", "%t", 1, TRUE)) ESCAPE (A);99 if (!gfits_modify_alt (tgtheader, "ZTABLE", "%t", 1, TRUE)) ESCAPE; 99 100 100 101 // define compression-specific keywords, update header as needed. 101 if (!gfits_modify (tgtheader, "ZTILELEN", "%d", 1, ztilelen)) ESCAPE (A);102 103 if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE (A);104 if (!gfits_modify (tgtheader, "ZNAXIS2", OFF_T_FMT, 1, srcheader->Naxis[1])) ESCAPE (A);102 if (!gfits_modify (tgtheader, "ZTILELEN", "%d", 1, ztilelen)) ESCAPE; 103 104 if (!gfits_modify (tgtheader, "ZNAXIS1", OFF_T_FMT, 1, srcheader->Naxis[0])) ESCAPE; 105 if (!gfits_modify (tgtheader, "ZNAXIS2", OFF_T_FMT, 1, srcheader->Naxis[1])) ESCAPE; 105 106 106 107 off_t pcount; 107 if (!gfits_scan (srcheader, "PCOUNT", OFF_T_FMT, 1, &pcount)) ESCAPE (A);108 if (!gfits_modify (tgtheader, "ZPCOUNT", OFF_T_FMT, 1, pcount)) ESCAPE (A);108 if (!gfits_scan (srcheader, "PCOUNT", OFF_T_FMT, 1, &pcount)) ESCAPE; 109 if (!gfits_modify (tgtheader, "ZPCOUNT", OFF_T_FMT, 1, pcount)) ESCAPE; 109 110 110 111 off_t theap; 111 112 if (gfits_scan (srcheader, "THEAP", OFF_T_FMT, 1, &theap)) { 112 if (!gfits_modify (tgtheader, "ZTHEAP", OFF_T_FMT, 1, theap)) ESCAPE (A);113 if (!gfits_modify (tgtheader, "ZTHEAP", OFF_T_FMT, 1, theap)) ESCAPE; 113 114 } 114 115 … … 118 119 for (i = 0; i < Nfields; i++) { 119 120 snprintf (keyword, 81, "ZFORM%d", i+1); 120 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE (A);121 if (!gfits_varlength_column_define (tgttable, &fields[i].zdef, i+1)) ESCAPE (A);122 if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE (A); //121 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE; 122 if (!gfits_varlength_column_define (tgttable, &fields[i].zdef, i+1)) ESCAPE; 123 if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE; // 123 124 fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize; 124 125 max_width = MAX(max_width, fields[i].rowsize); … … 126 127 // compression type per column (XXX for now we are just using zcmptype, as set above) 127 128 snprintf (keyword, 81, "ZCTYP%d", i+1); 128 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].zctype)) ESCAPE (A);129 if (!gfits_modify (tgtheader, keyword, "%s", 1, fields[i].zctype)) ESCAPE; 129 130 130 131 fields[i].offset = offset; … … 151 152 152 153 // copy the raw pixels from their native matrix locations to the temporary output buffer 153 if (!gfits_collect_table_data (srctable, raw, fields[j].offset, row_start, Nrows, fields[j].rowsize)) ESCAPE(A); 154 if (!strcasecmp(fields[i].zctype, "GZIP_2")) { 155 if (!gfits_collect_table_gzp2 (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE; 156 } else { 157 if (!gfits_collect_table_data (srctable, &fields[j], raw, row_start, Nrows)) ESCAPE; 158 } 154 159 155 160 // optname, optvalue = NULL, Noptions = 0 … … 157 162 int Nraw = Nrows*fields[j].Nvalues; // number of pixels 158 163 if (!strcmp(fields[j].zctype, "GZIP_1")) { 159 if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE (A);164 if (!gfits_byteswap_zdata (raw, Nraw * fields[j].pixsize, fields[j].pixsize)) ESCAPE; 160 165 } 161 166 162 167 int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression 163 if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE (A);168 if (!gfits_compress_data (zdata, &Nzdata, fields[j].zctype, NULL, NULL, 0, raw, Nraw, fields[j].pixsize, 0, 0)) ESCAPE; 164 169 165 if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE(A); 166 167 // XXX need to activate 168 // if (FALSE) gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize) ESCAPE(A); 170 if (strcasecmp(fields[j].zctype, "GZIP_1") && strcasecmp(fields[j].zctype, "GZIP_2") && strcasecmp(fields[j].zctype, "RICE_1")) { 171 if (!gfits_byteswap_zdata (zdata, Nzdata, fields[j].pixsize)) ESCAPE; 172 } 173 174 if (!gfits_varlength_column_add_data (tgttable, zdata, Nzdata, i, &fields[j].zdef)) ESCAPE; 169 175 } 170 176 } 171 177 172 178 for (i = 0; i < Nfields; i++) { 173 if (!gfits_varlength_column_finish (tgttable, &fields[i].zdef)) ESCAPE (A);179 if (!gfits_varlength_column_finish (tgttable, &fields[i].zdef)) ESCAPE; 174 180 } 175 181 … … 190 196 // raw_pixsize is the bytes / pixel for the input matrix 191 197 // place the raw image bytes for the current tile into the tile buffer 192 int gfits_collect_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize) {198 int gfits_collect_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 193 199 194 200 off_t i; … … 201 207 for (i = 0; i < Nrows; i++) { 202 208 int row = row_start + i; 203 memcpy (&raw[i* rowsize], &table->buffer[Nx*row + col],rowsize);209 memcpy (&raw[i*field->rowsize], &table->buffer[Nx*row + field->offset], field->rowsize); 204 210 # if (VERBOSE) 205 int j; for (j = 0; j < rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + col+ j]);211 int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]); 206 212 # endif 207 213 } … … 210 216 return (TRUE); 211 217 } 218 219 int gfits_collect_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 220 221 off_t i, j, k; 222 223 // we are copying NN rows into the column which starts at XX and has MM bytes per row 224 225 off_t Nx = table->header->Naxis[0]; 226 227 for (k = 0; k < field->pixsize; k++) { 228 for (i = 0; i < Nrows; i++) { 229 int row = row_start + i; 230 char *tgt = &raw[i*field->rowsize + k*Nrows*field->Nvalues]; 231 char *src = &table->buffer[Nx*row + field->offset + k]; 232 for (j = 0; j < field->Nvalues; j++, tgt+=field->pixsize, src++) { 233 *tgt = *src; 234 myAssert (src - raw < field-> 235 } 236 } 237 } 238 return (TRUE); 239 } -
branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c
r38356 r38363 3 3 # include <zlib.h> 4 4 5 # define ESCAPE(A) { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; } 6 7 int gfits_distribute_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize); 5 # define ESCAPE { fprintf (stderr, "error in %s @ line %d\n", __func__, __LINE__); goto escape; } 6 7 int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows); 8 int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows); 8 9 9 10 # define VERBOSE_DUMP 0 … … 53 54 54 55 int ztilelen; 55 if (!gfits_scan (srcheader, "ZTILELEN", "%d", 1, &ztilelen)) ESCAPE (A);56 if (!gfits_scan (srcheader, "ZTILELEN", "%d", 1, &ztilelen)) ESCAPE; 56 57 // XXX if ZTILELEN is missing, it should have the value of ZNAXIS2 57 58 … … 63 64 64 65 // creates an empty (Naxes = 2, Naxis[i] = 0) table header with XTENSION = BINTABLE, EXTNAME = COMPRESSED_TABLE 65 if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE (A);66 if (!gfits_create_table_header (tgtheader, "BINTABLE", extname)) ESCAPE; 66 67 67 68 int Nfields; 68 if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE (A);69 if (!gfits_scan (srcheader, "TFIELDS", "%d", 1, &Nfields)) ESCAPE; 69 70 70 71 // below we generate a fake table with tmpbuffers. allocated it to the max needed size … … 76 77 for (i = 0; i < Nfields; i++) { 77 78 snprintf (keyword, 80, "TTYPE%d", i+1); 78 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE (A);79 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE (A);79 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].ttype)) ESCAPE; 80 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].ttype_cmt)) ESCAPE; 80 81 81 82 // TUNIT is not mandatory … … 84 85 fields[i].tunit[0] = 0; 85 86 } else { 86 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE (A);87 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tunit_cmt)) ESCAPE; 87 88 } 88 89 89 90 snprintf (keyword, 80, "ZFORM%d", i+1); 90 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE (A);91 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE (A);91 if (!gfits_scan (srcheader, keyword, "%s", 1, fields[i].tformat)) ESCAPE; 92 if (!gfits_scan_alt (srcheader, keyword, "%C", 1, fields[i].tformat_cmt)) ESCAPE; 92 93 93 94 snprintf (keyword, 80, "ZCTYP%d", i+1); … … 96 97 } 97 98 98 if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE (A);99 if (!gfits_bintable_format (fields[i].tformat, fields[i].datatype, &fields[i].Nvalues, &fields[i].pixsize)) ESCAPE; 99 100 fields[i].rowsize = fields[i].Nvalues*fields[i].pixsize; 100 101 max_width = MAX(max_width, fields[i].rowsize); … … 103 104 offset += fields[i].rowsize; 104 105 105 if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE (A);106 107 if (!gfits_define_bintable_column (tgtheader, fields[i].tformat, fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE (A);106 if (!gfits_varlength_column_define (srctable, &fields[i].zdef, i + 1)) ESCAPE; 107 108 if (!gfits_define_bintable_column (tgtheader, fields[i].tformat, fields[i].ttype, fields[i].ttype_cmt, fields[i].tunit, 1.0, 0.0)) ESCAPE; 108 109 } 109 110 110 111 // allocates the default data array (tgttable->buffer) 111 if (!gfits_create_table (tgtheader, tgttable)) ESCAPE (A);112 if (!gfits_create_table (tgtheader, tgttable)) ESCAPE; 112 113 113 114 // copy original header to output header (XXX this needs to be finished) 114 if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE (A);115 if (!gfits_copy_keywords_compress (srcheader, tgtheader)) ESCAPE; 115 116 116 117 off_t Nx, Ny; 117 if (!gfits_scan (srcheader, "ZNAXIS1", OFF_T_FMT, 1, &Nx)) ESCAPE (A);118 if (!gfits_scan (srcheader, "ZNAXIS2", OFF_T_FMT, 1, &Ny)) ESCAPE (A);118 if (!gfits_scan (srcheader, "ZNAXIS1", OFF_T_FMT, 1, &Nx)) ESCAPE; 119 if (!gfits_scan (srcheader, "ZNAXIS2", OFF_T_FMT, 1, &Ny)) ESCAPE; 119 120 myAssert (Nx == tgtheader->Naxis[0], "table definition error?"); 120 121 … … 123 124 ALLOCATE_ZERO (tmpbuffer, char, max_width*Ny); 124 125 for (i = 0; i < Nfields; i++) { 125 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE (A);126 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE; 126 127 } 127 128 free (tmpbuffer); … … 153 154 off_t Nzdata; 154 155 char *zdata = gfits_varlength_column_pointer (srctable, &fields[i].zdef, row, &Nzdata); 155 if (!zdata) ESCAPE (A);156 if (!zdata) ESCAPE; 156 157 158 if (strcasecmp(fields[i].zctype, "GZIP_1") && strcasecmp(fields[i].zctype, "GZIP_2") && strcasecmp(fields[i].zctype, "RICE_1")) { 159 // Nzdata is number of bytes 160 if (!gfits_byteswap_zdata (zdata, Nzdata, fields[i].pixsize)) ESCAPE; 161 } 162 157 163 int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen; 158 164 int Nraw = Nraw_alloc; // expected number of pixel: Nrows*fields[i].Nvalues 159 if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE (A);165 if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE; 160 166 161 167 if (!strcasecmp(fields[i].zctype, "GZIP_1")) { 162 168 myAssert ((fields[i].zdef.format != 'C') && (fields[i].zdef.format != 'M'), "swap is probably wrong for C or M columns"); 163 if (!gfits_byteswap_zdata (raw, Nraw * fields[i].pixsize, fields[i].pixsize)) ESCAPE (A);169 if (!gfits_byteswap_zdata (raw, Nraw * fields[i].pixsize, fields[i].pixsize)) ESCAPE; 164 170 } 165 171 … … 171 177 172 178 // copy the raw pixels from their native matrix locations to the temporary output buffer 173 if (!gfits_distribute_table_data (tgttable, raw, fields[i].offset, row_start, Nrows, fields[i].rowsize)) ESCAPE(A); 174 175 // XXX need to activate 176 // if (FALSE) gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize) ESCAPE(A); 179 if (!strcasecmp(fields[i].zctype, "GZIP_2")) { 180 if (!gfits_distribute_table_gzp2 (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE; 181 } else { 182 if (!gfits_distribute_table_data (tgttable, &fields[i], raw, row_start, Nrows)) ESCAPE; 183 } 177 184 } 178 185 } … … 194 201 // raw_pixsize is the bytes / pixel for the input matrix 195 202 // place the raw image bytes for the current tile into the tile buffer 196 int gfits_distribute_table_data (FTable *table, char *raw, int col, int row_start, int Nrows, int rowsize) {203 int gfits_distribute_table_data (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 197 204 198 205 off_t i; … … 202 209 off_t Nx = table->header->Naxis[0]; 203 210 204 if (VERBOSE) fprintf (stderr, " collect: ");211 if (VERBOSE) fprintf (stderr, "distribute: "); 205 212 for (i = 0; i < Nrows; i++) { 206 213 int row = row_start + i; 207 memcpy (&table->buffer[Nx*row + col], &raw[i*rowsize],rowsize);214 memcpy (&table->buffer[Nx*row + field->offset], &raw[i*field->rowsize], field->rowsize); 208 215 # if (VERBOSE) 209 int j; for (j = 0; j < rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + col+ j]);216 int j; for (j = 0; j < field->rowsize; j++) fprintf (stderr, "0x%02hhx ", table->buffer[Nx*row + field->offset + j]); 210 217 # endif 211 218 } … … 214 221 return (TRUE); 215 222 } 223 224 int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows) { 225 226 off_t i, j, k; 227 228 // we are copying NN rows into the column which starts at XX and has MM bytes per row 229 230 off_t Nx = table->header->Naxis[0]; 231 232 for (k = 0; k < field->pixsize; k++) { 233 for (i = 0; i < Nrows; i++) { 234 int row = row_start + i; 235 char *src = &raw[i*field->rowsize + k*Nrows*field->Nvalues]; 236 char *tgt = &table->buffer[Nx*row + field->offset + k]; 237 for (j = 0; j < field->Nvalues; j++, tgt+=field->pixsize, src++) { 238 *tgt = *src; 239 } 240 } 241 } 242 return (TRUE); 243 } -
branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh
r38362 r38363 1 input tap.dvo 1 2 2 3 macro test_image_all 3 4 4 # foreach mode NONE GZIP_1 RICE_1 5 tapPLAN 88 6 7 foreach mode NONE GZIP_1 GZIP_2 RICE_1 5 8 # foreach mode GZIP_1 6 foreach mode GZIP_29 # foreach mode GZIP_2 7 10 # foreach mode RICE_1 8 11 foreach bitpix 8 16 32 -32 -64 9 12 # foreach bitpix 32 10 echo ===== bitpix = $bitpix ===== 13 if (($mode == RICE_1) && ($bitpix < 0)) continue ; # RICE_1 is for int only 14 tapDIAG 2 "===== bitpix = $bitpix, mode = $mode =====" 11 15 test_image_single $bitpix $mode 12 16 end 13 17 end 18 19 tapDONE 14 20 end 15 21 … … 30 36 rd b test.cmp.fits -x 0 31 37 set d = x - b 32 stat d 38 stat -q d 39 tapOK {abs($MEAN) < 0.001} "read our cmp $cmpmode $bitpix (MEAN = $MEAN)" 40 tapOK {$SIGMA < 0.001} "read our cmp $cmpmode $bitpix (SIGMA = $SIGMA)" 33 41 34 42 if ($cmpmode == NONE) return … … 43 51 exec fpack -r -S test.raw.fits > test.fpk.fits 44 52 end 45 echo "load fpack version"53 # echo "load fpack version" 46 54 rd c test.fpk.fits -x 0 47 55 set d = x - c 48 stat d 56 stat -q d 57 tapOK {abs($MEAN) < 0.001} "read fpack $cmpmode $bitpix (MEAN = $MEAN)" 58 tapOK {$SIGMA < 0.001} "read fpack $cmpmode $bitpix (SIGMA = $SIGMA)" 49 59 50 60 if ($cmpmode == RICE_1_0) … … 53 63 end 54 64 55 echo "run funpack on our version"65 # echo "run funpack on our version" 56 66 exec funpack -S test.cmp.fits > test.fun.fits 57 67 rd e test.fun.fits 58 68 set d = x - e 59 stat d 69 stat -q d 70 tapOK {abs($MEAN) < 0.001} "funpack our cmp $cmpmode $bitpix (MEAN = $MEAN)" 71 tapOK {$SIGMA < 0.001} "funpack our cmp $cmpmode $bitpix (SIGMA = $SIGMA)" 60 72 end 61 73 -
branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
r38340 r38363 14 14 test_compress ("NONE"); 15 15 test_compress ("GZIP_1"); 16 test_compress ("GZIP_2"); 17 // test_compress ("GZIP_1"); 16 18 17 19 exit (0); -
branches/eam_branches/ohana.20150429/src/opihi/cmd.data/rd.c
r38340 r38363 8 8 char region[512]; 9 9 Buffer *buf; 10 11 int VERBOSE = FALSE; 12 if ((N = get_argument (argc, argv, "-v"))) { 13 remove_argument (N, &argc, argv); 14 VERBOSE = TRUE; 15 } 10 16 11 17 int JustHead = FALSE; … … 193 199 gfits_copy_header (&buf[0].header, ftable.header); 194 200 195 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { fprintf (stderr, "problem reading compressed image table data\n"); fclose (f); return FALSE; }196 if (!gfits_byteswap_varlength_column (&ftable, 1)) { fprintf (stderr, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }197 if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { fprintf (stderr, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; }201 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { gprint (GP_ERR, "problem reading compressed image table data\n"); fclose (f); return FALSE; } 202 if (!gfits_byteswap_varlength_column (&ftable, 1)) { gprint (GP_ERR, "problem doing byteswap on compressed image metadata column\n"); fclose (f); gfits_free_table (&ftable); return FALSE; } 203 if (!gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable)) { gprint (GP_ERR, "problem uncompressing the image data\n"); fclose (f); gfits_free_table (&ftable); return FALSE; } 198 204 199 205 // uncompressing the image leaves the format as an extension … … 238 244 buf[0].unsign = buf[0].header.unsign; 239 245 240 gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", 241 buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]); 246 if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]); 242 247 243 248 blank = 0xffff;
Note:
See TracChangeset
for help on using the changeset viewer.
