source: trunk/SRC/Interpolation/cutsegment.pro @ 98

Last change on this file since 98 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: 3.3 KB
Line 
1;+
2; NAME: cutsegment
3;
4; PURPOSE: cut p segments into p*n equal parts
5;
6; CATEGORY: basic work
7;
8; CALLING SEQUENCE: res = cutsegment(x0, y0, x1, y1, n)
9;
10; INPUTS:
11;         x0,y0 and x1,y1, 1d arrays of p elements, the coordinates of
12;         the endpoints of the p segmements
13;         n: the number of pieces we want to cut each segment
14;
15; KEYWORD PARAMETERS:
16;
17;         /endpoints: see ouputs
18;
19;         /onsphere: to specify that the points are located on a
20;         sphere. In this case, x and y corresponds to longitude and
21;         latitude in degrees.
22;
23; OUTPUTS:
24;        defaut: a 3d array (2,n,p) that gives the coordinates of the
25;        middle of the cutted segments.
26;        if /endpoints, a 3d array (2,n+1,p) that gives the
27;        coordinates of the endpoints of the cutted segments.
28;
29; COMMON BLOCKS: no
30;
31; SIDE EFFECTS: no
32;
33; RESTRICTIONS: ?
34;
35; EXAMPLE:
36;
37;  IDL> x0=[2,5]
38;  IDL> y0=[5,1]
39;  IDL> x1=[9,3]
40;  IDL> y1=[1,8]
41;  IDL> res=cutsegment(x0, y0, x1, y1, 10)
42;  IDL> splot, [0,10], [0,10], xstyle = 1, ystyle = 1,/nodata
43;  IDL> oplot, [x0[0], x1[0]], [y0[0], y1[0]]
44;  IDL> oplot, [res[0,*,0]], [res[1,*,0]], color = 20, psym = 1, thick = 3
45;  IDL> oplot, [x0[1], x1[1]], [y0[1], y1[1]]
46;  IDL> oplot, [res[0,*,1]], [res[1,*,1]], color = 40, psym = 1, thick = 3
47;
48; MODIFICATION HISTORY:
49;           S. Masson (smasson@lodyc.jussieu.fr)
50;           July 5th, 2002
51;-
52FUNCTION cutsegment, x0, y0, x1, y1, n, endpoints = endpoints, onsphere = onsphere
53; number of segment
54  nseg = n_elements(x0)
55; number of point to find on each segment
56  n2find = n+keyword_set(endpoints)
57;
58  IF keyword_set(onsphere) THEN BEGIN
59; save the inputs arrays
60    x0in = temporary(x0)
61    y0in = temporary(y0)
62    x1in = temporary(x1)
63    y1in = temporary(y1)
64    sp_cood = [transpose(x0in[*]),transpose(y0in[*]),replicate(1, 1, nseg)]
65    rect_coord = CV_COORD(FROM_SPHERE = temporary(sp_cood), /TO_RECT, /DEGREES)
66    x0 = rect_coord[0, *]
67    y0 = rect_coord[1, *]
68    z0 = rect_coord[2, *]
69    rect_coord = -1 ;free memory
70    sp_cood = [transpose(x1in[*]),transpose(y1in[*]),replicate(1, 1, nseg)]
71    rect_coord = CV_COORD(FROM_SPHERE = temporary(sp_cood), /TO_RECT, /DEGREES)
72    x1 = rect_coord[0, *]
73    y1 = rect_coord[1, *]
74    z1 = rect_coord[2, *]
75    rect_coord = -1 ;free memory
76  ENDIF
77;
78  resx = replicate(1, n2find)#x0[*]
79  resx = temporary(resx)+(1./n*(findgen(n2find) $
80                                +.5*(1-keyword_set(endpoints))))#(x1-x0)[*]
81  resx = (temporary(resx))[*]
82;
83  resy = replicate(1, n2find)#y0[*]
84  resy = temporary(resy)+(1./n*(findgen(n2find) $
85                                +.5*(1-keyword_set(endpoints))))#(y1-y0)[*]
86  resy = (temporary(resy))[*]
87
88  IF keyword_set(onsphere) THEN BEGIN
89    resz = replicate(1, n2find)#z0[*]
90    resz = temporary(resz)+(1./n*(findgen(n2find) $
91                                  +.5*(1-keyword_set(endpoints))))#(z1-z0)[*]
92    resz = (temporary(resz))[*]
93
94    rec_cood = [transpose(temporary(resx)), transpose(temporary(resy)) $
95                , transpose(temporary(resz))]
96    res = CV_COORD(FROM_RECT = temporary(rec_cood), /TO_SPHERE, /DEGREES)
97; restore the input arrays
98    x0 = temporary(x0in)
99    y0 = temporary(y0in)
100    x1 = temporary(x1in)
101    y1 = temporary(y1in)
102  ENDIF ELSE res = [transpose(temporary(resx)), transpose(temporary(resy))]
103
104  res = reform(res[0:1, *], 2, n2find, nseg, /overwrite)
105
106  RETURN, res
107END
Note: See TracBrowser for help on using the repository browser.