Skip to content

Commit 06aaa33

Browse files
committed
Fixed to compile with modern LAPACK FORTRAN API.
1 parent d505e11 commit 06aaa33

File tree

8 files changed

+222
-204
lines changed

8 files changed

+222
-204
lines changed

copasi/lapack/blas.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2026 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -51,8 +51,6 @@ integer idamax_(integer *n, doublereal *dx, integer *incx);
5151
integer isamax_(integer *n, real *sx, integer *incx);
5252
/* Function */
5353
integer izamax_(integer *n, doublecomplex *zx, integer *incx);
54-
/* Function */
55-
logical lsame_(char *ca, char *cb);
5654

5755
/* Subroutine */
5856
int caxpy_(integer *n, complex *ca, complex *cx, integer *incx, complex *cy, integer *incy);

copasi/lapack/f2c.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
// Copyright (C) 2013 - 2015 by Pedro Mendes, Virginia Tech Intellectual
1+
// Copyright (C) 2019 - 2026 by Pedro Mendes, Rector and Visitors of the
2+
// University of Virginia, University of Heidelberg, and University
3+
// of Connecticut School of Medicine.
4+
// All rights reserved.
5+
6+
// Copyright (C) 2017 - 2018 by Pedro Mendes, Virginia Tech Intellectual
7+
// Properties, Inc., University of Heidelberg, and University of
8+
// of Connecticut School of Medicine.
9+
// All rights reserved.
10+
11+
// Copyright (C) 2013 - 2016 by Pedro Mendes, Virginia Tech Intellectual
212
// Properties, Inc., University of Heidelberg, and The University
313
// of Manchester.
414
// All rights reserved.
@@ -170,10 +180,10 @@ struct Namelist
170180
};
171181
typedef struct Namelist Namelist;
172182

173-
#define abs(x) ((x) >= 0 ? (x) : -(x))
183+
// #define abs(x) ((x) >= 0 ? (x) : -(x))
174184
#define dabs(x) (doublereal)abs(x)
175-
#define min(a,b) ((a) <= (b) ? (a) : (b))
176-
#define max(a,b) ((a) >= (b) ? (a) : (b))
185+
// #define min(a,b) ((a) <= (b) ? (a) : (b))
186+
// #define max(a,b) ((a) >= (b) ? (a) : (b))
177187
#define dmin(a,b) (doublereal)min(a,b)
178188
#define dmax(a,b) (doublereal)max(a,b)
179189
#define bit_test(a,b) ((a) >> (b) & 1)

copasi/lapack/lapackwrap.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2026 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -30,6 +30,9 @@
3030

3131
extern "C"
3232
{
33+
#define COPASI_CPLUSPLUS __cplusplus
34+
#define HAVE_LAPACK_CONFIG_H
35+
3336
#if (defined HAVE_MKL || (defined WIN32 && defined HAVE_LAPACK_H))
3437
# define cbdsqr_ CBDSQR
3538
# define cgbbrd_ CGBBRD
@@ -1261,6 +1264,9 @@ extern "C"
12611264

12621265
# if defined (HAVE_LAPACK_H) && !defined(HAVE_APPLE)
12631266
# include <lapack.h>
1267+
# if defined LAPACK_FORTRAN_STRLEN_END
1268+
# include "copasi/lapack/name_mangling.h"
1269+
# endif // LAPACK_FORTRAN_STRLEN_END
12641270
# else
12651271
# undef small
12661272
# if defined (HAVE_CLAPACK_H) && !defined(HAVE_APPLE) && !defined(COPASI_OVERWRITE_USE_LAPACK)

copasi/lapack/name_mangling.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2026 by Pedro Mendes, Rector and Visitors of the
2+
// University of Virginia, University of Heidelberg, and University
3+
// of Connecticut School of Medicine.
4+
// All rights reserved.
5+
6+
#pragma once
7+
8+
#define dgees_(...) LAPACK_dgees(__VA_ARGS__)
9+
#define dgetrs_(...) LAPACK_dgetrs(__VA_ARGS__)
10+
#define dgbtrs_(...) LAPACK_dgbtrs(__VA_ARGS__)
11+
#define dtrtri_(...) LAPACK_dtrtri(__VA_ARGS__)
12+
#define dlaset_(...) LAPACK_dlaset(__VA_ARGS__)
13+
#define dpotrf_(...) LAPACK_dpotrf(__VA_ARGS__)
14+
#define dpotrs_(...) LAPACK_dpotrs(__VA_ARGS__)
15+
#define dtrexc_(...) LAPACK_dtrexc(__VA_ARGS__)
16+
#define dtrsyl_(...) LAPACK_dtrsyl(__VA_ARGS__)
17+
#define dsyev_(...) LAPACK_dsyev(__VA_ARGS__)
18+
#define dpotri_(...) LAPACK_dpotri(__VA_ARGS__)
19+
20+
// This is not exposed by lapack.h
21+
integer dlaic1_(integer *job, integer *j, doublereal *x,
22+
doublereal *sest, doublereal *w, doublereal *gamma,
23+
doublereal *sestpr, doublereal *s, doublereal *c__);

copasi/odepack++/CRadau5.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2025 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2026 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -744,8 +744,8 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
744744
/* Computing MAX */
745745
/* Computing MIN */
746746
d__3 = .03, d__4 = pow_dd(&tolst, &c_b54);
747-
d__1 = uround * 10 / tolst, d__2 = min(d__3, d__4);
748-
fnewt = max(d__1, d__2);
747+
d__1 = uround * 10 / tolst, d__2 = std::min(d__3, d__4);
748+
fnewt = std::max(d__1, d__2);
749749
}
750750
else
751751
{
@@ -904,7 +904,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
904904
}
905905
}
906906

