home *** CD-ROM | disk | FTP | other *** search
- {ARRAYDIF.PAS
- created: 05/09/85
- revised: 00/00/85
- Purpose: This program saves an array of data to a file, in DIF format
- Source: adapted from XtrtDif.Pas
- }
-
- program Array_To_Dif;
-
- type
- string14 = string[14];
- Anystring = string[255];
-
- const
- NRows = 6;
- NColumns = 3;
-
-
- var
- InFile,DiFFile : string14;
- Dot_Pos : integer;
- Extension : string[3];
- Prefix : string[11];
- Data : array[1..NColumns,1..NRows] of real;
-
-
- {*** Read Data file & load into Array}
- Procedure ReadData(FileName:String14);
- var
- irow,icol : integer;
- F1 : text;
-
- begin
- writeln('* OPENING Data File for Read: ',FileName);
- Assign(F1,FileName);
- Reset(F1);
- for irow := 1 to NRows do begin
- for icol := 1 to NColumns do begin
- Read(F1,Data[icol,irow]);
- writeln(irow:8,icol:8,Data[icol,irow]:12:8);
-
- end; {icol}
- end; {irow}
- Close(F1);
-
- end; {ReadData}
-
-
-
- {*** SAVEDIF converts to DIF format
- Source: XtrtDif.Pas program }
-
- procedure SaveDif(FileName:string14);
- var
- F2: text;
- irow,icol: integer;
- st : anystring;
- NVector,NTuple : integer;
- SNVector, SNTuple : anystring;
- value : real;
-
- const
- DblQuote = #34#34;
-
- begin
- NVector := NColumns; {vector = column}
- NTuple := NRows; {tuple = row}
-
- Str(NVector,SNVector); {convert to string}
- Str(NTuple,SNTuple);
-
- write('* OPENING DIF FILE for Write: ',FileName);
- Assign(F2,FileName);
- Rewrite(F2);
-
- writeln; writeln('* SAVING DIF File: ');
-
- writeln(F2,'TABLE');
- writeln(F2,'0,1');
- writeln(F2,DblQuote);
- writeln(F2,'VECTORS');
- writeln(F2,'0,'+SNVector);
- writeln(F2,DblQuote);
- writeln(F2,'TUPLES');
- writeln(F2,'0,'+SNTuple);
- writeln(F2,DblQuote);
- writeln(F2,'DATA');
- writeln(F2,'0,0');
- writeln(F2,DblQuote);
-
- for icol := 1 to NColumns do begin
- writeln(F2,'-1,0');
- writeln(F2,'BOT');
- for irow := 1 to NRows do begin
- Value := Data[icol,irow];
- writeln('VALUE= ',value);
- (* if value = 0 then begin
- writeln(F2,'1,0');
- writeln(F2,DblQuote);
- end {if Data=0 }
- else begin *)
- Str(value,St);
- writeln(F2,'0,'+ St);
- writeln(F2,'V');
- (* end; {if Data[] }*)
- end; {for irow}
- end; {for icol}
- writeln(F2,'-1,0');
- writeln(F2,'EOD');
- { writeln(F2,-1);}
-
- Close(F2);
- writeln('* DONE *');
-
- end; {SaveDIF}
-
-
-
- begin {*** MAIN PROGRAM ***}
-
- Write('Enter file with array elements listing: ');
- Readln(InFile);
- Dot_Pos := POS('.',InFile);
- Extension := COPY(InFile,1+Dot_Pos,LENGTH(InFile));
- Prefix := COPY(InFile,1,Dot_Pos-1);
- DIFFile := Prefix + '.DIF';
- Writeln('DIF File Name will be: ',DIFFile);
-
- ReadData(InFile);
- SaveDIF(DIFFile);
- end.