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

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

upgrade of Interpolation according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1;+
2; NAME: inrecgrid
3;
4; PURPOSE: 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; CATEGORY: no DO loop, use the wonderfull value_locate function!
9;
10; CALLING SEQUENCE:res = inrecgrid(xin, yin, left, bottom)
11;
12; INPUTS:
13;
14;    x1d: a 1d array, the x position on the points
15;    y1d: a 1d array, the y position on the points
16;    left: a 1d, monotonically increasing array, the position of the
17;    "left" border of each cell.
18;    bottom: a 1d, monotonically increasing array, the position of the
19;    "bottom" border of each cell.
20;
21; OPTIONAL INPUTS:
22;
23; KEYWORD PARAMETERS:;
24;
25;    /output2d: to get the output as a 2d array (2,n_elements(x1d)),
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;
30;    checkout=[rbgrid,ubgrid] specify the right and upper bondaries of
31;    the grid and check if some points are out.
32;
33; OUTPUTS:the index on the cell accoring to the 2d array defined by
34; left and bottom.
35;
36; OPTIONAL OUTPUTS:
37;
38; COMMON BLOCKS: no
39;
40; SIDE EFFECTS:
41;
42; RESTRICTIONS:
43;
44; PROCEDURE:
45;
46; EXAMPLE:
47;
48;  IDL> a=indgen(5)
49;  IDL> b=indgen(7)
50;  IDL> r=inrecgrid([0.25,3.25,2],[4.25,2.8,1.4],a,b)
51;  IDL> print, r
52;            20          13           7
53;  IDL> r=inrecgrid([0.25,3.25,2],[4.25,2.8,1.4],a,a+1,b,b+1,/output2d)
54;  IDL> print, r
55;        0.00000      4.00000
56;        3.00000      2.00000
57;        2.00000      1.00000
58
59; MODIFICATION HISTORY:
60;            S. Masson (smasson@lodyc.jussieu.fr)
61;                      July 3rd, 2002
62;                      October 3rd, 2003: use value_locate
63;-
64
65FUNCTION inrecgrid, x1d, y1d, left, bottom, output2d = output2d, checkout = checkout
66;
67  ncellx = n_elements(left)
68  ncelly = n_elements(bottom)
69;
70  xpos = value_locate(left[*], x1d[*])
71  ypos = value_locate(bottom[*], y1d[*])
72;
73  IF n_elements(checkout) EQ 2 THEN BEGIN
74    out = where(x1d GT checkout[0])
75    IF out[0] NE -1 THEN xpos[out] = -1
76    out = where(y1d GT checkout[1])
77    IF out[0] NE -1 THEN ypos[out] = -1
78  ENDIF
79;
80  IF keyword_set(output2d) THEN return, [transpose(xpos), transpose(ypos)]
81;
82  IF NOT keyword_set(checkout) THEN RETURN, xpos+ncellx*ypos
83;
84  res = xpos+ncellx*ypos
85  out = where(xpos EQ -1 OR ypos EQ -1)
86  IF out[0] NE -1 THEN res[out] = -1
87
88  RETURN, res
89
90END
Note: See TracBrowser for help on using the repository browser.