C written 4/12/01 Phil Massey, Lowell Observatory
C Takes the list of data files in "tempim[1-8]", makes sure that a "als.2"
C exists, and then and sorts them by
C filter into "[U-I]im[1-8]" (40 files)
	character*80 in1,inline
	character*7 f1
	character*1 ii
	character*4 f2
	do 1 i=1,8
	write(ii,3) i
3	format(i1)
	f1="tempim"//ii
	write(6,4) f1
4	format(a10)
	open(unit=1,file=f1,status='old')
5	read(1,2,end=20) in1
2	format(a80)
C Now make sure that the "als.2" file exists:
	alast=lnblnk(in1)
C Now figure out which filter
		open(unit=2,file=in1(a:alast)//".als.2",
     &              status='old',err=98)
33		read(2,2,end=1001) inline
		if(inline(1:10).eq.'#K IFILTER') then
		f2=inline(17:17)//"im"//ii
		open(unit=3,file=f2,status="unknown",fileopt="EOF")
		write(3,2) in1
		close(unit=3)
		close(unit=2)
		go to 5
		end if
		go to 33
1001		stop "problem finding filter name in some damn file"
20	close(unit=1)
	go to 1
98	write(6,99) in1(1:alast)//".als.2"
99	format("Surprisingly, this allstar file doesn't exist:",a80)
	go to 5
1	continue
	stop "ALL OK IN SORTFILT"
	end
