Here a version with some timing handling
uses "file"
uses "console"
Dim FileToLoad As String Value APP_SourcePath & "cgn21w001.asc.txt"
dim MyMatrix() as string
dim nLines as long
dim nCols as long
dim T0, T1 as quad
Dim sBuffer As String
Dim InfoBuffer As String
Dim DataBuffer As String
Dim lPos As Long
Dim nRec As Long
Dim MyTimer As cTimer
MyTimer = New cTimer("Timer used to store elapsed time between stages")
MyTimer.Start
'---Just one line do the job of loading file data, parsing text lines, dimensioning and filling the matrix.
'------
'---Load full file into a string buffer
PrintL "Input file: " & FileToLoad
Print "Loading file ... "
sBuffer = FILE_Load(FileToLoad)
PrintL MyTimer.Elapsed
Print "Getting info and data parts ..."
'---Now we have to remove first 6 lines
'---First find the 6th occurrence of $CRLF
lPos = InStr(sBuffer, $CRLF, 6)
'---Than create two buffers: one for the info part and one for data part
InfoBuffer = LEFT$(sBuffer, lPos)
DataBuffer = Mid$(sBuffer, lPos + 2)
PrintL MyTimer.Elapsed
PrintL "Info size in bytes: ", Len(InfoBuffer)
PrintL "Data size in bytes: ", Len(DataBuffer)
Print "Creating Matrix data ... "
'---Now we parse data buffer
Parse(DataBuffer, MyMatrix(), $CRLF , $SPC)
'--Now get the number of lines and max number of columns parsed
nLines = ubound(MyMatrix(1))
nCols = ubound(MyMatrix(2))
PrintL MyTimer.Elapsed
PrintL "Lines:", nLines, "Columns:", nCols
'---Write some info
Print "Searching missing data ... "
dim CountLine as long
dim CountCol as long
For CountLine = 1 To nLines
For CountCol = 1 To nCols
If MyMatrix(CountLine, CountCol) = "-9999" Then
Incr nRec
End If
Next
Next
PrintL MyTimer.Elapsed
PrintL "Missing data found:", nRec
PrintL Repeat$(79, "-")
PrintL "Total time:", MyTimer.Elapsed
MyTimer.Stop
PrintL "Program terminated. Press any key to close."
WaitKey
Almost most of the time is taken by process that build MyMatrix that is Parse function.
Maybe I can improve this process in future thinBasic versions.
Bookmarks