Changeset 38441 for trunk/Ohana/src/libfits/table/F_set_column.c
- Timestamp:
- Jun 12, 2015, 6:18:23 PM (11 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libfits/table/F_set_column.c (modified) (41 diffs)
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/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);
Note:
See TracChangeset
for help on using the changeset viewer.
