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

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

header improvements + xxx doc

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