Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert .dta files into ascii-format

Status
Not open for further replies.

KristofM

Technical User
May 21, 2007
4
BE
Hello,

I have a customer who uses a TurboPascal program of 1994 to get readings out of a climate computer. The program creates logfiles with the daily information. These logfiles are stored as .dta files. I want to use these data in new programming language, and so I would like to convert the .dta files to the ascii-format. I do have the source code of the program.
Where should I look or what should I change or what can I use to get the files in -ascii format?

Thx!
 
You need to look at the old program that generates these dta files, figure out the format, then get a program that will write it to ASCII format (assuming these DTA files aren't already defined as "Text").

Or better yet, if your programming language can read the files themselves (which is highly likely), just translate the structures to the language you are using and read them.

And post back if you need any help beyond that.
 
Forgive me if you know loads of pascal; this bit is just in case you don't...

...and to find the place where the files are opened, look through all the units of the program (unless one of them has a helpful name like "filebits.pas") for instructions like:
assign(myfile, filename)
{$I-}
reset(myfile, 1)
{$I+}
....

If the variable "myfile" is of type text, then your .dta files are basically ascii (you could just look in notepad, too).
If they're not, then you'll need to look for the read and blockread instructions that collect the data, and look at the data-structures into which they're placed.

The worst-case scenario is that you'll find
blockread(myfile, dataspace^, 5623);
in which case 5623 bytes of random stuff are being read into an unhelpfully named bit of memory, and you'll have to track down all the pointer instructions used to extract bytes, words, floating point numbers and all the rest.

If you're really unlucky this program will use Turbo Pascal's own Real floating point type rather than single or double; TP's version is completely different to anything else on earth and you'd have to do some bit manipulations to convert it into anything useful to other languages.

If the worst comes to the worst, you can modify the original program to save in a more useful format.

 
Hello,

Thx guys for the reaction. Just fyi, I'm really a TurboPascal green.
I went trough the program, and found out that de data file I want to look at is a record in Pacal.

TYPE tabel=RECORD
compnaam: STRING[12];
compnr: BYTE;
diskstal: BOOLEAN;
aantalpreg: BYTE;
aantalaureg: BYTE;
pregnamen: ARRAY[1..12] OF STRING[12];
auregnamen: ARRAY[1..10] OF STRING[12];
configarray: ARRAY[0..36] OF INTEGER;
aantalpunten: STRING[12];
alarmarr: ARRAY[0..75] OF BYTE;
END;

VAR

filegegevens: FILE OF tabel;
recgegevens: tabel;

I was trying to get the information out, like follows, but I kept getting Run-Time errors...

BEGIN
ASSIGN(filegegevens,'c:\temp\data-log.dta');
{$I-} RESET(filegegevens) {$I+};
READ(filegegevens, recgegevens);
ASSIGN(PCname,recgegevens.compnaam);
writeln(PCname);
END.

It may be a very simple question, I'm sorry...
 
Hi

Code:
ASSIGN(PCname,recgegevens.compnaam); [gray]{ how is PCname declared ? }[/gray]
                        [gray]{ sure compnaam holds valid file name ? }[/gray]

[gray]{ here you have to open the file for writing }[/gray]

writeln(PCname); [gray]{ sure you want to write only an end-of-line ? }[/gray]

[gray]{ here you have to close the file }[/gray]

Feherke.
 
(Untested & no error control, assuming the entire data file is just the one record)
Code:
var
  filegegevens: FILE OF tabel;
  recgegevens: tabel;
  output_text: Text;
  i: integer;
begin
  ASSIGN(filegegevens,'c:\temp\data-log.dta');
{$I-}  RESET(filegegevens) {$I+};
  ASSIGN(output_text, 'c:\temp\data-log.txt');
  rewrite(output_text);
  read(filegegevens, recgegevens);
  with recgegevens do
    begin
      writeln(output_text, compnaam);
      writeln(output_text, compnr);
      writeln(output_text, diskstal);
      writeln(output_text, aantalpreg);
      writeln(output_text, aantalaureg);
      for i := 1 to 12 do
        writeln(output_text, pregnamen[i]);
      for i := 1 to 12 do
        writeln(output_text, auregnamen[i]);
      for i := 0 to 36 do
        writeln(output_text, configarray[i]);
      writeln(output_text, aantalpunten);                 
      for i := 0 to 75 do
        writeln(output_text, alarmarr[i]);
    end;
  close(filegegevens);
  close(output_text);
end.

Hope this helps.
 
Wow! Looks good...

The other thing you could do is read the .dta files directly in your new choice of language. Now you've found the data-structure it should be very straightforward. The only thing you need to know is that a pascal string is of bytes, and starts with one extra byte containing the size of the remainder of the string, and is not terminated in any way. A string[12] is therefore 13 bytes, with the first one containing the number of bytes occupied by characters. Boolean is a byte, and integer is a signed word.

 
To Glen9999,

Thx a lot! This works, I had the largest problem assigning it to a txt-file.
I suppose that, in case the data file contains more than one record (I have records of this kind), I can put the loop in something like

while(NOT(EOF(filegegevens))) DO
BEGIN
...
END;

Or is the pointing to the different records done differently?
And I can put the subsequent fields in of one record on one line of the .txt file using write instead of writeln
And append for each record?

Thank u again!

KristofM
 
reading is done sequentially, generally, so you can do as you described.

while not eof(input_file) do
begin
read(input_file, input_record);
write(output_file, output_record);
end;
 
Hi,

With the following code, i get an error when I run runtime error 2 at 0001.0056)...

VAR
gegevens: FILE OF datalogg;
recgegevens: datalogg;
output_text: Text;
output_rec: datalogg;
i: integer;

BEGIN
ASSIGN(gegevens,'c:\temp\log-data.dta');
{$I-} RESET(gegevens) {$I+};
ASSIGN(output_text,'c:\temp\test.txt');
rewrite(output_text);
while NOT(EOF(gegevens)) DO
BEGIN
read(gegevens, recgegevens);
with recgegevens DO
BEGIN
write(output_text, datum);
write(output_text, ',');
write(output_text, tijd);
write(output_text, ',');
for i := 0 to 99 do
write(output_text, logalarm);
write(output_text,',');
for i := 0 to 10 do
write(output_text, logreg,',');
write(output_text,',');
for i := 0 to 71 do
write(output_text, graf00);
writeln(output_text,',');
end;
write(gegevens, output_rec);
end;
writeln('De gegevens zijn naar de file geschreven');
close(gegevens);
close(output_text);
END.

Beats me...
 
Runtime Error 2 is "File not found", likely due to the following statement:

write(gegevens, output_rec);

which will likely (my guess given I haven't tried writing overwriting a file at EOF) overwrite in place the file and give nothing to read the next time you run it.
 
FWIW ".dta" was used in the original Borland DataBase Toolbox libraries as the default extension for the table, ".ndx" was used for the index. Each record/line in the file reserved the first field as an integer for house keeping of deleted records. After that all other fields were native pascal data types. Without the source text, the methods suggested above are probably your best hope...Steve~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top