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