Imported Upstream version 4.6.0
[debian/atlc] / src / non_gui / find_maximum_values.c
1 /* atlc - arbitrary transmission line calculator, for the analysis of
2 transmission lines are directional couplers. 
3
4 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either package_version 2
9 of the License, or (at your option) any later package_version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
19 USA.
20
21 Dr. David Kirkby, e-mail drkirkby at ntlworld.com 
22
23 */
24
25 #include "config.h"
26 #include "definitions.h"
27
28 extern int width, height;
29 extern unsigned char **oddity;
30 extern double **Er, **Vij;
31
32 void find_maximum_values(struct max_values *maximum_values, int zero_elementsQ)
33 {
34   double U, V, Ex, Ey, E, permittivity;
35   int i, j;
36
37   /* It makes sense to draw the even and odd mode images on the same
38   scale, so if its a coupler, they elements are not zeroed if the
39   function is called when doing the even mode, which is done
40   after the odd mode */
41
42   if(zero_elementsQ==ZERO_ELEMENTS_FIRST)
43   {
44     maximum_values->E_max=0.0;
45     maximum_values->Ex_or_Ey_max=0.0;
46     maximum_values->V_max=0.0;
47     maximum_values->U_max=0.0;
48     maximum_values->permittivity_max=0.0;
49   }
50   for(i=0;i<width;++i)
51   {
52     for(j=0;j<height;++j)
53     {
54       V=Vij[i][j];
55       U=find_energy_per_metre(i,j);
56       if(1)
57       {
58         if(i==0)       
59           Ex=2*Er[i+1][j]*(Vij[i][j]-Vij[i+1][j])/(Er[i+1][j]+Er[i][j]);
60         else if (i==width-1) 
61           Ex=2*Er[i-1][j]*(Vij[i-1][j]-Vij[i][j])/(Er[i-1][j]+Er[i][j]);
62         else /* This is the best estimate, but can't be done on boundary */
63         {
64           Ex=Er[i-1][j]*(Vij[i-1][j]-Vij[i][j])/(Er[i-1][j]+Er[i][j]);
65           Ex+=Er[i+1][j]*(Vij[i][j]-Vij[i+1][j])/(Er[i+1][j]+Er[i][j]);
66         }
67         if(j==0)
68           Ey=2*Er[i][j+1]*(Vij[i][j]-Vij[i][j+1])/(Er[i][j+1]+Er[i][j]);
69         else if (j==height-1)
70           Ey=2*Er[i][j-1]*(Vij[i][j-1]-Vij[i][j])/(Er[i][j-1]+Er[i][j]);
71         else
72         {
73           Ey=Er[i][j-1]*(Vij[i][j-1]-Vij[i][j])/(Er[i][j-1]+Er[i][j]);
74           Ey+=Er[i][j+1]*(Vij[i][j]-Vij[i][j+1])/(Er[i][j+1]+Er[i][j]);
75         }
76         E=sqrt(Ex*Ex+Ey*Ey);
77         permittivity=Er[i][j];
78       }
79       else
80       {
81         Ex=0.0;
82         Ey=0.0;
83         E=0.0;
84         permittivity=0.0;
85       }
86       if(U> 1.0)             
87         printf("U=%f v=%f Er=%f at %d %d\n",U,V,Er[i][j],i, j);
88
89       if(E>maximum_values->E_max) 
90         maximum_values->E_max=E;
91
92
93       if(fabs(Ex)>maximum_values->Ex_or_Ey_max)
94         maximum_values->Ex_or_Ey_max=fabs(Ex);
95
96       if(fabs(Ey)>maximum_values->Ex_or_Ey_max)
97         maximum_values->Ex_or_Ey_max=fabs(Ey);
98
99       if(fabs(E)>maximum_values->E_max)
100         maximum_values->E_max=fabs(E);
101
102       if(fabs(V) > maximum_values->V_max)
103         maximum_values->V_max=fabs(V); 
104
105       if(U > maximum_values->U_max)
106         maximum_values->U_max=U; 
107
108       if(permittivity >maximum_values->permittivity_max )
109         maximum_values->permittivity_max=permittivity; 
110         /* printf("Ex_or_Ey_max=%g E_max=%g V_max=%g U_max=%g Er_max=%g\n",maximum_values->Ex_or_Ey_max, maximum_values->E_max, maximum_values->V_max, maximum_values->U_max, maximum_values->permittivity_max);  */
111     }
112   }
113 }