pro storsave_wc,yrls,sa_yr,sa_day,sa_time,average,way ;back up files ;Load the existing storage file ;cmd="load,'/data/davis2/wwg/wcreek/output/stor/wc"+yrls+".stor',storage" ;cmd="load,'/davis/s1/wang/d2wwg/wcreek/output/stor/wc"+yrls+".stor',storage" IF way EQ 2 THEN BEGIN fname='' fname=!outstor+yrls+'.stor' openw,f,fname,/get_lun for i=0,len(sa_yr)-1 do begin printf,f,format='(I9,i6,F6.1, 1x, E15.7)',sa_yr(i),sa_day(i),sa_time(i),average(i) endfor close,f free_lun,f GOTO,ren ENDIF fname='' fname=!outstor+yrls+'.stor' cmd="load,fname,storage" r=execute(cmd) ;fname='/data/davis2/wwg/wcreek/output/stor/wc'+yrls+'.stor' ;fname='/davis/s1/wang/d2wwg/wcreek/output/stor/wc'+yrls+'.stor' ;fname=!outstor+yrls+'.stor' a1="spawn,'cp "+fname+" "+fname+".bak" a2=execute(a1) print,'Backing up old file' print,'Saving '+fname+'.bak' ;;; After backup, save the new data, two ways, ;;; way=1, use one-to-one checking ;;; way=0, simply add data in the end IF way EQ 1 THEN BEGIN openw,f,fname,/get_lun flag=fltarr(len(storage)) flag=flag+1.0 print,flag help,flag ;--update the data in the same day. for i=0,len(storage)-1 do begin a1=storage(1,i);julian day b1=storage(2,i);time for j=0,len(sa_yr)-1 do begin a2=sa_day(j);julian day in the new data array b2=sa_time(j);time in the new datat array if(a1 eq a2 and b1 eq b2)then begin flag(i)=0.0 ; print,a1,a2,b1,b2,flag(i),i endif endfor endfor for i=0,len(storage)-1 do begin if(flag(i) ne 0.0) then begin printf,f,format='(I9,i6,F6.1, 1x, E15.7)',storage(*,i) endif endfor for i=0,len(sa_yr)-1 do begin printf,f,format='(I9,i6,F6.1, 1x, E15.7)',sa_yr(i),sa_day(i),sa_time(i),average(i) endfor close,f free_lun,f ;load again to sort in order ;cmd="load,'/data/davis2/wwg/wcreek/output/stor/wc"+yrls+".stor',storage1" ;cmd="load,'/davis/s1/wang/d2wwg/wcreek/output/stor/wc"+yrls+".stor',storage1" cmd="load,fname,storage1" r=execute(cmd) a=fltarr(len(storage1)) for i=0,len(storage1)-1 do begin a(i)=(storage1(1,i)*100+storage1(2,i)) endfor print,a b=(sort(a)) s1=storage1(*,b) openw,f,fname,/get_lun for i=0,len(storage1)-1 do begin printf,f,format='(I9,i6,F6.1, 1x, E15.7)',s1(*,i) endfor close,f free_lun,f ENDIF IF way EQ 0 THEN BEGIN print,'adding new data inthe end of the old file' openw,f,fname,/get_lun print,storage for i=0,len(storage)-1 do begin printf,f,format='(I9,i6,F6.1, 1x, E15.7)',storage(*,i) endfor for i=0,len(sa_yr)-1 do begin printf,f,format='(I9,i6,F6.1, 1x, E15.7)',sa_yr(i),sa_day(i),sa_time(i),average(i) endfor close,f free_lun,f ENDIF ren: return end