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

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

improvements of headers (alignments)

  • Property svn:keywords set to Id
File size: 2.2 KB
RevLine 
[59]1;+
2;
[136]3; @file_comments
[372]4; given
5;  - a list of points, (x,y) position
6;  - the x and y limits of a rectangular grid
7;
[125]8; find in which cell is located each given point.
[59]9;
[238]10; @categories
[157]11; Without loop
[59]12;
[163]13; @param x1d {in}{required}{type=1d array}
14; the x position on the points
[125]15;
[163]16; @param y1d {in}{required}{type=1d array}
17; the y position on the points
[125]18;
[163]19; @param left {in}{required}{type=1d monotonically increasing array}
[118]20; the position of the "left" border of each cell.
[125]21;
[163]22; @param bottom {in}{required}{type=1d monotonically increasing array}
[118]23; the position of the "bottom" border of each cell.
[59]24;
[125]25; @keyword OUTPUT2D
26; to get the output as a 2d array (2,n_elements(x1d)),
[136]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.
[59]29;
[125]30; @keyword CHECKOUT
31; = [rbgrid,ubgrid] specify the right and upper boundaries of
[136]32; the grid and check if some points are out.
[59]33;
[125]34; @returns
[136]35; the index on the cell according to the 2d array defined by left and bottom.
[59]36;
[125]37; @examples
[59]38;
[371]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
[371]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)
[372]52;  - July 3rd, 2002
53;  - October 3rd, 2003: use value_locate
[118]54;
[231]55; @version
56; $Id$
[118]57;
[59]58;-
[327]59FUNCTION inrecgrid, x1d, y1d, left, bottom $
60                  , OUTPUT2D=output2d, CHECKOUT=checkout
[59]61;
[114]62  compile_opt idl2, strictarrsubs
63;
[59]64  ncellx = n_elements(left)
65  ncelly = n_elements(bottom)
66;
67  xpos = value_locate(left[*], x1d[*])
68  ypos = value_locate(bottom[*], y1d[*])
69;
70  IF n_elements(checkout) EQ 2 THEN BEGIN
71    out = where(x1d GT checkout[0])
72    IF out[0] NE -1 THEN xpos[out] = -1
73    out = where(y1d GT checkout[1])
74    IF out[0] NE -1 THEN ypos[out] = -1
75  ENDIF
76;
77  IF keyword_set(output2d) THEN return, [transpose(xpos), transpose(ypos)]
78;
79  IF NOT keyword_set(checkout) THEN RETURN, xpos+ncellx*ypos
80;
81  res = xpos+ncellx*ypos
82  out = where(xpos EQ -1 OR ypos EQ -1)
83  IF out[0] NE -1 THEN res[out] = -1
[125]84;
[59]85  RETURN, res
86
87END
Note: See TracBrowser for help on using the repository browser.