!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
**s/r cartall - Computes the F_lon,F_lat positions for a rotated system
*

      subroutine cartall( F_lon,F_lat,F_xyz_8,n) 3
#include "impnone.cdk"
      integer n
      real*8 F_xyz_8(3,*)
      real F_lon(*),F_lat(*)
*
*author
*     unknown
*
*revision
* v2_00 - Lee V.            - initial MPI version (from cartall v1_03)
* v2_30 - Dugas B.          - input real*8 cartesian coordinates
*
*object
*     see above ID
*     
*arguments
*  Name        I/O                 Description
*----------------------------------------------------------------
* F_lon        O   F_longitude positions for a rotated coordinate system
* F_lat        O   F_latitude  positions for a rotated coordinate system
* F_xyz_8      I   rotation matrix
*
**
      integer i
      real*8, parameter :: ONE = 1.0d0, PI = 180.0d0
      real*8 rad_8
*
*     ---------------------------------------------------------------
*
      rad_8 = PI/acos(-ONE)
      do i=1,n
         F_lat(i) = asin(max(-1.d0,min(1.d0,F_xyz_8(3,i)))) * rad_8
         F_lon(i) = atan2( F_xyz_8(2,i),F_xyz_8(1,i) ) * rad_8
         F_lon(i) = amod( F_lon(i) , 360.0 )
         if (F_lon(i).lt.0.0) F_lon(i) = F_lon(i)+360.0
      enddo
*
*     ---------------------------------------------------------------
*
      return
      end