{$Debug}
Module Line;
(*
(
( FILENAME: LineMod.Pas
(			Handles data collection for preparing a Line Chart
(
( CONTENTS: GetLineData
(			SaveLineData
(			Line_Chart
(
( REVISION HISTORY
(
( VERSION  DATE  BY DESCRIPTION
(      
(
( 2.1.1 020189 CB Expand size of some LString variables
(					that were too small to 50 characters
( 2.0   021287 TM Allow as much data as memory permits
( 1.2   021786 CB Allow retries in OpenDataFile
( 1.1   011086 CB Fixed CodeS
( 1.0   120185 CB First release
(
(
*)

TYPE 
   cCoordsType  =  ARRAY[1..5] OF WORD;
   LineNameType =  ARRAY[1..5] OF LSTRING(20);
   LSFileSpec   =  LSTRING(50);
   Pointer      =  ADS OF WORD;
   pValueRec    =  ADS OF RECORD
                             xValue      :  Real;
                             yValue      :  Real;
                             NxtPtr      :  ADSMEM;
                             PrevPtr     :  ADSMEM;
                   END;
   HeaderType   =  ARRAY [1..5] OF ADSMEM;

CONST 
   Cancel       =  7;
   CodeS        =  211;
   Code_s       =  243;
   ColorFmt     =  '[sys]<sys>ColorLine.Fm';
   CReturn      =  10;
   DownArrow    =  11;
   DScroll      =  13;
   DType        =  'Character.';
   F1           =  21;
   F2           =  22;
   F3           =  23;
   F4           =  24;
   F5           =  25;
   F6           =  26;
   F7           =  28;
   F8           =  29;
   F9           =  30;
   F10          =  31;
   Finish       =  4;
   Fmt          =  'ChgFmt';
   Go           =  27;
   LineCode     =  2;
   ModeRead     =  ReType(WORD,'mr');
   ModeWrite    =  ReType(WORD,'mw');
   MonoFmt      =  '[sys]<sys>Line.Fm';
   NextPage     =  12;
   OverType     =  7;
   PrevPage     =  5;
   Saving       =  'Saving...';
   SaveCmplt =  'Save Complete';
   UpArrow      =  1;
   UScroll      =  11;
   WaitMsg      =  'Please Wait.....';

VAR [EXTERN]
   BSVid,
   LineForm  :  WORD;

VAR 

   BsBuf     :  ARRAY[1..1024] OF BYTE;
   BSWA      :  ARRAY[1..130] OF BYTE;
   ByteRet   :  BYTE;
   cbRead    :  WORD;
   ChartType :  WORD;
   cLines    :  WORD;
   cCoords   :  cCoordsType;
   DataPtr   :  pValueRec;
   TEMPPTR   :  PVALUEREC;
   DataRet   :  LSFileSpec;
   ExitKey   :  WORD;
   fDone     :  BOOLEAN;
   fF2       :  BOOLEAN;
   FIndxX    :  Integer;
   FIndxY    :  Integer;
   fGraph    :  BOOLEAN;
   FldName   :  ARRAY[1..20] OF LSTRING(10);
   ExitState :  RECORD
                   ich[0]       :  WORD;
                   ch[2]        :  WORD;
                   fAutoExit[4] :  BOOLEAN;
                   fModified[6] :  WORD;
                   fEmpty[8]    :  WORD;
                   Reserved[10] :  ARRAY[1..6] OF BYTE;
                END;
   FmFile    :  LSFileSpec;
   FormColumn:  Integer;
   FormRow   :  Integer;
   Hdr       :  ARRAY[1..8] OF WORD;
   Header    :  HeaderType;
   InitState :  ARRAY[1..4] OF WORD;
   I,J       :  Integer;
   iNames    :  Integer;
   Indx      :  Integer;
   iCoords   :  Integer;
   ixValues  :  Integer;
   iyValues  :  Integer;
   LineTitle :  LSFileSpec;
   LineName  :  LineNameType;
   MaxCoords :  cCoordsType;
   Ok        :  BOOLEAN;
   pDataValue:  pValueRec;
   pNewData  :  pValueRec;
   PicFile   :  LSFileSpec;
   Values    :  LSTRING(10);
   xLabel    :  LSFileSpec;
   yLabel    :  LSFileSpec;

VALUE 
   FldName[1] := 'LineTitle';
   FldName[2] := 'xLabel';
   FldName[3] := 'yLabel';
   FldName[4] := 'cLines';
   FldName[5] := 'LineData1';
   FldName[6] := 'LineData2';
   FldName[7] := 'LineData3';
   FldName[8] := 'LineData4';
   FldName[9] := 'LineData5';
   FldName[10] := 'LineData6';
   FldName[11] := 'LineData7';
   FldName[12] := 'LineData8';
   FldName[13] := 'LineData9';
   FldName[14] := 'LineData10';
   FldName[15] := 'LineData11';
   FldName[16] := 'LineData12';
   FldName[17] := 'Line';
   FldName[18] := 'xValue';
   FldName[19] := 'yValue';
   FldName[20] := 'Format';

{$Include:'Forms.Edf'}
{$Include:'Main.Edf'}
{$Include:'MiscMod.Edf'}

{$Include:'Bs.Edf'}

FUNCTION ReadKBD(pCharRet : POINTER) :  WORD; EXTERN;

FUNCTION AllocMemorySL(cBytes : WORD; ppSegmentRet : POINTER) :  WORD; EXTERN;

FUNCTION DeallocMemorySL(pSegment : POINTER; cBytes : WORD) :  WORD; EXTERN;

{
 Find the minimum of the two numbers 
 which are the parameters.           
}

FUNCTION IMin(Int1, Int2 : INTEGER) :  INTEGER;

BEGIN
   IF (Int1 > Int2)
      THEN
         IMin := Int2
      ELSE
         IMin := Int1;
END;

FUNCTION ReadASCIIData :  WORD;

VAR 
   FieldNm,
   DataIn,
   DFormat,
   XFormat1,
   XFormat2,
   DataFile    :  LSTRING(80);
   Spaces      :  ARRAY [1..999] OF BYTE;
   J,
   Position    :  INTEGER;
   fValid      :  BOOLEAN;
   Erc,
   SpaceErc,
   cbRead,
   DataLen,
   SpacesLen1,
   SpacesLen2  :  WORD;

BEGIN
   REPEAT
      FieldNm := 'DataFile';
      Read_The_FieldC(ADS LineForm, FieldNm, 0, DataFile, Upper(DataFile),
      ADS ExitState);
      IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
         THEN
            Erc := 0
         ELSE BEGIN
                 Erc := OpenByteStream(ADS BSWA[1],
                        ADS DataFile[1], DataFile.Len,
                        ADS NIL,0,
                        ModeRead,
                        ADS BsBuf[1], SizeOf(BsBuf));

                 IF (Erc <> 0)
                    THEN BEGIN
                            Beep;
                            Write_the_FieldC(ADS LineForm, FieldNm, 0, ADS NULL, 0);
                       END;

            END;

   UNTIL (Erc = 0);

   IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
      THEN
      ELSE
         REPEAT
            FieldNm := 'XFormat1';
            Read_The_FieldC(ADS LineForm, FieldNm, 0, XFormat1,
                            Upper(DataFile), ADS ExitState);
            IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
               THEN
                  fValid := TRUE
               ELSE BEGIN

                       fValid := Decode(XFormat1, SpacesLen1);

                       IF NOT (fValid)
                          THEN BEGIN
                                  Beep;
                                  Write_the_FieldC(ADS LineForm, FieldNm, 0, ADS NULL, 0);
                             END;

                  END;

         UNTIL (fValid);

   IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
      THEN
      ELSE
         REPEAT
            FieldNm := 'DFormat';
            Read_The_FieldC(ADS LineForm, FieldNm, 0, DFormat,
                            Upper(DataFile), ADS ExitState);
            IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
               THEN
                  fValid := TRUE
               ELSE BEGIN

                       fValid := Decode(DFormat, DataLen);

                       IF NOT (fValid)
                          THEN BEGIN
                                  Beep;
                                  Write_the_FieldC(ADS LineForm, FieldNm, 0, ADS NULL, 0);
                             END;

                  END;

         UNTIL (fValid);

   IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
      THEN
      ELSE
         REPEAT
            FieldNm := 'XFormat2';
            Read_The_FieldC(ADS LineForm, FieldNm, 0, XFormat2,
                            Upper(DataFile), ADS ExitState);
            IF (ExitState.ch = Finish) OR (ExitState.ch = Cancel)
               THEN
                  fValid := TRUE
               ELSE BEGIN

                       fValid := Decode(XFormat2, SpacesLen2);

                       IF NOT (fValid)
                          THEN BEGIN
                                  Beep;
                                  Write_the_FieldC(ADS LineForm, FieldNm, 0, ADS NULL, 0);
                             END
                          ELSE
                             CASE FormColumn OF

                                3 :  BEGIN

                                        FIndxX := 1;
                                        FIndxY := 1;
                                        ixValues := 1;
                                        iyValues := 1;
                                        FormRow := FIndxX + 4;

                                        pDataValue := Header[iNames];
                                        J := 1;
                                        REPEAT
                                           SpaceErc := ReadBsRecord(ADS BSWA, ADS Spaces[1],
                                                       SpacesLen1, ADS cbRead);
                                           Erc := ReadBsRecord(ADS BSWA,
                                                  ADS Values[1],
                                                  DataLen, ADS cbRead);
                                           Values.Len := cbRead;
                                           Ok := Decode(Values,pDataValue^.xValue);
                                           SpaceErc := ReadBsRecord(ADS BSWA, ADS Spaces[1],
                                                       SpacesLen2, ADS cbRead);
                                           J := J + 1;
                                           pDataValue := pDataValue^.NxtPtr;
                                        UNTIL (Erc <> 0) OR (J > ORD(cCoords[iNames])) OR
                                              (NOT Ok);

                                        FOR J := 1 TO 12 DO
                                           CheckErc(DefaultField(ADS LineForm,
                                                    ADS FldName[J+4,1],
                                                    FldName[J+4].Len, 3));

                                        pDataValue := Header[iNames];
                                        FOR J := 1 TO IMin(Ord(cCoords[iNames]), 12) DO
                                           BEGIN
                                              Ok := Encode(Values,pDataValue^.xValue:10:2);
                                              Write_the_FieldC(ADS LineForm, FldName[J+4],
                                                               3,ADS Values[1],
                                                               Values.Len);
                                              pDataValue := pDataValue^.NxtPtr;
                                           END;

                                        DataPtr := Header[iNames];

                                     END;

                                4 :  BEGIN

                                        FIndxX := 1;
                                        FIndxY := 1;
                                        ixValues := 1;
                                        iyValues := 1;
                                        FormRow := FIndxY + 4;

                                        pDataValue := Header[iNames];
                                        J := 1;
                                        REPEAT
                                           SpaceErc := ReadBsRecord(ADS BSWA, ADS Spaces[1],
                                                       SpacesLen1, ADS cbRead);
                                           Erc := ReadBsRecord(ADS BSWA,
                                                  ADS Values[1],
                                                  DataLen, ADS cbRead);
                                           Values.Len := cbRead;
                                           Ok := Decode(Values,pDataValue^.yValue);
                                           SpaceErc := ReadBsRecord(ADS BSWA, ADS Spaces[1],
                                                       SpacesLen2, ADS cbRead);
                                           J := J + 1;
                                           pDataValue := pDataValue^.NxtPtr;
                                        UNTIL (Erc <> 0) OR (J > ORD(cCoords[iNames])) OR
                                              (NOT Ok);

                                        FOR J := 1 TO 12 DO
                                           CheckErc(DefaultField(ADS LineForm,
                                                    ADS FldName[J+4,1],
                                                    FldName[J+4].Len,
                                                    4));

                                        pDataValue := Header[iNames];
                                        FOR J := 1 TO IMin(Ord(cCoords[iNames]), 12) DO
                                           BEGIN
                                              Ok := Encode(Values,pDataValue^.yValue:10:2);
                                              Write_the_FieldC(ADS LineForm, FldName[J+4],
                                                               4,ADS Values[1],
                                                               Values.Len);
                                              pDataValue := pDataValue^.NxtPtr;
                                           END;

                                        DataPtr := Header[iNames];

                                     END;

                             OTHERWISE ;

                             END; { CASE }

                  END;

         UNTIL (fValid);

   Erc := CloseByteStream(ADS BSWA);

   ReadASCIIData := ExitState.ch;

END; { ReadASCIIData Function }

{
 Read the data file and load the data 
 into the appropriate variables.      
}

PROCEDURE GetLineData(VARS DataFile : LSFileSpec);

BEGIN
   CheckErc(OpenDataFile(DataFile,ModeRead,False));

   CheckErc(ReadDataFile(ADS ChartType,2,ADS cbRead));
   CheckErc(ReadDataFile(ADS Hdr[1], 16,ADS cbRead));
   CheckErc(ReadDataFile(ADS cLines,2,ADS cbRead));
   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         CheckErc(ReadDataFile(ADS cCoords[I], 2, ADS cbRead));
         MaxCoords[I] := cCoords[I];

         CheckErc(AllocMemorySL(SIZEOF(pDataValue^), ADS pDataValue));
         Header[I] := pDataValue;
         CheckErc(ReadDataFile(ADS pDataValue^.xValue, 4, ADS cbRead));
         FOR J := 2 TO Ord(cCoords[I]) DO
            BEGIN
               DataPtr := pDataValue;
               CheckErc(AllocMemorySL(SIZEOF(pDataValue^),
               ADS pDataValue));
               DataPtr^.NxtPtr := pDataValue;
               pDataValue^.PrevPtr := DataPtr;
               CheckErc(ReadDataFile(ADS pDataValue^.xValue,4,
                        ADS cbRead));
            END;

         pDataValue := Header[I];
         CheckErc(ReadDataFile(ADS pDataValue^.yValue, 4, ADS cbRead));
         FOR J := 2 TO Ord(cCoords[I]) DO
            BEGIN
               pDataValue := pDataValue^.NxtPtr;
               CheckErc(ReadDataFile(ADS pDataValue^.yValue, 4, ADS cbRead));
            END;
      END;

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS PicFile[1],Wrd(ByteRet),ADS cbread));
   PicFile.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS FmFile[1],Wrd(ByteRet),ADS cbread));
   FmFile.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS DataFile[1],Wrd(ByteRet),ADS cbread));
   DataFile.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS LineTitle[1],Wrd(ByteRet),ADS cbread));
   LineTitle.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS xLabel[1],Wrd(ByteRet),ADS cbread));
   xLabel.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS yLabel[1],Wrd(ByteRet),ADS cbread));
   yLabel.Len := Wrd(ByteRet);

   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         CheckErc(Read_A_Byte(ADS ByteRet));
         CheckErc(ReadDataFile(ADS LineName[I,1],Wrd(ByteRet),ADS cbread));
         LineName[I,0] := Chr(ByteRet);
      END;
   CloseDataFile;
END;

{
 Save data entered for this pie chart 
}

PROCEDURE SaveLineData(VARS DataFile : LSFileSpec);

BEGIN
   IF fGraph
      THEN
(**)
(*     If fGraph then check to see if file already exists    *)
(**)
         REPEAT
            cbRead := ULCMPB(ADS DataFile[Ord(DataFile.len3)], ADS '.dat',4);
            IF cbRead <> FFFF
               THEN ConCat(DataFile, '.Dat');
            Movesl(ADS DataFile[1],ADS PicFile[1],DataFile.Len4);
            PicFile.Len := DataFile.Len4;
         UNTIL OverWriteOk(DataFile)
      ELSE
         BEGIN
(**)
(* Used CODES, do not check for data file go ahead and save *)
(**)
            cbRead := ULCMPB(ADS DataFile[Ord(DataFile.len3)], ADS '.dat',4);
            IF cbRead <> FFFF
               THEN ConCat(DataFile, '.Dat');
            Movesl(ADS DataFile[1],ADS PicFile[1],DataFile.Len4);
            PicFile.Len := DataFile.Len4;
         END;

   CheckErc(OpenDataFile(DataFile,ModeWrite,fGraph));
(**)
(* Write BGP data file *)
(**)
   WriteDataFile(ADS LineCode,2);
   FOR I := 1 TO 8 DO
      Hdr[I] := FFFF;
   WriteDataFile(ADS Hdr[1],16);
   WriteDataFile(ADS cLines,2);
   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         WriteDataFile(ADS cCoords[I],2);

         pDataValue := Header[I];
         WriteDataFile(ADS pDataValue^.xValue,4);
         FOR J := 2 TO Ord(cCoords[I]) DO
            BEGIN
               pDataValue := pDataValue^.NxtPtr;
               WriteDataFile(ADS pDataValue^.xValue,4);
            END;

         pDataValue := Header[I];
         WriteDataFile(ADS pDataValue^.yValue,4);
         FOR J := 2 TO Ord(cCoords[I]) DO
            BEGIN
               pDataValue := pDataValue^.NxtPtr;
               WriteDataFile(ADS pDataValue^.yValue,4);
            END;
      END;

(**)
(* Append parameters passed to BGP via memory (VLPB) *)
(* to the end of the data file. This is done so that *)
(* all data for a given graph is located in one file *)
(* and can be easily recalled for Editing.           *)
(**)
   IF fGraph
      THEN ParamInit(2048,7);

   IF fGraph
      THEN ParamSetSimple(1,PicFile);
   WriteDataFile(ADS PicFile[0], PicFile.len+1);

   IF fGraph
      THEN ParamSetSimple(2,FmFile);
   WriteDataFile(ADS FmFile[0], FmFile.len+1);

   IF fGraph
      THEN ParamSetSimple(3,DataFile);
   WriteDataFile(ADS DataFile[0], DataFile.len+1);

   IF fGraph
      THEN ParamSetSimple(4,LineTitle);
   WriteDataFile(ADS LineTitle[0], LineTitle.len+1);

   IF fGraph
      THEN ParamSetSimple(5,xLabel);
   WriteDataFile(ADS xLabel[0], xLabel.len+1);

   IF fGraph
      THEN ParamSetSimple(6,yLabel);
   WriteDataFile(ADS yLabel[0], yLabel.len+1);

   IF fGraph
      THEN ParamListStart(7);
   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         IF fGraph
            THEN ParamSetNextInList(LineName[I]);
         WriteDataFile(ADS LineName[I].Len,LineName[I].Len+1);
      END;

   CloseDataFile;
END;

{
 1) Collects all the data from the LINEFORM necessary to graph     
    a Line chart.                                                  
 2) Chains to BGP.Run.                                             
                                                                   
 fEdit will be TRUE if the Edit Function key has been pressed  or  
 all form fields have been accessed. DataSpec will then contain    
 the file spec of the data file.                                   
                                                                   
 Fields on the form are accessed by:                               
        setting FormColumn >  for the COLUMN the field is in   
        setting FormRow >  for the ROW the field is in      
             FormColumn = 1  Column = 2  Column = 3  Column = 4    
                       
 FormRow = 1 Title                                                 
           2 X Axis Name                                           
           3 Y Axis Name                                           
           4  of Lines                                            
           5 LineName[1]     cCoords[1]  XVal[1]     YVal[1]       
           6 LineName[2]     cCoords[2]  XVal[2]     YVal[2]       
           7 LineName[3]     cCoords[3]  XVal[3]     YVal[3]       
           8 LineName[4]     cCoords[4]  XVal[4]     YVal[4]       
           9 LineName[5]     cCoords[5]  XVal[5]     YVal[5]       
          10                             XVal[6]     YVal[6]       
          11                             XVal[7]     YVal[7]       
          12                             XVal[8]     YVal[8]       
          13                             XVal[9]     YVal[9]       
          14                             XVal[10]    YVal[10]      
          15                             XVal[11]    YVal[11]      
          16                             XVal[12]    YVal[12]      
                                                                   
}

PROCEDURE Line_Chart(fEdit  : BOOLEAN;
                     DataSpec : LSFileSpec);

BEGIN
   DisplayFKeys;
   DisplayFunctionKey(10,'Return',0);
   fDone := False;
   fF2 := False;
   FormRow := 1;
   InitState[1] := 0;
   cLines := 0;
   iNames := 1;
   iCoords  := 1;
   DataPtr := Header[iNames];
   ixValues := 1;
   iyValues := 1;
   FIndxX := 1;
   FIndxY := 1;
   FormColumn := 1;
   FOR I := 1 TO 5 DO
      BEGIN
         cCoords[I] := 0;
         MaxCoords[I] := 0;
      END;
   CheckErc(DisplayForm(ADS LineForm, 0, 255,255));

   IF fEdit
      THEN
         BEGIN
(**)
(* Go read the data file and display the data into *)
(* the form.                                       *)
(**)
            GetLineData(DataSpec);
            Write_the_FieldC(ADS LineForm, FldName[1], 0,ADS LineTitle[1],
                             LineTitle.Len);
            Write_the_FieldC(ADS LineForm, FldName[2], 0,ADS xLabel[1],
                             xLabel.Len);
            Write_the_FieldC(ADS LineForm, FldName[3], 0,ADS yLabel[1],
                             yLabel.Len);
            Write_the_FieldB(ADS LineForm, FldName[4], 0, ADS cLines);
            FOR I := 1 TO Ord(cLines) DO
               BEGIN
                  Write_the_FieldC(ADS LineForm, FldName[I+4], 1,
                                   ADS LineName[I,1], LineName[I].Len);
                  Write_the_FieldB(ADS LineForm, FldName[I+4], 2,
                                   ADS cCoords[I]);
               END;

            pDataValue := Header[1];
            Write_the_FieldC(ADS LineForm, FldName[20], 0, ADS FmFile[1],
                             FmFile.Len);
         END
      ELSE
         BEGIN
(**)
(* Set up the default Format file to be used to    *)
(* create the graph and display it to the form.    *)
(**)
            IF Color_Hdw
               THEN FmFile := ColorFmt
               ELSE FmFile := MonoFmt;
            Write_the_FieldC(ADS LineForm, FldName[20], 0, ADS FmFile[1],
                             FmFile.Len);
         END;

   WHILE NOT(fDone) DO
      BEGIN
         IF fEdit
            THEN
               BEGIN
                  CheckErc(SetKbdLed(OverType,True));
                  DisplayFunctionKey(1,'Graph',4);
                  DisplayFunctionKey(2,'InFile',0);
                  DisplayFunctionKey(3,Fmt,5);
                  DisplayFunctionKey(4,'Names',0);
                  DisplayFunctionKey(5,'DatPts',0);
                  DisplayFunctionKey(6,'xValues',0);
                  DisplayFunctionKey(7,'yValues',0);
                  DisplayFunctionKey(8,Null,5);
                  DisplayFunctionKey(9,Null,5);
               END
            ELSE
               BEGIN
                  CheckErc(SetKbdLed(OverType,False));
                  DisplayFunctionKey(1,'Graph',0);
                  DisplayFunctionKey(3,Fmt,5);
                  DisplayFunctionKey(4,Null,0);
                  DisplayFunctionKey(5,Null,0);
                  DisplayFunctionKey(6,Null,0);
                  DisplayFunctionKey(7,Null,0);
                  DisplayFunctionKey(8,Null,5);
                  DisplayFunctionKey(9,Null,5)
               END;

         CASE FormColumn OF
(**)
(* If the FormRow is > 4 then the Title, XAxis   *)
(* name, YAxix name,  Number if Lines have been *)
(* entered.                                      *)
(*    FormColumn = 1 is the LineName column.     *)
(*    FormColumn = 2 is the Number of data       *)
(*                 points per LineName.          *)
(*    FormColumn = 3 is the X Value column.      *)
(*    FormColumn = 4 is the Y Value column.      *)
(*                                               *)
(* This Case statement writes the number of the  *)
(* Active LineName, Number of Data Points,       *)
(* X Value or the Y Value into the form, that is *)
(* currently being input.                        *)
(**)
            1 :  IF FormRow > 4
                    THEN
                       BEGIN
                          DisplayFunctionKey(4,'Names',0);
                          DisplayFunctionKey(5,'DatPts',0);
                          DisplayFunctionKey(6,'xValues',0);
                          DisplayFunctionKey(7,'yValues',0);
                          DisplayFunctionKey(8,Null,5);
                          DisplayFunctionKey(9,Null,5);
                          CheckErc(DefaultField(ADS LineForm,
                                   ADS FldName[17,1],FldName[17].Len,2));
                          CheckErc(DefaultField(ADS LineForm,
                                   ADS FldName[18,1],FldName[18].Len,0));
                          CheckErc(DefaultField(ADS LineForm,
                                   ADS FldName[19,1],FldName[19].Len,0));
                          Write_the_FieldB(ADS LineForm, FldName[17] ,1,
                                           ADS iNames);
(**)
(* Clear the X  Y values on the form for the *)
(* current line name.                         *)
(**)
                          FOR I := 1 TO 12 DO
                             BEGIN
                                CheckErc(DefaultField(ADS LineForm,
                                         ADS FldName[I+4,1],
                                         FldName[I+4].Len, 3));
                                CheckErc(DefaultField(ADS LineForm,
                                         ADS FldName[I+4,1],
                                         FldName[I+4].Len, 4));
                             END;
(**)
(* Display the X  Y values on the form for   *)
(* the current Line Name.                     *)
(**)
                          FIndxX := 1;
                          FIndxY := 1;
                          ixValues := 1;
                          iyValues := 1;
                          pDataValue := Header[iNames];
                          FOR I := 1 TO IMin(Ord(cCoords[iNames]), 12) DO
                             BEGIN
                                Ok := Encode(Values,pDataValue^.xValue:10:2);
                                Write_the_FieldC(ADS LineForm, FldName[I+4],
                                                 3,ADS Values[1], Values.Len);
                                Ok := Encode(Values,pDataValue^.yValue:10:2);
                                Write_the_FieldC(ADS LineForm, FldName[I+4],
                                                 4,ADS Values[1], Values.Len);
                                pDataValue := pDataValue^.NxtPtr;
                             END;
                       END;
            2 : BEGIN
                    DisplayFunctionKey(4,'Names',0);
                    DisplayFunctionKey(5,'DatPts',0);
                    DisplayFunctionKey(6,'xValues',0);
                    DisplayFunctionKey(7,'yValues',0);
                    DisplayFunctionKey(8,Null,5);
                    DisplayFunctionKey(9,Null,5);
                    CheckErc(SetFieldAttrs(ADS LineForm,
                             ADS FldName[iNames+4,1],FldName[iNames+4].Len,
                             1,0));
                    CheckErc(DefaultField(ADS LineForm,
                             ADS FldName[17,1],FldName[17].Len,1));
                    CheckErc(DefaultField(ADS LineForm,
                             ADS FldName[18,1],FldName[18].Len,0));
                    CheckErc(DefaultField(ADS LineForm,
                             ADS FldName[19,1],FldName[19].Len,1));
                    Write_the_FieldB(ADS LineForm, FldName[17] ,2, ADS iCoords)
                 END;
            3,4 : BEGIN
                      DisplayFunctionKey(2,'InFile',0);
                      DisplayFunctionKey(8,' Prev',4);
                      DisplayFunctionKey(9,' Next',4);
                      IF fF2
                         THEN BEGIN
                                 DisplayFunctionKey(6,'xValues',0);
                                 DisplayFunctionKey(7,'yValues',0);
                            END;
                      CheckErc(DefaultField(ADS LineForm, ADS FldName[17,1],
                               FldName[17].Len,1));
                      CheckErc(DefaultField(ADS LineForm, ADS FldName[17,1],
                               FldName[17].Len,2));
                      IF FormRow > 4
                         THEN CheckErc(SetFieldAttrs(ADS LineForm,
                                       ADS FldName[iNames+4,1],FldName[iNames+4].Len, 1,5));
                      IF (FormRow = 5) AND (ixValues = 1) AND (iyValues = 1)
                         THEN
                            BEGIN
                               FOR I := 1 TO 12 DO
                                  BEGIN
                                     CheckErc(DefaultField(ADS LineForm, ADS FldName[I+4,1],FldName[I+4].Len, 3));
                                     CheckErc(DefaultField(ADS LineForm,ADS FldName[I+4,1],FldName[I+4].Len, 4))
                                  END;

                               FIndxX := 1;
                               FIndxY := 1;
                               pDataValue := Header[iNames];
                               FOR I := 1 TO IMin(Ord(cCoords[iNames]), 12) DO
                                  BEGIN
                                     Ok := Encode(Values,
                                           pDataValue^.xValue:10:2);
                                     IF pDataValue^.xValue <> 0 OR ELSE fEdit
                                        THEN
                                           Write_the_FieldC(ADS LineForm,
                                                            FldName[I+4],
                                                            3,ADS Values[1],
                                                            Values.Len);
                                     Ok := Encode(Values,
                                           pDataValue^.yValue:10:2);
                                     IF pDataValue^.yValue <> 0 OR ELSE fEdit
                                        THEN
                                           Write_the_FieldC(ADS LineForm,
                                                            FldName[I+4],
                                                            4,ADS Values[1],
                                                            Values.Len);
                                     pDataValue := pDataValue^.NxtPtr;
                                  END;
                            END;
                      IF FormColumn = 3
                         THEN
                            BEGIN
                               CheckErc(DefaultField(ADS LineForm,
                                        ADS FldName[19,1],FldName[19].Len,0));
                               Write_the_FieldB(ADS LineForm, FldName[18] ,1,
                                                ADS ixValues)
                            END
                         ELSE
                            BEGIN
                               CheckErc(DefaultField(ADS LineForm,
                                        ADS FldName[18,1],FldName[18].Len,0));
                               Write_the_FieldB(ADS LineForm, FldName[19] ,1,
                                                ADS iyValues)
                            END;
                      IF FormRow = 4
                         THEN
                            BEGIN
                               CheckErc(SetFieldAttrs(ADS LineForm,
                                        ADS FldName[iNames+4,1],FldName[iNames+4].Len, 1,0));
                               DisplayFunctionKey(8,Null,5);
                               DisplayFunctionKey(9,Null,5)
                            END;

                   END;
         OTHERWISE ;
         END;

         Ok := FALSE;
         WHILE NOT(Ok) DO
            BEGIN
(**)
(* Ok will be set to TRUE if the data entered for *)
(* the form field is appropriate for that field.  *)
(* Data read from the field in the form is        *)
(* returned in the LString DataRet.               *)
(**)

               Read_The_FieldC(ADS LineForm, FldName[FormRow], Wrd(FormColumn), DataRet, Upper(DataRet), ADS ExitState);
               WriteStatusLine(ADS LineForm, Null, 0, False);

(**)
(* Based on which Row and Column is active on  *)
(* the form this case statement knows what data*)
(* is being input and does the appropriate     *)
(* checks and places the entered data in the   *)
(* appropriate variable.                       *)
(**)
               CASE FormRow OF
(**)
(* Based on which Row and Column is active on  *)
(* the form this case statement knows what data*)
(* is being input and does the appropriate     *)
(* checks and places the entered data in the   *)
(* appropriate variable.                       *)
(**)
                  1 : BEGIN
                          LineTitle := DataRet;
                          RemoveBlanks(LineTitle,DataSpec);
                          IF DataSpec.Len = 0
                             THEN Ok := False
                             ELSE
                                BEGIN
                                   Ok := True;
                                   FormColumn := 1;
                                   iNames := 1;
                                   iCoords := 1;
                                   DataPtr := Header[iNames];
                                   FIndxX := 1;
                                   FIndxY := 1;
                                   ixValues := 1;
                                   iyValues := 1
                                END;
                          CASE ExitState.ch OF
                             F2, F10, Finish, Cancel :  Ok := True;
                          OTHERWISE ;
                          END;
                          IF NOT(OK)
                             THEN
                                BEGIN
                                   Beep;
                                   WriteStatusLine(ADS LineForm, 'An entry is required', 0,False)
                                END
                       END;
                  2 : BEGIN
                          xLabel := DataRet;
                          FormColumn := 1;
                          Ok := True
                       END;
                  3 : BEGIN
                          yLabel := DataRet;
                          FormColumn := 1;
                          Ok := True
                       END;
                  4 : BEGIN
                          FormColumn := 1;
                          RemoveBlanks(DataRet,DataRet);
                          Ok := Decode(DataRet,cLines);
                          IF (cLines <= 0) OR (cLines > 5)
                             THEN Ok := False;
                          CASE ExitState.ch OF
                             F2, F10, Finish, Cancel, UpArrow :  Ok := True;
                          OTHERWISE ;
                          END;
                          IF NOT(OK)
                             THEN
                                BEGIN
                                   Beep;
                                   WriteStatusLine(ADS LineForm,'Valid entries are 1  5.', 0,False)
                                END
                       END;
               OTHERWISE
                  BEGIN
                     CASE FormColumn OF
                        1 : BEGIN
                                LineName[iNames] := DataRet;
                                Ok := True
                             END;
                        2 : BEGIN
                                RemoveBlanks(DataRet,DataRet);
                                Ok := Decode(DataRet,cCoords[iCoords]);
                                IF (cCoords[iCoords] <= 0)
                                   THEN Ok := False
                                   ELSE IF (MaxCoords[iCoords] <
                                           cCoords[iCoords])
                                           THEN BEGIN

                                                   IF (MaxCoords[iCoords] > 0)
                                                      THEN
                                                         BEGIN
                                                            pDataValue := Header[iCoords];
                                                            FOR I := 2 TO
                                                                ORD(MaxCoords[iCoords]) DO
                                                               pDataValue := pDataValue^.NxtPtr;
                                                         END;
                                                   FOR I := ORD(MaxCoords[iCoords]+1) TO
                                                       ORD(cCoords[iCoords]) DO
                                                      BEGIN
                                                         CheckErc(AllocMemorySL(
                                                                  SIZEOF(pNewData^),
                                                         ADS pNewData));
                                                         pNewData^.xValue := 0.0;
                                                         pNewData^.yValue := 0.0;
                                                         IF (I = 1)
                                                            THEN BEGIN
                                                                    Header[iCoords] := pNewData;
                                                                    DataPtr := Header[iNames];
                                                               END
                                                            ELSE BEGIN
                                                                    pDataValue^.NxtPtr := pNewData;
                                                                    pNewData^.PrevPtr := pDataValue;
                                                               END;
                                                         pDataValue := pNewData;
                                                      END;

                                                   MaxCoords[iCoords] := cCoords[iCoords];

                                              END;
                                CASE ExitState.ch OF
                                   F2, F10, Finish, Cancel, UpArrow :  Ok := True;
                                OTHERWISE ;
                                END;
                                IF NOT(OK)
                                   THEN
                                      BEGIN
                                         Beep;
                                         WriteStatusLine(ADS LineForm,'Valid entries are 1  12.', 0,False)
                                      END
                             END;
                        3 : BEGIN
                                RemoveBlanks(DataRet,DataRet);
                                Ok := Decode(DataRet,DataPtr^.xValue);
                                CASE ExitState.ch OF
                                   F2, F10, Finish, Cancel, UpArrow :  Ok := True;
                                OTHERWISE ;
                                END;
                                IF NOT(OK)
                                   THEN
                                      BEGIN
                                         Beep;
                                         WriteStatusLine(ADS LineForm,
                                                         'A Number is required', 0,False)
                                      END
                             END;
                        4 : BEGIN
                                RemoveBlanks(DataRet,DataRet);
                                Ok := Decode(DataRet,DataPtr^.yValue);
                                CASE ExitState.ch OF
                                   F2, F10, Finish, Cancel, UpArrow :  Ok := True;
                                OTHERWISE ;
                                END;
                                IF NOT(OK)
                                   THEN
                                      BEGIN
                                         Beep;
                                         WriteStatusLine(ADS LineForm,'A Number is required', 0,False)
                                      END
                             END;
                     OTHERWISE ;
                     END
                  END;{Case of FormColumn}
               END;{Case of FormRow}
            END; {While Not(Ok)}

         CASE ExitState.ch OF
(**)
(* This case statement checks the value of *)
(* the keyboard key used to terminate the  *)
(* current form field.                     *)
(**)
            CodeS,
            Code_s   :  IF DataSpec.Len <> 0
                           THEN
                              BEGIN
                                 WriteStatusLine(ADS LineForm, Saving, 0, False);
                                 SaveLineData(DataSpec);
                                 WriteStatusLine(ADS LineForm, SaveCmplt, 0, False)
                              END;
            F1,Go    :  IF fEdit
                           THEN
                              BEGIN
                                 fDone := TRUE;
                                 fGraph := TRUE
                              END;
            F10      : BEGIN
                           fDone := True;
                           fGraph := FALSE
                        END;
            Finish   :  ConfirmFinish;
            Cancel   :  WriteStatusLine(ADS LineForm, Null, 0, False);
            F2       :  IF (FormColumn > 2)
                           THEN BEGIN
                                   ExitKey := ReadASCIIData;
                                   IF (ExitKey = Finish)
                                      THEN
                                         ConfirmFinish;
                                   fF2 := True;
                                   IF (iNames = Ord(cLines))
                                      AND (FormRow > 4) AND (FormColumn = 4)
                                      THEN
                                         fEdit := True;
                              END;
            F3       :  Read_The_FieldC(ADS LineForm, FldName[20], 0, FmFile,Upper(FmFile), ADS ExitState);
            F4       :  IF fEdit OR ELSE (cLines > 0)
                           THEN [FormColumn := 1;
            FormRow := iNames+4];
            F5       :  IF fEdit OR ELSE (cLines > 0)
                           THEN [FormColumn := 2;
            FormRow := iCoords+4];
            F6       :  IF fEdit OR ELSE (cLines > 0)
                           THEN [FormColumn := 3;
            IF FIndxX > ORD(cCoords[iNames])
               THEN BEGIN
                       FIndxX := ORD(cCoords[iNames]);
                       ixValues := ORD(cCoords[iNames]);
                  END;
            DataPtr := Header[iNames];
            FOR J := 2 TO ixValues DO
               DataPtr := DataPtr^.NxtPtr;
            FormRow := FIndxX+4];
            F7       :  IF fEdit OR ELSE (cLines > 0)
                           THEN [FormColumn := 4;
            IF FIndxY > ORD(cCoords[iNames])
               THEN BEGIN
                       FIndxY := ORD(cCoords[iNames]);
                       iyValues := ORD(cCoords[iNames]);
                  END;
            DataPtr := Header[iNames];
            FOR J := 2 TO iyValues DO
               DataPtr := DataPtr^.NxtPtr;
            FormRow := FIndxY+4];
            F8,PrevPage :  IF (FormRow > 4) AND
                              THEN ((FormColumn =3) OR (FormColumn = 4))
                                 THEN
                                    BEGIN
                                       CheckErc(SetFieldAttrs(ADS LineForm,ADS FldName[iNames+4,1], FldName[iNames+4].Len,1,0));
                                       FormRow := 5;
                                       FIndxX := FormRow4;
                                       FIndxY := FormRow4;
                                       ixValues := FormRow4;
                                       iyValues := FormRow4;
                                       IF iNames <> 1
                                          THEN iNames := iNames1;
                                       DataPtr := Header[iNames];
                                    END;
            F9,NextPage :  IF (FormRow > 4) AND
                              THEN ((FormColumn =3) OR (FormColumn = 4))
                                 THEN
                                    BEGIN
                                       CheckErc(SetFieldAttrs(ADS LineForm,ADS FldName[iNames+4,1],FldName[iNames+4].Len,1,0));
                                       FormRow := 5;
                                       FIndxX := FormRow4;
                                       FIndxY := FormRow4;
                                       ixValues := FormRow4;
                                       iyValues := FormRow4;
                                       IF iNames <> Ord(cLines)
                                          THEN iNames := iNames+1;
                                       DataPtr := Header[iNames];
                                    END;
            UpArrow   :  IF FormRow = 1
                            THEN  DO Nothing
                            ELSE
                               BEGIN
                                  FormRow := FormRow 1;
                                  IF FormRow > 4
                                     THEN
                                        BEGIN
                                           CASE FormColumn OF
                                              1 :  [iNames   := FormRow4;
                                              DataPtr := Header[iNames];
                                              ];
                                              2 :  iCoords  := FormRow4;
                                              3 :  [FIndxX := FormRow4;
                                              ixValues := ixValues  1;
                                              DataPtr := DataPtr^.PrevPtr;
                                              ];
                                              4 :  [FIndxY := FormRow4;
                                              iyValues := iyValues  1;
                                              DataPtr := DataPtr^.PrevPtr;
                                              ];
                                           OTHERWISE ;
                                           END;
                                        END
                               END;
            DownArrow : BEGIN
                            CASE FormRow OF
                               1 :  FormRow := 2;
                               2 :  FormRow := 3;
                               3 :  FormRow := 4;
                               4 :  FormRow := 5;
                               5..17 :
                                        BEGIN
                                           CASE FormColumn OF
                                              1 :  IF iNames = Ord(cLines)
                                                      THEN
                                                         BEGIN
                                                            FormRow := 5;
                                                            iNames := FormRow4;
                                                            DataPtr := Header[iNames];
                                                         END
                                                      ELSE
                                                         BEGIN
                                                            FormRow  := FormRow +1;
                                                            iNames := FormRow4;
                                                            DataPtr := Header[iNames];
                                                         END;
                                              2 :  IF iCoords = Ord(cLines)
                                                      THEN
                                                         BEGIN
                                                            FormRow := 5;
                                                            iCoords := FormRow4
                                                         END
                                                      ELSE
                                                         BEGIN
                                                            FormRow := FormRow +1;
                                                            iCoords := FormRow4
                                                         END;
                                              3 :  IF (ixValues = Ord(cCoords[iNames])) OR
                                                      (FIndxX = 12)
                                                      THEN
                                                         BEGIN
                                                            FormRow := 5;
                                                            ixValues := ixValues  FIndxX + 1;
                                                            FOR I := 1 TO (FIndxX1) DO
                                                               DataPtr := DataPtr^.PrevPtr;
                                                            FIndxX := FormRow4;
                                                         END
                                                      ELSE [FormRow := FormRow +1;
                                              ixValues := ixValues+1;
                                              FIndxX := FormRow4;
                                              DataPtr := DataPtr^.NxtPtr];
                                              4 :  IF (iyValues= Ord(cCoords[iNames])) OR
                                                      (FIndxY = 12)
                                                      THEN
                                                         BEGIN
                                                            FormRow := 5;
                                                            iyValues := iyValues  FIndxY + 1;
                                                            FOR I := 1 TO (FIndxY1) DO
                                                               DataPtr := DataPtr^.PrevPtr;
                                                            FIndxY := FormRow4;
                                                         END
                                                      ELSE
                                                         BEGIN
                                                            FormRow := FormRow +1;
                                                            iyValues := iyValues+1;
                                                            FIndxY := FormRow4;
                                                            DataPtr := DataPtr^.NxtPtr
                                                         END;
                                           OTHERWISE ;
                                           END
                                        END;
                            OTHERWISE ;
                            END
                         END;
            UScroll  :  BEGIN
                           CASE FormRow OF
                              1 :  FormRow := 2;
                              2 :  FormRow := 3;
                              3 :  FormRow := 4;
                              4 :  FormRow := 5;
                              5..17 :  CASE FormColumn OF
                                          3 :  BEGIN
                                                  IF ((ixValues  FIndxX + 2) <= ORD(cCoords[iNames]))
                                                     THEN
                                                        BEGIN
                                                           pDataValue := DataPtr;
                                                           Indx := ixValues  FIndxX + 2;
                                                           FOR I := (ixValues+1) TO Indx DO
                                                              pDataValue := pDataValue^.NxtPtr;
                                                           FOR I := (ixValues1) DOWNTO Indx DO
                                                              pDataValue := pDataValue^.PrevPtr;
                                                           ixValues := ixValues + 1;
                                                           DataPtr := DataPtr^.NxtPtr;
                                                           I := 1;
                                                        END
                                                     ELSE
                                                        I := 100;

                                                  WHILE (I <= 12) DO
                                                     BEGIN
                                                        IF (Indx <= ORD(cCoords[iNames]))
                                                           THEN BEGIN
                                                                   Ok := Encode(Values,pDataValue^.xValue:10:2);
                                                                   Write_the_FieldC(ADS LineForm, FldName[I+4], 3,ADS Values[1],
                                                                                    Values.Len);
                                                                   IF (Indx = ORD(cCoords[iNames]))
                                                                      AND (FIndxX > I)
                                                                      THEN BEGIN
                                                                              FIndxX := I;
                                                                              ixValues := ORD(cCoords[iNames]);
                                                                              FormRow := FormRow1;
                                                                              DataPtr := pDataValue;
                                                                         END;
                                                                   pDataValue := pDataValue^.NxtPtr;
                                                              END
                                                           ELSE
                                                              CheckErc(DefaultField(ADS LineForm,
                                                                       ADS FldName[I+4,1],
                                                                       FldName[I+4].Len, 3));

                                                        I := I + 1;
                                                        Indx := Indx + 1;
                                                     END;
                                               END;
                                          4 :  BEGIN
                                                  IF ((iyValues  FIndxY + 2) <= ORD(cCoords[iNames]))
                                                     THEN
                                                        BEGIN
                                                           pDataValue := DataPtr;
                                                           Indx := iyValues  FIndxY + 2;
                                                           FOR I := (iyValues+1) TO Indx DO
                                                              pDataValue := pDataValue^.NxtPtr;
                                                           FOR I := (iyValues1) DOWNTO Indx DO
                                                              pDataValue := pDataValue^.PrevPtr;
                                                           iyValues := iyValues + 1;
                                                           DataPtr := DataPtr^.NxtPtr;
                                                           I := 1;
                                                        END
                                                     ELSE
                                                        I := 100;

                                                  WHILE (I <= 12) DO
                                                     BEGIN
                                                        IF (Indx <= ORD(cCoords[iNames]))
                                                           THEN BEGIN
                                                                   Ok := Encode(Values,pDataValue^.yValue:10:2);
                                                                   Write_the_FieldC(ADS LineForm, FldName[I+4], 4,ADS Values[1],
                                                                                    Values.Len);
                                                                   IF (Indx = ORD(cCoords[iNames]))
                                                                      AND (FIndxY > I)
                                                                      THEN BEGIN
                                                                              FIndxY := I;
                                                                              iyValues := ORD(cCoords[iNames]);
                                                                              FormRow := FormRow1;
                                                                              DataPtr := pDataValue;
                                                                         END;
                                                                   pDataValue := pDataValue^.NxtPtr;
                                                              END
                                                           ELSE
                                                              CheckErc(DefaultField(ADS LineForm,
                                                                       ADS FldName[I+4,1],
                                                                       FldName[I+4].Len, 4));

                                                        I := I + 1;
                                                        Indx := Indx + 1;
                                                     END;
                                               END;
                                       OTHERWISE ;
                                       END

                              OTHERWISE ;
                              END
                        END;
            DScroll  :  BEGIN
                           CASE FormRow OF
                              1 :  FormRow := 2;
                              2 :  FormRow := 3;
                              3 :  FormRow := 4;
                              4 :  FormRow := 5;
                              5..17 :  CASE FormColumn OF
                                          3 :  BEGIN
                                                  IF ((ixValues  FIndxX) > 0)
                                                     THEN
                                                        BEGIN
                                                           pDataValue := DataPtr;
                                                           Indx := ixValues  FIndxX;
                                                           FOR I := (ixValues1) DOWNTO Indx DO
                                                              pDataValue := pDataValue^.PrevPtr;
                                                           ixValues := ixValues  1;
                                                           DataPtr := DataPtr^.PrevPtr;
                                                           I := 1;
                                                        END
                                                     ELSE
                                                        I := 100;

                                                  WHILE (I <= 12) DO
                                                     BEGIN
                                                        IF (Indx <= ORD(cCoords[iNames]))
                                                           THEN BEGIN
                                                                   Ok := Encode(Values,pDataValue^.xValue:10:2);
                                                                   Write_the_FieldC(ADS LineForm, FldName[I+4], 3,ADS Values[1],
                                                                                    Values.Len);
(*
IF (Indx = ORD(cCoords[iNames]))
AND (FIndxX > I) THEN BEGIN
FIndxX := I;
ixValues := ORD(cCoords[iNames]);
FormRow := FormRow1;
DataPtr := pDataValue;
END;
*)
                                                                   pDataValue := pDataValue^.NxtPtr;
                                                              END
                                                           ELSE
                                                              CheckErc(DefaultField(ADS LineForm,
                                                                       ADS FldName[I+4,1],
                                                                       FldName[I+4].Len, 3));

                                                        I := I + 1;
                                                        Indx := Indx + 1;
                                                     END;
                                               END;
                                          4 :  BEGIN
                                                  IF ((iyValues  FindxY) > 0)
                                                     THEN
                                                        BEGIN
                                                           pDataValue := DataPtr;
                                                           Indx := iyValues  FindxY;
                                                           FOR I := (iyValues1) DOWNTO Indx DO
                                                              pDataValue := pDataValue^.PrevPtr;
                                                           iyValues := iyValues  1;
                                                           DataPtr := DataPtr^.PrevPtr;
                                                           I := 1;
                                                        END
                                                     ELSE
                                                        I := 100;

                                                  WHILE (I <= 12) DO
                                                     BEGIN
                                                        IF (Indx <= ORD(cCoords[iNames]))
                                                           THEN BEGIN
                                                                   Ok := Encode(Values,pDataValue^.xValue:10:2);
                                                                   Write_the_FieldC(ADS LineForm, FldName[I+4], 4,ADS Values[1],
                                                                                    Values.Len);
(*
IF (Indx = ORD(cCoords[iNames]))
AND (FindxY > I) THEN BEGIN
FindxY := I;
iyValues := ORD(cCoords[iNames]);
FormRow := FormRow1;
DataPtr := pDataValue;
END;
*)
                                                                   pDataValue := pDataValue^.NxtPtr;
                                                              END
                                                           ELSE
                                                              CheckErc(DefaultField(ADS LineForm,
                                                                       ADS FldName[I+4,1],
                                                                       FldName[I+4].Len, 4));

                                                        I := I + 1;
                                                        Indx := Indx + 1;
                                                     END;
                                               END;
                                       OTHERWISE ;
                                       END

                              OTHERWISE ;
                              END
                        END;
         OTHERWISE
            BEGIN
               CASE FormRow OF
                  1 :  FormRow := 2;
                  2 :  FormRow := 3;
                  3 :  FormRow := 4;
                  4 :  FormRow := 5;
                  5..17 :
                           BEGIN
                              CASE FormColumn OF
                                 1 :  IF iNames = Ord(cLines)
                                         THEN
                                            BEGIN
                                               FormRow := 5;
                                               iNames := FormRow4;
                                               DataPtr := Header[iNames];
                                               iCoords := 1;
                                               FormColumn := 2
                                            END
                                         ELSE
                                            BEGIN
                                               FormRow := FormRow +1;
                                               iNames := FormRow4;
                                               DataPtr := Header[iNames];
                                            END;
                                 2 :  IF iCoords = Ord(cLines)
                                         THEN
                                            BEGIN
                                               iCoords := 1;
                                               FIndxX := 1;
                                               FIndxY := 1;
                                               ixValues := 1;
                                               iyValues := 1;
                                               FormRow := 5;
                                               FormColumn := 3
                                            END
                                         ELSE
                                            BEGIN
                                               iCoords := iCoords + 1;
                                               FormRow := FormRow +1
                                            END;
                                 3 :
                                      BEGIN
                                         IF (ixValues = Ord(cCoords[iNames]))
                                            THEN BEGIN
                                                    FIndxX := 1;
                                                    FIndxY := 1;
                                                    ixValues := 1;
                                                    iyValues := 1;
                                                    DataPtr := Header[iNames];
                                                    FormRow := 5;
                                                    FormColumn := 4
                                               END
                                            ELSE BEGIN
                                                    IF (FIndxX = 12)
                                                       THEN BEGIN
                                                               pDataValue := DataPtr;
                                                               Indx := ixValues  FIndxX + 2;
                                                               FOR I := (ixValues1) DOWNTO Indx DO
                                                                  pDataValue := pDataValue^.PrevPtr;
                                                               ixValues := ixValues + 1;
                                                               DataPtr := DataPtr^.NxtPtr;
                                                               I := 1;

                                                               WHILE (I <= 12) DO
                                                                  BEGIN
                                                                     Ok := Encode(Values,pDataValue^.xValue:10:2);
                                                                     Write_the_FieldC(ADS LineForm, FldName[I+4], 3,ADS Values[1],
                                                                                      Values.Len);
                                                                     pDataValue := pDataValue^.NxtPtr;
                                                                     I := I + 1;
                                                                  END
                                                          END
                                                       ELSE BEGIN
                                                               FIndxX := FIndxX +1;
                                                               ixValues := ixValues +1;
                                                               DataPtr := DataPtr^.NxtPtr;
                                                               FormRow := FormRow +1
                                                          END
                                               END
                                      END;
                                 4 :
                                      IF iNames = Ord(cLines) AND
                                         THEN
                                            (iyValues = Ord(cCoords[iNames])) THEN
                                                                                 BEGIN

                                                                                    CheckErc(SetFieldAttrs(ADS LineForm, ADS FldName
                                                                                             [iNames+4,1],
                                                                                             FldName[iNames+4].Len, 1,0));
                                                                                    FormRow := 1;
                                                                                    fEdit := TRUE;
                                                                                    FormColumn := 1
                                                                                 END
                                            ELSE BEGIN
                                                    IF (iyValues= Ord(cCoords[iNames]))
                                                       THEN BEGIN
                                                               CheckErc(SetFieldAttrs(ADS LineForm,
                                                                        ADS FldName[iNames+4,1],
                                                                        FldName[iNames+4].Len, 1, 0));
                                                               iNames := iNames +1;
                                                               DataPtr := Header[iNames];
                                                               FormRow := 5;
                                                               FormColumn := 3;
                                                               fF2 := False;
                                                               FIndxX := 1;
                                                               FIndxY := 1;
                                                               ixValues := 1;
                                                               iyValues := 1
                                                          END
                                                       ELSE BEGIN
                                                               IF (FIndxY = 12)
                                                                  THEN BEGIN
                                                                          pDataValue := DataPtr;
                                                                          Indx := iyValues  FIndxY + 2;
                                                                          FOR I := (iyValues1) DOWNTO Indx DO
                                                                             pDataValue := pDataValue^.PrevPtr;
                                                                          iyValues := iyValues + 1;
                                                                          DataPtr := DataPtr^.NxtPtr;
                                                                          I := 1;

                                                                          WHILE (I <= 12) DO
                                                                             BEGIN
                                                                                Ok := Encode(Values,pDataValue^.yValue:10:2);
                                                                                Write_the_FieldC(ADS LineForm, FldName[I+4], 4,ADS
                                                                                                 Values[1], Values.Len);
                                                                                pDataValue := pDataValue^.NxtPtr;
                                                                                I := I + 1;
                                                                             END
                                                                     END
                                                                  ELSE BEGIN
                                                                          FIndxY := FIndxY + 1;
                                                                          iyValues := iyValues + 1;
                                                                          DataPtr := DataPtr^.NxtPtr;
                                                                          FormRow := FormRow +1
                                                                     END
                                                          END
                                               END;

                              OTHERWISE ;
                              END {Case of FormColumn}

                           END;
               OTHERWISE ;
               END {Case of FormRow}
            END;
         END;{Case of ExitState.ch}

(**)
(* Check that all required fields have been entered, *)
(* if not, set the form row  column to where the    *)
(* entry is in error and activate that field.        *)
(**)
         IF (fDone AND fGraph)
            THEN
               FOR I := Ord(cLines) DOWNTO 1 DO
                  IF LineName[I].Len = 0
                     THEN
                        BEGIN
                           Beep;
                           WriteStatusLine(ADS LineForm, 'Invalid or missing entry',0,False);
                           iNames := I;
                           DataPtr := Header[iNames];
                           FormRow := iNames+4;
                           FormColumn := 1;
                           FIndxX := 1;
                           FIndxY := 1;
                           ixValues := 1;
                           iyValues := 1;
                           fDone := False
                        END;

      END; {While not(fDone}

   CheckErc(UnDisplayForm(ADS LineForm));

   IF fGraph
      THEN
         BEGIN
            SaveLineData(DataSpec);
            ZipBGP
         END;

END;{Procedure}
END.
 THEN BEGIN
                                                               CheckErc(SetFieldAttrs(ADS LineForm,
                                                                        ADS FldName[iNames+4,1],
                  