Skip to content

Commit a3cad3d

Browse files
authored
Merge pull request #2 from HugoMVale/fnc-sig
change fcn signature
2 parents 0636806 + d8f726f commit a3cad3d

File tree

14 files changed

+1952
-1957
lines changed

14 files changed

+1952
-1957
lines changed

c/example/example3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ This is a translation of example 3 from the ODRPACK95 documentation.
99
#include "../include/odrpack/odrpack.h"
1010

1111
// User-supplied function for evaluating the model
12-
void fcn(const int *n, const int *m, const int *q, const int *np,
12+
void fcn(const int *n, const int *m, const int *q, const int *np, const int *ldifx,
1313
const double beta[], const double xplusd[],
14-
const int ifixb[], const int ifixx[], const int *ldifx, const int *ideval,
14+
const int ifixb[], const int ifixx[], const int *ideval,
1515
double f[], double fjacb[], double fjacd[], int *istop) {
1616
// Local variables
1717
double freq, omega, ctheta, stheta, theta, phi, r;

c/example/example5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ This is an adaptation of example 5 from the ODRPACK95 documentation.
1010
#include "../include/odrpack/odrpack.h"
1111

1212
// User-supplied function for evaluating the model and its partial derivatives
13-
void fcn(const int *n, const int *m, const int *q, const int *np,
13+
void fcn(const int *n, const int *m, const int *q, const int *np, const int *ldifx,
1414
const double beta[], const double xplusd[],
15-
const int ifixb[], const int ifixx[], const int *ldifx, const int *ideval,
15+
const int ifixb[], const int ifixx[], const int *ideval,
1616
double f[], double fjacb[], double fjacd[], int *istop) {
1717
*istop = 0;
1818

c/include/odrpack/odrpack.h

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,30 @@ ODRPACK_EXTERN void close_file(
3838
* @param m `==>` Number of columns of data in the independent variable.
3939
* @param q `==>` Number of responses per observation.
4040
* @param np `==>` Number of function parameters.
41+
* @param ldifx `==>` Leading dimension of array `ifixx`, `ifixx ∈ {1, n}`
4142
* @param beta `==>` Array [np] of current parameter values.
4243
* @param xplusd `==>` Array [m][ldn] of current explanatory variable values, i.e., `x + delta`.
4344
* @param ifixb `==>` Array [np] of indicators for fixing parameters `beta`.
4445
* @param ifixx `==>` Array [m][ldifx] of indicators for fixing explanatory variable `x`.
45-
* @param ldifx `==>` Leading dimension of array `ifixx`, `ifixx ∈ {1, n}`
4646
* @param ideval `==>` Indicator for selecting computation to be performed.
4747
* @param f `<==` Array [q][n] for predicted function values.
4848
* @param fjacb `<==` Array [q][np][n] for Jacobian with respect to `beta`.
4949
* @param fjacd `<==` Array [q][m][n] for Jacobian with respect to errors `delta`.
5050
* @param istop `<==` Integer for stopping condition. Values:
5151
* 0 - current `beta` and `x + delta` were acceptable and values were computed successfully,
52-
* 1 - current `beta` and `x + delta` are not acceptable; ODRPACK95 should select values closer to most recently used values if possible,
53-
* -1 - current `beta` and `x + delta` are not acceptable; ODRPACK95 should stop.
52+
* 1 - current `beta` and `x + delta` are not acceptable; 'odrpack' should select values closer to most recently used values if possible,
53+
* -1 - current `beta` and `x + delta` are not acceptable; 'odrpack' should stop.
5454
*/
5555
typedef void (*odrpack_fcn_t)(
5656
const int *n,
5757
const int *m,
5858
const int *q,
5959
const int *np,
60+
const int *ldifx,
6061
const double beta[],
6162
const double xplusd[],
6263
const int ifixb[],
6364
const int ifixx[],
64-
const int *ldifx,
6565
const int *ideval,
6666
double f[],
6767
double fjacb[],
@@ -248,88 +248,88 @@ ODRPACK_EXTERN void odr_long_c(
248248
*/
249249
typedef struct
250250
{
251-
int msgb; /**< The starting location in array `iwork` of array `msgb`. */
252-
int msgd; /**< The starting location in array `iwork` of array `msgd`. */
253-
int ifix2; /**< The starting location in array `iwork` of array `ifix2`. */
254-
int istop; /**< The location in array `iwork` of variable `istop`. */
255-
int nnzw; /**< The location in array `iwork` of variable `nnzw`. */
256-
int npp; /**< The location in array `iwork` of variable `npp`. */
257-
int idf; /**< The location in array `iwork` of variable `idf`. */
258-
int job; /**< The location in array `iwork` of variable `job`. */
259-
int iprin; /**< The location in array `iwork` of variable `iprint`. */
260-
int luner; /**< The location in array `iwork` of variable `lunerr`. */
261-
int lunrp; /**< The location in array `iwork` of variable `lunrpt`. */
262-
int nrow; /**< The location in array `iwork` of variable `nrow`. */
263-
int ntol; /**< The location in array `iwork` of variable `ntol`. */
264-
int neta; /**< The location in array `iwork` of variable `neta`. */
265-
int maxit; /**< The location in array `iwork` of variable `maxit`. */
266-
int niter; /**< The location in array `iwork` of variable `niter`. */
267-
int nfev; /**< The location in array `iwork` of variable `nfev`. */
268-
int njev; /**< The location in array `iwork` of variable `njev`. */
269-
int int2; /**< The location in array `iwork` of variable `int2`. */
270-
int irank; /**< The location in array `iwork` of variable `irank`. */
271-
int ldtt; /**< The location in array `iwork` of variable `ldtt`. */
272-
int bound; /**< The location in array `iwork` of variable `bound`. */
273-
int liwkmn; /**< The minimum acceptable length of array `iwork`. */
251+
int msgb; /**< The starting location in array `iwork` of array `msgb`. */
252+
int msgd; /**< The starting location in array `iwork` of array `msgd`. */
253+
int ifix2; /**< The starting location in array `iwork` of array `ifix2`. */
254+
int istop; /**< The location in array `iwork` of variable `istop`. */
255+
int nnzw; /**< The location in array `iwork` of variable `nnzw`. */
256+
int npp; /**< The location in array `iwork` of variable `npp`. */
257+
int idf; /**< The location in array `iwork` of variable `idf`. */
258+
int job; /**< The location in array `iwork` of variable `job`. */
259+
int iprint; /**< The location in array `iwork` of variable `iprint`. */
260+
int lunerr; /**< The location in array `iwork` of variable `lunerr`. */
261+
int lunrpt; /**< The location in array `iwork` of variable `lunrpt`. */
262+
int nrow; /**< The location in array `iwork` of variable `nrow`. */
263+
int ntol; /**< The location in array `iwork` of variable `ntol`. */
264+
int neta; /**< The location in array `iwork` of variable `neta`. */
265+
int maxit; /**< The location in array `iwork` of variable `maxit`. */
266+
int niter; /**< The location in array `iwork` of variable `niter`. */
267+
int nfev; /**< The location in array `iwork` of variable `nfev`. */
268+
int njev; /**< The location in array `iwork` of variable `njev`. */
269+
int int2; /**< The location in array `iwork` of variable `int2`. */
270+
int irank; /**< The location in array `iwork` of variable `irank`. */
271+
int ldtt; /**< The location in array `iwork` of variable `ldtt`. */
272+
int bound; /**< The location in array `iwork` of variable `bound`. */
273+
int liwkmin; /**< The minimum acceptable length of array `iwork`. */
274274
} iworkidx_t;
275275

276276
/**
277277
* @brief 0-based locations within real work array.
278278
*/
279279
typedef struct
280280
{
281-
int delta; /**< Starting location of array `delta`. */
282-
int eps; /**< Starting location of array `eps`. */
283-
int xplus; /**< Starting location of array `xplusd`. */
284-
int fn; /**< Starting location of array `fn`. */
285-
int sd; /**< Starting location of array `sd`. */
286-
int vcv; /**< Starting location of array `vcv`. */
287-
int rvar; /**< Location of variable `rvar`. */
288-
int wss; /**< Location of variable `wss`. */
289-
int wssde; /**< Location of variable `wssdel`. */
290-
int wssep; /**< Location of variable `wsep`. */
291-
int rcond; /**< Location of variable `rcond`. */
292-
int eta; /**< Location of variable `eta`. */
293-
int olmav; /**< Location of variable `olmavg`. */
294-
int tau; /**< Location of variable `tau`. */
295-
int alpha; /**< Location of variable `alpha`. */
296-
int actrs; /**< Location of variable `actrs`. */
297-
int pnorm; /**< Location of variable `pnorm`. */
298-
int rnors; /**< Location of variable `rnorms`. */
299-
int prers; /**< Location of variable `prers`. */
300-
int partl; /**< Location of variable `partol`. */
301-
int sstol; /**< Location of variable `sstol`. */
302-
int taufc; /**< Location of variable `taufac`. */
303-
int epsma; /**< Location of variable `epsmac`. */
304-
int beta0; /**< Starting location of array `beta0`. */
305-
int betac; /**< Starting location of array `betac`. */
306-
int betas; /**< Starting location of array `betas`. */
307-
int betan; /**< Starting location of array `betan`. */
308-
int s; /**< Starting location of array `s`. */
309-
int ss; /**< Starting location of array `ss`. */
310-
int ssf; /**< Starting location of array `ssf`. */
311-
int qraux; /**< Starting location of array `qraux`. */
312-
int u; /**< Starting location of array `u`. */
313-
int fs; /**< Starting location of array `fs`. */
314-
int fjacb; /**< Starting location of array `fjacb`. */
315-
int we1; /**< Location of variable `we1`. */
316-
int diff; /**< Starting location of array `diff`. */
317-
int delts; /**< Starting location of array `deltas`. */
318-
int deltn; /**< Starting location of array `deltan`. */
319-
int t; /**< Starting location of array `t`. */
320-
int tt; /**< Starting location of array `tt`. */
321-
int omega; /**< Starting location of array `omega`. */
322-
int fjacd; /**< Starting location of array `fjacd`. */
323-
int wrk1; /**< Starting location of array `wrk1`. */
324-
int wrk2; /**< Starting location of array `wrk2`. */
325-
int wrk3; /**< Starting location of array `wrk3`. */
326-
int wrk4; /**< Starting location of array `wrk4`. */
327-
int wrk5; /**< Starting location of array `wrk5`. */
328-
int wrk6; /**< Starting location of array `wrk6`. */
329-
int wrk7; /**< Starting location of array `wrk7`. */
330-
int lower; /**< Starting location of array `lower`. */
331-
int upper; /**< Starting location of array `upper`. */
332-
int lrwkmn; /**< Minimum acceptable length of vector `rwork`. */
281+
int delta; /**< Starting location of array `delta`. */
282+
int eps; /**< Starting location of array `eps`. */
283+
int xplusd; /**< Starting location of array `xplusd`. */
284+
int fn; /**< Starting location of array `fn`. */
285+
int sd; /**< Starting location of array `sd`. */
286+
int vcv; /**< Starting location of array `vcv`. */
287+
int rvar; /**< Location of variable `rvar`. */
288+
int wss; /**< Location of variable `wss`. */
289+
int wssdel; /**< Location of variable `wssdel`. */
290+
int wsseps; /**< Location of variable `wsep`. */
291+
int rcond; /**< Location of variable `rcond`. */
292+
int eta; /**< Location of variable `eta`. */
293+
int olmavg; /**< Location of variable `olmavg`. */
294+
int tau; /**< Location of variable `tau`. */
295+
int alpha; /**< Location of variable `alpha`. */
296+
int actrs; /**< Location of variable `actrs`. */
297+
int pnorm; /**< Location of variable `pnorm`. */
298+
int rnorms; /**< Location of variable `rnorms`. */
299+
int prers; /**< Location of variable `prers`. */
300+
int partol; /**< Location of variable `partol`. */
301+
int sstol; /**< Location of variable `sstol`. */
302+
int taufac; /**< Location of variable `taufac`. */
303+
int epsmac; /**< Location of variable `epsmac`. */
304+
int beta0; /**< Starting location of array `beta0`. */
305+
int betac; /**< Starting location of array `betac`. */
306+
int betas; /**< Starting location of array `betas`. */
307+
int betan; /**< Starting location of array `betan`. */
308+
int s; /**< Starting location of array `s`. */
309+
int ss; /**< Starting location of array `ss`. */
310+
int ssf; /**< Starting location of array `ssf`. */
311+
int qraux; /**< Starting location of array `qraux`. */
312+
int u; /**< Starting location of array `u`. */
313+
int fs; /**< Starting location of array `fs`. */
314+
int fjacb; /**< Starting location of array `fjacb`. */
315+
int we1; /**< Location of variable `we1`. */
316+
int diff; /**< Starting location of array `diff`. */
317+
int deltas; /**< Starting location of array `deltas`. */
318+
int deltan; /**< Starting location of array `deltan`. */
319+
int t; /**< Starting location of array `t`. */
320+
int tt; /**< Starting location of array `tt`. */
321+
int omega; /**< Starting location of array `omega`. */
322+
int fjacd; /**< Starting location of array `fjacd`. */
323+
int wrk1; /**< Starting location of array `wrk1`. */
324+
int wrk2; /**< Starting location of array `wrk2`. */
325+
int wrk3; /**< Starting location of array `wrk3`. */
326+
int wrk4; /**< Starting location of array `wrk4`. */
327+
int wrk5; /**< Starting location of array `wrk5`. */
328+
int wrk6; /**< Starting location of array `wrk6`. */
329+
int wrk7; /**< Starting location of array `wrk7`. */
330+
int lower; /**< Starting location of array `lower`. */
331+
int upper; /**< Starting location of array `upper`. */
332+
int lrwkmin; /**< Minimum acceptable length of vector `rwork`. */
333333
} rworkidx_t;
334334

335335
/**
@@ -355,7 +355,7 @@ ODRPACK_EXTERN void loc_iwork_c(
355355
* @param np `==>` Number of function parameters.
356356
* @param ldwe `==>` Leading dimension of array `we`.
357357
* @param ld2we `==>` Second dimension of array `we`.
358-
* @param isodr `==>` Variable designating whether the solution is by ODR (`isodr=.true.`) or by OLS (`isodr=.false.`).
358+
* @param isodr `==>` Variable designating whether the solution is by ODR (`true`) or by OLS (`false`).
359359
* @param rwi `<==` 0-based indexes of real work array.
360360
*/
361361
ODRPACK_EXTERN void loc_rwork_c(
@@ -375,7 +375,7 @@ ODRPACK_EXTERN void loc_rwork_c(
375375
* @param m `==>` Number of columns of data in the explanatory variable.
376376
* @param q `==>` Number of responses per observation.
377377
* @param np `==>` Number of function parameters.
378-
* @param isodr `==>` Variable designating whether the solution is by ODR (`isodr=.true.`) or by OLS (`isodr=.false.`).
378+
* @param isodr `==>` Variable designating whether the solution is by ODR (`true`) or by OLS (`false`).
379379
* @param lrwork `<==` Length of real `rwork` array.
380380
* @param liwork `<==` Length of integer `iwork` array.
381381
*/

example/example1.f90

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ module example1_model
66

77
contains
88

9-
pure subroutine fcn( &
10-
n, m, q, np, beta, xplusd, ifixb, ifixx, ldifx, ideval, f, fjacb, fjacd, istop)
9+
pure subroutine fcn(beta, xplusd, ifixb, ifixx, ideval, f, fjacb, fjacd, istop)
1110
!! User-supplied subroutine for evaluating the model.
1211

13-
integer, intent(in) :: ideval, ldifx, m, n, np, q
14-
integer, intent(in) :: ifixb(np), ifixx(ldifx, m)
15-
real(kind=wp), intent(in) :: beta(np), xplusd(n, m)
16-
real(kind=wp), intent(out) :: f(n, q), fjacb(n, np, q), fjacd(n, m, q)
12+
integer, intent(in) :: ideval, ifixb(:), ifixx(:, :)
13+
real(kind=wp), intent(in) :: beta(:), xplusd(:, :)
14+
real(kind=wp), intent(out) :: f(:, :), fjacb(:, :, :), fjacd(:, :, :)
1715
integer, intent(out) :: istop
1816

1917
! Local variables
@@ -29,23 +27,23 @@ pure subroutine fcn( &
2927

3028
! Compute predicted values
3129
if (mod(ideval, 10) >= 1) then
32-
do i = 1, q
33-
f(:, i) = beta(1) + beta(2)*(exp(beta(3)*xplusd(:, 1)) - one)**2
34-
end do
30+
do i = 1, ubound(f, 2)
31+
f(:, i) = beta(1) + beta(2)*(exp(beta(3)*xplusd(:, 1)) - one)**2
32+
end do
3533
end if
3634

3735
! Compute derivatives with respect to 'beta'
3836
if (mod(ideval/10, 10) >= 1) then
39-
do i = 1, q
40-
fjacb(:, 1, i) = one
41-
fjacb(:, 2, i) = (exp(beta(3)*xplusd(:, 1)) - one)**2
42-
fjacb(:, 3, i) = beta(2)*2*(exp(beta(3)*xplusd(:, 1)) - one)*exp(beta(3)*xplusd(:, 1))*xplusd(:, 1)
43-
end do
37+
do i = 1, ubound(f, 2)
38+
fjacb(:, 1, i) = one
39+
fjacb(:, 2, i) = (exp(beta(3)*xplusd(:, 1)) - one)**2
40+
fjacb(:, 3, i) = beta(2)*2*(exp(beta(3)*xplusd(:, 1)) - one)*exp(beta(3)*xplusd(:, 1))*xplusd(:, 1)
41+
end do
4442
end if
4543

4644
! Compute derivatives with respect to 'delta'
4745
if (mod(ideval/100, 10) >= 1) then
48-
do i = 1, q
46+
do i = 1, ubound(f, 2)
4947
fjacd(:, 1, i) = beta(2)*2*(exp(beta(3)*xplusd(:, 1)) - one)*exp(beta(3)*xplusd(:, 1))*beta(3)
5048
end do
5149
end if
@@ -63,7 +61,7 @@ program example1
6361
implicit none
6462

6563
! Variable declarations
66-
integer :: i, info, iprint, j, job, lundata, lunrpt, m, n, np, q
64+
integer :: i, iprint, j, job, lundata, lunrpt, m, n, np, q
6765
integer, allocatable :: ifixx(:, :)
6866
real(kind=wp), allocatable :: beta(:), x(:, :), y(:, :)
6967

@@ -101,14 +99,9 @@ program example1
10199
iprint = 1112
102100

103101
! Compute solution
104-
call odr(fcn=fcn, &
105-
n=n, m=m, q=q, np=np, &
106-
beta=beta, &
107-
y=y, x=x, &
102+
call odr(fcn, n, m, q, np, beta, y, x, &
108103
ifixx=ifixx, &
109-
job=job, &
110-
iprint=iprint, lunerr=lunrpt, lunrpt=lunrpt, &
111-
info=info)
104+
job=job, iprint=iprint, lunerr=lunrpt, lunrpt=lunrpt)
112105

113106
close (lunrpt)
114107

example/example2.f90

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ module example2_model
66

77
contains
88

9-
pure subroutine fcn( &
10-
n, m, q, np, beta, xplusd, ifixb, ifixx, ldifx, ideval, f, fjacb, fjacd, istop)
9+
pure subroutine fcn(beta, xplusd, ifixb, ifixx, ideval, f, fjacb, fjacd, istop)
1110
!! User-supplied subroutine for evaluating the model.
1211

13-
integer, intent(in) :: ideval, ldifx, m, n, np, q
14-
integer, intent(in) :: ifixb(np), ifixx(ldifx, m)
15-
real(kind=wp), intent(in) :: beta(np), xplusd(n, m)
16-
real(kind=wp), intent(out) :: f(n, q), fjacb(n, np, q), fjacd(n, m, q)
12+
integer, intent(in) :: ideval, ifixb(:), ifixx(:, :)
13+
real(kind=wp), intent(in) :: beta(:), xplusd(:, :)
14+
real(kind=wp), intent(out) :: f(:, :), fjacb(:, :, :), fjacd(:, :, :)
1715
integer, intent(out) :: istop
1816

1917
! Local variables
@@ -29,7 +27,7 @@ pure subroutine fcn( &
2927

3028
! Compute predicted values
3129
if (mod(ideval, 10) >= 1) then
32-
do i = 1, q
30+
do i = 1, ubound(f, 2)
3331
f(:, i) = beta(3)*(xplusd(:, 1) - beta(1))**2 + &
3432
2*beta(4)*(xplusd(:, 1) - beta(1))*(xplusd(:, 2) - beta(2)) + &
3533
beta(5)*(xplusd(:, 2) - beta(2))**2 - one
@@ -49,7 +47,7 @@ program example2
4947
implicit none
5048

5149
! Variable declarations
52-
integer :: i, info, iprint, j, job, lundata, lunrpt, m, n, np, q
50+
integer :: i, iprint, j, job, lundata, lunrpt, m, n, np, q
5351
real(kind=wp), allocatable :: beta(:), x(:, :), y(:, :)
5452

5553
! Set up report files
@@ -78,13 +76,8 @@ program example2
7876
iprint = 2002
7977

8078
! Compute solution
81-
call odr(fcn=fcn, &
82-
n=n, m=m, q=q, np=np, &
83-
beta=beta, &
84-
y=y, x=x, &
85-
job=job, &
86-
lunerr=lunrpt, lunrpt=lunrpt, iprint=iprint, &
87-
info=info)
79+
call odr(fcn, n, m, q, np, beta, y, x, &
80+
job=job, lunerr=lunrpt, lunrpt=lunrpt, iprint=iprint)
8881

8982
close (lunrpt)
9083

0 commit comments

Comments
 (0)