c       program prof2saki
c       written by Jeff Phillips
	dimension id(14),pgm(2),x(2000),obs(2000),z(2000)
	character*50 ifile,ofile,ifile2
        data dval/1.e38/
c
	print 16,' binary input file: '
16	format(1x,a,$)
	read (5,10) ifile
10	format (a50)
        open (10,file=ifile,form='unformatted',status='old')
	print 16,' ascii output file: '
	read (5,10) ofile
        open (11,file=ofile,form='formatted',status='new')
        print 16,' binary altitude file (in meters) (or return): '
	read (5,10) ifile2
	if (ifile2.ne.' ') then
                open (12,file=ifile2,form='unformatted',status='old')
		read (12) id
                print 16,' enter a constant (in meters) to add to'
                print 16,' the altitude: '
                read (5,*) alt
		go to 11
		endif
        print 16,' enter altitude (in meters): '
	read (5,*) alt
	do 9 i=1,2000
9       z(i)=-0.001*alt
11	read (10) id,pgm,nc,nr,nz,xo,dx,yo,dy
	if (nz.eq.1.and.nr.eq.1.and.nc.lt.2001) go to 12
	print *, ' can`t handle it.'
	go to 999
12	if (dx.eq.0) go to 20
	do 15 i=1,nc
15	x(i)=xo+(i-1)*dx
	go to 25
20	read (10) (x(i),i=1,nc)
25	continue
	read (10) zil,(obs(i),i=1,nc)
	if (ifile2.ne.' ') then
		read (12) zil,(z(i),i=1,nc)
		do 29 i=1,nc
		if (z(i).ge.dval) z(i)=0.
29              z(i)=-0.001*(z(i)+alt)
		end if
	do 30 i=1,nc
	if (obs(i).ge.dval) obs(i)=0.
30	write (11,*) x(i),z(i),obs(i)
999	stop
	end
