/// <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))))); }
/// <summary>Fill header with keywords that describe image data.</summary> /// <param name="head">The FITS header</param> /// <exception cref="FitsException"> FitsException if the object does not contain valid image data.</exception> internal override void FillHeader(Header head) { if (dataArray == null) { head.NullImage(); return; } Type classname = ArrayFuncs.GetBaseClass(dataArray); int[] dimens = ArrayFuncs.GetDimensions(dataArray); if (dimens == null || dimens.Length == 0) { throw new FitsException("Image data object not array. "); } int bitpix; // Changed from classname[dimens.Length] to classname[classname.IndexOf(".") + 1] switch (classname.ToString()) { case "System.Byte": bitpix = 8; break; case "System.Int16": bitpix = 16; break; case "System.Int32": bitpix = 32; break; case "System.Int64": bitpix = 64; break; case "System.Single": bitpix = -32; break; case "System.Double": bitpix = -64; break; default: throw new FitsException("Invalid Object Type for FITS data:" + classname.ToString()); } // if this is neither a primary header nor an image extension, // make it a primary header head.Simple = true; head.Bitpix = bitpix; head.Naxes = dimens.Length; for (int i = 1; i <= dimens.Length; i += 1) { if (dimens[i - 1] == -1) { throw new FitsException("Unfilled array for dimension: " + i); } head.SetNaxis(i, dimens[dimens.Length - i]); } // suggested in .97 version: EXTEND keyword added before PCOUNT and GCOUNT. head.AddValue("EXTEND", true, "Extension permitted"); // Just in case! head.AddValue("PCOUNT", 0, "No extra parameters"); head.AddValue("GCOUNT", 1, "One group"); }
internal override void FillHeader(Header h) { //int[] dims = ArrayFuncs.GetDimensions(dataArray); int[] dims = ArrayFuncs.GetDimensions(dataArray.GetValue(0)); //if (dataArray.Length <= 0 || dataArray[0].Length != 2) if (dims.Length != 2) { throw new FitsException("Data not conformable to Random Groups"); } int gcount = dataArray.Length; //Object paraSamp = dataArray[0][0]; //Object dataSamp = dataArray[0][1]; Object paraSamp = ((Array)dataArray.GetValue(0)).GetValue(0); Object dataSamp = ((Array)dataArray.GetValue(0)).GetValue(1); Type pbase = ArrayFuncs.GetBaseClass(paraSamp); Type dbase = ArrayFuncs.GetBaseClass(dataSamp); if (pbase != dbase) { throw new FitsException("Data and parameters do not agree in type for random group"); } int[] pdims = ArrayFuncs.GetDimensions(paraSamp); int[] ddims = ArrayFuncs.GetDimensions(dataSamp); if (pdims.Length != 1) { throw new FitsException("Parameters are not 1 d array for random groups"); } // Got the information we need to build the header. h.Simple = true; if (dbase == typeof(byte)) { h.Bitpix = 8; } else if (dbase == typeof(short)) { h.Bitpix = 16; } else if (dbase == typeof(int)) { h.Bitpix = 32; } else if (dbase == typeof(long)) { // Non-standard h.Bitpix = 64; } else if (dbase == typeof(float)) { h.Bitpix = -32; } else if (dbase == typeof(double)) { h.Bitpix = -64; } else { throw new FitsException("Data type:" + dbase + " not supported for random groups"); } h.Naxes = ddims.Length + 1; h.AddValue("NAXIS1", 0, ""); for (int i = 2; i <= ddims.Length + 1; i += 1) { h.AddValue("NAXIS" + i, ddims[i - 2], ""); } h.AddValue("GROUPS", true, ""); h.AddValue("GCOUNT", dataArray.Length, ""); h.AddValue("PCOUNT", pdims[0], ""); }
/// <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) { return(o != null && typeof(Array).Equals(o.GetType()) && !ArrayFuncs.GetBaseClass(o).Equals(typeof(bool))); }
/// <summary>This version of addColumn allows the user to override /// the default length associated with each column type.</summary> public virtual int addColumn(Object newCol, int length) { if (nFields > 0 && ((Array)newCol).Length != nRows) { throw new FitsException("New column has different number of rows"); } if (nFields == 0) { nRows = ((Array)newCol).Length; } Object[] newData = new Object[nFields + 1]; int[] newOffsets = new int[nFields + 1]; int[] newLengths = new int[nFields + 1]; Type[] newTypes = new Type[nFields + 1]; String[] newNulls = new String[nFields + 1]; Array.Copy(data, 0, newData, 0, nFields); Array.Copy(offsets, 0, newOffsets, 0, nFields); Array.Copy(lengths, 0, newLengths, 0, nFields); Array.Copy(types, 0, newTypes, 0, nFields); Array.Copy(nulls, 0, newNulls, 0, nFields); data = newData; offsets = newOffsets; lengths = newLengths; types = newTypes; nulls = newNulls; newData[nFields] = newCol; offsets[nFields] = rowLen + 1; lengths[nFields] = length; types[nFields] = ArrayFuncs.GetBaseClass(newCol); rowLen += length + 1; if (isNull_Renamed_Field != null) { bool[] newIsNull = new bool[nRows * (nFields + 1)]; // Fix the null pointers. int add = 0; for (int i = 0; i < isNull_Renamed_Field.Length; i += 1) { if (i % nFields == 0) { add += 1; } if (isNull_Renamed_Field[i]) { newIsNull[i + add] = true; } } isNull_Renamed_Field = newIsNull; } nFields += 1; // Invalidate the buffer buffer = null; return(nFields); }