Changeset 41676
- Timestamp:
- Jul 1, 2021, 1:58:44 PM (5 years ago)
- Location:
- trunk/Ohana/src/libfits/table
- Files:
-
- 3 edited
-
F_get_column.c (modified) (3 diffs)
-
F_set_column.c (modified) (1 diff)
-
F_table_format.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/table/F_get_column.c
r41474 r41676 310 310 C - complex float 311 311 M - complex double 312 P - var leng htarray descrpt (64 bit)312 P - var length array descrpt (64 bit) 313 313 314 314 all can be preceeded by integer N which specified number … … 341 341 342 342 if (!gfits_table_format (format, type, Nval, &Nbytes)) return (FALSE); 343 *Nval = 1;344 343 345 344 return (TRUE); … … 379 378 gfits_scan (header, "NAXIS2", OFF_T_FMT, 1, &Ny); 380 379 381 /* scan columns to find insert point */ 382 Nstart = 0; 383 for (i = 1; i < N; i++) { 384 snprintf (field, 256, "TFORM%d", i); 385 gfits_scan (header, field, "%s", 1, format); 386 gfits_table_format (format, tmp, &Nv, &Nb); 387 Nstart += Nv*Nb; 380 // find the starting byte for this column 381 // FITS ASCII table is supposed to have TBCOLn to specify the starting point 382 // but if it is missing, we can try to find by counting 383 snprintf (field, 256, "TBCOL%d", N); 384 int status = gfits_scan (header, field, "%d", 1, &Nstart); 385 if (!status) { 386 /* scan columns to find insert point */ 387 Nstart = 0; 388 for (i = 1; i < N; i++) { 389 snprintf (field, 256, "TFORM%d", i); 390 gfits_scan (header, field, "%s", 1, format); 391 gfits_table_format (format, tmp, &Nv, &Nb); 392 Nstart += Nv*Nb; 393 } 394 } else { 395 Nstart --; 388 396 } 389 397 390 398 /* allocate temporary line, init pointers */ 391 ALLOCATE (line, char, Nval +1);392 bzero (line, Nval +1);399 ALLOCATE (line, char, Nval*Nbytes+1); 400 bzero (line, Nval*Nbytes+1); 393 401 Pin = table[0].buffer + Nstart; 394 402 -
trunk/Ohana/src/libfits/table/F_set_column.c
r41422 r41676 478 478 /* print line with appropriate formatting */ 479 479 ALLOCATE (array, char, Nbytes*Nval*Nrow); 480 ALLOCATE (line, char, N val+1);480 ALLOCATE (line, char, Nbytes+1); 481 481 Pin = data; 482 482 Pout = array; 483 483 if (!strcmp (type, "char")) { 484 for (i = 0; i < N val*Nrow; i++, Pin++, Pout++) {484 for (i = 0; i < Nbytes*Nval*Nrow; i++, Pin++, Pout++) { 485 485 *Pout = *Pin; 486 486 } 487 487 } 488 488 if (!strcmp (type, "int")) { 489 for (i = 0; i < Nrow; i++, Pin+=4, Pout+=N val) {490 snprintf (line, N val+ 1, cformat, *(int *)Pin);491 memcpy (Pout, line, N val);489 for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nbytes) { 490 snprintf (line, Nbytes + 1, cformat, *(int *)Pin); 491 memcpy (Pout, line, Nbytes); 492 492 } 493 493 } 494 494 if (!strcmp (type, "float")) { 495 for (i = 0; i < Nrow; i++, Pin+=4, Pout+=N val) {496 snprintf (line, N val+ 1, cformat, *(float *)Pin);497 memcpy (Pout, line, N val);495 for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nbytes) { 496 snprintf (line, Nbytes + 1, cformat, *(float *)Pin); 497 memcpy (Pout, line, Nbytes); 498 498 } 499 499 } -
trunk/Ohana/src/libfits/table/F_table_format.c
r41474 r41676 5 5 // get the format of a table column 6 6 // Nval : number of joined columns 7 // Nbytes : width of column 7 // Nbytes : width of column, determined by the type (e.g., float = 4 bytes) 8 8 int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) { 9 9 … … 90 90 91 91 /***********************/ 92 // get the format of a table column 93 // Nval : number of fields (1 for all types except string) 94 // Nbytes : width of FITS table column, ie number of bytes in ASCII table 92 95 int gfits_table_format (char *format, char *type, int *Nval, int *Nbytes) { 93 96 … … 109 112 int isLong = FALSE; 110 113 char Type = 'x'; 111 if (Fchar == 'D') { *Nbytes = 1; strcpy (type, "double"); Type = 'e'; *Nval = Nv; isLong = TRUE; }112 if (Fchar == 'E') { *Nbytes = 1; strcpy (type, "float"); Type = 'e'; *Nval = Nv; }113 if (Fchar == 'F') { *Nbytes = 1; strcpy (type, "float"); Type = 'f'; *Nval = Nv; }114 if (Fchar == 'I') { *Nbytes = 1; strcpy (type, "int"); Type = 'd'; *Nval = Nv; }115 if (Fchar == 'A') { *Nbytes = 1; strcpy (type, "char"); Type = 's'; *Nval = Nv; }114 if (Fchar == 'D') { *Nbytes = Nv; strcpy (type, "double"); Type = 'e'; *Nval = 1; isLong = TRUE; } 115 if (Fchar == 'E') { *Nbytes = Nv; strcpy (type, "float"); Type = 'e'; *Nval = 1; } 116 if (Fchar == 'F') { *Nbytes = Nv; strcpy (type, "float"); Type = 'f'; *Nval = 1; } 117 if (Fchar == 'I') { *Nbytes = Nv; strcpy (type, "int"); Type = 'd'; *Nval = 1; } 118 if (Fchar == 'A') { *Nbytes = 1; strcpy (type, "char"); Type = 's'; *Nval = Nv; } 116 119 if (!*Nbytes) { return (FALSE); } 117 120 … … 133 136 /* 134 137 valid TABLE column formats: 135 FN.N - floating point 136 INN - integer 138 FN.N - floating point taking NN characters in the table 139 INN - integer taking NN characters in the table 137 140 ANN - NN char string 138 141
Note:
See TracChangeset
for help on using the changeset viewer.
