/// <summary>Create a null binary table data segment.</summary> /// <exception cref="TableException"> TableException</exception> public BinaryTable() { try { table = new ColumnTable(new Object[0], new int[0]); } catch (TableException e) { Console.Error.WriteLine("Impossible exception in BinaryTable() constructor" + e); } heap = new FitsHeap(0); ExtendArrays(0); nRow = 0; nCol = 0; rowLen = 0; }
/// <summary>Read the data -- or defer reading on random access</summary> public override void Read(ArrayDataIO i) { SetFileOffset(i); currInput = i; if (i is RandomAccess) { try { //BinaryReader temp_BinaryReader; Int64 temp_Int64; //temp_BinaryReader = i; temp_Int64 = i.Position;//temp_BinaryReader.BaseStream.Position; temp_Int64 = i.Seek(TrueSize, SeekOrigin.Current) - temp_Int64; //temp_BinaryReader.BaseStream.Seek(TrueSize, IO.SeekOrigin.Current) - temp_Int64; int generatedAux = (int)temp_Int64; //IO.BinaryReader temp_BinaryReader2; Int64 temp_Int65; //temp_BinaryReader2 = i; temp_Int65 = i.Position;//temp_BinaryReader2.BaseStream.Position; temp_Int65 = i.Seek(FitsUtil.Padding(TrueSize), SeekOrigin.Current) - temp_Int65;//temp_BinaryReader2.BaseStream.Seek(FitsUtil.padding(TrueSize), IO.SeekOrigin.Current) - temp_Int65; int generatedAux2 = (int)temp_Int65; } catch(IOException e) { throw new FitsException("Unable to skip binary table HDU:" + e); } } else { if (table == null) { table = CreateTable(); } ReadTrueData(i); } }
/// <summary>Create a binary table from an existing ColumnTable.</summary> public BinaryTable(ColumnTable tab) { nCol = tab.NCols; ExtendArrays(nCol); bases = tab.Bases; sizes = tab.Sizes; modelRow = new Object[nCol]; dimens = new int[nCol][]; // Set all flags to 0. flags = new int[nCol]; // Set the column dimension. Note that // we cannot distinguish an array of length 1 from a // scalar here: we assume a scalar. for (int col=0; col<nCol; col += 1) { if (sizes[col] != 1) { dimens[col] = new int[]{sizes[col]}; } else { dimens[col] = new int[0]; } } for (int col=0; col < nCol; col += 1) { modelRow[col] = ArrayFuncs.NewInstance(bases[col], sizes[col]); } columns = null; table = tab; heap = new FitsHeap(0); rowLen = 0; for (int col = 0; col < nCol; col += 1) { rowLen += sizes[col] * ArrayFuncs.GetBaseLength(tab.GetColumn(col)); } heapOffset = 0 ; nRow = tab.NRows; }
/// <summary>Add a column where the data is already flattened.</summary> /// <param name="o">The new column data. This should be a one-dimensional primitive array.</param> /// <param name="dims">The dimensions of one row of the column.</param> /// <exception cref="TableException"> TableException Thrown when the new data /// is not of the same type as the data it replaces.</exception> public int AddFlattenedColumn(Object o, int[] dims) { ExtendArrays(nCol + 1); bases[nCol] = ArrayFuncs.GetBaseClass(o); if (bases[nCol] == typeof(bool)) { flags[nCol] |= COL_BOOLEAN; } else if (bases[nCol] == typeof(String)) { flags[nCol] |= COL_STRING; } // Convert to column first in case // this is a String or variable length array. o = ArrayToColumn(nCol, o); int size = 1; for (int dim = 0; dim < dims.Length; dim += 1) { size *= dims[dim]; } sizes[nCol] = size; // change suggested in .99.2 version if (size != 0) { int xRow = ((Array)o).Length / size; if (xRow > 0 && nCol != 0 && xRow != nRow) { throw new FitsException("Added column does not have correct row count"); } } // .99.1 changes: new method for condition check if (!IsVarCol(nCol)) { modelRow[nCol] = ArrayFuncs.NewInstance(ArrayFuncs.GetBaseClass(o), dims); rowLen += size * ArrayFuncs.GetBaseLength(o); } else { if (IsLongVary(nCol)) { modelRow[nCol] = new long[2]; rowLen += 16; } else { modelRow[nCol] = new int[2]; rowLen += 8; } } // Only add to table if table already exists or if we // are filling up the last element in columns. // This way if we allocate a bunch of columns at the beginning // we only create the column table after we have all the columns // ready. columns[nCol] = o; try { if (table != null) { table.AddColumn((Array)o, sizes[nCol]); } else if (nCol == columns.Length - 1) { table = new ColumnTable(columns, sizes); } } catch (TableException e) { throw new FitsException("Error in ColumnTable:" + e); } // change suggested in .99.2 version // nCol += 1; return nCol; }
/// <summary>Create a column table given the number of /// rows and a model row. This is used when /// we defer instantiation of the ColumnTable until /// the user requests data from the table. /// </summary> /// <exception cref=""> TableException Thrown when the new data /// is not of the same type as the data it replaces.</exception> private ColumnTable CreateTable() { int nfields = modelRow.Length; Object[] arrCol = new Object[nfields]; for (int i = 0; i < nfields; i += 1) { arrCol[i] = ArrayFuncs.NewInstance(ArrayFuncs.GetBaseClass(modelRow[i]), sizes[i] * nRow); } ColumnTable table; try { table = new ColumnTable(arrCol, sizes); } catch (TableException e) { throw new FitsException("Unable to create table:" + e); } return table; }