!copyright (C) 2001  MSC-RPN COMM  %%%RPNPHY%%%
***s/p litblrad2
*

      subroutine litblrad2 (varenv,sousrep,fichier,prout,rdradf_d) 1,1
*
#include "impnone.cdk"
#include "phy_macros_f.h"
      external rdradf_d
      logical prout
      character *(*) varenv, fichier,sousrep
*
*
*
*
*Author
*          B. Bilodeau (april 1994) - from lirg123
*
*Revision
*
* 001      B. Dugas (Aug 97) - Redefine IUNIT for FORTRAN file
* 002      M. Desgagne (Oct 98) - call back to rdradf_d (from dynamics)
* 003      B. Bilodeau (Jan 01) - remove call to ozpak
* 004      B. Bilodeau (May 03) - IBM conversion
*              - invert dimension of some radiation tables in order to
*                reduce the cache flooding in radir6 
*
*Object
*          to read the radiation table from file (either unformatted
*          fortran binary file or RPN standard file) for infra-red
*          radiation calculation
*
*Arguments
*
*          - input -
* varenv   environment variable giving the data file path
* sousrep  sub-directory where the file is located
* fichier  name of the radiation table file
* prout    logical switch to print on stdout
* rdradf_d call back routine from the dynamics to manage the file
*           
*
**
*
#include "radpnt.cdk"
*
#include "consphy.cdk"
*
#include "radparam.cdk"
*
#include "ozopnt.cdk"
*
#include "raddata.cdk"
*
************************************************************************
*     AUTOMATIC ARRAYS
************************************************************************
*
      AUTOMATIC (  BCNINV  , REAL , (NTT, NCO2     ) )
      AUTOMATIC (  DBCNINV , REAL , (NTT, NCO2     ) )
      AUTOMATIC (  TH2OINV , REAL , (MXX, NCO2     ) )
      AUTOMATIC (  YG3INV  , REAL , (MXX, NCX, NCO2) )
*
************************************************************************
*
      character chemin*512
      integer i,j,k,ij,indice,long
*
*     calcul des pointeurs qui decoupent le champ g
      call pntg123
*
      chemin = ' '
      call getenvc (varenv,chemin)
      if (chemin.ne.' ') then
         indice = index(chemin,' ')
         long   = len(sousrep)
         chemin(indice:indice+long-1) = sousrep
      endif
*
      call rdradf_d (fichier, chemin, g, ntotal, .false.)
*
*     inverser les dimensions de bcn, dbcn, th2o et yg3 pour 
*     optimiser l'utilisation de la cache
*
      do j=1,ntt
         do i=1,nco2
            ij = (j-1)*nco2 + i - 1
            bcninv (j,i) = g(bcn +ij)
            dbcninv(j,i) = g(dbcn+ij)
         end do
      end do
*
      do j=1,mxx
         do i=1,nco2
            ij = (j-1)*nco2 + i - 1
            th2oinv(j,i) = g(th2o+ij)
         end do
      end do
*
      do k=1,ncx
         do j=1,mxx
            do i=1,nco2
               ij = (k-1)*mxx*nco2 + (j-1)*nco2 + i - 1
               yg3inv(j,k,i) = g(yg3+ij)
            end do
         end do
      end do
*
      do i=1,ntt*nco2
         g(bcn +i-1) = bcninv (i,1)
         g(dbcn+i-1) = dbcninv(i,1)
      end do
*
      do i=1,mxx*nco2
         g(th2o+i-1) = th2oinv(i,1)
      end do
*
      do i=1,mxx*ncx*nco2
         g(yg3+i-1) = yg3inv(i,1,1)
      end do
*
      return
      end