Share

API example: Extract information from screen out file

This example assumes you have some knowledge of the following:

  • the MSCD format, as defined in message.dat.
  • the .out file; see details in ..../data/dat/cmmesage.dat
  • analysis sequences; see details in the ..../data/dat/process.dat

To run this API, you must have already run a Flow analysis, and the required study file should be selected and open.

This script performs the following tasks:

  • Gets the name of the .out file and associated flow results
  • Creates and populates the ScreenOutput Class for the lOutName
  • Finds the Total Projected Area
  • Reaads the Maximum Injection pressure and the time it occurred.
'%RunPerInstance
'@
'@ DESCRIPTION
'@ This script shows how to extract information from the screen out (.out) file.
'@ Several examples are shown
'@
'@ This script perfoms a similar function to the studyrlt command
'@ studyrlt  <study> -message <sequence>  <message ID> <occurrence> <item>

'@ Some knowledge of the  format used in the .out file is required.
'@ please see details in the ..../data/dat/cmmesage.dat  for details
'@ Some know of the analysis sequences is required.
'@ please see details in the ..../data/dat/process.dat  for details
'@
'@ SYNTAX
'@ RaadScreenOutput
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ Assumes a Flow analysis has been run and the required study file is selected and open.
'@ Some knowledge of the MSCD format as defined in message.dat  is required
'@ Limited error checking is performed
'@
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
  Set Synergy = SynergyGetter.GetSASynergy
Else
  Set Synergy = CreateObject("amiws.Synergy")
End If

Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()

' Get the name of the .out file associated with the flow results.
' Note:  This assumes a Flow analysis sequence was run.
Dim lName
lName = StudyDoc.GetResultPrefix("Flow")
Dim lOutName
lOutName = lName & ".out"

' Create and Populate the ScreenOutput Class for the lOutName
Dim lMessages
Set lMessages = New ScreenOutput
lMessages.LoadOutputFile(lOutName)

Dim MM, lStr

' Find the Total Projected Area
' return the array of numerical values associated with the first instance of Message ID (MSCD) 39410
' MSCD 39410 1 0 0 0 0 0 5
'       Total projected area                               = %11.4G
'    m^2,1,1
' Note: Please see .../data/dat/shared/cmmesage.dat for format details
Set MM = lMessages.GetMessage(39410,1)
lStr = " Total Proejcted Area    = " & CStr(MM.GetFloat(0)) 
MsgBox CStr(lStr)

' Read Maximum Injection pressure and the time it occurred
' return the array of numerical values associated with the last instance of Message ID (MSCD) 39410
' MSCD 41400 1 0 0 0 0 0 5
'       Maximum injection pressure          (at %11.4G) = %11.4G
'    s,1,2
'    Pa,1,1
' Note: Please see .../data/dat/shared/cmmesage.dat for format details
Set MM = lMessages.GetMessage(41400,0)
lStr = "Maximum injection pressure occured at " & CStr(MM.GetFloat(1)) & " Pressure =     " & CStr(MM.GetFloat(0))
MsgBox CStr(lStr)

MsgBox "Script Complete"

' ---- Message class
Class Message
  Private mMSCD   ' MSCD Message ID
  Private mNumString    ' Number of Strings associated with the Message
  Private mNumFloat     ' Number of Floats  Associated with the Message
  Private mStrings()    ' The Strings Associated with the Message
  Private mFloats()  ' The Numerical Values Associated with the Message

  Public Sub SetMSCD(aMSCD)
    mMSCD = aMSCD
  End Sub

  Public Sub SetNumString(aNumString)
    mNumString = aNumString
  End Sub

  Public Sub SetNumFloat(aNumFloat)
    mNumFloat = aNumFloat
  End Sub

  Public Sub AddFloat(aFloat)
    mNumFloat = mNumFloat + 1
    ReDim Preserve mFloats(mNumFloat)
    mFloats(mNumFloat-1) = aFloat
  End Sub

  Public Sub AddString(aString)
    mNumString = mNumString + 1
    ReDim Preserve mStrings(mNumString)
    mStrings(mNumString-1) = aString
  End Sub

  Public Function GetMSCD()
    GetMSCD = mMSCD
  End Function
  Public Function GetString(aIndex)
    GetString = ""
    If aIndex >= 0 And aIndex < mNumString Then
       GetString = mStrings(aIndex)
    End if
  End Function

  Public Function GetFloat(aIndex)
    GetFloat = ""
    If aIndex >= 0 And aIndex < mNumFloat Then
       GetFloat = mFloats(aIndex)
    End if
  End Function

  Public Function GetNumString()
    GetNumString = mNumString
  End Function

  Public Function GetNumFloat()
    GetNumFloat = mNumFloat
  End Function

  Private Sub Class_Initialize
    mMSCD = -1
    mNumString = 0
    mNumFloat = 0
  End Sub
End Class

Class ScreenOutput

 Private mMessages()  ' Array of Messages associate with the screen output File
 Private mNumMessages  ' Number of messages in the screen output file

  Public Function LoadOutputFile(aFile)
    Const ForReading = 1
    Dim FS
    Set FS = CreateObject("Scripting.FileSystemObject")
    Dim File
    Set File = FS.OpenTextFile(aFile, ForReading)
        While Not File.AtEndOfStream
      Dim ID
      ID = -1
        ' Read the MSCD
        Dim Line,lenLine
    Line = File.ReadLine
    lenLine = len(Line)
    If Not File.AtEndOfStream or lenLine >= 1 Then
      ID = Line
      Dim curMessage
      Set curMessage = New Message
      curMessage.SetMSCD(ID)
      ' Read the number of strings
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numString
        numString = Line
        ' Read Strings
        Dim i
        For i = 1 To numString
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
            CurMessage.AddString(Line)
          End if
        Next
      End if
      ' Read the number of floats
      Line = File.ReadLine
      lenLine = len(Line)
      If Not File.AtEndOfStream or lenLine >= 1 Then
        Dim numFloat
        numFloat = Line
        ' Read Floats
        For i = 1 To numFloat
          Line = File.ReadLine
          lenLine = len(Line)
          If Not File.AtEndOfStream or lenLine >= 1 Then
           CurMessage.AddFloat(Line)
          End if
        Next
      End If
      ' Add current message to the list
      AddMessage(CurMessage)
    End If
  Wend
    File.Close
  End Function

  Public Sub AddMessage(aMessage)
  mNumMessages = mNumMessages + 1
    ReDim Preserve mMessages(mNumMessages)
    Set mMessages(mNumMessages-1) = aMessage
  End Sub

  Public Function GetNumMessages()
    GetNumMessages = mNumMessages
  End Function

  Public Function GetMessage(aMSCD,aOccur)
    Set GetMessage = Nothing
    Dim j
    Dim lFindInstance
    lFindInstance = aOccur
    If aOccur < 0 Then
      lFindInstance = 0
    End if
    Dim Count
    Count = 0
    For j = 0 To mNumMessages-1
      'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
      If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
         Count = Count + 1
         If Count >= lFindInstance Then
           Set GetMessage = mMessages(j)
           Exit Function
         End if
      End if
    Next
  End Function

  Private Sub Class_Initialize
  mNumMessages = 0
  End Sub
End Class

Was this information helpful?