;+ ; ; @file_comments ; lit les fichiers Net-Cdf de l'experience TOTEM/ECMWF qui ; contiennent les sorties a 5j regroupees par type de grille par ; paquets de 6 mois. ; sur maia: /u/rech/eee/reee217/TOTEM/REF/OUTPUTS ; ; @obsolete ; ; @categories ; Reading ; ; @examples ; ; IDL> res=nlec5j( nom, numsortie, nbretps) ; ; @param nom {in}{required} ; nom du tableau contenant le champ que l'on veut (le ; trouver avec ncdflec,fichier,/var ; ; @param numsortie {in}{required} ; le numero du pas de temps que l'on veut sortir du ; fichier (compte a partir de 1) a partir de year ; ; @param nbretps {in}{required} ; nombre de pas de temps a extraire ; ; @keyword BOITE ; boite sur laquelle integrer (par defaut tt le domaine) ; ; @keyword GRILLE ; impose la grille a laquelle est rapporte le champ. rq permet ; d'aller plus vite ds la lecture ; ; @keyword TOUT ; oblige a lire le tableau entier en non pas celui reduit a domdef ; ; @keyword _EXTRA ; Used to pass keywords ; @returns ; tableau 2d (qd on ne demande pas de serie) ou 3d ou 4d ds le cas dune serie ; ; @uses ; common ; ; @restrictions ; appele par nlec ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; ; @version ; $Id$ ; ;- function nlec5j, nom, numsortie, nbretps $ ,BOITE=boite, GRILLE=grille, TOUT=tout, _EXTRA=ex ; compile_opt idl2, strictarrsubs, obsolete ; @common ;------------------------------------------------------------ res=-1 anneedepart=1979 ;------------------------------------------------------------ ; gestion du nom du fichier ;------------------------------------------------------------ if numsortie le 36 then BEGIN mmdd='0101' numsort=numsortie ENDIF else BEGIN if leapyr(year) then mmdd='0629' else mmdd='0630' numsort=numsortie-36 endelse case 1 of year lt 10: s_year ='0'+string(format='(i1)',year) year lt 100 and year ge 10 :s_year = string(format='(i2)',year) year ge 100: s_year = string(format='(i2)',(year-1900)*(year LT 2000)) endcase numfich=(year-anneedepart)*2+7+(mmdd ne '0101') s_date=s_year+mmdd if numfich lt 10 then numfich='0'+string(format='(i1)',numfich) $ else numfich= string(format='(i2)',numfich) ;------------------------------------------------------------ ; gestion du nom de la grille en testant les differentes possibilites ; et ouverture du fichier ;------------------------------------------------------------ if keyword_set(grille) then begin vargrid=grille nomfich=prefix+'.'+numfich+'.'+s_date+'.grid.'+vargrid+'.nc' IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+iodir+nomfich+' > /dev/null' cdfid=ncdf_open(iodir+nomfich) varcontient=ncdf_varinq(cdfid,nom) endif else begin ; liste des fichiers pouvant convenir quelsfichiers = findfile(iodir+prefix+'.'+numfich+'.'+s_date+'.grid.*') IF quelsfichiers[0] EQ '' THEN BEGIN ; liste vide if keyword_set(bavard) then $ ras = report('LES FICHIERS: '+iodir+prefix+'.'+numfich+'.'+s_date+'.grid... n''existe pas.') return, -1 ENDIF for i=0,n_elements(quelsfichiers)-1 do begin IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+quelsfichiers[i]+' > /dev/null' cdfid=ncdf_open(quelsfichiers[i]) contient=ncdf_inquire(cdfid) for varid=0,contient.nvars-1 do BEGIN ; ds les fichiers existants on varcontient=ncdf_varinq(cdfid,varid) ; cherche le nom des variables if varcontient.name eq nom then BEGIN vargrid=strmid(quelsfichiers[i],strpos(quelsfichiers[i],'grid')+5,1) ;nom de grille goto, grilletrouvee ENDIF endfor ncdf_close,cdfid endfor if keyword_set(bavard) then $ ras = report('La variable '+nom+' n''existe pas ds les fichiers'+iodir+prefix+'.'+numfich+'.'+s_date+'.grid...') return, -1 endelse grilletrouvee: ;------------------------------------------------------------ ; lecture de certains attributs ;------------------------------------------------------------ ncdf_attget,cdfid,nom,'title',value varname=string(value) ncdf_attget,cdfid,nom,'units',value varunit=string(value) if rstrpos(varname,'(') eq -1 then varname=varname+' ('+varunit+')' if month lt 10 then s_month='0'+string(format='(i1)',month) $ else s_month= string(format='(i2)',month) if day lt 10 then s_day='0'+string(format='(i1)',day) $ else s_day= string(format='(i2)',day) vardate=s_year+s_month+s_day ncdf_attget,cdfid,'file_name',value,/global varexp=string(value[0:(where(value EQ (byte('.'))[0]))[0]-1]) ;------------------------------------------------------------ ;------------------------------------------------------------ ; extraction du tableau qui nous interesse ;------------------------------------------------------------ ;------------------------------------------------------------ ; determination du domaine geographique ;------------------------------------------------------------ if keyword_set(tout) then begin nx=jpi ny=jpj nz=jpk premierx = 0 premiery = 0 premierz = 0 endif else BEGIN ;------------------------------------------------------------ ; redefinition eventuelle du domaine ajuste a boite (a 6 elements) ; + on recupere la dim du nouveau domaine ;------------------------------------------------------------ if keyword_set(boite) then BEGIN Case N_Elements(Boite) Of 1:Domdef, lon1, lon2, lat1, lat2, 0.,boite[0],GRILLE=vargrid, _EXTRA = ex 2:Domdef, lon1, lon2, lat1, lat2, boite[0],boite[1],GRILLE=vargrid, _EXTRA = ex 4:Domdef, [Boite, prof1, prof2],GRILLE=vargrid, _EXTRA = ex 5:Domdef, [Boite[0:3], 0, Boite[4]],GRILLE=vargrid, _EXTRA = ex 6:Domdef, Boite,GRILLE=vargrid, _EXTRA = ex Else: return, report('Mauvaise Definition de Boite') endcase ENDIF grille, mask, glam, gphi, gdep, nx, ny,nz,premierx,premiery, premierz, dernierx, derniery, dernierz ENDELSE ;------------------------------------------------------------ ; determination du nombre de pas de tps a extraire ds ce fichier ;------------------------------------------------------------ if nbretps gt 36+1*(mmdd ne '0101')-numsort+1 then nt=36+1*(mmdd ne '0101')-numsort+1 $ else nt=nbretps ;------------------------------------------------------------ ; if varcontient.ndims eq 3 then $ ncdf_varget,cdfid,nom,res,offset=[premierx,premiery,numsort-1],count=[nx,ny,nt] $ else $ ncdf_varget,cdfid,nom,res,offset=[premierx,premiery, premierz,numsort-1],count=[nx,ny,nz,nt] ;------------------------------------------------------------ ; rappel en boucle de nlec si il faut ouvrir de nouveaux fichiers ; pour constituer la serie temporelle ;------------------------------------------------------------ if nbretps gt 36+1*(mmdd ne '0101')-numsort+1 then begin if mmdd ne '0101' then year = year+1 if varcontient.ndims eq 3 then $ res = [[[res]] $ ,[[nlec5j(nom,1+36*(mmdd eq '0101'),nbretps-nt,tout=tout,GRILLE=vargrid,BOITE=boite)]]] $ ELSE BEGIN res=[res[*] $ ,(nlec5j(nom,1+36*(mmdd eq '0101'),nbretps-nt,tout=tout,GRILLE=vargrid, BOITE=boite))[*]] res=reform(res,nx,ny,nz,nbretps, /over) ENDELSE ncdf_varget,cdfid,'time_counter',temps, offset = [numsort-1],count=[nt] time = [long(temps)+julday(1, 5, 1979), time] jpt=nt+jpt endif else BEGIN ncdf_varget,cdfid,'time_counter',temps, offset = [numsort-1],count=[nt] time = long(temps)+julday(1, 5, 1979) jpt=nt endelse ;------------------------------------------------------------ ncdf_close,cdfid return,res ;------------------------------------------------------------ ;------------------------------------------------------------ end