From 59dfcb77998df77e4897259fcf3bffea25b1dae8 Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Wed, 13 Sep 2023 16:55:35 +0200 Subject: [PATCH] src/gray_cli.f90: allow enabling or disabling all units --- src/gray_cli.f90 | 35 +++++++++++++++++++++++------------ src/units.f90 | 3 ++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/gray_cli.f90 b/src/gray_cli.f90 index b87bc1f..79a3fbe 100644 --- a/src/gray_cli.f90 +++ b/src/gray_cli.f90 @@ -54,6 +54,7 @@ contains print '(a)', ' (default: gray.ini)' print '(a)', ' -s, --sum FILE sum the output profiles from a list of files' print '(a)', ' -u, --units ID[,ID...] select which units to output (default: 4, 7);' + print '(a)', ' use `all` to enable all, or `none` for no units.' print '(a)', ' see the manual for all unit IDs.' print '(a)', ' -g, --gray-param ID=VAL set a GRAY parameter, overriding the value' print '(a)', ' specified via --params-file/--config-file;' @@ -102,7 +103,7 @@ contains subroutine parse_cli_options(opts) ! Parse the CLI arguments and initialise the options - use units, only : ucenr, usumm + use units, only : ucenr, usumm, all_enabled use logger, only : WARNING implicit none @@ -161,19 +162,29 @@ contains case ('-u', '--units') call get_next_command(i, temp) - ! resize the array - commas = count([(temp(i:i) == ',', i = 1, len(temp))]) - deallocate(opts%units) - allocate(opts%units(commas + 1)) + if (temp == 'none') then + ! disable all output units + deallocate(opts%units) + allocate(opts%units(0)) + elseif (temp == 'all') then + ! enable all output units + all_enabled = .true. + else + ! resize the array + commas = count([(temp(i:i) == ',', i = 1, len(temp))]) + deallocate(opts%units) + allocate(opts%units(commas + 1)) - ! read the list of table IDs - read (temp, *, iostat=error) opts%units - if (error > 0) then - print '(a,a)', 'invalid table IDs: ', temp - deallocate(argument) - deallocate(temp) - call exit(1) + ! read the list of table IDs + read (temp, *, iostat=error) opts%units + if (error > 0) then + print '(a,a)', 'invalid table IDs: ', temp + deallocate(argument) + deallocate(temp) + call exit(1) + end if end if + deallocate(temp) case ('-g', '--gray-param') diff --git a/src/units.f90 b/src/units.f90 index d9e014e..aeeb119 100644 --- a/src/units.f90 +++ b/src/units.f90 @@ -20,6 +20,7 @@ module units #endif ! List of active units + logical, save :: all_enabled = .false. integer, allocatable, save :: active_units(:) contains @@ -66,7 +67,7 @@ contains integer, intent(in) :: unit logical :: on - on = any(active_units == unit) + on = all_enabled .or. any(active_units == unit) end function unit_active