1 | ;+ |
---|
2 | ; |
---|
3 | ; ======================== |
---|
4 | ; file_asc_p2l2_to_mem.pro |
---|
5 | ; ======================== |
---|
6 | ; |
---|
7 | ; .. function:: file_asc_p2l2_to_mem(filename) |
---|
8 | ; |
---|
9 | ; Read long station information files and store data in a structure |
---|
10 | ; |
---|
11 | ; :param filename: filename to be read |
---|
12 | ; :type filename: string |
---|
13 | ; :raise filename: required |
---|
14 | ; |
---|
15 | ; :returns: data structure +todo+ details or -1 if error |
---|
16 | ; :rtype: structure +todo+ details |
---|
17 | ; |
---|
18 | ; notes |
---|
19 | ; decalage |
---|
20 | ; xx |
---|
21 | ; |
---|
22 | ; :examples: |
---|
23 | ; |
---|
24 | ; :: |
---|
25 | ; |
---|
26 | ; IDL> filename='/usr/work/incas/fplod/pomme_d/sta.P2L2.asc' |
---|
27 | ; IDL> result=file_asc_p2l2_to_mem(filename) |
---|
28 | ; |
---|
29 | ; impression de contrôle : 1re station, toutes les stations:: |
---|
30 | ; |
---|
31 | ; IDL> help, result,/structure |
---|
32 | ; IDL> print, result[0].station |
---|
33 | ; IDL> print, result.station |
---|
34 | ; |
---|
35 | ; :uses: |
---|
36 | ; |
---|
37 | ; :func:`report` |
---|
38 | ; |
---|
39 | ; :restrictions: |
---|
40 | ; |
---|
41 | ; :todo: |
---|
42 | ; |
---|
43 | ; format fixe |
---|
44 | ; |
---|
45 | ; test existence of filename |
---|
46 | ; |
---|
47 | ; usage of ${POMME_ID} |
---|
48 | ; |
---|
49 | ; :history: |
---|
50 | ; |
---|
51 | ; - fplod 20101123T122132Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
52 | ; |
---|
53 | ; * creation using "Reading Into a Structure" of |
---|
54 | ; http://www.dfanning.com/tips/ascii_column_data.html |
---|
55 | ; |
---|
56 | ; |
---|
57 | ; :version: |
---|
58 | ; |
---|
59 | ; $Id$ |
---|
60 | ; |
---|
61 | ;- |
---|
62 | FUNCTION file_asc_p2l2_to_mem, filename |
---|
63 | ; |
---|
64 | compile_opt idl2, strictarrsubs |
---|
65 | ; |
---|
66 | ; Return to caller if errors |
---|
67 | ON_ERROR, 2 |
---|
68 | ; |
---|
69 | usage = 'result=file_asc_p2l2_to_mem(filename)' |
---|
70 | ; |
---|
71 | nparam = N_PARAMS() |
---|
72 | IF (nparam LT 1) THEN BEGIN |
---|
73 | ras = report(['Incorrect number of arguments.' $ |
---|
74 | + '!C' $ |
---|
75 | + 'Usage : ' + usage]) |
---|
76 | return, -1 |
---|
77 | ENDIF |
---|
78 | ; |
---|
79 | arg_type = size(filename,/type) |
---|
80 | IF (arg_type NE 7) THEN BEGIN |
---|
81 | ras = report(['Incorrect arg type filename' $ |
---|
82 | + '!C' $ |
---|
83 | + 'Usage : ' + usage]) |
---|
84 | return, -1 |
---|
85 | ENDIF |
---|
86 | ; |
---|
87 | arg_dim = size(filename,/n_elements) |
---|
88 | IF (arg_dim LT 1) THEN BEGIN |
---|
89 | ras = report(['Incorrect arg dimension filename' $ |
---|
90 | + '!C' $ |
---|
91 | + 'Usage : ' + usage]) |
---|
92 | return, -1 |
---|
93 | ENDIF |
---|
94 | ; |
---|
95 | ; initialize header |
---|
96 | header = STRARR(1) |
---|
97 | ; |
---|
98 | resultstruct = { station: 0L $ |
---|
99 | , sonde: 0L $ |
---|
100 | , zmax: 0L $ |
---|
101 | , an: 0L $ |
---|
102 | , mm: 0L $ |
---|
103 | , jj: 0L $ |
---|
104 | , hh_begin: 0L $ |
---|
105 | , mm_begin: 0L $ |
---|
106 | , deg_lat_begin : 0L $ |
---|
107 | , mm_lat_begin: 0.0 $ |
---|
108 | , deg_lon_begin: 0L $ |
---|
109 | , mm_lon_begin: 0.0 $ |
---|
110 | , hh_end: 0L $ |
---|
111 | , mm_end: 0L $ |
---|
112 | , deg_lat_end: 0L $ |
---|
113 | , mm_lat_end: 0.0 $ |
---|
114 | , deg_lon_end: 0L $ |
---|
115 | , mm_lon_end: 0.0 $ |
---|
116 | } |
---|
117 | ; |
---|
118 | nrows = file_lines(filename) - N_ELEMENTS(header) |
---|
119 | result = Replicate(resultstruct, nrows) |
---|
120 | ; |
---|
121 | ; open file |
---|
122 | OPENR, lun, filename, /GET_LUN |
---|
123 | ;++ hanlde error |
---|
124 | ; |
---|
125 | ; read header |
---|
126 | READF, lun, header |
---|
127 | ; |
---|
128 | ; read data lines |
---|
129 | READF, lun, result |
---|
130 | ; |
---|
131 | ; close file |
---|
132 | FREE_LUN, lun |
---|
133 | ; |
---|
134 | return, result |
---|
135 | ; |
---|
136 | END |
---|