public void CreateByColumn() { Fits f = MakeAsciiTable(); WriteFile(f, "at1.fits"); System.Console.Out.WriteLine("\n\n**** Create a table column by Column ****"); f = new Fits("at1.fits", FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); Object[] inputs = GetSampleCols(); Object[] outputs = (Object[])hdu.Kernel; for (int i = 0; i < 50; i += 1) { ((String[])outputs[4])[i] = ((String[])outputs[4])[i].Trim(); } for (int j = 0; j < 5; j += 1) { Assertion.AssertEquals("ByCol:" + j, true, ArrayFuncs.ArrayEquals(inputs[j], outputs[j], Math.Pow(10, -6), Math.Pow(10, -14))); } }
/// <summary>Check if this data is usable as an ASCII table.</summary> public static bool IsData(Object o) { if (ArrayFuncs.CountDimensions(o) != 2) { return(false); } Type t = ArrayFuncs.GetBaseClass(o); return(t != null && (t.Equals(typeof(String)) || t.Equals(typeof(int)) || t.Equals(typeof(long)) || t.Equals(typeof(float)) || t.Equals(typeof(double)))); /* * if(o is Object[]) * { * System.Object[] oo = (System.Object[]) o; * for (int i = 0; i < oo.Length; i += 1) * { * if (oo[i] is System.String[] || oo[i] is int[] || oo[i] is long[] || oo[i] is float[] || oo[i] is double[]) * { * continue; * } * return false; * } * return true; * } * else * { * return false; * } */ }
public void ReadByElement() { Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("at2.fits"), FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); for (int i = 0; i < data.NRows; i += 1) { Object[] row = (Object[])data.GetRow(i); for (int j = 0; j < data.NCols; j += 1) { Object val = data.GetElement(i, j); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(val, row[j])); } } } finally { if (f != null) { f.Close(); } } }
public void TestVar() { Object[] data = new Object[] { floats, vf, vs, vd, shorts, vbool }; Fits f = new Fits(); f.AddHDU(Fits.MakeHDU(data)); //BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt2.fits", FileMode.Open, FileAccess.ReadWrite)); BufferedFile bdos = new BufferedFile("bt2.fits", FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bdos); bdos.Close(); f = new Fits("bt2.fits", FileAccess.Read); f.Read(); BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1); Header hdr = bhdu.Header; Assertion.AssertEquals("var1", true, hdr.GetIntValue("PCOUNT") > 0); Assertion.AssertEquals("var2", 6, hdr.GetIntValue("TFIELDS")); for (int i = 0; i < data.Length; i += 1) { Assertion.AssertEquals("vardata(" + i + ")", true, ArrayFuncs.ArrayEquals(data[i], bhdu.GetColumn(i))); } }
public void ReadByColumn() { Fits f = new Fits("at1.fits", FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); Object[] cols = GetSampleCols(); Assertion.AssertEquals("Number of rows", data.NRows, 50); Assertion.AssertEquals("Number of columns", data.NCols, 5); for (int j = 0; j < data.NCols; j += 1) { Object col = data.GetColumn(j); if (j == 4) { String[] st = (String[])col; for (int i = 0; i < st.Length; i += 1) { st[i] = st[i].Trim(); } } Assertion.AssertEquals("Ascii Columns:" + j, true, ArrayFuncs.ArrayEquals(cols[j], col, Math.Pow(10, -6), Math.Pow(10, -14))); } }
/// <summary>Read a single row from the table. This returns a set of arrays of dimension 1.</summary> private Array ParseSingleRow(int row) { int offset = row * rowLen; Array res = new Array[nFields]; try { GetBuffer(rowLen, fileOffset + row * rowLen); } catch (IOException) { throw new FitsException("Unable to read row"); } for (int i = 0; i < nFields; i += 1) { res.SetValue(ArrayFuncs.NewInstance(types[i], 1), i); if (!ExtractElement(offsets[i], lengths[i], res, i, 0, nulls[i])) { res.SetValue(null, i); } } // Invalidate buffer for future use. buffer = null; return(res); }
/// <summary>Read a single element from the table. This returns an array of dimension 1.</summary> private Array ParseSingleElement(int row, int col) { Array res = new Array[1]; try { GetBuffer(lengths[col], fileOffset + row * rowLen + offsets[col]); } catch (IOException) { buffer = null; throw new FitsException("Unable to read element"); } res.SetValue(ArrayFuncs.NewInstance(types[col], 1), 0); if (ExtractElement(0, lengths[col], res, 0, 0, nulls[col])) { buffer = null; return((Array)res.GetValue(0)); } else { buffer = null; return(null); } }
/// <summary>Create FITS data object corresponding to a given header.</summary> public static Data ManufactureData(Header hdr) { int gcount = hdr.GetIntValue("GCOUNT", -1); int pcount = hdr.GetIntValue("PCOUNT", -1); if (!hdr.GetBooleanValue("GROUPS") || hdr.GetIntValue("NAXIS1", -1) != 0 || gcount < 0 || pcount < 0 || hdr.GetIntValue("NAXIS") < 2) { throw new FitsException("Invalid Random Groups Parameters"); } // Allocate the object. Object[][] dataArray; if (gcount > 0) { dataArray = new Object[gcount][]; for (int i = 0; i < gcount; i++) { dataArray[i] = new Object[2]; } } else { dataArray = new Object[0][]; } Object[] sampleRow = GenerateSampleRow(hdr); for (int i = 0; i < gcount; i += 1) { ((Object[][])dataArray)[i][0] = ((Object[])ArrayFuncs.DeepClone(sampleRow))[0]; ((Object[][])dataArray)[i][1] = ((Object[])ArrayFuncs.DeepClone(sampleRow))[1]; } return(new RandomGroupsData(dataArray)); }
internal static Object[] GenerateSampleRow(Header h) { int ndim = h.GetIntValue("NAXIS", 0) - 1; int[] dims = new int[ndim]; int bitpix = h.GetIntValue("BITPIX", 0); Type baseClass; switch (bitpix) { case 8: baseClass = typeof(byte); break; case 16: baseClass = typeof(short); break; case 32: baseClass = typeof(int); break; case 64: baseClass = typeof(long); break; case -32: baseClass = typeof(float); break; case -64: baseClass = typeof(double); break; default: throw new FitsException("Invalid BITPIX:" + bitpix); } // Note that we have to invert the order of the axes // for the FITS file to get the order in the array we // are generating. Also recall that NAXIS1=0, so that // we have an 'extra' dimension. for (int i = 0; i < ndim; i += 1) { long cdim = h.GetIntValue("NAXIS" + (i + 2), 0); if (cdim < 0) { throw new FitsException("Invalid array dimension:" + cdim); } dims[ndim - i - 1] = (int)cdim; } Object[] sample = new Object[2]; sample[0] = ArrayFuncs.NewInstance(baseClass, h.GetIntValue("PCOUNT")); sample[1] = ArrayFuncs.NewInstance(baseClass, dims); return(sample); }
public void CreateByColumn() { Fits f = null; try { f = MakeAsciiTable(); WriteFile(f, TestFileSetup.GetTargetFilename("at1.fits")); System.Console.Out.WriteLine("\n\n**** Create a table column by Column ****"); f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); Object[] inputs = GetSampleCols(); Object[] outputs = (Object[])hdu.Kernel; for (int i = 0; i < 50; i += 1) { ((String[])outputs[4])[i] = ((String[])outputs[4])[i].Trim(); } for (int j = 0; j < 5; j += 1) { Assert.AreEqual(true, ArrayFuncs.ArrayEquals(inputs[j], outputs[j], Math.Pow(10, -6), Math.Pow(10, -14))); } } finally { f.Close(); } }
// .99.1 changes /// <summary>Delete rows from a FITS table.</summary> public virtual void DeleteRows(int start, int len) { if (nRows == 0 || start < 0 || start >= nRows || len <= 0) { return; } if (start + len > nRows) { len = nRows - start; } // .99.2 changes // Data d = (Data)DataArray; Object dummy_o = DataArray; try { for (int i = 0; i < nFields; i += 1) { Object o = ArrayFuncs.NewInstance(types[i], nRows - len); Array.Copy((Array)data[i], 0, (Array)o, 0, start); Array.Copy((Array)data[i], start + len, (Array)o, start, nRows - len - start); data[i] = o; } nRows -= len; } catch (Exception e) { throw new FitsException("Error deleting row:" + e); } }
// Read a FITS file public void ReadFile() { Initialize(); Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("image1.fits")); BasicHDU[] hdus = f.Read(); Assert.AreEqual(f.NumberOfHDUs, 8); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bimg, hdus[0].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(simg, hdus[1].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(iimg, hdus[2].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(limg, hdus[3].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(fimg, hdus[4].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(dimg, hdus[5].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(img3, hdus[6].Data.Kernel)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(img1, hdus[7].Data.Kernel)); } finally { if (f != null) { f.Close(); } } }
/// <summary>Add some data to the heap.</summary> internal virtual int PutData(Object data) { int size = ArrayFuncs.ComputeSize(data); ExpandHeap(size); MemoryStream bo = new MemoryStream(size); try { BufferedDataStream o = new BufferedDataStream(bo); o.WriteArray(data); o.Flush(); o.Close(); } catch (IOException) { throw new FitsException("Unable to write variable column length data"); } Array.Copy(bo.ToArray(), 0, heap, heapSize, size); int oldOffset = heapSize; heapSize += size; // change suggested in .99.1 version: heapOffset = heapSize; return(oldOffset); }
/// <summary>Check if this data is usable as an ASCII table.</summary> public static bool IsData(Object o) { if (ArrayFuncs.CountDimensions(o) != 2) { return(false); } /* Type t = ArrayFuncs.GetBaseClass(o); * return t != null && (t.Equals(typeof(String)) || t.Equals(typeof(int)) || t.Equals(typeof(long)) || * t.Equals(typeof(float)) || t.Equals(typeof(double))); */ if (o is Object[]) { System.Object[] oo = (System.Object[])o; for (int i = 0; i < oo.Length; i += 1) { if (oo[i] is System.String[] || oo[i] is int[] || oo[i] is long[] || oo[i] is float[] || oo[i] is double[]) { continue; } return(false); } return(true); } else { return(false); } }
/// <summary>Check if this data is compatible with Random Groups structure. /// Must be an Object[ngr][2] structure with both elements of each /// group having the same base type and the first element being /// a simple primitive array. We do not check anything but /// the first row.</summary> public static bool IsData(Object oo) { if (oo is Object[][]) //ArrayFuncs.CountDimensions(oo) == 2) { //Object[][] o = (Object[][]) oo; //if(o.Length > 0) if (ArrayFuncs.IsArrayOfArrays(oo)) { try { Array a = (Array)oo; Type t1 = ArrayFuncs.GetBaseClass(((Array)a.GetValue(0)).GetValue(0)); Type t2 = ArrayFuncs.GetBaseClass(((Array)a.GetValue(0)).GetValue(1)); return(((Array)a.GetValue(0)).Length == 2 && t1.Equals(t2) && !t1.Equals(typeof(char)) && !t1.Equals(typeof(bool))); } catch (Exception) { return(false); } } else { try { Array a = (Array)oo; Type t1 = a.GetValue(new int[] { 0, 0 }).GetType(); Type t2 = a.GetValue(new int[] { 0, 1 }).GetType(); return(a.GetLength(1) == 2 && t1.Equals(t2) && !t1.Equals(typeof(char)) && !t1.Equals(typeof(bool))); } catch (Exception) { return(false); } } /* * { * if(o[0].Length == 2) * { * if (ArrayFuncs.getBaseClass(o[0][0]) == ArrayFuncs.getBaseClass(o[0][1])) * { * System.String cn = o[0][0].GetType().FullName; * if (cn.Length == 2 && cn[1] != 'Z' || cn[1] != 'C') * { * return true; * } * } * } * } */ } return(false); }
/// <summary>Check if this object can be described as a FITS image.</summary> /// <param name="o">The Object being tested.</param> public static bool IsData(Object o) { // Removed multidimension Array check logic: "(typeof(Array).Equals(o.GetType()) || o.GetType().FullName.IndexOf("[")!=-1)" // return (o != null) && o.GetType().IsArray && (!ArrayFuncs.GetBaseClass(o).Equals(typeof(bool))); return((o != null) && o.GetType().IsArray&& (ArrayFuncs.GetBaseClass(o).IsPrimitive&& !(ArrayFuncs.GetBaseClass(o).Equals(typeof(bool))))); }
public void CreateByRow() { Fits f = null; try { f = new Fits(); AsciiTable data = new AsciiTable(); Object[] row = new Object[4]; System.Console.Out.WriteLine("\n\n**** Create a table column by Row ****"); for (int i = 0; i < 50; i += 1) { data.AddRow(GetRow(i)); } f.AddHDU(Fits.MakeHDU(data)); WriteFile(f, TestFileSetup.GetTargetFilename("at2.fits")); f.Close(); // Read it back. f = new Fits(TestFileSetup.GetTargetFilename("at2.fits"), FileAccess.Read); Object[] output = (Object[])f.GetHDU(1).Kernel; Object[] input = GetRowBlock(50); for (int i = 0; i < 50; i += 1) { String[] str = (String[])output[2]; String[] istr = (String[])input[2]; int len1 = str[1].Length; str[i] = str[i].Trim(); // The first row would have set the length for all the // remaining rows... if (istr[i].Length > len1) { istr[i] = istr[i].Substring(0, len1); } } for (int j = 0; j < 3; j += 1) { Assert.AreEqual(true, ArrayFuncs.ArrayEquals(input[j], output[j], Math.Pow(10, -6), Math.Pow(10, -14))); } } finally { if (f != null) { f.Close(); } } }
public void TestSimpleIO() { FitsFactory.UseAsciiTables = false; Fits f = new Fits(); Object[] data = new Object[] { bytes, bits, bools, shorts, ints, floats, doubles, longs, strings }; f.AddHDU(Fits.MakeHDU(data)); BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1); bhdu.SetColumnName(0, "bytes", null); bhdu.SetColumnName(1, "bits", "bits later on"); bhdu.SetColumnName(6, "doubles", null); bhdu.SetColumnName(5, "floats", "4 x 4 array"); BufferedFile bf = new BufferedFile("bt1.fits", FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bf); bf.Flush(); bf.Close(); f = new Fits("bt1.fits"); f.Read(); Assertion.AssertEquals("NHDU", 2, f.NumberOfHDUs); BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1); Header hdr = thdu.Header; Assertion.AssertEquals("HDR1", 9, hdr.GetIntValue("TFIELDS")); Assertion.AssertEquals("HDR2", 2, hdr.GetIntValue("NAXIS")); Assertion.AssertEquals("HDR3", 8, hdr.GetIntValue("BITPIX")); Assertion.AssertEquals("HDR4", "BINTABLE", hdr.GetStringValue("XTENSION")); Assertion.AssertEquals("HDR5", "bytes", hdr.GetStringValue("TTYPE1")); Assertion.AssertEquals("HDR6", "doubles", hdr.GetStringValue("TTYPE7")); for (int i = 0; i < data.Length; i += 1) { Object col = thdu.GetColumn(i); if (i == 8) { String[] st = (String[])col; for (int j = 0; j < st.Length; j += 1) { st[j] = st[j].Trim(); } } Assertion.AssertEquals("Data" + i, true, ArrayFuncs.ArrayEquals(data[i], col)); } f.Close(); }
/// <summary> /// method to write data /// </summary> /// <param name="o"></param> public override void Write(ArrayDataIO o) { // Don't need to write null data (noted by Jens Knudstrup) if (byteSize == 0) { return; } // changes suggested in .97 version: if (dataArray == null) { if (tiler != null) { // Need to read in the whole image first. try { dataArray = tiler.CompleteImage; } catch (IOException) { throw new FitsException("Error attempting to fill image"); } } else if (dataArray == null && dataDescription != null) { // Need to create an array to match a specified header. dataArray = ArrayFuncs.NewInstance(dataDescription.type, dataDescription.dims); } else { // This image isn't ready to be written! throw new FitsException("Null image data"); } } try { o.WriteArray(dataArray); } catch (IOException e) { throw new FitsException("IO Error on image write: " + e); } byte[] padding = new byte[FitsUtil.Padding(TrueSize)]; try { o.Write(padding); o.Flush(); } catch (IOException e) { throw new FitsException("Error writing padding: " + e); } }
/// <summary> /// Method to read data /// </summary> /// <param name="i"></param> public override void Read(ArrayDataIO i) { // Don't need to read null data (noted by Jens Knudstrup) if (byteSize == 0) { return; } SetFileOffset(i); //if(i is RandomAccess) if (i.CanSeek) { //tiler = new ImageDataTiler(this, (RandomAccess) i, ((RandomAccess) i).FilePointer, dataDescription); tiler = new ImageDataTiler(this, (RandomAccess)i, ((Stream)i).Position, dataDescription); try { double pos = i.Position; //pos = i.Seek((int)byteSize) - pos; i.Seek(byteSize); } catch (IOException e) { throw new FitsException("Unable to skip over data:" + e); } } else { dataArray = ArrayFuncs.NewInstance(dataDescription.type, dataDescription.dims); try { i.ReadArray(dataArray); } catch (IOException e) { throw new FitsException("Unable to read image data:" + e); } tiler = new ImageDataTiler(this, null, 0, dataDescription); } int pad = FitsUtil.Padding(TrueSize); try { long pos = i.Seek(pad); if (pos != pad) { throw new FitsException("Error skipping padding"); } } catch (IOException e) { throw new FitsException("Error reading image padding:" + e); } }
/// <summary>Extract a single element from a table. This returns /// an array of length 1.</summary> private Array SingleElement(int row, int col) { Array res = null; if (isNull_Renamed_Field == null || !isNull_Renamed_Field[row * nFields + col]) { res = ArrayFuncs.NewInstance(types[col], 1); Array.Copy((Array)data[col], row, res, 0, 1); } return(res); }
protected static int[] ComputeByteWidths(Array[] a) { int[] result = new int[a.Length]; for (int i = 0; i < a.Length; ++i) { result[i] = ArrayFuncs.ComputeSize(a[i]); } return(result); }
public static Data Encapsulate(Object o) { if (ArrayFuncs.CountDimensions(o) == 2) // is Object[][]) { //return new RandomGroupsData((System.Object[][]) o); return(new RandomGroupsData((Array)o)); } else { throw new FitsException("Attempt to encapsulate invalid data in Random Group"); } }
// Initialize Objects public void Initialize() { bimg = new byte[40][]; for (int i = 0; i < bimg.Length; i++) { bimg[i] = new byte[40]; } for (int i = 10; i < 30; i += 1) { for (int j = 10; j < 30; j += 1) { bimg[i][j] = (byte)(i + j); } } simg = (Array[])ArrayFuncs.ConvertArray(bimg, typeof(short)); // Array.ConvertAll<byte, short>(bimg, Convert.ToInt16); iimg = (Array[])ArrayFuncs.ConvertArray(bimg, typeof(int)); // Array.ConvertAll<byte, int>(bimg, Convert.ToInt32); limg = (Array[])ArrayFuncs.ConvertArray(bimg, typeof(long)); // Array.ConvertAll<byte, long>(bimg, Convert.ToInt64); ; fimg = (Array[])ArrayFuncs.ConvertArray(bimg, typeof(float)); // Array.ConvertAll<byte, float>(bimg, Convert.ToSingle); ; dimg = (Array[])ArrayFuncs.ConvertArray(bimg, typeof(double)); // Array.ConvertAll<byte, double>(bimg, Convert.ToDouble); ; img3 = new int[10][][]; for (int i = 0; i < img3.Length; i++) { img3[i] = new int[20][]; } for (int i = 0; i < img3.Length; i++) { for (int j = 0; j < img3[i].Length; j++) { img3[i][j] = new int[30]; } } for (int i = 0; i < 10; i += 1) { for (int j = 0; j < 20; j += 1) { for (int k = 0; k < 30; k += 1) { img3[i][j][k] = i + j + k; } } } img1 = (double[])ArrayFuncs.Flatten(dimg); }
public void saveImageToFitsForSolveOnly(string path, imageInfo image, Array imgArray) { var imageData = (Array)ArrayFuncs.Flatten(imgArray); const double bZero = 0; const double bScale = 1.0; if (image.MaxADU <= 65535) { //bZero = 32768; //imageData = (ushort[])ArrayFuncs.ConvertArray(imageData, typeof(ushort)); } int[] dims = ArrayFuncs.GetDimensions(imgArray); // put the image data in a basic HDU of the fits BasicHDU imageHdu = FitsFactory.HDUFactory(ArrayFuncs.Curl(imageData, dims)); // Add the other fits fields to the HDU imageHdu.AddValue("BZERO", bZero, ""); imageHdu.AddValue("BSCALE", bScale, ""); imageHdu.AddValue("DATAMIN", 0.0, ""); // should this reflect the actual data values imageHdu.AddValue("DATAMAX", image.MaxADU, "pixel values above this level are considered saturated."); imageHdu.AddValue("DATE-OBS", image.LastExposureStartTime, ""); imageHdu.AddValue("XPIXSZ", image.PixelSizeX * image.BinX, "physical X dimension of the sensor's pixels in microns"); // (present only if the information is provided by the camera driver). Includes binning. imageHdu.AddValue("YPIXSZ", image.PixelSizeY * image.BinY, "physical Y dimension of the sensor's pixels in microns"); // (present only if the information is provided by the camera driver). Includes binning. imageHdu.AddValue("XBINNING", image.BinX, ""); imageHdu.AddValue("YBINNING", image.BinY, ""); imageHdu.AddValue("OBJCTRA", image.RA, "Approximate Right Ascension of image centre"); imageHdu.AddValue("OBJCTDEC", image.Dec, "Approximate Declination of image centre"); // save it var fitsImage = new Fits(); fitsImage.AddHDU(imageHdu); //Adds the actual image data (the header info already exists in imageHDU) FileStream fs = null; try { fs = new FileStream(path, FileMode.Create); using (var bds = new BufferedDataStream(fs)) { fs = null; fitsImage.Write(bds); } } finally { if (fs != null) { fs.Dispose(); } } }
public void BuildByColumn() { Fits f = null; try { BinaryTable btab = new BinaryTable(); btab.AddColumn(floats); btab.AddColumn(vf); btab.AddColumn(strings); btab.AddColumn(vbool); btab.AddColumn(ints); f = new Fits(); f.AddHDU(Fits.MakeHDU(btab)); BufferedFile bdos = new BufferedFile( TestFileSetup.GetTargetFilename("bt3.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bdos); bdos.Close(); bdos.Dispose(); f.Close(); f = new Fits(TestFileSetup.GetTargetFilename("bt3.fits")); BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1); btab = (BinaryTable)bhdu.Data; Assert.AreEqual(true, ArrayFuncs.ArrayEquals(floats, bhdu.GetColumn(0))); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(vf, bhdu.GetColumn(1))); // problem is here only String[] col = (String[])bhdu.GetColumn(2); for (int i = 0; i < col.Length; i += 1) { col[i] = col[i].Trim(); } Assert.AreEqual(true, ArrayFuncs.ArrayEquals(strings, col)); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(vbool, bhdu.GetColumn(3))); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ints, bhdu.GetColumn(4))); } finally { if (f != null) { f.Close(); } } }
/// <summary>Extract a single row from a table. This returns /// an array of Objects each of which is an array of length 1.</summary> private Array SingleRow(int row) { Array res = new Array[nFields]; for (int i = 0; i < nFields; i += 1) { if (isNull_Renamed_Field == null || !isNull_Renamed_Field[row * nFields + i]) { res.SetValue(ArrayFuncs.NewInstance(types[i], 1), i); Array.Copy((Array)data[i], row, (Array)res.GetValue(i), 0, 1); } } return(res); }
/// <summary> Print a little information about the data set.</summary> public override void Info() { Console.Out.WriteLine("ASCII Table:"); Console.Out.WriteLine(" Header:"); Console.Out.WriteLine(" Number of fields:" + myHeader.GetIntValue("TFIELDS")); Console.Out.WriteLine(" Number of rows: " + myHeader.GetIntValue("NAXIS2")); Console.Out.WriteLine(" Length of row: " + myHeader.GetIntValue("NAXIS1")); Console.Out.WriteLine(" Data:"); Array data = (Array)Kernel; for (int i = 0; i < NCols; i += 1) { System.Console.Out.WriteLine(" " + i + ":" + ArrayFuncs.ArrayDescription(data.GetValue(i))); } }
/// <summary>Display structural information about the current HDU.</summary> public override void Info() { Console.Out.WriteLine("Random Groups HDU"); if (myHeader != null) { Console.Out.WriteLine(" HeaderInformation:"); Console.Out.WriteLine(" Ngroups:" + myHeader.GetIntValue("GCOUNT")); Console.Out.WriteLine(" Npar: " + myHeader.GetIntValue("PCOUNT")); Console.Out.WriteLine(" BITPIX: " + myHeader.GetIntValue("BITPIX")); Console.Out.WriteLine(" NAXIS: " + myHeader.GetIntValue("NAXIS")); for (int i = 0; i < myHeader.GetIntValue("NAXIS"); i += 1) { Console.Out.WriteLine(" NAXIS" + (i + 1) + "= " + myHeader.GetIntValue("NAXIS" + (i + 1))); } } else { Console.Out.WriteLine(" No Header Information"); } // Object[][] data = null; Array data = null; if (myData != null) { try { //data = (Object[][]) myData.DataArray; data = (Array)myData.DataArray; } catch (FitsException) { data = null; } } //if(data == null || data.Length < 1 || data[0].Length != 2) if (data == null || data.Length < 1 || data.GetLength(1) != 2) { Console.Out.WriteLine(" Invalid/unreadable data"); } else { Console.Out.WriteLine(" Number of groups:" + data.Length); Console.Out.WriteLine(" Parameters: " + ArrayFuncs.ArrayDescription(data.GetValue(new int[] { 0, 0 }))); Console.Out.WriteLine(" Data:" + ArrayFuncs.ArrayDescription(data.GetValue(new int[] { 0, 1 }))); } }
/// <summary>Print out some information about this HDU.</summary> public override void Info() { BinaryTable myData = (BinaryTable)this.myData; Console.Out.WriteLine(" Binary Table"); Console.Out.WriteLine(" Header Information:"); int nhcol = myHeader.GetIntValue("TFIELDS", -1); int nrow = myHeader.GetIntValue("NAXIS2", -1); int rowsize = myHeader.GetIntValue("NAXIS1", -1); Console.Out.Write(" " + nhcol + " fields"); Console.Out.WriteLine(", " + nrow + " rows of length " + rowsize); for (int i = 1; i <= nhcol; i += 1) { Console.Out.Write(" " + i + ":"); CheckField("TTYPE" + i); CheckField("TFORM" + i); CheckField("TDIM" + i); Console.Out.WriteLine(" "); } Console.Out.WriteLine(" Data Information:"); if (myData == null || table.NRows == 0 || table.NCols == 0) { Console.Out.WriteLine(" No data present"); if (table.HeapSize > 0) { Console.Out.WriteLine(" Heap size is: " + table.HeapSize + " bytes"); } } else { Console.Out.WriteLine(" Number of rows=" + table.NRows); Console.Out.WriteLine(" Number of columns=" + table.NCols); if (table.HeapSize > 0) { Console.Out.WriteLine(" Heap size is: " + table.HeapSize + " bytes"); } Object[] cols = table.FlatColumns; for (int i = 0; i < cols.Length; i += 1) { Console.Out.WriteLine(" " + i + ":" + ArrayFuncs.ArrayDescription(cols[i])); } } }