source: trunk/src/mem_to_file_amsu_t2.pro @ 545

Last change on this file since 545 was 545, checked in by pinsard, 12 years ago

fix for doc

  • Property svn:keywords set to URL Id
File size: 4.9 KB
Line 
1;+
2;
3; =======================
4; mem_to_file_amsu_t2.pro
5; =======================
6;
7; .. function:: mem_to_file_amsu_t2(amsu_t2, testfilename)
8;
9; DESCRIPTION
10; ===========
11;
12; Write info and data of **amsu_t2** structure to an amsu_t2 file
13;
14; If **testfilename** is not empty, this filename will be written, otherwise
15; amsu_t2 terminology will be applied.
16;
17; :returns: name of the output file if ok or -1 if error
18; :rtype: integer
19;
20; EXAMPLES
21; ========
22;
23; Realistic example with VARAMMA file AMSU-A channel 5
24; :file:`${PROJECT_ID}/AMSU/2006/08/a5_20060801.dat`::
25;
26;   numch='a5'
27;   yyyy=2006L
28;   mm=8
29;   dd=1
30;   testfilename=''
31;   lonmin=-25.
32;   lonmax=25.
33;   latmin=-5.
34;   latmax=20.
35;   amsu_t2 = file_amsu_t2_to_mem(yyyy, mm, dd, numch, lonmin, lonmax, latmin, latmax, testfilename)
36;   testfilename='./a'
37;   result = mem_to_file_amsu_t2(amsu_t2, testfilename)
38;
39; look for differences::
40;
41;   $ diff ./a ${PROJECT_ID}/AMSU/2006/08/a5_20060801_060w30s_050e45n.dat
42;
43; SEE ALSO
44; ========
45;
46; :ref:`extract_amsua.pro` where this function should be called
47;
48; :func:`file_amsu_t2_to_mem`
49;
50; use :func:`geolocation_to_string_idl`
51;
52; TODO
53; ====
54;
55; ajouter de # dans les lignes d'entete
56;
57; crier sur valeur manquante de tb
58;
59; à intégrer dans :ref:`extract_amsua.pro`
60;
61; check args
62;
63; spécial idl : je n'arrive pas à éviter la boucle sur les lignes de data !!
64;
65; EVOLUTIONS
66; ==========
67;
68; $Id: mem_to_file_amsu_t2.pro$
69;
70; $URL$
71;
72; - fplod 20120417
73;
74;   * usage of key_performance
75;
76; - fplod 20120410
77;
78;   * build output directory if needed
79;   * update example
80;
81; - fplod 20111213T143503Z aedon.locean-ipsl.upmc.fr (Darwin)
82;
83;   * geobox in filename
84;
85; - fplod 20111213T094118Z cratos (Linux)
86;
87;   * ajout de resol dans l'en tete
88;
89; - fplod 20111209T150209Z cratos (Linux)
90;
91;   * ajout de nbpix dans la première ligne de header
92;   * ajout d'une seconde ligne d'entete avec les coordonnées de la zone
93;   * suppression de parametres redondants
94;
95; - fplod 20111208T173432Z aedon.locean-ipsl.upmc.fr (Darwin)
96;
97;   * name of output file as result if ok
98;
99; - fplod 20111208T105205Z cratos (Linux)
100;
101;   * nvelle terminologie
102;   * nouveau format (header + données) de fichier
103;
104; - fplod 20111206T163330Z cratos (Linux)
105;
106;   * creation thanks to http://www.idlcoyote.com/tips/ascii_column_data.html
107;
108;-
109FUNCTION mem_to_file_amsu_t2, amsu_t2 $
110                            , testfilename
111;
112compile_opt idl2, strictarrsubs
113;
114@cm_project
115@common
116;
117s = size(SCOPE_TRACEBACK(/STRUCTURE),/DIMENSION)
118routine = (SCOPE_TRACEBACK(/STRUCTURE))[s-1].Routine
119;
120if key_performance EQ 1 THEN BEGIN
121    time1 = SYSTIME(1)
122ENDIF
123;
124; Return to caller if errors
125ON_ERROR, 2
126;
127result = -1
128;
129usage = 'result=mem_to_file_amsu_t2(amsu_t2, testfilename)'
130nparam = N_PARAMS()
131IF (nparam NE 2) THEN BEGIN
132   ras = report(['Incorrect number of arguments.' $
133         + '!C' $
134         + 'Usage : ' + usage])
135   return, result
136ENDIF
137;
138
139if (testfilename eq '') then begin
140    look = 'filename'
141    scale = 1.
142    geomin = geolocation_to_string_idl(amsu_t2.header2.lonmin, amsu_t2.header2.latmin, look, scale)
143    geomax = geolocation_to_string_idl(amsu_t2.header2.lonmax, amsu_t2.header2.latmax, look, scale)
144    fullfilename = project_id_env+ 'AMSU/' $
145            + string(amsu_t2.header1.yyyy,format='(I4.4)') + '/' $
146            + string(amsu_t2.header1.mm,format='(I2.2)') + '/' $
147            + amsu_t2.header1.numch + '_' $
148            + string(amsu_t2.header1.yyyy,format='(I4.4)') $
149            + string(amsu_t2.header1.mm,format='(I2.2)') $
150            + string(amsu_t2.header1.dd,format='(I2.2)') + '_' $
151            + geomin + '_' $
152            + geomax $
153            + '.dat'
154endif else begin
155    fullfilename = testfilename
156endelse
157;
158; buid the directory if needed
159dirout = file_dirname(fullfilename,/MARK_DIRECTORY)
160IF (FILE_TEST(dirout, /DIRECTORY, /EXECUTABLE, /WRITE) EQ 0) THEN BEGIN
161    FILE_MKDIR, dirout
162ENDIF
163
164print, 'ouverture pour ecriture de ', fullfilename
165;
166; build header format string
167format_header1 = '(I4.4,I2.2,I2.2,1X,A2,1X,I3.3,1X,F6.3)'
168format_header2 = '(1x,f8.3,1x,f8.3,1x,f8.3,1x,f8.3)'
169
170; build data format string
171format_data = '(i2,1x,f8.4,i3,1x,f8.3,1x,f8.3,1x,I1,1x,f8.3)'
172;
173nrows = n_elements(amsu_t2.data)
174;
175; open file
176OPENW, lun, fullfilename, /GET_LUN, ERROR = error
177IF (error NE 0) then begin
178   ras = report(['eee : can not open for writing '$
179         + '!C' $
180         + fullfilename])
181   return, result
182ENDIF
183;
184; write header lines
185header1=amsu_t2.header1
186PRINTF, lun, header1, format=format_header1
187header2=amsu_t2.header2
188PRINTF, lun, header2, format=format_header2
189;
190; write data lines
191for irow=0, nrows -1 do begin
192    data=amsu_t2.data[irow]
193    PRINTF, lun, data, format=format_data
194endfor
195;
196; close file
197FREE_LUN, lun
198;
199result = fullfilename
200;
201IF key_performance EQ 1 THEN BEGIN
202   msg = report(['ppp : ' + routine + ' : durée totale ' $
203               + string(SYSTIME(1)-time1,format='(F12.6)')])
204ENDIF
205;
206return, result
207;
208END
Note: See TracBrowser for help on using the repository browser.