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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
DESCRIPTION OF INTERPOLATION LIBRARY
written by Irina Kosinovsky 1993
updated by Mitasova Nov. 96
NEEDS UPDATE FOR spatially variable smoothing and other changes
done by Helena in 1997
Note by Irina in 1993: Below is the collection of functions
needed for interpolation programs. It should be
divided into several libraries to provide better
functionality.
DATA STRUCTURES:
----------------
struct interp_params
{
double zmult; /* multiplier for z-values */
FILE *fdinp; /* input stream */
int kmin; /* min number of points per segment for interpolation */
int kmax; /* max number of points per segment */
char *maskmap; /* name of mask */
int nsizr,nsizc; /* number of rows and columns */
double *az,*adx,*ady,*adxx,*adyy,*adxy; /* array for interpolated values */
double fi; /* tension */
int KMAX2; /* max num. of points for interp.*/
int scik1,scik2,scik3; /* multipliers for interp. values*/
double rsm; /* smoothing, for rsm<0 use variable smooth from sites */
char *elev,*slope,*aspect,*pcurv,*tcurv,*mcurv; /* output files */
double dmin; /* min distance between points */
double x_orig, y_orig; /* origin */
int deriv; /* 1 if compute partial derivs */
FILE *Tmp_fd_z,*Tmp_fd_dx,*Tmp_fd_dy, /* temp files for writing interp.*/
*Tmp_fd_xx,*Tmp_fd_yy,*Tmp_fd_xy; /* values */
FILE *fddevi; /* pointer to deviations file */
int (*grid_calc) (); /*calculates grid for given segm*/
int (*matrix_create) (); /*creates matrix for a given segm*/
int (*check_points) (); /*checks interp. func. at points */
int (*secpar) (); /* calculates aspect,slope,curv. */
double (*interp) (); /* radial basis function */
int (*interpder) (); /* derivatives of radial basis function */
int (*wr_temp) (); /* writes temp files */
};
FUNCTIONS:
----------
void
IL_init_params_2d(params,inp,zm,k1,k2,msk,rows,cols,ar1,ar2,ar3,ar4,ar5,ar6,
tension,k3,sc1,sc2,sc3,sm,f1,f2,f3,f4,f5,f6,dm,x_or,y_or,
der,t1,t2,t3,t4,t5,t6,dev)
struct interp_params *params;
FILE *inp; /* input stream */
double zm; /* multiplier for z-values */
int k1; /* min number of points per segment for interpolation */
int k2; /* max number of points per segment */
char *msk; /* name of mask */
int rows,cols; /* number of rows and columns */
double *ar1,*ar2,*ar3,*ar4,*ar5,*ar6; /* arrays for interpolated values */
double tension; /* tension */
int k3; /* max num. of points for interp.*/
int sc1,sc2,sc3; /* multipliers for interp. values*/
double sm; /* smoothing, if sm<0 take it from sites file input */
char *f1,*f2,*f3,*f4,*f5,*f6; /*output files */
double dm; /* min distance between points */
double x_or, y_or; /* origin */
int der; /* 1 if compute partial derivs */
FILE *t1,*t2,*t3,*t4,*t5,*t6; /* temp files for writing interp. values */
FILE *dev; /* pointer to deviations file */
Initializes parameters called by the library
void
IL_init_func_2d(params,grid_f,matr_f,point_f,secp_f,interp_f,
interpder_f,temp_f)
struct interp_params *params;
int (*grid_f) (); /*calculates grid for given segm*/
int (*matr_f) (); /*creates matrix for a given segm*/
int (*point_f) (); /*checks interp. func. at points */
int (*secp_f) (); /* calculates aspect,slope,curv. */
double (*interp_f) (); /* radial basis function*/
int (*interpder_f) (); /* derivatives of radial basis fucntion */
int (*temp_f) (); /* writes temp files */
Initializes functions called by the library
double
IL_crst (r,fi)
double r; /* distance squared*/
double fi; /* tension */
Radial basis function - regularized spline with tension (d=2)
int
IL_crstg (r, fi, gd1, gd2)
double r; /* distance squared*/
double fi; /* tension */
double *gd1;
double *gd2;
Derivatives of radial basis function - regularized spline with tension(d=2)
int
IL_input_data_2d(params,info,xmin,xmax,ymin,ymax,zmin,zmax,MAXPOINTS,n_points)
struct interp_params *params;
struct tree_info *info; /* quadtree info */
double *xmin,*xmax,*ymin,*ymax,*zmin,*zmax;
int maxpoints; /* max number of points per segment for interpolation */
int *n_points; /* number of points used for interpolation */
Inserts input data inside the region into a quad tree.
Also translates data.
Returns number of segments in the quad tree.
int IL_vector_input_data_2d(params,Map,dmax,cats,iselev,info,xmin,
xmax,ymin,ymax,zmin,zmax,n_points)
struct interp_params *params;
struct Map_info *Map; /* input vector file */
double dmax; /* max distance between points */
struct Categories *cats; /* Cats file */
int iselev; /* do zeroes represent elevation? */
struct tree_info *info; /* quadtree info */
double *xmin,*xmax,*ymin,*ymax,*zmin,*zmax;
int *n_points; /* number of points used for interpolation */
Inserts input data inside the region into a quad tree.
Also translates data.
Returns number of segments in the quad tree.
struct BM *
IL_create_bitmask(params)
struct interp_params *params;
Creates a bitmap mask from maskmap raster file and/or current MASK if
present and returns a pointer to the bitmask. If no mask is in force returns
NULL.
int
IL_grid_calc_2d(params,data,bitmask,zmin,zmax,zminac,zmaxac,gmin,gmax,
c1min,c1max,c2min,c2max,ertot,b,offset1)
struct interp_params *params;
struct quaddata *data; /* given segment */
struct BM *bitmask; /* bitmask */
double zmin,zmax; /* min and max input z-values */
double *zminac,*zmaxac, /* min and max interp. z-values */
*gmin,*gmax, /* min and max inperp. slope val.*/
*c1min,*c1max,*c2min,*c2max; /* min and max interp. curv. val.*/
double *ertot; /* rms deviation of the interpolated surface */
double *b; /* solutions of linear equations */
int offset1; /* offset for temp file writing */
Calculates grid for the given segment represented by data (contains n_rows,
n_cols, ew_res,ns_res, and all points inside + overlap) using solutions of
system of lin. equations and interpolating functions interp() and interpder().
Also calls secpar() to compute slope, aspect and curvatures if required.
int
IL_matrix_create(params,points,n_points,matrix,indx)
struct interp_params *params;
struct triple *points; /* points for interpolation */
int n_points; /* number of points */
double **matrix; /* matrix */
int *indx;
Creates system of linear equations represented by matrix using given points
and interpolating function interp()
int
IL_check_at_points_2d (params,n_points,points,b,ertot,zmin)
struct interp_params *params;
int n_points; /* number of points */
struct triple *points; /* points for interpolation */
double *b; /* solution of linear equations */
double *ertot; /* rms deviation of the interpolated surface */
double zmin; /* min z-value */
Checks if interpolating function interp() evaluates correct z-values at given
points. If smoothing is used calculate the maximum and rms deviation caused by smoothing.
int
IL_secpar_loop_2d(params,ngstc,nszc,k,bitmask,gmin,gmax,c1min,c1max,c2min,
c2max,cond1,cond2)
struct interp_params *params;
int ngstc; /* starting column */
int nszc; /* ending column */
int k; /* current row */
struct BM *bitmask;
double *gmin,*gmax,*c1min,*c1max,*c2min,*c2max; /* min,max interp. values */
int cond1,cond2; /*determine if particular values need to be computed*/
Computes slope, aspect and curvatures (depending on cond1, cond2) for derivative
arrays adx,...,adxy between columns ngstc and nszc.
int
IL_write_temp_2d(params,ngstc,nszc,offset2)
struct interp_params *params;
int ngstc,nszc,offset2; /* begin. and end. column, offset */
Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc and
offset) in corresponding temp file */
int
IL_interp_segments_2d (params,info,tree,bitmask,zmin,zmax,zminac,zmaxac,
gmin,gmax,c1min,c1max,c2min,c2max,ertot,totsegm,offset1,dnorm)
struct interp_params *params;
struct tree_info *info; /* info for the quad tree */
struct multtree *tree; /* current leaf of the quad tree */
struct BM *bitmask; /* bitmask */
double zmin,zmax; /* min and max input z-values */
double *zminac,*zmaxac, /* min and max interp. z-values */
*gmin,*gmax, /* min and max inperp. slope val.*/
*c1min,*c1max,*c2min,*c2max; /* min and max interp. curv. val.*/
double *ertot; /* rms deviation of the interpolated surface*/
int totsegm; /* total number of segments */
int offset1; /* offset for temp file writing */
double dnorm; /* normalization factor */
Recursively processes each segment in a tree by
a) finding points from neighbouring segments so that the total number of
points is between KMIN and KMAX2 by calling tree function MT_get_region().
b) creating and solving the system of linear equations using these points
and interp() by calling matrix_create() and G_ludcmp().
c) checking the interpolated values at given points by calling
check_points().
d) computing grid for this segment using points and interp() by calling
grid_calc().
int
IL_interp_segments_new_2d (params,info,tree,bitmask,
zmin,zmax,zminac,zmaxac,gmin,gmax,c1min,c1max,
c2min,c2max,ertot,totsegm,offset1,dnorm)
struct interp_params *params;
struct tree_info *info; /* info for the quad tree */
struct multtree *tree; /* current leaf of the quad tree */
struct BM *bitmask; /* bitmask */
double zmin,zmax; /* min and max input z-values */
double *zminac,*zmaxac, /* min and max interp. z-values */
*gmin,*gmax, /* min and max inperp. slope val.*/
*c1min,*c1max,*c2min,*c2max; /* min and max interp. curv. val.*/
double *ertot; /* rms deviation of the interpolated surface*/
int totsegm; /* total number of segments */
int offset1; /* offset for temp file writing */
double dnorm; /* normalization factor */
The difference between this function and IL_interp_segments_2d() is making
sure that additional points are taken from all directions, i.e. it finds
equal number of points from neigbouring segments in each of 8 neigbourhoods.
Recursively processes each segment in a tree by
a) finding points from neighbouring segments so that the total number of
points is between KMIN and KMAX2 by calling tree function MT_get_region().
b) creating and solving the system of linear equations using these points
and interp() by calling matrix_create() and G_ludcmp().
c) checking the interpolated function values at points by calling
check_points().
d) computing grid for this segment using points and interp() by calling
grid_calc().
int
IL_output_2d (params,cellhd,zmin,zmax,zminac,zmaxac,c1min,c1max,c2min,c2max,
gmin,gmax,ertot,dnorm)
struct interp_params *params;
struct Cell_head *cellhd; /* current region */
double zmin,zmax, /* min,max input z-values */
zminac,zmaxac,c1min,c1max, /* min,max interpolated values */
c2min,c2max,gmin,gmax;
double *ertot; /* rms deviation of the interpolated surface*/
double dnorm; /* normalization factor */
Creates output files as well as history files and color tables for them.
|