source: trunk/ToBeReviewed/MATRICE/inrecgrid.pro.save @ 67

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

miscellaneous modifications according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/

  • Property svn:executable set to *
File size: 4.0 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
9;
10; CALLING SEQUENCE:res = inrecgrid(xin, yin, wb1d, eb1d, sb1d, nb1d)
11;
12; INPUTS:
13;    x1d: a 1d array, the x position on the points
14;    y1d: a 1d array, the y position on the points
15;    wb1d: a 1d sorted array, the position of the "west" border of each cell.
16;    eb1d: a 1d sorted array, the position of the "east" border of each cell.
17;    sb1d: a 1d sorted array, the position of the "south" border of each cell.
18;    nb1d: a 1d sorted array, the position of the "north" border of each cell.
19;    + see RESTRICTIONS part   
20;
21; OPTIONAL INPUTS:
22;
23; KEYWORD PARAMETERS:
24;    /output2d: to the output as a 2d array (2,n_elements(x1d)), with
25;    res[0,*] the x index accoring to the 1d array defined by wb1d or
26;    eb1d and res[1,*] the y index accoring to the 1d array defined by
27;    sb1d or nb1d.
28;
29;    /check: to check if the inputs parameters verify all the test
30;    described in section RESTRICTIONS
31;
32; OUTPUTS:the index on the cell accoring to the 2d array defined by
33; wb1d, eb1d, sb1d and nb1d
34;
35; OPTIONAL OUTPUTS:
36;
37; COMMON BLOCKS: no
38;
39; SIDE EFFECTS:
40;
41; RESTRICTIONS:
42;    x1d and y1d must have the same number of elements
43;    wb1d and eb1d must have the same number of elements
44;    sb1d and nb1d must have the same number of elements
45;    the cells form a 2d array with the size:
46;      n_elements(wb1d)*n_elements(sb1d)
47;    we must have:
48;      total(eb1d le wb1d) eq 0
49;      total(nb1d le sb1d) eq 0
50;      min(wb1d) le min(x1d)
51;      max(eb1d) ge max(x1d)
52;      min(sb1d) le min(y1d)
53;      max(nb1d) ge max(y1d)
54;      total(sort(wb1d) ne lindgen(n_elements(wb1d))) eq 0
55;      total(sort(eb1d) ne lindgen(n_elements(eb1d))) eq 0
56;      total(sort(sb1d) ne lindgen(n_elements(sb1d))) eq 0
57;      total(sort(nb1d) ne lindgen(n_elements(nb1d))) eq 0
58;
59; PROCEDURE:
60;
61; EXAMPLE:
62;
63;  IDL> a=indgen(5)
64;  IDL> b=indgen(7)
65;  IDL> r=inrecgrid([0.25,3.25,2],[4.25,2.8,1.4],a,a+1,b,b+1)
66;  IDL> print, r
67;            20          13           7
68;  IDL> r=inrecgrid([0.25,3.25,2],[4.25,2.8,1.4],a,a+1,b,b+1,/output2d)
69;  IDL> print, r
70;        0.00000      4.00000
71;        3.00000      2.00000
72;        2.00000      1.00000
73
74; MODIFICATION HISTORY:
75;            S. Masson (smasson@lodyc.jussieu.fr)
76;                      July 3rd, 2002
77;-
78
79FUNCTION inrecgrid, x1d, y1d, wb1d, eb1d, sb1d, nb1d, output2d = output2d,  check = check
80; test
81  IF keyword_set(check) THEN BEGIN
82    IF total(eb1d le wb1d) ne 0 then stop
83    IF total(nb1d le sb1d) ne 0 then stop
84    IF min(wb1d) gt min(x1d) then stop
85    IF max(eb1d) lt max(x1d) then stop
86    IF min(sb1d) gt min(y1d) then stop
87    IF max(nb1d) lt max(y1d) then stop
88    IF total(sort(wb1d) ne lindgen(n_elements(wb1d))) ne 0 then stop
89    IF total(sort(eb1d) ne lindgen(n_elements(eb1d))) ne 0 then stop
90    IF total(sort(sb1d) ne lindgen(n_elements(sb1d))) ne 0 then stop
91    IF total(sort(nb1d) ne lindgen(n_elements(nb1d))) ne 0 then stop
92  ENDIF
93;
94  ncellx = n_elements(wb1d)
95  ncelly = n_elements(sb1d)
96  nx = n_elements(x1d)
97  ny = n_elements(y1d)
98; x dimension
99  wb = wb1d[*]#replicate(1, nx)
100  eb = eb1d[*]#replicate(1, nx)
101  x = replicate(1, ncellx)#x1d[*]
102  testx = (temporary(wb) LE x)*(temporary(eb) GT x)
103  x = -1 ; free memory
104  testx = where(temporary(testx) EQ 1)
105  IF n_elements(testx) NE nx THEN BEGIN
106    print, 'One point is out of the grid'
107    stop
108  ENDIF
109  testx = temporary(testx) MOD ncellx
110; y dimension
111  sb = sb1d[*]#replicate(1, ny)
112  nb = nb1d[*]#replicate(1, ny)
113  y = replicate(1, ncelly)#y1d[*]
114  testy = (temporary(sb) LE y)*(temporary(nb) GT y)
115  y = -1 ; free memory
116  testy = where(temporary(testy) EQ 1)
117  IF n_elements(testy) NE ny THEN BEGIN
118    print, 'One point is out of the grid'
119    stop
120  ENDIF
121  testy = temporary(testy) MOD ncelly
122
123  IF keyword_set(output2d) THEN return, [transpose(testx), transpose(testy)] $
124  ELSE RETURN, long(testx)+ncellx*long(testy)
125
126END
Note: See TracBrowser for help on using the repository browser.