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

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

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:keywords set to Id
File size: 2.2 KB
RevLine 
[59]1;+
2;
[125]3; @file_comments
[133]4; given - a list of points, (x,y) position
[125]5;       - the x and y limits of a rectangular grid
6; find in which cell is located each given point.
[59]7;
[101]8; @categories no DO loop, use the wonderfull value_locate function!
[59]9;
[125]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,
[118]18; the position of the "left" border of each cell.
[125]19;
20; @param bottom {in}{required}
21; a 1d, monotonically increasing array,
[118]22; the position of the "bottom" border of each cell.
[59]23;
[125]24; @keyword OUTPUT2D
25; to get the output as a 2d array (2,n_elements(x1d)),
[59]26;    with res[0,*] the x index accoring to the 1d array defined by
27;    left and res[1,*] the y index accoring to the 1d array defined by
28;    bottom.
29;
[125]30; @keyword CHECKOUT
31; = [rbgrid,ubgrid] specify the right and upper boundaries of
[59]32;    the grid and check if some points are out.
33;
[125]34; @returns
35; the index on the cell accoring to the 2d array defined by left and bottom.
[59]36;
[125]37; @examples
[59]38;
[125]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
[59]43;            20          13           7
[125]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
[59]46;        0.00000      4.00000
47;        3.00000      2.00000
48;        2.00000      1.00000
[125]49;
[101]50; @history
[125]51; S. Masson (smasson\@lodyc.jussieu.fr)
52; July 3rd, 2002
53; October 3rd, 2003: use value_locate
[118]54;
55; @version $Id$
56;
[59]57;-
[125]58FUNCTION inrecgrid, x1d, y1d, left, bottom, OUTPUT2D = output2d, CHECKOUT = checkout
[59]59;
[114]60  compile_opt idl2, strictarrsubs
61;
[59]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
[125]82;
[59]83  RETURN, res
84
85END
Note: See TracBrowser for help on using the repository browser.