      SUBROUTINE TIMEIT(CMSGTM,DTIME)
C***********************************************************************
C This version of timeit uses the system call "etime" available under
C SunOS and some other bsd-like Unix systems (e.g., Convex unix).
C
C***********************************************************************
c begin history
C 94.06.20 (PJF) add dtime to the formal parameters
C 95.06.19 (PJF) modified to suppress printing in CMSGTM='noprint'
C 04.04.05 (BTD) changed IF(CMSGTM(1:7).NE.. to IF(CMSGTM.NE..
c end history
C Copyright (C) 1993,1995,2004 B.T. Draine and P.J. Flatau
C This code is covered by the GNU General Public License.
C***********************************************************************
C Arguments:
      CHARACTER CMSGTM*(*)
      REAL DTIME
C
C External system calls:
      REAL ETIME
      EXTERNAL ETIME
C
C Local variables:
      REAL OLDTIM
      CHARACTER CSTA*3,CMSGNM*70
      REAL TARRAY(2)
C
C External subroutines:
      EXTERNAL WRIMSG
C
C Local variables to be saved:
      SAVE CSTA,OLDTIM
C
C Data statements:
      DATA CSTA/'ONE'/
C
      IF(CSTA.EQ.'ONE')THEN
         CSTA='TWO'
         OLDTIM=ETIME(TARRAY)
      ELSEIF(CSTA.EQ.'TWO')THEN
         CSTA='ONE'
         DTIME=ETIME(TARRAY)-OLDTIM
         IF(CMSGTM.NE.'NOPRINT'.AND.CMSGTM.NE.'noprint')THEN
            WRITE(CMSGNM,FMT='(A,A)')' Timing results for: ',CMSGTM
            CALL WRIMSG('TIMEIT',CMSGNM)
            IF(DTIME.GT.1.E4)THEN
               WRITE(CMSGNM,FMT='(F9.0, A)')DTIME,' CPU time (in secs)'
            ELSE
               WRITE(CMSGNM,FMT='(F9.3, A)')DTIME,' CPU time (in secs)'
            ENDIF
            CALL WRIMSG('TIMEIT',CMSGNM)
         ENDIF
      ENDIF
      RETURN
      END

