25 #include <octave/oct.h>
28 #include "eiram_octave.hpp"
32 Calculate reaction rates and cross-sections described by polynomial fit formulas \n\
33 (interface to fortran module EIRAM) \n\
35 [Y1 Y2 .. ] = eiram(X1, [X2,] name, type, index, [path]) \n\
37 Y1, Y2 ... : vectors or matrices with the results, \n\
38 each Y1, Y2 ..., corresponds to one reaction defined in INDEX, \n\
39 each column in Y1, Y2 ... corresponds to one value of X1 \n\
40 X1 : row vector, first argument of the fit \n\
41 X2 : optional, column vector, second argument of the fit \n\
42 name : string, name of the file with the data-set ('HYDHEL', 'AMJUEL' etc.) \n\
43 type : string, type of the reaction ('H.1','H.3','H.4' etc.) \n\
44 index : array of strings, index of the reaction ('3.1.8', '2.1.5' etc.) \n\
45 path : optional, string, complete path to the file defined by NAME, \n\
46 if PATH is omitted than it is assumed that the data-set is in the current folder \n\
48 Units : energy and temperature in [eV], density in [cm^-3], \n\
49 cross sections in cm^2, collision rates in cm^3/s, \n\
50 energy loss rates in cm^3/s*eV \n\
53 % Charge-exchange H + p, Ebeam=10 eV \n\
54 svcx = eiram(10,[1:100],'HYDHEL','H.3','3.1.8'); \n\
56 % Momentum transfer cross-sections for elastic collisions p+H, p+He, p+H2 \n\
57 [sel_D sel_He sel_D2] = eiram([0.1:10],'AMJUEL','H.1',['0.1D'; '0.2D'; '0.3D'],'.../eiram/data/'); \n\
59 % Ionization rate of H atoms, electron density 1e12 cm-3 and 1e14 cm-3 \n\
60 svi = eiram([1e12 1e14],[0.1:0.1:10 10+1:1:100],'AMJUEL','H.4','2.1.5');"){
61 octave_value_list retval;
62 int nargin = args.length();
64 if(nargin < 4) { error(
"At least 4 input arguments required");
return retval;}
66 if(!args(0).is_numeric_type()) { error(
"1st argument must be of numeric type");
return retval;}
70 if(args(1).is_numeric_type()) { numberOfArgs = 2; }
71 else { numberOfArgs = 1; }
73 if ( (nargin-numberOfArgs) < 3 ) { error(
"Too few input arguments"); }
75 NDArray Arg1s = args(0).array_value();
76 double* Arg1s_v = Arg1s.fortran_vec();
78 if(error_state) {
return retval;}
79 octave_idx_type n_Arg1s = Arg1s.numel();
81 std::string fileName = args(numberOfArgs).char_matrix_value().row_as_string(0);
82 std::string reactionType = args(numberOfArgs+1).char_matrix_value().row_as_string(0);
83 charMatrix reactionIndex = args(numberOfArgs+2).char_matrix_value();
84 if(error_state) {
return retval;}
87 if( (nargin-numberOfArgs) > 3 ) {filePath = args(numberOfArgs+3).char_matrix_value().row_as_string(0);}
91 if(error_state) {
return retval;}
93 F77_XFCN(
eiram_load_wrapper, FORTSUB, (filePath.c_str(), fileName.c_str(), err, filePath.length(), fileName.length()));
99 sprintf(str,
"Input file %s%s is not found",filePath.c_str(),fileName.c_str());
103 sprintf(str,
"Cannot read input file %s%s",filePath.c_str(),fileName.c_str());
107 error(
"error during initialization of EIRAM");
113 octave_idx_type
n_reactions = reactionIndex.rows();
116 std::string index=reactionIndex.row_as_string(i);
118 if( numberOfArgs == 1) {
119 Matrix Ys(n_Arg1s, 1);
124 fileName.c_str(),reactionType.c_str(),
126 F77_CHAR_ARG_LEN(fileName.length())
127 F77_CHAR_ARG_LEN(reactionType.length())
128 F77_CHAR_ARG_LEN(index.length())
130 if(err == 0) {retval(i) = Ys;}
133 else if( numberOfArgs == 2) {
134 NDArray Arg2s=args(1).array_value();
135 double* Arg2s_v = Arg2s.fortran_vec();
136 octave_idx_type n_Arg2s = Arg2s.numel();
137 Matrix Ys(n_Arg2s, n_Arg1s);
141 Arg1s_v, Arg2s_v,n_Arg1s,n_Arg2s,
142 fileName.c_str(),reactionType.c_str(),
144 F77_CHAR_ARG_LEN(fileName.length())
145 F77_CHAR_ARG_LEN(reactionType.length())
146 F77_CHAR_ARG_LEN(index.length())
148 if(err == 0) {retval(i) = Ys;}
153 error(
"error : negative argument");
156 error(
"error : negative 1st argument");
159 error(
"error : negative 2nd argument");
163 sprintf(str,
"error: requested reaction %s %s %s is not found",fileName.c_str(),reactionType.c_str(),index.c_str());
167 error(
"error : double fit is requested for reaction described by a single fit");
170 error(
"error : single fit is requested for reaction described by a double fit");
173 if(err != 0) {error(
"error during execution of EIRAM");}
DEFUN_DLD(eiram, args, nargout,"\n\
Calculate reaction rates and cross-sections described by polynomial fit formulas \n\
(interface to fortran module EIRAM) \n\
\n\
[Y1 Y2 .. ] = eiram(X1, [X2,] name, type, index, [path]) \n\
\n\
Y1, Y2 ... : vectors or matrices with the results, \n\
each Y1, Y2 ..., corresponds to one reaction defined in INDEX, \n\
each column in Y1, Y2 ... corresponds to one value of X1 \n\
X1 : row vector, first argument of the fit \n\
X2 : optional, column vector, second argument of the fit \n\
name : string, name of the file with the data-set ('HYDHEL', 'AMJUEL' etc.) \n\
type : string, type of the reaction ('H.1','H.3','H.4' etc.) \n\
index : array of strings, index of the reaction ('3.1.8', '2.1.5' etc.) \n\
path : optional, string, complete path to the file defined by NAME, \n\
if PATH is omitted than it is assumed that the data-set is in the current folder \n\
\n\
Units : energy and temperature in [eV], density in [cm^-3], \n\
cross sections in cm^2, collision rates in cm^3/s, \n\
energy loss rates in cm^3/s*eV \n\
\n\
Examples: \n\
% Charge-exchange H + p, Ebeam=10 eV \n\
svcx = eiram(10,[1:100],'HYDHEL','H.3','3.1.8'); \n\
\n\
% Momentum transfer cross-sections for elastic collisions p+H, p+He, p+H2 \n\
[sel_D sel_He sel_D2] = eiram([0.1:10],'AMJUEL','H.1',['0.1D'; '0.2D'; '0.3D'],'.../eiram/data/'); \n\
\n\
% Ionization rate of H atoms, electron density 1e12 cm-3 and 1e14 cm-3 \n\
svi = eiram([1e12 1e14],[0.1:0.1:10 10+1:1:100],'AMJUEL','H.4','2.1.5');")
integer, parameter n_reactions
subroutine eiram_deallocate_wrapper(err)
module-less wrapper for eiram_deallocate
subroutine eiram_matlab_calc2(Y, X1, X2, M, N, fileName, reactionType, reactionIndex, err)
Binding for eiram_calc2 which has to be called from Matlab/Octave interface.
subroutine eiram_load_wrapper(filePath, fileName, err)
Wrappers are required for subroutines defined in a fortran module. See eiram_octave.hpp, eiram_octave.cpp as an example of how to call those subroutines in a C program.
subroutine eiram_matlab_calc1(Y, X, N, fileName, reactionType, reactionIndex, err)
Binding for eiram_calc1 which has to be called from Matlab/Octave interface.