 {~ Luminance expressed both standardly and in a queer astronomical way ~}

program Lum;

uses str_num;

(* Transformation of luminance expressed in basic units
        -  i.e., in candelas per square meter  -
   to the obscure equivalents of "magnites per square <something>",
       where <something> is either second, minute or degree of arc.

 Such an equivalent means a faintness of a star, which would have the same
 luminance when defocused to such a space angle.

   Jen\'\ik Hollan, 1993-12-11 *)

var sec,Qsec,MSS,JS,ln10,S_M,S_D,C_5M,Dia: real;
    code: integer;
    switch: char;
    st: string;

procedure help;
begin
writeln(#10,'LUM #');
writeln(' will say you, what are the equivalents of the luminance of');
writeln(' #  cd/m2  (candela per square meter)');
writeln('LUM m #');
writeln(' will compute the luminance of a star of # magnitudes defocused to');
writeln(' one "square minute";');
writeln('LUM S #');
writeln(' will do that for the defocusation of');
writeln(' one "square second",');
writeln('LUM D #');
writeln(' for that of one "square degree"');
writeln('LUM m<diam> #     and similarly for S and D');
writeln(' will do that for a star defocused to a circle of <diam> minutes diameter.');
writeln;
writeln(
'1999 (C) Jan Hollan, N.Copernicus Observatory and Planetarium in Brno,'+cl+
' subject to the GNU General Public License, http://www.gnu.org/copyleft;'+cl+
' source code available at http://astro.sci.muni.cz/pub/hollan/programmes)');
halt
end;

function MagSqSec(JS:real):real;
begin
 MagSqSec:=-2.5*ln(JS*Qsec/2.54E-6)/ln10
end;

function Luminance(MSS:real):real;
begin
 Luminance:= exp(-0.4*ln10*MSS) * 2.54E-6 / Qsec
end;

begin
ln10:=ln(10);
sec:=Pi/180/3600; Qsec:=sec*sec;
S_M:=-2.5*ln(60*60)/Ln10;
S_D:=-2.5*ln(3600*3600)/ln10;
C_5M:=-2.5*ln(300*300*pi/4)/Ln10;

JS:=Luminance(21.6);

if Paramcount=0 then help;
if paramcount>2 then help;

if paramcount=1 then
begin
 if (pos('?',paramstr(1))>0) or (pos('-h',paramstr(1))>0) then help;
 val(paramstr(1),JS,code);
 if code>0 then
  begin
   writeln(paramstr(1), ' is no value of Luminance!'); halt;
  end
 else
  begin
   MSS:=MagSqSec(JS);
   writeln;
   writeln('The given Luminance of ');
   writeln('                       ',SRx(2,JS),' cd/m^2 corresponds to a star of');
   writeln('faintness of some');
   writeln;
   writeln(MSS:5:2,' mag   defocused to one "square second",');
   writeln(MSS+S_M:5:2,' mag   defocused to one "square minute",');
   writeln(MSS+S_D:5:2,' mag   defocused to one "square degree".');
   writeln(MSS+C_5M:5:2,' mag   defocused to a circle of diameter of 5 angular minutes');
   writeln('            (on the verge of being a "point" for human nightime vision)');
   writeln;
  end
end
else
 begin
 val(paramstr(2),MSS,code);
 if code>0 then
  begin
   writeln(paramstr(2), ' is no number - faintness / 1 mag!'); halt;
  end
 else
  begin
   writeln;
   writeln('The equivalent of Luminance expressed by a star of faintness of');
   write(MSS:5:2,' mag  defocused to ');
   st:=paramstr(1);
   switch:=st[1];
   val(copy(st,2,length(st)-1),Dia,code);
   if Dia=0 then
    case Switch of
     'M','m' : begin
            writeln('"one square minute"');
            MSS:=MSS-S_M;
           end;
     'D','d' : begin
            writeln('"one square degree"');
            MSS:=MSS-S_D;
           end;
     'S','s' : writeln('"one square second"');
     else begin writeln('what ? - ',paramstr(1),' is none of the S, M, D options'); halt end;
    end
   else
    begin
     write('a circle of angular diameter of');
     case Switch of
      'M','m' : begin
             writeln(Dia:6:1,' minutes');
             MSS:=MSS-S_M;
            end;
      'D','d' : begin
             writeln(Dia:6:1,' degrees');
             MSS:=MSS-S_D;
            end;
      'S','s' : writeln(Dia:6:1,' seconds');
      else begin writeln('what ? - ',paramstr(1),' is none of the S, M, D options'); halt end;
     end;
     MSS:=MSS+2.5*ln(sqr(Dia)*pi/4)/ln10;
    end;

   JS:=Luminance(MSS);
   writeln('      means a Luminance of some ');
   writeln('                           ',SRx(2,JS),' cd/m^2 ');
   writeln;
   writeln('and alternative equivalent stars might be faint');
   writeln;
   writeln(MSS:5:2,' mag  when defocused to one "square second",');
   writeln(MSS+S_M:5:2,' mag  when defocused to one "square minute",');
   writeln(MSS+S_D:5:2,' mag  when defocused to one "square degree".');
   writeln(MSS+C_5M:5:2,' mag   defocused to a circle of diameter of 5 angular minutes');
   writeln('            (on the verge of being a "point" for human nightime vision)');
   writeln;
  end
 end;

end.
