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

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

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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