Menu

[r6169]: / trunk / toolkits / natgrid / src / natgridd.c  Maximize  Restore  History

Download this file

167 lines (150 with data), 3.8 kB

  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
165
166
#include "nnghead.h"
#include "nngheadd.h"
double *c_natgridd(int n, double x[], double y[], double z[],
int nxi, int nyi, double xi[], double yi[], int *ier)
{
double **data_out=NULL, *rtrn_val=NULL;
*ier = 0;
if (single_point == 0)
{
asflag = 1;
Initialized(n, x, y, nxi, nyi, xi, yi);
if (ReadDatad(n,x,y,z) != 0)
{
*ier = error_status;
return ( (double *) NULL);
}
}
if (adf)
{
CircOut();
if (error_status)
{
*ier = error_status;
return ( (double *) NULL);
}
}
if (igrad)
{
Gradient();
if (error_status)
{
*ier = error_status;
return ( (double *) NULL);
}
}
data_out = MakeGridd(nxi, nyi, xi, yi);
if (error_status)
{
if((data_out !=NULL)&&(data_out[0]!=NULL)) {
free(data_out[0]);
free(data_out);
}
*ier = error_status;
return ( (double *) NULL);
}
if (single_point == 0)
{
Terminate();
}
horilap = -1.;
vertlap = -1.;
rtrn_val = data_out[0];
free(data_out);
return (rtrn_val);
}
void Initialized(int n, double x[], double y[], int nxi, int nyi,
double xi[], double yi[])
{
double xil, xir, yib, yit;
/*
* Reserve memory for returning natural neighbor indices
* and associated weights when requested in single point
* mode for linear interpolation.
*/
nbrs = (int *) calloc(n,sizeof(int));
wts = (double *) calloc(n,sizeof(double));
error_status = 0;
datcnt = 0;
magx_orig = magx;
magy_orig = magy;
magz_orig = magz;
iscale = 0;
magx_auto = 1.;
magy_auto = 1.;
magz_auto = 1.;
/*
* Find the limits of the output array.
*/
xstart = armind(nxi, xi);
xend = armaxd(nxi, xi);
ystart = armind(nyi, yi);
yend = armaxd(nyi, yi);
/*
* Find the limits of the input array.
*/
xil = armind(n, x);
xir = armaxd(n, x);
yib = armind(n, y);
yit = armaxd(n, y);
/*
* As the default (that is, unless horizontal and vertical overlaps
* have been specifically set by the user) choose the overlap values
* as the smallest values that will make all input data points included
* in the overlap region.
*/
if (horilap EQ -1.) {
if ( (xstart >= xil) && (xend <= xir) ) {
horilap = 1.01 * (((xstart-xil) < (xir-xend)) ?
(xir-xend) : (xstart-xil));
}
else if ( (xstart >= xil) && (xend >= xir) ) {
horilap = 1.01 * (xstart-xil);
}
else if ( (xstart <= xil) && (xend <= xir) ) {
horilap = 1.01 * (xir-xend);
}
else if ( (xstart <= xil) && (xir <= xend) ) {
horilap = 0.;
}
}
if (horilap <= EPSILON) {
horilap = 0.01 * (xend - xstart);
}
if (vertlap EQ -1.) {
if ( (yib <= ystart) && (yend <= yit) ) {
vertlap = 1.01 * (((ystart-yib) < (yit-yend)) ?
(yit-yend) : (ystart-yib));
}
else if ( (ystart <= yib) && (yend <= yit) ) {
vertlap = 1.01 * (yit-yend);
}
else if ( (yib <= ystart) && (yit <= yend) ) {
vertlap = 1.01 * (ystart-yib);
}
else if ( (ystart <= yib) && (yit <= yend) ) {
vertlap = 0.;
}
}
if (vertlap <= EPSILON) {
vertlap = 0.01 * (yend - ystart);
}
}
double armind(int num, double *x)
{
int i;
float amin;
amin = x[0];
for (i = 1 ; i < num ; i++)
if (x[i] < amin) amin = x[i];
return(amin);
}
double armaxd(int num, double *x)
{
int i;
float amax;
amax = x[0];
for (i = 1 ; i < num ; i++)
if (x[i] > amax) amax = x[i];
return(amax);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.