INTEGER FUNCTION NV2INItanc                                               
     +(option,param)                                                            
                                                                                
                                                                                
      implicit		NONE                                                            
                                                                                
                                                                                
                                                                                
      integer		option		! initialization option                                  
      integer		param(*)	! navigation parameters or                              
                                                                                
                                                                                
      character*4	navtyp		! codicil type                                        
      character*4	outcoord	! output coordinate type                             
      character*80	cbuf		! text output buffer                                   
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      real		Lin0		! image line of pole                                          
      real		Ele0		! image element of pole                                       
      real		Scale		! km per unit image coordinate                               
      real		Lon0		! standard longitude                                          
      real		Lat0		! standard latitude                                           
      real		Colat0		! standard colatitude                                       
                                                                                
                                                                                
      real		Coscl		! cosine(Colat0)                                             
      real		Tancl		! tangent(Colat0)                                            
      real		Tancl2		! tangent(Colat0/2)                                         
      real		Mxtheta		! limit of angle from std. lon                             
                                                                                
                                                                                
      real		D2R		! degrees to radians factor                                    
      real		Pi                                                                  
      real		Badreal		! returned when navigation                                 
      real		Erad		! Earth radius                                                
      logical		Init		! initialized flag                                         
      logical		Latlon		! .TRUE. for lat/lon I/O                                 
                                                                                
                                                                                
      COMMON/TANCtancnv2/                                                       
     + Lin0, Ele0, Scale, Lon0, Colat0, Lat0,                                   
     &  Coscl, Tancl, Tancl2, Mxtheta,                                          
     &  D2R, Pi, Badreal, Erad, Init, Latlon                                    
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      Erad = 6371.2 		! This value of Erad is ok                                
      Pi	= acos(-1.)                                                            
      D2R	= Pi / 180.                                                           
                                                                                
      Badreal	= -1.E10		! obvious unreasonable value                            
                                                                                
                                                                                
      if( option.eq.1 ) then                                                    
                                                                                
         call DDEST('nvxini(tanc) option=1',0)                                  
                                                                                
         call movwc(param(1),navtyp)                                            
         if( navtyp.eq.'TANC') then                                             
                                                                                
                                                                                
            Lin0	= param(2) / 10000.                                            
            Ele0	= param(3) / 10000.                                            
            Scale	= param(4) / 10000.                                           
            Lat0	= param(5) / 10000.                                            
            Lon0	= param(6) / 10000.                                            
                                                                                
            write(cbuf,'('' nvxini: Lat0, Lon0 '',2F12.4)')                     
     *        Lat0, Lon0                                                        
            call DDEST(cbuf,0)                                                  
                                                                                
                                                                                
            if(Scale.le.0. ) then                                               
               call DDEST('nvxini(tanc) scale is negative',0)                   
               Init	= .FALSE.                                                   
               NV2INItanc                                                       
     +	= -3                                                                     
               return                                                           
            end if                                                              
                                                                                
            if(Lat0.le.-90. .or. Lat0.ge.90. ) then                             
               call DDEST('nvxini(tanc) standard lat out of range',0)           
               Init	= .FALSE.                                                   
               NV2INItanc                                                       
     +	= -3                                                                     
               return                                                           
            end if                                                              
                                                                                
            if(Lat0 .eq. 0.)then                                                
               call DDEST('nvxini(tanc) standard lat equal to 0'//              
     &                    ' not allowed',0)                                     
               Init	= .FALSE.                                                   
               NV2INItanc                                                       
     +	= -3                                                                     
               return                                                           
            end if                                                              
                                                                                
            if(Lon0.le.-180. .or. Lon0.gt.180. ) then                           
               call DDEST('nvxini(tanc) standard lon out of range',0)           
               Init	= .FALSE.                                                   
               NV2INItanc                                                       
     +	= -3                                                                     
               return                                                           
            end if                                                              
                                                                                
                                                                                
            Lon0	= -Lon0 * D2R                                                  
                                                                                
                                                                                
            if(Lat0 .lt. 0)then                                                 
              Colat0      =  Pi/2.  + D2R*Lat0                                  
            else                                                                
              Colat0      =  Pi/2.  - D2R*Lat0                                  
            endif                                                               
                                                                                
            write(cbuf,'('' nvxini:  Colat0, Lon_0 '',2F12.4)')                 
     *        Colat0, Lon0                                                      
            call DDEST(cbuf,0)                                                  
                                                                                
                                                                                
            Coscl	= cos(Colat0)                                                 
	    Tancl	= tan(Colat0)                                                        
	    Tancl2	= tan(Colat0/2.)                                                    
	    Mxtheta	= Pi*Coscl                                                         
                                                                                
            write(cbuf,'('' nvxini: Coscl,   Tancl'', 2F7.4)')                  
     *        Coscl, Tancl                                                      
            call DDEST(cbuf,0)                                                  
                                                                                
            write(cbuf,'('' nvxini: Tancl2, Mxtheta '', 2F7.4)')                
     *        tancl2, Mxtheta                                                   
            call DDEST(cbuf,0)                                                  
                                                                                
	    Latlon	= .TRUE.                                                            
                                                                                
                                                                                
         else		! option=1 but type not 'TANC'                                   
                                                                                
            call DDEST('nvxini(tanc) parameter type bad',0)                     
            Init	= .FALSE.                                                      
            NV2INItanc                                                          
     +	= -4                                                                     
	    return                                                                     
                                                                                
         end if                                                                 
                                                                                
      else if ( option .eq. 2) then                                             
                                                                                
         call movwc(param(1),outcoord)                                          
	 if( outcoord.eq.'LL' ) then                                                   
	     Latlon = .TRUE.                                                           
	 else if( outcoord.eq.'XYZ') then                                              
	     Latlon = .FALSE.                                                          
         else                                                                   
             call DDEST('option=2 coord '//outcoord//' not supported',0)        
             Init   = .FALSE.                                                   
             NV2INItanc                                                         
     + = -5                                                                     
         end if                                                                 
                                                                                
      else		! option not 1 or 2                                                 
                                                                                
         call DDEST('nvxini(tanc) unrecognized output option ',option)          
         NV2INItanc                                                             
     + =  -4                                                                    
         return                                                                 
                                                                                
      end if                                                                    
                                                                                
      NV2INItanc                                                                
     +	= 0                                                                      
      Init	= .TRUE.                                                             
                                                                                
      return                                                                    
      end                                                                       
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      INTEGER FUNCTION NV2SAEtanc                                               
     +( lin, ele, dummy, e1, e2, e3 )                                           
                                                                                
      implicit		NONE                                                            
                                                                                
                                                                                
      real		lin	! image line to navigate                                        
      real		ele	! image element to navigate                                     
      real             d_lin    ! lin difference                                
      real             d_ele    ! ele difference                                
      real		dummy	! (unused argument)                                           
      real		e1	! Earth coordinate 1                                             
      real		e2	! Earth coordinate 2                                             
      real		e3	! Earth coordinate 3                                             
                                                                                
                                                                                
      real		lat	! latitude  (McIDAS convention)                                 
      real		lon	! longitude (McIDAS convention)                                 
      real		hgt	! height                                                        
      real		dx	! zonal displacement from pole                                   
      real		dy	! meridional displacement from pole                              
      real		radius	! distance from pole on projection                           
      real		theta	! angle from standard longitude on                            
      real           theta_rh	! right handed angle measure                      
      real		colat	! colatitude of navigated point                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      real		Lin0		! image line of pole                                          
      real		Ele0		! image element of pole                                       
      real		Scale		! km per unit image coordinate                               
      real		Lon0		! standard longitude                                          
      real		Colat0		! standard colatitude                                       
      real		Lat0		! standard latitude                                           
                                                                                
                                                                                
      real		Coscl		! cosine(Colat0)                                             
      real		Tancl		! tangent(Colat0)                                            
      real		Tancl2		! tangent(Colat0/2)                                         
      real		Mxtheta		! limit of angle from std. lon                             
                                                                                
                                                                                
      real		D2R		! degrees to radians factor                                    
      real		Pi                                                                  
      real		Badreal		! returned when navigation                                 
      real		Erad		! Earth radius                                                
      logical		Init		! initialized flag                                         
      logical		Latlon		! .TRUE. for lat/lon I/O                                 
                                                                                
                                                                                
      COMMON/TANCtancnv2/                                                       
     + Lin0, Ele0, Scale, Lon0, Colat0, Lat0,                                   
     &  Coscl, Tancl, Tancl2, Mxtheta,                                          
     &  D2R, Pi, Badreal, Erad, Init, Latlon                                    
                                                                                
                                                                                
      e1	= Badreal                                                              
      e2	= Badreal                                                              
      e3	= Badreal                                                              
                                                                                
                                                                                
                                                                                
      if(.not.Init) then                                                        
          NV2SAEtanc                                                            
     + = -6                                                                     
          return                                                                
      end if                                                                    
                                                                                
                                                                                
                                                                                
      d_lin     = lin-Lin0                                                      
      d_ele     = ele-Ele0                                                      
                                                                                
      if((abs(d_lin) .LT. 0.01).AND.(abs(d_ele) .LT. 0.01))then                 
         radius = 0.0                                                           
         theta_rh = 0.0                                                         
      else                                                                      
         dx	= Scale*(d_lin)                                                     
         dy	= Scale*(d_ele)                                                     
                                                                                
         radius	= sqrt(dx*dx+dy*dy)                                             
         theta_rh = atan2(dy,dx)                                                
      endif                                                                     
                                                                                
                                                                                
      if(Lat0 .lt. 0.)then                                                      
         if(theta_rh .le. 0.)then                                               
            theta  =  (Pi - abs(theta_rh))                                      
         else if(theta_rh .gt. 0)then                                           
            theta  = -1.*(Pi - abs(theta_rh))                                   
         endif                                                                  
      else                                                                      
            theta = theta_rh                                                    
      endif                                                                     
                                                                                
                                                                                
      if ( theta.le.-Mxtheta .or. theta.gt.Mxtheta ) then                       
         NV2SAEtanc                                                             
     + = -1                                                                     
         return                                                                 
      end if                                                                    
                                                                                
                                                                                
                                                                                
         lon = Lon0 + theta/Coscl                                               
                                                                                
         if(lon.le.-Pi) lon = lon + 2.d0*Pi                                     
         if(lon.gt. Pi) lon = lon - 2.d0*Pi                                     
                                                                                
         colat	= 2.*atan( Tancl2 * (radius/(Erad*Tancl))**(1./Coscl))           
                                                                                
                                                                                
      lon	= -lon/D2R                                                            
      lat	= 90. - colat/D2R                                                     
      hgt	= 0.                                                                  
                                                                                
                                                                                
      if(.not.Latlon) then                                                      
          if(Lat0 .lt. 0.)lat = -1.*lat                                         
          call nllxyz(lat,lon,e1,e2,e3)                                         
      else                                                                      
          if(Lat0 .lt. 0.)then                                                  
            e1 = -1.*lat                                                        
          else                                                                  
            e1 = lat                                                            
          endif                                                                 
          e2 = lon                                                              
	  e3 = 0.                                                                      
      end if                                                                    
                                                                                
      NV2SAEtanc                                                                
     +	= 0                                                                      
                                                                                
      return                                                                    
      end                                                                       
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      INTEGER FUNCTION NV2EAStanc                                               
     +( e1, e2, e3, lin, ele, dummy)                                            
                                                                                
      implicit		NONE                                                            
                                                                                
                                                                                
      real		e1	! Earth coordinate 1                                             
      real		e2	! Earth coordinate 2                                             
      real		e3	! Earth coordinate 3                                             
      real		lin	! image line to navigate                                        
      real		ele	! image element to navigate                                     
      real		dummy	! (unused argument)                                           
                                                                                
                                                                                
      real		lat	! latitude  (McIDAS convention)                                 
      real		lon	! longitude (McIDAS convention)                                 
      real		hgt	! height                                                        
      real		in_lon	! input longitude (radians,                                  
      real		colat	! colatitude                                                  
      real		radius	! distance from pole on projection                           
      real		theta	! angle from standard longitude on                            
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      real		Lin0		! image line of pole                                          
      real		Ele0		! image element of pole                                       
      real		Scale		! km per unit image coordinate                               
      real		Lon0		! standard longitude                                          
      real		Colat0		! standard colatitude                                       
      real		Lat0		! standard latitude                                           
                                                                                
                                                                                
      real		Coscl		! cosine(Colat0)                                             
      real		Tancl		! tangent(Colat0)                                            
      real		Tancl2		! tangent(Colat0/2)                                         
      real		Mxtheta		! limit of angle from std. lon                             
                                                                                
                                                                                
      real		D2R		! degrees to radians factor                                    
      real		Pi                                                                  
      real		Badreal		! returned when navigation                                 
      real		Erad		! Earth radius                                                
      logical		Init		! initialized flag                                         
      logical		Latlon		! .TRUE. for lat/lon I/O                                 
                                                                                
                                                                                
      COMMON/TANCtancnv2/                                                       
     + Lin0, Ele0, Scale, Lon0, Colat0, Lat0,                                   
     &  Coscl, Tancl, Tancl2, Mxtheta,                                          
     &  D2R, Pi, Badreal, Erad, Init, Latlon                                    
                                                                                
                                                                                
                                                                                
      lin	= Badreal                                                             
      ele	= Badreal                                                             
      dummy	= Badreal                                                           
                                                                                
                                                                                
      if(.not.init) then                                                        
          NV2EAStanc                                                            
     + = -6                                                                     
          return                                                                
      end if                                                                    
                                                                                
                                                                                
      if(Latlon) then                                                           
          lat = e1                                                              
          lon = e2                                                              
          hgt = e3                                                              
      else                                                                      
          call nxyzll( e1, e2, e3, lat, lon)                                    
	  hgt = 0.                                                                     
      end if                                                                    
                                                                                
                                                                                
      if ( lat.lt.-90. .or. lat.gt.90. ) then                                   
         NV2EAStanc                                                             
     +	= -2                                                                     
         return                                                                 
      end if                                                                    
                                                                                
      if( lon.le.-360..or.lon.gt.360.) then                                     
          NV2EAStanc                                                            
     + = -2                                                                     
          return                                                                
      end if                                                                    
                                                                                
      if( lat.eq.-90. .or. lat.eq.90. ) then                                    
          NV2EAStanc                                                            
     + = -1                                                                     
          return                                                                
      end if                                                                    
                                                                                
                                                                                
      if(Lat0 .lt. 0)then                                                       
           colat     = Pi/2. + D2R*lat                                          
      else                                                                      
           colat     = Pi/2. - D2R*lat                                          
      endif                                                                     
      in_lon	= -D2R*lon                                                         
                                                                                
                                                                                
      if(in_lon.le.-Pi) in_lon = in_lon + 2.*Pi                                 
      if(in_lon.gt. Pi) in_lon = in_lon - 2.*Pi                                 
                                                                                
                                                                                
                                                                                
      if ( colat.eq.Pi ) then                                                   
        NV2EAStanc                                                              
     +	= -1                                                                     
        return                                                                  
      end if                                                                    
                                                                                
                                                                                
                                                                                
      radius	= Erad * Tancl *( tan(colat/2.)/Tancl2 ) ** Coscl                  
      theta	= in_lon-Lon0                                                       
                                                                                
      if(theta.le.-Pi) theta = theta + 2.*Pi                                    
      if(theta.gt. Pi) theta = theta - 2.*Pi                                    
                                                                                
      theta     = Coscl * theta                                                 
                                                                                
                                                                                
                                                                                
      if(Lat0 .lt. 0.)then                                                      
         theta = Pi + theta                                                     
      endif                                                                     
                                                                                
         lin	= Lin0 + radius*cos(theta)/Scale                                   
         ele	= Ele0 + radius*sin(theta)/Scale                                   
                                                                                
      dummy	= 0.                                                                
                                                                                
      NV2EAStanc                                                                
     + 	= 0                                                                     
                                                                                
      return                                                                    
      end                                                                       
                                                                                
                                                                                
                                                                                
                                                                                
      INTEGER FUNCTION NV2OPTtanc                                               
     +( option, xin, xout)                                                      
                                                                                
      implicit		NONE                                                            
                                                                                
                                                                                
      integer		option	! special service name (character                         
      real		xin(*)	! input vector                                               
      real		xout(*) ! output vector                                             
                                                                                
                                                                                
      character*4	copt	! special service (character form)                       
      real		colat	! input colatitude                                            
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
      real		Lin0		! image line of pole                                          
      real		Ele0		! image element of pole                                       
      real		Scale		! km per unit image coordinate                               
      real		Lon0		! standard longitude                                          
      real		Colat0		! standard colatitude                                       
      real		Lat0		! standard latitude                                           
                                                                                
                                                                                
      real		Coscl		! cosine(Colat0)                                             
      real		Tancl		! tangent(Colat0)                                            
      real		Tancl2		! tangent(Colat0/2)                                         
      real		Mxtheta		! limit of angle from std. lon                             
                                                                                
                                                                                
      real		D2R		! degrees to radians factor                                    
      real		Pi                                                                  
      real		Badreal		! returned when navigation                                 
      real		Erad		! Earth radius                                                
      logical		Init		! initialized flag                                         
      logical		Latlon		! .TRUE. for lat/lon I/O                                 
                                                                                
                                                                                
      COMMON/TANCtancnv2/                                                       
     + Lin0, Ele0, Scale, Lon0, Colat0, Lat0,                                   
     &  Coscl, Tancl, Tancl2, Mxtheta,                                          
     &  D2R, Pi, Badreal, Erad, Init, Latlon                                    
                                                                                
                                                                                
                                                                                
      xout(1) 	= Badreal                                                        
                                                                                
                                                                                
      if(.not.init) then                                                        
          NV2OPTtanc                                                            
     + = -6                                                                     
          return                                                                
      end if                                                                    
                                                                                
                                                                                
      call movwc(option,copt)                                                   
                                                                                
      if(copt.eq.'SCAL') then                                                   
                                                                                
                                                                                
         if ( xin(1).gt.90. .or. xin(1).lt.-90. ) then                          
             NV2OPTtanc                                                         
     + = -2                                                                     
             return                                                             
	 else if ( xin(1).eq.90. .or. xin(1).eq.-90. ) then                            
	     NV2OPTtanc                                                                
     + = -1	                                                                    
	     return                                                                    
         end if                                                                 
                                                                                
                                                                                
         if(Lat0 .lt. 0.)then                                                   
            colat = Pi/2. + D2R*xin(1)                                          
         else                                                                   
            colat = Pi/2. - D2R*xin(1)                                          
         endif                                                                  
                                                                                
                                                                                
         xout(1) = scale                                                        
     *           *(sin(Colat0)*(tan(colat/2.)/Tancl2)**Coscl)/sin(colat)        
                                                                                
                                                                                
      else                                                                      
         NV2OPTtanc                                                             
     + = -5                                                                     
         return                                                                 
      end if                                                                    
                                                                                
      NV2OPTtanc                                                                
     + = 0                                                                      
                                                                                
      return                                                                    
      end