Skip to content

Commit b738c56

Browse files
authored
Parsing for input file in command now also accepts a '.inp' extension (#44)
What was previously referred to as the 'input file name' is actually the stem of the input file. Renamed this variable for clarity. Also added the option to turn the input file to this stem in the argparser.
1 parent 4bf36d6 commit b738c56

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ the CEA install directory to the user's `PATH` environment variable, e.g.:
7272
Once properly configured, you should be able to run the provided sample problems
7373
from any working directory as follows:
7474

75-
cea <cea_source_dir>/samples/rp1311_examples.inp
75+
cea <cea_source_dir>/samples/rp1311_examples
7676

7777
### Build Prerequisites
7878

@@ -129,6 +129,8 @@ Legacy CLI (classic `.inp` deck - run this from the `build/source` directory):
129129

130130
./cea ../samples/example1
131131

132+
Note that specifying the `.inp` extension for input files is optional.
133+
132134
Python example (runs the H2/O2 case after installing the Python bindings):
133135

134136
python source/bind/python/cea/samples/h2_02.py

source/main.f90

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ program cea
1717
implicit none
1818

1919
! Locals
20-
character(:), allocatable :: input_file, thermo_file, trans_file
20+
character(:), allocatable :: input_file_stem, thermo_file, trans_file
2121
character(:), allocatable :: compile_thermo_input, compile_trans_input
2222
character(:), allocatable :: data_search_dirs(:)
2323
type(ThermoDB) :: all_thermo
@@ -36,7 +36,7 @@ program cea
3636
integer :: n
3737
logical :: ok
3838

39-
call parse_arguments(input_file, thermo_file, trans_file, compile_thermo_input, compile_trans_input)
39+
call parse_arguments(input_file_stem, thermo_file, trans_file, compile_thermo_input, compile_trans_input)
4040
call log_info('CEA Version: '//version_string)
4141

4242
if (allocated(compile_thermo_input) .or. allocated(compile_trans_input)) then
@@ -51,11 +51,11 @@ program cea
5151
stop
5252
end if
5353

54-
call log_info('Input File: '//input_file)
54+
call log_info('Input File: '//input_file_stem)
5555
call log_info('Thermo File: '//thermo_file)
5656

57-
if (.not. exists(input_file//'.inp')) then
58-
call abort('Could not locate input file: '//input_file)
57+
if (.not. exists(input_file_stem//'.inp')) then
58+
call abort('Could not locate input file: '//input_file_stem)
5959
end if
6060

6161
call get_data_search_dirs(data_search_dirs)
@@ -73,11 +73,11 @@ program cea
7373
end if
7474

7575
! Read and parse the input and data files
76-
problems = read_input(input_file//'.inp')
76+
problems = read_input(input_file_stem//'.inp')
7777
all_thermo = read_thermo(thermo_file)
7878

7979
! Initialize the output file
80-
open(1, file=input_file(1:len_trim(input_file))//".out", status="replace")
80+
open(1, file=input_file_stem(1:len_trim(input_file_stem))//".out", status="replace")
8181

8282
! Loop over all problem in the input file
8383
do n = 1, size(problems)
@@ -129,8 +129,8 @@ program cea
129129

130130
contains
131131

132-
subroutine parse_arguments(input_file, thermo_file, trans_file, compile_thermo_input, compile_trans_input)
133-
character(:), allocatable, intent(out) :: input_file
132+
subroutine parse_arguments(input_file_stem, thermo_file, trans_file, compile_thermo_input, compile_trans_input)
133+
character(:), allocatable, intent(out) :: input_file_stem
134134
character(:), allocatable, intent(out) :: thermo_file
135135
character(:), allocatable, intent(out) :: trans_file
136136
character(:), allocatable, intent(out) :: compile_thermo_input
@@ -172,20 +172,26 @@ subroutine parse_arguments(input_file, thermo_file, trans_file, compile_thermo_i
172172
stop
173173
case default
174174
call log_info('Reading input_file from first positional argument')
175-
input_file = arg
175+
! If the user has added a .inp extension, remove it.
176+
input_file_stem = arg
177+
if (len(arg) > 4) then
178+
if (arg(len(arg)-3:len(arg)) == '.inp') then
179+
input_file_stem = arg(:len(arg)-4)
180+
end if
181+
end if
176182
end select
177183
end do
178184

179185
if (allocated(compile_thermo_input) .or. allocated(compile_trans_input)) then
180-
if (allocated(input_file)) then
186+
if (allocated(input_file_stem)) then
181187
call log_error('input_file is not allowed with --compile-thermo/--compile-trans')
182188
call display_help
183189
call abort
184190
end if
185191
return
186192
end if
187193

188-
if (.not. allocated(input_file)) then
194+
if (.not. allocated(input_file_stem)) then
189195
call log_error('Required argument not specified: input_file')
190196
call display_help
191197
call abort

0 commit comments

Comments
 (0)