1 #ifdef HAVE_STDLIB_H
2 #include <stdlib.h>
3 #endif
4 #include <errno.h>
5 #include "yagi.h"
6 
7 #include <errno.h>
8 
copy_matrix(int length,int width,double ** to,double ** from)9 void copy_matrix(int length, int width, double **to, double **from)
10 {
11 	int i,j;
12 	for(i=1;i<=length;++i)
13 	{
14 		for(j=1;j<=width;++j)
15 		{
16 			to[i][j]=from[i][j];
17 		}
18 	}
19 
20 #ifdef DEBUG
21 	if(errno)
22 	{
23 		fprintf(stderr,"Errno =%d in copy_matrix() of copym.c\n", errno);
24 		exit(1);
25 	}
26 #endif
27 }
28 
29 /* The following functions copies data from a matrix z containing real and
30 imaqginary data to a much larger real matrix A, so that simultaneouis
31 equations can be solved by the method in 'Numerical Recipes in C'
32 
33 		put the data in the form:
34 
35 		|Zr -Zi|   |Ir|   = |Vr|   which we will call A.x=b
36 		|Zi  Zr|   |Ii|     |Vi|
37 
38 		so the Z data goes now in a 2Nx2N matrix. This is a bit wasteful of space
39 		and time, but it will do here. */
40 
copy_complex_data_to_real_matrix(int elements,double ** z,double ** A)41 void copy_complex_data_to_real_matrix(int elements, double **z, double **A)
42 {
43 		int i, j;
44 		for(i=1;i<=elements;++i)
45 		{
46 			for(j=1;j<=elements;++j)
47 			{
48 				A[i][j]=z[i][2*j-1];   /* real data, top left corner of Z */
49 				A[i+elements][j+elements]=z[i][2*j-1]; /* Bot right, real data */
50 				A[i][j+elements]=-z[i][2*j]; /* imaginary, top right */
51 				A[i+elements][j]=z[i][2*j]; /* bottom left, imaginary */
52 			}
53 		}
54 #ifdef DEBUG
55 	if(errno)
56 	{
57 		fprintf(stderr,"Errno =%d in copy_complex_data_to_real_m() of copym.c\n", errno);
58 		exit(1);
59 	}
60 #endif
61 }
62