source: trunk/src/file_asc_p1l1_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.5 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; ::
24;
25;    IDL> filename='/usr/work/incas/fplod/pomme_d/sta.P1L1.asc'
26;    IDL> result=file_asc_p1l1_to_mem(filename)
27;
28; impression de contrôle : 1re station, toutes les stations ::
29;
30;    IDL> help, result, /structure
31;    IDL> print, result[0].station
32;    IDL> print, result.station
33;
34; :uses:
35;
36; :func:`report`
37;
38; :restrictions:
39;
40; :todo:
41;
42; format fixe
43;
44; test existence of filename
45;
46; usage of ${POMME_ID}
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;
56; :version:
57;
58; $Id$
59;
60;-
61FUNCTION file_asc_p1l1_to_mem, filename
62;
63compile_opt idl2, strictarrsubs
64;
65; Return to caller if errors
66ON_ERROR, 2
67;
68usage = 'result=file_asc_p1l1_to_mem(filename)'
69;
70nparam = N_PARAMS()
71IF (nparam LT 1) THEN BEGIN
72   ras = report(['Incorrect number of arguments.' $
73         + '!C' $
74         + 'Usage : ' + usage])
75   return, -1
76ENDIF
77;
78arg_type = size(filename,/type)
79IF (arg_type NE 7) THEN BEGIN
80   ras = report(['Incorrect arg type filename' $
81         + '!C' $
82         + 'Usage : ' + usage])
83   return, -1
84ENDIF
85;
86arg_dim =  size(filename,/n_elements)
87IF (arg_dim LT 1) THEN BEGIN
88   ras = report(['Incorrect arg dimension filename' $
89         + '!C' $
90         + 'Usage : ' + usage])
91  return, -1
92ENDIF
93;
94; initialize header
95header = STRARR(1)
96;
97resultstruct = { station:0L $
98                 , prof :0L $
99                 , zctd : 0L $
100                 , an: 0L $
101                 , mm: 0L $
102                 , jj: 0L $
103                 , hh_begin: 0L $
104                 , mm_begin: 0L $
105                 , ss_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               }
111nrows = file_lines(filename) - N_ELEMENTS(header);
112result = Replicate(resultstruct, nrows)
113;
114; open file
115OPENR, lun, filename, /GET_LUN
116;++ hanlde error
117;
118; read header
119READF, lun, header
120;
121; read data lines
122READF, lun, result
123;
124; close file
125FREE_LUN, lun
126;
127return, result
128;
129END
Note: See TracBrowser for help on using the repository browser.