!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODULE CONSTANTS USE Rcm_mod_subs, ONLY : rprec,iprec,isize,jsize,jwrap REAL(rprec),PARAMETER :: radius_earth_m = 6380.e3 ! Earth's radius in meters REAL(rprec),PARAMETER :: radius_iono_m = 6380.e3 + 100.e3 + 20.e3 ! ionosphere radius in meters REAL(rprec),PARAMETER :: boltz = 1.38E-23 REAl(rprec),PARAMETER :: mass_proton=1.6726e-27 REAL(rprec),PARAMETER :: mass_electron=9.1094e-31 REAL(rprec),PARAMETER :: ev=1.6022e-19 REAL(rprec),PARAMETER :: gamma=1.6667 REAL(rprec),PARAMETER :: one_over_gamma=0.6 REAL(rprec),PARAMETER :: mu0 = 4.0e-7*3.14159 END MODULE CONSTANTS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODULE rice_housekeeping_module USE Rcm_mod_subs, ONLY : rprec,iprec IMPLICIT NONE LOGICAL :: L_write_rcmu = .false., & L_write_rcmu2 = .false., & L_write_tracing_debug = .false., & L_write_vars_debug = .false., & L_write_int_grid_debug= .true. INTEGER :: Idt_overwrite = 1 CHARACTER (LEN=256) :: xjd_filename="LFM-MIX-RCM.xjd" CHARACTER (LEN=256) :: intermediateGrid_filename="RCM-rect.dat" CONTAINS SUBROUTINE Read_rcm_lfm_params IMPLICIT NONE INTEGER, PARAMETER :: Lun = 10 LOGICAL :: L_flag INQUIRE (FILE='rcm_lfm.param',EXIST=L_flag) IF (.NOT.L_flag) THEN WRITE (*,*) ' RCM_LFM: no rcm_lfm.param file found, default values will be used' ELSE OPEN (LUN, FILE='rcm_lfm.param', STATUS='OLD') READ (lun,*) L_write_rcmu2 READ (LUN,*) L_write_rcmu READ (LUN,*) L_write_tracing_debug READ (LUN,*) L_write_vars_debug READ (LUN,*) L_write_int_grid_debug READ (LUN,*) Idt_overwrite READ (LUN,*) xjd_filename READ (LUN,*) intermediateGrid_filename END IF WRITE (*,*) WRITE (*,'(A,L7)') ' RCM_LFM: rcmu2.dat file (in TORCM) will be written?_____', L_write_rcmu2 WRITE (*,'(A,L7)') ' RCM_LFM: rcmu.dat file (in TOMHD) will be written?_____', L_write_rcmu WRITE (*,'(A,L7)') ' RCM_LFM: debug tracing files (in TORCM) will be written?_____', L_write_tracing_debug WRITE (*,'(A,L7)') ' RCM_LFM: debug vars print to stdout (in TORCM,TOMHD) ?_____', L_write_vars_debug WRITE (*,'(A,L7)') ' RCM_LFM: intermediate grid file output (in TORCM) ?_____', L_write_int_grid_debug WRITE (*,'(A,I5)') ' RCM_LFM: Internal RCM time step (in s) will be set to ?_____', Idt_overwrite WRITE (*,'(A,A)') ' RCM_LFM: XML Job Description (XJD) file is ___________________', xjd_filename WRITE (*,'(A,A)') ' RCM_LFM: Intermeidate Grid is defined in file ________________', intermediateGrid_filename WRITE (*,*) RETURN END SUBROUTINE Read_rcm_lfm_params END MODULE rice_housekeeping_module !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Variables on the LFM grid MODUlE lfm_transfergrid USE Rcm_mod_subs, ONLY : iprec,rprec implicit none SAVE INTEGER(iprec) :: ni_mid,nj_mid,nk_mid !> Number of cells in LFM grid. REAL(rprec),ALLOCATABLE :: XMID_lfm(:,:,:) REAL(rprec),ALLOCATABLE :: YMID_lfm(:,:,:) REAL(rprec),ALLOCATABLE :: ZMID_lfm(:,:,:) REAL(rprec),ALLOCATABLE :: bleed_RHO_lfm(:,:,:) !> Density on LFM grid REAL(rprec),ALLOCATABLE :: bleed_PRESSURE_lfm(:,:,:) !> Pressure on LFM grid INTEGER(iprec),ALLOCATABLE :: bleed_MASK_lfm(:,:,:) !> Mask on LFM grid: 0=not part of RCM; 1=part of RCM INTEGER(iprec),ALLOCATABLE :: bleed_MASK_lfm_temp(:,:,:) !> Temporary Mask on LFM grid: 0=not part of RCM; 1=part of RCM contains !> Set the LFM grid dimensions (number of cells) and allocate RCM !! bleed variables (pressure, density and mask). !! Don't forget to deallocate! SUBROUTINE setupLFMGrid(ni,nj,nk) implicit none integer, intent(in), optional :: ni,nj,nk if (present(ni)) ni_mid = ni if (present(nj)) nj_mid = nj if (present(nk)) nk_mid = nk ALLOCATE (XMID_lfm (ni_mid, nj_mid, nk_mid)) ALLOCATE (YMID_lfm (ni_mid, nj_mid, nk_mid)) ALLOCATE (ZMID_lfm (ni_mid, nj_mid, nk_mid)) ALLOCATE (bleed_RHO_lfm (ni_mid, nj_mid, nk_mid)) ALLOCATE (bleed_PRESSURE_lfm (ni_mid, nj_mid, nk_mid)) ALLOCATE (bleed_MASK_lfm (ni_mid, nj_mid, nk_mid)) ALLOCATE (bleed_MASK_lfm_temp (ni_mid, nj_mid, nk_mid)) END SUBROUTINE setupLFMGrid !> Deallocate any variables allocated in setupLFMGrid. SUBROUTINE tearDownLFMGrid if (ALLOCATED(xmid_lfm)) DEALLOCATE (xmid_lfm) if (ALLOCATED(ymid_lfm)) DEALLOCATE (ymid_lfm) if (ALLOCATED(zmid_lfm)) DEALLOCATE (zmid_lfm) if (ALLOCATED(bleed_RHO_lfm)) DEALLOCATE (bleed_RHO_lfm) if (ALLOCATED(bleed_PRESSURE_lfm)) DEALLOCATE (bleed_PRESSURE_lfm) if (ALLOCATED(bleed_MASK_lfm)) DEALLOCATE (bleed_MASK_lfm) END SUBROUTINE tearDownLFMGrid END MODULE lfm_transfergrid !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Intermediate Grid definition & helper functions MODULE intermediate_grid USE Rcm_mod_subs, ONLY : rprec,iprec IMPLICIT NONE INTEGER(iprec), SAVE :: idim_ig=-1,jdim_ig=-1,kdim_ig=-1 REAL(rprec), ALLOCATABLE, SAVE :: x_ig(:), y_ig(:), z_ig(:), & press_ig(:,:,:), rho_ig(:,:,:), & bx_ig(:,:,:), by_ig(:,:,:), bz_ig(:,:,:), & vel_ig(:,:,:) INTEGER(iprec), ALLOCATABLE, SAVE :: imask_ig (:,:,:) REAL(rprec) :: xmin_ig,xmax_ig,ymin_ig,ymax_ig,zmax_ig,zmin_ig contains !> Allocate Intermediate Grid (IG) variables and read IG from file !! Don't forget to deallocate! SUBROUTINE setupIg use CONSTANTS, only : radius_earth_m use rice_housekeeping_module, only : intermediateGrid_filename IMPLICIT NONE INTEGER :: i,j,k, iDummy open(unit=74, file=intermediateGrid_filename, STATUS="OLD") read(74,*) idim_ig,jdim_ig,kdim_ig ALLOCATE ( x_ig(idim_ig) ) ALLOCATE ( y_ig(jdim_ig) ) ALLOCATE ( z_ig(kdim_ig) ) ALLOCATE ( press_ig (idim_ig, jdim_ig, kdim_ig) ) ALLOCATE ( rho_ig (idim_ig, jdim_ig, kdim_ig) ) ALLOCATE ( bx_ig (idim_ig, jdim_ig, kdim_ig) ) ALLOCATE ( by_ig (idim_ig, jdim_ig, kdim_ig) ) ALLOCATE ( bz_ig (idim_ig, jdim_ig, kdim_ig) ) ALLOCATE ( vel_ig (idim_ig, jdim_ig, kdim_ig) ) ALLOCATE ( imask_ig (idim_ig, jdim_ig, kdim_ig) ) read(74,*) idim_ig do i=1,idim_ig read(74,*) iDummy, x_ig(i) end do read(74,*) jdim_ig do j=1,jdim_ig read(74,*) iDummy, y_ig(j) end do read(74,*) kdim_ig do k=1,kdim_ig read(74,*) iDummy, z_ig(k) end do ! Intermediate Grid is stored in Earth Radii "RCM-rect.dat". close(unit=74) END SUBROUTINE setupIg !> Deallocate any varaibles allocated by setup. SUBROUTINE tearDownIg IF (ALLOCATED(x_ig)) DEALLOCATE (x_ig) IF (ALLOCATED(y_ig)) DEALLOCATE (y_ig) IF (ALLOCATED(z_ig)) DEALLOCATE (z_ig) IF (ALLOCATED(press_ig)) DEALLOCATE (press_ig) IF (ALLOCATED(rho_ig)) DEALLOCATE (rho_ig) IF (ALLOCATED(bx_ig)) DEALLOCATE (bx_ig) IF (ALLOCATED(by_ig)) DEALLOCATE (by_ig) IF (ALLOCATED(bz_ig)) DEALLOCATE (bz_ig) IF (ALLOCATED(vel_ig)) DEALLOCATE (vel_ig) IF (ALLOCATED(imask_ig)) DEALLOCATE (imask_ig) END SUBROUTINE tearDownIg END MODULE intermediate_grid !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> RCM Ionosphere grid definition, coupled model variables and helper !! functions. MODULE ionosphere_intermediate USE Rcm_mod_subs, ONLY : iprec,rprec, isize, jsize, jwrap, pi, colat, aloct implicit none integer(iprec) :: nLat_ion integer(iprec) :: nLon_ion real(rprec),allocatable :: gcolat(:) !> RCM Latitude grid points real(rprec),allocatable :: glong(:) !> RCM Longitude grid points real(rprec),allocatable :: pot(:,:) !> Potential; received from LFM MHD real(rprec),allocatable :: eng_avg(:,:) !> Average Energy (sent to MIX Coupler/Solver) real(rprec),allocatable :: flux(:,:) !> Energy Flux (sent to MIX Coupler/Solver) real(rprec),allocatable :: fac(:,:) !> Total FAC density (sent to MIX Coupler/Solver) real(rprec),allocatable :: sigmap(:,:) real(rprec),allocatable :: sigmah(:,:) contains !> Allocate Ionosphere Grid variables and read Ion grid from "RCM-ion.dat". !! Don't forget to deallocate! SUBROUTINE setupIon IMPLICIT NONE integer :: lat,lon nLat_ion = isize nLon_ion = jsize-jwrap+1 ALLOCATE( gcolat(nLat_ion) ) ALLOCATE( glong(nLon_ion) ) ALLOCATE( pot(nLat_ion, nLon_ion) ) ALLOCATE( eng_avg(nLat_ion, nLon_ion) ) ALLOCATE( flux(nLat_ion, nLon_ion) ) ALLOCATE( fac(nLat_ion, nLon_ion) ) ALLOCATE( sigmap(nLat_ion, nLon_ion) ) ALLOCATE( sigmah(nLat_ion, nLon_ion) ) gcolat (:) = colat (:,1) glong (:) = aloct (1,jwrap:jsize) if (glong(nLon_ion) < pi) glong(nLon_ion) = glong(nLon_ion) + 2*pi END SUBROUTINE setupIon !> Deallocate any variables allocated by setupIon. SUBROUTINE tearDownIon if (ALLOCATED(pot)) DEALLOCATE(pot) if (ALLOCATED(sigmap)) DEALLOCATE(sigmap) if (ALLOCATED(sigmah)) DEALLOCATE(sigmah) if (ALLOCATED(gcolat)) DEALLOCATE(gcolat) if (ALLOCATED(glong)) DEALLOCATE(glong) END SUBROUTINE tearDownIon END MODULE ionosphere_intermediate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODULE conversion_module USE Rcm_mod_subs, ONLY : rprec,iprec IMPLICIT NONE INTEGER(iprec) :: idim,jdim,kdim REAL(rprec), ALLOCATABLE :: bndloc_old(:),almmin(:),almmax(:),almdel(:),& eta_midnight(:) REAL(rprec), ALLOCATABLE :: x0(:,:),y0(:,:),z0(:,:),dir0(:,:) REAL(rprec), ALLOCATABLE :: te(:,:),ti(:,:),to(:,:),& eetabnd(:,:),& den(:,:),press(:,:),& deno(:,:),presso(:,:),& beta_average(:,:) REAL(rprec), ALLOCATABLE :: eeta_new(:,:,:) INTEGER(iprec), ALLOCATABLE :: open(:,:),imin_j_old(:),inner_bndy(:) END MODULE conversion_module !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODULE dipole_params USE Rcm_mod_subs, ONLY : rprec,iprec IMPLICIT NONE REAL(rprec) :: dm !> Dipole Moment REAL(rprec) :: tilt END MODULE dipole_params !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODULE tracer_params USE Rcm_mod_subs, ONLY : rprec,iprec IMPLICIT NONE REAL(rprec), PARAMETER :: er1=0.005,er2=0.001 END MODULE tracer_params !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!