Index: addend.f
===================================================================
--- addend.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ addend.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -28,4 +28,9 @@
       character res*4,rpat*4,sbrs*4,grn*4,grc*4
 
+      integer nml
+      
+      integer i, ifirs, ilars
+      
+      double precision cg
 
       grn = grpn
@@ -170,8 +175,20 @@
       character rpat*4,sbrs*4
       logical ntbb,bb
+      integer nml, nrs, ibd, iybd
 
       dimension ibd(mxbd+1),iybd(mxbd+1)
-
-
+      
+      integer iopfil, iendst
+      
+      double precision valang, dihedr
+
+      integer ish, i, i1, irng1, irng2, ilavr, ilaat, i2, i3, ibdrg,
+     &        ib, iat, ifirs, ifivr, ii, iow, isgbb1, ity, nfi, ilars,
+     &        ivrrp, ivrsb, jsh, j, iybdrg, k, lvrrp, nb, natsb, nla, 
+     &        nfirp, nxt, nsb, nlarp, nfisb, nlasb, nrp, nsh,
+     &        nvrsb, nxtbb1, nxtbb2, nxtsb
+      double precision ba, ca, ct, dx, dz, h3, h2, sa, st,to, x1, x2,
+     &        x3, y1, y2, y3, z1, z2, z3
+      
       ifirs=irsml1(nml)
       ilars=irsml2(nml)
@@ -638,4 +655,9 @@
 
       character rpat*4,sbrs*4,atnm*4,res*4,cgty*5,line*100
+      integer nml, nrs
+
+      integer iopfil, iendst
+
+      integer ifirs, ilars, ifvr, ilib, i, l, j, nchg
 
       ifirs=irsml1(nml)
Index: bgs.f
===================================================================
--- bgs.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ bgs.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -8,60 +8,4 @@
 ! ****************************************************************
 
-! Subroutine initlund: Initializes data structures used frequently 
-! in connection with Biased Gaussian Steps and the energy functions
-! from Anders Irback's protein folding model. Calls: none.
-!
-      subroutine init_lund
-      include 'INCL.H'
-      include 'incl_lund.h'
-      logical bgsposs
-      do i=1,mxrs
-         iN(i)=-1
-         iCa(i)=-1
-         iC(i)=-1
-         iphi(i)=-34
-         ipsi(i)=-35
-      enddo
-!      print *,'total number of variables = ',nvr
-
-      do i=1,ntlml
-         npprs=1
-         do j=ivrml1(i),ivrml1(i)+nvrml(i)-1
-            mlvr(j)=i
-            if (nmvr(j).eq.'phi') then 
-               iphi(npprs)=j
-! Now if the residue is a proline, there is no phi angle in the variable
-! list in SMMP, and so iphi(j) will remain at the initial value. 
-! So, make sure you never use iphi(i) for proline. 
-            endif
-            if (nmvr(j).eq.'psi'.or.nmvr(j).eq.'pst') then 
-               ipsi(npprs)=j
-               npprs=npprs+1
-            endif
-         enddo
-         do j=irsml1(i),irsml2(i)
-            iN(j)=iatrs1(j) 
-            do k=iatrs1(j),iatrs2(j)
-               if (nmat(k)(1:2).eq.'ca') then 
-                  iCa(j)=k 
-               endif
-               if (nmat(k)(1:1).eq.'c') then 
-                  iC(j)=k 
-               endif 
-            enddo
-!            print *,'determined phi,psi serial for residue',j,' as '
-!     #           ,iphi(j),ipsi(j)
-         enddo
-      enddo
-      abgs=300.0
-      bbgs=10.0
-      bgsnvar=0
-      do i=1,nvr
-         if (bgsposs(i)) then
-            bgsnvar=bgsnvar+1
-            bgsvar(bgsnvar)=i
-         endif
-      enddo
-      end
 
 ! Checks if it is possible to perform a BGS update starting at the 
Index: bldmol.f
===================================================================
--- bldmol.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ bldmol.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -29,5 +29,11 @@
 
       include 'INCL.H'
-
+      ! Subroutine arguments
+      integer nml
+      
+      integer i, i1, i2, i3, ifirs, jow, j, jj
+      double precision x1, x2, x3, y1, y2, y3, z1, z2, z3
+      
+      double precision xg, zg
       dimension xg(3),zg(3)
 
