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

Last change on this file since 228 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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