From 010c4c0c20e5ce8b07bc36f068c0c5aee055380a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stephane.adjemian@ens.fr>
Date: Thu, 25 Nov 2010 14:26:24 +0100
Subject: [PATCH] Fixed bug in kalman_steady_state.cc related to long integer
 and (mkl) lapack calls. Changed building system by adding -fdefault-integer-8
 flag to gfortran when slicot is compiled on a 64-bits platform.

---
 m4/ax_mexopts.m4                              |  1 +
 .../kalman_steady_state.cc                    | 20 ++++++++-----------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/m4/ax_mexopts.m4 b/m4/ax_mexopts.m4
index ed2782ec59..f147af0a40 100644
--- a/m4/ax_mexopts.m4
+++ b/m4/ax_mexopts.m4
@@ -45,6 +45,7 @@ case ${MATLAB_ARCH} in
     else # glnxa64
       MATLAB_CFLAGS="$MATLAB_CFLAGS -fno-omit-frame-pointer"
       MATLAB_CXXFLAGS="$MATLAB_CXXFLAGS -fno-omit-frame-pointer"
+      MATLAB_FFLAGS="$MATLAB_FFLAGS -fdefault-integer-8"
     fi
     ax_mexopts_ok="yes"
     ;;
diff --git a/mex/sources/kalman_steady_state/kalman_steady_state.cc b/mex/sources/kalman_steady_state/kalman_steady_state.cc
index 02ecd13620..6e053351eb 100644
--- a/mex/sources/kalman_steady_state/kalman_steady_state.cc
+++ b/mex/sources/kalman_steady_state/kalman_steady_state.cc
@@ -49,22 +49,18 @@
 ++    [1] T = transpose(dynare transition matrix) and Z = transpose(dynare selection matrix).    
 */ 
 
-
-//#include <iostream>
 #include <string.h>
-//#include "matrix.h"
 #include <stdlib.h>
-//#include "mex.h"
 #include <dynmex.h>
-//#include "../matlab_versions_compatibility.h"
+#include <dynlapack.h>
 
 #if !defined(MATLAB_MEX_FILE) || !defined(_WIN32)
-# define sb02od sb02od_
+#define sb02od sb02od_
 #endif
 
 extern "C"
 {
-  int sb02od(char*, char*, char*, char*, char*, char*, mwSize*, mwSize*, mwSize*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, double*, mwSize*, double*, double*, double*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, int*, double*, mwSize*, int*, int*);
+  int sb02od(char*, char*, char*, char*, char*, char*, mwSize*, mwSize*, mwSize*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, double*, mwSize*, double*, double*, double*, double*, mwSize*, double*, mwSize*, double*, mwSize*, double*, lapack_int*, double*, mwSize*, lapack_int*, lapack_int*);
 }
 
 template <typename T> T max(T x, T y)
@@ -185,7 +181,7 @@ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
   mwSize LDWORK = max( (mwSize)7*((mwSize)2*n + (mwSize)1) + (mwSize)16, (mwSize)16*n );
   LDWORK = max( LDWORK, (mwSize)2*n + p, (mwSize)3*p);
   double tolerance = -1.0;
-  int INFO;
+  lapack_int INFO;
   // Outputs of subroutine sb02OD
   double rcond;
   double *WR, *WI, *BETA, *S, *TT, *UU;
@@ -196,12 +192,12 @@ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
   TT = (double *) mxCalloc(LDT*nn, sizeof(double));
   UU = (double *) mxCalloc(LDU*nn, sizeof(double));
   // Working arrays
-  int *IWORK;
-  IWORK = (int *) mxCalloc(LIWORK, sizeof(int));
+  lapack_int *IWORK;
+  IWORK = (lapack_int *) mxCalloc(LIWORK, sizeof(lapack_int));
   double *DWORK;
   DWORK = (double *) mxCalloc(LDWORK, sizeof(double));
-  int *BWORK;
-  BWORK = (int *) mxCalloc(nn, sizeof(int));
+  lapack_int *BWORK;
+  BWORK = (lapack_int *) mxCalloc(nn, sizeof(lapack_int));
   // Initialize the output of the mex file
   double *P;
   plhs[0] = mxCreateDoubleMatrix(n,n,mxREAL);
-- 
GitLab