@@ -97,5 +103,8 @@
  
       include 'INCL.H'
-
+! arguments      
+      integer nml, i1, i2, i3
+      
+      integer ibd, i, irs, ix
       dimension ibd(4)
       logical bb
@@ -178,5 +187,9 @@
 
       include 'INCL.H'
-
+!     arguments
+      integer i, ia
+      double precision ct, st, ca, sa, bl, x1, x2, x3, z1, z2, z3
+      double precision y1, y2, y3, h2, h3, dx, dz
+      
       ct=cstoat(i)
       st=sntoat(i)
@@ -249,5 +262,9 @@
 
       include 'INCL.H'
-
+!     arguments
+      integer i1, i2, i3
+      double precision x1, x2, x3, y1, y2, y3, z1, z2, z3, h1, h2, h3
+      double precision dz, dx
+      
       h1=xat(i2)
       h2=yat(i2)
@@ -308,7 +325,12 @@
 
       include 'INCL.H'
-      
+!     arguments
+      integer nml, i1, i2, i3
+      double precision xg, zg, ag
       dimension xg(3),zg(3),ag(3,3)
 
+      integer i
+      double precision ca, sa, cb,sb, cg, sg, d, ct2, ct3, dx, dz
+      double precision x1, x2, x3, y1, y2, y3, z1, z2, z3, st2, sa2, st3
 
       ca = cos(gbpr(4,nml))  ! alpha
Index: canon.f
===================================================================
--- canon.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ canon.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -40,5 +40,5 @@
       integer nmes
 !     temp:  Temperature of simulation
-      double precision temp
+      double precision temp, e_min
 !
 !      common/bet/beta
@@ -63,4 +63,5 @@
 
       eol = energy()
+      e_min = eol
       write (*,'(a,e12.5,/)')  'energy of start configuration:',eol
 
@@ -79,4 +80,10 @@
       do nsw=0,nswp
         call metropolis(eol,acz,can_weight)
+        if (eol.lt.e_min) then
+           write (*,*) "New minimum energy:", eol, "t=", nsw
+           write (*,*) eyel,eyhb,eyvr,eysl
+           e_min = eol
+           call outpdb(0, "minen.pdb")
+        endif
 !
         if(mod(nsw,nmes).eq.0) then
@@ -96,6 +103,7 @@
         end do
 ! Write down information on actual conformation
-         write(13,'(i5,2f12.3,5i7)')  nsw,  eol, rgy,
-     &                              nhel,mhel,nbet,mbet,mhb
+         write(13,'(i7,2f15.3,5i7,4f15.3)')  nsw,  eol, rgy,
+     &                              nhel,mhel,nbet,mbet,mhb,
+     &                              eyel,eyhb,eyvr,eysl
         end if
 !
Index: dihedr.f
===================================================================
--- dihedr.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ dihedr.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -22,4 +22,9 @@
 
       include 'INCL.H'
+      
+      integer i1, i2, i3, i4
+      
+      double precision x1, y1, z1, x2, y2, z2, ux1,uy1, uz1, a, u, u1,
+     &                 u2, ux2, uy2, uz2
 
       x1=xat(i2)-xat(i1)
@@ -77,4 +82,9 @@
 
       include 'INCL.H'
+      
+      integer i1, i2, i3
+      
+      double precision h1, h2, h3, x1, x2, x3, y1, y2, y3, x, y, u, a
+      
       h1=xat(i2)
       h2=yat(i2)
Index: enyflx.f
===================================================================
--- enyflx.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ enyflx.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -22,4 +22,12 @@
 
       include 'INCL.H'
+      
+      integer nml
+      
+      integer ntlvr, i, i14, i1, i1s, i2, i2s, ia, ic, ijhb, ifivr, 
+     &        ims, io, iowh, it, jowh, ity, iv, ivw, j, jty
+      double precision cqi, cth, qp, e0, evw, vr, ep, rij, py, px, pz, 
+     &                 rij2, rij6, rij12, sr, xij, xi, yij, xj, yj, yi, 
+     &                 zj, zi, zij
 
       ntlvr=nvrml(nml)
