Skip to content

Commit

Permalink
improve do, still working on odr_c
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMVale committed Jun 27, 2024
1 parent 85430f8 commit 8455113
Showing 1 changed file with 110 additions and 97 deletions.
207 changes: 110 additions & 97 deletions src/odrpack_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module odrpack_c
implicit none
private

public :: odr_short_c, dwinf_c, open_file, close_file
public :: odr_basic_c, odr_short_c, dwinf_c, open_file, close_file

abstract interface
subroutine fcn_tc(n, m, np, nq, ldn, ldm, ldnp, beta, xplusd, ifixb, ifixx, ldifx, &
Expand Down Expand Up @@ -96,15 +96,15 @@ subroutine odr_short_c( &
real(c_double), intent(in) :: we(ldwe, ld2we, nq)
!! `epsilon` weights.
integer(c_int), intent(in) :: ldwe
!! Leading dimension of array `we`.
!! Leading dimension of array `we`, `ldwe ∈ {1, n}`.
integer(c_int), intent(in) :: ld2we
!! Second dimension of array `we`.
!! Second dimension of array `we`, `ld2we ∈ {1, n}`.
real(c_double), intent(in) :: wd(ldwd, ld2wd, m)
!! `delta` weights.
integer(c_int), intent(in) :: ldwd
!! Leading dimension of array `wd`.
!! Leading dimension of array `wd`, `ldwd ∈ {1, n}`.
integer(c_int), intent(in) :: ld2wd
!! Second dimension of array `wd`.
!! Second dimension of array `wd`, `ld2wd ∈ {1, m}`.
real(c_double), intent(in), optional :: lower(np)
!! Lower bound on `beta`.
real(kind=wp), intent(in), optional :: upper(np)
Expand All @@ -129,100 +129,113 @@ subroutine odr_short_c( &

end subroutine odr_short_c

subroutine odr_c( &
fcn, &
n, m, np, nq, &
beta, &
y, x, &
! delta, &
! we, wd, &
ifixb, & !ifixx, &
job, ndigit, taufac, &
sstol, partol, maxit, &
iprint, lunerr, lunrpt, &
stpb, & !stpd, &
sclb, & !scld, &
info, &
lower, upper) bind(C)
!! Driver routine for finding the weighted explicit or implicit orthogonal distance
!! regression (ODR) or ordinary linear or nonlinear least squares (OLS) solution (long call
!! statement).
procedure(fcn_tc) :: fcn
!! User-supplied subroutine for evaluating the model.
integer(c_int), intent(in) :: n
!! Number of observations.
integer(c_int), intent(in) :: m
!! Number of columns of data in the independent variable.
integer(c_int), intent(in) :: np
!! Number of function parameters.
integer(c_int), intent(in) :: nq
!! Number of responses per observation.
real(c_double), intent(inout) :: beta(np)
!! Function parameters.
real(c_double), intent(in) :: y(n, nq)
!! Dependent variable. Unused when the model is implicit.
real(c_double), intent(in) :: x(n, m)
!! Explanatory variable.
! real(c_double), intent(inout), optional :: delta(n, m)
! !! Initial error in the `x` data.
! real(c_double), intent(in), optional :: we(ldwe, ld2we, nq)
! !! `epsilon` weights.
! real(c_double), intent(in), optional :: wd(ldwd, ld2wd, m)
! !! `delta` weights.
integer(c_int), intent(in), optional :: ifixb(np)
!! Values designating whether the elements of `beta` are fixed at their input values or not.
! integer(c_int), intent(in), optional :: ifixx(ldifx, m)
! !! Values designating whether the elements of `x` are fixed at their input values or not.
integer(c_int), intent(in), optional :: job
!! Variable controlling problem initialization and computational method.
integer(c_int), intent(in), optional :: ndigit
!! Number of accurate digits in the function results, as supplied by the user.
real(c_double), intent(in), optional :: taufac
!! Factor used to compute the initial trust region diameter.
real(c_double), intent(in), optional :: sstol
!! Sum-of-squares convergence stopping tolerance.
real(c_double), intent(in), optional :: partol
!! Parameter convergence stopping tolerance.
integer(c_int), intent(in), optional :: maxit
!! Maximum number of iterations allowed.
integer(c_int), intent(in), optional :: iprint
!! Print control variable.
integer(c_int), intent(in), optional :: lunerr
!! Logical unit number for error messages.
integer(c_int), intent(in), optional :: lunrpt
!! Logical unit number for computation reports.
real(c_double), intent(in), optional :: stpb(np)
!! Relative step for computing finite difference derivatives with respect to `beta`.
! integer(c_int), intent(in) :: ldstpd
! real(c_double), intent(in), optional :: stpd(ldstpd, m)
! !! Relative step for computing finite difference derivatives with respect to `delta`.
real(c_double), intent(in), optional :: sclb(np)
!! Scaling values for `beta`.
! real(c_double), intent(in), optional :: scld(ldscld, m)
! !! Scaling values for `delta`.
integer(c_int), intent(out), optional :: info
!! Variable designating why the computations were stopped.
real(c_double), intent(in), optional :: lower(np)
!! Lower bound on `beta`.
real(c_double), intent(in), optional :: upper(np)
!! Upper bound on `beta`.
! subroutine odr_c( &
! fcn, &
! n, m, np, nq, &
! beta, &
! y, x, &
! we, ldwe, ld2we, &
! wd, ldwd, ld2wd, &
! ifixb, ifixx, ldifx, &
! stpb, stpd, ldstpd, &
! sclb, scld, ldscld, &
! lower, upper, &
! delta, &
! job, ndigit, taufac, &
! sstol, partol, maxit, &
! iprint, lunerr, lunrpt, &

call odr(fcn, n, m, np, nq, beta, y, x, &
! delta=delta, &
! we=we, wd=wd, &
ifixb=ifixb, &
! ifixx=ifixx, &
job=job, ndigit=ndigit, taufac=taufac, &
sstol=sstol, partol=partol, maxit=maxit, &
iprint=iprint, lunerr=lunerr, lunrpt=lunrpt, &
stpb=stpb, &
!stpd=stpd, &
sclb=sclb, &
!scld=scld, &
info=info, &
lower=lower, upper=upper)
! info) bind(C)
! !! Wrapper for the ODR routine including mandatory arguments and all optional arguments.
! procedure(fcn_tc) :: fcn
! !! User-supplied subroutine for evaluating the model.
! integer(c_int), intent(in) :: n
! !! Number of observations.
! integer(c_int), intent(in) :: m
! !! Number of columns of data in the independent variable.
! integer(c_int), intent(in) :: np
! !! Number of function parameters.
! integer(c_int), intent(in) :: nq
! !! Number of responses per observation.
! real(c_double), intent(inout) :: beta(np)
! !! Function parameters.
! real(c_double), intent(in) :: y(n, nq)
! !! Dependent variable. Unused when the model is implicit.
! real(c_double), intent(in) :: x(n, m)
! !! Explanatory variable.
! real(c_double), intent(in) :: we(ldwe, ld2we, nq)
! !! `epsilon` weights.
! integer(c_int), intent(in) :: ldwe
! !! Leading dimension of array `we`, `ldwe ∈ {1, n}`.
! integer(c_int), intent(in) :: ld2we
! !! Second dimension of array `we`, `ld2we ∈ {1, n}`.
! real(c_double), intent(in) :: wd(ldwd, ld2wd, m)
! !! `delta` weights.
! integer(c_int), intent(in) :: ldwd
! !! Leading dimension of array `wd`, `ldwd ∈ {1, n}`.
! integer(c_int), intent(in) :: ld2wd
! !! Second dimension of array `wd`, `ld2wd ∈ {1, m}`.
! integer(c_int), intent(in) :: ifixb(np)
! !! Values designating whether the elements of `beta` are fixed at their input values or not.
! integer(c_int), intent(in) :: ifixx(ldifx, m)
! !! Values designating whether the elements of `x` are fixed at their input values or not.
! integer(c_int), intent(in) :: ldifx
! !! Leading dimension of array `ifixx`, `ldifx ∈ {1, n}`.
! real(c_double), intent(in) :: stpb(np)
! !! Relative step for computing finite difference derivatives with respect to `beta`.
! real(c_double), intent(in) :: stpd(ldstpd, m)
! !! Relative step for computing finite difference derivatives with respect to `delta`.
! integer(c_int), intent(in) :: ldstpd
! !! Leading dimension of array `stpd`, `ldstpd ∈ {1, n}`.
! real(c_double), intent(in) :: sclb(np)
! !! Scaling values for `beta`.
! real(c_double), intent(in) :: scld(ldscld, m)
! !! Scaling values for `delta`.
! integer(c_int), intent(in) :: ldscld
! !! Leading dimension of array `scld`, `ldstpd ∈ {1, n}`.
! real(c_double), intent(in), optional :: lower(np)
! !! Lower bound on `beta`.
! real(kind=wp), intent(in), optional :: upper(np)
! !! Upper bound on `beta`.
! real(c_double), intent(inout), pointer, optional :: delta(n, m)
! !! Initial error in the `x` data.
! integer(c_int), intent(in), optional :: job
! !! Variable controlling initialization and computational method.
! integer(c_int), intent(in), optional :: ndigit
! !! Number of accurate digits in the function results, as supplied by the user.
! real(c_double), intent(in), optional :: taufac
! !! Factor used to compute the initial trust region diameter.
! real(c_double), intent(in), optional :: sstol
! !! Sum-of-squares convergence stopping tolerance.
! real(c_double), intent(in), optional :: partol
! !! Parameter convergence stopping tolerance.
! integer(c_int), intent(in), optional :: maxit
! !! Maximum number of iterations allowed.
! integer(c_int), intent(in), optional :: iprint
! !! Print control variable.
! integer(c_int), intent(in), optional :: lunerr
! !! Logical unit number for error messages.
! integer(c_int), intent(in), optional :: lunrpt
! !! Logical unit number for computation reports.
! integer(c_int), intent(out), optional :: info
! !! Variable designating why the computations were stopped.

! call odr(fcn, n, m, np, nq, beta, y, x, &
! ! delta=delta, &
! we=we, wd=wd, &
! lower=lower, upper=upper, &
! ifixb=ifixb, &
! ! ifixx=ifixx, &
! job=job, ndigit=ndigit, taufac=taufac, &
! sstol=sstol, partol=partol, maxit=maxit, &
! iprint=iprint, lunerr=lunerr, lunrpt=lunrpt, &
! stpb=stpb, &
! !stpd=stpd, &
! sclb=sclb, &
! !scld=scld, &
! info=info)

end subroutine odr_c
! end subroutine odr_c

subroutine open_file(lun, fn, fnlen, ierr) bind(C)
!! Open a new file associated with a specified logical unit number.
Expand Down

0 comments on commit 8455113

Please sign in to comment.