1 | ;+ |
---|
2 | ; |
---|
3 | ; ================ |
---|
4 | ; file_prn2mem.pro |
---|
5 | ; ================ |
---|
6 | ; |
---|
7 | ; .. function:: file_prn2mem(filename) |
---|
8 | ; |
---|
9 | ; Read in situ MLD files and store data in a structure |
---|
10 | ; |
---|
11 | ; nb : mld float to handle NaN in file |
---|
12 | ; ++ NaN dans les colonnes entier transformés en 0 par la lecture |
---|
13 | ; |
---|
14 | ; :param filename: filename to be read |
---|
15 | ; :type filename: string |
---|
16 | ; :raise filename: required |
---|
17 | ; |
---|
18 | ; :returns: data structure +todo+ details or -1 if error |
---|
19 | ; :rtype: structure +todo+ details |
---|
20 | ; |
---|
21 | ; :examples: |
---|
22 | ; |
---|
23 | ; .. code-block:: idl |
---|
24 | ; |
---|
25 | ; filename='/usr/temp/marina/POM/mld_prieur_P1L1.prn' |
---|
26 | ; result = file_prn2mem(filename) |
---|
27 | ; |
---|
28 | ; filename='/usr/temp/marina/POM/mld_prieur_P1L2_tot.prn' |
---|
29 | ; result = file_prn2mem(filename) |
---|
30 | ; |
---|
31 | ; filename='/usr/temp/marina/POM/mld_prieur_P2L1.prn' |
---|
32 | ; result = file_prn2mem(filename) |
---|
33 | ; |
---|
34 | ; filename='/usr/temp/marina/POM/mld_prieur_P2L2.prn' |
---|
35 | ; result = file_prn2mem(filename) |
---|
36 | ; |
---|
37 | ; filename='/usr/temp/marina/POM/mld_prieur_P1L2_tot.prn' |
---|
38 | ; result = file_prn2mem(filename) |
---|
39 | ; |
---|
40 | ; impression de contrÃŽle : 1re station, toutes les stations: |
---|
41 | ; |
---|
42 | ; .. code-block:: idl |
---|
43 | ; |
---|
44 | ; help, result, /structure |
---|
45 | ; print, result[0].station |
---|
46 | ; print, result.station |
---|
47 | ; print, result[0].zhomelch |
---|
48 | ; print, result[nrows - 1].zhomelch |
---|
49 | ; |
---|
50 | ; :uses: |
---|
51 | ; |
---|
52 | ; :func:`report <saxo:report>` |
---|
53 | ; |
---|
54 | ; :see also: |
---|
55 | ; |
---|
56 | ; :func:`file_prn_to_mem` |
---|
57 | ; |
---|
58 | ; :restrictions: |
---|
59 | ; |
---|
60 | ; :todo: |
---|
61 | ; |
---|
62 | ; format fixe |
---|
63 | ; |
---|
64 | ; test existence of filename |
---|
65 | ; |
---|
66 | ; :history: |
---|
67 | ; |
---|
68 | ; - fplod 20101123T134447Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
69 | ; |
---|
70 | ; * creation using "Reading Into a Structure" of |
---|
71 | ; http://www.dfanning.com/tips/ascii_column_data.html |
---|
72 | ; |
---|
73 | ; :version: |
---|
74 | ; |
---|
75 | ; $Id$ |
---|
76 | ; |
---|
77 | ;- |
---|
78 | FUNCTION file_prn2mem, filename |
---|
79 | ; |
---|
80 | compile_opt idl2, strictarrsubs |
---|
81 | ; |
---|
82 | ; Return to caller if errors |
---|
83 | ON_ERROR, 2 |
---|
84 | ; |
---|
85 | usage = 'result = file_prn2mem(filename) |
---|
86 | ; |
---|
87 | nparam = N_PARAMS() |
---|
88 | IF (nparam LT 1) THEN BEGIN |
---|
89 | ras = report(['Incorrect number of arguments.' $ |
---|
90 | + '!C' $ |
---|
91 | + 'Usage : ' + usage]) |
---|
92 | return, -1 |
---|
93 | ENDIF |
---|
94 | ; |
---|
95 | arg_type = size(filename,/type) |
---|
96 | IF (arg_type NE 7) THEN BEGIN |
---|
97 | ras = report(['Incorrect arg type filename' $ |
---|
98 | + '!C' $ |
---|
99 | + 'Usage : ' + usage]) |
---|
100 | return, -1 |
---|
101 | ENDIF |
---|
102 | ; |
---|
103 | arg_dim = size(filename,/n_elements) |
---|
104 | IF (arg_dim LT 1) THEN BEGIN |
---|
105 | ras = report(['Incorrect arg dimension filename' $ |
---|
106 | + '!C' $ |
---|
107 | + 'Usage : ' + usage]) |
---|
108 | return, -1 |
---|
109 | ENDIF |
---|
110 | ; |
---|
111 | ; initialize header |
---|
112 | header = STRARR(3) |
---|
113 | ; |
---|
114 | resultstruct = { station: 0L $ |
---|
115 | , doy: 0.0 $ |
---|
116 | , zm: 0L $ |
---|
117 | , fluo: 0.0 $ |
---|
118 | , zfluo: 0.0 $ |
---|
119 | , fluosurfac: 0.0 $ |
---|
120 | , zhom001: 0.0 $ |
---|
121 | , zhom002 : 0.0 $ |
---|
122 | , zhom005 : 0.0 $ |
---|
123 | , zhom010: 0.0 $ |
---|
124 | , zhomelch : 0.0 $ |
---|
125 | } |
---|
126 | ; |
---|
127 | nrows = file_lines(filename) - N_ELEMENTS(header) |
---|
128 | result = Replicate(resultstruct, nrows) |
---|
129 | ; |
---|
130 | ; open file |
---|
131 | OPENR, lun, filename, /GET_LUN |
---|
132 | ;++ handle error |
---|
133 | ; |
---|
134 | ; read header |
---|
135 | READF, lun, header |
---|
136 | ; |
---|
137 | ; read data lines |
---|
138 | READF, lun, result |
---|
139 | ; |
---|
140 | ; close file |
---|
141 | FREE_LUN, lun |
---|
142 | ; |
---|
143 | return, result |
---|
144 | ; |
---|
145 | END |
---|