      SUBROUTINE CLOSEDENSEFILES(npots,jpotlevs,ireqpars,ip2,
     *  maxlevel,ioutfile,maxparm,maxpot,iposfile,m)

C     CLOSEDENSEFILES CLOSES FILES CONTAINING VARIABLES
C     ON GIVEN DENSITY SURFACES

      dimension ip2(0:maxlevel),ioutfile(0:maxparm,maxpot)
      dimension jpotlevs(maxpot),iposfile(maxpot)

c     run through for each requested reference surface

      do 45 n=1,npots

c     close position file

      call onefileclose(iposfile(n))

c     close variable files

       do 50 i0=1,ireqpars
        call onefileclose(ioutfile(ip2(i0),n))
50     continue
       
45    continue

      return
      end

