source: trunk/src/file_asc_p2l1_to_mem.pro @ 13

Last change on this file since 13 was 13, checked in by pinsard, 10 years ago

fix thanks to coding rules

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1;+
2;
3; ========================
4; file_asc_p2l1_to_mem.pro
5; ========================
6;
7; .. function:: file_asc_p2l1_to_mem(filename)
8;
9;    Read P2L1 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; removed 1 empty line at the end
20;
21; :examples:
22;
23; .. code-block:: idl
24;
25;    filename='/usr/work/incas/fplod/pomme_d/sta.P2L1.asc'
26;    result = file_asc_p2l1_to_mem(filename)
27;
28; impression de controle : 1re station, toutes les stations:
29;
30; .. code-block:: idl
31;
32;    print, result, /structure
33;    print, result[0].station
34;    print, result.station
35;    print, result[0]
36;    print, result[80]
37;
38; :uses:
39;
40; :func:`report <saxo:report>`
41;
42; :see also:
43;
44; :restrictions:
45;
46; :todo:
47;
48; format fixe
49;
50; test existence of filename
51;
52; add sequence using read/write
53;
54; :history:
55;
56; - fplod 20101126T115613Z aedon.locean-ipsl.upmc.fr (Darwin)
57;
58;   * specialized for P2L1
59;
60; - fplod 20101123T125624Z aedon.locean-ipsl.upmc.fr (Darwin)
61;
62;   * creation using "Reading Into a Structure" of
63;     http://www.dfanning.com/tips/ascii_column_data.html
64;
65; :version:
66;
67; $Id$
68;
69;-
70FUNCTION file_asc_p2l1_to_mem, filename
71    ;
72    compile_opt idl2, strictarrsubs
73    ;
74    ; Return to caller if errors
75    ON_ERROR, 2
76    ;
77    usage = 'result = file_asc_p2l1_to_mem(filename)'
78    ;
79    nparam = N_PARAMS()
80    IF (nparam LT 1) THEN BEGIN
81        ras = report(['Incorrect number of arguments.' $
82        + '!C' $
83        + 'Usage : ' + usage])
84        return, -1
85    ENDIF
86    ;
87    arg_type = size(filename,/type)
88    IF (arg_type NE 7) THEN BEGIN
89        ras = report(['Incorrect arg type filename' $
90        + '!C' $
91        + 'Usage : ' + usage])
92        return, -1
93    ENDIF
94    ;
95    arg_dim =  size(filename,/n_elements)
96    IF (arg_dim LT 1) THEN BEGIN
97        ras = report(['Incorrect arg dimension filename' $
98        + '!C' $
99        + 'Usage : ' + usage])
100        return, -1
101    ENDIF
102    ;
103    ; initialize header
104    header = STRARR(1)
105    ;
106    resultstruct = { station: 0L $
107    , sonde: 0L $
108    , zctd: 0L $
109    , an: 0L $
110    , mm: 0L $
111    , jj: 0L $
112    , hh_begin: 0L $
113    , mm_begin: 0L $
114    , lat_begin: 0.0 $
115    , lon_begin: 0.0 $
116    , hh_end: 0L $
117    , mm_end: 0L $
118    , lat_end: 0.0 $
119    , lon_end: 0.0}
120    ;
121    nrows = file_lines(filename) - N_ELEMENTS(header);
122    result = Replicate(resultstruct, nrows)
123    ;
124    ; open file
125    OPENR, lun, filename, /GET_LUN
126    ;++ hanlde error
127    ;
128    ; read header
129    READF, lun, header
130    ;
131    ; read data lines
132    READF, lun, result
133    ;
134    ; close file
135    FREE_LUN, lun
136    ;
137    return, result
138    ;
139END
Note: See TracBrowser for help on using the repository browser.