public TableReader(TableDesc desc, string matrixFile) { this.desc = desc; matrixReader = new BinaryReader(File.Open(matrixFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); }
public TableReader(string descFile, string matrixFile) : this(TableDesc.GetTableFromSpecFile(descFile), matrixFile) { }
public static TableDesc GetTableFromSpecFile(string filename) { var lines = File.ReadLines(filename, encoding); int currLine = 0; Spec spec = new Spec(); spec.nameDimMap = new Dictionary <string, Dim>(); spec.descriptions = lines.TakeWhile(x => x.StartsWith("/*")).ToArray(); var lineArr = lines.Where(x => x.Trim().Length != 0 && !x.StartsWith("/*")).ToArray(); // Read Spec attrs while (!lineArr[currLine].StartsWith("[")) { var l = lineArr[currLine]; var splited = l.Split('='); spec.attrs = new Attributes(); spec.attrs.Add(splited[0], string.Join("=", splited.Skip(1))); currLine++; } int numDim; bool res = int.TryParse(spec.attrs.GetAttr(SpecAttrNames.NumDims), out numDim); spec.dims = new List <Dim>(); while (currLine < lineArr.Length) { var dim = ReadDim(lineArr, ref currLine); spec.nameDimMap.Add(dim.name, dim); if (dim.name == "VOLUME" && dim.attrs.GetAttr(DimAttrNames.Type) == "VOL") { if (spec.volume != null && spec.volume.name != null && spec.volume.name.Length != 0) { throw new TableFileMalformatException("Duplicate volume dim"); } spec.volume = dim; } else if (dim.attrs.GetAttr(DimAttrNames.Type) == "MEASURE") { if (spec.measure != null && spec.measure.name != null && spec.measure.name.Length != 0) { throw new TableFileMalformatException("Duplicate mesure dim"); } spec.measure = dim; } else { spec.dims.Add(dim); } } if (spec.volume.name == null) { throw new TableFileMalformatException("No volume dim detected"); } if (spec.measure.name == null) { throw new TableFileMalformatException("No volume dim detected"); } //volume should be counted into dim spec.dims.Add(spec.volume); //calc intervals for (int i = spec.dims.Count - 2; i >= 0; i--) { spec.dims[i].interval = spec.dims[i + 1].interval * spec.dims[i + 1].items.Count; } if (res && numDim != spec.dims.Count) { throw new TableFileMalformatException("Dim not match numdims attr"); } spec.numDims = spec.dims.Count; // ReadDims var pvtable = new TableDesc(); pvtable.spec = spec; return(pvtable); }