Changeset 33648
- Timestamp:
- Apr 1, 2012, 2:22:08 PM (14 years ago)
- Location:
- trunk/Ohana/src/libfits
- Files:
-
- 11 edited
-
header/F_modify.c (modified) (6 diffs)
-
header/F_print.c (modified) (5 diffs)
-
include/gfitsio.h (modified) (2 diffs)
-
matrix/F_compress_M.c (modified) (4 diffs)
-
matrix/F_load_M.c (modified) (2 diffs)
-
matrix/F_read_portion.c (modified) (2 diffs)
-
matrix/F_read_segment.c (modified) (2 diffs)
-
matrix/F_write_M.c (modified) (4 diffs)
-
table/F_define_column.c (modified) (1 diff)
-
table/F_get_column.c (modified) (2 diffs)
-
table/F_set_column.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/header/F_modify.c
r28246 r33648 70 70 /* string value. Quotes must be at least 18 chars apart */ 71 71 if (!strcmp (mode, "%s")) { 72 strncpy (data, va_arg (argp, char *), 68); 72 char *ptr = va_arg (argp, char *); 73 if (!ptr) goto invalid; 74 strncpy (data, ptr, 68); 73 75 snprintf (string, 81, "%-8s= '%-18s' / %-s ", field, data, comment); 74 76 goto found_it; … … 76 78 77 79 /* failed to find mode */ 80 invalid: 81 va_end (argp); 78 82 return (FALSE); 79 83 … … 82 86 va_end (argp); 83 87 return (TRUE); 84 85 88 } 86 89 … … 143 146 /* comment type of value. */ 144 147 if (!strcmp (mode, "%S")) { 145 strncpy (data, va_arg (argp, char *), 71); 148 char *ptr = va_arg (argp, char *); 149 if (!ptr) goto invalid; 150 strncpy (data, ptr, 71); 146 151 snprintf (string, 81, "%-8s %-71s", field, data); 147 152 } … … 157 162 158 163 strncpy (data, qs, MAX (MIN (qe - qs, 71), 0)); 159 strncpy (comment, va_arg (argp, char *), 80); 164 165 char *ptr = va_arg (argp, char *); 166 if (!ptr) goto invalid; 167 strncpy (comment, ptr, 80); 160 168 gfits_pad_ending (comment, ' ', 82); /* comment must contain spaces to the end */ 161 169 snprintf (string, 81, "%-8s= %s / %-s", field, data, comment); … … 167 175 return (TRUE); 168 176 177 invalid: 178 va_end (argp); 179 return (FALSE); 169 180 } 170 181 -
trunk/Ohana/src/libfits/header/F_print.c
r28246 r33648 65 65 /* string value. Quotes must be at least 18 chars apart. Longer lines will this should be fixed to allow arbitrary string lengths, up to 69 chars */ 66 66 if (!strcmp (mode, "%s")) { 67 strcpy (line, va_arg (argp, char *)); 67 char *ptr = va_arg (argp, char *); 68 if (!ptr) goto invalid; 69 strcpy (line, ptr); 68 70 line[68] = 0; 69 71 snprintf (string, 81, "%-8s= '%-18s' / %46s ", field, line, blank); 70 72 goto found_it; 71 73 } 74 75 invalid: 76 va_end (argp); 72 77 return (FALSE); 73 78 … … 76 81 va_end (argp); 77 82 return (TRUE); 78 79 83 } 80 84 … … 130 134 if (!strcmp (mode, "%S")) { 131 135 /* we are forcing the entry to be <= 69 char long */ 132 strcpy (line, va_arg (argp, char *)); 133 line[71] = 0; 136 char *ptr = va_arg (argp, char *); 137 if (!ptr) goto invalid; 138 bzero (line, 80); 139 strncpy (line, ptr, 71); 134 140 snprintf (string, 81, "%-8s %-71s", field, line); 135 141 } … … 146 152 147 153 /* can't write the comment in gfits_print - use gfits_modify */ 148 if (!strcmp (mode, "%C")) return (FALSE);154 if (!strcmp (mode, "%C")) goto invalid; 149 155 150 156 strncpy (p, string, 80); … … 153 159 return (TRUE); 154 160 161 invalid: 162 va_end (argp); 163 return (FALSE); 155 164 } -
trunk/Ohana/src/libfits/include/gfitsio.h
r31663 r33648 184 184 int gfits_get_bintable_column PROTO((Header *header, FTable *table, char *label, void **data)); 185 185 int gfits_get_bintable_column_type PROTO((Header *header, char *label, char *type, int *Nval)); 186 int gfits_get_bintable_column_type_by_N PROTO((Header *header, int N, char *type, int *Nval)); 186 187 void *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, off_t *Nrow, int *Ncol)); 187 188 int gfits_get_table_column PROTO((Header *header, FTable *table, char *label, void **data)); … … 190 191 int gfits_read_table PROTO((char *filename, FTable *ftable)); 191 192 int gfits_set_bintable_column PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow)); 193 int gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow)); 192 194 int gfits_set_table_column PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow)); 193 195 int gfits_table_column PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4); -
trunk/Ohana/src/libfits/matrix/F_compress_M.c
r28241 r33648 424 424 int gfits_byteswap_zdata (char *zdata, int Nzdata, int pixsize) { 425 425 426 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; } 427 426 428 # ifdef BYTE_SWAP 427 429 428 430 int i; 429 char tmp;430 431 431 432 switch (pixsize) { … … 435 436 case 2: 436 437 for (i = 0; i < 2*Nzdata; i+=2) { 437 tmp = zdata[i]; 438 zdata[i] = zdata[i+1]; 439 zdata[i+1] = tmp; 438 DOSWAP (zdata[i+0], zdata[i+1]); 440 439 } 441 440 break; … … 443 442 case 4: 444 443 for (i = 0; i < 4*Nzdata; i+=4) { 445 tmp = zdata[i+1]; 446 zdata[i+1] = zdata[i+2]; 447 zdata[i+2] = tmp; 448 tmp = zdata[i]; 449 zdata[i] = zdata[i+3]; 450 zdata[i+3] = tmp; 444 DOSWAP (zdata[i+0], zdata[i+3]); 445 DOSWAP (zdata[i+1], zdata[i+2]); 451 446 } 452 447 break; … … 454 449 case 8: 455 450 for (i = 0; i < 8*Nzdata; i+=8) { 456 tmp = zdata[i+0]; 457 zdata[i+0] = zdata[i+7]; 458 zdata[i+7] = tmp; 459 tmp = zdata[i+1]; 460 zdata[i+1] = zdata[i+6]; 461 zdata[i+6] = tmp; 462 tmp = zdata[i+2]; 463 zdata[i+2] = zdata[i+5]; 464 zdata[i+5] = tmp; 465 tmp = zdata[i+3]; 466 zdata[i+3] = zdata[i+4]; 467 zdata[i+4] = tmp; 451 DOSWAP (zdata[i+0], zdata[i+7]); 452 DOSWAP (zdata[i+1], zdata[i+6]); 453 DOSWAP (zdata[i+2], zdata[i+5]); 454 DOSWAP (zdata[i+3], zdata[i+4]); 468 455 } 469 456 break; -
trunk/Ohana/src/libfits/matrix/F_load_M.c
r28241 r33648 38 38 } 39 39 40 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; } 41 40 42 # ifdef BYTE_SWAP 41 43 { 42 44 int perpix; 43 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7 , tmp;45 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7; 44 46 45 47 perpix = abs(header[0].bitpix) / 8; … … 55 57 if (perpix == 2) { 56 58 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 57 tmp = *byte0; 58 *byte0 = *byte1; 59 *byte1 = tmp; 59 DOSWAP(*byte0, *byte1); 60 60 } 61 61 } 62 62 if (perpix == 4) { 63 63 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 64 tmp = *byte0; 65 *byte0 = *byte3; 66 *byte3 = tmp; 67 tmp = *byte1; 68 *byte1 = *byte2; 69 *byte2 = tmp; 64 DOSWAP (*byte0, *byte3); 65 DOSWAP (*byte1, *byte2); 70 66 } 71 67 } 72 68 if (perpix == 8) { 73 69 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 74 tmp = *byte0; 75 *byte0 = *byte7; 76 *byte7 = tmp; 77 tmp = *byte1; 78 *byte1 = *byte6; 79 *byte6 = tmp; 80 tmp = *byte1; 81 *byte2 = *byte5; 82 *byte5 = tmp; 83 tmp = *byte1; 84 *byte3 = *byte4; 85 *byte4 = tmp; 70 DOSWAP (*byte0, *byte7); 71 DOSWAP (*byte1, *byte6); 72 DOSWAP (*byte2, *byte5); 73 DOSWAP (*byte3, *byte4); 86 74 } 87 75 } -
trunk/Ohana/src/libfits/matrix/F_read_portion.c
r28241 r33648 52 52 fclose (f); 53 53 54 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; } 55 54 56 # ifdef BYTE_SWAP 55 57 { 56 58 off_t i; 57 59 int perpix; 58 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7 , ctmp;59 60 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7; 61 60 62 perpix = abs(header.bitpix) / 8; 61 63 if (perpix > 1) { … … 70 72 if (perpix == 2) { 71 73 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 72 ctmp = *byte0; 73 *byte0 = *byte1; 74 *byte1 = ctmp; 74 DOSWAP(*byte0, *byte1); 75 75 } 76 76 } 77 77 if (perpix == 4) { 78 78 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 79 ctmp = *byte0; 80 *byte0 = *byte3; 81 *byte3 = ctmp; 82 ctmp = *byte1; 83 *byte1 = *byte2; 84 *byte2 = ctmp; 79 DOSWAP (*byte0, *byte3); 80 DOSWAP (*byte1, *byte2); 85 81 } 86 82 } 87 83 if (perpix == 8) { 88 84 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 89 ctmp = *byte0; 90 *byte0 = *byte7; 91 *byte7 = ctmp; 92 ctmp = *byte1; 93 *byte1 = *byte6; 94 *byte6 = ctmp; 95 ctmp = *byte1; 96 *byte2 = *byte5; 97 *byte5 = ctmp; 98 ctmp = *byte1; 99 *byte3 = *byte4; 100 *byte4 = ctmp; 85 DOSWAP (*byte0, *byte7); 86 DOSWAP (*byte1, *byte6); 87 DOSWAP (*byte2, *byte5); 88 DOSWAP (*byte3, *byte4); 101 89 } 102 90 } -
trunk/Ohana/src/libfits/matrix/F_read_segment.c
r28241 r33648 95 95 matrix[0].datasize = Nbytes; 96 96 97 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; } 98 97 99 # ifdef BYTE_SWAP 98 100 { 99 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7 , ctmp;101 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7; 100 102 int perpix; 101 103 … … 112 114 if (perpix == 2) { 113 115 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 114 ctmp = *byte0; 115 *byte0 = *byte1; 116 *byte1 = ctmp; 116 DOSWAP(*byte0, *byte1); 117 117 } 118 118 } 119 119 if (perpix == 4) { 120 120 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 121 ctmp = *byte0; 122 *byte0 = *byte3; 123 *byte3 = ctmp; 124 ctmp = *byte1; 125 *byte1 = *byte2; 126 *byte2 = ctmp; 121 DOSWAP (*byte0, *byte3); 122 DOSWAP (*byte1, *byte2); 127 123 } 128 124 } 129 125 if (perpix == 8) { 130 126 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 131 ctmp = *byte0; 132 *byte0 = *byte7; 133 *byte7 = ctmp; 134 ctmp = *byte1; 135 *byte1 = *byte6; 136 *byte6 = ctmp; 137 ctmp = *byte1; 138 *byte2 = *byte5; 139 *byte5 = ctmp; 140 ctmp = *byte1; 141 *byte3 = *byte4; 142 *byte4 = ctmp; 127 DOSWAP (*byte0, *byte7); 128 DOSWAP (*byte1, *byte6); 129 DOSWAP (*byte2, *byte5); 130 DOSWAP (*byte3, *byte4); 143 131 } 144 132 } -
trunk/Ohana/src/libfits/matrix/F_write_M.c
r27435 r33648 36 36 nbytes = FT_RECORD_SIZE * ((off_t) (matrix[0].datasize / FT_RECORD_SIZE)); 37 37 38 # define DOSWAP(A,B) { char tmp = A; A = B; B = tmp; } 39 38 40 /* this is a bit cumbersome: swap all words, write out file, then swap back... */ 39 41 # ifdef BYTE_SWAP 40 42 { 41 43 off_t i; 42 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7 , tmp;44 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7; 43 45 int perpix; 44 46 … … 55 57 if (perpix == 2) { 56 58 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 57 tmp = *byte0; 58 *byte0 = *byte1; 59 *byte1 = tmp; 59 DOSWAP(*byte0, *byte1); 60 60 } 61 61 } 62 62 if (perpix == 4) { 63 63 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 64 tmp = *byte0; 65 *byte0 = *byte3; 66 *byte3 = tmp; 67 tmp = *byte1; 68 *byte1 = *byte2; 69 *byte2 = tmp; 64 DOSWAP (*byte0, *byte3); 65 DOSWAP (*byte1, *byte2); 70 66 } 71 67 } 72 68 if (perpix == 8) { 73 69 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 74 tmp = *byte0; 75 *byte0 = *byte7; 76 *byte7 = tmp; 77 tmp = *byte1; 78 *byte1 = *byte6; 79 *byte6 = tmp; 80 tmp = *byte1; 81 *byte2 = *byte5; 82 *byte5 = tmp; 83 tmp = *byte1; 84 *byte3 = *byte4; 85 *byte4 = tmp; 70 DOSWAP (*byte0, *byte7); 71 DOSWAP (*byte1, *byte6); 72 DOSWAP (*byte2, *byte5); 73 DOSWAP (*byte3, *byte4); 86 74 } 87 75 } … … 98 86 { 99 87 off_t i; 100 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7 , tmp;88 unsigned char *byte0, *byte1, *byte2, *byte3, *byte4, *byte5, *byte6, *byte7; 101 89 int perpix; 102 90 … … 113 101 if (perpix == 2) { 114 102 for (i = 0; i < nbytes; i+=2, byte0 += 2, byte1 += 2) { 115 tmp = *byte0; 116 *byte0 = *byte1; 117 *byte1 = tmp; 103 DOSWAP(*byte0, *byte1); 118 104 } 119 105 } 120 106 if (perpix == 4) { 121 107 for (i = 0; i < nbytes; i+=4, byte0 += 4, byte1 += 4, byte2 += 4, byte3 += 4) { 122 tmp = *byte0; 123 *byte0 = *byte3; 124 *byte3 = tmp; 125 tmp = *byte1; 126 *byte1 = *byte2; 127 *byte2 = tmp; 108 DOSWAP (*byte0, *byte3); 109 DOSWAP (*byte1, *byte2); 128 110 } 129 111 } 130 112 if (perpix == 8) { 131 113 for (i = 0; i < nbytes; i+=8, byte0 += 8, byte1 += 8, byte2 += 8, byte3 += 8, byte4 += 8, byte5 += 8, byte6 += 8, byte7 += 8) { 132 tmp = *byte0; 133 *byte0 = *byte7; 134 *byte7 = tmp; 135 tmp = *byte1; 136 *byte1 = *byte6; 137 *byte6 = tmp; 138 tmp = *byte1; 139 *byte2 = *byte5; 140 *byte5 = tmp; 141 tmp = *byte1; 142 *byte3 = *byte4; 143 *byte4 = tmp; 114 DOSWAP (*byte0, *byte7); 115 DOSWAP (*byte1, *byte6); 116 DOSWAP (*byte2, *byte5); 117 DOSWAP (*byte3, *byte4); 144 118 } 145 119 } -
trunk/Ohana/src/libfits/table/F_define_column.c
r28241 r33648 4 4 /***********************/ 5 5 int gfits_define_bintable_column (Header *header, char *format, char *label, char *comment, char *unit, double bscale, double bzero) { 6 7 assert (label); 8 assert (format); 6 9 7 10 off_t Naxis1; -
trunk/Ohana/src/libfits/table/F_get_column.c
r31371 r33648 126 126 127 127 /***********************/ 128 int gfits_get_bintable_column_type_by_N (Header *header, int N, char *type, int *Nval) { 129 130 int Nbytes; 131 char field[80], format[80]; 132 133 assert (N > 0); 134 135 sprintf (field, "TFORM%d", N); 136 if (!gfits_scan (header, field, "%s", 1, format)) return FALSE; 137 if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE); 138 return (TRUE); 139 } 140 141 /***********************/ 128 142 int gfits_get_bintable_column_type (Header *header, char *label, char *type, int *Nval) { 129 143 130 int i, N, Nfields , Nbytes;131 char tlabel[80], field[80] , format[80];144 int i, N, Nfields; 145 char tlabel[80], field[80]; 132 146 133 147 if (label == (char *) NULL) return (FALSE); … … 144 158 N = i - 1; 145 159 146 sprintf (field, "TFORM%d", N); 147 gfits_scan (header, field, "%s", 1, format); 148 149 if (!gfits_bintable_format (format, type, Nval, &Nbytes)) return (FALSE); 160 if (!gfits_get_bintable_column_type_by_N (header, N, type, Nval)) return FALSE; 150 161 return (TRUE); 151 162 } -
trunk/Ohana/src/libfits/table/F_set_column.c
r31371 r33648 40 40 /* interpret format */ 41 41 sprintf (field, "TSCAL%d", N); 42 gfits_scan (header, field, "%lf", 1, &Bscale); 42 if (!gfits_scan (header, field, "%lf", 1, &Bscale)) { 43 Bscale = 1.0; 44 } 43 45 sprintf (field, "TZERO%d", N); 44 gfits_scan (header, field, "%lf", 1, &Bzero); 46 if (!gfits_scan (header, field, "%lf", 1, &Bzero)) { 47 Bzero = 0.0; 48 } 45 49 sprintf (field, "TFORM%d", N); 46 50 gfits_scan (header, field, "%s", 1, format); … … 126 130 for (i = 0; i < Nrow; i++, Pout += Nx, Pin += Nval*Nbytes) { 127 131 memcpy (Pout, Pin, Nval*Nbytes); 132 } 133 134 free (array); 135 return (TRUE); 136 } 137 138 /***********************/ 139 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow) { 140 141 off_t Nx, Ny, nbytes; 142 int i, N, Nfields; 143 int Nval, NbytesOut, Nstart, Nv, Nb; 144 char tlabel[80], field[80], format[80], outtype[16], tmpline[16]; 145 char *Pin, *Pout, *array; 146 double Bscale, Bzero; 147 148 if (label == (char *) NULL) return (FALSE); 149 if (label[0] == 0) return (FALSE); 150 151 /* find label in header */ 152 tlabel[0] = 0; 153 gfits_scan (header, "TFIELDS", "%d", 1, &Nfields); 154 for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) { 155 sprintf (field, "TTYPE%d", i); 156 gfits_scan (header, field, "%s", 1, tlabel); 157 } 158 if (strcasecmp (label, tlabel)) return (FALSE); 159 N = i - 1; 160 161 /* interpret format */ 162 sprintf (field, "TSCAL%d", N); 163 if (!gfits_scan (header, field, "%lf", 1, &Bscale)) { 164 Bscale = 1.0; 165 } 166 sprintf (field, "TZERO%d", N); 167 if (!gfits_scan (header, field, "%lf", 1, &Bzero)) { 168 Bzero = 0.0; 169 } 170 sprintf (field, "TFORM%d", N); 171 gfits_scan (header, field, "%s", 1, format); 172 173 if (!gfits_bintable_format (format, outtype, &Nval, &NbytesOut)) return (FALSE); 174 175 /* check existing table dimensions */ 176 gfits_scan (header, "NAXIS1", OFF_T_FMT, 1, &Nx); 177 gfits_scan (header, "NAXIS2", OFF_T_FMT, 1, &Ny); 178 if (Ny == 0) { 179 Ny = Nrow; 180 header[0].Naxis[1] = Ny; 181 gfits_modify (header, "NAXIS2", OFF_T_FMT, 1, Ny); 182 183 nbytes = gfits_data_size (header); 184 REALLOCATE (table[0].buffer, char, MAX (nbytes, 1)); 185 bzero (table[0].buffer, nbytes); 186 table[0].datasize = nbytes; 187 } 188 if (Ny != Nrow) return (FALSE); 189 190 /* scan columns to find insert point */ 191 Nstart = 0; 192 for (i = 1; i < N; i++) { 193 sprintf (field, "TFORM%d", i); 194 gfits_scan (header, field, "%s", 1, format); 195 gfits_bintable_format (format, tmpline, &Nv, &Nb); 196 Nstart += Nv*Nb; 197 } 198 199 /* make duplicate of data with correct type 200 byte swap and Bzero/Bscale */ 201 ALLOCATE (array, char, NbytesOut*Nval*Nrow); 202 Pin = data; 203 Pout = array; 204 205 /** input == char **/ 206 if (!strcmp (outtype, "char") && !strcmp (intype, "char")) { 207 int NbytesIn = 1; 208 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 209 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 210 } 211 } 212 if (!strcmp (outtype, "short") && !strcmp (intype, "char")) { 213 int NbytesIn = 1; 214 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 215 *(short *)Pout = (*(char *)Pin - Bzero) / Bscale; 216 # ifdef BYTE_SWAP 217 SWAP_BYTE; 218 # endif 219 } 220 } 221 if (!strcmp (outtype, "int") && !strcmp (intype, "char")) { 222 int NbytesIn = 1; 223 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 224 *(int *)Pout = (*(char *)Pin - Bzero) / Bscale; 225 # ifdef BYTE_SWAP 226 SWAP_WORD; 227 # endif 228 } 229 } 230 if (!strcmp (outtype, "float") && !strcmp (intype, "char")) { 231 int NbytesIn = 1; 232 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 233 *(float *)Pout = (*(char *)Pin - Bzero) / Bscale; 234 # ifdef BYTE_SWAP 235 SWAP_WORD; 236 # endif 237 } 238 } 239 if (!strcmp (outtype, "double") && !strcmp (intype, "char")) { 240 int NbytesIn = 1; 241 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 242 *(double *)Pout = (*(char *)Pin - Bzero) / Bscale; 243 # ifdef BYTE_SWAP 244 SWAP_DBLE; 245 # endif 246 } 247 } 248 249 /** input == short **/ 250 if (!strcmp (outtype, "char") && !strcmp (intype, "short")) { 251 int NbytesIn = 2; 252 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 253 *(char *)Pout = (*(short *)Pin - Bzero) / Bscale; 254 } 255 } 256 if (!strcmp (outtype, "short") && !strcmp (intype, "short")) { 257 int NbytesIn = 2; 258 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 259 *(short *)Pout = (*(short *)Pin - Bzero) / Bscale; 260 # ifdef BYTE_SWAP 261 SWAP_BYTE; 262 # endif 263 } 264 } 265 if (!strcmp (outtype, "int") && !strcmp (intype, "short")) { 266 int NbytesIn = 2; 267 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 268 *(int *)Pout = (*(short *)Pin - Bzero) / Bscale; 269 # ifdef BYTE_SWAP 270 SWAP_WORD; 271 # endif 272 } 273 } 274 if (!strcmp (outtype, "float") && !strcmp (intype, "short")) { 275 int NbytesIn = 2; 276 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 277 *(float *)Pout = (*(short *)Pin - Bzero) / Bscale; 278 # ifdef BYTE_SWAP 279 SWAP_WORD; 280 # endif 281 } 282 } 283 if (!strcmp (outtype, "double") && !strcmp (intype, "short")) { 284 int NbytesIn = 2; 285 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 286 *(double *)Pout = (*(short *)Pin - Bzero) / Bscale; 287 # ifdef BYTE_SWAP 288 SWAP_DBLE; 289 # endif 290 } 291 } 292 293 /** input == int **/ 294 if (!strcmp (outtype, "char") && !strcmp (intype, "int")) { 295 int NbytesIn = 4; 296 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 297 *(char *)Pout = (*(int *)Pin - Bzero) / Bscale; 298 } 299 } 300 if (!strcmp (outtype, "short") && !strcmp (intype, "int")) { 301 int NbytesIn = 4; 302 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 303 *(short *)Pout = (*(int *)Pin - Bzero) / Bscale; 304 # ifdef BYTE_SWAP 305 SWAP_BYTE; 306 # endif 307 } 308 } 309 if (!strcmp (outtype, "int") && !strcmp (intype, "int")) { 310 int NbytesIn = 4; 311 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 312 *(int *)Pout = (*(int *)Pin - Bzero) / Bscale; 313 # ifdef BYTE_SWAP 314 SWAP_WORD; 315 # endif 316 } 317 } 318 if (!strcmp (outtype, "float") && !strcmp (intype, "int")) { 319 int NbytesIn = 4; 320 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 321 *(float *)Pout = (*(int *)Pin - Bzero) / Bscale; 322 # ifdef BYTE_SWAP 323 SWAP_WORD; 324 # endif 325 } 326 } 327 if (!strcmp (outtype, "double") && !strcmp (intype, "int")) { 328 int NbytesIn = 4; 329 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 330 *(double *)Pout = (*(int *)Pin - Bzero) / Bscale; 331 # ifdef BYTE_SWAP 332 SWAP_DBLE; 333 # endif 334 } 335 } 336 337 /** input == float **/ 338 if (!strcmp (outtype, "char") && !strcmp (intype, "float")) { 339 int NbytesIn = 4; 340 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 341 *(char *)Pout = (*(float *)Pin - Bzero) / Bscale; 342 } 343 } 344 if (!strcmp (outtype, "short") && !strcmp (intype, "float")) { 345 int NbytesIn = 4; 346 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 347 *(short *)Pout = (*(float *)Pin - Bzero) / Bscale; 348 # ifdef BYTE_SWAP 349 SWAP_BYTE; 350 # endif 351 } 352 } 353 if (!strcmp (outtype, "int") && !strcmp (intype, "float")) { 354 int NbytesIn = 4; 355 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 356 *(int *)Pout = (*(float *)Pin - Bzero) / Bscale; 357 # ifdef BYTE_SWAP 358 SWAP_WORD; 359 # endif 360 } 361 } 362 if (!strcmp (outtype, "float") && !strcmp (intype, "float")) { 363 int NbytesIn = 4; 364 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 365 *(float *)Pout = (*(float *)Pin - Bzero) / Bscale; 366 # ifdef BYTE_SWAP 367 SWAP_WORD; 368 # endif 369 } 370 } 371 if (!strcmp (outtype, "double") && !strcmp (intype, "float")) { 372 int NbytesIn = 4; 373 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 374 *(double *)Pout = (*(float *)Pin - Bzero) / Bscale; 375 # ifdef BYTE_SWAP 376 SWAP_DBLE; 377 # endif 378 } 379 } 380 381 /** input == double **/ 382 if (!strcmp (outtype, "char") && !strcmp (intype, "double")) { 383 int NbytesIn = 8; 384 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 385 *(char *)Pout = (*(double *)Pin - Bzero) / Bscale; 386 } 387 } 388 if (!strcmp (outtype, "short") && !strcmp (intype, "double")) { 389 int NbytesIn = 8; 390 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 391 *(short *)Pout = (*(double *)Pin - Bzero) / Bscale; 392 # ifdef BYTE_SWAP 393 SWAP_BYTE; 394 # endif 395 } 396 } 397 if (!strcmp (outtype, "int") && !strcmp (intype, "double")) { 398 int NbytesIn = 8; 399 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 400 *(int *)Pout = (*(double *)Pin - Bzero) / Bscale; 401 # ifdef BYTE_SWAP 402 SWAP_WORD; 403 # endif 404 } 405 } 406 if (!strcmp (outtype, "float") && !strcmp (intype, "double")) { 407 int NbytesIn = 8; 408 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 409 *(float *)Pout = (*(double *)Pin - Bzero) / Bscale; 410 # ifdef BYTE_SWAP 411 SWAP_WORD; 412 # endif 413 } 414 } 415 if (!strcmp (outtype, "double") && !strcmp (intype, "double")) { 416 int NbytesIn = 8; 417 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 418 *(double *)Pout = (*(double *)Pin - Bzero) / Bscale; 419 # ifdef BYTE_SWAP 420 SWAP_DBLE; 421 # endif 422 } 423 } 424 425 /* check array space */ 426 if (Nx*Ny < Nx*(Nrow - 1) + Nstart + Nval*NbytesOut) { 427 fprintf (stderr, "mismatch in array sizes\n"); 428 return (FALSE); 429 } 430 431 /* insert bytes from array into appropriate section of buffer */ 432 Pout = table[0].buffer + Nstart; 433 Pin = array; 434 for (i = 0; i < Nrow; i++, Pout += Nx, Pin += Nval*NbytesOut) { 435 memcpy (Pout, Pin, Nval*NbytesOut); 128 436 } 129 437
Note:
See TracChangeset
for help on using the changeset viewer.
