File: griddata.m

package info (click to toggle)
plplot 5.3.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 26,248 kB
  • ctags: 11,687
  • sloc: ansic: 86,045; xml: 17,249; sh: 12,400; tcl: 8,113; cpp: 6,824; perl: 4,383; python: 3,915; makefile: 2,899; java: 2,788; fortran: 290; sed: 5; awk: 1
file content (91 lines) | stat: -rw-r--r-- 2,801 bytes parent folder | download | duplicates (3)
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
## Copyright (C) 2003 Joao Cardoso.
## 
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## This file is part of plplot_octave.

## usage: zg = griddata(x, y, z, xg, yg [,method [, arg]])
##
## griddata takes irregularly sampled data from three input arrays
##    x[npts], y[npts], and z[npts], reads the desired grid location from
##   input arrays xg[nptsx] and yg[nptsy], and returns the gridded data 
##   into output array zg[nptsx][nptsy].
##
##   The algorithm used to grid the data is specified with the argument 
##   method. The algorithm  can use argument arg. 
##   The available(*) algorithms are:
##
##         GRID_CSA: Bivariate Cubic Spline approximation
##         GRID_DTLI: Delaunay Triangulation Linear Interpolation 
##         GRID_NNI: Natural Neighbors Interpolation 
##         GRID_NNIDW: Nearest Neighbors Inverse Distance Weighted
##         GRID_NNLI: Nearest Neighbors Linear Interpolation 
##         GRID_NNAIDW:  Nearest Neighbors Around Inverse Distance Weighted (default) 
##
##   Some algorithms can generate NaNs, and as PLplot is not NaN aware the
##   returned data must be treated before being plotted, e.g., zg(isnan (zg)) = 0;
##
##   (*) Some algorithms might not be present in your system, depending
##    on the availability of the QHull library.
##    GRID_CSA, GRID_DTLI and GRID_NNI use the csa and nn library from 
##    Pavel Sakof, http://www.marine.csiro.au/~sakov/

function  zg = griddata(x, y, z, xg, yg, method, arg)

  __pl_init;

  global GRID_CSA GRID_DTLI GRID_NNI GRID_NNIDW GRID_NNLI GRID_NNAIDW

  if (nargin < 5)
    help griddata
    return;
  endif

  if (is_vector(x) && is_vector(y) && is_vector(z) &&
      is_vector(xg) && is_vector(yg))
    
    [err, x, y, z] = common_size(x, y, z);
    if (err)
      help griddata
      return;
    endif

    if (nargin == 5)
      method = GRID_NNAIDW;
      arg = 15;
    elseif (nargin == 6)
      arg = 0;
    endif

    if (! any(method == [GRID_CSA GRID_DTLI GRID_NNI GRID_NNIDW GRID_NNLI GRID_NNAIDW]))
      help griddata
      return
    endif

    if (rows(xg) == 1)
      xg = xg';
    endif

    if (rows(yg) == 1)
      yg = yg';
    endif

    zg = plgriddata(x, y, z, xg, yg, method, arg);
    ##if (any(any(isnan(zg))))
    ##  warning("griddata: NaNs returned.");
    ##endif

  else
    help griddata
    return
  endif 

endfunction