source: trunk/src/file_asc_p2l2_to_mem.pro @ 2

Last change on this file since 2 was 2, checked in by pinsard, 14 years ago

first commit with original work of Marina Levy and Francoise Pinsard

  • 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; 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;-
62FUNCTION file_asc_p2l2_to_mem, filename
63;
64compile_opt idl2, strictarrsubs
65;
66; Return to caller if errors
67ON_ERROR, 2
68;
69usage = 'result=file_asc_p2l2_to_mem(filename)'
70;
71nparam = N_PARAMS()
72IF (nparam LT 1) THEN BEGIN
73   ras = report(['Incorrect number of arguments.' $
74         + '!C' $
75         + 'Usage : ' + usage])
76   return, -1
77ENDIF
78;
79arg_type = size(filename,/type)
80IF (arg_type NE 7) THEN BEGIN
81   ras = report(['Incorrect arg type filename' $
82         + '!C' $
83         + 'Usage : ' + usage])
84   return, -1
85ENDIF
86;
87arg_dim =  size(filename,/n_elements)
88IF (arg_dim LT 1) THEN BEGIN
89   ras = report(['Incorrect arg dimension filename' $
90         + '!C' $
91         + 'Usage : ' + usage])
92  return, -1
93ENDIF
94;
95; initialize header
96header = STRARR(1)
97;
98resultstruct = { 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;
118nrows = file_lines(filename) - N_ELEMENTS(header)
119result = Replicate(resultstruct, nrows)
120;
121; open file
122OPENR, lun, filename, /GET_LUN
123;++ hanlde error
124;
125; read header
126READF, lun, header
127;
128; read data lines
129READF, lun, result
130;
131; close file
132FREE_LUN, lun
133;
134return, result
135;
136END
Note: See TracBrowser for help on using the repository browser.