private bool OpenFile(string filePath) { var retval = false; var status = 0; if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("The file path cannot be a null or empty string!"); } if (FilePath != null) { throw new InvalidOperationException("OpenFile cannot be called a again once a file has been opened!"); } CFits.OpenFile(out _fitsPointer, filePath, CFits.READONLY, ref status); Header = GetHeaderData(); Status = status; if (status == 0) { FilePath = filePath; retval = true; } return(retval); }
private FitsHeader GetHeaderData() { if (Status != 0) { return(null); } var status = 0; var fitsHeader = new FitsHeader(); var ndx = 1; while (true) { string keyName = null; string keyValue = null; string keyComment = null; CFits.ReadHeaderRecord(_fitsPointer, ndx++, ref keyName, ref keyValue, ref keyComment, ref status); if (status == (int)ErrorStatusCode.KEY_OUT_BOUNDS) { break; } else if (status != 0) { Status = status; var errText = CFits.GetErrorStatus(status); throw new Exception("FITS ReadHeaderRecord error - " + errText); } var keyUnits = ""; ExtractUnits(ref keyUnits, ref keyComment); var item = new FitsHeaderItem(keyName, keyValue, keyUnits, keyComment); fitsHeader.Add(item); } Header = fitsHeader; return(fitsHeader); }
public static int LoadImage(string filepath, out FitsHeader header) { int retval; header = null; try { Mgr.Status = 0; if (Mgr.OpenFile(filepath)) { header = Mgr.Header; } } finally { retval = Mgr.Status; Mgr.CloseFile(); } return(retval); }