Index: enysol.f
===================================================================
--- enysol.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ enysol.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -25,4 +25,21 @@
 ! -------------------------------------------------------------
 ! TODO: Check the solvent energy for multiple molecules     
+!     arguments
+      integer nmol
+      
+!     functions
+      integer nursat
+
+      integer numbox, inbox, indsort, look, i, ii, ia, ib, ibox, icount
+      integer ilk, il, ik, ix, iy, iz, j, jy, jbox, jbi, jres, jj, jcnt
+      integer jtk, jx, jz, lbn, lst, mhx, mx, nsy, ndy, mz, my, nboxj
+      integer ndx, ncbox, nbt, nez, ndz, nex, ney, nlow, nhx, nnei
+      integer nrshi, nqxy, nrslow, mbt, nsx, nsz, numat, nup
+      double precision xyz, radb, radb2, ymin, diamax, area, akrad
+      double precision avr_x, avr_y, avr_z, dd, dr, dx, dy, dz, sizex
+      double precision rmax, shiftx, shifty, shiftz, sizey, sizez
+      double precision sizes, trad, zmin, xmax, xmin, ymax, zmax
+      double precision sdr, sdd, volume
+      
       dimension numbox(mxat),inbox(mxbox+1),indsort(mxat),look(mxat)
       dimension xyz(mxinbox,3),radb(mxinbox),radb2(mxinbox)
@@ -323,5 +340,5 @@
       include 'INCL.H'
       character lin*80
-
+      integer i
 !    Skipping comment lines, which begin with '!'  
       read(20,'(a)') lin
Index: getmol.f
===================================================================
--- getmol.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ getmol.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -38,5 +38,12 @@
 
       include 'INCL.H'
-
+!     arguments
+      integer nml
+!     functions      
+      integer iopfil, iendst
+      
+      integer i, iat, iow, ifirs, ibd, ilars, j, mvr, nbd, n, nbd1, nj
+      integer nh, nrs, ntlat, ntlvr, nat, nxt
+      double precision ba, t, to
       character res*4
 
@@ -270,9 +277,17 @@
 
       include 'INCL.H'
-
+!     arguments
+      integer nat, nxt, nvrr
+      
+!     functions
+      integer iendst
+      
+      integer icl, ibd, ib3, i, ib1, ib2, ic, iow, iexcp, ity, jow, lg
+      integer nln, j
       dimension icl(3),ibd(mxbd)
       character blnk,fix(3),nm(3)*3,res*4,resl*4,line*132
       data blnk/' '/
 
+      double precision ba, to
 
       nln=0
Index: incl_lund.h
===================================================================
--- incl_lund.h	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ incl_lund.h	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -31,14 +31,14 @@
       dimension asaexv(mxtyat,mxtyat),bsaexv(mxtyat,mxtyat)
 
-      common /lundff/kbias,
-     &     epshb1,epshb2,powa,powb,sighb,cthb,
-     &     cthb2,
-     &     alhb,blhb,sighb2,cdon,cacc,casc,
-     &     ihpat,nhpat,hpstrg,
-     &     exvk,exvcut,exvcut2,
-     &     matcon,
-     &     sigsa,sig2lcp,asalcp,bsalcp,
-     &     lcp1,lcp2,ilpst,ilpnd,
-     &     exvlam,exvcutg,exvcutg2,
-     &     sig2exv,asaexv,bsaexv
+      common /lundff/kbias,                                             &
+     &     epshb1,epshb2,powa,powb,sighb,cthb,                          &
+     &     cthb2,                                                       &
+     &     alhb,blhb,sighb2,cdon,cacc,casc,                             &
+     &     ihpat,nhpat,hpstrg,                                          & 
+     &     exvk,exvcut,exvcut2,                                         &
+     &     matcon,                                                      & 
+     &     sigsa,sig2lcp,asalcp,bsalcp,                                 &
+     &     lcp1,lcp2,ilpst,ilpnd,                                       &
+     &     exvlam,exvcutg,exvcutg2,                                     &
+     &     sig2exv,asaexv,bsaexv 
       save /lundff/
Index: init_molecule.f
===================================================================
--- init_molecule.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ init_molecule.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -32,6 +32,6 @@
       include 'INCP.H'
 
