Changeset 16700
- Timestamp:
- Feb 27, 2008, 5:16:50 PM (18 years ago)
- Location:
- branches/eam_branch_20080223/Ohana/src/libfits
- Files:
-
- 2 edited
-
include/gfitsio.h (modified) (1 diff)
-
table/F_get_column.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080223/Ohana/src/libfits/include/gfitsio.h
r15751 r16700 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 void *gfits_get_bintable_column_data PROTO((Header *header, FTable *table, char *label, char *type, int *Nrow, int *Ncol)); 186 187 int gfits_get_table_column PROTO((Header *header, FTable *table, char *label, void **data)); 187 188 int gfits_get_table_column_type PROTO((Header *header, char *label, char *type)); -
branches/eam_branch_20080223/Ohana/src/libfits/table/F_get_column.c
r16139 r16700 14 14 tmp = Pin[2]; Pin[2] = Pin[5]; Pin[5] = tmp; \ 15 15 tmp = Pin[3]; Pin[3] = Pin[4]; Pin[4] = tmp; } 16 17 void *gfits_get_bintable_column_data (Header *header, FTable *table, char *label, char *type, int *Nrow, int *Ncol) { 18 19 int i, N, Nfields, Nval, Nbytes, Nx, Ny, Nstart, Nv, Nb; 20 char tlabel[80], field[80], format[80], tmpline[16]; 21 char *Pin, *Pout, *array; 22 double Bscale, Bzero; 23 24 if (label == (char *) NULL) return (NULL); 25 if (label[0] == 0) return (NULL); 26 27 /* find label in header */ 28 tlabel[0] = 0; 29 if (!gfits_scan (header, "TFIELDS", "%d", 1, &Nfields)) return (NULL); 30 for (i = 1; strcmp (label, tlabel) && (i < Nfields + 1); i++) { 31 sprintf (field, "TTYPE%d", i); 32 gfits_scan (header, field, "%s", 1, tlabel); 33 } 34 if (strcmp (label, tlabel)) return (NULL); 35 N = i - 1; 36 37 Bscale = 1; 38 Bzero = 0; 39 40 /* interpret format */ 41 sprintf (field, "TSCAL%d", N); 42 gfits_scan (header, field, "%lf", 1, &Bscale); 43 sprintf (field, "TZERO%d", N); 44 gfits_scan (header, field, "%lf", 1, &Bzero); 45 sprintf (field, "TFORM%d", N); 46 gfits_scan (header, field, "%s", 1, format); 47 48 if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (NULL); 49 50 /* check existing table dimensions */ 51 gfits_scan (header, "NAXIS1", "%d", 1, &Nx); 52 gfits_scan (header, "NAXIS2", "%d", 1, &Ny); 53 54 /* scan columns to find insert point */ 55 Nstart = 0; 56 for (i = 1; i < N; i++) { 57 sprintf (field, "TFORM%d", i); 58 gfits_scan (header, field, "%s", 1, format); 59 gfits_bintable_format (format, tmpline, &Nv, &Nb); 60 Nstart += Nv*Nb; 61 } 62 63 /* extract bytes from table into array */ 64 ALLOCATE (array, char, Nbytes*Nval*Ny); 65 Pin = table[0].buffer + Nstart; 66 Pout = array; 67 for (i = 0; i < Ny; i++, Pin += Nx, Pout += Nval*Nbytes) { 68 memcpy (Pout, Pin, Nval*Nbytes); 69 } 70 71 /* convert data in-situ with correct type, byte swap and Bzero/Bscale */ 72 Pin = array; 73 Pout = array; 74 if (!strcmp (type, "char")) { 75 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 76 *(char *)Pout = *(char *)Pin*Bscale + Bzero; 77 } 78 } 79 if (!strcmp (type, "short")) { 80 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 81 # ifdef BYTE_SWAP 82 SWAP_BYTE; 83 # endif 84 *(short *)Pout = *(short *)Pin*Bscale + Bzero; 85 } 86 } 87 if (!strcmp (type, "int")) { 88 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 89 # ifdef BYTE_SWAP 90 SWAP_WORD; 91 # endif 92 *(int *)Pout = *(int *)Pin*Bscale + Bzero; 93 } 94 } 95 if (!strcmp (type, "float")) { 96 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 97 # ifdef BYTE_SWAP 98 SWAP_WORD; 99 # endif 100 *(float *)Pout = *(float *)Pin*Bscale + Bzero; 101 } 102 } 103 if (!strcmp (type, "double")) { 104 for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) { 105 # ifdef BYTE_SWAP 106 SWAP_DBLE; 107 # endif 108 *(double *)Pout = *(double *)Pin*Bscale + Bzero; 109 } 110 } 111 112 *Ncol = Nval; 113 *Nrow = Ny; 114 return (array); 115 } 16 116 17 117 /***********************/
Note:
See TracChangeset
for help on using the changeset viewer.
