source: ether_visual/trunk/lecteur_norm.pro @ 15

Last change on this file since 15 was 15, checked in by cbipsl, 18 years ago

transfer fichier 1 ok

  • Property svn:executable set to *
File size: 17.8 KB
RevLine 
[15]1function lecteur_norm, filenames,infonames, lecteurs, varid, output_varid,transfos, ether_norm_struct, daterange=daterange, lonrange=lonrange, latrange=latrange, param_aux=param_aux,densite=densite,erreur=erreur
2;
3; filenames : tableau de string
4;
5; infonames : tableau de string
6; lecteurs : tableau de string
7; varid : tableau de structures du type [{variable:'Aerosol', nature:'Mes', subvariable:'1018IR', unite:'m/s'},{variable:'Altitude',, nature:'Mes', subvariable:''}]
8;output_varid : tableau de structure. parametres en sortie du lecteur (apres transformation)
9; transfos : tableau de structures [ptr_new([{nom:'t9',aux1:4,aux2:999},{nom:'c1',aux1:999,aux2:999}],ptr_new([{nom:'c1',aux1:999,aux2:999},{nom:'t4',aux1:4,aux2:999},{nom:'c2',aux1:999,aux2:999}]]
10; ether_norm_struct :
11; Tags de la structure ETHER_NORM_STRUCT
12; ---------------------------------
13;   nb_prof        (scalaire entier):
14;       nombre de profils
15;       nombre de profils total issu de chaque fichier de donnees traité et inclus dans les plages daterange, lonrange, latrange
16;   nb_var         (scalaire entier):
17;       nombre de variables
18;       nombre de variables en sortie = N_elements(output_varid)
19;   nb_niv         (scalaire entier):
20;       nombre de niveaux verticaux des profils
21;       nombre de niveaux MAX issu de chaque fichier de donnees traité
22;       Nota : si le nombre de niveaux est differents selon le fichier de donnee traitee , mettre des valeurs 999.999 dans tableau aux niveaux non definis
23;   date           (tableau de chaines de caractËres de dimension nbprof):
24;       date de chacun des profils au format AAAAMMJJhhmmss
25;   latitude       (tableau de reels de dimension nbprof):
26;       latitude de chacun des profils (en °, entre -90° au S et +90° au N)
27;   longitude      (tableau de reels de dimension nbprof):
28;       longitude de chacun des profils (en °, entre -180° à l'W et +180° à l'E)
29;   numorb         tableau de chaines de caracteres de dimension nbprof):
30;       numero d'orbite pour chacun des profils
31;       dans le cas d'instruments embarques sur satellite
32;   zensol         (tableau de reels de dimension nbprof):
33;       angle zenithal solaire pour chacun des profils
34;   comment        (tableau de chaines de caracteres de dimension nbprof):
35;       informations specifiques aux fichiers
36;   variable       (tableau de chaines de caracteres de dimension nb_var):
37;       liste des variables lues dans le fichier
38;       (especes chimiques ou parametres physiques)
39;   subvariable    (tableau de chaines de caracteres de dimension nb_var):
40;       liste des sous-variables (information complementaire à propos des variables)
41;   unite          (tableau de chaines de caracteres de dimension nb_var):
42;       unite dans laquelle est exprimee chacune des variables
43;   nature         (tableau de chaines de caracteres de dimension nb_var):
44;       nature de chacune des variables (provenant de mesures ou d'un modele)
45;   tableau         (tableau de reels de dimension nb_prof x nb_var x nb_niv):
46;       valeurs prises par chacune des variables, par niveau vertical et par profil
47;
48; NOTA : pour chaque variable de sortie (i) decrite dans output_varid , il existe un index (idx) unique telque :
49; ether_norm_struct.variable[idx]=output_varid[i].variable
50; ether_norm_struct.subvariable[idx]=output_varid[i].subvariable
51; ether_norm_struct.nature[idx]=output_varid[i].nature
52; ether_norm_struct.unite[idx]]=output_varid[i].unite
53; ether_norm_struct.tableau[*,idx,*] : ensemble des valeurs calculee pour la variable (i) par profil et par niveau
54;
55; daterange=[20040601120054,20040602120054]
56; lonrange=[20,180]
57; param_aux=param_aux ; ex : [ptr_new({nomfile:<file>,nomvariable:'Press',nomsubvariable:'.',nomnature:'Mes', nominfo:'<file>'},       
58;                                    {nomfile:aux_input,nomvariable:'Temp',nomsubvariable:'.',nomnature:'Mes', nominfo:'<file>'}]))
59; densite=densite ; 1 ou 0
60; erreur=erreur
61;
62
63if densite eq 3 then begin
64
65ether_struct = CALL_FUNCTION(lecteurs[0],filenames[0])
66
67endif else begin
68
69
70;setdata,systime(),0,1
71IF N_ELEMENTS(filenames) eq 0 THEN BEGIN
72    erreur='At least one file must be specified'
73    print,erreur
74    RETURN,'-1'
75ENDIF
76IF N_ELEMENTS(infonames) eq 0 THEN BEGIN
77    erreur='At least one information file must be specified'
78    print,erreur
79    RETURN,'-1'
80ENDIF
81IF N_ELEMENTS(lecteurs) eq 0 THEN BEGIN
82    erreur='At least one reader program must be specified'
83    print,erreur
84    RETURN,'-1'
85ENDIF
86IF N_ELEMENTS(infonames) ne N_ELEMENTS(filenames) THEN BEGIN
87    erreur='The number of information files must be equal to the number of files'
88    print,erreur
89    RETURN,'-1'
90ENDIF
91IF N_ELEMENTS(varid) ne N_ELEMENTS(transfos) THEN BEGIN
92    erreur='The number of transformations must be equal to the number of variables'
93    print,erreur
94    RETURN,'-1'
95ENDIF
96IF N_ELEMENTS(varid) lt 2 THEN BEGIN
97    erreur='At least 2 variables must be specified'
98    print,erreur
99    RETURN,'-1'
100ENDIF
101IF N_ELEMENTS(output_varid) lt 2 THEN BEGIN
102    erreur='At least 2 variables must be specified for the output variables'
103    print,erreur
104    RETURN,'-1'
105ENDIF
106IF N_ELEMENTS(param_aux) ne N_ELEMENTS(filenames) THEN BEGIN
107    IF N_ELEMENTS(param_aux) eq 1 THEN param_aux = REPLICATE(param_aux, N_ELEMENTS(filenames)) ELSE BEGIN
108        if n_elements(param_aux) eq 0 then param_aux = replicate([ptr_new([{nomfile:'',nomvariable:'',nomsubvariable:'',nomnature:'',nominfo:''}])],n_elements(filenames)) else begin
109        erreur='The number of auxiliary parameters must be equal to the number of files'
110        print,erreur
111        RETURN,'-1'
112        endelse
113endelse
114ENDIF
115
116IF SIZE(output_varid[0],/type) ne 8 THEN BEGIN
117    erreur='The output variables must be contained in a structure'
118    print,erreur
119    RETURN,'-1'
120END
121tag = TAG_NAMES(output_varid[0])
122IF TOTAL(STRMATCH(tag,'variable',/fold_case)) eq 0 THEN BEGIN
123    erreur="The tag 'variable' is not defined in output variables"
124    print,erreur
125    RETURN,'-1'
126ENDIF
127IF TOTAL(STRMATCH(tag,'subvariable',/fold_case)) eq 0 THEN BEGIN
128    erreur="The tag 'subvariable' is not defined in output variables"
129    print,erreur
130    RETURN,'-1'
131ENDIF
132IF TOTAL(STRMATCH(tag,'nature',/fold_case)) eq 0 THEN BEGIN
133    erreur="The tag 'nature' is not defined in output variables"
134    print,erreur
135    RETURN,'-1'
136ENDIF
137
138IF SIZE(varid[0],/type) ne 8 THEN BEGIN
139    erreur='The variables must be contained in a structure'
140    print,erreur
141    RETURN,'-1'
142END
143tag = TAG_NAMES(varid[0])
144IF TOTAL(STRMATCH(tag,'variable',/fold_case)) eq 0 THEN BEGIN
145    erreur="The tag 'variable' is not defined"
146    print,erreur
147    RETURN,'-1'
148ENDIF
149IF TOTAL(STRMATCH(tag,'subvariable',/fold_case)) eq 0 THEN BEGIN
150    erreur="The tag 'subvariable' is not defined"
151    print,erreur
152    RETURN,'-1'
153ENDIF
154IF TOTAL(STRMATCH(tag,'nature',/fold_case)) eq 0 THEN BEGIN
155    erreur="The tag 'nature' is not defined"
156    print,erreur
157    RETURN,'-1'
158ENDIF
159
160
161IF N_ELEMENTS(daterange) lt 2 THEN daterange=[ulong64(0),ulong64(30000000000000)]
162IF N_ELEMENTS(lonrange) lt 2 THEN lonrange=[-180,360]
163IF N_ELEMENTS(latrange) lt 2 THEN latrange=[-90,90]
164
165
166; initialisation des variables de sortie
167varx = ptr_new()
168vary = ptr_new()
169
170vardate = ptr_new()
171varlatitude = ptr_new()
172varlongitude = ptr_new()
173varnumorb = ptr_new()
174varzensol = ptr_new()
175varcomment = ptr_new()
176
177
178; boucle sur les fichiers
179erreur=''
180erreur0=''
181niveau_norm=1
182tot_nbprof=0
183FOR ifile = 0, N_ELEMENTS(filenames)-1 DO BEGIN
184        ; filenames[ifile] est bien accessible ?
185        IF FILE_TEST(filenames[ifile],/read) eq 0 THEN print,"The file "+filenames[ifile]+" does not exist or is not readable" ELSE BEGIN
186       
187        ; lecture du fichier
188        ;print,'filename=',filenames[ifile]
189        ether_struct = CALL_FUNCTION(lecteurs[0],filenames[ifile],infonames[ifile],densite=densite,paramaux=*param_aux[ifile])
190        print,'size(ether_struct->reader',size(ether_struct.tableau)
191        ;print,'******************'
192;print,ether_struct.variable
193;print,'*******************'
194
195;print,'******************'
196;print,ether_struct.subvariable
197;nprint,'*******************'
198
199;print,'******************'
200;print,ether_struct.nature
201;print,'*******************'
202
203       
204        ; extraction des variables; combien il y en a, d'abord ?
205       
206        nvar = N_ELEMENTS(varid)
207        ; declaration array de pointeurs car la dimension des profils n'est pas connue
208        var = ptrarr(nvar)
209
210        ; commence par la fin -> sont stockees les variables auxiliaires et au passage application des tranformations
211        noprof=0
212       
213        FOR ivar = nvar-1,0,-1 DO BEGIN
214;               print,'ivar=',ivar
215;               print,'ether_struct.nature=',ether_struct.nature
216;               print,'varid[ivar].nature=',varid[ivar].nature
217;               print,'****************************************'
218;               print,'ether_struct.variable=',ether_struct.variable
219;               print,'varid[ivar].variable=',varid[ivar].variable
220
221
222;               if ether_struct.nature eq varid[ivar].nature then begin
223;                       print,'OUI NATURE'
224;               endif else begin
225;                       print, 'NON NATURE'
226;               endelse
227
228;               if ether_struct.subvariable eq varid[ivar].subvariable then begin
229;                        print, 'OUI SUB'
230;                endif else begin
231;                        print, 'NON SUB'
232;                endelse
233               
234
235                idx = WHERE(STRMATCH(ether_struct.variable,varid[ivar].variable) ne 0 and $
236                        ether_struct.nature eq varid[ivar].nature and $
237                        ether_struct.subvariable eq varid[ivar].subvariable,count)
238                        ;print,'variable=',ether_struct.variable
239                        ;print,'longitude=',ether_struct.longitude
240                        ;print,'latitude=',ether_struct.latitude
241                       
242                IF count eq 0 and varid[ivar].variable ne 'phi' and varid[ivar].nature ne 'ARL' THEN BEGIN
243                        erreur0=erreur0+"!cThe variable ("+varid[ivar].variable+","$
244                                +varid[ivar].nature+","+varid[ivar].subvariable+") is not available in the file  "+filenames[ifile]
245                        noprof=1
246                        print,'!!>>',erreur0
247                ENDIF ELSE BEGIN
248                        isel = WHERE(ether_struct.longitude ge lonrange[0],count)
249                        if count eq 0 then begin
250                                print,'pb lonmin'
251                        endif
252
253                        isel = WHERE(ether_struct.longitude le lonrange[1],count)
254                        if count eq 0 then begin
255                                print,'pb lonmax'
256                        endif
257
258                        isel = WHERE(ether_struct.latitude ge latrange[0],count)
259                        if count eq 0 then begin
260                                print,'pb latmin'
261                        endif
262
263                        isel = WHERE(ether_struct.latitude le latrange[1],count)
264                        if count eq 0 then begin
265                                print,'pb latmax'
266                        endif
267
268                        isel = WHERE( ulong64(ether_struct.date) ge daterange[0],count)
269                        if count eq 0 then begin
270                                print,'pb datemin'
271                        endif
272
273                        isel = WHERE( ulong64(ether_struct.date) le daterange[1],count)
274                        if count eq 0 then begin
275                                print,'pb datemax'
276                        endif
277
278                        isel = WHERE(ether_struct.longitude ge lonrange[0] and ether_struct.longitude le lonrange[1] and $
279                                ether_struct.latitude ge latrange[0] and ether_struct.latitude le latrange[1] and $
280                                ulong64(ether_struct.date) ge daterange[0] and ulong64(ether_struct.date) le daterange[1] ,count)
281
282                                 
283                        IF count eq 0 THEN BEGIN
284                                erreur='No drawing in the selected range of date/latitude/longitude!c -> Directory : '+$
285                                        strmid(filenames[ifile],0,strpos(filenames[ifile],'/',/reverse_search))+'!c -> File : '+$
286                                        strmid(filenames[ifile],strpos(filenames[ifile],'/',/reverse_search)+1)
287
288                                print,erreur
289                                erreur0=erreur0+'!c'+erreur
290                                noprof=1
291                                break
292                        ENDIF
293
294                        IF densite eq 0 THEN nbniv = (size(ether_struct.tableau))[3] else nbniv = 1
295                       
296                        ; Lancement du script ARLETTY
297                        IF varid[ivar].nature eq 'ARL' THEN BEGIN
298                                arletty,ether_struct,isel,count,varid,ivar,numreq,erreur=erreur
299                                erreur0=erreur0+'!c'+erreur
300                        ENDIF ELSE BEGIN
301                                IF varid[ivar].variable eq 'phi' THEN BEGIN
302                                        dumvar = fltarr(count,nbniv)
303                                        FOR iniv = 0L, nbniv-1 DO BEGIN
304                                                dumvar[*,iniv]=ether_struct.latitude[isel]
305                                        ENDFOR 
306                                ENDIF ELSE BEGIN
307        ;                               print,'size(n_elements)=',size(ether_struct.tableau)
308        ;                               print,'idx=',idx
309                                        IF n_elements(ether_struct.tableau[isel,idx,*]) eq 1 THEN BEGIN
310                                                dumvar =ether_struct.tableau[isel,idx,*]
311                                        ENDIF ELSE BEGIN
312        ;                                       print,'count=',count
313        ;                                       print,'nbniv=',nbniv
314        ;                                       print,'size(ether_struct.tableau[isel,idx,*]=',size(ether_struct.tableau[isel,idx,*])
315        ;                                       print,'n_elements(ether_struct.tableau[isel,idx,*])=",n_elements(ether_struct.tableau[isel,idx,*])
316                                                dumvar = REFORM(ether_struct.tableau[isel,idx,*],count,nbniv)
317                                        ENDELSE
318                                ENDELSE
319                        ENDELSE
320
321;                       print,'ivar=',ivar,' | ','dumvar=',dumvar       
322
323                        nbprof=count
324                       
325                        if ivar eq 0 then begin
326                                tot_nbprof = tot_nbprof + nbprof
327                        endif
328
329                        ;transformations/conversions
330                        ntransfo = N_ELEMENTS(*transfos[ivar])
331
332                        FOR itransfo = 0, ntransfo-1 DO BEGIN
333                               
334                                idx = (*transfos[ivar])[itransfo].aux1
335
336                                IF idx ge 2 and idx lt nvar THEN BEGIN
337
338                                        IF STREGEX(varid[idx].variable,'phi',/fold_case) ge 0 THEN aux1=ether_struct.latitude ELSE aux1=*var[idx]
339
340                                ENDIF ELSE aux1=dumvar
341
342                                idx = (*transfos[ivar])[itransfo].aux2
343                                IF idx ge 2 and idx lt nvar THEN BEGIN
344                                        IF STREGEX(varid[idx].variable,'phi',/fold_case) ge 0 THEN aux2=ether_struct.latitude ELSE aux2=*var[idx]
345                                ENDIF ELSE aux2=dumvar
346
347                                idx = WHERE(dumvar ne 999 and aux1 ne 999 and aux2 ne 999,count)
348                               
349                                IF count ne 0 THEN BEGIN
350                                        FOR iprof = 0L, nbprof-1 DO BEGIN
351                                                dumvar[iprof,*] = CALL_FUNCTION((*transfos[ivar])[itransfo].nom,dumvar[iprof,*],aux1=aux1[iprof,*],$
352                                        aux2=aux2[iprof,*])
353                                                IF n_elements(dumvar[iprof,*]) gt niveau_norm THEN niveau_norm=n_elements(dumvar[iprof,*])
354                                        ENDFOR
355                                        IF densite eq 0 THEN BEGIN
356                                                var[ivar] = ptr_new(reform(dumvar,nbprof,(size(ether_struct.tableau))[3]))
357                                                                       
358                                        ENDIF ELSE BEGIN
359                                                IF n_elements(dumvar) eq 1 THEN BEGIN
360                                                        var[ivar] = ptr_new(dumvar)
361                                                ENDIF ELSE var[ivar] = ptr_new(REFORM(dumvar,nbprof,1))
362                                        ENDELSE
363                       
364                                ENDIF ELSE BEGIN       
365                                        print,'err0=',erreur0
366                                        erreur0=erreur0+'!cImpossible transformation : '+(*transfos[ivar])[itransfo].nom
367                                        var[ivar] = ptr_new(999)
368                                ENDELSE
369                        ENDFOR
370                       
371                ENDELSE
372        ENDFOR
373        donnee=''
374        IF noprof eq 0 THEN BEGIN
375                varx = [varx, var[0]]
376                vary = [vary, var[1]]
377               
378                varlongitude = [varlongitude, ptr_new(reform(ether_struct.longitude[isel]))]
379                varlatitude = [varlatitude, ptr_new(reform(ether_struct.latitude[isel]))]
380                vardate = [vardate, ptr_new(reform(ether_struct.date[isel]))]
381                varnumorb = [varnumorb, ptr_new(reform(ether_struct.numorb[isel]))]
382                varzensol = [varzensol, ptr_new(reform(ether_struct.zensol[isel]))]
383                varcomment = [varcomment, ptr_new(reform(ether_struct.zensol[isel]))]
384        ENDIF
385    ENDELSE
386ENDFOR
387
388if n_elements(varx) le 1 then return,'-1'
389;print,'varx=',varx
390varx = varx[1:*]
391vary = vary[1:*]
392varlongitude = varlongitude[1:*]
393varlatitude = varlatitude[1:*]
394vardate = vardate[1:*]
395varnumorb = varnumorb[1:*]
396varzensol = varzensol[1:*]
397varcomment = varcomment[1:*]
398
399pl_varx=varx
400
401;if n_elements(varx) le 1 then return,'-1
402
403pl_vary=vary
404pl_varlongitude=varlongitude
405pl_varlatitude=varlatitude
406pl_vardate=vardate
407pl_varnumorb=varnumorb
408pl_varzensol=varzensol
409pl_varcomment=varcomment
410
411;dimension 2 de ether_norm_struct=nombre de variable en sortie
412nbvar=n_elements(output_varid)
413
414;calcul du nombre total de profils
415nivtab=tot_nbprof
416
417; construction de la structure ether normalisee
418ether_norm_struct = {nb_prof : nivtab, nb_var : nbvar, nb_niv : niveau_norm, $
419                date : strarr(nivtab), $
420                latitude : fltarr(nivtab), longitude : fltarr(nivtab), $
421                numorb : strarr(nivtab), zensol : fltarr(nivtab), $
422                comment : strarr(nivtab), $
423                variable : strarr(n_elements(output_varid)), subvariable : strarr(n_elements(output_varid)), $
424                unite : strarr(n_elements(output_varid)), nature: strarr(n_elements(output_varid)), $
425                tableau : fltarr(nivtab,nbvar,niveau_norm)}
426
427indice=0
428
429
430;on parcourt le tableaux de points transformes des profils retenus
431;pour remplir ether_norm_struct.tableau
432
433for n=0L,n_elements(pl_varx)-1 do begin
434        nbprof=(size(*pl_varx[n],/dimensions))[0]
435       
436        for iprof=0L,nbprof-1 do begin
437                m=0L
438                for m=0L,n_elements((*pl_varx[n])[iprof,*])-1 do begin
439                        ether_norm_struct.tableau[indice,0,m]=(*pl_varx[n])[iprof,m]
440                        ether_norm_struct.tableau[indice,1,m]=(*pl_vary[n])[iprof,m]
441;                       ether_norm_struct.tableau[indice,2,m]=(*pl_vary[n])[iprof,m]
442                endfor
443                       
444                ether_norm_struct.longitude[indice]=(*pl_varlongitude[n])[iprof]
445                ether_norm_struct.latitude[indice]=(*pl_varlatitude[n])[iprof]
446                ether_norm_struct.zensol[indice]=(*pl_varzensol[n])[iprof]
447                ether_norm_struct.date[indice]=(*pl_vardate[n])[iprof]
448                ether_norm_struct.numorb[indice]=(*pl_varnumorb[n])[iprof]
449                ether_norm_struct.comment[indice]=(*pl_varcomment[n])[iprof]   
450                       
451                ;si ce profil n'a pas le nombre de niveau maximum, initialisation valeur a 999.999
452                if m lt niveau_norm-1 then begin
453                        for k=m, niveau_norm-1 do begin
454                                ether_norm_struct.tableau[indice,0,k]=999.999
455                                ether_norm_struct.tableau[indice,1,k]=999.999
456;                               ether_norm_struct.tableau[indice,2,k]=999.999
457                        endfor
458                endif
459                indice=indice+1
460        endfor
461               
462endfor
463
464;on renseigne ether_norm_struct des variables de sortie listees dans output_varid
465;print,'n_elements(output_varid)=',output_varid[2]
466for n=0L,n_elements(output_varid)-1 do begin
467        ether_norm_struct.variable[n]=output_varid[n].variable
468        ether_norm_struct.subvariable[n]=output_varid[n].subvariable
469        ether_norm_struct.unite[n]=output_varid[n].unite
470        ether_norm_struct.nature[n]=output_varid[n].nature
471endfor
472erreur=erreur0
473;setdata,systime(),1,1
474;print,'*******VARIABLES**********'
475;print,ether_norm_struct.tableau
476;print,'**************************'
477
478endelse
479RETURN, '0'
480END
481
Note: See TracBrowser for help on using the repository browser.