source: trunk/procs/extract_str.pro @ 205

Last change on this file since 205 was 196, checked in by pinsard, 14 years ago

complete param and keyword in headers

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1;+
2;
3; extract sub-string of line that is between char1 and char2
4;
5; @categories
6; String
7;
8; @param LINE {in}{required}{type=string}
9; string to be exam
10;
11; @param CHAR1 {in}{required}{type=string}
12; first character of the substring to
13; be extracted from LINE
14;
15; @param CHAR2 {in}{required}{type=string}
16; last character of the substring to
17; be extracted from LINE
18;
19; @returns
20; -1 in case of error
21;
22; @examples
23;
24; IDL> line='A1234B678'
25; IDL> char1='A'
26; IDL> char2='B'
27; IDL> result=extract_str(line, char1, char2)
28; IDL> print, result
29; 1234
30;
31; @history
32;
33; - fplod 20091208T165219Z aedon.locean-ipsl.upmc.fr (Darwin)
34;
35;   * check parameters
36;
37; @version
38; $Id$
39;
40;-
41FUNCTION extract_str, line, char1, char2
42;
43  compile_opt idl2, strictarrsubs
44;
45; Return to caller if errors
46 ON_ERROR, 2
47;
48 usage='result=extract_str(line, char1, char2)'
49;
50 nparam = N_PARAMS()
51 IF (nparam LT 3) THEN BEGIN
52    ras = report(['Incorrect number of arguments.' $
53          + '!C' $
54          + 'Usage : ' + usage])
55    mn = '???'
56    return, mn
57 ENDIF
58;
59 arg_type = size(line,/type)
60 IF (arg_type NE 7) THEN BEGIN
61   ras = report(['Incorrect arg type line' $
62          + '!C' $
63          + 'Usage : ' + usage])
64   return, -1
65 ENDIF
66;
67 arg_type = size(char1,/type)
68 IF (arg_type NE 7) THEN BEGIN
69   ras = report(['Incorrect arg type char1' $
70          + '!C' $
71          + 'Usage : ' + usage])
72   return, -1
73 ENDIF
74
75 arg_type = size(char2,/type)
76 print, arg_type
77 IF (arg_type NE 7) THEN BEGIN
78   ras = report(['Incorrect arg type char2' $
79          + '!C' $
80          + 'Usage : ' + usage])
81   return, -1
82 ENDIF
83
84
85   pos_char1 = strpos(line,char1)
86   pos_char2 = strpos(line,char2)
87   lenght_to_extract = pos_char2-pos_char1-1
88
89   IF lenght_to_extract LE 0 THEN BEGIN
90      print, 'No sub-string in ', line, ' between in : ', char1, char2
91      return, -1
92   ENDIF
93
94   return, STRMID(line, pos_char1+1, lenght_to_extract)
95END
Note: See TracBrowser for help on using the repository browser.