Changeset 38340
- Timestamp:
- May 30, 2015, 7:59:48 PM (11 years ago)
- Location:
- branches/eam_branches/ohana.20150429/src
- Files:
-
- 17 edited
-
libfits/extern/gzip.c (modified) (8 diffs)
-
libfits/include/gfitsio.h (modified) (1 diff)
-
libfits/matrix/F_compress_M.c (modified) (3 diffs)
-
libfits/matrix/F_compress_data.c (modified) (2 diffs)
-
libfits/matrix/F_compress_utils.c (modified) (2 diffs)
-
libfits/matrix/F_uncompress_M.c (modified) (4 diffs)
-
libfits/matrix/F_uncompress_data.c (modified) (2 diffs)
-
libfits/table/F_uncompress_T.c (modified) (2 diffs)
-
libfits/test/compress.sh (modified) (2 diffs)
-
libfits/test/imagecomp.c (modified) (7 diffs)
-
libfits/test/tablecomp.c (modified) (1 diff)
-
opihi/cmd.data/rd.c (modified) (3 diffs)
-
opihi/cmd.data/read_vectors.c (modified) (8 diffs)
-
opihi/cmd.data/wd.c (modified) (1 diff)
-
opihi/cmd.data/write_vectors.c (modified) (1 diff)
-
opihi/include/dvomath.h (modified) (1 diff)
-
opihi/lib.shell/VectorIO.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/extern/gzip.c
r38339 r38340 2 2 # include <gfitsio.h> 3 3 # include <zlib.h> 4 # define EXTRA_VERBOSE 1 4 5 5 6 /** the two functions in this file re-implement the uncompress function of zlib. … … 10 11 11 12 /* zlib.h -- interface of the 'zlib' general purpose compression library 12 version 1.2.3, July 18th, 200513 14 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler15 16 This software is provided 'as-is', without any express or implied17 warranty. In no event will the authors be held liable for any damages18 arising from the use of this software.19 20 Permission is granted to anyone to use this software for any purpose,21 including commercial applications, and to alter it and redistribute it22 freely, subject to the following restrictions:23 24 1. The origin of this software must not be misrepresented; you must not25 claim that you wrote the original software. If you use this software26 in a product, an acknowledgment in the product documentation would be27 appreciated but is not required.28 2. Altered source versions must be plainly marked as such, and must not be29 misrepresented as being the original software.30 3. This notice may not be removed or altered from any source distribution.31 32 Jean-loup Gailly Mark Adler33 jloup@gzip.org madler@alumni.caltech.edu34 35 36 The data format used by the zlib library is described by RFCs (Request for37 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt38 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).13 version 1.2.3, July 18th, 2005 14 15 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler 16 17 This software is provided 'as-is', without any express or implied 18 warranty. In no event will the authors be held liable for any damages 19 arising from the use of this software. 20 21 Permission is granted to anyone to use this software for any purpose, 22 including commercial applications, and to alter it and redistribute it 23 freely, subject to the following restrictions: 24 25 1. The origin of this software must not be misrepresented; you must not 26 claim that you wrote the original software. If you use this software 27 in a product, an acknowledgment in the product documentation would be 28 appreciated but is not required. 29 2. Altered source versions must be plainly marked as such, and must not be 30 misrepresented as being the original software. 31 3. This notice may not be removed or altered from any source distribution. 32 33 Jean-loup Gailly Mark Adler 34 jloup@gzip.org madler@alumni.caltech.edu 35 36 37 The data format used by the zlib library is described by RFCs (Request for 38 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt 39 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 39 40 */ 40 41 41 42 /* 42 The 'zlib' compression library provides in-memory compression and43 The 'zlib' compression library provides in-memory compression and 43 44 decompression functions, including integrity checks of the uncompressed 44 45 data. This version of the library supports only one compression method … … 46 47 stream interface. 47 48 48 Compression can be done in a single step if the buffers are large49 Compression can be done in a single step if the buffers are large 49 50 enough (for example if an input file is mmap'ed), or can be done by 50 51 repeated calls of the compression function. In the latter case, the … … 52 53 (providing more output space) before each call. 53 54 54 The compressed data format used by default by the in-memory functions is55 The compressed data format used by default by the in-memory functions is 55 56 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 56 57 around a deflate stream, which is itself documented in RFC 1951. 57 58 58 The library also supports reading and writing files in gzip (.gz) format59 The library also supports reading and writing files in gzip (.gz) format 59 60 with an interface similar to that of stdio using the functions that start 60 61 with "gz". The gzip format is different from the zlib format. gzip is a 61 62 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 62 63 63 This library can optionally read and write gzip streams in memory as well.64 65 The zlib format was designed to be compact and fast for use in memory64 This library can optionally read and write gzip streams in memory as well. 65 66 The zlib format was designed to be compact and fast for use in memory 66 67 and on communications channels. The gzip format was designed for single- 67 68 file compression on file systems, has a larger header than zlib to maintain 68 69 directory information, and uses a different, slower check method than zlib. 69 70 70 The library does not install any signal handler. The decoder checks71 The library does not install any signal handler. The decoder checks 71 72 the consistency of the compressed data, so the library should never 72 73 crash even in case of corrupted input. … … 116 117 } 117 118 118 // XXX ??? is cfitsio writing data which is incompatible with zlib ??? 119 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 120 121 // NOTE: CFITSIO uses gzip format, not just zlib 119 122 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) 120 123 { 121 z_stream stream; 122 int i, err; 123 124 stream.next_in = (Bytef*)source; 125 stream.avail_in = (uInt)sourceLen; 126 /* Check for source > 64K on 16-bit machine: */ 127 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 128 129 stream.next_out = dest; 130 stream.avail_out = (uInt)*destLen; 131 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 132 133 stream.zalloc = Z_NULL; 134 stream.zfree = Z_NULL; 135 stream.opaque = Z_NULL; 136 137 if (0) { 138 fprintf (stderr, "inp unc: "); 139 for (i = 0; i < sourceLen; i++) { 140 fprintf (stderr, "0x%02hhx ", source[i]); 141 } 142 fprintf (stderr, "\n"); 143 } 144 145 // err = inflateInit2(&stream, -15); 146 err = inflateInit(&stream); 147 if (0) fprintf (stderr, "inp buffers unc 0: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out); 148 149 if (err != Z_OK) return err; 150 151 err = inflate(&stream, Z_FINISH); 152 if (0) fprintf (stderr, "out buffers unc 1: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out); 153 if (err != Z_STREAM_END) { 154 inflateEnd(&stream); 155 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) return Z_DATA_ERROR; 156 return err; 157 } 158 if (0) fprintf (stderr, "out buffers unc 2: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out); 159 160 if (0) { 161 fprintf (stderr, "out unc: "); 162 for (i = 0; i < stream.total_out; i++) { 163 fprintf (stderr, "0x%02hhx ", dest[i]); 164 } 165 fprintf (stderr, "\n"); 166 } 167 168 assert (stream.total_out <= *destLen); 169 *destLen = stream.total_out; 170 171 err = inflateEnd(&stream); 172 return err; 124 z_stream stream; 125 int i, err; 126 127 stream.next_in = (Bytef*)source; 128 stream.avail_in = (uInt)sourceLen; 129 130 /* Check for source > 64K on 16-bit machine: */ 131 if ((uLong)stream.avail_in != sourceLen) ESCAPE (Z_BUF_ERROR); 132 133 stream.next_out = dest; 134 stream.avail_out = (uInt)*destLen; 135 if ((uLong)stream.avail_out != *destLen) ESCAPE (Z_BUF_ERROR); 136 137 stream.zalloc = Z_NULL; 138 stream.zfree = Z_NULL; 139 stream.opaque = Z_NULL; 140 141 if (EXTRA_VERBOSE) { 142 fprintf (stderr, "inp unc: "); 143 for (i = 0; i < sourceLen; i++) { 144 fprintf (stderr, "0x%02hhx ", source[i]); 145 } 146 fprintf (stderr, "\n"); 147 } 148 149 // a value of 32 tells inflate to use the window size used in the compression AND to look for both zlib and gzip headers 150 err = inflateInit2(&stream, 32); 151 if (err != Z_OK) ESCAPE (err); 152 153 err = inflate(&stream, Z_FINISH); 154 if (err != Z_STREAM_END) { 155 inflateEnd(&stream); 156 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) ESCAPE (Z_DATA_ERROR); 157 ESCAPE(err); 158 } 159 160 if (EXTRA_VERBOSE) { 161 fprintf (stderr, "out unc: "); 162 for (i = 0; i < stream.total_out; i++) { 163 fprintf (stderr, "0x%02hhx ", dest[i]); 164 } 165 fprintf (stderr, "\n"); 166 } 167 168 assert (stream.total_out <= *destLen); 169 *destLen = stream.total_out; 170 171 err = inflateEnd(&stream); 172 return err; 173 173 } 174 174 … … 182 182 183 183 /* Check for source > 64K on 16-bit machine: */ 184 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;184 if ((uLong)stream.avail_in != sourceLen) ESCAPE (Z_BUF_ERROR); 185 185 186 186 stream.next_out = dest; 187 187 stream.avail_out = (uInt)*destLen; // allocated space 188 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;188 if ((uLong)stream.avail_out != *destLen) ESCAPE (Z_BUF_ERROR); 189 189 190 190 stream.zalloc = Z_NULL; … … 192 192 stream.opaque = Z_NULL; 193 193 194 if ( 0) {194 if (EXTRA_VERBOSE) { 195 195 fprintf (stderr, "inp cmp: "); 196 196 for (i = 0; i < sourceLen; i++) { … … 202 202 // the '1' is the compression level: make this a user argument 203 203 // NOTE: cfitsio uses a fixed value of 1 204 err = deflateInit(&stream, 1); 204 // I am using deflateInit2 because cfitsio expects gzip, not just zlib 205 err = deflateInit2(&stream, 1, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY); 205 206 if (0) fprintf (stderr, "inp buffers cmp 0: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out); 206 207 207 if (err != Z_OK) return err;208 if (err != Z_OK) ESCAPE(err); 208 209 209 210 // XXX this is written to do the compression in a single pass. it could be re-done to have 210 211 // the compression occur in a series of steps 211 212 err = deflate(&stream, Z_FINISH); 212 if (0) fprintf (stderr, "out buffers cmp 1: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out);213 214 213 if (err != Z_STREAM_END) { 215 214 err = deflateEnd(&stream); 216 return Z_BUF_ERROR; 217 } 218 if (0) fprintf (stderr, "out buffers cmp 2: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out); 219 220 if (0) { 215 ESCAPE (Z_BUF_ERROR); 216 } 217 218 if (EXTRA_VERBOSE) { 221 219 fprintf (stderr, "out cmp: "); 222 220 for (i = 0; i < stream.total_out; i++) { -
branches/eam_branches/ohana.20150429/src/libfits/include/gfitsio.h
r38335 r38340 205 205 206 206 int gfits_byteswap_zdata PROTO((char *zdata, int Nzdata, int bitpix)); 207 int gfits_extension_is_compressed PROTO((Header *header)); 207 int gfits_extension_is_compressed_image PROTO((Header *header)); 208 int gfits_extension_is_compressed_table PROTO((Header *header)); 208 209 int gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); 209 210 int gfits_vartable_heap_pixsize PROTO((char format)); -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c
r38329 r38340 139 139 int tile_pixsize = gfits_uncompressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0); 140 140 141 int Nzdata_alloc = raw_pixsize*max_tile_size + 100; 141 142 ALLOCATE (raw, char, raw_pixsize*max_tile_size); 142 ALLOCATE (zdata, char, raw_pixsize*max_tile_size);143 ALLOCATE (zdata, char, Nzdata_alloc); 143 144 144 145 // init the otile[] counters … … 155 156 if (!gfits_collect_data (matrix, raw, Nraw, raw_pixsize, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE(A); 156 157 158 if (!strcasecmp(zcmptype, "GZIP_1")) { 159 if (!gfits_byteswap_zdata (raw, Nraw, raw_pixsize)) ESCAPE(A); 160 } 161 157 162 // XXX the tile must not be > 2GB 158 163 159 164 // optname, optvalue = NULL, Noptions = 0 160 165 161 int Nzdata = raw_pixsize*max_tile_size; // available space, replaced with actual output size on compression166 int Nzdata = Nzdata_alloc; // available space, replaced with actual output size on compression 162 167 if (!gfits_compress_data (zdata, &Nzdata, zcmptype, NULL, NULL, 0, raw, Nraw, tile_pixsize)) ESCAPE(A); 163 168 … … 298 303 SETUP_INSIZE (int, 4); 299 304 break; 305 case 8: 306 SETUP_INSIZE (double, 8); 307 break; 300 308 default: 301 309 abort(); -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c
r38334 r38340 27 27 int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 28 28 29 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 30 29 31 int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype, 30 32 char **optname, char **optvalue, int Nopt, … … 53 55 status = gfits_compress ((Bytef *) zdata, &destLen, (Bytef *) rawdata, Nbytes); 54 56 *Nzdata = destLen; 55 if (status != Z_OK) { 56 fprintf (stderr, "error in compress (GZIP)\n"); 57 return (FALSE); 58 } 57 if (status != Z_OK) ESCAPE(FALSE); 59 58 return (TRUE); 60 59 } -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c
r38339 r38340 131 131 } 132 132 133 int gfits_extension_is_compressed (Header *header) {133 int gfits_extension_is_compressed_image (Header *header) { 134 134 135 135 int has_extension, has_extname, has_zimage, zimage; … … 146 146 } 147 147 148 return (FALSE); 149 } 150 151 int gfits_extension_is_compressed_table (Header *header) { 152 153 int has_ztable, ztable; 154 has_ztable = gfits_scan_alt (header, "ZTABLE", "%t", 1, &ztable); 155 if (has_ztable && ztable) return (TRUE); 148 156 return (FALSE); 149 157 } -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c
r38339 r38340 249 249 // size of a pixel in the output from the decompression routine 250 250 odata_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 251 ALLOCATE (out, char, odata_pixsize*max_tile_size); 251 252 int Nout_alloc = odata_pixsize*max_tile_size; 253 ALLOCATE (out, char, Nout_alloc); 252 254 253 255 off_t row; … … 258 260 259 261 // expected output size for this tile 260 Nout = gfits_tile_size (matrix, otile, ztile); 262 // Nout = gfits_tile_size (matrix, otile, ztile); 263 Nout = Nout_alloc; 261 264 262 265 zdata = gfits_varlength_column_pointer (ftable, &zdef, row, &Nzdata); … … 273 276 // XXX the tile must not be > 2GB 274 277 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, odata_pixsize)) ESCAPE; 278 279 if (!strcasecmp(cmptype, "GZIP_1")) { 280 if (!gfits_byteswap_zdata (out, Nout, odata_pixsize)) ESCAPE; 281 } 275 282 276 283 // copy the uncompressed pixels into their correct locations … … 387 394 SETUP_INSIZE (int, 4); 388 395 break; 396 case 8: 397 SETUP_INSIZE (double, 8); 398 break; 389 399 default: 390 400 abort(); -
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_data.c
r38334 r38340 26 26 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 27 27 28 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 29 28 30 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize) { 29 31 … … 49 51 // XXX shouldn't we validate the result : we think we know the size 50 52 status = gfits_uncompress ((Bytef *) outdata, &tNout, (Bytef *) zdata, Nzdata); 51 if (status != Z_OK) { 52 fprintf (stderr, "error in uncompress (GZIP)\n"); 53 return (FALSE); 54 } 53 if (status != Z_OK) ESCAPE(FALSE); 55 54 *Nout = tNout / out_pixsize; 56 55 -
branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c
r38335 r38340 98 98 99 99 // allocate the intermediate storage buffers 100 ALLOCATE (raw, char, max_width*ztilelen); 100 int Nraw_alloc = max_width*ztilelen + 100; 101 ALLOCATE (raw, char, Nraw_alloc); 101 102 ALLOCATE (zdata, char, max_width*ztilelen); 102 103 … … 120 121 121 122 int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen; 122 int Nraw = Nrows*fields[i].Nvalues; // number of pixels 123 123 int Nraw = Nraw_alloc; // expected number of pixel: Nrows*fields[i].Nvalues 124 124 if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, fields[i].pixsize)) ESCAPE(A); 125 125 -
branches/eam_branches/ohana.20150429/src/libfits/test/compress.sh
r38339 r38340 1 2 macro testall 3 4 foreach bitpix 8 16 32 -32 -64 5 echo ===== bitpix = $bitpix ===== 6 test1 $bitpix 7 end 8 end 1 9 2 10 macro test1 3 mcreate z 500 500 11 if ($0 != 2) 12 echo "USAGE: test_image (bitpix)" 13 break 14 end 15 16 mcreate z 8 8 4 17 set x = xramp(z) 5 wd x test.raw.fits -bitpix -32-bzero 0 -bscale 16 wd x test.cmp.fits -bitpix -32-bzero 0 -bscale 1 -compress18 wd x test.raw.fits -bitpix $1 -bzero 0 -bscale 1 19 wd x test.cmp.fits -bitpix $1 -bzero 0 -bscale 1 -compress 7 20 rd b test.cmp.fits -x 0 8 21 set d = x - b 9 22 stat d 10 exec fpack -g -S test.raw.fits > test.fpk.fits 11 exec funpack -S test.cmp.fits > test.fun.fits 23 24 if ($bitpix == -64) 25 echo "*** bitpix $bitpix fails fpack / funpack ***" 26 else 27 exec fpack -g -S test.raw.fits > test.fpk.fits 28 echo "load fpack version" 29 rd c test.fpk.fits -x 0 30 set d = x - c 31 stat d 32 end 33 34 if ($bitpix == -64) 35 echo "*** bitpix $bitpix fails fpack / funpack ***" 36 else 37 exec funpack -S test.cmp.fits > test.fun.fits 38 rd e test.fun.fits 39 set d = x - e 40 stat d 41 end 12 42 end 13 43 … … 25 55 macro test3 26 56 57 $NPT = 10 58 create x 0 $NPT 59 set y = x^2 60 create ID 1 {$NPT + 1} -int 61 62 write -fits test test.raw.tbl x y ID 63 write -fits test test.cmp.tbl x y ID -compress-mode NONE 64 65 foreach f x y ID 66 set $f\_raw = $f 67 delete $f 68 end 69 70 echo "===== raw =====" 71 data test.raw.tbl 72 read -fits test x y ID 73 74 foreach f x y ID 75 set dv = $f - $f\_raw 76 vstat dv 77 end 78 delete -q x y ID 79 80 echo "===== cmp =====" 81 data test.cmp.tbl 82 read -fits test x y ID 83 84 foreach f x y ID 85 set dv = $f - $f\_raw 86 vstat dv 87 end 88 end 89 90 macro test4 91 27 92 create x 0 100 28 93 set y = x^2 94 create ID 1 101 -int 29 95 30 create ID 1 101 -int31 96 write -fits test test.raw.tbl x y ID 97 write -fits test test.cmp.tbl x y ID -compress 32 98 33 write -fits test test.cmp.tbl x y ID -compress 99 foreach f x y ID 100 set $f\_raw = $f 101 delete $f 102 end 103 104 echo "===== raw =====" 105 data test.raw.tbl 106 read -fits test x y ID 107 108 foreach f x y ID 109 set dv = $f - $f\_raw 110 vstat dv 111 end 112 delete -q x y ID 113 114 echo "===== cmp =====" 115 data test.cmp.tbl 116 read -fits test x y ID 117 118 foreach f x y ID 119 set dv = $f - $f\_raw 120 vstat dv 121 end 34 122 end -
branches/eam_branches/ohana.20150429/src/libfits/test/imagecomp.c
r38335 r38340 3 3 # include "tap_ohana.h" 4 4 5 int test_compress ( char *zcmptype);5 int test_compress (int bitpix, char *zcmptype); 6 6 7 7 int main (int argc, char **argv) { … … 11 11 diag ("libfits imagecomp.c tests"); 12 12 13 test_compress ("NONE"); 14 test_compress ("GZIP_1"); 13 test_compress ( 8, "NONE"); 14 test_compress ( 16, "NONE"); 15 test_compress ( 32, "NONE"); 16 test_compress (-32, "NONE"); 17 test_compress (-64, "NONE"); 18 19 test_compress ( 8, "GZIP_1"); 20 test_compress ( 16, "GZIP_1"); 21 test_compress ( 32, "GZIP_1"); 22 test_compress (-32, "GZIP_1"); 23 test_compress (-64, "GZIP_1"); 15 24 16 25 exit (0); … … 20 29 # define NY 100 21 30 22 int test_compress ( char *zcmptype) { // make a table, compress, uncompress, compare : use compression zcmptype31 int test_compress (int bitpix, char *zcmptype) { // make a table, compress, uncompress, compare : use compression zcmptype 23 32 24 33 Header rawheader; … … 31 40 ftable.header = &theader; 32 41 33 diag ("--- starting test_compress with zcmptype %s ---", zcmptype);42 diag ("--- starting test_compress with bitpix %d, zcmptype %s ---", bitpix, zcmptype); 34 43 ok (gfits_init_header (&rawheader), "init'ed the raw header"); 35 44 ok (gfits_init_matrix (&rawmatrix), "init'ed the raw matrix"); … … 38 47 39 48 /* assign the necessary internal values */ 40 rawheader.bitpix = -32;49 rawheader.bitpix = bitpix; 41 50 rawheader.Naxes = 2; 42 51 rawheader.Naxis[0] = NX; … … 46 55 ok (gfits_create_header (&rawheader), "created header"); 47 56 ok (gfits_create_matrix (&rawheader, &rawmatrix), "created matrix"); 48 49 float *rawdata = (float *) rawmatrix.buffer; 57 58 char *rawdata_char = (char *) rawmatrix.buffer; 59 short *rawdata_short = (short *) rawmatrix.buffer; 60 int *rawdata_int = (int *) rawmatrix.buffer; 61 float *rawdata_float = (float *) rawmatrix.buffer; 62 double *rawdata_double = (double *) rawmatrix.buffer; 63 50 64 int ix, iy; 51 65 for (ix = 0; ix < NX; ix++) { 52 66 for (iy = 0; iy < NY; iy++) { 53 rawdata[ix + NX*iy] = ix * iy*iy; 67 switch (bitpix) { 68 case 8: rawdata_char [ix + NX*iy] = ix + iy*iy; break; 69 case 16: rawdata_short [ix + NX*iy] = ix + iy*iy; break; 70 case 32: rawdata_int [ix + NX*iy] = ix + iy*iy; break; 71 case -32: rawdata_float [ix + NX*iy] = ix + iy*iy; break; 72 case -64: rawdata_double[ix + NX*iy] = ix + iy*iy; break; 73 default: myAbort ("bad bitpix value"); 74 } 54 75 } 55 76 } … … 64 85 int Nbad = 0; 65 86 66 float *outdata = (float *) outmatrix.buffer; 87 char *outdata_char = (char *) outmatrix.buffer; 88 short *outdata_short = (short *) outmatrix.buffer; 89 int *outdata_int = (int *) outmatrix.buffer; 90 float *outdata_float = (float *) outmatrix.buffer; 91 double *outdata_double = (double *) outmatrix.buffer; 92 67 93 for (ix = 0; ix < NX; ix++) { 68 94 for (iy = 0; iy < NY; iy++) { 69 if (rawdata[ix + NX*iy] != outdata[ix + NX*iy]) Nbad ++; 95 switch (bitpix) { 96 case 8: if (rawdata_char [ix + NX*iy] != outdata_char [ix + NX*iy]) Nbad ++; break; 97 case 16: if (rawdata_short [ix + NX*iy] != outdata_short [ix + NX*iy]) Nbad ++; break; 98 case 32: if (rawdata_int [ix + NX*iy] != outdata_int [ix + NX*iy]) Nbad ++; break; 99 case -32: if (rawdata_float [ix + NX*iy] != outdata_float [ix + NX*iy]) Nbad ++; break; 100 case -64: if (rawdata_double[ix + NX*iy] != outdata_double[ix + NX*iy]) Nbad ++; break; 101 default: myAbort ("bad bitpix value"); 102 } 70 103 } 71 104 } -
branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
r38335 r38340 82 82 off_t Nrow; 83 83 84 short *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"), "read short table column"); 85 int *ID_t = gfits_get_bintable_column_data (outheader, outtable, "ID", type, &Nrow, &Ncol); ok (!strcmp (type, "int"), "read int table column"); 86 float *X_t = gfits_get_bintable_column_data (outheader, outtable, "X", type, &Nrow, &Ncol); ok (!strcmp (type, "float"), "read float table column"); 87 double *Y_t = gfits_get_bintable_column_data (outheader, outtable, "Y", type, &Nrow, &Ncol); ok (!strcmp (type, "double"), "read double table column"); 88 84 short *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"), "read short table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 85 int *ID_t = gfits_get_bintable_column_data (outheader, outtable, "ID", type, &Nrow, &Ncol); ok (!strcmp (type, "int"), "read int table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 86 float *X_t = gfits_get_bintable_column_data (outheader, outtable, "X", type, &Nrow, &Ncol); ok (!strcmp (type, "float"), "read float table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 87 double *Y_t = gfits_get_bintable_column_data (outheader, outtable, "Y", type, &Nrow, &Ncol); ok (!strcmp (type, "double"), "read double table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 88 89 89 // count mismatched values 90 90 int Nseq = 0; -
branches/eam_branches/ohana.20150429/src/opihi/cmd.data/rd.c
r38338 r38340 85 85 return (FALSE); 86 86 } 87 if (gfits_extension_is_compressed (&buf[0].header)) {87 if (gfits_extension_is_compressed_image (&buf[0].header)) { 88 88 IsCompressed = TRUE; 89 89 } … … 118 118 Nword = 1; 119 119 IsCompressed = FALSE; 120 if (gfits_extension_is_compressed (&buf[0].header)) {120 if (gfits_extension_is_compressed_image (&buf[0].header)) { 121 121 if (!strcmp (CCDKeyword, "EXTNAME")) Nword = 1; 122 122 IsCompressed = TRUE; … … 194 194 195 195 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { fprintf (stderr, "problem reading compressed image table data\n"); fclose (f); return FALSE; } 196 fprintf (stderr, "rd 1: ");197 for (i = 0; i < 32; i++) {198 fprintf (stderr, "0x%0hhx ", ftable.buffer[i]);199 }200 fprintf (stderr, "\n");201 202 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; } 203 fprintf (stderr, "rd 2: ");204 for (i = 0; i < 32; i++) {205 fprintf (stderr, "0x%0hhx ", ftable.buffer[i]);206 }207 fprintf (stderr, "\n");208 209 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; } 210 198 -
branches/eam_branches/ohana.20150429/src/opihi/cmd.data/read_vectors.c
r38062 r38340 412 412 table.header = &header; 413 413 414 int IsCompressed = FALSE; 415 414 416 /* load appropriate extension (if extname is a number, use count) */ 415 417 if (Nextend > -1) { … … 430 432 if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend); 431 433 432 if (getSizes) { 434 IsCompressed = gfits_extension_is_compressed_table (&header); 435 436 if (getSizes && !IsCompressed) { 433 437 read_table_sizes (&header); 434 438 if (CCDKeyword != NULL) free (CCDKeyword); 435 439 gfits_free_header (&header); 436 440 return TRUE; 441 } 442 if (IsCompressed) { 443 if (getSizes) { 444 gprint (GP_ERR, "%s[%s] is compressed: -sizes is invalid\n", filename, extname); 445 gfits_free_header (&header); 446 return FALSE; 447 } 448 if ((start > 0) || (Nrows > -1)) { 449 gprint (GP_ERR, "%s[%s] is compressed: must read entire table\n", filename, extname); 450 gfits_free_header (&header); 451 return FALSE; 452 } 437 453 } 438 454 … … 483 499 } 484 500 485 if (getSizes) { 501 IsCompressed = gfits_extension_is_compressed_table (&header); 502 503 if (getSizes && !IsCompressed) { 486 504 read_table_sizes (&header); 487 505 if (CCDKeyword != NULL) free (CCDKeyword); … … 489 507 return TRUE; 490 508 } 509 if (IsCompressed) { 510 if (getSizes) { 511 gprint (GP_ERR, "%s[%s] is compressed: -sizes is invalid\n", filename, extname); 512 gfits_free_header (&header); 513 return FALSE; 514 } 515 if ((start > 0) || (Nrows > -1)) { 516 gprint (GP_ERR, "%s[%s] is compressed: must read entire table\n", filename, extname); 517 gfits_free_header (&header); 518 return FALSE; 519 } 520 } 491 521 492 522 if (Nrows == -1) { … … 503 533 504 534 if (!gfits_fread_ftable_range (f, padIfShort, &table, start, Nrows)) ESCAPE ("error reading table for extension %d\n", Nextend); 505 506 // if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");507 508 535 break; 509 536 } … … 518 545 Binary = !strcmp (type, "BINTABLE"); 519 546 Ny = header.Naxis[1]; 547 548 Header *outheader = &header; 549 FTable *outtable = &table; 550 551 Header rawheader; 552 FTable rawtable; 553 if (IsCompressed) { 554 rawtable.header = &rawheader; 555 if (!gfits_uncompress_table (&table, &rawtable)) ESCAPE ("failed to uncompress table"); 556 outheader = &rawheader; 557 outtable = &rawtable; 558 gfits_free_header (&header); 559 gfits_free_table (&table); 560 Ny = rawheader.Naxis[1]; 561 } 520 562 521 563 /* find columns which match requested vectors */ … … 527 569 Nval = 0; 528 570 if (Binary) { 529 if (!gfits_get_bintable_column_type ( &header, argv[i], type, &Nval)) ESCAPE ("requested field not found");530 if (!gfits_get_bintable_column ( &header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");571 if (!gfits_get_bintable_column_type (outheader, argv[i], type, &Nval)) ESCAPE ("requested field not found"); 572 if (!gfits_get_bintable_column (outheader, outtable, argv[i], &data)) ESCAPE ("error reading data from specified field"); 531 573 } else { 532 if (!gfits_get_table_column_type ( &header, argv[i], type)) ESCAPE ("requested field not found");533 if (!gfits_get_table_column ( &header, &table, argv[i], &data)) ESCAPE ("error reading data from specified field");574 if (!gfits_get_table_column_type (outheader, argv[i], type)) ESCAPE ("requested field not found"); 575 if (!gfits_get_table_column (outheader, outtable, argv[i], &data)) ESCAPE ("error reading data from specified field"); 534 576 } 535 577 if (Nval == 0) ESCAPE ("no data for field in table"); … … 594 636 } 595 637 if (CCDKeyword != NULL) free (CCDKeyword); 596 gfits_free_table ( &table);597 gfits_free_header ( &header);638 gfits_free_table (outtable); 639 gfits_free_header (outheader); 598 640 return (TRUE); 599 641 } -
branches/eam_branches/ohana.20150429/src/opihi/cmd.data/wd.c
r38338 r38340 205 205 ftable.header = &theader; 206 206 207 int i;208 207 gfits_compress_image (&temp_header, &temp_matrix, &ftable, NULL, CompressMode); 209 fprintf (stderr, "wd 1: ");210 for (i = 0; i < 32; i++) {211 fprintf (stderr, "0x%0hhx ", ftable.buffer[i]);212 }213 fprintf (stderr, "\n");214 215 208 gfits_byteswap_varlength_column (&ftable, 1); 216 fprintf (stderr, "wd 2: ");217 for (i = 0; i < 32; i++) {218 fprintf (stderr, "0x%0hhx ", ftable.buffer[i]);219 }220 fprintf (stderr, "\n");221 222 209 gfits_fwrite_Theader (f, &theader); 223 210 gfits_fwrite_table (f, &ftable); -
branches/eam_branches/ohana.20150429/src/opihi/cmd.data/write_vectors.c
r38330 r38340 63 63 } 64 64 65 int compress = FALSE; 66 if ((N = get_argument (argc, argv, "-compress"))) { 67 remove_argument (N, &argc, argv); 68 compress = TRUE; 65 char *compress = NULL; 66 if ((N = get_argument (argc, argv, "-compress-mode"))) { 67 remove_argument (N, &argc, argv); 68 compress = strcreate(argv[N]); 69 remove_argument (N, &argc, argv); 70 } else if ((N = get_argument (argc, argv, "-compress"))) { 71 remove_argument (N, &argc, argv); 72 compress = strcreate("GZIP_1"); 69 73 if (!FITS) { 70 74 fprintf (stderr, "NOTE: write_vectors -compress has no effect on non-FITS\n"); -
branches/eam_branches/ohana.20150429/src/opihi/include/dvomath.h
r38330 r38340 167 167 168 168 /* vector IO functions */ 169 int WriteVectorTableFITS PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, intcompress, char *format));169 int WriteVectorTableFITS PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format)); 170 170 Vector **ReadVectorTableFITS PROTO((char *filename, char *extname, int *Nvec)); 171 171 -
branches/eam_branches/ohana.20150429/src/opihi/lib.shell/VectorIO.c
r38330 r38340 72 72 73 73 // write a set of vectors to a FITS file (vectors names become fits column names) 74 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, intcompress, char *format) {74 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format) { 75 75 76 76 Header rawheader; … … 106 106 if (compress) { 107 107 cmptable.header = &cmpheader; 108 if (!gfits_compress_table (&rawtable, &cmptable, 10, "GZIP_1")) goto escape;108 if (!gfits_compress_table (&rawtable, &cmptable, 10, compress)) goto escape; 109 109 outtable = &cmptable; 110 110 outheader = &cmpheader;
Note:
See TracChangeset
for help on using the changeset viewer.
