-
Notifications
You must be signed in to change notification settings - Fork 1
/
pow.F
114 lines (91 loc) · 2.92 KB
/
pow.F
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
#include "fintrf.h"
C======================================================================
#if 0
C
C pow.F
C .F file needs to be preprocessed to generate .for equivalent
C
#endif
C
C pow.f
C
C Computational function that takes a scalar and doubles it.
C This is a MEX-file for MATLAB.
C Copyright 1984-2018 The MathWorks, Inc.
C
C======================================================================
C Gateway routine
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
C Declarations
implicit none
C mexFunction arguments:
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
C Function declarations:
#if MX_HAS_INTERLEAVED_COMPLEX
mwPointer mxGetDoubles
#else
mwPointer mxGetPr
#endif
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
C Pointers to input/output mxArrays:
mwPointer x_ptr, y_ptr
C Array information:
mwPointer mrows, ncols
mwSize size
C Arguments for computational routine:
real*8 x_input, y_output
C-----------------------------------------------------------------------
C Check for proper number of arguments.
if(nrhs .ne. 1) then
call mexErrMsgIdAndTxt ('MATLAB:pow:nInput',
+ 'One input required.')
elseif(nlhs .gt. 1) then
call mexErrMsgIdAndTxt ('MATLAB:pow:nOutput',
+ 'Too many output arguments.')
endif
C Validate inputs
C Check that the input is a number.
if(mxIsNumeric(prhs(1)) .eq. 0) then
call mexErrMsgIdAndTxt ('MATLAB:pow:NonNumeric',
+ 'Input must be a number.')
endif
C Get the size of the input array.
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
C Validate inputs
C Check that the input is a scalar number.
if(.not.((mrows .eq. 1) .and. (ncols .eq. 1))) then
call mexErrMsgIdAndTxt ('MATLAB:pow:NonScalar',
+ 'Input must be a scalar number.')
endif
size = mrows*ncols
C Create Fortran array from the input argument.
#if MX_HAS_INTERLEAVED_COMPLEX
x_ptr = mxGetDoubles(prhs(1))
#else
x_ptr = mxGetPr(prhs(1))
#endif
call mxCopyPtrToReal8(x_ptr,x_input,size)
C Create matrix for the return argument.
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
#if MX_HAS_INTERLEAVED_COMPLEX
y_ptr = mxGetDoubles(plhs(1))
#else
y_ptr = mxGetPr(plhs(1))
#endif
C Call the computational subroutine.
call pow(y_output, x_input)
C Load the data into y_ptr, which is the output to MATLAB.
call mxCopyReal8ToPtr(y_output,y_ptr,size)
return
end
C-----------------------------------------------------------------------
C Computational routine
subroutine pow(y_output, x_input)
real*8 x_input, y_output
y_output = x_input**int(x_input)
return
end