unit Header;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFormHeader = class(TForm)
    MemoHeader: TMemo;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormHeader: TFormHeader;

implementation

uses Unit1, Global;

{$R *.DFM}

procedure TFormHeader.FormShow(Sender: TObject);
const MaxLines = 500;
var i, n, k : integer;
    s       : string[81];
    f       : file;
    ext     : string;
begin
  Caption:='File header';
  Left:=Form1.Left;
  Top:=Form1.Top;
  Height:=Form1.Height;
  Width:=860;
  if  (ext='.TIF') or (ext='.BIF') or (ext='.PNG') then
    begin
      MemoHeader.Clear;
      MemoHeader.Lines.Add('No header info.')
    end;
  ext:=UpperCase(ExtractFileExt(Info.FileName));
  if (ext='.FITS') or (ext='.FTS') or (ext='.FIT') then
    begin
      MemoHeader.Clear;
      s[0]:=chr(81);
      s[1]:=' ';
      System.Assign(f,Info.FileName);
      if n>MaxLines then n:=MaxLines;
      k:=1;
      System.Reset(f,1);
      n:=FileSize(f) div 80;
      if n>MaxLines then n:=MaxLines;
      repeat
        System.BlockRead(f,s[2],80);
        MemoHeader.Lines.Add(s);
        inc(k);
      until (Pos(' END ',UpperCase(s))>0) or (k>=n);
      if k>=n then MemoHeader.Lines.Add('-------- FITS header too long --------------');
    end;
end;

end.
