Changeset 40113
- Timestamp:
- Aug 9, 2017, 12:47:22 PM (9 years ago)
- Location:
- branches/eam_branches/ohana.20170809/src/libfits
- Files:
-
- 13 edited
-
header/F_H_field.c (modified) (2 diffs)
-
header/F_create_H.c (modified) (2 diffs)
-
header/F_modify.c (modified) (5 diffs)
-
header/F_print.c (modified) (5 diffs)
-
header/F_scan.c (modified) (2 diffs)
-
matrix/F_compress_utils.c (modified) (1 diff)
-
matrix/F_uncompress_data.c (modified) (1 diff)
-
table/F_create_T.c (modified) (2 diffs)
-
table/F_create_TH.c (modified) (2 diffs)
-
table/F_define_column.c (modified) (1 diff)
-
table/F_set_column.c (modified) (9 diffs)
-
table/F_table_format.c (modified) (2 diffs)
-
table/F_uncompress_T.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20170809/src/libfits/header/F_H_field.c
r39926 r40113 104 104 ptr = buf + 9; // start of following keyword 105 105 if (strncmp (field, ptr, Nfield)) continue; 106 if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO). test for the following '=' sign 106 107 Nfound ++; 107 108 } … … 116 117 ptr = buf + 9; // start of following keyword 117 118 if (strncmp (field, ptr, Nfield)) continue; 119 if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO). test for the following '=' sign 118 120 Nfound ++; 119 121 if (Nwant == Nfound) return (ptr); -
branches/eam_branches/ohana.20170809/src/libfits/header/F_create_H.c
r34577 r40113 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # define NBYTES 28804 3 5 4 /******************** fits create header ***********************************/ … … 9 8 char axis[10]; 10 9 11 header[0].datasize = NBYTES;10 header[0].datasize = FT_RECORD_SIZE; 12 11 13 ALLOCATE (header[0].buffer, char, NBYTES);12 ALLOCATE (header[0].buffer, char, FT_RECORD_SIZE); 14 13 15 for (i = 0; i < NBYTES; i++) 16 header[0].buffer[i] = ' '; 14 // XXX this is just slightly suspicious : I am not ending the buffer with a NULL. if I 15 // use any string operations on it then they can run past the end. 16 for (i = 0; i < FT_RECORD_SIZE; i++) header[0].buffer[i] = ' '; 17 17 strncpy (header[0].buffer, "END", 3); 18 18 -
branches/eam_branches/ohana.20170809/src/libfits/header/F_modify.c
r38441 r40113 72 72 char *ptr = va_arg (argp, char *); 73 73 if (!ptr) goto invalid; 74 strncpy (data, ptr, 68); 74 strncpy (data, ptr, 68); data[68] = 0; 75 75 snprintf (string, 81, "%-8s= '%-8s' / %-s ", field, data, comment); 76 76 goto found_it; … … 119 119 header[0].datasize += FT_RECORD_SIZE; 120 120 REALLOCATE (header[0].buffer, char, header[0].datasize); 121 /* re-find the "END" marker, in case new memory block is used */ 121 122 p = gfits_header_field (header, "END", 1); 122 123 if (p == NULL) return (FALSE); … … 138 139 /* write the boolean mode */ 139 140 if (!strcmp (mode, "%t")) { 140 if (va_arg (argp, int)) 141 snprintf (string, 81, "%-8s= %18s T / %-s ", field, " ", comment); 142 else 143 snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment); 141 // fill data will spaces, null terminated, so snprintf can generate a space-filled block 142 memset (data, ' ', FT_LINE_LENGTH); data[FT_LINE_LENGTH] = 0; 143 if (va_arg (argp, int)) { 144 snprintf (string, 81, "%-8s= %18s T / %-s ", field, data, comment); 145 } else { 146 snprintf (string, 81, "%-8s= %18s F / %-s ", field, data, comment); 147 } 144 148 } 145 149 … … 148 152 char *ptr = va_arg (argp, char *); 149 153 if (!ptr) goto invalid; 150 strncpy (data, ptr, 71); 154 strncpy (data, ptr, 71); data[71] = 0; 151 155 snprintf (string, 81, "%-8s %-71s", field, data); 152 156 } … … 159 163 /* keep ' on ends, if there */ 160 164 if (qe[0] == 0x27) qe ++; 161 if (qs[-1] == 0x27) qs --; 165 if (qs >= p + 1) { 166 if (qs[-1] == 0x27) qs --; 167 } 162 168 163 169 strncpy (data, qs, MAX (MIN (qe - qs, 71), 0)); -
branches/eam_branches/ohana.20170809/src/libfits/header/F_print.c
r34577 r40113 7 7 /* this function expects one more argument, the value to be written */ 8 8 9 static char blank[] = " "; 10 char string[82], line[80]; 9 char string[82], line[82], blank[82]; 11 10 char *p; 12 11 va_list argp; … … 41 40 memset (p, ' ', FT_LINE_LENGTH); 42 41 42 memset (blank, ' ', FT_LINE_LENGTH); blank[FT_LINE_LENGTH] = 0; 43 43 44 /* write the new FITS card, setting the comment to be blank */ 44 45 /* in these lines, the value field will expand as needed, forcing out the comment … … 67 68 char *ptr = va_arg (argp, char *); 68 69 if (!ptr) goto invalid; 69 strcpy (line, ptr); 70 line[68] = 0; 70 strncpy (line, ptr, 68); line[68] = 0; 71 71 snprintf (string, 81, "%-8s= '%-8s' / %46s ", field, line, blank); 72 72 goto found_it; … … 88 88 /* this function expects one more argument, the value to be written */ 89 89 90 static char blank[] = " "; 91 char string[82], line[80]; 92 char *p, a; 90 char string[82], line[82], blank[82]; 91 char *p; 93 92 va_list argp; 94 93 95 94 va_start (argp, N); 95 bzero (line, 82); 96 bzero (string, 82); 97 bzero (blank, 82); 96 98 97 99 if (mode[0] != '%') { … … 122 124 memset (p, ' ', FT_LINE_LENGTH); 123 125 126 memset (blank, ' ', FT_LINE_LENGTH); blank[FT_LINE_LENGTH] = 0; 127 124 128 /* write the boolean mode */ 125 129 if (!strcmp (mode, "%t")) { 126 a = va_arg (argp, int);127 if (a == 1) 130 int a = va_arg (argp, int); 131 if (a == 1) { 128 132 snprintf (string, 81, "%-8s= %18s T / %46s ", field, blank, blank); 129 else133 } else { 130 134 snprintf (string, 81, "%-8s= %18s F / %46s ", field, blank, blank); 135 } 131 136 } 132 137 -
branches/eam_branches/ohana.20170809/src/libfits/header/F_scan.c
r39324 r40113 89 89 // XXX is this safe for 64bit off_t and 32bit off_t? 90 90 // XXX the problem is that we read FITS files on many machine types: I need to ensure 91 // that we are portable -- this s seems inconsistent91 // that we are portable -- this seems inconsistent 92 92 if (!strcmp (mode, "%jd")) { *va_arg (argp, intmax_t *) = value; return (TRUE); } 93 93 … … 168 168 /* all others require '=' in column p + 1 + strlen(field) */ 169 169 Nfield = strlen (field); 170 if (p[Nfield + 1] != '=') return (FALSE); 170 if (p[Nfield + 1] != '=') return (FALSE); // probably redundant since gfits_header_hierarch_field requires this condition 171 171 172 172 /* comment from data line */ -
branches/eam_branches/ohana.20170809/src/libfits/matrix/F_compress_utils.c
r39457 r40113 136 136 137 137 int has_extension, has_extname, has_zimage, zimage; 138 char extname[8 0], extension[80];138 char extname[82], extension[82]; 139 139 140 140 has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension); -
branches/eam_branches/ohana.20170809/src/libfits/matrix/F_uncompress_data.c
r39457 r40113 6 6 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 7 7 8 // *Nout comes in with the number of expected (uncompressed) bytes 9 // *Nout returns the number uncompressed pixels 8 10 int gfits_uncompress_data (char *zdata, unsigned long Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, unsigned long int *Nout, unsigned long int Nout_alloc, int out_pixsize) { 9 11 -
branches/eam_branches/ohana.20170809/src/libfits/table/F_create_T.c
r38441 r40113 43 43 } 44 44 table[0].datasize = Nbytes; 45 table[0].validsize = Nbytes; 45 46 table[0].heap_start = gfits_heap_start (header); 46 47 return (TRUE); … … 58 59 bzero (table[0].buffer, Nbytes); 59 60 table[0].datasize = Nbytes; 61 table[0].validsize = Nbytes; 60 62 table[0].heap_start = gfits_heap_start (header); 61 63 return (TRUE); -
branches/eam_branches/ohana.20170809/src/libfits/table/F_create_TH.c
r38989 r40113 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # define NBYTES 28804 3 5 4 /* a basic table header (extension) is different from a primary header … … 13 12 char axis[128]; 14 13 15 header[0].datasize = NBYTES;14 header[0].datasize = FT_RECORD_SIZE; 16 15 17 16 myAssert (!header->buffer, "failed to init header or free buffer?"); 18 ALLOCATE (header[0].buffer, char, NBYTES);17 ALLOCATE (header[0].buffer, char, FT_RECORD_SIZE); 19 18 20 for (i = 0; i < NBYTES; i++) 21 header[0].buffer[i] = ' '; 19 for (i = 0; i < FT_RECORD_SIZE; i++) header[0].buffer[i] = ' '; 22 20 strncpy (header[0].buffer, "END", 3); 23 21 -
branches/eam_branches/ohana.20170809/src/libfits/table/F_define_column.c
r38553 r40113 56 56 char type[64], field[64]; 57 57 58 if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE); 58 if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE); // *** FUNC : OK 59 59 60 60 Nfields = 0; -
branches/eam_branches/ohana.20170809/src/libfits/table/F_set_column.c
r39993 r40113 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # define OHANA_MEMCHECK 04 # define CHECK_MEMBLOCKS 03 # define OHANA_MEMCHECK 1 4 # define CHECK_MEMBLOCKS 1 5 5 6 6 # define SWAP_NONE … … 33 33 int Nval, Nbytes, Nstart, Nv, Nb; 34 34 char tlabel[256], field[256], format[256], type[64], tmpline[64]; 35 char *Pin, *Pout , *array;35 char *Pin, *Pout; 36 36 double Bscale, Bzero; 37 37 … … 53 53 # endif 54 54 55 // fprintf (stderr, "Pin: 0x%08lx, Pout: 0x%08lx, array: 0x%08lx\n", (long int) &Pin, (long int) &Pout, (long int) &array); 56 55 57 if (label == (char *) NULL) return (FALSE); 56 58 if (label[0] == 0) return (FALSE); … … 67 69 68 70 /* interpret format */ 71 # if (0) 69 72 snprintf (field, 256, "TSCAL%d", N); 70 73 if (!gfits_scan (header, field, "%lf", 1, &Bscale)) { … … 75 78 Bzero = 0.0; 76 79 } 80 # else 81 Bscale = 1.0; 82 Bzero = 0.0; 83 # endif 84 77 85 snprintf (field, 256, "TFORM%d", N); 78 86 if (!gfits_scan (header, field, "%s", 1, format)) return FALSE; … … 107 115 /* make duplicate of data with correct type 108 116 byte swap and Bzero/Bscale */ 109 ALLOCATE (array, char, Nbytes*Nval*Nrow);117 ALLOCATE_PTR (array, char, Nbytes*Nval*Nrow); 110 118 if (CHECK_MEMBLOCKS) { 111 119 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 112 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);120 // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 113 121 if (!ref->nextBlock && !ref->prevBlock) abort(); 122 if (!ref->size) abort(); 114 123 } 115 124 … … 121 130 if (CHECK_MEMBLOCKS) { 122 131 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 123 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);132 // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 124 133 if (!ref->nextBlock && !ref->prevBlock) abort(); 125 134 } … … 213 222 if (CHECK_MEMBLOCKS) { 214 223 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 215 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);224 // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 216 225 if (!ref->nextBlock && !ref->prevBlock) abort(); 217 226 } … … 242 251 if (CHECK_MEMBLOCKS) { 243 252 OhanaMemblock *ref = (OhanaMemblock *) array - 1; 244 fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);253 // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc); 245 254 if (!ref->nextBlock && !ref->prevBlock) abort(); 246 255 } -
branches/eam_branches/ohana.20170809/src/libfits/table/F_table_format.c
r39399 r40113 3 3 4 4 /***********************/ 5 // get the format of a table column 5 // get the format of a table column (see comment block below) 6 6 // Nval : number of joined columns 7 7 // Nbytes : width of column … … 86 86 87 87 all can be preceeded by integer N which specified number 88 of entries in array 88 of entries in array: 89 90 1L == L 91 2L 92 3E, etc 89 93 */ 90 94 -
branches/eam_branches/ohana.20170809/src/libfits/table/F_uncompress_T.c
r39457 r40113 267 267 unsigned long int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen; 268 268 unsigned long int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes 269 unsigned long int Npix_expect = Nrows*fields[i].Nvalues; // expected number of pixels 270 271 myAssert (Nraw <= Nraw_alloc, "bad size"); 269 272 if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, Nraw_alloc, fields[i].pixsize)) ESCAPE; 273 myAssert (Npix_expect == Nraw, "bad size"); 270 274 271 275 if (VERBOSE_DUMP) {
Note:
See TracChangeset
for help on using the changeset viewer.
