;+ ; Contains the check_corres_year_directory procedure ; ; :Author: ; Eléonore Holle ; ; :History: ; 2013/11/06: Created ; ; 2014/10/08: Last Edit ;- ; ;+ ; Procedure de mise a jour du fichier corres_year_directory ; ; :Params: ; ; :Keywords: ; update: in, optional, type=byte ; recalculs? ;- PRO check_corres_year_directory,update = update ; num_flight est le numero de repertoire le plus eleve du fichier ; corres_year_directory (exemple: pour s80flight on prendra ; num_flight = 80 ligne ='' ; lecture du fichier corres_year_directory pour trouver le dernier repertoire openr,lun,'corres_year_directory',/get_lun while not EOF(lun) do begin readf,lun,ligne if (strmid(ligne,0,1) eq 's') then num_flight = strmid(ligne,1,2) endwhile free_lun,lun ; recherche d un eventuel nouveau repertoire i=num_flight+1 ; recuperation de la page html du contenu du fichier sXXflight pour XX=i str_i = strcompress(string(i),/remove_all) adresse = 'http://cassini.physics.uiowa.edu/~wsk/cas/daspage/cas_data/s'+str_i+'flight/' command = "wget --http-user=casrpws --http-passwd=uiowa "+adresse spawn,command structure = file_info('index.html') if structure.exists ne 0 then begin num_flight_new = i date_premier_k = '' date_dernier_k = '' print,'//////////NOUVEAU REPERTOIRE///////' openr,lun,'index.html',/get_lun while not EOF(lun) do begin readf,lun,ligne if strmid(ligne,0,20) eq '<IMG SRC="/icons/unk' and date_premier_k eq '' then date_premier_k = strmid(ligne,53,10) if strmid(ligne,0,20) eq '<IMG SRC="/icons/unk' then date_dernier_k = strmid(ligne,53,10) if strmid(ligne,0,6) eq '</PRE>' then break endwhile spawn,"rm -rf index.html" free_lun,lun endif ;stop ; tableau contenant les dates de debut de chaque repertoire sXXflight ; en iowa first_K = strarr(num_flight) ; tableau contenant les dates de debut de chaque repertoire sXXflight ; dans le fichier corres_year_directory first_corres = strarr(num_flight) for i=1,num_flight do begin ; recuperation de la page html du contenu du fichier sXXflight pour XX=i if i lt 10 then str_i ='0'+strcompress(string(i),/remove_all) else str_i = strcompress(string(i),/remove_all) adresse = 'http://cassini.physics.uiowa.edu/~wsk/cas/daspage/cas_data/s'+str_i+'flight/' command = "wget --http-user=casrpws --http-passwd=uiowa "+adresse spawn,command openr,lun,'index.html',/get_lun ligne='' ; boucle qui parcourt la page html et stocke les dates de debut en iowa test =0 while not EOF(lun) do begin readf,lun,ligne if (strmid(ligne,0,28) eq '<IMG SRC="/icons/unknown.gif') then begin first = strmid(ligne,53,10) test = 1 endif if test eq 1 then break endwhile free_lun,lun ; suppression de la page html dont on n'a plus besoin spawn, "rm -rf index.html" first_K[i-1] = first endfor ind = 0 ; lecture de toutes les dates de debut des repertoires listes dans le ; fichier corres_year_directory et enregistrement dans le tableau first_corres openr,lun,'corres_year_directory',/get_lun while not EOF(lun) and ind lt num_flight do begin readf,lun,ligne if (strmid(ligne,0,1) eq 's') then begin first_corres[ind] = strmid(ligne,11,10) ind = ind+1 endif endwhile free_lun,lun ; chaine qui contiendra la liste des numeros de repertoire a modifier liste='' compteur=0 ; comparaison des dates de debut en iowa et dans corres_year_directory for i=0,num_flight-1 do begin if first_K[i] ne first_corres[i] then begin print,'-----------------------------------------------------' print,'Attention changement du repertoire ',strcompress('s'+string(i+1)+'flight',/remove_all) print,'Date debut dans le fichier corres_year_directory: ',first_corres[i] print,'Date debut sur le site iowa : ',first_K[i] if liste ne '' then liste = liste+'/'+string(i+1) else liste = string(i+1) compteur = compteur + 1 endif endfor if compteur eq 0 then print,'Pas de difference entre corres_year_directory et iowa' if keyword_set(update) then update = 1 else update = 0 ;stop if update eq 1 then begin if compteur ne 0 then begin j=0 ; indices pour periodes de recalculs tab_indices=intarr(compteur) for i=0,num_flight-1 do begin if first_K[i] ne first_corres[i] then begin tab_indices[j]=i j=j+1 endif endfor ; mise en tableau des dates debut a changer et des num de repertoire correspondant liste = strcompress(liste,/remove_all) tab_date=strarr(compteur,2) tab_date[*,0] = str_sep(liste,'/') for i=0,compteur-1 do tab_date[i,1] = first_K[tab_indices[i]] ; boucle pour connaitre le nombre de lignes du fichier ligne='' nb_lignes = 0 openr,lun,'corres_year_directory',/get_lun while not EOF(lun) do begin readf,lun,ligne nb_lignes = nb_lignes + 1 endwhile free_lun,lun tab_lignes = strarr(nb_lignes) ; mise a jour de corres_year_directory ligne='' date_fin = '' i = 0 j = 0 openr,lun,'corres_year_directory',/get_lun while not EOF(lun) do begin readf,lun,ligne ; test pour savoir si l on est sur une ligne a changer if strmid(ligne,0,3) eq strcompress('s'+tab_date(j,0),/remove_all) then begin ligne = strmid(ligne,0,11)+tab_date(j,1)+strmid(ligne,21,11) ; recherche de la date de fin de la ligne d avant if strmid(ligne,1,2) ne '01' then begin yyyy = strmid(ligne,11,4) ddd = strmid(ligne,15,3) hh = strmid(ligne,19,2) if hh ne '00' then begin hh = fix(hh) if hh lt 11 then hh = '0'+string(hh -1) else hh = string(hh-1) date_fin = strcompress(yyyy+ddd+'.'+hh,/remove_all) endif else begin if ddd ne 001 then begin ddd = string(ddd-1) ddd = strcompress(ddd,/remove_all) if strlen(ddd) eq 2 then ddd = '0'+ddd if strlen(ddd) eq 1 then ddd = '00'+ddd date_fin = strcompress(yyyy+ddd+'.23',/remove_all) endif else begin yyyy = string(yyyy -1) if((yyyy mod 4 eq 0 && yyyy mod 100 ne 0) or (yyyy mod 400 eq 0)) then ddd=366 else ddd=365 date_fin = strcompress(string(yyyy)+string(ddd)+'.23',/remove_all) endelse endelse endif tab_lignes[i-1] = strmid(tab_lignes[i-1],0,22)+date_fin tab_lignes[i] = ligne if j ne compteur-1 then j=j+1 endif else tab_lignes[i] = ligne i = i+1 endwhile free_lun,lun ; reecriture du fichier corres_year_directory openw,lun,'corres_year_directory',/get_lun for i=0,nb_lignes-2 do printf,lun,tab_lignes[i] if date_premier_k ne '' then begin yyyy = strmid(date_premier_k,0,4) ddd = strmid(date_premier_k,4,3) hh = strmid(date_premier_k,8,2) if hh ne '00' then begin hh = fix(hh) if hh lt 11 then hh = '0'+string(hh -1) else hh = string(hh-1) date_fin = strcompress(yyyy+ddd+'.'+hh,/remove_all) endif else begin if ddd ne 001 then begin ddd = string(ddd-1) ddd = strcompress(ddd,/remove_all) if strlen(ddd) eq 2 then ddd = '0'+ddd if strlen(ddd) eq 1 then ddd = '00'+ddd date_fin = strcompress(yyyy+ddd+'.23',/remove_all) endif else begin yyyy = string(yyyy -1) if((yyyy mod 4 eq 0 && yyyy mod 100 ne 0) or (yyyy mod 400 eq 0)) then ddd=366 else ddd=365 date_fin = strcompress(string(yyyy)+string(ddd)+'.23',/remove_all) endelse endelse line_before_new_line='' line_before_new_line = strmid(tab_lignes[nb_lignes-1],0,22)+date_fin printf,lun, line_before_new_line new_line = strcompress('s'+string(num_flight_new),/remove_all)+'flight/ '+date_premier_k+' '+date_dernier_k printf,lun,new_line endif else printf,lun,tab_lignes[nb_lignes-1] free_lun,lun ; message envoye str = '' nom_rep = strarr(compteur) for i=0,compteur-1 do begin if fix(tab_indices[i]+1) ge 10 then nom_rep[i] = strcompress('s'+string(tab_indices[i]+1)+'flight',/remove_all) else begin nom_rep[i] = strcompress('s0'+string(tab_indices[i+1])+'flight',/remove_all) endelse endfor for i=0,compteur-1 do str = str + '/// Periode : '+first_K[tab_indices[i]]+' a '+first_corres[tab_indices[i]]+' dans le repertoire '+nom_rep[i]+' . /////////////////// ' str = ' Calculs a faire sur les periodes : ////////////////////////////////////////////////////// '+ str ;stop if date_premier_k ne '' then begin str_rep = strcompress(string(num_flight_new),/remove_all) str_rep = strcompress('s'+str_rep+'flight',/remove_all) str = str + 'ATTENTION nouveau repertoire '+str_rep print,'///////////// ATTENTION nouveau repertoire '+str_rep+' //////////////////////' endif spawn,'echo '+str+' | mail -s "Calculs kronosdp a faire" eleonore.holle@obspm.fr' endif else spawn, 'echo Pas de modifications a faire | mail -s "Pas de nouveaux calculs a faire" eleonore.holle@obspm.fr' endif else begin print,'////////////////////////////////////////////////////////////////////////////////////////////' print,'Si vous desirez faire la mise a jour du fichier corres_year_directory relancez la procedure ' print,'avec le mot cle update check_corres_year_directory,update=1' endelse END