program mkave character*80 f1,f2,s1,fn real,allocatable::x(:),yave(:),yactual(:) write(6,*)'average of spectra in a list' if( iargc().ne.3)then write(6,600) 600 format(' usage: mkave ',/,/, 1 ' ... file.list',/, 2 ' ... resultant spectrum',/, 3 ' iopt ... 0 ... plain average',/, 4 ' 1 ... normalized to first spectrum',/) stop endif call getarg(1,f1) call getarg(2,f2) call getarg(3,s1) read(s1,*)iopt n=0 open(10,file=f1,status='old') 1 read(10,'(a)',end=99,err=99)fn n=n+1 goto 1 99 close(10) write(6,*)n,' spectra' if(n.lt.1)stop open(10,file=f1) read(10,'(a)')fn close(10) write(6,*)fn np=0 2 open(11,file=fn,status='old') read(11,*,end=88,err=88)xx,y np=np+1 goto 2 88 close(11) write(6,*)np,' points' if(np.lt.1)stop allocate(x(np),yave(np),yactual(np)) do 3 i=1,np x(i)=0. 3 yave(i)=0. anorm1=0. open(10,file=f1) do 4 i=1,n read(10,'(a)')fn open(11,file=fn) anorm=0. do 5 j=1,np read(11,*)xx,y anorm=anorm+abs(y) 5 yactual(j)=y close(11) if(i.eq.1)then anorm1=anorm else if(iopt.eq.1)then do 6 j=1,np 6 yactual(j)=yactual(j)*anorm1/anorm endif endif do 4 j=1,np 4 yave(j)=yave(j)+yactual(j) close(10) do 7 i=1,np 7 yave(i)=yave(i)/real(n) open(10,file=f2) do 8 i=1,np 8 write(10,100)x(i),yave(i) 100 format(f12.2,g12.4) close(10) end