From 32a1243ab87e49e1f3b11d0199e4d909f5b39ee5 Mon Sep 17 00:00:00 2001
From: michel <michel@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Tue, 7 Apr 2009 21:18:56 +0000
Subject: [PATCH] 4.0 merged r2565 changeset from trunk (again fixe for mjdgges
 on Matlab before and after v.7.8 on 64 bits plateforms)

git-svn-id: https://www.dynare.org/svn/dynare/branches/4.0@2566 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 mex/sources/build_matlab.m    |  5 +++++
 mex/sources/mjdgges/mjdgges.c | 16 +++++++++-------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/mex/sources/build_matlab.m b/mex/sources/build_matlab.m
index 1138f75515..cb76da9ad9 100644
--- a/mex/sources/build_matlab.m
+++ b/mex/sources/build_matlab.m
@@ -54,6 +54,11 @@ if matlab_ver_less_than('7.3')
     COMPILE_OPTIONS = [ COMPILE_OPTIONS ' -DMWTYPES_NOT_DEFINED' ];
 end
 
+% Matlab Lapack expects mwSignedIndex arguments only starting with Matlab 7.8
+if ~matlab_ver_less_than('7.8')
+    COMPILE_OPTIONS = [ COMPILE_OPTIONS ' -DLAPACK_USE_MWSIGNEDINDEX' ];
+end
+
 % Large array dims for 64 bits platforms appeared in Matlab 7.3
 if (strcmpi('GLNXA64', computer) || strcmpi('PCWIN64', computer)) ...
       && ~matlab_ver_less_than('7.3')
diff --git a/mex/sources/mjdgges/mjdgges.c b/mex/sources/mjdgges/mjdgges.c
index 77c4337cfe..3686386a3d 100644
--- a/mex/sources/mjdgges/mjdgges.c
+++ b/mex/sources/mjdgges/mjdgges.c
@@ -20,8 +20,10 @@
 #include <string.h>
 #include "mex.h"
 
-#if defined(MWTYPES_NOT_DEFINED) || defined(OCTAVE)
-typedef int mwSignedIndex;
+#if !defined(LAPACK_USE_MWSIGNEDINDEX) || defined(OCTAVE)
+typedef int lapack_int;
+#else
+typedef mwSignedIndex lapack_int;
 #endif
 
 #ifdef NO_LAPACK_H
@@ -36,26 +38,26 @@ void dgges(char *, char *, char *, int (*)(), int *, double *, int *, double *,
 
 double criterium;
 
-mwSignedIndex my_criteria(double *alphar, double *alphai, double *beta)
+lapack_int my_criteria(double *alphar, double *alphai, double *beta)
 {
   return( (*alphar * *alphar + *alphai * *alphai) < criterium * *beta * *beta);
 }
 
 void mjdgges(double *a, double *b, double *z, double *n, double *sdim, double *eval_r, double *eval_i, double *info)
 {
-  mwSignedIndex i_n, i_info, i_sdim, one, lwork;
+  lapack_int i_n, i_info, i_sdim, one, lwork;
   double *alphar, *alphai, *beta, *work, *par, *pai, *pb, *per, *pei;
   double *junk;
-  mwSignedIndex *bwork;
+  lapack_int *bwork;
 
   one = 1;
-  i_n = (mwSignedIndex)*n;
+  i_n = (lapack_int)*n;
   alphar = mxCalloc(i_n,sizeof(double));
   alphai = mxCalloc(i_n,sizeof(double));
   beta = mxCalloc(i_n,sizeof(double));
   lwork = 16*i_n+16;
   work = mxCalloc(lwork,sizeof(double));
-  bwork = mxCalloc(i_n,sizeof(mwSignedIndex));
+  bwork = mxCalloc(i_n,sizeof(lapack_int));
   /* made necessary by bug in Lapack */
   junk = mxCalloc(i_n*i_n,sizeof(double));
 
-- 
GitLab