You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
getopt()- and getopt_long()-like functionality (similar to the C-functions) for Fortran 90. Based on sources from [Mark Gates](http://lagrange.mechse.illinois.edu/mwest/partmc/partmc-2.2.1/src/getopt.F90).
3
+
getopt()- and getopt_long()-like functionality (similar to the C-functions) for Fortran 90/2003 or higher. Based on sources from [Mark Gates](http://lagrange.mechse.illinois.edu/mwest/partmc/partmc-2.2.1/src/getopt.F90).
5
4
6
-
## Purpose:
5
+
*f90getopt* is developed as an easy to learn and compact library in one source file. The `f90getopt.F90` file can just be added to existing sources and deployed with them without producing dependencies. You can "learn" f90getopt in minutes and therefore it is even suitable for very small projects or "throw-away-code".
6
+
7
+
*[Purpose](#Purpose)
8
+
*[Features](#Features)
9
+
*[Requirements](#Requirements)
10
+
*[Example](#Example)
11
+
*[Build the sample program](#Build-the-sample-program)
12
+
*[Run the sample program](#Run-the-sample-program)
13
+
*[Compile and link to static library](#Compile-and-link-to-static-library)
14
+
*[Userfunctions and Variables](#Userfunctions-and-Variables)
15
+
*[Differences](#Differences)
16
+
*[From C version](#From-C-version)
17
+
*[For long options](#For-long-options)
18
+
*[Changelog](#Changelog)
19
+
*[License](#License)
20
+
21
+
## Purpose
7
22
8
23
Parsing command-line options and arguments like:
9
24
10
25
<pre>myapp -xv --longarg --arg=5.0 -p 9</pre>
11
26
12
-
## Features:
27
+
## Features
13
28
14
29
* Short option without argument (e.g.: -x)
15
30
* Short option with argument (e.g.: -p 9 or -p9)
16
31
* Short options w/o arguments can be embraced (e.g.: -xv)
17
32
* Long option w/o argument (e.g: --longarg)
18
-
* Long option w/ argument (e.g.: --arg 5.0) and ***NEW***: Equal sign (e.g.: --arg=5.0)
33
+
* Long option w/ argument (e.g.: --arg 5.0 or --arg=5.0)
19
34
20
35
## Requirements
21
-
Fortran 90 compiler which offers Fortran 2003 features *command_argument_count()* and *get_command_argument()*. E.g.: gfortran (GNU), g95 (g95.org), ifort (Intel), etc.
36
+
37
+
Fortran 2003 or Fortran 90 compiler which offers Fortran 2003 features *command_argument_count()* and *get_command_argument()*. E.g.: gfortran (GNU), g95 (g95.org), ifort (Intel), etc.
22
38
23
39
## Example
24
40
41
+
This is a full working example and it make use of long and short options. It is well documented and should answer most questions. If you need further information, refer the [Wiki page](https://github.com/haniibrahim/f90getopt/wiki)
42
+
25
43
```
26
44
program f90getopt_sample
45
+
! Sample program for f90getopt function
46
+
27
47
use f90getopt
28
48
implicit none
29
-
!character:: ch ! Unused: ch=getopt()
30
49
31
-
! START For longopts only
32
-
type(option_s):: opts(3)
33
-
opts(1) = option_s( "alpha", .false., 'a' )
34
-
opts(2) = option_s( "beta", .true., 'b' )
35
-
opts(3) = option_s( "help", .false., 'h')
50
+
! START for longopts only (optional)
51
+
! ----------------------------------
52
+
! option_s derived type:
53
+
! 1st value = long option name (character array, max. 80)
54
+
! 2nd value = if option has value (boolean)
55
+
! 3rd value = short option name (single character), same as in getopt()
56
+
! option_s is not needed if you just use short options
print*, "option beta/b=", trim(optarg) ! "trim" is quite useful to avoid trailing spaces
87
+
case("h")
88
+
print*, "help-screen"
54
89
end select
55
90
end do
91
+
! END processing options
92
+
56
93
end program f90getopt_sample
57
94
```
58
95
59
-
Build the sample program:
96
+
### Build the sample program
60
97
61
-
Put ```f90getopt.f90``` and your sample program from above (let's say ```f90getopt-sample.f90```) in the same directory and change to this directory with the ```cd```command in the terminal (or Windows command prompt). Then type:
98
+
Put `f90getopt.f90` and your sample program from above (let's say `f90getopt_sample.f90`) in the same directory and change to this directory with the `cd`command in the terminal (or Windows command prompt). Then type:
(you can omit `.exe` in `-o f90fetopt_sample` on Windows)
104
+
(you can omit `.exe` in `-o f90getopt_sample` on Windows)
105
+
106
+
to compile it.
68
107
69
-
to compile it and run it with, e.g.:
108
+
### Run the sample program
70
109
71
110
On Unices:
72
111
@@ -89,19 +128,19 @@ Output is:
89
128
option beta/b=23.2
90
129
```
91
130
92
-
## Compile and link to (static) library
131
+
## Compile and link to static library
93
132
94
133
To avoid copying the source file `f90getopt.F90` to your working directory everytime you want to use their features, it make sense to create a static library. After, you just need to link the library to your project. To do this follow the steps below:
95
134
96
-
Change to the directory where the ```f90getopt.F90``` is located and type:
135
+
Change to the directory where the `f90getopt.F90` is located and type:
97
136
98
137
```
99
138
gfortran -c f90getopt.F90
100
139
ar cr libf90getopt.a f90getopt.o
101
140
ranlib libf90getopt.a
102
141
```
103
142
104
-
You will get a static libray called ```libf90getopt.a``` and a module file ```f90getopt.mod```. Move the a-file on UNIX(-like) systems to ```/usr/local/lib``` and the mod-file to ```/usr/local/include```:
143
+
You will get a static libray called `libf90getopt.a` and a module file `f90getopt.mod`. Move the a-file on UNIX(-like) systems to `/usr/local/lib` and the mod-file to `/usr/local/include`:
105
144
106
145
```
107
146
sudo cp ./libf90getopt.a /usr/local/lib/
@@ -113,51 +152,56 @@ On Windows go to the appropriate directory of your compiler-system. MinGW and Cy
113
152
To compile and link the sample program with the libray can be done on Unices with:
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
204
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
161
205
162
206
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
0 commit comments