urbanjost / m_cli2 Goto Github PK
View Code? Open in Web Editor NEWFortran commandline-interface using a simple prototype command
License: The Unlicense
Fortran commandline-interface using a simple prototype command
License: The Unlicense
Meson has released version 1.0.0 and is mature.
M_CLI2 currently supports fpm, adding Meson build support would be a good option as well, just like fpm and CMake, Meson is also effective at establishing source file dependencies.
Thanks, M_CLI2 works great. I added Meson support for M_CLI2 under this branch.
If this sounds good to you @urbanjost , I'll add a PR for that.
I'm not entirely sure where this exactly originates and where to find a good documentation on this, but some compilers and build tools support a “response file.” Usually the syntax is
prog @file1.rsp @file2.rsp
where file1.rsp
, file2.rsp
, ... contain the command line arguments separated by newlines and can be combined with normal command lines arguments. Some implementations allow further references to other response files in the response file. I did find some documentation for MSBuild.exe on rsp-files and some notes at the ninja build manpage.
This might be an interesting feature for this library since it would allow to store (maybe even load and/or dump) command lines as a file, which makes it useful for testing or storing frequently needed (complicated) command lines.
Tried to compile this project with the PGI compilers. This didn't work, in case it is helpful I will share my workflow for the setup and test to reproduce the compiler errors.
NVHPC 20.7:
wget https://developer.download.nvidia.com/hpc-sdk/nvhpc_2020_207_Linux_x86_64_cuda_11.0.tar.gz
tar xpzf nvhpc_2020_207_Linux_x86_64_cuda_11.0.tar.gz
NVHPC_SILENT=true NVHPC_INSTALL_DIR=/opt/nvidia/hpc_sdk NVHPC_INSTALL_TYPE=single sudo nvhpc_2020_207_Linux_x86_64_cuda_11.0/install
module use /opt/nvidia/hpc_sdk/modulefiles
module load nvhpc
gfortran
to nvfortran
make -C src
NVFORTRAN-S-0000-Internal compiler error. size_of: attempt to get size of assumed size character 0 (M_CLI2.f90: 2012)
0 inform, 0 warnings, 1 severes, 0 fatal for get_anyarray_cc
NVFORTRAN-S-0000-Internal compiler error. size_of: attempt to get size of assumed size character 0 (M_CLI2.f90: 2043)
NVFORTRAN-S-0000-Internal compiler error. size_of: attempt to get size of assumed size character 0 (M_CLI2.f90: 2043)
0 inform, 0 warnings, 2 severes, 0 fatal for get_args_fixed_length_a_array
NVFORTRAN-S-0081-Illegal selector - KIND value must be non-negative (M_CLI2.f90: 2493)
NVFORTRAN-S-0155-Duplicate TYPE IS real (M_CLI2.f90: 2493)
0 inform, 0 warnings, 2 severes, 0 fatal for print_generic
NVFORTRAN-S-0081-Illegal selector - KIND value must be non-negative (M_CLI2.f90: 2555)
NVFORTRAN-S-0155-Duplicate TYPE IS real (M_CLI2.f90: 2555)
0 inform, 0 warnings, 2 severes, 0 fatal for print_generic
NVHPC 20.9:
wget https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc_2020_209_Linux_x86_64_cuda_11.0.tar.gz
tar xpzf nvhpc_2020_209_Linux_x86_64_cuda_11.0.tar.gz
NVHPC_SILENT=true NVHPC_INSTALL_DIR=/opt/nvidia/hpc_sdk NVHPC_INSTALL_TYPE=single sudo nvhpc_2020_209_Linux_x86_64_cuda_11.0/install
module use /opt/nvidia/hpc_sdk/modulefiles
module load nvhpc
gfortran
to nvfortran
make -C src
NVFORTRAN-S-0155-ALLOCATE Type-Specification is incompatible with type of object strings (M_CLI2.f90: 1836)
NVFORTRAN-S-0155-ALLOCATE Type-Specification is incompatible with type of object strings (M_CLI2.f90: 1841)
0 inform, 0 warnings, 2 severes, 0 fatal for get_fixed_length_any_size_cxxxx
NVFORTRAN-S-0081-Illegal selector - KIND value must be non-negative (M_CLI2.f90: 2293)
NVFORTRAN-S-0155-Duplicate TYPE IS real (M_CLI2.f90: 2293)
0 inform, 0 warnings, 2 severes, 0 fatal for print_generic
NVFORTRAN-S-0081-Illegal selector - KIND value must be non-negative (M_CLI2.f90: 2355)
NVFORTRAN-S-0155-Duplicate TYPE IS real (M_CLI2.f90: 2355)
0 inform, 0 warnings, 2 severes, 0 fatal for print_generic
I was experimenting response file for fpm and running command like fpm @build
from a powershell terminal on Windows.
The issue is that @
has a special meaning in powershell and the command cannot be interpreted. It only returns the help for fpm
Fortran Package Manager:
USAGE: fpm [ SUBCOMMAND [SUBCOMMAND_OPTIONS] ]|[--list|--help|--version]
where SUBCOMMAND is commonly new|build|run|test
subcommand may be one of
build Compile the package placing results in the "build" directory
help Display help
list Display this list of subcommand descriptions
new Create a new Fortran package directory with sample files
run Run the local package application programs
test Run the test programs
update Update and manage project dependencies
...
sections in the rsp containing hyphens are perfectly fine, so I can run fpm @gfortran-build
.
Or, I can also use the classical cmd prompt.
There is probably not much to do here, but I thought I report the issue for the record in case someone faces the same problem.
Kind of a very special niche problem, since conda-forge's GCC toolchain for Windows is stuck at 5.3.0.
Compilation of fpm fails for M_CLI2:
f951.exe: Warning: -fPIC ignored for target (all code is position independent)
build\dependencies\M_CLI2\src\M_CLI2.f90:2973:29:
xarray((i+1)/2)=cmplx( darray(i),darray(i+1) )
1
Warning: Conversion from REAL(8) to default-kind COMPLEX(4) at (1) might lose precision, consider using the KIND argument [-Wconversion]
build\dependencies\M_CLI2\src\M_CLI2.f90:3330:24:
subroutine journal(where, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, ga, gb, gc, gd, ge, gf, gg, gh, gi, gj, sep)
1
Warning: Unused dummy argument 'where' at (1) [-Wunused-dummy-argument]
build\dependencies\M_CLI2\src\M_CLI2.f90:2020:0:
function separator2() result(sep)
^
Warning: 'separator2' defined but not used [-Wunused-function]
build\dependencies\M_CLI2\src\M_CLI2.f90:1087:0:
subroutine set_usage(keyword,description,value)
^
Warning: 'set_usage' defined but not used [-Wunused-function]
build\dependencies\M_CLI2\src\M_CLI2.f90:6035:0:
sg=unnamed
^
internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1801
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://sourceforge.net/projects/msys2> for instructions.
This has very low priority.
From the docs it is unclear if short options may be bundled, e.g. -a -b specified as -ab.
The meson.build
succsesfully build m_cli2 library and install it with appropriate symlinks but there is no rule to install m_cli2.mod
file that is required as header to use the dynamic library.
I just tried adding --flag
to fpm and found that M_CLI2 won't let me do:
fpm run -- build --flag "-O2"
As it will result in an unknown short keyword error:
UNKNOWN COMPOUND SHORT KEYWORD:O in -O3
KEYWORD SHORT PRESENT VALUE
version v F [F]
verbose F [F]
usage u F [F]
show-model F [F]
release F [F]
list F [F]
help h F [F]
flag T [" "]
compiler F ["gfortran"]
UNNAMED
000001[build ]
Any pointers on how we can elegantly implement this?
#bash-shell completion scripts (using complete(1) and compgen(1)) would be very nice, and bash is almost ubiquitous except for some MSWindows environments.
So it a special switch were built in like --CLI_bash_completion you could call the program and it would write out a basic completion script that you could source or write to a file to expand upon or put in standard system location.
Changed gfortran
in src/Makefile
to nagfor
and used make -C src
, build fails with:
Extension: M_CLI2.f90, line 1152: Line longer than 132 characters
Extension: M_CLI2.f90, line 1703: Line longer than 132 characters
Warning: M_CLI2.f90, line 2354: Unused dummy variable WHERE
Questionable: M_CLI2.f90, line 3288: Variable IFOK set but never referenced
Warning: M_CLI2.f90, line 5102: INT16 explicitly imported into GET_GENERIC but not used
Warning: M_CLI2.f90, line 5102: INT32 explicitly imported into GET_GENERIC but not used
Warning: M_CLI2.f90, line 5102: INT64 explicitly imported into GET_GENERIC but not used
Warning: M_CLI2.f90, line 5102: INT8 explicitly imported into GET_GENERIC but not used
Warning: M_CLI2.f90, line 5102: REAL128 explicitly imported into GET_GENERIC but not used
Warning: M_CLI2.f90, line 5102: REAL32 explicitly imported into GET_GENERIC but not used
Warning: M_CLI2.f90, line 5258: INPUT_UNIT explicitly imported into M_CLI2 (as STDIN) but not used
Questionable: M_CLI2.f90, line 809: Last statement of DO loop body is an unconditional EXIT statement
Questionable: M_CLI2.f90, line 1301: Last statement of DO loop body is an unconditional CYCLE statement
Error: M_CLI2.f90, line 2494: Missing field width for L edit descriptor
Error: M_CLI2.f90, line 2557: Missing field width for L edit descriptor
[NAG Fortran Compiler error termination, 2 errors, 13 warnings]
Error occurs for:
Line 2494 in c459fba
Line 2557 in c459fba
First of all, thank you @urbanjost for writing this library, it's very cool.
In the process of using the M_CLI2
library, I found that the allocatable
attributes of help_text
and version_text
do not seem to be so necessary.
Removing the allocatable
attributes makes the set_args
interface more lenient, allowing the user to enter an array of constant strings (character(*), parameter :: help_text(*) = [...]
).
I made such a modification (a commit), and it looks like there are no apparent issues.
program main
use M_CLI2
character(*), parameter :: help_text(*) = [character(10) :: "help1", "help2"]
character(:), allocatable :: version_text(:)
version_text = [character(10) :: "version1", "version2"]
call set_args("", help_text, version_text)
end program main
Before:
>> fpm run -- --help
M_CLI2.F90 done.
libdemo.a done.
main.f90 failed.
[ 75%]Compiling...
app\main.f90:8:22:
8 | call set_args("", help_text, version_text)
| 1
Error: Actual argument at (1) to allocatable or pointer dummy argument 'help_text' must have a deferred length type parameter if
and only if the dummy has one
<ERROR> Compilation failed for object " app_main.f90.o "
<ERROR>stopping due to failed compilation
STOP 1
After:
>> fpm run -- --help
M_CLI2.F90 done.
libdemo.a done.
main.f90 done.
demo.exe done.
[100%] Project compiled successfully.
help1
help2
The current Makefile
doesn't provide rule to build m_cli2
shared library that results in impossibility to use M_CLI2 as unbundled package or module (system installed) due to undefined reference
errors.
Using gfortran I had to build it manually initially passed into F90FLAGS
of Makefile
the option -fPIC
to build proper object file M_CLI2.o
that than could be linked to shared (passing it's SONAME too) library by
gfortran -Wl,-soname,libm_cli2.so.1 -shared -o libm_cli2.so.1 M_CLI2.o
and then creating symlink libm_cli2.so
pointed to libm_cli2.so.1
.
Please add additional Makefile
rules to build shared library for appropriate compilers.
On OpenBSD x86 architecture, I have a weird behaviour when using M_CLI2
.
I first noticed it while build fpm
on x86, and next reduced the example code to the following:
program show
use M_CLI2, only : set_args, lget, rget, sget, igets
implicit none
call set_args('-l F')
print *, "lget", lget('l')
end program show
Please note, that there is no problem with real and rget
(I don't specialy tested others types).
On x86_64, the program seems to work well:
$ ./test
lget F
$ ./test -l
lget T
$ ./test -l xxx
lget T
$ ./test -h
./test --version F
--usage F
--help F
--version F -l F
On x86, I have the following behaviour:
$ ./test
lget*get_anyarray_l* expected one value found 3
$ ./test -l
lget T
$ ./test -l xxx
lget*get_anyarray_l* bad logical expression for l=XXX
F
$ ./test -h
lget T
I tested with both gfortan 8.4.0 and gfortran 11.2.0 (both available on OpenBSD) with the same result.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.