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

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

correction of some *.pro using aspell list; introduction of default idldoc syntax

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