Errors writing .FITS Header

Discussion in 'Scripting and Programming' started by David F. Emery, Mar 31, 2015.

  1. David F. Emery

    David F. Emery Cyanogen Customer

    Mar 30, 2015
    I am having an issue adding a .FITS header key to a .FITS file I have created from a .jpg image. I am using the most recent versions of MaxIm DL (6.08) and PinPoint (full version) with Visual Studio 2013:

    This VB.NET code successfully makes the new .FITS file… this part seems to work perfectly:
    Dim Docu As New MaxIm.Document
    Dim FITSfile As String = "c:\FITS\"
    Docu.SaveFile(FITSfile, mxFITS, True, 1, False)
    Docu = Nothing​

    But when I attempt to re-open the .FITS file and add a new header key, I get an exception error. This is my code:
    Dim Docu As New MaxIm.Document
    Dim FITSfile As String = "c:\FITS\"
    Dim HeaderKey As String = "DATE-OBS"
    Dim HeaderData As Object = "2015-03-29T21:55:22"
    (TYPE Variant is no longer supported in .NET, so I use TYPE Object instead)​
    Docu.SetFITSKey(HeaderKey, HeaderData)
    Docu.SaveFile(FITSfile, mxFITS, True, 1, False)
    Docu = Nothing​
    MaxIm opens the .fits and displays it properly, but I get this Exception Error reported on the line SetFITSkey(HeaderKey, HeaderData):
    RemotingException is Unhandled
    An unhandled exception of type 'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll
    Additional information: ByRef value type parameter cannot be null.

    Strangely, however, if the .fits file is manually saved at that point (MaxIm is open with the .fits file displayed), the new key has, indeed, been added even though my code throws the error. BUT other utilities I sometimes use to look at .FITS files (Avis.exe is an example) can’t read it and give me an error message that says something like ‘Incompatible file format’.

    When I attempt to re-open the .FITS file to add the .FITS key using PinPoint script instead of MaxIm script, I get a different Exception Error. This is the code:
    Dim p As Object = CreateObject("PinPoint.Plate")
    Dim FITSfile As String = "c:\FITS\"
    Dim HeaderData As String = "2015-03-29T21:55:22"
    Dim HeaderKey As String = "DATE-OBS"
    p.writeFITS(HeaderKey, HeaderData)

    The following exception is thrown by the line p.AttachFITS(FITSfile):
    COMException was unhandled
    System.Runtime.InteropServices.COMException was unhandled
    Message=Failed to open image file for read access.
    Extension doesn't start with SIMPLE or XTENSION keyword. (ffrhdu)
    SIMPLE‚=”T²BITPIX‚=“16 /8 unsigned int, 16 & 32 int, -32 & -64 real…NAXISƒ=”3 /n
    ffopen could not interpret primary array header of file: C:\FITS\
    This does not look like a FITS file.
    And there may be other problems, too

    Digging into this error message reveals that the script method is apparently not seeing the ‘T’ in the first .FITS header line…. it should be:
    SIMPLE = T
    BITPIX = 16
    But as you can see from the error message, the script apparently sees instead:
    SIMPLE=,” T²BITPIX, ="16 etc.​
    and consequently it crashes since the .FITS header appears to be improperly constructed or incomplete. That is essentially what the first error message is saying as well. And that would seem to explain why neither MaxIm script or PinPoint script can complete without throwing an exception.

    When the first routine created the .fit file from the .jpg file (prior to the attempted addition of a new header key), the initial .FITS header was generated entirely by MaxIm. So this leads me to ask,
    “Am I doing something wrong, particularly in the TYPE designation of the HeaderKey and HeaderData variables?"​
    “Is there a bug in the MaxIm routine that generates the .FITS header when the .jpg file is saved as a .fit file?”​
    Last edited: Apr 1, 2015

Share This Page