m_cpuinfo Subroutine

public subroutine m_cpuinfo(model_name)

reads /proc/cpuinfo if it exists (i.e. Linux) to return relevant info

Arguments

Type IntentOptional Attributes Name
character(len=default_string_length) :: model_name

as obtained from the 'model name' field, UNKNOWN otherwise


Source Code

   SUBROUTINE m_cpuinfo(model_name)
      !! reads /proc/cpuinfo if it exists (i.e. Linux) to return relevant info

      CHARACTER(LEN=default_string_length)               :: model_name
         !! as obtained from the 'model name' field, UNKNOWN otherwise

      INTEGER, PARAMETER                                 :: bufferlen = 2048

      CHARACTER(LEN=bufferlen)                           :: buffer
      INTEGER                                            :: i, icol, iline, imod, stat

      model_name = "UNKNOWN"
      buffer = ""
      OPEN (121245, FILE="/proc/cpuinfo", ACTION="READ", STATUS="OLD", ACCESS="STREAM", IOSTAT=stat)
      IF (stat == 0) THEN
         DO i = 1, bufferlen
            READ (121245, END=999) buffer(I:I)
         END DO
999      CLOSE (121245)
         imod = INDEX(buffer, "model name")
         IF (imod > 0) THEN
            icol = imod - 1 + INDEX(buffer(imod:), ":")
            iline = icol - 1 + INDEX(buffer(icol:), NEW_LINE('A'))
            IF (iline == icol - 1) iline = bufferlen + 1
            model_name = buffer(icol + 1:iline - 1)
         END IF
      END IF
   END SUBROUTINE m_cpuinfo