-!f2py character*80 optional, intent(in) :: seqfile = ' '
-!f2py character*80 optional, intent(in) :: varfile = ' ' 
+Cf2py character*80 optional, intent(in) :: seqfile = ' '
+Cf2py character*80 optional, intent(in) :: varfile = ' ' 
       
       character grpn*4,grpc*4
Index: main.f
===================================================================
--- main.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ main.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -25,4 +25,6 @@
       character grpn*4,grpc*4
       logical lrand,bgsposs
+      integer argc, status, argv_length
+      character(len=255) :: argv
 
 ! =================================================== Energy setup
@@ -32,4 +34,11 @@
 !     libraries of residues. 
       libdir='./SMMP/'
+      
+!     Set the maximum log level. The larger the number the more detailed
+!     the log.
+      MAXLOGLEVEL = 1
+!     File unit to use for the log file.
+      LOGFILEUNIT = 27
+      open(LOGFILEUNIT, file="smmp.log")
 
 !      The switch in the following line is now not used.
@@ -62,5 +71,5 @@
                  ! =1: ab Initio from sequence (& variables)
       seqfile='EXAMPLES/enkefa.seq'
-      varfile='EXAMPLES/enkefa.var'
+      varfile='EXAMPLES/enkefa.ann'
 !       varfile = ' '
       
@@ -95,4 +104,5 @@
       eps = 1.0d-7 ! requested precision
       call minim(imin, maxit, eps)
+      call outvar(0, ' ')
 !     To do a canonical Monte Carlo simulation uncomment the lines below
 !       nequi = 100
Index: mklist.f
===================================================================
--- mklist.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ mklist.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -19,5 +19,7 @@
 ! TODO: Calculate van-der-Waals regions over all molecules.
       include 'INCL.H'
-
+      integer nml
+
+      integer mxh, mx2, l1st1, l1st2, l2nd1, l2nd2, l1i, l2i
       parameter (mxh=50,         ! max. # of atom regions
      &           mx2=50)
@@ -27,4 +29,8 @@
       dimension l1st1(mxh),l1st2(mxh),l2nd1(mxh),l2nd2(mxh)
      &         ,l1i(mxbd),l2i(mx2)
+
+      integer ia, i, i1s, i2s, ibd, ib, ifivr, ifiat, ilaat, im, ilavr,
+     &        iob, io, ioiob, iow, it, is, iv, jbd, j, n1i, n14, n1st,
+     &        n2nd, n2i, ntlms, nvw
 
 ! _______________________ indices of 1st vdw-region/14-partner for 'nml'
Index: mulcan_par_mod.f90
===================================================================
--- mulcan_par_mod.f90	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ mulcan_par_mod.f90	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -239,5 +239,5 @@
 ! File with contact map of reference configuration
 ! FIXME: This must go. Reference structure needs to be read in main()
-      open(9,file='enkefa.ref')
+      open(9,file='1vp.ref')
 ! File with multicanonical parameter
       open(10,file='muca.d')
Index: redseq.f
===================================================================
--- redseq.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ redseq.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -28,5 +28,9 @@
       include 'INCL.H'
 
+      ! Function definitions
+      integer iofil, iendst, ibegst, iopfil
+
       character blnk,res*4,line*132,hlin*132
+      integer i, i1, i2, ifirs, ie, id, ib, ic, ii, l, lg, nln, nrs
       data blnk/' '/
 
Index: redstr.f
===================================================================
--- redstr.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ redstr.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -26,9 +26,10 @@
 ! CALLS: ibegst,iendst
 ! ..........................................................
-
-      implicit integer*4 (i-n)
-
+      integer ib, ie, l
       character spr,blnk,str*(*),strn*(*)
+      
       data blnk/' '/
+      
+      integer i, ic, ish, ii
 
       if (spr.eq.blnk) then
@@ -234,5 +235,8 @@
 
       character*(*) str
-
+      
+      integer ibegst, iendst
+      
+      integer i, ic, ii, ish
       ii=ibegst(str)
       if (ii.gt.0) then
@@ -258,4 +262,8 @@
 
       character str*(*)
+      
+      integer iendst, ibegst
+      
+      integer i, ii, ic, ish
 
       ii=ibegst(str)
@@ -283,5 +291,5 @@
 ! ........................................................
 
