Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/urbanjost/m_args
Command line parsing using a NAMELIST group -- packages for use with fpm(1)
https://github.com/urbanjost/m_args
argument command command-line commandline fortran-package-manager fpm parsing
Last synced: about 6 hours ago
JSON representation
Command line parsing using a NAMELIST group -- packages for use with fpm(1)
- Host: GitHub
- URL: https://github.com/urbanjost/m_args
- Owner: urbanjost
- License: unlicense
- Created: 2021-03-29T01:10:10.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-30T00:13:21.000Z (7 months ago)
- Last Synced: 2024-03-30T04:37:39.566Z (7 months ago)
- Topics: argument, command, command-line, commandline, fortran-package-manager, fpm, parsing
- Language: Fortran
- Homepage:
- Size: 1.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# M_args
A module that provides for command line parsing using NAMELIST syntax. See
[M_arges](https://urbanjost.github.io/M_args/M_args.3m_args.html) for a
full description.Installation requires fpm(1):
[Fortran Package Manager](https://github.com/fortran-lang/fpm) )
## Sample Usage
```fortran
module M_arguments
use M_args, only : get_namelist, print_dictionary, unnamed, oneline! >>> CHANGE THIS
! declare and initialize a namelist. Letter_ denotes an uppercase short command keyword
real :: x=111.1, y=222.2, z=333.3
real :: point(3)=[10.0,20.0,30.0]
character(len=80) :: title=" "
logical :: l=.false., l_=.false.
logical :: help=.false., version=.false., v=.false., h=.false.
equivalence (help,h),(version,v)namelist /args/ x,y,z,point,title,help,h,version,v,l,l_
! << END OF CHANGEScontains
subroutine get_args()
integer :: ios
character(len=255) :: message ! use for I/O error messages
character(len=:),allocatable :: readme ! stores updated namelist
character(len=10000) :: hold_namelist(60)
hold_namelist=''
write(hold_namelist,nml=args,iostat=ios,iomsg=message)
if(ios.eq.0)then
readme=get_namelist(oneline(hold_namelist))
read(readme,nml=args,iostat=ios,iomsg=message)
endif
if(ios.ne.0)then
write(*,'("ERROR:",i0,1x,a)')ios, trim(message)
call print_dictionary()
stop 1
endif
end subroutine get_args
end module M_argumentsprogram short
use M_arguments, only : get_args, unnamed
use M_arguments ! make user variables available
implicit none
integer :: i
call get_args() ! crack command line options
! >> USER YOUR VARIABLES HERE. FOR EXAMPLE:
write(*,*)'VALUES ARE NOW ', new_line('A'),&
&'x ',x, new_line('A'),&
&'y ',y, new_line('A'),&
&'z ',z, new_line('A'),&
&'point ',point, new_line('A'),&
&'title ',title, new_line('A'),&
&'help ',help,'h ',h, new_line('A'),&
&'version ',version,'v ',v, new_line('A'),&
&'l ',l, new_line('A'),&
&'l_ ',l_
if(size(unnamed).gt.0)then
write(*,'(a)')'UNNAMED:'
write(*,'(i6.6,3a)')(i,'[',unnamed(i),']',i=1,size(unnamed))
endif
!<< END OF EXAMPLE USAGE OF VARIABLES
end program short
!end program demo_M_args
```
This program can now be called like
```bash
./demo_M_args -x 200 -y 123 -l --title 'My title'
```## Supports FPM ![fpm](docs/images/fpm_logo.gif)
download the github repository and build it with
fpm ( as described at [Fortran Package Manager](https://github.com/fortran-lang/fpm) )```bash
git clone https://github.com/urbanjost/M_args.git
cd M_args
fpm test
```or just list it as a dependency in your fpm.toml project file.
```toml
[dependencies]
M_args = { git = "https://github.com/urbanjost/M_args.git" }
```