DESCRIPTION.INTERP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. DESCRIPTION OF INTERPOLATION LIBRARY
  2. written by Irina Kosinovsky 1993
  3. updated by Mitasova Nov. 96
  4. NEEDS UPDATE FOR spatially variable smoothing and other changes
  5. done by Helena in 1997
  6. Note by Irina in 1993: Below is the collection of functions
  7. needed for interpolation programs. It should be
  8. divided into several libraries to provide better
  9. functionality.
  10. DATA STRUCTURES:
  11. ----------------
  12. struct interp_params
  13. {
  14. double zmult; /* multiplier for z-values */
  15. FILE *fdinp; /* input stream */
  16. int kmin; /* min number of points per segment for interpolation */
  17. int kmax; /* max number of points per segment */
  18. char *maskmap; /* name of mask */
  19. int nsizr,nsizc; /* number of rows and columns */
  20. double *az,*adx,*ady,*adxx,*adyy,*adxy; /* array for interpolated values */
  21. double fi; /* tension */
  22. int KMAX2; /* max num. of points for interp.*/
  23. int scik1,scik2,scik3; /* multipliers for interp. values*/
  24. double rsm; /* smoothing, for rsm<0 use variable smooth from sites */
  25. char *elev,*slope,*aspect,*pcurv,*tcurv,*mcurv; /* output files */
  26. double dmin; /* min distance between points */
  27. double x_orig, y_orig; /* origin */
  28. int deriv; /* 1 if compute partial derivs */
  29. FILE *Tmp_fd_z,*Tmp_fd_dx,*Tmp_fd_dy, /* temp files for writing interp.*/
  30. *Tmp_fd_xx,*Tmp_fd_yy,*Tmp_fd_xy; /* values */
  31. FILE *fddevi; /* pointer to deviations file */
  32. int (*grid_calc) (); /*calculates grid for given segm*/
  33. int (*matrix_create) (); /*creates matrix for a given segm*/
  34. int (*check_points) (); /*checks interp. func. at points */
  35. int (*secpar) (); /* calculates aspect,slope,curv. */
  36. double (*interp) (); /* radial basis function */
  37. int (*interpder) (); /* derivatives of radial basis function */
  38. int (*wr_temp) (); /* writes temp files */
  39. int c, /* cross validation */
  40. char *wheresql /* SQL WHERE */
  41. };
  42. FUNCTIONS:
  43. ----------
  44. void
  45. IL_init_params_2d(params,inp,zm,k1,k2,msk,rows,cols,ar1,ar2,ar3,ar4,ar5,ar6,
  46. tension,k3,sc1,sc2,sc3,sm,f1,f2,f3,f4,f5,f6,dm,x_or,y_or,
  47. der,t1,t2,t3,t4,t5,t6,dev)
  48. struct interp_params *params;
  49. FILE *inp; /* input stream */
  50. double zm; /* multiplier for z-values */
  51. int k1; /* min number of points per segment for interpolation */
  52. int k2; /* max number of points per segment */
  53. char *msk; /* name of mask */
  54. int rows,cols; /* number of rows and columns */
  55. double *ar1,*ar2,*ar3,*ar4,*ar5,*ar6; /* arrays for interpolated values */
  56. double tension; /* tension */
  57. int k3; /* max num. of points for interp.*/
  58. int sc1,sc2,sc3; /* multipliers for interp. values*/
  59. double sm; /* smoothing, if sm<0 take it from sites file input */
  60. char *f1,*f2,*f3,*f4,*f5,*f6; /*output files */
  61. double dm; /* min distance between points */
  62. double x_or, y_or; /* origin */
  63. int der; /* 1 if compute partial derivs */
  64. FILE *t1,*t2,*t3,*t4,*t5,*t6; /* temp files for writing interp. values */
  65. FILE *dev; /* pointer to deviations file */
  66. Initializes parameters called by the library
  67. void
  68. IL_init_func_2d(params,grid_f,matr_f,point_f,secp_f,interp_f,
  69. interpder_f,temp_f)
  70. struct interp_params *params;
  71. int (*grid_f) (); /*calculates grid for given segm*/
  72. int (*matr_f) (); /*creates matrix for a given segm*/
  73. int (*point_f) (); /*checks interp. func. at points */
  74. int (*secp_f) (); /* calculates aspect,slope,curv. */
  75. double (*interp_f) (); /* radial basis function*/
  76. int (*interpder_f) (); /* derivatives of radial basis fucntion */
  77. int (*temp_f) (); /* writes temp files */
  78. Initializes functions called by the library
  79. double
  80. IL_crst (r,fi)
  81. double r; /* distance squared*/
  82. double fi; /* tension */
  83. Radial basis function - regularized spline with tension (d=2)
  84. int
  85. IL_crstg (r, fi, gd1, gd2)
  86. double r; /* distance squared*/
  87. double fi; /* tension */
  88. double *gd1;
  89. double *gd2;
  90. Derivatives of radial basis function - regularized spline with tension(d=2)
  91. int
  92. IL_input_data_2d(params,info,xmin,xmax,ymin,ymax,zmin,zmax,MAXPOINTS,n_points)
  93. struct interp_params *params;
  94. struct tree_info *info; /* quadtree info */
  95. double *xmin,*xmax,*ymin,*ymax,*zmin,*zmax;
  96. int maxpoints; /* max number of points per segment for interpolation */
  97. int *n_points; /* number of points used for interpolation */
  98. Inserts input data inside the region into a quad tree.
  99. Also translates data.
  100. Returns number of segments in the quad tree.
  101. int IL_vector_input_data_2d(params,Map,dmax,cats,iselev,info,xmin,
  102. xmax,ymin,ymax,zmin,zmax,n_points)
  103. struct interp_params *params;
  104. struct Map_info *Map; /* input vector file */
  105. double dmax; /* max distance between points */
  106. struct Categories *cats; /* Cats file */
  107. int iselev; /* do zeroes represent elevation? */
  108. struct tree_info *info; /* quadtree info */
  109. double *xmin,*xmax,*ymin,*ymax,*zmin,*zmax;
  110. int *n_points; /* number of points used for interpolation */
  111. Inserts input data inside the region into a quad tree.
  112. Also translates data.
  113. Returns number of segments in the quad tree.
  114. struct BM *
  115. IL_create_bitmask(params)
  116. struct interp_params *params;
  117. Creates a bitmap mask from maskmap raster file and/or current MASK if
  118. present and returns a pointer to the bitmask. If no mask is in force returns
  119. NULL.
  120. int
  121. IL_grid_calc_2d(params,data,bitmask,zmin,zmax,zminac,zmaxac,gmin,gmax,
  122. c1min,c1max,c2min,c2max,ertot,b,offset1)
  123. struct interp_params *params;
  124. struct quaddata *data; /* given segment */
  125. struct BM *bitmask; /* bitmask */
  126. double zmin,zmax; /* min and max input z-values */
  127. double *zminac,*zmaxac, /* min and max interp. z-values */
  128. *gmin,*gmax, /* min and max inperp. slope val.*/
  129. *c1min,*c1max,*c2min,*c2max; /* min and max interp. curv. val.*/
  130. double *ertot; /* rms deviation of the interpolated surface */
  131. double *b; /* solutions of linear equations */
  132. int offset1; /* offset for temp file writing */
  133. Calculates grid for the given segment represented by data (contains n_rows,
  134. n_cols, ew_res,ns_res, and all points inside + overlap) using solutions of
  135. system of lin. equations and interpolating functions interp() and interpder().
  136. Also calls secpar() to compute slope, aspect and curvatures if required.
  137. int
  138. IL_matrix_create(params,points,n_points,matrix,indx)
  139. struct interp_params *params;
  140. struct triple *points; /* points for interpolation */
  141. int n_points; /* number of points */
  142. double **matrix; /* matrix */
  143. int *indx;
  144. Creates system of linear equations represented by matrix using given points
  145. and interpolating function interp()
  146. int
  147. IL_check_at_points_2d (params,n_points,points,b,ertot,zmin)
  148. struct interp_params *params;
  149. int n_points; /* number of points */
  150. struct triple *points; /* points for interpolation */
  151. double *b; /* solution of linear equations */
  152. double *ertot; /* rms deviation of the interpolated surface */
  153. double zmin; /* min z-value */
  154. Checks if interpolating function interp() evaluates correct z-values at given
  155. points. If smoothing is used calculate the maximum and rms deviation caused by smoothing.
  156. int
  157. IL_secpar_loop_2d(params,ngstc,nszc,k,bitmask,gmin,gmax,c1min,c1max,c2min,
  158. c2max,cond1,cond2)
  159. struct interp_params *params;
  160. int ngstc; /* starting column */
  161. int nszc; /* ending column */
  162. int k; /* current row */
  163. struct BM *bitmask;
  164. double *gmin,*gmax,*c1min,*c1max,*c2min,*c2max; /* min,max interp. values */
  165. int cond1,cond2; /*determine if particular values need to be computed*/
  166. Computes slope, aspect and curvatures (depending on cond1, cond2) for derivative
  167. arrays adx,...,adxy between columns ngstc and nszc.
  168. int
  169. IL_write_temp_2d(params,ngstc,nszc,offset2)
  170. struct interp_params *params;
  171. int ngstc,nszc,offset2; /* begin. and end. column, offset */
  172. Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc and
  173. offset) in corresponding temp file */
  174. int
  175. IL_interp_segments_2d (params,info,tree,bitmask,zmin,zmax,zminac,zmaxac,
  176. gmin,gmax,c1min,c1max,c2min,c2max,ertot,totsegm,offset1,dnorm)
  177. struct interp_params *params;
  178. struct tree_info *info; /* info for the quad tree */
  179. struct multtree *tree; /* current leaf of the quad tree */
  180. struct BM *bitmask; /* bitmask */
  181. double zmin,zmax; /* min and max input z-values */
  182. double *zminac,*zmaxac, /* min and max interp. z-values */
  183. *gmin,*gmax, /* min and max inperp. slope val.*/
  184. *c1min,*c1max,*c2min,*c2max; /* min and max interp. curv. val.*/
  185. double *ertot; /* rms deviation of the interpolated surface*/
  186. int totsegm; /* total number of segments */
  187. int offset1; /* offset for temp file writing */
  188. double dnorm; /* normalization factor */
  189. Recursively processes each segment in a tree by
  190. a) finding points from neighbouring segments so that the total number of
  191. points is between KMIN and KMAX2 by calling tree function MT_get_region().
  192. b) creating and solving the system of linear equations using these points
  193. and interp() by calling matrix_create() and G_ludcmp().
  194. c) checking the interpolated values at given points by calling
  195. check_points().
  196. d) computing grid for this segment using points and interp() by calling
  197. grid_calc().
  198. int
  199. IL_interp_segments_new_2d (params,info,tree,bitmask,
  200. zmin,zmax,zminac,zmaxac,gmin,gmax,c1min,c1max,
  201. c2min,c2max,ertot,totsegm,offset1,dnorm)
  202. struct interp_params *params;
  203. struct tree_info *info; /* info for the quad tree */
  204. struct multtree *tree; /* current leaf of the quad tree */
  205. struct BM *bitmask; /* bitmask */
  206. double zmin,zmax; /* min and max input z-values */
  207. double *zminac,*zmaxac, /* min and max interp. z-values */
  208. *gmin,*gmax, /* min and max inperp. slope val.*/
  209. *c1min,*c1max,*c2min,*c2max; /* min and max interp. curv. val.*/
  210. double *ertot; /* rms deviation of the interpolated surface*/
  211. int totsegm; /* total number of segments */
  212. int offset1; /* offset for temp file writing */
  213. double dnorm; /* normalization factor */
  214. The difference between this function and IL_interp_segments_2d() is making
  215. sure that additional points are taken from all directions, i.e. it finds
  216. equal number of points from neigbouring segments in each of 8 neigbourhoods.
  217. Recursively processes each segment in a tree by
  218. a) finding points from neighbouring segments so that the total number of
  219. points is between KMIN and KMAX2 by calling tree function MT_get_region().
  220. b) creating and solving the system of linear equations using these points
  221. and interp() by calling matrix_create() and G_ludcmp().
  222. c) checking the interpolated function values at points by calling
  223. check_points().
  224. d) computing grid for this segment using points and interp() by calling
  225. grid_calc().
  226. int
  227. IL_output_2d (params,cellhd,zmin,zmax,zminac,zmaxac,c1min,c1max,c2min,c2max,
  228. gmin,gmax,ertot,dnorm)
  229. struct interp_params *params;
  230. struct Cell_head *cellhd; /* current region */
  231. double zmin,zmax, /* min,max input z-values */
  232. zminac,zmaxac,c1min,c1max, /* min,max interpolated values */
  233. c2min,c2max,gmin,gmax;
  234. double *ertot; /* rms deviation of the interpolated surface*/
  235. double dnorm; /* normalization factor */
  236. Creates output files as well as history files and color tables for them.