anchor.diff: -﻿open System
  +﻿
  +open System
   open System.IO
   open System.Collections.Generic
   open System.Collections
  
positive.code:         use writer = new BinaryWriter(File.Open(fileName, FileMode.OpenOrCreate))
          values
          |> Seq.iter (writeValue writer)
          
      
      let readValue (reader:BinaryReader) cellIndex = 
          // set stream to correct location
          reader.BaseStream.Position <- cellIndex*4L
  
          
          let value = reader.ReadInt32()
          if value <> Int32.MinValue then
              Some(value) 
          else 
              None
          
      let readValues fileName indices = 
          use reader = new BinaryReader(File.Open(fileName, FileMode.Open))
          // Performance IDEA: sort the indices
          // Use list or array to force value creation (otherwise reader goes out of scope)
          let values = List.map (readValue reader) (List.ofSeq indices)
          values
  
      let test() = 
          let fileName = @"D:\temp\testSimpleReadWrite.sbg" // *.sbg simple binary grid
          let initial = [None;Some(Int32.MinValue+1);Some(Int32.MaxValue);None;Some(0);Some(1);Some(-1);None;Some(2);Some(213);None]
  
          writeValues fileName initial
          let expected = Seq.concat ([[initial.[4];initial.[3];initial.[4];initial.[4];initial.[2]];initial])
          let actual = readValues fileName (Seq.concat [[4L;3L;4L;4L;2L];[0L..(initial.LongCount()-1L)]])
          let result = Seq.zip actual expected |> Seq.forall (fun (a, b) -> a = b)
          printfn "Simple read write test returned %b" result
  
  module AsciiToBin =
  
  
negative.code:         let root = @"D:\a\data\marspec\MARSPEC_10m\ascii\"
          let paths = Directory.GetFiles(root, "*.asc")
          testRandomQuery "testAllMarspec10m" paths 100 1000 |> ignore
          MemoryMappedRead.clearCache()
          SimpleReadWrite.clearCache()
          // SimpleBinaryReadWrite
          // 39s 10000 * 10
          // 22s 1000 * 100
          // 17s 100 * 1000
          // 16s 100 * 1000 with BinaryReader caching
          // MemoryMappedRead
          // 86s 10000 * 10
          // 28s 1000 * 100
          // 10s 100*1000
          // 9s 100*1000 with MemoryMappedFile caching
          
  
      let testGebco() =
          ignore // TODO
  
  module Test =
      let simpleReadWriteTest() = 
          let fileName = @"D:\temp\testSimpleReadWrite.sbg" // *.sbg simple binary grid
          let initial = [None;Some(Int32.MinValue+1);Some(Int32.MaxValue);None;Some(0);Some(1);Some(-1);None;Some(2);Some(213);None]
  
          SimpleReadWrite.writeValues fileName initial
          let expected = Seq.concat ([[initial.[4];initial.[3];initial.[4];initial.[4];initial.[2]];initial])
          let actual = SimpleReadWrite.readValues fileName (Seq.concat [[4L;3L;4L;4L;2L];[0L..(initial.LongCount()-1L)]])
          let result = Seq.zip actual expected |> Seq.forall (fun (a, b) -> a = b)
          printfn "Simple read write test returned %b" result
  
      let memoryMappedReadTest() =
          let fileName = @"D:\temp\testSimpleReadWrite.sbg" // *.sbg simple binary grid
          let initial = [None;Some(Int32.MinValue+1);Some(Int32.MaxValue);None;Some(0);Some(1);Some(-1);None;Some(2);Some(213);None]
          let expected = Seq.concat ([[initial.[4];initial.[3];initial.[4];initial.[4];initial.[2]];initial])
          let actual = MemoryMappedRead.readValues fileName (Seq.concat [[4L;3L;4L;4L;2L];[0L..(initial.LongCount()-1L)]])
          let result = Seq.zip actual expected |> Seq.forall (fun (a, b) -> a = b)
          printfn "Memory mapped read test returned %b" result
  
      let runall() =
          simpleReadWriteTest()
          memoryMappedReadTest()
          AsciiToBin.testSmallMarspec()
          AsciiToBin.testAllMarspec10m()
  Test.runall()
  