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

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:keywords set to Id
File size: 2.2 KB
RevLine 
[59]1;+
2;
[136]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;
[238]8; @categories
[157]9; Without loop
[59]10;
[163]11; @param x1d {in}{required}{type=1d array}
12; the x position on the points
[125]13;
[163]14; @param y1d {in}{required}{type=1d array}
15; the y position on the points
[125]16;
[163]17; @param left {in}{required}{type=1d monotonically increasing array}
[118]18; the position of the "left" border of each cell.
[125]19;
[163]20; @param bottom {in}{required}{type=1d monotonically increasing array}
[118]21; the position of the "bottom" border of each cell.
[59]22;
[125]23; @keyword OUTPUT2D
24; to get the output as a 2d array (2,n_elements(x1d)),
[136]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.
[59]27;
[125]28; @keyword CHECKOUT
29; = [rbgrid,ubgrid] specify the right and upper boundaries of
[136]30; the grid and check if some points are out.
[59]31;
[125]32; @returns
[136]33; the index on the cell according to the 2d array defined by left and bottom.
[59]34;
[125]35; @examples
[59]36;
[371]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
[59]41;            20          13           7
[371]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
[59]44;        0.00000      4.00000
45;        3.00000      2.00000
46;        2.00000      1.00000
[125]47;
[101]48; @history
[125]49; S. Masson (smasson\@lodyc.jussieu.fr)
50; July 3rd, 2002
51; October 3rd, 2003: use value_locate
[118]52;
[231]53; @version
54; $Id$
[118]55;
[59]56;-
[327]57FUNCTION inrecgrid, x1d, y1d, left, bottom $
58                  , 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.