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 | ;- |
---|
109 | FUNCTION mem_to_file_amsu_t2, amsu_t2 $ |
---|
110 | , testfilename |
---|
111 | ; |
---|
112 | compile_opt idl2, strictarrsubs |
---|
113 | ; |
---|
114 | @cm_project |
---|
115 | @common |
---|
116 | ; |
---|
117 | s = size(SCOPE_TRACEBACK(/STRUCTURE),/DIMENSION) |
---|
118 | routine = (SCOPE_TRACEBACK(/STRUCTURE))[s-1].Routine |
---|
119 | ; |
---|
120 | if key_performance EQ 1 THEN BEGIN |
---|
121 | time1 = SYSTIME(1) |
---|
122 | ENDIF |
---|
123 | ; |
---|
124 | ; Return to caller if errors |
---|
125 | ON_ERROR, 2 |
---|
126 | ; |
---|
127 | result = -1 |
---|
128 | ; |
---|
129 | usage = 'result=mem_to_file_amsu_t2(amsu_t2, testfilename)' |
---|
130 | nparam = N_PARAMS() |
---|
131 | IF (nparam NE 2) THEN BEGIN |
---|
132 | ras = report(['Incorrect number of arguments.' $ |
---|
133 | + '!C' $ |
---|
134 | + 'Usage : ' + usage]) |
---|
135 | return, result |
---|
136 | ENDIF |
---|
137 | ; |
---|
138 | |
---|
139 | if (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' |
---|
154 | endif else begin |
---|
155 | fullfilename = testfilename |
---|
156 | endelse |
---|
157 | ; |
---|
158 | ; buid the directory if needed |
---|
159 | dirout = file_dirname(fullfilename,/MARK_DIRECTORY) |
---|
160 | IF (FILE_TEST(dirout, /DIRECTORY, /EXECUTABLE, /WRITE) EQ 0) THEN BEGIN |
---|
161 | FILE_MKDIR, dirout |
---|
162 | ENDIF |
---|
163 | |
---|
164 | print, 'ouverture pour ecriture de ', fullfilename |
---|
165 | ; |
---|
166 | ; build header format string |
---|
167 | format_header1 = '(I4.4,I2.2,I2.2,1X,A2,1X,I3.3,1X,F6.3)' |
---|
168 | format_header2 = '(1x,f8.3,1x,f8.3,1x,f8.3,1x,f8.3)' |
---|
169 | |
---|
170 | ; build data format string |
---|
171 | format_data = '(i2,1x,f8.4,i3,1x,f8.3,1x,f8.3,1x,I1,1x,f8.3)' |
---|
172 | ; |
---|
173 | nrows = n_elements(amsu_t2.data) |
---|
174 | ; |
---|
175 | ; open file |
---|
176 | OPENW, lun, fullfilename, /GET_LUN, ERROR = error |
---|
177 | IF (error NE 0) then begin |
---|
178 | ras = report(['eee : can not open for writing '$ |
---|
179 | + '!C' $ |
---|
180 | + fullfilename]) |
---|
181 | return, result |
---|
182 | ENDIF |
---|
183 | ; |
---|
184 | ; write header lines |
---|
185 | header1=amsu_t2.header1 |
---|
186 | PRINTF, lun, header1, format=format_header1 |
---|
187 | header2=amsu_t2.header2 |
---|
188 | PRINTF, lun, header2, format=format_header2 |
---|
189 | ; |
---|
190 | ; write data lines |
---|
191 | for irow=0, nrows -1 do begin |
---|
192 | data=amsu_t2.data[irow] |
---|
193 | PRINTF, lun, data, format=format_data |
---|
194 | endfor |
---|
195 | ; |
---|
196 | ; close file |
---|
197 | FREE_LUN, lun |
---|
198 | ; |
---|
199 | result = fullfilename |
---|
200 | ; |
---|
201 | IF key_performance EQ 1 THEN BEGIN |
---|
202 | msg = report(['ppp : ' + routine + ' : durée totale ' $ |
---|
203 | + string(SYSTIME(1)-time1,format='(F12.6)')]) |
---|
204 | ENDIF |
---|
205 | ; |
---|
206 | return, result |
---|
207 | ; |
---|
208 | END |
---|