/// <summary>Create an ASCII table given a header</summary> public AsciiTable(Header hdr) { nRows = hdr.GetIntValue("NAXIS2"); nFields = hdr.GetIntValue("TFIELDS"); rowLen = hdr.GetIntValue("NAXIS1"); types = new Type[nFields]; offsets = new int[nFields]; lengths = new int[nFields]; nulls = new String[nFields]; for (int i = 0; i < nFields; i += 1) { offsets[i] = hdr.GetIntValue("TBCOL" + (i + 1)) - 1; String s = hdr.GetStringValue("TFORM" + (i + 1)); if (offsets[i] < 0 || s == null) { throw new FitsException("Invalid Specification for column:" + (i + 1)); } s = s.Trim(); char c = s[0]; s = s.Substring(1); if (s.IndexOf('.') > 0) { s = s.Substring(0, (s.IndexOf('.')) - (0)); } lengths[i] = Int32.Parse(s); switch (c) { case 'A': types[i] = typeof(String); break; case 'I': if (lengths[i] > 10) { types[i] = typeof(long); } else { types[i] = typeof(int); } break; case 'F': case 'E': types[i] = typeof(float); break; case 'D': types[i] = typeof(double); break; } nulls[i] = hdr.GetStringValue("TNULL" + (i + 1)); if (nulls[i] != null) { nulls[i] = nulls[i].Trim(); } } }
/// <summary>Check if we can find the length of the data for this header.</summary> /// <returns><CODE>true</CODE> if this HDU has a valid header.</returns> public static new bool IsHeader(Header hdr) { if(hdr.GetStringValue("XTENSION") != null && hdr.GetIntValue("NAXIS", - 1) >= 0) { return true; } return false; }
/// <summary>Is this a random groups header?</summary> /// <param name="myHeader">The header to be tested.</param> public static new bool IsHeader(Header hdr) { if (hdr.GetBooleanValue("SIMPLE")) { return hdr.GetBooleanValue("GROUPS"); } String s = hdr.GetStringValue("XTENSION"); if (s.Trim().Equals("IMAGE")) { return hdr.GetBooleanValue("GROUPS"); } return false; }
/// <summary>Process one column from a FITS Header.</summary> private int ProcessCol(Header header, int col) { String tform = header.GetStringValue("TFORM" + (col + 1)); // .99 changes if (tform == null) { throw new FitsException("Attempt to process column " + (col + 1) + " but no TFORMn found."); } tform = tform.Trim(); String tdims = header.GetStringValue("TDIM" + (col + 1)); if (tform == null) { throw new FitsException("No TFORM for column:" + col); } if (tdims != null) { tdims = tdims.Trim(); } char type = GetTformType(tform); // .99.1 changes: condition changed if (type == 'P' || type == 'Q') { flags[col] |= COL_VARYING; // .99.1 changes: if (type == 'Q') { flags[col] |= COL_LONGVARY; } type = GetTformVarType(tform); } int size = GetTformLength(tform); // Handle the special size cases. // // Bit arrays if (type == 'X') { size = (size + 7) / 8; flags[col] |= COL_BIT; // Variable length arrays (just a two element array ) } // .99.1 changes: new method for condition check else if (IsVarCol(col)) { size = 2; } int bSize = size; int[] dims = null; // .99.1 changes: new method for condition check // Cannot really handle arbitrary arrays of bits. if (tdims != null && type != 'X' && !IsVarCol(col)) { dims = GetTDims(tdims); } if (dims == null) { // .99.1 change if (size == 1) { dims = new int[0]; } else { dims = new int[] { size }; } } if (type == 'C' || type == 'M') { flags[col] |= COL_COMPLEX; } Type colBase = null; switch (type) { case 'A': colBase = typeof(byte); flags[col] |= COL_STRING; bases[col] = typeof(String); break; case 'L': colBase = typeof(byte); bases[col] = typeof(bool); flags[col] |= COL_BOOLEAN; break; case 'X': case 'B': colBase = typeof(byte); bases[col] = typeof(byte); break; case 'I': colBase = typeof(short); bases[col] = typeof(short); bSize *= 2; break; case 'J': colBase = typeof(int); bases[col] = typeof(int); bSize *= 4; break; case 'K': colBase = typeof(long); bases[col] = typeof(long); bSize *= 8; break; case 'E': case 'C': colBase = typeof(float); bases[col] = typeof(float); bSize *= 4; break; case 'D': case 'M': colBase = typeof(double); bases[col] = typeof(double); bSize *= 8; break; default: throw new FitsException("Invalid type in column:" + col); } // .99.1 changes: new method for condition check if (IsVarCol(col)) { dims = new int[]{nRow, 2}; colBase = typeof(int); bSize = 8; } // .99.1 changes: new method for condition check else if (IsLongVary(col)) { colBase = typeof(long); bSize = 16; } // .99.1 changes: new method for condition check else if (IsComplex(col)) { int[] xdims = new int[dims.Length + 1]; Array.Copy(dims, 0, xdims, 0, dims.Length); xdims[dims.Length] = 2; dims = xdims; } modelRow[col] = ArrayFuncs.NewInstance(colBase, dims); dimens[col] = dims; sizes[col] = size; return bSize; }
/// <summary> Check that this is a valid ascii table header.</summary> /// <param name="header">to validate.</param> /// <returns> <CODE>true</CODE> if this is an ascii table header.</returns> public static new bool IsHeader(Header header) { return header.GetStringValue("XTENSION").Trim().Equals("TABLE"); }
/// <summary>Check that this is a valid binary table header.</summary> /// <param name="header">to validate.</param> /// <returns> <CODE>true</CODE> if this is a binary table header.</returns> public static new bool IsHeader(Header header) { String xten = header.GetStringValue("XTENSION"); if (xten == null) { return false; } xten = xten.Trim(); if (xten.Equals("BINTABLE") || xten.Equals("A3DTABLE")) { return true; } else { return false; } }
/// <summary>Check that this HDU has a valid header for this type.</summary> /// <returns> <CODE>true</CODE> if this HDU has a valid header.</returns> public static new bool IsHeader(Header hdr) { bool found = false; found = hdr.GetBooleanValue("SIMPLE"); if (!found) { String s = hdr.GetStringValue("XTENSION"); if (s != null) { if (s.Trim().Equals("IMAGE") || s.Trim().Equals("IUEIMAGE")) { found = true; } } } if (!found) { return false; } return !hdr.GetBooleanValue("GROUPS"); }