home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / PLOT / SURFUTI3.ZIP / READINI.INC < prev    next >
Encoding:
Text File  |  1991-09-28  |  11.0 KB  |  321 lines

  1. { This file is no longer used in SURFMODL, only for file conversion. }
  2. procedure READINI (Datafile: text80);
  3. { Read the INItialization file }
  4.  
  5. var Num: integer;           { #parameters read on line }
  6.     Realvar: vartype;       { temp array for storage of line input }
  7.     Infile: text;           { file to read }
  8.     Comment: text80;        { comment at end of line }
  9.     Version: integer;       { version # of the INI file }
  10.     Line_num: integer;      { line # in input file }
  11.     Cmmd: integer;          { selection # }
  12.     Filebad: boolean;       { flag bad file }
  13.     Mat: integer;           { material # }
  14.     Lite: integer;          { light source # }
  15.     Sys_type_set: boolean;  { was the system type set in this INI file? }
  16.     Sys: integer;           { index to legal system number array }
  17.     Command: cmmdtype;      { symbolic command type }
  18.     Parm: parmtype;         { symbolic parameter }
  19.     Dir: dirstr;            { directory name of file }
  20.     Name: namestr;          { name of file }
  21.     Ext: extstr;            { extension of file }
  22.     ch: char;
  23.  
  24. begin
  25. {$ifndef INICVT}
  26.   ClrScr;
  27.   writeln ('Reading .INI file . . .');
  28. {$endif}
  29.   Sys_type_set := FALSE;
  30.   { Correctly name the INI file }
  31.   fsplit (Datafile, Dir, Name, Ext);
  32.   { Save the Data file mask for other data file uses }
  33.   Filemask := Dir + Name;
  34.  
  35.   Inifile := Filemask + '.INI';
  36.  
  37.   Filebad := FALSE;
  38. { See if it exists }
  39.   assign (Infile, Inifile);
  40.   {$I-}
  41.   reset (Infile);
  42.   {$I+}
  43.   if (ioresult = 0) then begin
  44.     { File exists; read it and set global parameters }
  45.     Line_num := 0;
  46.     Num := inreal (Infile, Realvar, Comment, Command, Parm, Line_num, FALSE);
  47.     if (Num <> 1) then begin
  48.       writeln ('Bad INIfile: Reading version number.');
  49.       Filebad := TRUE;
  50.     end else
  51.       Version := round (Realvar[1]);
  52.  
  53.     if (Version >= 1) and (Version <= 4) and (not Filebad) then begin
  54.       Cmmd := 0;
  55.       while (Cmmd <> 99) and (not Filebad) do begin
  56.         Num := inreal (Infile, Realvar, Comment, Command, Parm, Line_num,
  57.             FALSE);
  58.         if (Num < 1) then begin
  59.           writeln ('Bad INIfile');
  60.           Filebad := TRUE;
  61.         end;
  62.         if (Filebad) then
  63.           Cmmd := 99
  64.         else
  65.           Cmmd := round (Realvar[1]);
  66.  
  67.         case Cmmd of
  68.           1:
  69.             begin
  70.             (* KVC 09/05/91 Obsolete!
  71.             if (Num <> 2) then begin
  72.               writeln ('INIfile: System number input bad');
  73.               Filebad := TRUE;
  74.             end else begin
  75.               grSys := trunc(Realvar[2]);
  76.               if (version = 4) then begin
  77.                 grmode := round (100.0 * (realvar[2] - grsys));
  78.               end
  79.               else
  80.                 grmode := 0; {guaranteed for all modes}
  81.               if version <= 3 then
  82.                 grsys := oldsys[grsys];
  83.               if (Version >= 3) then
  84.                 Sys_type_set := TRUE;
  85.             end; { if Num }
  86.             *)
  87.             end;
  88.           2:
  89.             if (Num <> 4) then begin
  90.               writeln ('INIfile: Eye coordinates bad');
  91.               Filebad := TRUE;
  92.             end else begin
  93.               Xeye := Realvar[2];
  94.               Yeye := Realvar[3];
  95.               Zeye := Realvar[4];
  96.             end;
  97.           3:
  98.             if (Num <> 4) then begin
  99.               writeln ('INIfile: Focal point coordinates bad');
  100.               Filebad := TRUE;
  101.             end else begin
  102.               Xfocal := Realvar[2];
  103.               Yfocal := Realvar[3];
  104.               Zfocal := Realvar[4];
  105.             end;
  106.           4:
  107.             if (Num <> 2) then begin
  108.               writeln ('INIfile: Bad magnification factor');
  109.               Filebad := TRUE;
  110.             end else
  111.               Magnify := Realvar[2];
  112.           5:
  113.             if (Num <> 2) or (Realvar[2]<0.0) or (Realvar[2]>3.0) then begin
  114.               writeln ('INIfile: Bad view type');
  115.               Filebad := TRUE;
  116.             end else
  117.               Viewtype := round(Realvar[2]);
  118.           6:; { Autoresolve removed }
  119.           7:
  120.             if (Version = 1) then begin
  121.               if (Num <> 6) or (Realvar[2]<1.0)or(Realvar[2]>MAXMATL) then begin
  122.                 writeln ('Warning: Bad matl data in INIfile.');
  123.                 write ('Press any key to continue...');
  124.                 ch := readkey;
  125.               end else begin
  126.                 Mat := round (Realvar[2]);
  127.                 if (Mat > Nmatl) then
  128.                   Nmatl := Mat;
  129.                 R1[Mat] := Realvar[3];
  130.                 R2[Mat] := Realvar[4];
  131.                 R3[Mat] := Realvar[5];
  132.                 Color[Mat] := round (Realvar[6]);
  133.                 Ambient[Mat] := 0.1;
  134.                 color_to_RGB (Color[Mat], Redmax[Mat], Grnmax[Mat], 
  135.                               Blumax[Mat]);
  136.               end;
  137.             end else begin
  138.               if (Num <> 7) or (Realvar[2]<1.0)or(Realvar[2]>MAXMATL) then begin
  139.                 writeln ('Warning: Bad matl data in INIfile.');
  140.                 write ('Press any key to continue...');
  141.                 ch := readkey;
  142.               end else begin
  143.                 Mat := round (Realvar[2]);
  144.                 if (Mat > Nmatl) then
  145.                   Nmatl := Mat;
  146.                 R1[Mat] := Realvar[3];
  147.                 R2[Mat] := Realvar[4];
  148.                 R3[Mat] := Realvar[5];
  149.                 Color[Mat] := round (Realvar[6]);
  150.                 Ambient[Mat] := Realvar[7];
  151.                 color_to_RGB (Color[Mat], Redmax[Mat], Grnmax[Mat], 
  152.                               Blumax[Mat]);
  153.               end;
  154.             end; { if Version }
  155.           8:
  156.             if (Num <> 6) or (Realvar[2] < 1.0) or (Realvar[2] > MAXLITE)
  157.                 or (Realvar[2] > Nlite+1) then begin
  158.               writeln ('INIfile: Bad Light Source Data');
  159.               Filebad := TRUE;
  160.             end else begin
  161.               Lite := round (Realvar[2]);
  162.               if (Lite > Nlite) then
  163.                 Nlite := Lite;
  164.               Xlite[Lite] := Realvar[3];
  165.               Ylite[Lite] := Realvar[4];
  166.               Zlite[Lite] := Realvar[5];
  167.               Intensity[Lite] := Realvar[6];
  168.             end;
  169.           9:
  170.             if (Num <> 2) or (Version <> 1) then begin
  171.               writeln ('INIfile: Bad ambient light');
  172.               Filebad := TRUE;
  173.             end else
  174.               for Mat := 1 to Nmatl do
  175.                 Ambient[Mat] := Realvar[2];
  176.           10:
  177.             if (Num <> 2) then begin
  178.               writeln ('INIfile: Bad Epsilon');
  179.               Filebad := TRUE;
  180.             end else
  181.               if (Realvar[2] > 0.0) then begin
  182.                 Epsilon := Realvar[2];
  183.                 Interpolate := TRUE;
  184.               end else
  185.                 Interpolate := FALSE;
  186.           11:
  187.             if (Num <> 2) or (Realvar[2]<0.0) or (Realvar[2]>1.0) then begin
  188.               writeln ('INIfile: Bad Shadowing');
  189.               Filebad := TRUE;
  190.             end else
  191.               if (Realvar[2] = 0.0) then
  192.                 Shadowing := FALSE
  193.               else
  194.                 Shadowing := TRUE;
  195.           12: begin
  196.              (* KVC 09/17/91 Obsolete!
  197.              if (Num <> 2) or (Realvar[2] < 0) then begin
  198.                writeln ('INIfile: Bad number of graphics characters');
  199.                Filebad := TRUE;
  200.              end else
  201.                Ngraphchar := round (Realvar[2]);
  202.              *)
  203.             end;
  204.           13:
  205.              if (Num <> 6) or (Realvar[2]<0) or (Realvar[2]>2) or
  206.                 (Realvar[6]<0) or (Realvar[6]>32) then begin
  207.                writeln ('INIfile: Bad axis codes');
  208.                Filebad := TRUE;
  209.              end else begin
  210.                Showaxes := round(Realvar[2]);
  211.                Xaxislen := Realvar[3];
  212.                Yaxislen := Realvar[4];
  213.                Zaxislen := Realvar[5];
  214.                Axiscolor := round(Realvar[6]);
  215.              end;
  216.           14:
  217.              if (Num <> 2) then begin
  218.                writeln ('INIfile: Bad window number');
  219.                Filebad := TRUE;
  220.              end else
  221.                Nwindow := round(Realvar[2]);
  222.           15:
  223.             begin
  224.             (* KVC 09/14/91 Obsolete!
  225.              if (Num <> 3) or (Realvar[2] < 1) or (Realvar[3] < 0) or
  226.                  (Realvar[3] > 1) then begin
  227.                writeln ('INIfile: Bad system color data');
  228.                Filebad := TRUE;
  229.              end else begin
  230.                Ncolors := round(Realvar[2]);
  231.                if (Realvar[3] = 0) then
  232.                  Mono := FALSE
  233.                else
  234.                  Mono := TRUE;
  235.              end;
  236.             *)
  237.             end;
  238.           16:
  239.             if (Num <> 2) then begin
  240.               writeln ('INIfile: Bad Randshade');
  241.               Filebad := TRUE;
  242.             end else begin
  243.               if (Realvar[2] > 0.0) then begin
  244.                 Randshade := Realvar[2];
  245.                 Dorandom := TRUE;
  246.               end else
  247.                 Dorandom := FALSE;
  248.             end;
  249.           17:
  250.             if (Num <> 5)or(Realvar[2] < 1.0)or(Realvar[2] > MAXMATL) then begin
  251.               writeln ('INIfile: Bad RGB data');
  252.               Filebad := TRUE;
  253.             end else begin
  254.               Mat := round(Realvar[2]);
  255.               if (Mat > Nmatl) then
  256.                 Nmatl := Mat;
  257.               Redmax[Mat] := round(Realvar[3]);
  258.               Grnmax[Mat] := round(Realvar[4]);
  259.               Blumax[Mat] := round(Realvar[5]);
  260.               if Redmax[Mat] < 1 then
  261.                 Redmax[Mat] := 1;
  262.               if Redmax[Mat] > 256 then
  263.                 Redmax[Mat] := 256;
  264.               if Grnmax[Mat] < 1 then
  265.                 Grnmax[Mat] := 1;
  266.               if Grnmax[Mat] > 256 then
  267.                 Grnmax[Mat] := 256;
  268.               if Blumax[Mat] < 1 then
  269.                 Blumax[Mat] := 1;
  270.               if Blumax[Mat] > 256 then
  271.                 Blumax[Mat] := 256;
  272.               end;
  273.           18:
  274.              if (Num <> 2) then begin
  275.                writeln ('INIfile: Bad ShowAllBorders code');
  276.                Filebad := TRUE;
  277.              end else
  278.                ShowAllBorders := round(Realvar[2]);
  279.           99:
  280.           else
  281.             writeln ('Warning: INIfile has unknown code (',Cmmd,')');
  282.         end; { case Cmmd }
  283.       end; { while }
  284.     end else begin
  285.       writeln ('INIfile: Bad version number');
  286.       Filebad := TRUE;
  287.     end; { if Version }
  288.  
  289.     close (Infile);
  290.     if (Filebad) then begin
  291.       writeln ('Error found in line ',Line_num,' of ',Inifile);
  292. {$ifdef INICVT}
  293.       Ini_ok := FALSE;
  294. {$else}
  295.       write ('Press any key to continue...');
  296.       ch := readkey;
  297. {$endif}
  298.     end;
  299.  
  300.   end else begin
  301. {$ifdef INICVT}
  302.     writeln ('File ', Inifile, ' does not exist.');
  303.     Ini_ok := FALSE;
  304. {$else}
  305.     writeln ('No INItialization file.');
  306.     writeln ('Using last values.');
  307. {$endif}
  308.   end; { if ioresult }
  309.  
  310.   (* KVC 09/05/91 Obsolete!
  311.   if not sys_type_set then
  312.     grsys := 0; {detect graphics}
  313.  
  314.   if driveron then begin
  315.     closedriver;
  316.   end;
  317.   setsys;
  318.   *)
  319.  
  320. end; { procedure READINI }
  321.