With newer versions of emscripten, linker errors surface eariler.
This makes it easier to find function pointer cast errors without
having to execute the bad code path -- the errors happen when the
wasm modules are linked (at load time in the browser)

Anyways, this fixes more linker errors. Mostly the problems have
to do with LAPACK functions that take string arguments. Most
LAPACK functions that take string arguments use them as enums and
only care about the first character of the string. Because of the
way that f2c works, we need to replace these strings with the ascii
code of the first character so we should replace:

sTRSV( 'UPPER', 'NOTRANS', 'NONUNIT', J, H, LDH, Y, 1 )
==>
CALL sTRSV( 85, 78, 78, J, H, LDH, Y, 1 )

where 85 and 78 are the ascii codes of U and N. Various character
variables are subbed into being integer variables. The two
functions `ilaenv` and `xerbla` expect actual C strings as an
argument, but it is very annoying to produce C strings so instead
I added wrapper functions ilaenvf2c and xerblaf2c to clapack and
instead of calling ilaenv and xerbla we call the f2c versions.

Fix scipy linking errors. With newer versions of emscripten, linker errors surface eariler.
This makes it easier to find function pointer cast errors without
having to execute the bad code path -- the errors happen when the
wasm modules are linked (at load time in the browser)

Anyways, this fixes more linker errors. Mostly the problems have
to do with LAPACK functions that take string arguments. Most
LAPACK functions that take string arguments use them as enums and
only care about the first character of the string. Because of the
way that f2c works, we need to replace these strings with the ascii
code of the first character so we should replace:

sTRSV( 'UPPER', 'NOTRANS', 'NONUNIT', J, H, LDH, Y, 1 )
==>
CALL sTRSV( 85, 78, 78, J, H, LDH, Y, 1 )

where 85 and 78 are the ascii codes of U and N. Various character
variables are subbed into being integer variables. The two
functions `ilaenv` and `xerbla` expect actual C strings as an
argument, but it is very annoying to produce C strings so instead
I added wrapper functions ilaenvf2c and xerblaf2c to clapack and
instead of calling ilaenv and xerbla we call the f2c versions.

