From 5c4b824e5d53b9e0d2d6c7931db0948cd151318f Mon Sep 17 00:00:00 2001 From: Jacob Williams Date: Sat, 10 Feb 2024 09:07:58 -0600 Subject: [PATCH] added ability to specify file dirs. moved files into data directories --- ae8max.asc => data/aep8/ae8max.asc | 0 ae8min.asc => data/aep8/ae8min.asc | 0 ap8max.asc => data/aep8/ap8max.asc | 0 ap8min.asc => data/aep8/ap8min.asc | 0 dgrf1945.dat => data/igrf/dgrf1945.dat | 0 dgrf1950.dat => data/igrf/dgrf1950.dat | 0 dgrf1955.dat => data/igrf/dgrf1955.dat | 0 dgrf1960.dat => data/igrf/dgrf1960.dat | 0 dgrf1965.dat => data/igrf/dgrf1965.dat | 0 dgrf1970.dat => data/igrf/dgrf1970.dat | 0 dgrf1975.dat => data/igrf/dgrf1975.dat | 0 dgrf1980.dat => data/igrf/dgrf1980.dat | 0 dgrf1985.dat => data/igrf/dgrf1985.dat | 0 dgrf1990.dat => data/igrf/dgrf1990.dat | 0 dgrf1995.dat => data/igrf/dgrf1995.dat | 0 dgrf2000.dat => data/igrf/dgrf2000.dat | 0 dgrf2005.dat => data/igrf/dgrf2005.dat | 0 dgrf2010.dat => data/igrf/dgrf2010.dat | 0 dgrf2015.dat => data/igrf/dgrf2015.dat | 0 igrf2020.dat => data/igrf/igrf2020.dat | 0 igrf2020s.dat => data/igrf/igrf2020s.dat | 0 src/core.f90 | 19 +++++++++++++ src/shellig.f90 | 35 +++++++++++++++++++++--- src/trmfun.f90 | 31 +++++++++++++++++++-- 24 files changed, 79 insertions(+), 6 deletions(-) rename ae8max.asc => data/aep8/ae8max.asc (100%) rename ae8min.asc => data/aep8/ae8min.asc (100%) rename ap8max.asc => data/aep8/ap8max.asc (100%) rename ap8min.asc => data/aep8/ap8min.asc (100%) rename dgrf1945.dat => data/igrf/dgrf1945.dat (100%) rename dgrf1950.dat => data/igrf/dgrf1950.dat (100%) rename dgrf1955.dat => data/igrf/dgrf1955.dat (100%) rename dgrf1960.dat => data/igrf/dgrf1960.dat (100%) rename dgrf1965.dat => data/igrf/dgrf1965.dat (100%) rename dgrf1970.dat => data/igrf/dgrf1970.dat (100%) rename dgrf1975.dat => data/igrf/dgrf1975.dat (100%) rename dgrf1980.dat => data/igrf/dgrf1980.dat (100%) rename dgrf1985.dat => data/igrf/dgrf1985.dat (100%) rename dgrf1990.dat => data/igrf/dgrf1990.dat (100%) rename dgrf1995.dat => data/igrf/dgrf1995.dat (100%) rename dgrf2000.dat => data/igrf/dgrf2000.dat (100%) rename dgrf2005.dat => data/igrf/dgrf2005.dat (100%) rename dgrf2010.dat => data/igrf/dgrf2010.dat (100%) rename dgrf2015.dat => data/igrf/dgrf2015.dat (100%) rename igrf2020.dat => data/igrf/igrf2020.dat (100%) rename igrf2020s.dat => data/igrf/igrf2020s.dat (100%) diff --git a/ae8max.asc b/data/aep8/ae8max.asc similarity index 100% rename from ae8max.asc rename to data/aep8/ae8max.asc diff --git a/ae8min.asc b/data/aep8/ae8min.asc similarity index 100% rename from ae8min.asc rename to data/aep8/ae8min.asc diff --git a/ap8max.asc b/data/aep8/ap8max.asc similarity index 100% rename from ap8max.asc rename to data/aep8/ap8max.asc diff --git a/ap8min.asc b/data/aep8/ap8min.asc similarity index 100% rename from ap8min.asc rename to data/aep8/ap8min.asc diff --git a/dgrf1945.dat b/data/igrf/dgrf1945.dat similarity index 100% rename from dgrf1945.dat rename to data/igrf/dgrf1945.dat diff --git a/dgrf1950.dat b/data/igrf/dgrf1950.dat similarity index 100% rename from dgrf1950.dat rename to data/igrf/dgrf1950.dat diff --git a/dgrf1955.dat b/data/igrf/dgrf1955.dat similarity index 100% rename from dgrf1955.dat rename to data/igrf/dgrf1955.dat diff --git a/dgrf1960.dat b/data/igrf/dgrf1960.dat similarity index 100% rename from dgrf1960.dat rename to data/igrf/dgrf1960.dat diff --git a/dgrf1965.dat b/data/igrf/dgrf1965.dat similarity index 100% rename from dgrf1965.dat rename to data/igrf/dgrf1965.dat diff --git a/dgrf1970.dat b/data/igrf/dgrf1970.dat similarity index 100% rename from dgrf1970.dat rename to data/igrf/dgrf1970.dat diff --git a/dgrf1975.dat b/data/igrf/dgrf1975.dat similarity index 100% rename from dgrf1975.dat rename to data/igrf/dgrf1975.dat diff --git a/dgrf1980.dat b/data/igrf/dgrf1980.dat similarity index 100% rename from dgrf1980.dat rename to data/igrf/dgrf1980.dat diff --git a/dgrf1985.dat b/data/igrf/dgrf1985.dat similarity index 100% rename from dgrf1985.dat rename to data/igrf/dgrf1985.dat diff --git a/dgrf1990.dat b/data/igrf/dgrf1990.dat similarity index 100% rename from dgrf1990.dat rename to data/igrf/dgrf1990.dat diff --git a/dgrf1995.dat b/data/igrf/dgrf1995.dat similarity index 100% rename from dgrf1995.dat rename to data/igrf/dgrf1995.dat diff --git a/dgrf2000.dat b/data/igrf/dgrf2000.dat similarity index 100% rename from dgrf2000.dat rename to data/igrf/dgrf2000.dat diff --git a/dgrf2005.dat b/data/igrf/dgrf2005.dat similarity index 100% rename from dgrf2005.dat rename to data/igrf/dgrf2005.dat diff --git a/dgrf2010.dat b/data/igrf/dgrf2010.dat similarity index 100% rename from dgrf2010.dat rename to data/igrf/dgrf2010.dat diff --git a/dgrf2015.dat b/data/igrf/dgrf2015.dat similarity index 100% rename from dgrf2015.dat rename to data/igrf/dgrf2015.dat diff --git a/igrf2020.dat b/data/igrf/igrf2020.dat similarity index 100% rename from igrf2020.dat rename to data/igrf/igrf2020.dat diff --git a/igrf2020s.dat b/data/igrf/igrf2020s.dat similarity index 100% rename from igrf2020s.dat rename to data/igrf/igrf2020s.dat diff --git a/src/core.f90 b/src/core.f90 index dde1e45..05ad9f7 100644 --- a/src/core.f90 +++ b/src/core.f90 @@ -22,12 +22,31 @@ module core contains private procedure,public :: get_flux => get_flux_ + procedure,public :: set_data_files_paths end type radbelt_type public :: get_flux !! simple function version for testing contains +!***************************************************************************************** +!> +! Set the paths to the data files. +! If not used or blank, the folder `data/aep8` and `data/igrf` in the +! current working directory is assumed + + subroutine set_data_files_paths(me, aep8_dir, igrf_dir) + + class(radbelt_type),intent(inout) :: me + character(len=*),intent(in) :: aep8_dir + character(len=*),intent(in) :: igrf_dir + + call me%trm%set_data_file_dir(trim(aep8_dir)) + call me%igrf%set_data_file_dir(trim(igrf_dir)) + + end subroutine set_data_files_paths +!***************************************************************************************** + !***************************************************************************************** !> ! Calculate the flux of trapped particles at a specific location and time. diff --git a/src/shellig.f90 b/src/shellig.f90 index f872753..9f988eb 100644 --- a/src/shellig.f90 +++ b/src/shellig.f90 @@ -40,6 +40,8 @@ module shellig_module type,public :: shellig_type private + character(len=:),allocatable :: igrf_dir !! directory containing the data files + ! formerly in the `fidb0` common block real(wp),dimension(3) :: sp = 0.0_wp @@ -49,7 +51,7 @@ module shellig_module ! formerly in `model` common block integer :: iyea = 0 !! the int year corresponding to the file `name` that has been read - character(len=filename_len) :: name = '' !! file name + character(len=:),allocatable :: name !! file name integer :: nmax = 0 !! maximum order of spherical harmonics real(wp) :: Time = 0.0_wp !! year (decimal: 1973.5) for which magnetic field is to be calculated real(wp),dimension(144) :: g = 0.0_wp !! `g(m)` -- normalized field coefficients (see [[feldcof]]) m=nmax*(nmax+2) @@ -74,12 +76,37 @@ module shellig_module procedure, public :: shellg procedure, public :: findb0 procedure :: stoer, getshc, intershc, extrashc + procedure,public :: set_data_file_dir, get_data_file_dir end type shellig_type contains !***************************************************************************************** +!***************************************************************************************** +!> +! Set the directory containing the data files. + + subroutine set_data_file_dir(me,dir) + class(shellig_type),intent(inout) :: me + character(len=*),intent(in) :: dir + me%igrf_dir = trim(dir) + end subroutine set_data_file_dir + +!***************************************************************************************** +!> +! Get the directory containing the data files. + + function get_data_file_dir(me) result(dir) + class(shellig_type),intent(in) :: me + character(len=:),allocatable :: dir + if (allocated(me%igrf_dir)) then + dir = trim(me%igrf_dir) // '/' + else + dir = 'data/igrf/' ! default + end if + end function get_data_file_dir + !***************************************************************************************** !> ! Wrapper for IGRF functions. @@ -662,7 +689,7 @@ subroutine feldcof(me,year,dimo) real(wp) :: dte1 , dte2 , erad , gha(144) , sqrt2 integer :: i , ier , j , l , m , n , iyea - character(len=filename_len) :: fil2 + character(len=:),allocatable :: fil2 real(wp) :: x , f0 , f !! these were double precision in original !! code while everything else was single precision @@ -694,9 +721,9 @@ subroutine feldcof(me,year,dimo) if ( l<1 ) l = 1 if ( l>numye ) l = numye dte1 = dtemod(l) - me%name = filmod(l) + me%name = me%get_data_file_dir() // trim(filmod(l)) dte2 = dtemod(l+1) - fil2 = filmod(l+1) + fil2 = me%get_data_file_dir() // trim(filmod(l+1)) if (read_file) then ! get igrf coefficients for the boundary years ! [if they have not ready been loaded] diff --git a/src/trmfun.f90 b/src/trmfun.f90 index 52102a9..f38dba1 100644 --- a/src/trmfun.f90 +++ b/src/trmfun.f90 @@ -22,6 +22,8 @@ module trmfun_module !! main class for the `aep8` model private + character(len=:),allocatable :: aep8_dir !! directory containing the data files + ! data read from the files: character(len=:),allocatable :: file_loaded !! the file that has been loaded integer,dimension(8) :: ihead = 0 @@ -38,10 +40,35 @@ module trmfun_module private procedure,public :: aep8 !! main routine procedure,public :: trara1, trara2 !! low-level routine + procedure,public :: set_data_file_dir, get_data_file_dir end type trm_type contains +!***************************************************************************************** +!> +! Set the directory containing the data files. + + subroutine set_data_file_dir(me,dir) + class(trm_type),intent(inout) :: me + character(len=*),intent(in) :: dir + me%aep8_dir = trim(dir) + end subroutine set_data_file_dir + +!***************************************************************************************** +!> +! Get the directory containing the data files. + + function get_data_file_dir(me) result(dir) + class(trm_type),intent(in) :: me + character(len=:),allocatable :: dir + if (allocated(me%aep8_dir)) then + dir = trim(me%aep8_dir) // '/' + else + dir = 'data/aep8/' ! default + end if + end function get_data_file_dir + !***************************************************************************************** !> ! Main wrapper for the radiation model. @@ -59,10 +86,10 @@ subroutine aep8(me,e,l,bb0,imname,flux) real(wp) :: ee(1), f(1) !! temp variables integer :: i , ierr, iuaeap , nmap - character(len=len(mname)) :: name + character(len=:),allocatable :: name logical :: load_file - name = mname(Imname) ! the file to load + name = me%get_data_file_dir() // trim(mname(Imname)) ! the file to load ! JW : do we need to reset some or all of these ? me%fistep = 0.0_wp