      program main
      implicit none
      include 'max.inc'
      include 'formats.inc'
c     
c     Purpose: to read raw data files contained in the "data" folder, for standard atmospheres,
c     and produce "atm" and "ck" files in the "std_kdist" folder, that are needed by the
c     "PPart" code.
c     
c     Variables
      integer pidx
      integer Nlay,Nb,Nq
      double precision z(0:Nlay_mx)
      double precision pres(0:Nlay_mx)
      double precision temp(0:Nlay_mx)
      double precision x_h2o(0:Nlay_mx)
      double precision T(0:Nlay_mx+1)
      double precision lambda_lo(1:Nb_mx)
      double precision lambda_hi(1:Nb_mx)
      double precision w_quad(1:Nq_mx)
      double precision ck(1:Nlay_mx,1:Nb_mx,1:Nq_mx)
c     temp
      integer i,band,quad
      character*1 pidx_str1
      character*(Nchar_mx) atm_file,ck_file
c     label
      integer strlen
      character*(Nchar_mx) label
      label='program main'

      do pidx=1,5
         call read_std_profile(pidx,
     &        Nlay,Nb,Nq,
     &        lambda_lo,lambda_hi,w_quad,
     &        z,pres,temp,x_h2o,T,ck)

         call num2str1(pidx,pidx_str1)
         atm_file='./std_kdist/'
     &        //'std_atm_i'
     &        //pidx_str1(1:strlen(pidx_str1))
     &        //'.txt'
         open(11,file=atm_file(1:strlen(atm_file)))
         write(11,*) Nlay+1
         do i=0,Nlay
            write(11,48) z(i),pres(i),temp(i),x_h2o(i),T(i)
         enddo                  ! i
         close(11)

         ck_file='./std_kdist/'
     &        //'std_ck_i'
     &        //pidx_str1(1:strlen(pidx_str1))
     &        //'.txt'
         open(12,file=ck_file(1:strlen(ck_file)))
         write(12,*) Nlay
         write(12,*) Nb
         do band=1,Nb
            write(12,*) Nq
            write(12,*) lambda_lo(band),lambda_hi(band),1.0D+0
            write(12,48) (w_quad(quad),quad=1,Nq)
            do quad=1,Nq
               write(12,48) (ck(i,band,quad),i=1,Nlay)
            enddo               ! quad
         enddo                  ! band
         close(12)
      enddo                     ! pidx
      
      end
