
MODULE globchem_gcdata

    IMPLICIT NONE

    ! KPP DP - Double precision kind
    INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14,300)

    INTEGER :: GC_NTT
    REAL(kind=dp) :: GC_DT
    REAL(kind=dp), ALLOCATABLE :: GC_VAR(:,:), GC_FIX(:,:)
    REAL(kind=dp), ALLOCATABLE :: GC_RCONST(:,:)

  CONTAINS

    SUBROUTINE load_gc_data()
      USE globchem_parameters
      USE globchem_driver_parameters
      IMPLICIT NONE

      INTEGER :: i, j, ii

      ! Read canned GEOS-Chem data
      open(UNIT=796,FILE="rconst.dat")
      open(UNIT=797,FILE="conc.dat")

      read(797,*) GC_NTT
      read(797,*) GC_DT

      ! DEBUG
      !GC_NTT = 24

      write (*,*) "Tropospheric cells: ",GC_NTT
      write (*,*) "Integration timespan: ",GC_DT

      allocate(GC_VAR(NVAR,GC_NTT))
      allocate(GC_FIX(NFIX,GC_NTT))
      allocate(GC_RCONST(NREACT,GC_NTT))

      write (*,*) "Loading concentration data...",GC_NTT
      do i=1,GC_NTT
        read(797,*) GC_VAR(1:NVAR,i)
        read(797,*) GC_FIX(1:NFIX,i)
      end do

      write (*,*) "Loading reaction rates..."
      do i=1,GC_NTT/24
        ii = (i-1)*24 + 1
        read(796,*) GC_RCONST(1:NREACT,ii)
        do j=1,23
          GC_RCONST(1:NREACT,ii+j) = GC_RCONST(1:NREACT,ii)
        end do
      end do

      close (796)
      close (797)

      RETURN
    END SUBROUTINE load_gc_data

END MODULE globchem_gcdata


!------------------------- END globchem_main.f90 END -------------------------
