-
Notifications
You must be signed in to change notification settings - Fork 0
/
xs2rates
executable file
·217 lines (171 loc) · 6.28 KB
/
xs2rates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/sh
PROGRAM="$(basename "$0")"
JPROGRAM="${JULIABIN}/${PROGRAM}.jl"
usage() {
cat <<help
$PROGRAM
Wrapper for my julia script $PROGRAM (\${JULIABIN}), which converts scattering data between
cross sections and rate coefficients. The rate coefficient (no kinetic averaging or convolution)
is essentially just the cross section multiplied by the collider's velocity, (2*E/m)^1/2
usage: ${PROGRAM} [operation] [operand]
operations: operand: function:
-h none show this message.
-i,--input file specify input file
-o,--output file specify output file
--input-type string the input data type. Should be "XS" for cross sections or "RATE" for
rate coefficients
--xs-units string the unit type of the cross section data (e.g., "cm" for cm^2).
--rate-units-l string the length unit of the rate coefficient data (e.g., "cm" for cm^3/s).
--rate-units-t string the time unit of the rate coefficient data (e.g., "s" for cm^3/s).
--nrg-units string the unit type of the input energy (e.g., "eV" for electron volts).
--no-ignore-comments none if supplied, do not ignore lines with comment characters. This will
probably break the script. If omitted, ignore comments.
-comment_char string the comment character (default '#'). This must be a single character.
The following would be a valid implementation of ${PROGRAM} :
${PROGRAM} -i cross_sections.dat -o rates.dat \\
--input-type "XS" \\
--xs-units cm \\
--rate-units-l cm \\
--rate-units-t s \\
--nrg-units eV \\
-comment_char "#" \\
Input file: a file of electron energies (Eel) and cross sections (σ) or rate coefficients (α)
in any units of energy and length^2 (σ) or length^3/s (α), formatted as
Eel σ/α
. .
. .
. .
Output file: a conversion between σ and α in the same format
Eel α/σ
. .
. .
. .
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Needed : my units script !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
https://github.com/banana-bred/units
help
}
die() {
exit_code=1
error_message="$1"
echo 1>&2
echo "${PROGRAM}: ${error_message}" 1>&2
echo 1>&2
usage
exit "${exit_code}"
}
main() {
ignore_comments="true"
comment_char="#"
while :; do
case $1 in
-h|-\?|--help)
usage
exit 0
;;
-i | --input)
[ "$2" ] && input="${2}" && shift || die 'ERROR: "--input" requires a non-empty option argument.'
;;
-i= | --input=)
die 'ERROR: "--input" requires a non-empty argument.'
;;
-i=?* | --input=?*)
input="${1#*=}"
;;
-o | --output)
[ "$2" ] && output="${2}" && shift || die 'ERROR: "--output" requires a non-empty option argument.'
;;
-o= | --output=)
die 'ERROR: "--output" requires a non-empty argument.'
;;
-o=?* | --output=?*)
output="${1#*=}"
;;
--input-type)
[ "$2" ] && input_type="${2}" && shift || die 'ERROR: "--input-type" requires a non-empty option argument.'
;;
--input-type=)
die 'ERROR: "--input-type" requires a non-empty argument.'
;;
--input-type=?*)
input_type="${1#*=}"
;;
--xs-units )
[ "$2" ] && XS_units="${2}" && shift || die 'ERROR: "--xs-units" requires a non-empty option argument.'
;;
--xs-units=)
die 'ERROR: "--xs-units" requires a non-empty argument.'
;;
--xs-units=?*)
XS_units="${1#*=}"
;;
--rate-units-l )
[ "$2" ] && RATE_units_l="${2}" && shift || die 'ERROR: "--rate-units-l" requires a non-empty option argument.'
;;
--rate-units=)
die 'ERROR: "--rate-units-l" requires a non-empty argument.'
;;
--rate-units=?*)
RATE_units_l="${1#*=}"
;;
--rate-units-t )
[ "$2" ] && RATE_units_t="${2}" && shift || die 'ERROR: "--rate-units-t" requires a non-empty option argument.'
;;
--rate-units=)
die 'ERROR: "--rate-units-t" requires a non-empty argument.'
;;
--rate-units=?*)
RATE_units_t="${1#*=}"
;;
--nrg-units )
[ "$2" ] && nrg_units="${2}" && shift || die 'ERROR: "--nrg-units" requires a non-empty option argument.'
;;
--nrg-units=)
die 'ERROR: "--nrg-units" requires a non-empty argument.'
;;
--nrg-units=?*)
nrg_units="${1#*=}"
;;
--no-ignore-comments)
ignore_comments="false"
;;
-comment_char)
[ "$2" ] && comment_char="${2}" && shift || die 'ERROR: "-comment_char" requires a non-empty option argument.'
;;
-comment_char=)
die 'ERROR: "-comment_char" requires a non-empty argument.'
;;
-comment_char=?*)
comment_char="${1#*=}"
;;
--)
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "${1}"
;;
*)
break
;;
esac
shift
done
flag=false
[ -z "${input}" ] && echo "Need an input file with -i" 1>&2 && flag=true
[ -e "${input}" ] || (echo "Input file""'""$input""'"" does not exist" 1>&2 && flag=true)
[ -z "${output}" ] && echo "Need an output file with -o" 1>&2 && flag=true
[ -z "${XS_units}" ] && echo "Need to define input cross section units with --xs-units" 1>&2 && flag=true
[ -z "${RATE_units_l}" ] && echo "Need to define rate coefficient length units with --rate-units-l" 1>&2 && flag=true
[ -z "${RATE_units_t}" ] && echo "Need to define rate coefficient time units with --rate-units-t" 1>&2 && flag=true
[ -z "${nrg_units}" ] && echo "Need to define input electron energy units with --nrg-units" 1>&2 && flag=true
$flag && die "Variable(s) not defined. See above ^^^"
# -- get mulitiplicative constants to convert data to the expected units
xsConversion="$(units 1 "$XS_units" bohr)"
rateLengthConversion="$(units 1 "$RATE_units_l" bohr)"
rateTimeConversion="$(units 1 "$RATE_units_t" s)"
nrgConversion="$(units 1 "$nrg_units" hartree)"
julia "$JPROGRAM" "$input" "$output" "$xsConversion" "$rateLengthConversion" "$rateTimeConversion" "$nrgConversion" "$comment_char" "$ignore_comments" "$input_type"
}
main "$@"