Navigation: Scripting Reference Manual > Functions & Subroutines > DataCollectorSurfReadCollectedDataFile

 

DataCollectorSurfReadCollectedDataFile

 

Contact Us: fredsupport@photonengr.com

 

Description

This function reads CSV data written from a data collector surface object and loads the data into a data collector surface node.  The user bears the responsibility for loading appropriate data into the data collector surface objects.  If the CSV file data being read does not correspond to the data collector surface that wrote the data file, the data will simply be remapped into the same facet ID numbers as in the original data collector surface object.

 

Syntax

success = DataCollectorSurfReadCollectedDataFile( surf, fname )

 

Parameters

success (Boolean)

Return value indicating whether the file was successfully read into the data collector surface node.  A return value of False may indicate that the CSV file is not output from a data collector surface or that the specified file does not contain any datum to be loaded (i.e the CSV file contains only a header with no datum values).  The latter is an indication that the data collector surface object that generated the CSV file did not collect any data to be written.

 

surf As Long

Node number of the data collector surface into which the CSV data is being loaded.

 

fname As String

Full file path name to the CSV file whose data is being read.

 

Example

The example below demonstrates how to search a directory for CSV files, parse the file names to identify the associated data collector surface objects, and then load the CSV data into the associated objects.  The assumptions in this example are that the only CSV files in the search directory correspond to data collector surface files and that the name of the CSV files follows the convention of using the data collector surface full name string with *.csv appended as the file extension (ex. Geometry.Pipe.Front.csv ).

 

Sub Main

          

    'File directory to be searched

    Dim fDir As String

    fDir = GetDocDir()

 

    'Use custom function call to get CSV file names

    Dim fileList() As String, nFiles As Long

    nFiles = GetFiles( fDir, "csv", fileList() )

    If nFiles < 1 Then

        Print "No CSV files found for loading."

        End

    End If

 

    'Loop over files, process name string and load into object

    'Assumption is that the CSV files are named after their associated collector object

    Dim dcSurf As Long, success As Boolean

    Dim fileParse() As String, fname As String, fshort As String

    For Each fname In fileList

       

        'Re-form object full name from file name

        fileParse = Split( fname, "\" )

        fshort    = fileParse(UBound(fileParse))

        fshort    = Left(fshort,Len(fshort)-4)

 

        'Find the associated object

        dcSurf = FindFullName( fshort )

        If dcSurf > -1 Then

            success = DataCollectorSurfReadCollectedDataFile( dcSurf, fname )

            If success Then

                Print "Loaded file " & fname & " into model."

            Else

                Print "Unable to load file " & fname & " into model.  Possibly, no data is conatined in the file."

            End If

        Else

            Print "No object associated with file " & fshort & ".csv"

        End If

 

    Next

 

 

End Sub

 

Function GetFiles( ByVal in_dir As String, _

                   ByVal in_ext As String, _

                   ByRef out_FileList() As String ) As Long

 

    'This helper function scans a directory for files

    'with a specific extension returns their path names

    'INPUTS:

    '   in_dir   = string defining the directory to be searched

    '   in_ext   = string defining the file extension

    'OUTPUTS:

    '   returns the number of files that were found

    '   updates out_fileList to contain the full file paths

 

    'Change to the search directory

    ChDir( in_dir )

 

    Dim nF As Long

    Dim cFile As String

    nF = 0

    cFile = Dir$("*." & in_ext)

    While cFile <> ""

        If nF = 0 Then

            ReDim out_FileList(0)

            out_FileList(0) = in_dir & "\" & cFile

        Else

            ReDim Preserve out_FileList( nF )

            out_FileList(UBound(out_FileList)) = in_dir & "\" & cFile

        End If

        nF   += 1

        cFile = Dir$()

    Wend

 

    Return nF

 

End Function

 

See Also

Data Collector Surface Scripting

DataCollectorSurfGetDataStats

DataCollectorSurfGetDatum

DataCollectorSurfGetDatumCount

DataCollectorSurfIsCollectData

DataCollectorSurfIsDataAvailable

DataCollectorSurfSetCollectData

DataCollectorSurfSetDatum

DataCollectorSurfWriteCollectedDataFile

 

 

 

 

 

 

Copyright © Photon Engineering, LLC