From 4a1c6e7b4f237ea6331ddeb7f38c3d7dbf6d0dbb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 10 Jul 2023 20:05:17 +0200 Subject: [PATCH] unified code --- src/CLI.f90 | 10 +++--- src/config.f90 | 82 +++++++++++++++++--------------------------------- 2 files changed, 31 insertions(+), 61 deletions(-) diff --git a/src/CLI.f90 b/src/CLI.f90 index cc0fec002..771d6da9f 100644 --- a/src/CLI.f90 +++ b/src/CLI.f90 @@ -185,11 +185,8 @@ subroutine CLI_init() CLI_geomFile = getPathRelCWD(geomArg,'geometry') CLI_loadFile = getPathRelCWD(loadArg,'load case') CLI_materialFile = getPathRelCWD(materialArg,'material configuration') - if (allocated(numericsArg)) then + if (allocated(numericsArg)) & CLI_numericsFile = getPathRelCWD(numericsArg,'numerics configuration') - else - CLI_numericsFile = '' - endif if (.not. allocated(solverJobname)) then solverJobname = jobname(CLI_geomFile,CLI_loadFile,CLI_materialFile,CLI_numericsFile) @@ -295,11 +292,12 @@ end function getSolverJobname function jobname(geomFile,LoadFile,materialsFile,numericsFile) character(len=:), allocatable :: jobname - character(len=*), intent(in) :: geomFile,loadFile,materialsFile,numericsFile + character(len=*), intent(in) :: geomFile,loadFile,materialsFile + character(len=:), allocatable, intent(in) :: numericsFile jobname = stem(geomFile)//'_'//stem(loadFile)//'_'//stem(materialsFile) - if (len_trim(numericsFile) > 0) jobname = jobname//'_'//stem(numericsFile) + if (allocated(numericsFile)) jobname = jobname//'_'//stem(numericsFile) contains diff --git a/src/config.f90 b/src/config.f90 index e0b2dcdad..edb72fbd3 100644 --- a/src/config.f90 +++ b/src/config.f90 @@ -34,8 +34,23 @@ subroutine config_init() print'(/,1x,a)', '<<<+- config init -+>>>'; flush(IO_STDOUT) - call parse_material() - call parse_numerics() +#if defined(MESH) || defined(GRID) + config_material => parse(CLI_materialFile,'material configuration') +#else + config_material => parse('material.yaml','material configuration') +#endif + + config_numerics => emptyDict +#if defined(MESH) || defined(GRID) + if (allocated(CLI_numericsFile)) & + config_numerics => parse(CLI_numericsFile,'numerics configuration') +#else + MSCMarc: block + logical :: exists + inquire(file='numerics.yaml',exist=exists) + if (exists) config_numerics => parse('numerics.yaml','numerics configuration') + end block MSCMarc +#endif end subroutine config_init @@ -92,70 +107,27 @@ end function config_listReferences !-------------------------------------------------------------------------------------------------- -!> @brief Read material.yaml. +!> @brief Read configuration, spread over all processes, and add to DADF5. !-------------------------------------------------------------------------------------------------- -subroutine parse_material() +function parse(fname,description) - character(len=:), allocatable :: & - fileContent, fname + character(len=*), intent(in) :: fname, description + type(tDict), pointer :: parse + + character(len=:), allocatable :: fileContent if (worldrank == 0) then - print'(/,1x,a)', 'reading material configuration'; flush(IO_STDOUT) -#if defined(MESH) || defined(GRID) - fname = CLI_materialFile -#else - fname = 'material.yaml' -#endif + print'(/,1x,a)', 'reading '//description; flush(IO_STDOUT) fileContent = IO_read(fname) - if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:) call result_openJobFile(parallel=.false.) - call result_writeDataset_str(fileContent,'setup',fname,'material configuration') + call result_writeDataset_str(fileContent,'setup',fname(scan(fname,'/',.true.)+1:),description) call result_closeJobFile() end if call parallelization_bcast_str(fileContent) - config_material => YAML_parse_str_asDict(fileContent) + parse => YAML_parse_str_asDict(fileContent) -end subroutine parse_material - - -!-------------------------------------------------------------------------------------------------- -!> @brief Read numerics.yaml. -!-------------------------------------------------------------------------------------------------- -subroutine parse_numerics() - - character(len=:), allocatable :: & - fileContent, fname - logical :: parse - - - config_numerics => emptyDict - -#if defined(MESH) || defined(GRID) - fname = CLI_numericsFile - parse = len_trim(CLI_numericsFile) > 0 -#else - fname = 'numerics.yaml' - inquire(file=fname, exist=parse) -#endif - - if (parse) then - - if (worldrank == 0) then - print'(1x,a)', 'reading numerics configuration'; flush(IO_STDOUT) - fileContent = IO_read(fname) - if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:) - call result_openJobFile(parallel=.false.) - call result_writeDataset_str(fileContent,'setup',fname,'numerics configuration') - call result_closeJobFile() - end if - call parallelization_bcast_str(fileContent) - - config_numerics => YAML_parse_str_asDict(fileContent) - - end if - -end subroutine parse_numerics +end function parse end module config