public FITSHeader(string fileName) { FileStream fs = new FileStream(fileName, FileMode.Open); ArrayList headerlines = new ArrayList(); bool ext = false; FITSFILEOPS.SCANPRIMARYUNIT(fs, false, ref headerlines, ref ext); fs.Close(); HEADERKEYS = new JPFITS.FITSHeaderKey[headerlines.Count]; for (int i = 0; i < HEADERKEYS.Length; i++) { HEADERKEYS[i] = new FITSHeaderKey((string)headerlines[i]); } }
public static string[] GETALLEXTENSIONNAMES(string FileName, string extension_type) { FileStream fs = new FileStream(FileName, FileMode.Open); ArrayList header_return = null; bool hasext = false; if (!FITSFILEOPS.SCANPRIMARYUNIT(fs, true, ref header_return, ref hasext) || !hasext) { fs.Close(); if (!hasext) { throw new Exception("File '" + FileName + "' indicates no extensions present."); } else { throw new Exception("File '" + FileName + "' not formatted as FITS file."); } } byte[] charheaderblock = new byte[2880]; int naxis = 0, naxis1 = 0, naxis2 = 0, bitpix = 0; long pcount = -1; bool endheader = false, extensiontypefound = false, endfile = false, extnamekeyexists = false; string strheaderline; ArrayList namelist = new ArrayList(); string extname = ""; if (fs.Position >= fs.Length) { endfile = true; } while (!endfile) { //reset extname = ""; endheader = false; extnamekeyexists = false; extensiontypefound = false; naxis = 0; naxis1 = 0; naxis2 = 0; pcount = -1; bitpix = 0; while (!endheader) { fs.Read(charheaderblock, 0, 2880); for (int i = 0; i < 36; i++) { strheaderline = System.Text.Encoding.ASCII.GetString(charheaderblock, i * 80, 80); if (!extensiontypefound) { if (strheaderline.Substring(0, 8) == "XTENSION") { int f = strheaderline.IndexOf("'"); int l = strheaderline.LastIndexOf("'"); if (strheaderline.Substring(f + 1, l - f - 1).Trim() == extension_type) { extensiontypefound = true; } continue; } } if (!extnamekeyexists) { if (strheaderline.Substring(0, 8) == "EXTNAME ") { extnamekeyexists = true; int f = strheaderline.IndexOf("'"); int l = strheaderline.LastIndexOf("'"); extname = strheaderline.Substring(f + 1, l - f - 1).Trim(); continue; } } if (naxis == 0) { if (strheaderline.Substring(0, 8).Trim().Equals("NAXIS")) { naxis = Convert.ToInt32(strheaderline.Substring(10, 20)); continue; } } if (naxis1 == 0) { if (strheaderline.Substring(0, 8).Trim().Equals("NAXIS1")) { naxis1 = Convert.ToInt32(strheaderline.Substring(10, 20)); continue; } } if (naxis2 == 0) { if (strheaderline.Substring(0, 8).Trim().Equals("NAXIS2")) { naxis2 = Convert.ToInt32(strheaderline.Substring(10, 20)); continue; } } if (bitpix == 0) { if (strheaderline.Substring(0, 8).Trim().Equals("BITPIX")) { bitpix = Convert.ToInt32(strheaderline.Substring(10, 20)); continue; } } if (pcount == -1) { if (strheaderline.Substring(0, 8).Trim().Equals("PCOUNT")) { pcount = Convert.ToInt64(strheaderline.Substring(10, 20)); continue; } } if (strheaderline.Substring(0, 8) == "END ") //check if we're at the end of the header keys { if (extensiontypefound) { namelist.Add(extname); } endheader = true; break; } } } long TableBytes = (long)(naxis1) * (long)(naxis2) * (long)(Math.Abs(bitpix)) / 8; fs.Seek((long)(Math.Ceiling((double)(TableBytes + pcount) / 2880) * 2880), SeekOrigin.Current); if (fs.Position >= fs.Length) { endfile = true; } } fs.Close(); string[] list = new string[namelist.Count]; for (int i = 0; i < namelist.Count; i++) { list[i] = (string)namelist[i]; } return(list); }