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