c***********************************************************************
c***********************************************************************
c                                                                      *
c       program plates2gmt                                             *
c                                                                      *
c purpose:  this program reads in a list of plates-formatted data file *
c      and converts it to a gmt-formatted xy file                      *
c                                                                      *
c                                                                      *
c                       PLATES                                         *
c                       U.T. Institute for Geophysics                  *
c                       4412 Spicewood Springs Road, Bldg. 600         *
c                       Austin, Texas  78759-8500                      *
c                                                                      *
c  written by:  L.M. Gahagan            June 18, 1993                  *
c                                                                      *
c***********************************************************************
c***********************************************************************
	program plates2gmt
c
        character name*80,idtype*2,astr*30
	character bstr*10
        integer iref,istr,id,itype,iclr
        real xlat,xlon,t1,t2
c
c  initialize variables
c
        iref=9999
        idtype='PP'
        itype=1
        t1=999
        t2=-999
        istr=1
	icnt = 1
        iclr=1
c
        write(*,*)' '
        write(*,*)'               plates2gmt'
        write(*,*)'  '
        write(*,*)'                 PLATES'
        write(*,*)'        Institute for Geophysics'
        write(*,*)'      University of Texas at Austin'
        write(*,*)'  4412 Spicewood Springs Road, Bldg. 600' 
        write(*,*)'         Austin, TX  78759-8500' 
        write(*,*)' '
	write(*,*)'     (Last modified: 20 April 1998)'
        write(*,*)' '
	write(*,*)'This program takes a plates-formatted data file'
	write(*,*)'and converts it to gmt-formatted xy file'
c
 5      write(*,*)'Enter name of input file'
	write(*,*)'(type quit to end program)'
        read(*,'(a)',err=18) name
	write(*,'(a)') name
	if(name(1:4).eq.'quit' .or. name(1:4).eq.'QUIT') goto 98
        open(unit=2,file=name,status='old',err=5)
        write(*,*) '  '
        write(*,*) 'enter name of output file'
        read(*,'(a)') name
        open(unit=3,file=name,status='unknown')
	write(*,*)' '
	write(*,*)'...working...'
	write(*,*)' '
	write(3,1005) '>'
c
 10	continue
        read(2,1001,err=97,end=20) iref,istr,astr
        read(2,1002) 
     *    id,t1,t2,idtype,itype,id,iclr,ipoint,bstr
	icnt=1
 15	continue
        read(2,*) xlat,xlon,ipen
	if(xlat.eq.99 .and. xlon.eq.99) then
	  write(3,1005) '>'
	  goto 10
	endif
	if(ipen.eq.3 .and. icnt.ne.1) write(3,1005) '>'
	write(3,1006) xlon,xlat
	icnt=0
	goto 15
c
  18	continue
	write(*,*) 'error with file name. stop'
  20	continue
	close(unit=2)
	close(unit=3)
	goto 5
c
c
 1001	format(i4,i5,x,a30)
 1002   format(x,i3,x,f6.1,x,f6.1,x,a2,i4,x,i3,x,i3,x,i5,x,a10)
 1004   format(f9.4,1x,f9.4,x,i1)
 1005   format(a1)
 1006   format(f9.4,x,f9.4)
c
 97     write(*,*)'Error'
        write(*,1001) iref,istr,astr
 98     continue
	write(*,*)'End program'
        stop
        end
