Changeset 38441 for trunk/Ohana/src/libfits
- Timestamp:
- Jun 12, 2015, 6:18:23 PM (11 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 20 edited
- 7 copied
-
. (modified) (1 prop)
-
src/libfits/Makefile (modified) (5 diffs)
-
src/libfits/doc/notes-compress.txt (modified) (1 diff)
-
src/libfits/extern/gzip.c (modified) (5 diffs)
-
src/libfits/header/F_copy_H.c (modified) (1 diff)
-
src/libfits/header/F_modify.c (modified) (4 diffs)
-
src/libfits/include/gfitsio.h (modified) (12 diffs)
-
src/libfits/matrix/F_compress_M.c (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_M.c )
-
src/libfits/matrix/F_compress_data.c (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c )
-
src/libfits/matrix/F_compress_utils.c (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_utils.c )
-
src/libfits/matrix/F_matrix.c (modified) (4 diffs)
-
src/libfits/matrix/F_uncompress_M.c (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/matrix/F_uncompress_M.c )
-
src/libfits/matrix/F_uncompress_data.c (modified) (2 diffs)
-
src/libfits/table/F_compress_T.c (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/table/F_compress_T.c )
-
src/libfits/table/F_copy_T.c (modified) (2 diffs)
-
src/libfits/table/F_create_T.c (modified) (3 diffs)
-
src/libfits/table/F_define_column.c (modified) (1 diff)
-
src/libfits/table/F_get_column.c (modified) (7 diffs)
-
src/libfits/table/F_read_T.c (modified) (5 diffs)
-
src/libfits/table/F_set_column.c (modified) (41 diffs)
-
src/libfits/table/F_table_format.c (modified) (4 diffs)
-
src/libfits/table/F_table_row.c (modified) (3 diffs)
-
src/libfits/table/F_table_varlength.c (modified) (5 diffs)
-
src/libfits/table/F_uncompress_T.c (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/table/F_uncompress_T.c )
-
src/libfits/table/F_write_T.c (modified) (9 diffs)
-
src/libfits/table/F_write_TH.c (modified) (2 diffs)
-
src/libfits/test (copied) (copied from branches/eam_branches/ohana.20150429/src/libfits/test )
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/ohana.20150429 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/libfits/Makefile
r38255 r38441 1 1 default: install 2 2 help: 3 @echo "make options: install libfits man clean dist "3 @echo "make options: install libfits man clean dist test test.verbose test.clean" 4 4 5 5 include ../../Makefile.System … … 13 13 INC = $(HOME)/include 14 14 MAN = $(HOME)/doc 15 TESTDIR = $(HOME)/test 16 TESTBIN = $(HOME)/test 15 17 include ../../Makefile.Common 16 18 … … 19 21 FULL_CPPFLAGS = $(BASE_CPPFLAGS) -I$(EXT) 20 22 FULL_LDFLAGS = $(BASE_LDFLAGS) -lohana 23 24 TEST_CFLAGS = $(BASE_CFLAGS) 25 TEST_CPPFLAGS = $(BASE_CPPFLAGS) 26 TEST_LDFLAGS = $(BASE_LDFLAGS) -lFITS -lohana -ltap_ohana 27 28 29 TESTXTRA = tcomptiming 30 TESTPROG = zlib ricetest imagecomp tablecomp 31 $(TESTPROG) : % : $(TESTBIN)/% 32 $(TESTXTRA) : % : $(TESTBIN)/% 33 test: $(TESTPROG) 34 for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done 35 test.verbose: $(TESTPROG) 36 for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS) -v; done 21 37 22 38 install: $(DESTLIB)/libFITS.a $(DESTLIB)/libFITS.$(DLLTYPE) $(DESTMAN)/fits.1 … … 37 53 38 54 MATRIX_OBJ = \ 39 $(MATR)/F_add_M_value.$(ARCH).o $(MATR)/F_add_M.$(ARCH).o \ 40 $(MATR)/F_create_M.$(ARCH).o $(MATR)/F_divide_M.$(ARCH).o \ 41 $(MATR)/F_free_M.$(ARCH).o $(MATR)/F_copy_M.$(ARCH).o \ 42 $(MATR)/F_write_M.$(ARCH).o $(MATR)/F_get_M_value.$(ARCH).o \ 43 $(MATR)/F_multiply_M.$(ARCH).o $(MATR)/F_read_M.$(ARCH).o \ 44 $(MATR)/F_insert_M.$(ARCH).o $(MATR)/F_set_M_value.$(ARCH).o \ 45 $(MATR)/F_convert_format.$(ARCH).o $(MATR)/F_read_segment.$(ARCH).o \ 46 $(MATR)/F_read_portion.$(ARCH).o $(MATR)/F_load_M.$(ARCH).o \ 47 $(MATR)/F_matrix.$(ARCH).o $(MATR)/F_compress_M.$(ARCH).o \ 48 $(MATR)/F_uncompress_data.$(ARCH).o $(MATR)/F_swap_raw.$(ARCH).o 55 $(MATR)/F_add_M_value.$(ARCH).o $(MATR)/F_add_M.$(ARCH).o \ 56 $(MATR)/F_create_M.$(ARCH).o $(MATR)/F_divide_M.$(ARCH).o \ 57 $(MATR)/F_free_M.$(ARCH).o $(MATR)/F_copy_M.$(ARCH).o \ 58 $(MATR)/F_write_M.$(ARCH).o $(MATR)/F_get_M_value.$(ARCH).o \ 59 $(MATR)/F_multiply_M.$(ARCH).o $(MATR)/F_read_M.$(ARCH).o \ 60 $(MATR)/F_insert_M.$(ARCH).o $(MATR)/F_set_M_value.$(ARCH).o \ 61 $(MATR)/F_convert_format.$(ARCH).o $(MATR)/F_read_segment.$(ARCH).o \ 62 $(MATR)/F_read_portion.$(ARCH).o $(MATR)/F_load_M.$(ARCH).o \ 63 $(MATR)/F_matrix.$(ARCH).o $(MATR)/F_compress_utils.$(ARCH).o \ 64 $(MATR)/F_compress_M.$(ARCH).o $(MATR)/F_compress_data.$(ARCH).o \ 65 $(MATR)/F_uncompress_M.$(ARCH).o $(MATR)/F_uncompress_data.$(ARCH).o \ 66 $(MATR)/F_swap_raw.$(ARCH).o 49 67 50 68 TABLE_OBJ = \ … … 55 73 $(TABL)/F_set_column.$(ARCH).o $(TABL)/F_get_column.$(ARCH).o \ 56 74 $(TABL)/F_table_row.$(ARCH).o $(TABL)/F_free_T.$(ARCH).o \ 57 $(TABL)/F_table_varlength.$(ARCH).o $(TABL)/F_copy_T.$(ARCH).o 75 $(TABL)/F_table_varlength.$(ARCH).o $(TABL)/F_copy_T.$(ARCH).o \ 76 $(TABL)/F_compress_T.$(ARCH).o $(TABL)/F_uncompress_T.$(ARCH).o 58 77 59 78 EXTERN_OBJ = \ -
trunk/Ohana/src/libfits/doc/notes-compress.txt
r15487 r38441 1 2 20150525 : 3 4 uncompression steps: 5 6 * read in a table: gfits_fread_ftable_data (f, &ftable, FALSE); (no byte swap) 7 * uncompress the image: gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable); 8 * get ZIMAGE from heaer & delete 9 * get ZCMPTYPE 10 * get ZBITPIX, ZNAXIS, ZNAXISnn 11 * get ZTILEn (if missing ZTILE1 = Nx, others 1) 12 * get ZNAME, ZVAL 13 * ZSIMPLE, ZTENSION, ZEXTEND, ZBLOCKED, ZPCOUNT, ZGCOUNT, etc 14 * ZSCALE, ZBLANK, OBLANK, ZZERO 15 16 * data is stored in fits table COMPRESSED_DATA (1PB, 1PI, 1PJ) 17 18 ------------------------------------------------ 1 19 2 20 TFORMn : rPt(e_max) -
trunk/Ohana/src/libfits/extern/gzip.c
r23816 r38441 2 2 # include <gfitsio.h> 3 3 # include <zlib.h> 4 # define EXTRA_VERBOSE 0 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 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) 120 { 121 z_stream stream; 122 int 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 = (alloc_func)0; 134 stream.zfree = (free_func)0; 135 136 // MAX_WBITS = 15 137 err = inflateInit2(&stream, -15); 138 if (err != Z_OK) return err; 139 140 err = inflate(&stream, Z_FINISH); 141 if (err != Z_STREAM_END) { 142 inflateEnd(&stream); 143 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 144 return Z_DATA_ERROR; 145 return err; 146 } 147 assert (stream.total_out <= *destLen); 148 *destLen = stream.total_out; 149 150 err = inflateEnd(&stream); 151 return err; 119 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 120 121 int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) { 122 123 z_stream stream; 124 int i, err; 125 126 stream.next_in = (Bytef*)source; 127 stream.avail_in = (uInt)sourceLen; 128 129 /* Check for source > 64K on 16-bit machine: */ 130 if ((uLong)stream.avail_in != sourceLen) ESCAPE (Z_BUF_ERROR); 131 132 stream.next_out = dest; 133 stream.avail_out = (uInt)*destLen; // allocated space 134 if ((uLong)stream.avail_out != *destLen) ESCAPE (Z_BUF_ERROR); 135 136 stream.zalloc = Z_NULL; 137 stream.zfree = Z_NULL; 138 stream.opaque = Z_NULL; 139 140 if (EXTRA_VERBOSE) { 141 fprintf (stderr, "inp cmp: "); 142 for (i = 0; i < sourceLen; i++) { 143 fprintf (stderr, "0x%02hhx ", source[i]); 144 } 145 fprintf (stderr, "\n"); 146 } 147 148 // the '1' is the compression level: make this a user argument 149 // NOTE: cfitsio uses a fixed value of 1 150 // I am using deflateInit2 because cfitsio expects gzip, not just zlib 151 // windowBits = 31 = (15 + 16) = (2^15 window bits) + (create a gzip stream) 152 err = deflateInit2(&stream, 1, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY); 153 if (0) fprintf (stderr, "inp buffers cmp 0: %d => %d => %d\n", stream.avail_in, stream.avail_out, (int) stream.total_out); 154 155 if (err != Z_OK) ESCAPE(err); 156 157 // XXX this is written to do the compression in a single pass. it could be re-done to have 158 // the compression occur in a series of steps 159 err = deflate(&stream, Z_FINISH); 160 if (err != Z_STREAM_END) { 161 err = deflateEnd(&stream); 162 ESCAPE (Z_BUF_ERROR); 163 } 164 165 if (EXTRA_VERBOSE) { 166 fprintf (stderr, "out cmp: "); 167 for (i = 0; i < stream.total_out; i++) { 168 fprintf (stderr, "0x%02hhx ", dest[i]); 169 } 170 fprintf (stderr, "\n"); 171 } 172 173 assert (stream.total_out <= *destLen); 174 *destLen = stream.total_out; 175 176 err = deflateEnd(&stream); 177 return err; 152 178 } 179 180 // NOTE: CFITSIO uses gzip format, not just zlib 181 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) { 182 183 z_stream stream; 184 int i, err; 185 186 stream.next_in = (Bytef*)source; 187 stream.avail_in = (uInt)sourceLen; 188 189 /* Check for source > 64K on 16-bit machine: */ 190 if ((uLong)stream.avail_in != sourceLen) ESCAPE (Z_BUF_ERROR); 191 192 stream.next_out = dest; 193 stream.avail_out = (uInt)*destLen; 194 if ((uLong)stream.avail_out != *destLen) ESCAPE (Z_BUF_ERROR); 195 196 stream.zalloc = Z_NULL; 197 stream.zfree = Z_NULL; 198 stream.opaque = Z_NULL; 199 200 if (EXTRA_VERBOSE) { 201 fprintf (stderr, "inp unc: "); 202 for (i = 0; i < sourceLen; i++) { 203 fprintf (stderr, "0x%02hhx ", source[i]); 204 } 205 fprintf (stderr, "\n"); 206 } 207 208 // windowBits = 47 = (15 + 32) = (2^15 window bits) + (test for either gzip or zlib 209 // streams). NOTE: modern versions of zlib (version > 1.2.3.4) allow for windowBits = 0 210 // (or 16 or 32) to use the compressed stream windowBits value. IPP cluster still has 211 // zlib version = 1.2.3, so we cannot use this feature. 212 err = inflateInit2(&stream, 47); 213 if (err != Z_OK) ESCAPE (err); 214 215 err = inflate(&stream, Z_FINISH); 216 if (err != Z_STREAM_END) { 217 inflateEnd(&stream); 218 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) ESCAPE (Z_DATA_ERROR); 219 ESCAPE(err); 220 } 221 222 if (EXTRA_VERBOSE) { 223 fprintf (stderr, "out unc: "); 224 for (i = 0; i < stream.total_out; i++) { 225 fprintf (stderr, "0x%02hhx ", dest[i]); 226 } 227 fprintf (stderr, "\n"); 228 } 229 230 assert (stream.total_out <= *destLen); 231 *destLen = stream.total_out; 232 233 err = inflateEnd(&stream); 234 return err; 235 } 236 -
trunk/Ohana/src/libfits/header/F_copy_H.c
r27435 r38441 30 30 return (TRUE); 31 31 } 32 33 int gfits_copy_header_ptr (Header *in, Header *out) { 34 35 int i; 36 37 if (!in) return FALSE; 38 if (!out) return FALSE; 39 40 out[0].simple = in[0].simple; 41 out[0].unsign = in[0].unsign; 42 out[0].extend = in[0].extend; 43 out[0].bitpix = in[0].bitpix; 44 45 out[0].Naxes = in[0].Naxes; 46 for (i = 0; i < FT_MAX_NAXES; i++) 47 out[0].Naxis[i] = in[0].Naxis[i]; 48 49 out[0].datasize = in[0].datasize; 50 51 out[0].pcount = in[0].pcount; 52 out[0].gcount = in[0].gcount; 53 out[0].bzero = in[0].bzero; 54 out[0].bscale = in[0].bscale; 55 56 out[0].buffer = in[0].buffer; 57 58 return (TRUE); 59 } -
trunk/Ohana/src/libfits/header/F_modify.c
r34577 r38441 48 48 strncpy (comment, qe, p + 80 - qe); 49 49 } 50 gfits_pad_ending (comment, ' ', 82); /* comment must contain spaces to the end */50 gfits_pad_ending (comment, 0x20, 82); /* comment must contain spaces to the end */ 51 51 52 52 /* write the numeric modes */ … … 134 134 strncpy (comment, qe, p + 80 - qe); 135 135 } 136 gfits_pad_ending (comment, ' ', 82); /* comment must contain spaces to the end */136 gfits_pad_ending (comment, 0x20, 82); /* comment must contain spaces to the end */ 137 137 138 138 /* write the boolean mode */ … … 166 166 if (!ptr) goto invalid; 167 167 strncpy (comment, ptr, 80); 168 gfits_pad_ending (comment, ' ', 82); /* comment must contain spaces to the end */168 gfits_pad_ending (comment, 0x20, 82); /* comment must contain spaces to the end */ 169 169 snprintf (string, 81, "%-8s= %s / %-s", field, data, comment); 170 170 /* this will keep the original line, but truncate the comment */ … … 296 296 */ 297 297 298 // XXX this is an absurd patch on a gcc bug: memset has a problem is value != 0 and N is constant 299 void myMemset (char *ptr, int value, size_t N) { 300 301 char *p = ptr; 302 303 size_t i = 0; 304 for (i = 0; i < N; i++, p++) { 305 *p = value; 306 } 307 } 308 298 309 /* fill 'line' with Nbyte space from first NULL to last byte with value */ 299 310 void gfits_pad_ending (char *line, char value, int Nbyte) { 300 301 char *p;302 int N;303 311 304 312 line[Nbyte-1] = 0; 305 313 306 p = line + strlen (line);307 N = MAX (Nbyte - strlen (line) - 1, 0);308 m emset (p, value, N);314 char *p = line + strlen (line); 315 size_t N = MAX (Nbyte - strlen (line) - 1, 0); 316 myMemset (p, value, N); 309 317 } 310 318 -
trunk/Ohana/src/libfits/include/gfitsio.h
r38255 r38441 73 73 off_t datasize; // size of the buffer (including block padding at the end) 74 74 off_t validsize; // size of the valid portion of the table (< validsize if file is short) 75 off_t heap_start; // byte offset to start of HEAP 75 76 } FTable; 76 77 … … 85 86 } VTable; 86 87 87 typedef struct { 88 int maxlen; // max size of all table rows 89 int nbytes; // number of bytes per column element 90 int Nstart; // byte offset of this column relative to first column 91 off_t heap_start; // byte offset to start of HEAP 92 char format; // data format character (one of: XLABIJEDCM) 93 char mode; // access data pointer type (one of P or Q) 88 // description / metadata needed for a single varlength column. A varlength column has a 89 // 2-element array giving the (length,offset) of data in the heap. Below, 'real data' are 90 // the values in the heap; 'metadata' are the values in the main table. 91 typedef struct { 92 int column; // field number (of the metadata) 93 char format; // format character for real data (one of: XLABIJKEDCM) 94 char mode; // format character for metadata (one of P [float] or Q [double]) 95 int maxlen; // max size of all table rows for this column 96 int nbytes; // number of bytes per real data column element 97 int offset; // byte offset of the metadata column relative to first column 94 98 } VarLengthColumn; 99 100 typedef struct { 101 char ttype[16]; // TTYPE field of original table 102 char ttype_cmt[80]; // comment associated with TTYPE 103 char tunit[16]; // TUNIT field of original table 104 char tunit_cmt[80]; // comment associated with TUNIT 105 char tformat[16]; // TFORM field of original table 106 char tformat_cmt[80]; // comment associated with TFORM 107 char zctype[80]; // compression type for this field 108 VarLengthColumn zdef; // description of the output variable length column 109 110 char datatype[80]; // named data type associated with ttype (eg, 18J -> int, 18D -> double) 111 int Nvalues; // number of values per row (eg 18J -> 18 int values) 112 int pixsize; // number of bytes per value of this row (eg, 18J -> 4 bytes) 113 int rowsize; // number of bytes for a full row (Nvalues * pixsize) 114 int offset; // byte offset of the real data column relative to first column 115 } TableField; 95 116 96 117 # ifndef PROTO … … 106 127 char *gfits_keyword_end PROTO((char *line)); 107 128 int gfits_copy_header PROTO((Header *in, Header *out)); 129 int gfits_copy_header_ptr PROTO((Header *in, Header *out)); 108 130 int gfits_create_header PROTO((Header *header)); 109 131 int gfits_delete PROTO((Header *header, char *field, int N)); … … 117 139 int gfits_modify PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5); 118 140 int gfits_print PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(printf, 3, 5); 119 int gfits_modify_alt PROTO((Header *header, char *field, char *mode, int N,...)); 120 int gfits_print_alt PROTO((Header *header, char *field, char *mode, int N,...)); 141 int gfits_modify_alt PROTO((Header *header, char *field, char *mode, int N,...)); // do not use a FORMAT: non-standard fmt chars 142 int gfits_print_alt PROTO((Header *header, char *field, char *mode, int N,...)); // do not use a FORMAT: non-standard fmt chars 121 143 int gfits_find_Xheader PROTO((FILE *f, Header *header, char *extname)); 122 144 int gfits_read_Xheader PROTO((char *filename, Header *header, int N)); … … 124 146 int gfits_save_header PROTO((FILE *f, Header *header)); 125 147 int gfits_scan PROTO((Header *header, char *field, char *mode, int N,...)) OHANA_FORMAT(scanf, 3, 5); 126 int gfits_scan_alt PROTO((Header *header, char *field, char *mode, int N,...)); 148 int gfits_scan_alt PROTO((Header *header, char *field, char *mode, int N,...)); // do not use a FORMAT: non-standard fmt chars 127 149 int gfits_set_unsign_mode PROTO((int mode)); 128 150 int gfits_stripwhite PROTO((char *string)); … … 133 155 off_t gfits_data_min_size PROTO((Header *header)); 134 156 off_t gfits_data_pad_size PROTO((off_t rawsize)); 157 off_t gfits_heap_start PROTO((Header *header)); 135 158 int gfits_extended_to_primary PROTO((Header *header, int simple, char *comment)); 136 159 int gfits_primary_to_extended PROTO((Header *header, char *exttype, char *comment)); … … 166 189 void gfits_set_matrix_value PROTO((Matrix *matrix, off_t x, off_t y, double value)); 167 190 int gfits_write_matrix PROTO((char *filename, Matrix *matrix)); 191 168 192 int gfits_uncompress_image PROTO((Header *header, Matrix *matrix, FTable *ftable)); 169 int gfits_uncompress_data PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize)); 170 int gfits_distribute_data PROTO((Matrix *matrix, int bitpix, char *data, int Ndata, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero)); 171 int gfits_byteswap_zdata PROTO((char *zdata, int Nzdata, int bitpix)); 193 int gfits_uncompress_data PROTO((char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize)); 194 int gfits_distribute_data PROTO((Matrix *matrix, char *data, int Ndata, int bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero)); 195 196 int gfits_compress_data PROTO((char *zdata, int *Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *rawdata, int Nraw, int raw_pixsize, int Nx, int Ny)); 197 int gfits_compress_image PROTO((Header *header, Matrix *matrix, FTable *ftable, int *Ztile, char *zcmptype)); 198 int gfits_collect_data PROTO((Matrix *matrix, char *raw, int Nraw, int raw_pixsize, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero)); 199 200 int gfits_copy_keywords_compress PROTO((Header *srchead, Header *tgthead)); 172 201 int gfits_swap_raw PROTO((Matrix *matrix)); 173 int gfits_extension_is_compressed PROTO((Header *header)); 202 174 203 off_t gfits_tile_size PROTO((Matrix *matrix, int *otile, int *ztile)); 204 int gfits_imtile_maxsize PROTO((Matrix *matrix, int *ztile)); 205 int gfits_imtile_count PROTO((Matrix *matrix, int *ztile, int *ntile)); 206 int gfits_imtile_start PROTO((Matrix *matrix, int *otile)); 207 int gfits_imtile_next PROTO((Matrix *matrix, int *ztile, int *ntile, int *otile)); 208 209 int gfits_extension_is_compressed_image PROTO((Header *header)); 210 int gfits_extension_is_compressed_table PROTO((Header *header)); 211 int gfits_byteswap_zdata PROTO((char *zdata, int Nzdata, int pixsize)); 212 int gfits_compressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); 175 213 int gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); 176 int gfits_vartable_heap_pixsize PROTO((char format)); 214 int gfits_uncompressed_data_bitpix PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); 215 int gfits_vartable_heap_pixsize PROTO((char format)); 216 int gfits_cmptype_valid PROTO((char *cmptype)); 217 218 int gfits_varlength_column_add_data PROTO((FTable *table, char *data, off_t Ndata, int row, VarLengthColumn *column)); 219 void *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, off_t row, off_t *length)); 220 int gfits_varlength_column_define PROTO((FTable *ftable, VarLengthColumn *def, int column)); 221 int gfits_varlength_column_finish PROTO((FTable *ftable, VarLengthColumn *def)); 222 int gfits_byteswap_varlength_column PROTO((FTable *ftable, int column)); 177 223 178 224 /******************************* Table functions *************/ … … 183 229 char *gfits_table_print PROTO((FTable *ftable,...)); 184 230 int gfits_add_rows PROTO((FTable *ftable, char *data, off_t Nrow, off_t Nbytes)); 231 int gfits_set_table_rows PROTO((Header *header, FTable *table, off_t Nrows)); 185 232 int gfits_bintable_format PROTO((char *format, char *type, int *Nval, int *Nbytes)); 186 233 int gfits_create_table PROTO((Header *header, FTable *ftable)); … … 199 246 int gfits_fwrite_ftable_range PROTO((FILE *f, FTable *table, off_t start, off_t Nrows, off_t Ndisk, off_t Ntotal)); 200 247 int gfits_get_bintable_column PROTO((Header *header, FTable *table, char *label, void **data)); 248 int gfits_get_bintable_column_raw PROTO((Header *header, FTable *table, char *label, void **data, char nativeOrder)); 201 249 int gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval)); 250 void *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol)); 202 251 int gfits_get_bintable_column_type_by_N PROTO((Header *header, int N, char *type, int *Nval)); 203 void *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol));252 void *gfits_get_bintable_column_data_raw PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder)); 204 253 int gfits_get_table_column PROTO((Header *header, FTable *table, char *label, void **data)); 205 254 int gfits_get_table_column_type PROTO((Header *header, char *label, char *type)); … … 207 256 int gfits_read_table PROTO((char *filename, FTable *ftable)); 208 257 int gfits_set_bintable_column PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow)); 209 int gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow ));258 int gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder)); 210 259 int gfits_set_table_column PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow)); 211 260 int gfits_table_column PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4); … … 219 268 int gfits_copy_ftable PROTO((FTable *in, FTable *out)); 220 269 int gfits_copy_vtable PROTO((VTable *in, VTable *out)); 270 int gfits_copy_ftable_ptr PROTO((FTable *in, FTable *out)); 221 271 222 272 int gfits_create_Theader PROTO((Header *header, char *type)); … … 227 277 int gfits_write_Theader PROTO((char *filename, Header *header)); 228 278 229 int gfits_varlength_column_define PROTO((FTable *ftable, VarLengthColumn *def, int column)); 230 void *gfits_varlength_column_pointer PROTO((FTable *ftable, VarLengthColumn *column, off_t row, off_t *length)); 279 int gfits_compress_table PROTO((FTable *srctable, FTable *tgttable, int ztilelen, char *zcmptype)); 280 int gfits_uncompress_table PROTO((FTable *srctable, FTable *tgttable)); 281 282 // XXX EAM for testing 283 int gfits_dump_raw_table (FTable *table, char *message); 284 int gfits_dump_cmp_table (FTable *table, char *message); 285 231 286 232 287 #endif /* FITSIO */ -
trunk/Ohana/src/libfits/matrix/F_matrix.c
r35164 r38441 2 2 # include <gfitsio.h> 3 3 4 off_t gfits_data_size (Header *header) { 5 6 int i; 7 off_t Nrec, size; 8 9 if (header[0].Naxes == 0) return (0); 10 11 size = abs(header[0].bitpix / 8); 12 13 for (i = 0; i < header[0].Naxes; i++) 14 size *= header[0].Naxis[i]; 15 16 // XXX do I multiply this times gcount? 17 size += header[0].pcount; 18 19 /* round up to next complete block */ 20 if (size % FT_RECORD_SIZE) { 21 Nrec = 1 + (int) (size / FT_RECORD_SIZE); 22 size = FT_RECORD_SIZE * Nrec; 23 } 24 25 return (size); 26 } 27 28 off_t gfits_data_min_size (Header *header) { 4 off_t gfits_heap_start (Header *header) { 29 5 30 6 int i; … … 38 14 size *= header[0].Naxis[i]; 39 15 40 // XXX do I multiply this times gcount? 16 return (size); 17 } 18 19 off_t gfits_data_min_size (Header *header) { 20 21 off_t size = gfits_heap_start (header); 41 22 size += header[0].pcount; 23 24 // XXX what do I do with gcount? 42 25 43 26 return (size); … … 46 29 off_t gfits_data_pad_size (off_t rawsize) { 47 30 48 off_t Nrec, size; 49 50 size = rawsize; 31 off_t size = rawsize; 51 32 52 33 /* round up to next complete block */ 53 34 if (rawsize % FT_RECORD_SIZE) { 54 Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE);35 off_t Nrec = 1 + (int) (rawsize / FT_RECORD_SIZE); 55 36 size = FT_RECORD_SIZE * Nrec; 56 37 } … … 58 39 return (size); 59 40 } 41 42 off_t gfits_data_size (Header *header) { 43 off_t rawsize = gfits_data_min_size(header); 44 off_t size = gfits_data_pad_size (rawsize); 45 46 return (size); 47 } 48 -
trunk/Ohana/src/libfits/matrix/F_uncompress_data.c
r23815 r38441 26 26 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 27 27 28 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize) { 28 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 29 30 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize) { 29 31 30 32 int status; 31 static int Ninsum = 0;32 static int Noutsum = 0;33 33 34 if (!strcasecmp(cmptype, "GZIP_1")) { 35 unsigned long tNout = *Nout * out_pixsize; 34 // do not actually uncompress : this is used for testing 35 if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1") || !strcasecmp(cmptype, "NONE_2")) { 36 memcpy (outdata, zdata, Nzdata); 37 myAssert (*Nout == Nzdata, "invalid size"); 38 *Nout = Nzdata / out_pixsize; 39 return (TRUE); 40 } 41 42 if (!strcasecmp(cmptype, "GZIP_1") || !strcasecmp(cmptype, "GZIP_2")) { 43 // unsigned long tNout = *Nout * out_pixsize; 44 // input value of *Nout is number of BYTES 45 unsigned long tNout = Nout_alloc; 36 46 37 47 // for GZIP data, I need to check for and remove the header on the first block: 38 gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata); 48 // XXX maybe not anymore 49 // gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata); 39 50 40 51 // uncompress does not require us to know the expected number of pixel; it tells us the number 52 // XXX shouldn't we validate the result : we think we know the size 41 53 status = gfits_uncompress ((Bytef *) outdata, &tNout, (Bytef *) zdata, Nzdata); 42 if (status != Z_OK) { 43 fprintf (stderr, "error in uncompress (GZIP)\n"); 44 return (FALSE); 45 } 54 if (status != Z_OK) ESCAPE(FALSE); 55 myAssert (*Nout == tNout, "uncompressed size mismatch"); 46 56 *Nout = tNout / out_pixsize; 57 // output value of *Nout is number of PIXELS 47 58 48 59 // the resulting uncompressed data is byteswapped 49 if (!gfits_byteswap_zdata (outdata, *Nout, out_pixsize)) return (FALSE);60 // if (!gfits_byteswap_zdata (outdata, *Nout, out_pixsize)) return (FALSE); 50 61 51 62 return (TRUE); 52 63 } 53 64 54 if (!strcasecmp(cmptype, "RICE_1") ) {65 if (!strcasecmp(cmptype, "RICE_1") || !strcasecmp(cmptype, "RICE_ONE")) { 55 66 int i, blocksize; 56 67 // look for the BLOCKSIZE … … 66 77 } 67 78 68 int Npix; 69 // Npix = *Nout * (out_pixsize / 4.0); 70 Npix = *Nout; 71 72 Ninsum += Nzdata; 73 Noutsum += *Nout; 74 // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum); 79 int status = FALSE; 80 int Npix = *Nout / out_pixsize; 81 int k; 75 82 76 83 switch (out_pixsize) { 77 84 case 4: 78 85 // rice decompression from the CFITSIO source tree : we need to tell it the expected number of pixels 79 // is also REQUIRES 4byte output, which is fairly stupid. 80 if (fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize)) { 81 fprintf (stderr, "error in rice decompression\n"); 82 return (FALSE); 86 status = fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize); 87 break; 88 case 2: 89 if (0) { 90 fprintf (stderr, "Nout: %d, Nrawpix: %d\n", Nzdata, Npix); 91 fprintf (stderr, "cmp out: "); 92 for (k = 0; k < Nzdata; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); } 93 fprintf (stderr, "\n"); 83 94 } 84 return (TRUE); 85 86 case 2: 87 if (fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize)) { 88 fprintf (stderr, "error in rice decompression\n"); 89 return (FALSE); 90 } 91 return (TRUE); 92 95 status = fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize); 96 break; 93 97 case 1: 94 if (fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize)) { 95 fprintf (stderr, "error in rice decompression\n"); 96 return (FALSE); 97 } 98 return (TRUE); 99 98 status = fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize); 99 break; 100 100 default: 101 101 fprintf (stderr, "invalid output pixel size %d\n", out_pixsize); 102 return (FALSE); 102 status = FALSE; 103 break; 103 104 } 104 105 if (status) { 106 *Nout = 0; 107 return FALSE; 108 } 109 *Nout = Npix; 110 return TRUE; 105 111 } 106 112 -
trunk/Ohana/src/libfits/table/F_copy_T.c
r34088 r38441 6 6 7 7 /* find buffer size */ 8 out[0].validsize = in[0].validsize; 9 out[0].datasize = in[0].datasize; 8 out[0].validsize = in[0].validsize; 9 out[0].datasize = in[0].datasize; 10 out[0].heap_start = in[0].heap_start; 10 11 11 12 ALLOCATE (out[0].buffer, char, out[0].datasize); 12 13 memcpy (out[0].buffer, in[0].buffer, out[0].datasize); 14 return (TRUE); 15 } 16 17 /*********************** copy ftable pointers (does not copy memory) ***********************************/ 18 int gfits_copy_ftable_ptr (FTable *in, FTable *out) { 19 20 if (!in) return FALSE; 21 if (!out) return FALSE; 22 23 /* find buffer size */ 24 out[0].validsize = in[0].validsize; 25 out[0].datasize = in[0].datasize; 26 out[0].heap_start = in[0].heap_start; 27 out[0].header = in[0].header; 28 out[0].buffer = in[0].buffer; 13 29 return (TRUE); 14 30 } … … 28 44 29 45 /* find buffer size */ 30 out[0].datasize = in[0].datasize; 31 out[0].pad = in[0].pad; 32 out[0].Nrow = in[0].Nrow; 46 out[0].datasize = in[0].datasize; 47 // out[0].heap_start = in[0].heap_start; 48 out[0].pad = in[0].pad; 49 out[0].Nrow = in[0].Nrow; 33 50 34 51 off_t Nrows = out[0].Nrow; -
trunk/Ohana/src/libfits/table/F_create_T.c
r35756 r38441 4 4 /*********************** fits init table *******************************/ 5 5 int gfits_init_table (FTable *table) { 6 table[0].header = NULL; 7 table[0].buffer = NULL; 8 table[0].datasize = 0; 9 table[0].validsize = 0; 6 table[0].header = NULL; 7 table[0].buffer = NULL; 8 table[0].datasize = 0; 9 table[0].heap_start = 0; 10 table[0].validsize = 0; 10 11 return (TRUE); 11 12 … … 42 43 } 43 44 table[0].datasize = Nbytes; 45 table[0].heap_start = gfits_heap_start (header); 44 46 return (TRUE); 45 47 48 } 49 50 /*********************** fits create table *******************************/ 51 int gfits_set_table_rows (Header *header, FTable *table, off_t Nrows) { 52 53 header[0].Naxis[1] = Nrows; 54 gfits_modify (header, "NAXIS2", OFF_T_FMT, 1, Nrows); 55 56 off_t Nbytes = gfits_data_size (header); 57 REALLOCATE (table[0].buffer, char, Nbytes); 58 bzero (table[0].buffer, Nbytes); 59 table[0].datasize = Nbytes; 60 table[0].heap_start = gfits_heap_start (header); 61 return (TRUE); 46 62 } 47 63 … … 60 76 Ny = table[0].header[0].Naxis[0]; 61 77 table[0].datasize = gfits_data_size (header); 78 // table[0].heap_start = gfits_heap_start (header); 62 79 table[0].pad = table[0].datasize - Nx*Ny; 63 80 -
trunk/Ohana/src/libfits/table/F_define_column.c
r35756 r38441 66 66 sprintf (field, "TTYPE%d", Nfields); 67 67 gfits_modify (header, field, "%s", 1, label); 68 gfits_modify_alt (header, field, "%C", 1, comment); 69 sprintf (field, "TUNIT%d", Nfields); 70 gfits_modify (header, field, "%s", 1, unit); 68 if (comment) { 69 gfits_modify_alt (header, field, "%C", 1, comment); 70 } 71 if (unit) { 72 sprintf (field, "TUNIT%d", Nfields); 73 gfits_modify (header, field, "%s", 1, unit); 74 } 71 75 sprintf (field, "TFORM%d", Nfields); 72 76 gfits_modify (header, field, "%s", 1, format); -
trunk/Ohana/src/libfits/table/F_get_column.c
r37039 r38441 17 17 18 18 void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol) { 19 void *data = gfits_get_bintable_column_data_raw (header, table, label, type, Nrow, Ncol, FALSE); 20 return data; 21 } 22 23 void *gfits_get_bintable_column_data_raw (Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol, char nativeOrder) { 19 24 20 25 off_t Nx, Ny; … … 71 76 } 72 77 73 /* convert data in-situ with correct type, byte swap and Bzero/Bscale */ 78 // NOTE: we have already copied the data to 'array', so the blocks below 79 // only need to swap if this is a direct copy 74 80 Pin = array; 75 81 Pout = array; 82 int directCopy = (Bzero == 0.0) && (Bscale == 1.0); 83 84 /* convert data in-situ with correct type, byte swap and Bzero/Bscale */ 76 85 if (!strcmp (type, "char")) { 77 86 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 78 *(char *)Pout = *(char *)Pin*Bscale + Bzero;87 if (!directCopy) { *(char *)Pout = *(char *)Pin*Bscale + Bzero; } 79 88 } 80 89 } 81 90 if (!strcmp (type, "byte")) { 82 91 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 83 *(char *)Pout = *(char *)Pin*Bscale + Bzero;92 if (!directCopy) { *(char *)Pout = *(char *)Pin*Bscale + Bzero; } 84 93 } 85 94 } … … 87 96 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 88 97 # ifdef BYTE_SWAP 89 SWAP_BYTE;90 # endif 91 *(short *)Pout = *(short *)Pin*Bscale + Bzero;98 if (!nativeOrder) { SWAP_BYTE; } 99 # endif 100 if (!directCopy) { *(short *)Pout = *(short *)Pin*Bscale + Bzero; } 92 101 } 93 102 } … … 95 104 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 96 105 # ifdef BYTE_SWAP 97 SWAP_WORD;98 # endif 99 *(int *)Pout = *(int *)Pin*Bscale + Bzero;106 if (!nativeOrder) { SWAP_WORD; } 107 # endif 108 if (!directCopy) { *(int *)Pout = *(int *)Pin*Bscale + Bzero; } 100 109 } 101 110 } 102 111 if (!strcmp (type, "int64_t")) { 103 if ((Bzero == 0.0) && (Bscale == 1.0)) { 104 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 105 # ifdef BYTE_SWAP 106 SWAP_DBLE; 107 # endif 108 *(int64_t *)Pout = *(int64_t *)Pin; 109 } 110 } else { 111 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 112 # ifdef BYTE_SWAP 113 SWAP_DBLE; 114 # endif 115 *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero; 116 } 112 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 113 # ifdef BYTE_SWAP 114 if (!nativeOrder) { SWAP_DBLE; } 115 # endif 116 if (!directCopy) { *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero; } 117 117 } 118 118 } … … 120 120 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 121 121 # ifdef BYTE_SWAP 122 SWAP_WORD;123 # endif 124 *(float *)Pout = *(float *)Pin*Bscale + Bzero;122 if (!nativeOrder) { SWAP_WORD; } 123 # endif 124 if (!directCopy) { *(float *)Pout = *(float *)Pin*Bscale + Bzero; } 125 125 } 126 126 } … … 128 128 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 129 129 # ifdef BYTE_SWAP 130 SWAP_DBLE; 131 # endif 132 *(double *)Pout = *(double *)Pin*Bscale + Bzero; 133 } 134 } 130 if (!nativeOrder) { SWAP_DBLE; } 131 # endif 132 if (!directCopy) { *(double *)Pout = *(double *)Pin*Bscale + Bzero; } 133 } 134 } 135 136 // check that we supplied a valid type 135 137 136 138 *Ncol = Nval; … … 174 176 if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE; 175 177 return (TRUE); 178 } 179 180 /***********************/ 181 int gfits_get_bintable_column_raw (Header *header, FTable *table, char *label, void **data, char nativeOrder) { 182 183 char type[16]; 184 off_t Nrow; 185 int Ncol; 186 187 char *array = gfits_get_bintable_column_data_raw (header, table, label, type, &Nrow, &Ncol, nativeOrder); 188 if (array == NULL) return (FALSE); 189 190 *data = array; 191 return TRUE; 176 192 } 177 193 -
trunk/Ohana/src/libfits/table/F_read_T.c
r37807 r38441 45 45 if (Nread < gfits_data_min_size (table[0].header)) { 46 46 fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__, Nread, gfits_data_min_size (table[0].header)); 47 if (padIfShort) { 48 memset (&table[0].buffer[Nread], 0, Nbytes - Nread); 49 fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n"); 50 table[0].validsize = Nread; 51 table[0].datasize = Nbytes; 52 return (TRUE); 53 } else { 54 gfits_free_table (table); 47 if (!padIfShort) { 48 gfits_free_table (table); 55 49 return (FALSE); 56 50 } 57 } 58 fprintf (stderr, "warning: file missing pad\n"); 51 memset (&table[0].buffer[Nread], 0, Nbytes - Nread); 52 fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n"); 53 } else { 54 fprintf (stderr, "warning: file missing pad\n"); 55 } 59 56 } 60 57 table[0].validsize = Nread; 61 58 table[0].datasize = Nbytes; 59 table[0].heap_start = gfits_heap_start (table->header); 62 60 return (TRUE); 63 61 } … … 93 91 } 94 92 fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__, Nread, Nbytes); 95 if (padIfShort) { 96 memset (&table[0].buffer[Nread], 0, Nbytes - Nread); 97 fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n"); 98 table[0].validsize = Nread; 99 table[0].datasize = Nbytes; 100 } else { 93 if (!padIfShort) { 101 94 free (table[0].buffer); 102 95 return (FALSE); 103 96 } 97 memset (&table[0].buffer[Nread], 0, Nbytes - Nread); 98 fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n"); 104 99 } 105 100 … … 107 102 table[0].header[0].Naxis[1] = Nrows; 108 103 gfits_modify (table[0].header, "NAXIS2", OFF_T_FMT, 1, Nrows); 109 table[0].datasize = gfits_data_size (table[0].header); 104 table[0].validsize = Nread; 105 table[0].datasize = Nbytes; 106 table[0].heap_start = gfits_heap_start (table->header); 110 107 111 108 return (TRUE); … … 122 119 Ny = table[0].header[0].Naxis[1]; 123 120 table[0].datasize = gfits_data_size (table[0].header); 121 // table[0].heap_start = gfits_heap_start (table[0].header); 124 122 table[0].pad = table[0].datasize - Nx*Ny; 125 123 … … 206 204 for (i = 0; i < Nrow; i++) table[0].row[i] = row[i]; 207 205 table[0].datasize = gfits_data_size (table[0].header); 206 // table[0].heap_start = gfits_heap_start (table[0].header); 208 207 table[0].pad = table[0].datasize - Nx*Ny; 209 208 return (TRUE); -
trunk/Ohana/src/libfits/table/F_set_column.c
r37039 r38441 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 4 # define SWAP_NONE 5 6 # ifdef BYTE_SWAP 3 7 # define SWAP_BYTE { \ 4 8 char tmp; \ … … 14 18 tmp = Pout[2]; Pout[2] = Pout[5]; Pout[5] = tmp; \ 15 19 tmp = Pout[3]; Pout[3] = Pout[4]; Pout[4] = tmp; } 20 # else 21 # define SWAP_BYTE 22 # define SWAP_WORD 23 # define SWAP_DBLE 24 # endif 16 25 17 26 /***********************/ 18 27 int gfits_set_bintable_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) { 19 28 20 off_t Nx, Ny , nbytes;29 off_t Nx, Ny; 21 30 int i, N, Nfields; 22 31 int Nval, Nbytes, Nstart, Nv, Nb; … … 55 64 gfits_scan (header, "NAXIS1", OFF_T_FMT, 1, &Nx); 56 65 gfits_scan (header, "NAXIS2", OFF_T_FMT, 1, &Ny); 66 67 // if no rows have yet been assigned, we need to allocate the full data buffer 57 68 if (Ny == 0) { 58 69 Ny = Nrow; 59 header[0].Naxis[1] = Ny; 60 gfits_modify (header, "NAXIS2", OFF_T_FMT, 1, Ny); 61 62 nbytes = gfits_data_size (header); 63 REALLOCATE (table[0].buffer, char, MAX (nbytes, 1)); 64 bzero (table[0].buffer, nbytes); 65 table[0].datasize = nbytes; 70 gfits_set_table_rows (header, table, Ny); 66 71 } 67 72 if (Ny != Nrow) return (FALSE); … … 143 148 } 144 149 150 if (!strcmp (type, "var")) { 151 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { 152 *(int *)Pout = *(int *)Pin; 153 # ifdef BYTE_SWAP 154 SWAP_WORD; 155 # endif 156 } 157 } 158 159 if (!strcmp (type, "var64")) { 160 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { 161 *(int *)Pout = *(int *)Pin; 162 # ifdef BYTE_SWAP 163 SWAP_DBLE; 164 # endif 165 } 166 } 167 145 168 /* check array space */ 146 169 if (Nx*Ny < Nx*(Nrow - 1) + Nstart + Nval*Nbytes) { … … 161 184 162 185 /***********************/ 163 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow) { 164 165 off_t Nx, Ny, nbytes; 186 // convert the input data array (of the specified intype) to the desired table data type. swap unless nativeOrder is requested 187 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder) { 188 189 off_t Nx, Ny; 166 190 int i, N, Nfields; 167 191 int Nval, NbytesOut, Nstart, Nv, Nb; … … 202 226 if (Ny == 0) { 203 227 Ny = Nrow; 204 header[0].Naxis[1] = Ny; 205 gfits_modify (header, "NAXIS2", OFF_T_FMT, 1, Ny); 206 207 nbytes = gfits_data_size (header); 208 REALLOCATE (table[0].buffer, char, MAX (nbytes, 1)); 209 bzero (table[0].buffer, nbytes); 210 table[0].datasize = nbytes; 228 gfits_set_table_rows (header, table, Ny); 211 229 } 212 230 if (Ny != Nrow) return (FALSE); … … 230 248 // if (!strcmp (intype, #ITYPE)) { 231 249 250 int directCopy = (Bzero == 0.0) && (Bscale == 1.0); 251 252 # define SET_VALUES(OUTNAME, OUTTYPE, INNAME, INTYPE, SWAP_OP, NBYTES_IN) \ 253 if (!strcmp (outtype, OUTNAME) && !strcmp (intype, INNAME)) { \ 254 int NbytesIn = NBYTES_IN; \ 255 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { \ 256 if (directCopy) { \ 257 *(OUTTYPE *)Pout = *(INTYPE *)Pin; \ 258 } else { \ 259 *(OUTTYPE *)Pout = (*(INTYPE *)Pin - Bzero) / Bscale; \ 260 } \ 261 if (!nativeOrder) { SWAP_OP; }}} 262 263 SET_VALUES("char", char, "char", char, SWAP_NONE, 1); 264 SET_VALUES("byte", char, "char", char, SWAP_NONE, 1); 265 SET_VALUES("short", short, "char", char, SWAP_BYTE, 1); 266 SET_VALUES("int", int, "char", char, SWAP_WORD, 1); 267 SET_VALUES("int64_t", int64_t, "char", char, SWAP_DBLE, 1); 268 SET_VALUES("float", float, "char", char, SWAP_WORD, 1); 269 SET_VALUES("double", double, "char", char, SWAP_DBLE, 1); 270 271 SET_VALUES("char", char, "byte", char, SWAP_NONE, 1); 272 SET_VALUES("byte", char, "byte", char, SWAP_NONE, 1); 273 SET_VALUES("short", short, "byte", char, SWAP_BYTE, 1); 274 SET_VALUES("int", int, "byte", char, SWAP_WORD, 1); 275 SET_VALUES("int64_t", int64_t, "byte", char, SWAP_DBLE, 1); 276 SET_VALUES("float", float, "byte", char, SWAP_WORD, 1); 277 SET_VALUES("double", double, "byte", char, SWAP_DBLE, 1); 278 279 SET_VALUES("char", char, "short", short, SWAP_NONE, 2); 280 SET_VALUES("byte", char, "short", short, SWAP_NONE, 2); 281 SET_VALUES("short", short, "short", short, SWAP_BYTE, 2); 282 SET_VALUES("int", int, "short", short, SWAP_WORD, 2); 283 SET_VALUES("int64_t", int64_t, "short", short, SWAP_DBLE, 2); 284 SET_VALUES("float", float, "short", short, SWAP_WORD, 2); 285 SET_VALUES("double", double, "short", short, SWAP_DBLE, 2); 286 287 SET_VALUES("char", char, "int", int, SWAP_NONE, 4); 288 SET_VALUES("byte", char, "int", int, SWAP_NONE, 4); 289 SET_VALUES("short", short, "int", int, SWAP_BYTE, 4); 290 SET_VALUES("int", int, "int", int, SWAP_WORD, 4); 291 SET_VALUES("int64_t", int64_t, "int", int, SWAP_DBLE, 4); 292 SET_VALUES("float", float, "int", int, SWAP_WORD, 4); 293 SET_VALUES("double", double, "int", int, SWAP_DBLE, 4); 294 295 SET_VALUES("char", char, "int64_t", int64_t, SWAP_NONE, 8); 296 SET_VALUES("byte", char, "int64_t", int64_t, SWAP_NONE, 8); 297 SET_VALUES("short", short, "int64_t", int64_t, SWAP_BYTE, 8); 298 SET_VALUES("int", int, "int64_t", int64_t, SWAP_WORD, 8); 299 SET_VALUES("int64_t", int64_t, "int64_t", int64_t, SWAP_DBLE, 8); 300 SET_VALUES("float", float, "int64_t", int64_t, SWAP_WORD, 8); 301 SET_VALUES("double", double, "int64_t", int64_t, SWAP_DBLE, 8); 302 303 SET_VALUES("char", char, "float", float, SWAP_NONE, 4); 304 SET_VALUES("byte", char, "float", float, SWAP_NONE, 4); 305 SET_VALUES("short", short, "float", float, SWAP_BYTE, 4); 306 SET_VALUES("int", int, "float", float, SWAP_WORD, 4); 307 SET_VALUES("int64_t", int64_t, "float", float, SWAP_DBLE, 4); 308 SET_VALUES("float", float, "float", float, SWAP_WORD, 4); 309 SET_VALUES("double", double, "float", float, SWAP_DBLE, 4); 310 311 SET_VALUES("char", char, "double", double, SWAP_NONE, 8); 312 SET_VALUES("byte", char, "double", double, SWAP_NONE, 8); 313 SET_VALUES("short", short, "double", double, SWAP_BYTE, 8); 314 SET_VALUES("int", int, "double", double, SWAP_WORD, 8); 315 SET_VALUES("int64_t", int64_t, "double", double, SWAP_DBLE, 8); 316 SET_VALUES("float", float, "double", double, SWAP_WORD, 8); 317 SET_VALUES("double", double, "double", double, SWAP_DBLE, 8); 318 319 # if (0) 232 320 /** input == char **/ 233 321 if (!strcmp (outtype, "char") && !strcmp (intype, "char")) { 234 322 int NbytesIn = 1; 235 323 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 236 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 324 if (directCopy) { *(char *)Pout = *(char *)Pin; } else { 325 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 326 } 237 327 } 238 328 } 239 329 if (!strcmp (outtype, "byte") && !strcmp (intype, "char")) { 330 int NbytesIn = 1; 331 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 332 if (directCopy) { *(char *)Pout = *(char *)Pin; } else { 333 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 334 } 335 } 336 } 337 if (!strcmp (outtype, "short") && !strcmp (intype, "char")) { 338 int NbytesIn = 1; 339 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 340 if (directCopy) { *(short *)Pout = *(char *)Pin; } else { 341 *(short *)Pout = (*(char *)Pin - Bzero) / Bscale; 342 } 343 # ifdef BYTE_SWAP 344 if (!nativeOrder) { SWAP_BYTE; } 345 # endif 346 } 347 } 348 if (!strcmp (outtype, "int") && !strcmp (intype, "char")) { 349 int NbytesIn = 1; 350 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 351 *(int *)Pout = (*(char *)Pin - Bzero) / Bscale; 352 # ifdef BYTE_SWAP 353 if (!nativeOrder) { SWAP_WORD; } 354 # endif 355 } 356 } 357 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) { 358 int NbytesIn = 1; 359 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 360 *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale; 361 # ifdef BYTE_SWAP 362 if (!nativeOrder) { SWAP_DBLE; } 363 # endif 364 } 365 } 366 if (!strcmp (outtype, "float") && !strcmp (intype, "char")) { 367 int NbytesIn = 1; 368 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 369 *(float *)Pout = (*(char *)Pin - Bzero) / Bscale; 370 # ifdef BYTE_SWAP 371 if (!nativeOrder) { SWAP_WORD; } 372 # endif 373 } 374 } 375 if (!strcmp (outtype, "double") && !strcmp (intype, "char")) { 376 int NbytesIn = 1; 377 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 378 *(double *)Pout = (*(char *)Pin - Bzero) / Bscale; 379 # ifdef BYTE_SWAP 380 if (!nativeOrder) { SWAP_DBLE; } 381 # endif 382 } 383 } 384 385 /** input == byte **/ 386 if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) { 240 387 int NbytesIn = 1; 241 388 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { … … 243 390 } 244 391 } 245 if (!strcmp (outtype, "short") && !strcmp (intype, "char")) { 246 int NbytesIn = 1; 247 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 248 *(short *)Pout = (*(char *)Pin - Bzero) / Bscale; 249 # ifdef BYTE_SWAP 250 SWAP_BYTE; 251 # endif 252 } 253 } 254 if (!strcmp (outtype, "int") && !strcmp (intype, "char")) { 255 int NbytesIn = 1; 256 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 257 *(int *)Pout = (*(char *)Pin - Bzero) / Bscale; 258 # ifdef BYTE_SWAP 259 SWAP_WORD; 260 # endif 261 } 262 } 263 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) { 264 int NbytesIn = 1; 265 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 266 *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale; 267 # ifdef BYTE_SWAP 268 SWAP_DBLE; 269 # endif 270 } 271 } 272 if (!strcmp (outtype, "float") && !strcmp (intype, "char")) { 273 int NbytesIn = 1; 274 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 275 *(float *)Pout = (*(char *)Pin - Bzero) / Bscale; 276 # ifdef BYTE_SWAP 277 SWAP_WORD; 278 # endif 279 } 280 } 281 if (!strcmp (outtype, "double") && !strcmp (intype, "char")) { 282 int NbytesIn = 1; 283 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 284 *(double *)Pout = (*(char *)Pin - Bzero) / Bscale; 285 # ifdef BYTE_SWAP 286 SWAP_DBLE; 287 # endif 288 } 289 } 290 291 /** input == byte **/ 292 if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) { 392 if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) { 293 393 int NbytesIn = 1; 294 394 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { … … 296 396 } 297 397 } 298 if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) {299 int NbytesIn = 1;300 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {301 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;302 }303 }304 398 if (!strcmp (outtype, "short") && !strcmp (intype, "byte")) { 305 399 int NbytesIn = 1; … … 307 401 *(short *)Pout = (*(char *)Pin - Bzero) / Bscale; 308 402 # ifdef BYTE_SWAP 309 SWAP_BYTE;403 if (!nativeOrder) { SWAP_BYTE; } 310 404 # endif 311 405 } … … 316 410 *(int *)Pout = (*(char *)Pin - Bzero) / Bscale; 317 411 # ifdef BYTE_SWAP 318 SWAP_WORD;412 if (!nativeOrder) { SWAP_WORD; } 319 413 # endif 320 414 } … … 325 419 *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale; 326 420 # ifdef BYTE_SWAP 327 SWAP_DBLE;421 if (!nativeOrder) { SWAP_DBLE; } 328 422 # endif 329 423 } … … 334 428 *(float *)Pout = (*(char *)Pin - Bzero) / Bscale; 335 429 # ifdef BYTE_SWAP 336 SWAP_WORD;430 if (!nativeOrder) { SWAP_WORD; } 337 431 # endif 338 432 } … … 343 437 *(double *)Pout = (*(char *)Pin - Bzero) / Bscale; 344 438 # ifdef BYTE_SWAP 345 SWAP_DBLE;439 if (!nativeOrder) { SWAP_DBLE; } 346 440 # endif 347 441 } … … 366 460 *(short *)Pout = (*(short *)Pin - Bzero) / Bscale; 367 461 # ifdef BYTE_SWAP 368 SWAP_BYTE;462 if (!nativeOrder) { SWAP_BYTE; } 369 463 # endif 370 464 } … … 375 469 *(int *)Pout = (*(short *)Pin - Bzero) / Bscale; 376 470 # ifdef BYTE_SWAP 377 SWAP_WORD;471 if (!nativeOrder) { SWAP_WORD; } 378 472 # endif 379 473 } … … 384 478 *(int64_t *)Pout = (*(short *)Pin - Bzero) / Bscale; 385 479 # ifdef BYTE_SWAP 386 SWAP_DBLE;480 if (!nativeOrder) { SWAP_DBLE; } 387 481 # endif 388 482 } … … 393 487 *(float *)Pout = (*(short *)Pin - Bzero) / Bscale; 394 488 # ifdef BYTE_SWAP 395 SWAP_WORD;489 if (!nativeOrder) { SWAP_WORD; } 396 490 # endif 397 491 } … … 402 496 *(double *)Pout = (*(short *)Pin - Bzero) / Bscale; 403 497 # ifdef BYTE_SWAP 404 SWAP_DBLE;498 if (!nativeOrder) { SWAP_DBLE; } 405 499 # endif 406 500 } … … 425 519 *(short *)Pout = (*(int *)Pin - Bzero) / Bscale; 426 520 # ifdef BYTE_SWAP 427 SWAP_BYTE;521 if (!nativeOrder) { SWAP_BYTE; } 428 522 # endif 429 523 } … … 434 528 *(int *)Pout = (*(int *)Pin - Bzero) / Bscale; 435 529 # ifdef BYTE_SWAP 436 SWAP_WORD;530 if (!nativeOrder) { SWAP_WORD; } 437 531 # endif 438 532 } … … 443 537 *(int64_t *)Pout = (*(int *)Pin - Bzero) / Bscale; 444 538 # ifdef BYTE_SWAP 445 SWAP_DBLE;539 if (!nativeOrder) { SWAP_DBLE; } 446 540 # endif 447 541 } … … 452 546 *(float *)Pout = (*(int *)Pin - Bzero) / Bscale; 453 547 # ifdef BYTE_SWAP 454 SWAP_WORD;548 if (!nativeOrder) { SWAP_WORD; } 455 549 # endif 456 550 } … … 461 555 *(double *)Pout = (*(int *)Pin - Bzero) / Bscale; 462 556 # ifdef BYTE_SWAP 463 SWAP_DBLE;557 if (!nativeOrder) { SWAP_DBLE; } 464 558 # endif 465 559 } … … 484 578 *(short *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 485 579 # ifdef BYTE_SWAP 486 SWAP_BYTE;580 if (!nativeOrder) { SWAP_BYTE; } 487 581 # endif 488 582 } … … 493 587 *(int *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 494 588 # ifdef BYTE_SWAP 495 SWAP_WORD;589 if (!nativeOrder) { SWAP_WORD; } 496 590 # endif 497 591 } … … 502 596 *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 503 597 # ifdef BYTE_SWAP 504 SWAP_DBLE;598 if (!nativeOrder) { SWAP_DBLE; } 505 599 # endif 506 600 } … … 511 605 *(float *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 512 606 # ifdef BYTE_SWAP 513 SWAP_WORD;607 if (!nativeOrder) { SWAP_WORD; } 514 608 # endif 515 609 } … … 520 614 *(double *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 521 615 # ifdef BYTE_SWAP 522 SWAP_DBLE;616 if (!nativeOrder) { SWAP_DBLE; } 523 617 # endif 524 618 } … … 543 637 *(short *)Pout = (*(float *)Pin - Bzero) / Bscale; 544 638 # ifdef BYTE_SWAP 545 SWAP_BYTE;639 if (!nativeOrder) { SWAP_BYTE; } 546 640 # endif 547 641 } … … 552 646 *(int *)Pout = (*(float *)Pin - Bzero) / Bscale; 553 647 # ifdef BYTE_SWAP 554 SWAP_WORD;648 if (!nativeOrder) { SWAP_WORD; } 555 649 # endif 556 650 } … … 561 655 *(int64_t *)Pout = (*(float *)Pin - Bzero) / Bscale; 562 656 # ifdef BYTE_SWAP 563 SWAP_DBLE;657 if (!nativeOrder) { SWAP_DBLE; } 564 658 # endif 565 659 } … … 570 664 *(float *)Pout = (*(float *)Pin - Bzero) / Bscale; 571 665 # ifdef BYTE_SWAP 572 SWAP_WORD;666 if (!nativeOrder) { SWAP_WORD; } 573 667 # endif 574 668 } … … 579 673 *(double *)Pout = (*(float *)Pin - Bzero) / Bscale; 580 674 # ifdef BYTE_SWAP 581 SWAP_DBLE;675 if (!nativeOrder) { SWAP_DBLE; } 582 676 # endif 583 677 } … … 602 696 *(short *)Pout = (*(double *)Pin - Bzero) / Bscale; 603 697 # ifdef BYTE_SWAP 604 SWAP_BYTE;698 if (!nativeOrder) { SWAP_BYTE; } 605 699 # endif 606 700 } … … 611 705 *(int *)Pout = (*(double *)Pin - Bzero) / Bscale; 612 706 # ifdef BYTE_SWAP 613 SWAP_WORD;707 if (!nativeOrder) { SWAP_WORD; } 614 708 # endif 615 709 } … … 620 714 *(int64_t *)Pout = (*(double *)Pin - Bzero) / Bscale; 621 715 # ifdef BYTE_SWAP 622 SWAP_DBLE;716 if (!nativeOrder) { SWAP_DBLE; } 623 717 # endif 624 718 } … … 629 723 *(float *)Pout = (*(double *)Pin - Bzero) / Bscale; 630 724 # ifdef BYTE_SWAP 631 SWAP_WORD;725 if (!nativeOrder) { SWAP_WORD; } 632 726 # endif 633 727 } … … 638 732 *(double *)Pout = (*(double *)Pin - Bzero) / Bscale; 639 733 # ifdef BYTE_SWAP 640 SWAP_DBLE; 641 # endif 642 } 643 } 734 if (!nativeOrder) { SWAP_DBLE; } 735 # endif 736 } 737 } 738 # endif 644 739 645 740 /* check array space */ … … 683 778 int gfits_set_table_column (Header *header, FTable *table, char *label, void *data, off_t Nrow) { 684 779 685 off_t Nx, Ny , nbytes;780 off_t Nx, Ny; 686 781 int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb; 687 782 char tlabel[80], field[80], format[80], cformat[80], type[16], tmp[16]; … … 713 808 if (Ny == 0) { 714 809 Ny = Nrow; 715 header[0].Naxis[1] = Ny; 716 gfits_modify (header, "NAXIS2", OFF_T_FMT, 1, Ny); 717 718 nbytes = gfits_data_size (header); 719 REALLOCATE (table[0].buffer, char, MAX (nbytes, 1)); 720 bzero (table[0].buffer, nbytes); 721 table[0].datasize = nbytes; 810 gfits_set_table_rows (header, table, Ny); 722 811 } 723 812 if (Ny != Nrow) return (FALSE); -
trunk/Ohana/src/libfits/table/F_table_format.c
r37039 r38441 8 8 int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) { 9 9 10 char *Lchar, *Fchar; 11 int Nv; 12 13 if (format == (char *) NULL) return (FALSE); 14 if (format[0] == 0) return (FALSE); 15 Lchar = &format[strlen(format) - 1]; 16 17 Nv = strtol (format, &Fchar, 10); 18 if (Fchar != Lchar) return (FALSE); 10 char *Fchar; 11 12 if (format == (char *) NULL) return (FALSE); // format must be defined 13 if (format[0] == 0) return (FALSE); // format must not be empty string 14 // char *Lchar = &format[strlen(format) - 1]; // last-char pointer 15 16 int Nv = strtol (format, &Fchar, 10); // Fchar points at end of leading number 17 // if (Fchar != Lchar) return (FALSE); -- this test is invalid for eg 1PB(nn) 19 18 if ((Nv == 0) && (Fchar == format)) Nv = 1; 20 19 … … 51 50 { *Nbytes = 8; strcpy (type, "double"); *Nval = Nv; } 52 51 break; 53 case 'P':54 { *Nbytes = 8; strcpy (type, "var"); *Nval = 2*Nv; }55 break;56 52 case 'C': 57 53 { *Nbytes = 8; strcpy (type, "float"); *Nval = 2*Nv; } … … 59 55 case 'M': 60 56 { *Nbytes = 16; strcpy (type, "double"); *Nval = 2*Nv; } 57 break; 58 case 'P': 59 { *Nbytes = 4; strcpy (type, "var"); *Nval = 2*Nv; } 60 break; 61 case 'Q': 62 { *Nbytes = 8; strcpy (type, "var64"); *Nval = 2*Nv; } 61 63 break; 62 64 default: … … 80 82 C - complex float 81 83 M - complex double 82 P - var length array descrpt (64 bit) 84 P - var length array descrpt (32 bit pointer) 85 Q - var length array descrpt (64 bit pointer) 83 86 84 87 all can be preceeded by integer N which specified number 85 88 of entries in array 86 87 89 */ 88 90 -
trunk/Ohana/src/libfits/table/F_table_row.c
r28241 r38441 28 28 REALLOCATE (table[0].buffer, char, MAX (nbytes, 1)); 29 29 table[0].datasize = nbytes; 30 table[0].heap_start = gfits_heap_start (header); 30 31 31 32 memcpy (&table[0].buffer[Nstart], data, Nbytes*Nrow); … … 67 68 68 69 table[0].datasize = gfits_data_size (table[0].header); 70 // table[0].heap_start = gfits_heap_start (header); 69 71 table[0].pad = table[0].datasize - Nx*Ny; 70 72 … … 102 104 REALLOCATE (table[0].buffer, char, MAX (nbytes, 1)); 103 105 table[0].datasize = nbytes; 106 table[0].heap_start = gfits_heap_start (header); 104 107 return (TRUE); 105 108 } -
trunk/Ohana/src/libfits/table/F_table_varlength.c
r28241 r38441 2 2 # include <gfitsio.h> 3 3 4 // fills the column definition structure for a specific column based on a given table. 4 5 int gfits_varlength_column_define (FTable *ftable, VarLengthColumn *def, int column) { 5 6 … … 14 15 snprintf (field, 80, "TFORM%d", column); 15 16 if (!gfits_scan (ftable->header, field, "%s", 1, format)) return (FALSE); 17 18 def->column = column; 16 19 17 20 // find and remove the max field length element … … 48 51 if (*p1 == 'I') { def->nbytes = 2; def->format = *p1; } 49 52 if (*p1 == 'J') { def->nbytes = 4; def->format = *p1; } 53 if (*p1 == 'K') { def->nbytes = 8; def->format = *p1; } 50 54 if (*p1 == 'E') { def->nbytes = 4; def->format = *p1; } 51 55 if (*p1 == 'D') { def->nbytes = 8; def->format = *p1; } … … 54 58 if (!def->nbytes) { return (FALSE); } 55 59 56 /* scan columns to find column offset */57 def-> Nstart = 0;60 /* scan columns to find column offset for metadata column*/ 61 def->offset = 0; 58 62 for (i = 1; i < column; i++) { 59 63 sprintf (field, "TFORM%d", i); 60 64 gfits_scan (ftable->header, field, "%s", 1, format); 61 65 gfits_bintable_format (format, tmpline, &Nv, &Nb); 62 def-> Nstart += Nv*Nb;66 def->offset += Nv*Nb; 63 67 } 64 68 65 69 // heap_start must be long long so file may be very large 66 if (!gfits_scan (ftable->header, "THEAP", OFF_T_FMT, 1, &def->heap_start)) { 67 def->heap_start = ftable->header->Naxis[0]*ftable->header->Naxis[1]; 68 } 69 70 // confirm that ftable->heap_start is correctly set? 71 72 return TRUE; 73 } 74 75 # define SWAP_WORD \ 76 tmp = pchar[0]; pchar[0] = pchar[3]; pchar[3] = tmp; \ 77 tmp = pchar[1]; pchar[1] = pchar[2]; pchar[2] = tmp; 78 79 # define SWAP_DBLE \ 80 tmp = pchar[0]; pchar[0] = pchar[7]; pchar[7] = tmp; \ 81 tmp = pchar[1]; pchar[1] = pchar[6]; pchar[6] = tmp; \ 82 tmp = pchar[2]; pchar[2] = pchar[5]; pchar[5] = tmp; \ 83 tmp = pchar[3]; pchar[3] = pchar[4]; pchar[4] = tmp; 84 85 int gfits_byteswap_varlength_column (FTable *ftable, int column) { 86 87 # ifdef BYTE_SWAP 88 VarLengthColumn zdef; 89 if (!gfits_varlength_column_define (ftable, &zdef, column)) return FALSE; 90 91 char *bufstart = &ftable->buffer[zdef.offset]; 92 93 int i; 94 char *pchar, tmp; 95 96 off_t Nx = ftable->header->Naxis[0]; 97 98 for (i = 0; i < ftable->header->Naxis[1]; i++) { 99 if (zdef.mode == 'P') { 100 pchar = &bufstart[i*Nx]; 101 SWAP_WORD; 102 pchar = &bufstart[i*Nx + 4]; 103 SWAP_WORD; 104 } 105 if (zdef.mode == 'Q') { 106 char *pchar, tmp; 107 pchar = &bufstart[i*Nx]; 108 SWAP_DBLE; 109 pchar = &bufstart[i*Nx + 8]; 110 SWAP_DBLE; 111 } 112 } 113 # endif 70 114 return TRUE; 71 115 } … … 75 119 void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, off_t row, off_t *length) { 76 120 77 void *result;78 off_t offset, Nx;79 80 121 if ((column->mode != 'P') && (column->mode != 'Q')) abort(); 81 122 82 123 // find the values for the specified row 83 124 // the values in the main table for this row and varlength column: 84 Nx = ftable->header->Naxis[0]; 85 86 # define SWAP_WORD \ 87 tmp = pchar[0]; pchar[0] = pchar[3]; pchar[3] = tmp; \ 88 tmp = pchar[1]; pchar[1] = pchar[2]; pchar[2] = tmp; 89 90 # ifdef BYTE_SWAP 91 char *pchar, tmp; 92 pchar = &ftable->buffer[row*Nx + column->Nstart]; 93 SWAP_WORD; 94 pchar = &ftable->buffer[row*Nx + column->Nstart + 4]; 95 SWAP_WORD; 96 # endif 125 off_t Nx = ftable->header->Naxis[0]; 126 off_t offset = 0; 97 127 98 128 if (column->mode == 'P') { 99 129 int *ptr; 100 ptr = (int *) &ftable->buffer[row*Nx + column-> Nstart];130 ptr = (int *) &ftable->buffer[row*Nx + column->offset]; 101 131 *length = ptr[0]; 102 132 offset = ptr[1]; 103 } else if (column->mode == 'Q') { 133 } 134 if (column->mode == 'Q') { 104 135 off_t *ptr; 105 ptr = (off_t *) &ftable->buffer[row*Nx + column-> Nstart];136 ptr = (off_t *) &ftable->buffer[row*Nx + column->offset]; 106 137 *length = ptr[0]; 107 138 offset = ptr[1]; 108 } else { 109 // this was actually trapped above 110 abort(); 111 } 112 113 result = (void *) (ftable->buffer + column->heap_start + offset); 139 } 140 141 // fprintf (stderr, "length: %d, offset: %d\n", (int) *length, (int) offset); 142 143 void *result = (void *) (ftable->buffer + ftable->heap_start + offset); 114 144 return result; 115 145 } 146 147 // to generate a compressed image or a compressed table, we need to be able to add data 148 // for varlength columns to the heap. To start, assume we have defined the cartesian 149 // portion of the table correctly, and are only extending the heap. 150 151 int gfits_varlength_column_add_data (FTable *table, char *data, off_t Ndata, int row, VarLengthColumn *column) { 152 153 // find the current starting point for new data (end of current buffer main data + current heap 154 off_t heap_offset = gfits_data_min_size (table->header); 155 156 // extend the buffer size to add the new data 157 off_t Nbytes = gfits_data_pad_size (heap_offset + Ndata); 158 REALLOCATE (table->buffer, char, Nbytes); 159 160 char *heap_ptr = table->buffer + heap_offset; 161 162 // add the new data to the table buffer 163 memcpy (heap_ptr, data, Ndata); 164 165 // *** now we add the data description to the table *** 166 167 if ((column->mode != 'P') && (column->mode != 'Q')) abort(); 168 169 // find the cell for the specified row & column 170 // the values in the main table for this row and varlength column: 171 int Nx = table->header->Naxis[0]; 172 173 // set the cell values 174 if (column->mode == 'P') { 175 int *ptr; 176 ptr = (int *) &table->buffer[row*Nx + column->offset]; 177 ptr[0] = Ndata; 178 ptr[1] = heap_offset - table->heap_start; 179 } 180 if (column->mode == 'Q') { 181 off_t *ptr; 182 ptr = (off_t *) &table->buffer[row*Nx + column->offset]; 183 ptr[0] = Ndata; 184 ptr[1] = heap_offset - table->heap_start; 185 } 186 187 // update maxlen 188 // fprintf (stderr, "row: %d, Ndata: %d, maxlen: %d\n", (int) row, (int) Ndata, (int) column->maxlen); 189 column->maxlen = MAX (column->maxlen, Ndata); 190 191 off_t pcount; 192 gfits_scan (table->header, "PCOUNT", OFF_T_FMT, 1, &pcount); 193 194 pcount += Ndata; 195 gfits_modify (table->header, "PCOUNT", OFF_T_FMT, 1, pcount); 196 table->header->pcount = pcount; 197 table->datasize = gfits_data_size (table->header); 198 myAssert (table->datasize == Nbytes, "inconsistent header and data"); 199 200 return TRUE; 201 } 202 203 // update the header TFORM value for this entry 204 int gfits_varlength_column_finish (FTable *ftable, VarLengthColumn *def) { 205 206 char field[81]; 207 char format[81]; 208 209 // grab the value of TFORMn for this column 210 snprintf (field, 80, "TFORM%d", def->column); 211 if (!gfits_scan (ftable->header, field, "%s", 1, format)) return FALSE; 212 213 // find and update the max field length element 214 char *p1 = strchr (format, '('); 215 if (!p1) return (FALSE); // not a valid varlength column -- missing (e_max) 216 217 p1 ++; 218 *p1 = 0; 219 220 snprintf (p1, 80 - (p1 - format), "%d)", def->maxlen); 221 if (!gfits_modify (ftable->header, field, "%s", 1, format)) return FALSE; 222 223 return TRUE; 224 } -
trunk/Ohana/src/libfits/table/F_write_T.c
r37807 r38441 14 14 15 15 status = fseeko (f, 0LL, SEEK_END); /* write table to end of file! */ 16 if (status) { perror ("fseeko: "); return (FALSE); } 16 17 status = gfits_fwrite_table (f, table); 17 18 … … 26 27 27 28 Nbytes = fwrite (table[0].buffer, sizeof(char), table[0].datasize, f); 28 29 if (Nbytes != table[0].datasize) return (FALSE); 29 if (Nbytes != table[0].datasize) { perror ("fwrite: "); return (FALSE); } 30 30 return (TRUE); 31 31 } … … 45 45 /* file pointer is at beginning of desired table data */ 46 46 start = ftello (f); 47 if (start < 0) { perror ("ftello: "); return FALSE; } 47 48 48 49 for (i = 0; i < Nrow; i++) { … … 50 51 fseeko (f, offset, SEEK_SET); 51 52 Nbytes = fwrite (table[0].buffer[i], sizeof (char), Nx, f); 52 if (Nbytes != Nx) { return (FALSE); }53 if (Nbytes != Nx) { perror ("fwrite: "); return (FALSE); } 53 54 } 54 55 … … 58 59 59 60 offset = start + Nx*Ny; 60 fseeko (f, offset, SEEK_SET); 61 int status = fseeko (f, offset, SEEK_SET); 62 if (status) { perror ("fseeko: "); return FALSE; } 63 61 64 Nbytes = fwrite (pad, sizeof (char), Npad, f); 62 if (Nbytes != Npad) { return (FALSE); }65 if (Nbytes != Npad) { perror ("fwrite: "); return (FALSE); } 63 66 free (pad); 64 67 … … 84 87 Nx = ftable[0].header[0].Naxis[0]; // final output table size on disk 85 88 ftable[0].datasize = gfits_data_size (ftable[0].header); 89 ftable[0].heap_start = gfits_heap_start (ftable[0].header); 86 90 87 91 Nskip = start * Nx; … … 96 100 // cursor must be at start of the table (after table header) 97 101 if (fseeko (f, Nskip, SEEK_CUR)) { 102 perror ("fseeko: "); 98 103 fprintf (stderr, "can't seek table start\n"); 99 104 return (FALSE); … … 101 106 102 107 Nwrite = fwrite (ftable[0].buffer, sizeof (char), Nbytes, f); 103 if (Nwrite != Nbytes) { 104 return (FALSE); 105 } 108 if (Nwrite != Nbytes) { perror ("fwrite: "); return (FALSE); } 106 109 107 110 if (Ntotal >= Ndisk) { … … 112 115 free (pad); 113 116 114 if (Nbytes != Npad) return (FALSE);117 if (Nbytes != Npad) { perror ("fwrite: "); return (FALSE); } 115 118 } 116 119 -
trunk/Ohana/src/libfits/table/F_write_TH.c
r27435 r38441 14 14 15 15 status = fseeko (f, 0LL, SEEK_END); /* write header to end of file! */ 16 if (status) { perror ("fseeko: "); return (FALSE); } 16 17 status = gfits_fwrite_Theader (f, header); 17 18 … … 26 27 27 28 Nbytes = fwrite (header[0].buffer, sizeof(char), header[0].datasize, f); 29 if (Nbytes != header[0].datasize) { perror ("fwrite: "); return (FALSE); } 28 30 29 if (Nbytes != header[0].datasize) return (FALSE);30 31 return (TRUE); 31 32 }
Note:
See TracChangeset
for help on using the changeset viewer.
