/// <summary>Create a tiler.</summary> /// <param name="f">The random access device from which image data may be read. /// This may be null if the tile information is available from memory.</param> /// <param name="fileOffset">The file offset within the RandomAccess device at which /// the data begins.</param> /// <param name="dims">The actual dimensions of the image.</param> /// <param name="base_Renamed">base class (should be a primitive type) of the image.</param> public ImageTiler(RandomAccess f, long fileOffset, int[] dims, Type base_Renamed) { this.f = f; this.fileOffset = fileOffset; this.dims = dims; this.base_Renamed = base_Renamed; }
/// <summary> /// Method Write ArrayDataIO /// </summary> /// <param name="o"></param> public override void Write(ArrayDataIO o) { if (data == null) { Object generatedAux = DataArray; } if (data == null) { throw new FitsException("Null unknown data"); } try { o.Write(data); } catch (IOException e) { throw new FitsException("IO Error on unknown data write" + e); } byte[] padding = new byte[FitsUtil.Padding(TrueSize)]; try { o.Write(padding); } catch (IOException e) { throw new FitsException("Error writing padding: " + e); } }
/// <summary>Skip the Data object immediately after the given Header object on /// the given stream object.</summary> /// <param name="stream">the stream which contains the data.</param> /// <param name="hdr">template indicating length of Data section</param> /// <exception cref="IOException"> IOException if the Data object could not be skipped.</exception> public static void SkipData(ArrayDataIO stream, Header hdr) { //System.IO.BinaryReader temp_BinaryReader; Int64 temp_Int64; //temp_BinaryReader = stream; temp_Int64 = stream.Position; //temp_BinaryReader.BaseStream.Position; temp_Int64 = stream.Seek((int)hdr.DataSize) - temp_Int64; //temp_BinaryReader.BaseStream.Seek((int) hdr.DataSize, System.IO.SeekOrigin.Current) - temp_Int64; int generatedAux = (int)temp_Int64; }
/// <summary>Write the heap</summary> public virtual void Write(ArrayDataIO str) { try { str.Write(heap, 0, heapSize); } catch (IOException e) { throw new FitsException("Error writing heap:" + e); } }
/// <summary> /// Method to read the ArrayDataIO /// </summary> /// <param name="i"></param> public override void Read(ArrayDataIO i) { SetFileOffset(i); if (i is RandomAccess) { try { //BinaryReader temp_BinaryReader; System.Int64 temp_Int64; //temp_BinaryReader = i; temp_Int64 = i.Position; //temp_BinaryReader.BaseStream.Position; temp_Int64 = i.Seek((int)byteSize) - temp_Int64; //temp_BinaryReader.BaseStream.Seek((int) byteSize, SeekOrigin.Current) - temp_Int64; int generatedAux = (int)temp_Int64; } catch (IOException e) { throw new FitsException("Unable to skip over data:" + e); } } else { try { i.Read(data); } catch (IOException e) { throw new FitsException("Unable to read unknown data:" + e); } } int pad = FitsUtil.Padding(TrueSize); try { //BinaryReader temp_BinaryReader2; System.Int64 temp_Int65; //temp_BinaryReader2 = i; temp_Int65 = i.Position; //temp_BinaryReader2.BaseStream.Position; temp_Int65 = i.Seek(pad) - temp_Int65; //temp_BinaryReader2.BaseStream.Seek(pad, SeekOrigin.Current) - temp_Int65; // if (temp_Int65 != pad) if (i.Seek(pad) != pad) { throw new FitsException("Error skipping padding"); } } catch (IOException e) { throw new FitsException("Error reading unknown padding:" + e); } }
/// <summary>Read in an ASCII table. Reading is deferred if /// we are reading from a random access device</summary> public override void Read(ArrayDataIO str) { SetFileOffset(str); currInput = str; //if(str is RandomAccess) if (str.CanSeek) { try { //BinaryReader temp_BinaryReader; Int64 temp_Int64; //temp_BinaryReader = str; temp_Int64 = str.Position; //temp_BinaryReader.BaseStream.Position; temp_Int64 = str.Seek(nRows * rowLen) - temp_Int64; //temp_BinaryReader.BaseStream.Seek(nRows * rowLen, SeekOrigin.Current) - temp_Int64; int generatedAux = (int)temp_Int64; } catch (IOException e) { throw new FitsException("Error skipping data: " + e); } } else { try { GetBuffer(rowLen * nRows, 0); } catch (IOException e) { throw new FitsException("Error reading ASCII table:" + e); } } try { //BinaryReader temp_BinaryReader2; Int64 temp_Int65; //temp_BinaryReader2 = str; temp_Int65 = str.Position; //temp_BinaryReader2.BaseStream.Position; temp_Int65 = str.Seek(FitsUtil.Padding(nRows * rowLen)) - temp_Int65; //temp_BinaryReader2.BaseStream.Seek(FitsUtil.padding(nRows * rowLen), SeekOrigin.Current) - temp_Int65; int generatedAux2 = (int)temp_Int65; } catch (IOException e) { throw new FitsException("Error skipping padding:" + e); } }
/// <summary>Read the heap</summary> public virtual void Read(ArrayDataIO str) { if (str is RandomAccess) { fileOffset = FitsUtil.FindOffset(str); input = str; } if (heap != null) { try { str.Read(heap, 0, heapSize); } catch (IOException e) { throw new FitsException("Error reading heap:" + e); } } }
/// <summary>Read in the Data object for this HDU.</summary> /// <param name="stream">the stream from which the data is read.</param> /// <exception cref="FitsException"> FitsException if the Data object could not be created from this HDU's Header</exception> public virtual void ReadData(ArrayDataIO stream) { myData = null; try { myData = ManufactureData(); } finally { // if we cannot build a Data object, skip this section if (myData == null) { try { SkipData(stream, myHeader); } catch (Exception) { } } } myData.Read(stream); }