LTP GCOV extension - code coverage report
Current view: directory - frmts/raw - atlsci_spheroid.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 71
Code covered: 73.2 % Executed lines: 52

       1                 : /******************************************************************************
       2                 :  * $Id: atlsci_spheroid.cpp 10645 2007-01-18 02:22:39Z warmerdam $
       3                 :  *
       4                 :  * Project:  Spheroid classes
       5                 :  * Purpose:  Provide spheroid lookup table base classes.
       6                 :  * Author:   Gillian Walter
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 1999, Frank Warmerdam
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #include "atlsci_spheroid.h"
      31                 : #include "cpl_string.h"
      32                 : 
      33                 : CPL_CVSID("$Id: atlsci_spheroid.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
      34                 : 
      35                 : /**********************************************************************/
      36                 : /* ================================================================== */
      37                 : /*          Spheroid definitions                                      */
      38                 : /* ================================================================== */
      39                 : /**********************************************************************/
      40                 : 
      41                 : 
      42             216 : void SpheroidItem :: SetValuesByRadii(const char *spheroidname, double eq_radius, double p_radius)
      43                 : {
      44             216 :     spheroid_name = CPLStrdup(spheroidname);
      45             216 :     equitorial_radius=eq_radius;
      46             216 :     polar_radius=p_radius;
      47             216 :     inverse_flattening=eq_radius/(eq_radius - polar_radius);
      48             216 : }
      49                 : 
      50            2378 : void SpheroidItem :: SetValuesByEqRadiusAndInvFlattening(const char *spheroidname, double eq_radius, double inverseflattening)
      51                 : {
      52            2378 :     spheroid_name = CPLStrdup(spheroidname);
      53            2378 :     equitorial_radius=eq_radius;
      54            2378 :     polar_radius=eq_radius*(1.0 - (1.0/inverse_flattening));
      55            2378 :     inverse_flattening=inverseflattening;
      56            2378 : }
      57           13568 : SpheroidItem :: SpheroidItem()
      58                 : {
      59           13568 :   spheroid_name=NULL;
      60           13568 :   equitorial_radius=-1.0;
      61           13568 :   polar_radius=-1.0;
      62           13568 :   inverse_flattening=-1.0;
      63           13568 : }
      64                 : 
      65           13568 : SpheroidItem :: ~SpheroidItem()
      66                 : {
      67           13568 :   if (spheroid_name != NULL)
      68            2594 :       CPLFree(spheroid_name);
      69           13568 : }
      70                 : 
      71              53 : SpheroidList :: SpheroidList()
      72                 : {
      73              53 :   num_spheroids=0;
      74              53 : }
      75                 : 
      76              53 : SpheroidList :: ~SpheroidList()
      77                 : {
      78              53 : }
      79                 : 
      80               0 : char *SpheroidList :: GetSpheroidNameByRadii( double eq_radius, double polar_radius )
      81                 : {
      82               0 :   int index=0;
      83               0 :   double er=0.0;
      84               0 :   double pr=0.0;
      85                 : 
      86               0 :   for(index=0;index<num_spheroids;index++)
      87                 :   {
      88               0 :     er = spheroids[index].equitorial_radius;
      89               0 :     pr = spheroids[index].polar_radius;
      90               0 :     if ((fabs(er - eq_radius) < epsilonR) && (fabs(pr - polar_radius) < epsilonR))
      91               0 :       return CPLStrdup(spheroids[index].spheroid_name);
      92                 :   }
      93                 :   
      94               0 :   return NULL;
      95                 : 
      96                 : }
      97                 : 
      98              34 : char *SpheroidList :: GetSpheroidNameByEqRadiusAndInvFlattening( double eq_radius, double inverse_flattening )
      99                 : {
     100              34 :   int index=0;
     101              34 :   double er=0.0;
     102              34 :   double invf=0.0;
     103                 : 
     104             871 :   for(index=0;index<num_spheroids;index++)
     105                 :   {
     106             862 :     er = spheroids[index].equitorial_radius;
     107             862 :     invf = spheroids[index].inverse_flattening;
     108             862 :     if ((fabs(er - eq_radius) < epsilonR) && (fabs(invf - inverse_flattening) < epsilonI))
     109              25 :       return CPLStrdup(spheroids[index].spheroid_name);
     110                 :   }
     111                 :   
     112               9 :   return NULL;
     113                 : 
     114                 : }
     115                 : 
     116              20 : double SpheroidList :: GetSpheroidEqRadius( const char *spheroid_name )
     117                 : {
     118              20 :   int index=0;
     119                 : 
     120             453 :   for(index=0;index<num_spheroids;index++)
     121                 :   {
     122             453 :     if EQUAL(spheroids[index].spheroid_name,spheroid_name)
     123              20 :       return spheroids[index].equitorial_radius;
     124                 :   }
     125                 :   
     126               0 :   return -1.0;
     127                 : 
     128                 : }
     129                 : 
     130              18 : int SpheroidList :: SpheroidInList( const char *spheroid_name )
     131                 : {
     132                 :   /* Return 1 if the spheroid name is recognized; 0 otherwise */
     133              18 :   int index=0;
     134                 : 
     135             440 :   for(index=0;index<num_spheroids;index++)
     136                 :   {
     137             440 :     if EQUAL(spheroids[index].spheroid_name,spheroid_name) 
     138              18 :       return 1;
     139                 :   }
     140                 :   
     141               0 :   return 0;
     142                 : }
     143                 : 
     144              20 : double SpheroidList :: GetSpheroidInverseFlattening( const char *spheroid_name )
     145                 : {
     146              20 :   int index=0;
     147                 : 
     148             453 :   for(index=0;index<num_spheroids;index++)
     149                 :   {
     150             453 :     if  EQUAL(spheroids[index].spheroid_name,spheroid_name)
     151              20 :       return spheroids[index].inverse_flattening;
     152                 :   }
     153                 :   
     154               0 :   return -1.0;
     155                 : 
     156                 : }
     157                 : 
     158               0 : double SpheroidList :: GetSpheroidPolarRadius( const char *spheroid_name )
     159                 : {
     160               0 :   int index=0;
     161                 : 
     162               0 :   for(index=0;index<num_spheroids;index++)
     163                 :   {
     164               0 :     if (strcmp(spheroids[index].spheroid_name,spheroid_name) == 0)
     165               0 :       return spheroids[index].polar_radius;
     166                 :   }
     167                 :   
     168               0 :   return -1.0;
     169                 : 
     170                 : }
     171                 : 

Generated by: LTP GCOV extension version 1.5