Changeset 3470 for trunk/psLib/src/astronomy/psCoord.c
- Timestamp:
- Mar 21, 2005, 3:35:49 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astronomy/psCoord.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psCoord.c
r3450 r3470 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-03- 18 21:34:43$12 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-03-22 01:35:49 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 396 396 void projectionFree(psProjection *p) 397 397 { 398 psFree(p);398 // There are no dynamically allocated items 399 399 } 400 400 … … 413 413 p->type = type; 414 414 415 p_psMemSetDeallocator(p, (psFreeFcn) p laneFree);415 p_psMemSetDeallocator(p, (psFreeFcn) projectionFree); 416 416 return(p); 417 417 } … … 547 547 PS_PTR_CHECK_NULL(position2, NULL); 548 548 549 // Check positions near 90 degree and issue warnings if necessary 549 550 if (position1->d >= DEG_TO_RAD(90.0)) { 550 psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position1->d is larger than 90 degrees. Returning NULL.\n"); 551 return(NULL); 551 psLogMsg(__func__, PS_LOG_WARN, 552 "WARNING: psDeproject(): position1->d is larger than 90 degrees. Returning NULL."); 553 return NULL; 552 554 } 553 555 if (position2->d >= DEG_TO_RAD(90.0)) { 554 psLogMsg(__func__, PS_LOG_WARN, "WARNING: psDeproject(): position2->d is larger than 90 degrees. Returning NULL.\n"); 555 return(NULL); 556 } 557 558 psPlane* lin; 559 psProjection proj; 560 psSphere* tmp; 561 556 psLogMsg(__func__, PS_LOG_WARN, 557 "WARNING: psDeproject(): position2->d is larger than 90 degrees. Returning NULL."); 558 return NULL; 559 } 560 561 // Allocate return structure 562 psSphere* tmp = psSphereAlloc(); 563 564 // Mode is LINEAR - Use first position as projection center and project second point 565 // onto tangent plane, set point projected into psSphere structure x->r y->d 562 566 if (mode == PS_LINEAR) { 563 proj.R = position1->r; 564 proj.D = position1->d; 565 proj.Xs = 1.0; 566 proj.Ys = 1.0; 567 proj.type = PS_PROJ_TAN; 568 569 lin = psProject(position1, &proj); 570 lin = psProject(position2, &proj); 571 tmp = psDeproject(lin, &proj); 567 psProjection* proj = psProjectionAlloc(position1->r, 568 position1->d, 569 1.0, 570 1.0, 571 PS_PROJ_TAN); 572 573 // Perform projection onto tangent plane 574 psPlane* lin = psProject(position2, proj); 575 576 // Set return values 577 tmp->r = lin->x; 578 tmp->d = lin->y; 579 580 // Free data structures allocated 581 psFree(proj); 572 582 psFree(lin); 573 // XXX: Do we need to convert units in tmp? 574 return (tmp); 583 584 // Mode is SPHERICAL - Get difference between positiion 1 and position 2 and convert 585 // offset value from radians to desired units and return 575 586 } else if (mode == PS_SPHERICAL) { 576 tmp = (psSphere* ) psAlloc(sizeof(psSphere));577 587 tmp->r = position2->r - position1->r; 578 588 tmp->d = position2->d - position1->d; … … 585 595 tmp->dErr = 0.0; 586 596 597 // Convert to desired units 587 598 if (unit == PS_ARCSEC) { 588 599 tmp->r = RAD_TO_SEC(tmp->r); … … 600 611 unit); 601 612 psFree(tmp); 602 return (NULL);613 return NULL; 603 614 } 604 605 return (tmp); 606 } 607 608 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 609 PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN, 610 mode); 611 return (NULL); 615 // Invalid mode 616 } else { 617 618 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 619 PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN, 620 mode); 621 psFree(tmp); 622 return NULL; 623 } 624 625 // Return value 626 return tmp; 612 627 } 613 628 … … 631 646 PS_PTR_CHECK_NULL(offset, NULL); 632 647 633 psPlane lin;634 648 psSphere* tmp; 635 psProjection proj;636 649 psF64 tmpR = 0.0; 637 650 psF64 tmpD = 0.0; 638 651 652 // If mode is linear then set position to projection center 653 // and offset to linear coordinate then deproject to obtain 654 // new sphere coordinate 639 655 if (mode == PS_LINEAR) { 640 proj.R = position->r; 641 proj.D = position->d; 642 proj.Xs = 1.0; 643 proj.Ys = 1.0; 644 proj.type = PS_PROJ_TAN; 645 646 lin.x = offset->r; 647 lin.y = offset->d; 648 649 tmp = psDeproject(&lin, &proj); 650 return (tmp); 656 657 // Allocate plane coordinate and set coordinate 658 psPlane* lin = psPlaneAlloc(); 659 lin->x = offset->r; 660 lin->y = offset->d; 661 662 // Allocate and set projection structure 663 psProjection* proj = psProjectionAlloc(position->r, 664 position->d, 665 1.0, 666 1.0, 667 PS_PROJ_TAN); 668 669 // Project tangent plane coord to spherical coord 670 tmp = psDeproject(lin, proj); 671 672 // Free data structures used 673 psFree(proj); 674 psFree(lin); 675 676 // If mode is spherical then convert offset to radians, add the offset 677 // to the position and wrap to 0 to 2pi 651 678 } else if (mode == PS_SPHERICAL) { 679 680 // Convert offset unit to radians 652 681 if (unit == PS_ARCSEC) { 653 682 tmpR = SEC_TO_RAD(offset->r); … … 666 695 PS_ERRORTEXT_psCoord_UNITS_UNKNOWN, 667 696 unit); 668 return (NULL);697 return NULL; 669 698 } 670 699 671 tmp = (psSphere* ) psAlloc(sizeof(psSphere)); 700 // Allocate sphere structure to return 701 tmp = psSphereAlloc(); 702 703 // Add offset and wrap to 0 to 2PI if necessary 672 704 tmp->r = position->r + tmpR; 673 705 tmp->r = fmod(tmp->r, 2.0*PS_PI); … … 677 709 tmp->dErr = 0.0; 678 710 679 return (tmp); 680 } 681 682 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 683 PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN, 684 mode); 685 686 return (NULL); 711 // Invalid mode report error 712 } else { 713 714 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 715 PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN, 716 mode); 717 return NULL; 718 } 719 720 return tmp; 687 721 } 688 722
Note:
See TracChangeset
for help on using the changeset viewer.
