leung@sp1.csrd.uiuc.edu (Bruce Leung) (03/13/91)
I'm trying to read a data file that was written using the mks$ function in Basic. Actually, I assume it was written using that since the only code I have is a Basic program to read the file (shown below). My question - how can I read this file using Turbo Pascal? I last used Basic about 10 years ago and I'm not very familiar with it. I'm not terribly familiar with Turbo Pascal either but that's the language my friend wants it in. I'll take Pascal or C code or the format that Basic uses to encode a single precision number in 4 bytes. Or any other clues anyone cares to give. (Though I would prefer Turbo Pascal clues! :-)) Thanks, Bruce Basic program fragment to display data file: 120 OPEN "R",1,"C:\DATA\F7.DAT",20 130 FIELD 1,4 AS DT$,4 AS HIGH$,4 AS LOW$,4 AS CLSE$,4 AS VOL$ ... 220 FOR LOOP = 2 TO NUMRECS 230 GET 1, LOOP 240 PRINT LOOP; TAB(10) 250 PRINT CVS(DT$); TAB(20) 250 PRINT CVS(HIGH$); TAB(30) etc. ----------------------------------------------------------------------------- Bruce Leung bleung@uiuc.edu | Women and cats do as they damn well please. University of Illinois | Men and dogs had best learn to live with it.
shaunc@gold.gvg.tek.com (Shaun Case) (03/13/91)
In article <1991Mar12.203014.14472@csrd.uiuc.edu> leung@sp1.csrd.uiuc.edu (Bruce Leung) writes: >I'm trying to read a data file that was written using the mks$ function >in Basic. Actually, I assume it was written using that since the only >code I have is a Basic program to read the file (shown below). > Perhaps you could modify the code you have to read in the data, then print it back out as strings. If so, then you can read it in in C or Pascal and convert it that way, once. If you want to use C, take a look at fscanf(), or better yet, fgets() and sscanf(). -- Shaun Case: shaunc@gold.gvg.tek.com or atman%ecst.csuchico.edu@RELAY.CS.NET or Shaun Case of 1:119/666.0 (Fidonet) or 1@9651 (WWIVnet) --- A bullet in the Bush is worth two in the hand.
leung@sp17.csrd.uiuc.edu (Bruce Leung) (03/13/91)
shaunc@gold.gvg.tek.com (Shaun Case) writes: >leung@sp1.csrd.uiuc.edu (Bruce Leung) writes: >>I'm trying to read a data file that was written using the mks$ function >>in Basic. Actually, I assume it was written using that since the only >>code I have is a Basic program to read the file (shown below). > >Perhaps you could modify the code you have to read in the data, >then print it back out as strings. If so, then you can read it >in in C or Pascal and convert it that way, once. That would work but I don't want to convert the files. I want to be able to read the files that are created by another program, possibly manipulate the data, and write it back. Using Basic is not an option. The problem is that Turbo Pascal uses 6 bytes for the REAL type. I tried using the SINGLE type that uses 4 bytes (yes, I have a coprocessor) but wasn't successful. It is quite likely I was doing something wrong. (Hence my request to the collective net wisdom.) >If you want to use C, take a look at fscanf(), or better yet, >fgets() and sscanf(). I'm familiar with C. To tell you the truth, I haven't tried C yet (head hung in shame) since I do want to do this in Turbo Pascal. Thanks for your suggestions though. Bruce ----------------------------------------------------------------------------- Bruce Leung bleung@uiuc.edu | Women and cats do as they damn well please. University of Illinois | Men and dogs had best learn to live with it.
resnicks@netcom.COM (Steve Resnick) (03/14/91)
In article <1991Mar13.051427.18507@csrd.uiuc.edu> leung@sp17.csrd.uiuc.edu (Bruce Leung) writes: >shaunc@gold.gvg.tek.com (Shaun Case) writes: >>leung@sp1.csrd.uiuc.edu (Bruce Leung) writes: >>>I'm trying to read a data file that was written using the mks$ function >>>in Basic. Actually, I assume it was written using that since the only >>>code I have is a Basic program to read the file (shown below). >> >>Perhaps you could modify the code you have to read in the data, >>then print it back out as strings. If so, then you can read it >>in in C or Pascal and convert it that way, once. > >That would work but I don't want to convert the files. I want to be able >to read the files that are created by another program, possibly manipulate >the data, and write it back. Using Basic is not an option. > >The problem is that Turbo Pascal uses 6 bytes for the REAL type. I tried >using the SINGLE type that uses 4 bytes (yes, I have a coprocessor) but >wasn't successful. It is quite likely I was doing something wrong. (Hence >my request to the collective net wisdom.) > >>If you want to use C, take a look at fscanf(), or better yet, >>fgets() and sscanf(). > >I'm familiar with C. To tell you the truth, I haven't tried C yet (head >hung in shame) since I do want to do this in Turbo Pascal. > No shame needed. As I pointed out to Bruce in a reply message, Microsoft GW-BASIC, QuickBASIC V1-3, IBM BASIC, IBM BASICA and older IBM BASIC compilers use the Microsoft Binary Format. (mbf). If you need to convert these numbers using a non-Microsoft compiler, you need to "hand-convert" the numbers. Most other compilers, (Borland, MSC, etc) use IEEE floating point format rather than Microsofts (for obvoius reasons (-:) Microsoft, does, however, provide the information to do the conversion to IEEE format, or, alternatively, you can use Microsoft C V 5+ to do the conversion (there is library support for this), just call 'em up and they will send it to you ... Cheers! Steve -- ------------------------------------------------------------------------------- resnicks@netcom.com, steve@camphq, IFNA: 1:143/105.0, USNail: 530 Lawrence Expressway, Suite 374 Sunnyvale, Ca 94086 - In real life: Steve Resnick. Flames, grammar and spelling errors >/dev/null 0x2b |~ 0x2b, THAT is the question. The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2 -------------------------------------------------------------------------------
leung@sp1.csrd.uiuc.edu (Bruce Leung) (03/15/91)
Thanks to Scott Bostater (who gave me real live working Turbo Pascal code), my problem is solved. If anyone is curious about the solution, feel free to send me e-mail. My thanks also go to everyone else who gave me suggestions. Bruce ----------------------------------------------------------------------------- Bruce Leung bleung@uiuc.edu | Women and cats do as they damn well please. University of Illinois | Men and dogs had best learn to live with it.