-      implicit integer*4 (i-n)
+      integer lun
 
       logical exs
Index: redvar.f
===================================================================
--- redvar.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ redvar.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -70,4 +70,6 @@
       include 'INCL.H'
 
+!     functions
+      integer iopfil, iendst, iredin, iredrl, ibegst
 ! maxfld: max. # of fields in one command
 ! maxide: max. # of identifiers in a field
@@ -75,4 +77,10 @@
 ! ilrg:   a large integer
 
+      integer maxfld, maxide, maxcmd, ilrg, ifdend, icb, i, ib, ibz
+      integer ife, ifb, ide, id, ice, ie, ieh, ieh1, iez, ihz, ifx, ifld
+      integer ile, ii, ihy, ilb, iml, it, in ,io, inum, kbz, iv, ity, jb
+      integer j, k, l, kez, kk, kv, lez, lbz,ll, ll1, ll2, n, nfi, ncmd
+      integer nfld, nide, nml, ntlvr
+      double precision vlvrx, rn, vr, val
       parameter (maxfld=4,
      &           maxide=30,
Index: regul.f
===================================================================
--- regul.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ regul.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -44,5 +44,5 @@
      &  '   Wt(energy) = ',wtey,'  Wt(regul.) = ',wtrg
 
-      call minim(1, nsteps, acc)
+      call minim(2, nsteps, acc)
 
       write(*,*) ' '
Index: setmvs.f
===================================================================
--- setmvs.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ setmvs.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -47,10 +47,18 @@
 
       include 'INCL.H'
+!     ID of molecule
+      integer nml
+
+      integer nursvr
 
       logical bb
-
+      integer mxh, lvw1h, lvw2h, l1h, l2h
       parameter (mxh=10)
       dimension lvw1h(mxh),lvw2h(mxh),l1h(mxh),l2h(mxh)
 
+      integer ifivr, i, i1, ia, ib, ic, ifirs, ifiat, ko, ilaat, ii,
+     &        ilars, ilavr, io, ir, irg1, is, it, iv, j, k, j1, jns,
+     &        j2, j1s, ja, jb, jv, jo, l, i2, irg2, n, nad, nms,
+     &        ntlvr
 
       ntlvr=nvrml(nml)
@@ -418,7 +426,12 @@
       include 'INCL.H'
 
+      integer nml, nrs, ifirg, ilarg, irg1, irg2
+                  
       logical bb
+      integer ibd
       dimension ibd(4)
 
+      integer i, ib, ila, ifi, il, ixt, k, j, jb            
+                  
       ilarg=ifirg
 
Index: setvar.f
===================================================================
--- setvar.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ setvar.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -23,6 +23,15 @@
 
       include 'INCL.H'
+Cf2py intent(in) nml, vlvrx
+      integer nml
+      double precision vlvrx
+      dimension vlvrx(mxvr)
+      
+!     functions
+      double precision difang
 
-      dimension vlvrx(mxvr)
+      integer i, iat,ity, iow, j, jat, i1vr
+      double precision ba, to, tsh
+      
 
       i1vr=ivrml1(nml)
Index: utilities.f
===================================================================
--- utilities.f	(revision ffd2d46888ff96b67701d9b306ce4aac68b5bd99)
+++ utilities.f	(revision cb47b9cbc592f256d0e066794c5ad7b9a1b99540)
@@ -168,2 +168,27 @@
 !     End fileNameMP
 
+
+!----------------------------------------------------------------------
+!     Add messages to log. This routine takes the log (debugging) mes-
+!     sages and writes them to the log file if the log level is less or
+!     equal to the maximum log level given by the global variable 
+!     MAXLOGLEVEL.
+!
+!     @author Jan H. Meinke
+!
+!     @param loglevel level at which this message should be added to 
+!            the log.
+!     @param message message to be written to the log.
+!     @param rank global rank of this node if running an MPI job zero 
+!            otherwise.
+!----------------------------------------------------------------------
+      subroutine addLogMessage(loglevel, message, rank)
+      
+         integer :: loglevel, rank
+         character(LEN=*) :: message
+         
+         if (loglevel <= MAXLOGLEVEL) then
+            write(LOGFILEUNIT, *) message
+         end if
+         
+      end subroutine addLogMessage