Make return types to fortran subroutines consistently be int. Some functions are defined within clapack as variously
void and int return. Normal C compilers don't care, but emscripten is strict about return values.
diff --git a/F2CLIBS/libf2c/ef1asc_.c b/F2CLIBS/libf2c/ef1asc_.c
index 70be0bc..b2a82a2 100644
--- a/F2CLIBS/libf2c/ef1asc_.c
+++ b/F2CLIBS/libf2c/ef1asc_.c
@@ -13,7 +13,7 @@ extern "C" {
 extern VOID s_copy();
 ef1asc_(a, la, b, lb) ftnint *a, *b; ftnlen *la, *lb;
 #else
-extern void s_copy(char*,char*,ftnlen,ftnlen);
+extern int s_copy(char*,char*,ftnlen,ftnlen);
 int ef1asc_(ftnint *a, ftnlen *la, ftnint *b, ftnlen *lb)
 #endif
 {
diff --git a/F2CLIBS/libf2c/f2ch.add b/F2CLIBS/libf2c/f2ch.add
index a2acc17..f3f0466 100644
--- a/F2CLIBS/libf2c/f2ch.add
+++ b/F2CLIBS/libf2c/f2ch.add
@@ -124,9 +124,9 @@ extern double r_sinh(float *);
 extern double r_sqrt(float *);
 extern double r_tan(float *);
 extern double r_tanh(float *);
-extern void s_cat(char *, char **, integer *, integer *, ftnlen);
+extern int s_cat(char *, char **, integer *, integer *, ftnlen);
 extern integer s_cmp(char *, char *, ftnlen, ftnlen);
-extern void s_copy(char *, char *, ftnlen, ftnlen);
+extern int s_copy(char *, char *, ftnlen, ftnlen);
 extern int s_paus(char *, ftnlen);
 extern integer s_rdfe(cilist *);
 extern integer s_rdue(cilist *);
diff --git a/F2CLIBS/libf2c/s_cat.c b/F2CLIBS/libf2c/s_cat.c
index 8d92a63..54c4ff1 100644
--- a/F2CLIBS/libf2c/s_cat.c
+++ b/F2CLIBS/libf2c/s_cat.c
@@ -28,11 +28,11 @@ extern
 extern "C" {
 #endif
 
- VOID
+ 
 #ifdef KR_headers
-s_cat(lp, rpp, rnp, np, ll) char *lp, *rpp[]; ftnint rnp[], *np; ftnlen ll;
+int s_cat(lp, rpp, rnp, np, ll) char *lp, *rpp[]; ftnint rnp[], *np; ftnlen ll;
 #else
-s_cat(char *lp, char *rpp[], ftnint rnp[], ftnint *np, ftnlen ll)
+int s_cat(char *lp, char *rpp[], ftnint rnp[], ftnint *np, ftnlen ll)
 #endif
 {
 	ftnlen i, nc;
diff --git a/F2CLIBS/libf2c/s_copy.c b/F2CLIBS/libf2c/s_copy.c
index 9dacfc7..8d8963f 100644
--- a/F2CLIBS/libf2c/s_copy.c
+++ b/F2CLIBS/libf2c/s_copy.c
@@ -12,9 +12,9 @@ extern "C" {
 /* assign strings:  a = b */
 
 #ifdef KR_headers
-VOID s_copy(a, b, la, lb) register char *a, *b; ftnlen la, lb;
+int s_copy(a, b, la, lb) register char *a, *b; ftnlen la, lb;
 #else
-void s_copy(register char *a, register char *b, ftnlen la, ftnlen lb)
+int s_copy(register char *a, register char *b, ftnlen la, ftnlen lb)
 #endif
 {
 	register char *aend, *bend;

From 572a3e20ba040b4f29bbef97a9db6658c10077d3 Mon Sep 17 00:00:00 2001
From: Joe Marshall <joe.marshall@nottingham.ac.uk>
Date: Fri, 18 Mar 2022 20:02:42 -0700
Subject: [PATCH 6/7] correct return types

Make return types to fortran subroutines consistently be int. Some functions are defined within clapack as variously
void and int return. Normal C compilers don't care, but emscripten is strict about return values.
---
 F2CLIBS/libf2c/ef1asc_.c | 2 +-
 F2CLIBS/libf2c/f2ch.add  | 4 ++--
 F2CLIBS/libf2c/s_cat.c   | 6 +++---
 F2CLIBS/libf2c/s_copy.c  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/F2CLIBS/libf2c/ef1asc_.c b/F2CLIBS/libf2c/ef1asc_.c
index 70be0bc..b2a82a2 100644
--- a/F2CLIBS/libf2c/ef1asc_.c
+++ b/F2CLIBS/libf2c/ef1asc_.c
@@ -13,7 +13,7 @@ extern "C" {
 extern VOID s_copy();
 ef1asc_(a, la, b, lb) ftnint *a, *b; ftnlen *la, *lb;
 #else
-extern void s_copy(char*,char*,ftnlen,ftnlen);
+extern int s_copy(char*,char*,ftnlen,ftnlen);
 int ef1asc_(ftnint *a, ftnlen *la, ftnint *b, ftnlen *lb)
 #endif
 {
diff --git a/F2CLIBS/libf2c/f2ch.add b/F2CLIBS/libf2c/f2ch.add
index a2acc17..f3f0466 100644
--- a/F2CLIBS/libf2c/f2ch.add
+++ b/F2CLIBS/libf2c/f2ch.add
@@ -124,9 +124,9 @@ extern double r_sinh(float *);
 extern double r_sqrt(float *);
 extern double r_tan(float *);
 extern double r_tanh(float *);
-extern void s_cat(char *, char **, integer *, integer *, ftnlen);
+extern int s_cat(char *, char **, integer *, integer *, ftnlen);
 extern integer s_cmp(char *, char *, ftnlen, ftnlen);
-extern void s_copy(char *, char *, ftnlen, ftnlen);
+extern int s_copy(char *, char *, ftnlen, ftnlen);
 extern int s_paus(char *, ftnlen);
 extern integer s_rdfe(cilist *);
 extern integer s_rdue(cilist *);
diff --git a/F2CLIBS/libf2c/s_cat.c b/F2CLIBS/libf2c/s_cat.c
index 8d92a63..54c4ff1 100644
--- a/F2CLIBS/libf2c/s_cat.c
+++ b/F2CLIBS/libf2c/s_cat.c
@@ -28,11 +28,11 @@ extern
 extern "C" {
 #endif
 
- VOID
+ 
 #ifdef KR_headers
-s_cat(lp, rpp, rnp, np, ll) char *lp, *rpp[]; ftnint rnp[], *np; ftnlen ll;
+int s_cat(lp, rpp, rnp, np, ll) char *lp, *rpp[]; ftnint rnp[], *np; ftnlen ll;
 #else
-s_cat(char *lp, char *rpp[], ftnint rnp[], ftnint *np, ftnlen ll)
+int s_cat(char *lp, char *rpp[], ftnint rnp[], ftnint *np, ftnlen ll)
 #endif
 {
 	ftnlen i, nc;
diff --git a/F2CLIBS/libf2c/s_copy.c b/F2CLIBS/libf2c/s_copy.c
index 9dacfc7..8d8963f 100644
--- a/F2CLIBS/libf2c/s_copy.c
+++ b/F2CLIBS/libf2c/s_copy.c
@@ -12,9 +12,9 @@ extern "C" {
 /* assign strings:  a = b */
 
 #ifdef KR_headers
-VOID s_copy(a, b, la, lb) register char *a, *b; ftnlen la, lb;
+int s_copy(a, b, la, lb) register char *a, *b; ftnlen la, lb;
 #else
-void s_copy(register char *a, register char *b, ftnlen la, ftnlen lb)
+int s_copy(register char *a, register char *b, ftnlen la, ftnlen lb)
 #endif
 {
 	register char *aend, *bend;
-- 
2.25.1

