LI7700 Data Parser
Revision as of 11:08, 21 October 2011 by 137.229.92.163 (talk)
Option Explicit
Const ForWriting As Integer = 2
Public Sub main()
' Declare a few variables
Dim input_directory As String
Dim output_directory As String
Dim fso, Folder, Files, file, filearray, filename
Dim infile, outfile
Dim templine, temparray
Dim outfilestring
''''''''''''''''''''''''''''''''''''
''' '''
''' set the input output stuff. '''
''' '''
''''''''''''''''''''''''''''''''''''
input_directory = "c:\uaf\active_projects\osp\li7700-ch4\raw\"
output_directory = "c:\uaf\active_projects\osp\li7700-ch4\clipped\"
'''''''''''''''''''''''''''''''''''''''''''''''
''' '''
''' List all of the files in the directory '''
''' '''
'''''''''''''''''''''''''''''''''''''''''''''''
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(input_directory) And fso.FolderExists(output_directory) Then ' Path is a directory
Set Folder = fso.GetFolder(input_directory)
Set Files = Folder.Files
'''''''''''''''''''''''''''''''''''
''' '''
''' Open and analyze each file '''
''' '''
'''''''''''''''''''''''''''''''''''
For Each file In Files
' Get the name of the input file
filearray = Split(file, "\")
filename = filearray(UBound(filearray))
'''''''''''''''''''''''''''''''''''''''''''''
''' '''
''' create a name for the output file... '''
''' if you'd prefer a different name, '''
''' change this line. '''
''' '''
'''''''''''''''''''''''''''''''''''''''''''''
outfilestring = output_directory & "clip_" & filename
' open the input and output files for reading writing
Set infile = fso.opentextfile(file)
Set outfile = fso.opentextfile(outfilestring, ForWriting, True)
' loop through the lines of data in the input file
Do While infile.atendofstream <> True
templine = infile.readline
temparray = Split(templine, Chr(9)) ' split each line based on tabs
' just a way to skip over the lines at the top
If UBound(temparray) > 9 Then
' if not numeric it's a header to skip.
If IsNumeric(temparray(8)) Then
' at this point we should have a valid data point to check.
If CDbl(temparray(8)) >= 30 Then
'' Good data, save it to the output file.
outfile.writeline templine
End If
End If
End If
Loop
infile.Close
outfile.Close
Next
End If
End Sub