anchor.diff: -      PROGRAM ff2gmt
  -C----
  -C Convert the static_out finite fault model to a format that GMT
  -C can use for mapping using psxy with -SJ option
  +      PROGRAM MAIN
  +C----
  +C Convert a finite fault model to a format that GMT can use
   C----
         IMPLICIT none
         REAL*8 pi,d2r
         PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/180.0d0)
  -      CHARACTER*40 ifile,ofile,nfile,tfile,cfile
  -      INTEGER getdep
  +      CHARACTER*40 ifile,sfile,tfile,zfile,cfile,nfile
         LOGICAL ex
         INTEGER i,nflt,FMAX
         PARAMETER (FMAX=1500)
         REAL*8 evlo(FMAX),evla(FMAX),evdp(FMAX),str(FMAX),dip(FMAX),
        1       rak(FMAX),dx(FMAX),dy(FMAX),slip(FMAX),trup(FMAX),hylo,hyla
         REAL*8 time
  -      INTEGER iL,iR,iB,iT
  -      REAL*8 Lmx,Rmx,Bmx,Tmx
  -
  +      REAL*8 cosd
  +
  +C----
   C Parse command line, check for files
  -      call gcmdln(ifile,ofile,time,nfile,tfile,cfile,getdep)
  +C----
  +      call gcmdln(ifile,sfile,tfile,zfile,cfile,nfile,time)
         if (ifile.eq.'none') then
             write(*,*) '!! Error: Input finite fault file unspecified'
             call usage('!! Use -f FFMFILE to specify input file')
  
positive.code:           inquire(file=ifile,EXIST=ex)
            if (.not.ex) call usage('!! Error: no input file: '//ifile)
        endif
        if (ofile.eq.'none') then
            write(*,*) '!! Error: No output file specified'
            call usage('!! Use -o SLPFILE to specify slip output file')
        endif
  
  C Read finite fault model, initiate output files
        call readffm(ifile,evlo,evla,evdp,str,dip,rak,dx,dy,slip,trup,
       1             hylo,hyla,nflt)
        open(unit=10,file=ofile,status='unknown')
        if (nfile.ne.'none') open(unit=11,file=nfile,status='unknown')
  
  C----
  C Write files in GMT readable format. If subfault has ruptured, include
  C slip so patch can be colored, otherwise leave out so patch will be
  C transparent.
  C----
        do 14 i = 1,nflt
            if (getdep.eq.1) then
                write(10,*) evlo(i),evla(i),evdp(i)*1.0d-3,str(i),
       1                    dx(i)*1.0d-3,dy(i)*dcos(d2r*dip(i))*1.0d-3
                goto 14
            endif
            if (time.le.0.0d0) then
                write(10,*) evlo(i),evla(i),slip(i),str(i),dx(i)*1.0d-3,
       1                    dy(i)*dcos(d2r*dip(i))*1.0d-3
            else
                if (trup(i).le.time) then
                    write(10,*) evlo(i),evla(i),slip(i),str(i),
       1                        dx(i)*1.0d-3,dy(i)*dcos(d2r*dip(i))*1.0d-3
                elseif (nfile.ne.'none') then
                    write(11,*) evlo(i),evla(i),str(i),dx(i)*1.0d-3,
       1                        dy(i)*dcos(d2r*dip(i))*1.0d-3
                endif
            endif
     14 continue
  
  C Print XYT file
        if (tfile.ne.'none') then
            open(unit=13,file=tfile,status='unknown')
            do 15 i = 1,nflt
                write(13,*) evlo(i),evla(i),trup(i)
     15     continue
        endif
  
  C Print quadrilateral outline of FFM
        if (cfile.ne.'none') then
            open(unit=14,file=cfile,status='unknown')
            do 16 i = 1,nflt
                if (i.eq.1) then
                    iL = i
                    iR = i
                    iB = i
                    iT = i
                    Lmx = evlo(i)
                    Rmx = evlo(i)
                    Bmx = evla(i)
                    Tmx = evla(i)
                else
                    if (evlo(i).lt.Lmx) then
                        Lmx = evlo(i)
                        iL = i
                    endif
                    if (evlo(i).gt.Rmx) then
                        Rmx = evlo(i)
                        iR = i
                    endif
                    if (evla(i).lt.Bmx) then
                        Bmx = evla(i)
                        iB = i
                    endif
                    if (evla(i).gt.Tmx) then
                        Tmx = evla(i)
                        iT = i
                    endif
                endif
     16     continue
            write(14,*) evlo(iL),evla(iL)
            write(14,*) evlo(iT),evla(iT)
            write(14,*) evlo(iR),evla(iR)
            write(14,*) evlo(iB),evla(iB)
            write(14,*) evlo(iL),evla(iL)
        endif
  
        END
  
  C======================================================================c
  
        SUBROUTINE readffm(ffmfile,evlo,evla,evdp,str,dip,rak,dx,dy,slip,
       1                   trup,hylo,hyla,nflt)
  
negative.code:           if (tag(1:2).eq.'-f') then
                i = i + 1
                call getarg(i,ifile)
            elseif (tag(1:5).eq.'-slip') then
                i = i + 1
                call getarg(i,sfile)
            elseif (tag(1:5).eq.'-time') then
                i = i + 1
                call getarg(i,tfile)
            elseif (tag(1:4).eq.'-dep') then
                i = i + 1
                call getarg(i,zfile)
            elseif (tag(1:5).eq.'-clip') then
                i = i + 1
                call getarg(i,cfile)
            elseif (tag(1:7).eq.'-noslip') then
                i = i + 1
                call getarg(i,nfile)
            elseif (tag(1:5).eq.'-trup') then
                i = i + 1
                call getarg(i,tag)
                read (tag,'(BN,F12.0)') time
            elseif (tag(1:2).eq.'-h') then
                call usage(' ')
            else
                call usage('!! Error: no option '//tag)
            endif
            goto 901
    902 continue
  