anchor.diff:        vrb = 0
         ostyle = 0
         indx = 0
  +      misfit = 0
         narg = iargc()
         if (narg.eq.0) call usage('!! Error: no command line arguments')
         i = 0
  
positive.code:       endif
  
  C----
  C Run inversion
  C----
        if (invert.eq.0) then
  
negative.code:       do 442 i = 1,npar
            x(i,1) = btmp(i,1)
    442 continue
        RETURN
        END
  
  C----------------------------------------------------------------------C
  
        SUBROUTINE getdamp(soln,gf,obs,nobs,OBSMAX,nflt,FLTMAX,damp,
       1                   smooth,smoof)
        IMPLICIT none
        CHARACTER*80 smoof
        REAL*8 damp,smooth
        INTEGER OBSMAX,FLTMAX
        REAL*8 obs(OBSMAX,6)
        REAL*8 gf(OBSMAX,FLTMAX,6)
        REAL*8 soln(FLTMAX,2),misfit,length
        REAL*8 pre(3)
        INTEGER i,j,nobs,nflt,k
        REAL*8 x1,x2,x3,y1,y2,y3,a,r,dampsv,rmin
        rmin = -1.0d0
        damp = 0.0d0
        k = 0
    101 k = k + 1
            call lstsqr(soln,gf,obs,nobs,OBSMAX,nflt,FLTMAX,damp,
       1                smooth,smoof)
            misfit = 0.0d0
            do 102 i = 1,nobs
                pre(1) = 0.0d0
                pre(2) = 0.0d0
                pre(3) = 0.0d0
                do 103 j = 1,nflt
                    pre(1) = pre(1) + gf(i,j,1)*soln(j,1)
       1                                             + gf(i,j,4)*soln(j,2)
                    pre(2) = pre(2) + gf(i,j,2)*soln(j,1)
       1                                             + gf(i,j,5)*soln(j,2)
                    pre(3) = pre(3) + gf(i,j,3)*soln(j,1)
       1                                             + gf(i,j,6)*soln(j,2)
    103         continue
                misfit = misfit + (pre(1)-obs(i,4))*(pre(1)-obs(i,4))
       1                   + (pre(2)-obs(i,5))*(pre(2)-obs(i,5))
       2                   + (pre(3)-obs(i,6))*(pre(3)-obs(i,6))
    102     continue
            length = 0.0d0
            do 104 i = 1,nflt
                length = length + soln(i,1)*soln(i,1)
       1                   + soln(i,2)*soln(i,2)
    104     continue
            misfit = dlog10(dsqrt(misfit))
            length = dlog10(dsqrt(length))
            if (k.eq.1) then
                x1 = misfit
                y1 = length
            elseif (k.eq.2) then
                x2 = misfit
                y2 = length
            elseif (k.eq.3) then
                x3 = misfit
                y3 = length
            else
                x1 = x2
                y1 = y2
                x2 = x3
                y2 = y3
                x3 = misfit
                y3 = length
            endif
            if (k.ge.3) then
                a = 2.0d0*(x2*y3-x3*y2+x3*y1-x1*y3+x1*y2-x2*y1)
                r = dsqrt(((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))*
       1              ((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))*
       2              ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)))/a
                if (r.gt.0.0d0.and.rmin.lt.0.0d0) then
                    dampsv = damp - 0.01d0
                    rmin = r
                elseif (r.gt.0.0d0.and.r.lt.rmin) then
                    dampsv = damp - 0.01d0
                    rmin = r
                endif
            endif
            damp = damp + 0.01d0
        if (k.le.100) goto 101
        write (0,1001) 'Choosing damping parameter: ',dampsv
   1001 format('L-curve damping parameter: ',F10.6)
        damp = dampsv
        RETURN
        END
  
  