1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* Copyright (C) 2017 - IIT Bombay - FOSSEE
This file must be used under the terms of the CeCILL.
This source file is licensed as described in the file COPYING, which
you should have received as part of this distribution. The terms
are also available at
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
Author: Sandeep Gupta
Organization: FOSSEE, IIT Bombay
Email: toolbox@scilab.in
*/
/*Fucntion to find generalised schur decomposition of given square complex matrices */
#include "schur.h"
#include "lapack.h"
#include "stdlib.h"
#include "string.h"
#include <math.h>
#include "doubleComplex.h"
#include "matrixTranspose.h"
/*flag --> 0: nothing
--> 1: continuous
--> 2: discrete
*/
lapack_logical selctg21( doubleComplex* in1, doubleComplex* in2, doubleComplex* in3);
lapack_logical selctg22( doubleComplex* in1, doubleComplex* in2, doubleComplex* in3);
doubleComplex dgschura(doubleComplex* in1, int size, doubleComplex* in2, int flag, int nout, \
doubleComplex* out1, doubleComplex* out2, doubleComplex* out3, doubleComplex* out4)
{
char JOBVSL = 'N';
char JOBVSR = 'N';
char SORT = 'N';
int SDIM = 0;
int LDVSL = size, LDVSR = size;
int LWORK = 2*size, INFO;
doubleComplex *ALPHA, *BETA, *VSL, *VSR, *WORK;
double *RWORK;
int *BWORK;
doubleComplex ret = 0;
doubleComplex *buf1, *buf2; /*input is copied to buf, since lapack function directly
modifies the input variable*/
/*Used incase of flag > 0*/
LAPACK_D_SELECT3 selctg = &selctg21;
if(nout >= 2){
JOBVSL = 'V';
JOBVSR = 'V';
}
if(flag > 0) SORT = 'S';
buf1 = (doubleComplex*) malloc((doubleComplex) size*size*sizeof(doubleComplex));
buf2 = (doubleComplex*) malloc((doubleComplex) size*size*sizeof(doubleComplex));
ALPHA = (doubleComplex*) malloc((doubleComplex) size*sizeof(doubleComplex));
RWORK = (double *)malloc((double)8*size*sizeof(double));
BETA = (doubleComplex*) malloc((doubleComplex) size*sizeof(doubleComplex));
VSL = (doubleComplex*) malloc((doubleComplex) LDVSL*size*sizeof(doubleComplex));
VSR = (doubleComplex*) malloc((doubleComplex) LDVSR*size*sizeof(doubleComplex));
WORK = (doubleComplex*) malloc((doubleComplex) LWORK*sizeof(doubleComplex));
BWORK = (int*) malloc((doubleComplex) size*sizeof(doubleComplex));
memcpy(buf1,in1,size*size*sizeof(doubleComplex));
memcpy(buf2,in2,size*size*sizeof(doubleComplex));
zgges_(&JOBVSL,&JOBVSR,&SORT,selctg,&size,buf1,&size,buf2,&size,&SDIM, \
ALPHA,BETA,VSL,&LDVSL,VSR,&LDVSR,WORK,&LWORK,RWORK,BWORK,&INFO);
/*if (INFO != 0)
{
out1 = NULL;
return 0;
}*/
if(nout == 1)
{
return(SDIM);
}
else if(nout == 2)
{
if(flag == 0)
{
/*copy in1 to out1 and in2 to out2*/
memcpy(out1,buf1,size*size*sizeof(doubleComplex));
memcpy(out2,buf2,size*size*sizeof(doubleComplex));
}
else
{
/*copy VSR to out1 and return SDIM */
memcpy(out1,VSR,size*size*sizeof(doubleComplex));
ret = SDIM;
}
}
else if(nout == 3)
{
/*copy VSL to out1, VSR to out2, return SDIM*/
memcpy(out1,VSL,size*size*sizeof(doubleComplex));
memcpy(out2,VSR,size*size*sizeof(doubleComplex));
ret = SDIM;
}
else if(nout == 4)
{
if(flag == 0)
{
/*copy in1 to out1 and in2 to out2*/
memcpy(out1,buf1,size*size*sizeof(doubleComplex));
memcpy(out2,buf2,size*size*sizeof(doubleComplex));
/*copy VSL to out3 and VSR to out4*/
memcpy(out3,VSL,size*size*sizeof(doubleComplex));
memcpy(out4,VSR,size*size*sizeof(doubleComplex));
}
else
{
/*copy in1 to out1 and in2 to out2*/
memcpy(out1,buf1,size*size*sizeof(doubleComplex));
memcpy(out2,buf2,size*size*sizeof(doubleComplex));
/*copy VSR to out3 and return SDIM*/
memcpy(out3,VSR,size*size*sizeof(doubleComplex));
ret = SDIM;
}
}
else /*nout = 5*/
{
/*copy in1 to out1 and in2 to out2*/
memcpy(out1,buf1,size*size*sizeof(doubleComplex));
memcpy(out2,buf2,size*size*sizeof(doubleComplex));
/*copy VSL to out3 and VSR to out4*/
memcpy(out3,VSL,size*size*sizeof(doubleComplex));
memcpy(out4,VSR,size*size*sizeof(doubleComplex));
/*return SDIM*/
ret = SDIM;
}
free(buf1);
free(buf2);
free(VSL);
free(VSR);
free(ALPHA);
free(BETA);
free(WORK);
free(BWORK);
return ret;
}
lapack_logical selctg21(doubleComplex* in1, doubleComplex* in2, doubleComplex* in3)
{
if((sqrt(*in1**in1+*in2**in2)/ *in3) < 1)
return 1;
else
return 0;
}
lapack_logical selctg22(doubleComplex* in1, doubleComplex* in2, doubleComplex* in3)
{
if((sqrt(*in1**in1+*in2**in2)/ *in3) < 1)
return 1;
else
return 0;
}
|