source: trunk/src/file_asc_p2l2_to_mem.pro @ 9

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

new SAXO and IDL init

  • 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 <saxo:report>`
38;
39; :restrictions:
40;
41; :todo:
42;
43; format fixe
44;
45; test existence of filename
46;
47; :history:
48;
49; - fplod 20101123T122132Z aedon.locean-ipsl.upmc.fr (Darwin)
50;
51;   * creation using "Reading Into a Structure" of
52;     http://www.dfanning.com/tips/ascii_column_data.html
53;
54;
55; :version:
56;
57; $Id$
58;
59;-
60FUNCTION file_asc_p2l2_to_mem, filename
61;
62compile_opt idl2, strictarrsubs
63;
64; Return to caller if errors
65ON_ERROR, 2
66;
67usage = 'result=file_asc_p2l2_to_mem(filename)'
68;
69nparam = N_PARAMS()
70IF (nparam LT 1) THEN BEGIN
71   ras = report(['Incorrect number of arguments.' $
72         + '!C' $
73         + 'Usage : ' + usage])
74   return, -1
75ENDIF
76;
77arg_type = size(filename,/type)
78IF (arg_type NE 7) THEN BEGIN
79   ras = report(['Incorrect arg type filename' $
80         + '!C' $
81         + 'Usage : ' + usage])
82   return, -1
83ENDIF
84;
85arg_dim =  size(filename,/n_elements)
86IF (arg_dim LT 1) THEN BEGIN
87   ras = report(['Incorrect arg dimension filename' $
88         + '!C' $
89         + 'Usage : ' + usage])
90  return, -1
91ENDIF
92;
93; initialize header
94header = STRARR(1)
95;
96resultstruct = { station: 0L $
97                , sonde: 0L $
98                , zmax: 0L $
99                , an: 0L $
100                , mm: 0L $
101                , jj: 0L $
102                , hh_begin: 0L $
103                , mm_begin: 0L $
104                , deg_lat_begin : 0L $
105                , mm_lat_begin: 0.0 $
106                , deg_lon_begin: 0L $
107                , mm_lon_begin: 0.0 $
108                , hh_end: 0L $
109                , mm_end: 0L $
110                , deg_lat_end: 0L $
111                , mm_lat_end: 0.0 $
112                , deg_lon_end: 0L $
113                , mm_lon_end: 0.0 $
114                }
115;
116nrows = file_lines(filename) - N_ELEMENTS(header)
117result = Replicate(resultstruct, nrows)
118;
119; open file
120OPENR, lun, filename, /GET_LUN
121;++ hanlde error
122;
123; read header
124READF, lun, header
125;
126; read data lines
127READF, lun, result
128;
129; close file
130FREE_LUN, lun
131;
132return, result
133;
134END
Note: See TracBrowser for help on using the repository browser.