I have some data that I extract some information from/ Generally it consists of a header containing some mixed format data (text and integer) followed by several lines of mixed format (Int, Double) information.
EX: Header: " VERSION C3 EARTH VARIABLE 1 (XYZ) *T**0 1007 TERMS" from which I parse out ["C3", "EARTH", 1, 0, 1007] this is followed by 1007 lines containing numbers similar to: [3310, 232, 0, 0, 11, -21, 2, 0, 0, 0, -1, 0, 0, 1, -0.00000001572, -0.00000001245, 0.00000002005, 4.16423892775, 6303.67498687370]
The input is all textual and to speed things up needs to be saved as binary data for input. That's the easy part -- read it in and parse it into arrays of type Any. Plists are too slow. Here is little code fragment of what I am trying to do:
var targetFile: Data = Data()
// read source file data (there is a try-catch here ignored in the code fragment)
let inputData = String ( contentsOf: sourceFileUrl )
sourceFileByLines = inputData.components( separatedBy: "\n" )
// multiple headers followed by multiple lines of data, repeated
// header loop starts here
getKeyInfomationFromHeaderLine ( line: sourceFileByLines! [ nextline ], theVersion: &version, body: &aBody , currentVariable: &variable, aT0Power: &t0Power, aTermCount: &termCount )
var headerValues: [Any] = [String(version), String(aBody), variable, t0Power, termCount]
targetfile += Data ( bytes: &headerValues, count: headerValues.count * MemoryLayout<[Any]>.stride )
// Start loop to process term data line.
// Build binary line
for i in 0...13 {
nextLineBinary [ i ] = Int ( nextLineSource [ i ] )!
}
for i in 14...18 {
nextLineBinary [ i ] = Double ( nextLineSource [ i ] )!
}
targetfile += Data ( bytes: &nextLineBinary, count: nextLineBinary.count * MemoryLayout<[Any]>.stride )
// increment & decrement loop control-variables
// End loop for data lines
// End loop for headers
All the variables are defined and the loops are proper and run to completion. But when I read the data into an [[Any]] array the data is confused (extra data is found, especially in the header values).
So the question is how should I be encoding, writing, reading, decoding and storing that data?
Any suggestions appreciated.
TIA,
ClarkW