From 25edae468be0a7fc527d0b07b7cd74f241554f17 Mon Sep 17 00:00:00 2001 From: Lorenzo Figini Date: Mon, 14 Nov 2022 18:28:27 +0000 Subject: [PATCH] Change derived-length string components to fixed-length in cli_options type --- src/gray_cli.f90 | 35 ++++++++++++++++++++--------------- src/main.f90 | 23 +++++++++++------------ 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/gray_cli.f90 b/src/gray_cli.f90 index 482cbda..dce4d17 100644 --- a/src/gray_cli.f90 +++ b/src/gray_cli.f90 @@ -9,14 +9,15 @@ module gray_cli ! 1. the print_help() subroutine ! 2. the print_cli_options() subroutine ! 3. the man page + integer, parameter :: max_options_len=255 type cli_options ! Switches logical :: quiet ! Files - character(len=:), allocatable :: output_dir - character(len=:), allocatable :: params_file - character(len=:), allocatable :: config_file - character(len=:), allocatable :: sum_filelist + character(len=max_options_len) :: output_dir = '' + character(len=max_options_len) :: params_file = '' + character(len=max_options_len) :: config_file = '' + character(len=max_options_len) :: sum_filelist = '' ! others integer :: verbose integer, allocatable :: units(:) @@ -90,9 +91,9 @@ contains print '(a)' , 'switches:' print '(a,l)' , ' - quiet: ' , opts%quiet print '(a)' , 'files:' - print '(a,a)' , ' output-dir: ' , opts%output_dir - print '(a,a)' , ' param-file: ' , opts%params_file - print '(a,a)' , ' sum: ' , opts%sum_filelist + print '(a,a)' , ' output-dir: ' , trim(opts%output_dir) + print '(a,a)' , ' param-file: ' , trim(opts%params_file) + print '(a,a)' , ' sum: ' , trim(opts%sum_filelist) print '(a)' , 'others:' print '(a,20i3)' , ' - units: ' , opts%units print '(a,l)' , ' - verbose: ' , opts%verbose @@ -151,19 +152,27 @@ contains opts%quiet = .true. case ('-o', '--output-dir') - call get_command_string(i + 1, opts%output_dir) + call get_command_string(i + 1, temp) + opts%output_dir = temp + deallocate(temp) skip_next = .true. case ('-p', '--params-file') - call get_command_string(i + 1, opts%params_file) + call get_command_string(i + 1, temp) + opts%params_file = temp + deallocate(temp) skip_next = .true. case ('-c', '--config-file') - call get_command_string(i + 1, opts%config_file) + call get_command_string(i + 1, temp) + opts%config_file = temp + deallocate(temp) skip_next = .true. case ('-s', '--sum') - call get_command_string(i + 1, opts%sum_filelist) + call get_command_string(i + 1, temp) + opts%sum_filelist = temp + deallocate(temp) skip_next = .true. case ('-u', '--units') @@ -303,10 +312,6 @@ contains ! subroutine arguments type(cli_options), intent(inout) :: opts - if (allocated(opts%output_dir)) deallocate(opts%output_dir) - if (allocated(opts%params_file)) deallocate(opts%params_file) - if (allocated(opts%config_file)) deallocate(opts%config_file) - if (allocated(opts%sum_filelist)) deallocate(opts%sum_filelist) if (allocated(opts%units)) deallocate(opts%units) end subroutine deinit_cli_options diff --git a/src/main.f90 b/src/main.f90 index 275b586..b2d8ea6 100644 --- a/src/main.f90 +++ b/src/main.f90 @@ -37,16 +37,16 @@ program main ! Load the parameters from file and move to its directory ! (all other filepaths are assumed relative to it) - if (allocated(opts%config_file)) then + if (len_trim(opts%config_file)>0) then ! Use the newer gray.ini configuration file call log_message(level=INFO, mod='main', msg='using GRAY INI config') - call read_gray_config(opts%config_file, params) - err = chdir(dirname(opts%config_file)) + call read_gray_config(trim(opts%config_file), params) + err = chdir(dirname(trim(opts%config_file))) else ! Use the legacy gray_params.data file call log_message(level=INFO, mod='main', msg='using GRAY params file') - call read_gray_params(opts%params_file, params) - err = chdir(dirname(opts%params_file)) + call read_gray_params(trim(opts%params_file), params) + err = chdir(dirname(trim(opts%params_file))) end if if (err /= 0) then @@ -69,15 +69,15 @@ program main call init_misc(params, data) ! Change the current directory to output files there - if (allocated(opts%output_dir)) then - if (chdir(trim(cwd) // '/' // opts%output_dir) /= 0) then + if (len_trim(opts%output_dir)>0) then + if (chdir(trim(cwd) // '/' // trim(opts%output_dir)) /= 0) then call log_message(level=ERROR, mod='main', & - msg='chdir to output_dir ('//opts%output_dir//') failed!') + msg='chdir to output_dir ('//trim(opts%output_dir)//') failed!') call exit(1) end if end if - if (allocated(opts%sum_filelist)) then + if (len_trim(opts%sum_filelist)>0) then call log_message(level=INFO, mod='main', msg='summing profiles') sum: block @@ -93,10 +93,10 @@ program main pins(params%output%nrho), rtin(params%output%nrho), & rpin(params%output%nrho)) - open(100, file=opts%sum_filelist, action='read', status='old', iostat=err) + open(100, file=trim(opts%sum_filelist), action='read', status='old', iostat=err) if (err /= 0) then call log_message(level=ERROR, mod='main', & - msg='opening file list ('//opts%sum_filelist//') failed!') + msg='opening file list ('//trim(opts%sum_filelist)//') failed!') call exit(1) end if @@ -154,7 +154,6 @@ program main close(100 + i) end do deallocate(dpdv, jcd, jphi, currins, pins, rtin, rpin) - deallocate(opts%params_file) end block sum else call gray_main(params, data, results, err)