907-
ldmas2 = max(1, ldmas);
907+
ldmas2 = std::max(1, ldmas);
908908

909909
/* ------ HESSENBERG OPTION ONLY FOR EXPLICIT EQU. WITH FULL JACOBIAN */
910910
if ((implct || jband) && ijob == 7)
@@ -1218,7 +1218,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
12181218
posneg = d_sign(&c_b103, &d__1);
12191219
/* Computing MIN */
12201220
d__2 = abs(*hmax), d__3 = (d__1 = *xend - *x, abs(d__1));
1221-
hmaxn = min(d__2, d__3);
1221+
hmaxn = std::min(d__2, d__3);
12221222

12231223
if (abs(*h__) <= *uround * 10.)
12241224
{
@@ -1227,7 +1227,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
12271227

12281228
/* Computing MIN */
12291229
d__1 = abs(*h__);
1230-
*h__ = min(d__1, hmaxn);
1230+
*h__ = std::min(d__1, hmaxn);
12311231
*h__ = d_sign(h__, &posneg);
12321232
hold = *h__;
12331233
reject = FALSE_;
@@ -1315,7 +1315,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
13151315
{
13161316
/* --- JACOBIAN IS BANDED */
13171317
mujacp = *mujac + 1;
1318-
md = min(linal_1.mbjac, *m2);
1318+
md = std::min(linal_1.mbjac, *m2);
13191319
i__1 = *m1 / *m2 + 1;
13201320

13211321
for (mm = 1; mm <= i__1; ++mm)
@@ -1329,7 +1329,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
13291329
f1[j] = y[j];
13301330
/* Computing MAX */
13311331
d__2 = 1e-5, d__3 = (d__1 = y[j], abs(d__1));
1332-
f2[j] = sqrt(*uround * max(d__2, d__3));
1332+
f2[j] = sqrt(*uround * std::max(d__2, d__3));
13331333
y[j] += f2[j];
13341334
j += md;
13351335

@@ -1343,11 +1343,11 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
13431343
j1 = k;
13441344
/* Computing MAX */
13451345
i__3 = 1, i__4 = j1 - *mujac;
1346-
lbeg = max(i__3, i__4) + *m1;
1346+
lbeg = std::max(i__3, i__4) + *m1;
13471347
L14:
13481348
/* Computing MIN */
13491349
i__3 = *m2, i__4 = j1 + *mljac;
1350-
lend = min(i__3, i__4) + *m1;
1350+
lend = std::min(i__3, i__4) + *m1;
13511351
y[j] = f1[j];
13521352
mujacj = mujacp - j1 - *m1;
13531353
i__3 = lend;
@@ -1379,7 +1379,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
13791379
ysafe = y[i__];
13801380
/* Computing MAX */
13811381
d__1 = 1e-5, d__2 = abs(ysafe);
1382-
delt = sqrt(*uround * max(d__1, d__2));
1382+
delt = sqrt(*uround * std::max(d__1, d__2));
13831383
y[i__] = ysafe + delt;
13841384
(*fcn)(n, x, &y[1], &cont[1], &rpar[1], &ipar[1]);
13851385
i__2 = *n;
@@ -1508,7 +1508,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
15081508
/* LOOP FOR THE SIMPLIFIED NEWTON ITERATION */
15091509
/* *** *** *** *** *** *** *** */
15101510
newt = 0;
1511-
d__1 = max(faccon, *uround);
1511+
d__1 = std::max(faccon, *uround);
15121512
faccon = pow_dd(&d__1, &c_b113);
15131513
theta = abs(*thet);
15141514
L40:
@@ -1605,8 +1605,8 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
16051605
if (dyth >= 1.)
16061606
{
16071607
/* Computing MAX */
1608-
d__1 = 1e-4, d__2 = min(20., dyth);
1609-
qnewt = max(d__1, d__2);
1608+
d__1 = 1e-4, d__2 = std::min(20., dyth);
1609+
qnewt = std::max(d__1, d__2);
16101610
d__1 = -1. / (*nit + 4. - 1 - newt);
16111611
hhfac = pow_dd(&qnewt, &d__1) * .8;
16121612
*h__ = hhfac * *h__;
@@ -1627,7 +1627,7 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
16271627
}
16281628
}
16291629

1630-
dynold = max(dyno, *uround);
1630+
dynold = std::max(dyno, *uround);
16311631
i__1 = *n;
16321632

16331633
for (i__ = 1; i__ <= i__1; ++i__)
@@ -1657,12 +1657,12 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
16571657
/* --- WE REQUIRE .2<=HNEW/H<=8. */
16581658
/* Computing MIN */
16591659
d__1 = *safe, d__2 = cfac / (newt + (*nit << 1));
1660-
fac = min(d__1, d__2);
1660+
fac = std::min(d__1, d__2);
16611661
/* Computing MAX */
16621662
/* Computing MIN */
16631663
d__3 = *facl, d__4 = pow_dd(&err, &c_b115) / fac;
1664-
d__1 = *facr, d__2 = min(d__3, d__4);
1665-
quot = max(d__1, d__2);
1664+
d__1 = *facr, d__2 = std::min(d__3, d__4);
1665+
quot = std::max(d__1, d__2);
16661666
hnew = *h__ / quot;
16671667

16681668
/* *** *** *** *** *** *** *** */
@@ -1684,14 +1684,14 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
16841684
d__1 = d__2 * d__2 / erracc;
16851685
facgus = hacc / *h__ * pow_dd(&d__1, &c_b115) / *safe;
16861686
/* Computing MAX */
1687-
d__1 = *facr, d__2 = min(*facl, facgus);
1688-
facgus = max(d__1, d__2);
1689-
quot = max(quot, facgus);
1687+
d__1 = *facr, d__2 = std::min(*facl, facgus);
1688+
facgus = std::max(d__1, d__2);
1689+
quot = std::max(quot, facgus);
16901690
hnew = *h__ / quot;
16911691
}
16921692

16931693
hacc = *h__;
1694-
erracc = max(.01, err);
1694+
erracc = std::max(.01, err);
16951695
}
16961696

16971697
xold = *x;
@@ -1767,15 +1767,15 @@ C_INT CRadau5::operator()(C_INT *n, CRadau5::evalF fcn, double *x, double *
17671767
++(*nfcn);
17681768
/* Computing MIN */
17691769
d__1 = abs(hnew);
1770-
hnew = posneg * min(d__1, hmaxn);
1770+
hnew = posneg * std::min(d__1, hmaxn);
17711771
hopt = hnew;
1772-
hopt = min(*h__, hnew);
1772+
hopt = std::min(*h__, hnew);
17731773

17741774
if (reject)
17751775
{
17761776
/* Computing MIN */
17771777
d__1 = abs(hnew), d__2 = abs(*h__);
1778-
hnew = posneg * min(d__1, d__2);
1778+
hnew = posneg * std::min(d__1, d__2);
17791779
}
17801780

17811781
reject = FALSE_;

0 commit comments

Comments
 (0)