source: trunk/src/file_asc_p2l2_to_mem.pro

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

fix thanks to coding rules; typo; dupe empty lines

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
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; décalage
20; xx
21;
22; :examples:
23;
24; .. code-block:: idl
25;
26;    filename='/usr/work/incas/fplod/pomme_d/sta.P2L2.asc'
27;    result = file_asc_p2l2_to_mem(filename)
28;
29; impression de contrÃŽle : 1re station, toutes les stations:
30;
31; .. code-block:: idl
32;
33;    help, result,/structure
34;    print, result[0].station
35;    print, result.station
36;
37; :uses:
38;
39; :func:`report <saxo:report>`
40;
41; :restrictions:
42;
43; :todo:
44;
45; format fixe
46;
47; test existence of filename
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; :version:
57;
58; $Id$
59;
60;-
61FUNCTION file_asc_p2l2_to_mem, filename
62    ;
63    compile_opt idl2, strictarrsubs
64    ;
65    ; Return to caller if errors
66    ON_ERROR, 2
67    ;
68    usage = 'result = file_asc_p2l2_to_mem(filename)'
69    ;
70    nparam = N_PARAMS()
71    IF (nparam LT 1) THEN BEGIN
72        ras = report(['Incorrect number of arguments.' $
73        + '!C' $
74        + 'Usage : ' + usage])
75        return, -1
76    ENDIF
77    ;
78    arg_type = size(filename,/type)
79    IF (arg_type NE 7) THEN BEGIN
80        ras = report(['Incorrect arg type filename' $
81        + '!C' $
82        + 'Usage : ' + usage])
83        return, -1
84    ENDIF
85    ;
86    arg_dim =  size(filename,/n_elements)
87    IF (arg_dim LT 1) THEN BEGIN
88        ras = report(['Incorrect arg dimension filename' $
89        + '!C' $
90        + 'Usage : ' + usage])
91        return, -1
92    ENDIF
93    ;
94    ; initialize header
95    header = STRARR(1)
96    ;
97    resultstruct = { station: 0L $
98    , sonde: 0L $
99    , zmax: 0L $
100    , an: 0L $
101    , mm: 0L $
102    , jj: 0L $
103    , hh_begin: 0L $
104    , mm_begin: 0L $
105    , deg_lat_begin : 0L $
106    , mm_lat_begin: 0.0 $
107    , deg_lon_begin: 0L $
108    , mm_lon_begin: 0.0 $
109    , hh_end: 0L $
110    , mm_end: 0L $
111    , deg_lat_end: 0L $
112    , mm_lat_end: 0.0 $
113    , deg_lon_end: 0L $
114    , mm_lon_end: 0.0 $
115    }
116    ;
117    nrows = file_lines(filename) - N_ELEMENTS(header)
118    result = Replicate(resultstruct, nrows)
119    ;
120    ; open file
121    OPENR, lun, filename, /GET_LUN
122    ;++ handle error
123    ;
124    ; read header
125    READF, lun, header
126    ;
127    ; read data lines
128    READF, lun, result
129    ;
130    ; close file
131    FREE_LUN, lun
132    ;
133    return, result
134    ;
135END
Note: See TracBrowser for help on using the repository browser.