source: trunk/SRC/Interpolation/inrecgrid.pro @ 121

Last change on this file since 121 was 121, checked in by pinsard, 18 years ago

correction of some *.pro using aspell list; introduction of default idldoc syntax

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1;+
2;
3; @file_comments given - a list of points, (x,y) position 
4;                - the x and y limits of a rectangular grid
5;          find in which cell is located each given point.
6;
7; @categories no DO loop, use the wonderfull value_locate function!
8;
9; @param x1d {in}{required}  a 1d array, the x position on the points
10; @param y1d {in}{required}  a 1d array, the y position on the points
11; @param left {in}{required} a 1d, monotonically increasing array,
12; the position of the "left" border of each cell.
13; @param bottom {in}{required}  a 1d, monotonically increasing array,
14; the position of the "bottom" border of each cell.
15;
16; @keyword /output2d to get the output as a 2d array (2,n_elements(x1d)),
17;    with res[0,*] the x index accoring to the 1d array defined by
18;    left and res[1,*] the y index accoring to the 1d array defined by
19;    bottom.
20;
21; @keyword checkout=[rbgrid,ubgrid] specify the right and upper bondaries of
22;    the grid and check if some points are out.
23;
24; @returns the index on the cell accoring to the 2d array defined by
25; left and bottom.
26;
27; @examples
28;
29;  IDL> a=indgen(5)
30;  IDL> b=indgen(7)
31;  IDL> r=inrecgrid([0.25,3.25,2],[4.25,2.8,1.4],a,b)
32;  IDL> print, r
33;            20          13           7
34;  IDL> r=inrecgrid([0.25,3.25,2],[4.25,2.8,1.4],a,a+1,b,b+1,/output2d)
35;  IDL> print, r
36;        0.00000      4.00000
37;        3.00000      2.00000
38;        2.00000      1.00000
39
40; @history
41;            S. Masson (smasson\@lodyc.jussieu.fr)
42;                      July 3rd, 2002
43;                      October 3rd, 2003: use value_locate
44;
45; @version $Id$
46;
47;-
48
49FUNCTION inrecgrid, x1d, y1d, left, bottom, output2d = output2d, checkout = checkout
50;
51  compile_opt idl2, strictarrsubs
52;
53  ncellx = n_elements(left)
54  ncelly = n_elements(bottom)
55;
56  xpos = value_locate(left[*], x1d[*])
57  ypos = value_locate(bottom[*], y1d[*])
58;
59  IF n_elements(checkout) EQ 2 THEN BEGIN
60    out = where(x1d GT checkout[0])
61    IF out[0] NE -1 THEN xpos[out] = -1
62    out = where(y1d GT checkout[1])
63    IF out[0] NE -1 THEN ypos[out] = -1
64  ENDIF
65;
66  IF keyword_set(output2d) THEN return, [transpose(xpos), transpose(ypos)]
67;
68  IF NOT keyword_set(checkout) THEN RETURN, xpos+ncellx*ypos
69;
70  res = xpos+ncellx*ypos
71  out = where(xpos EQ -1 OR ypos EQ -1)
72  IF out[0] NE -1 THEN res[out] = -1
73
74  RETURN, res
75
76END
Note: See TracBrowser for help on using the repository browser.