473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading random data from file

4
Hi,

I am having a file in this format

************************************************** ********************
************************************************** ********************
*** ***
*** Program Summary File ***
*** ======= ====== ======= ==== ***
*** ***
*** *** ***
************************************************** ********************
************************************************** ********************
&summ
dire = '/home,
grd_in = 'x.grid',
flw_in = 'x.flow',
par_in = x.par',
flw_out = 'tx.flow.out',
sta_out = x.sta',
status = 'interrupted',
error = 'erratic',
iter = 18856, cpusec = 7.4445E+04, speed = 159413.0,
rmin = 0.9909, ravg = 1.0057, rmax = 1.0252,
emax = 8.5078E-04, eavg = 7.0496E-05, emass = 1.5355E-03,
vrms = 2.0803E+02, flow = 3.3041E+01,
tke = 1.0532E-02, diss = 9.9826E-01,
/

Speed = 0.0000000E+00 RPM
Cp (ft^2/sec^2/deg R) = 5.0932700E+03
Gamma = 1.1000000
Gas constant = 4.6302463E+02
Exit physical annular flow = 3.3067703E+01 lbm/sec

I want to extract the data values highlighted as BOLD ( Speed, Gamma, Gas constant, Exit physical annular flow).I was able to read the entire line from the file using gets() but how to get these particular values from the string I got. Since each line in the file is having different format, I am having difficulty in getting them. Suggestion please .
Sep 19 '06 #1
3 2941
D_C
293 100+
Here's some pseudocode:
Expand|Select|Wrap|Line Numbers
  1. while (NOT end of file OR NOT captured data)
  2. {
  3.   read in a line
  4.   if the first 8 characters are not "Speed = "
  5.    discard the line
  6.   otherwise
  7.   {
  8.     find the last space on that line;
  9.     everything else in between is the speed
  10.  
  11.     read in and discard the next line // CP
  12.  
  13.     read in the next line
  14.     if the first 8 characters are not "Gamma = "
  15.       there is an error
  16.     otherwise
  17.       everything after the 8th character is the gamma value
  18.  
  19.     read in the next line
  20.     if the first 14 characters are not "Gas constant = "
  21.       there is an error
  22.     otherwise
  23.       everything after the 14th character is the gas constant
  24.  
  25.     read in the next line
  26.     if the first 29 characters are not "Exit physical annular flow = "
  27.       there is an error
  28.     otherwise
  29.     {
  30.       find the last space
  31.       everything else in between is the EPA flow
  32.     }
  33.  
  34.     close the file
  35.     captured data is true
  36.   }
  37. }
Sep 19 '06 #2
smk
4
Thank you very much
I got it
Sep 21 '06 #3
D_C
293 100+
Actually, you know that the line that starts "Speed = " should end with " RPM". So you could compare for that as the last four instead of finding the last space. Similarly with the " lbm/sec" at the end of the "Exit ... flow" line.
Sep 21 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Viswa | last post by:
PythonGurus, I would like to read the ascii data from a file with many columns into a list. I want the type to be float. data=open('dat1.dat','r') lines=data.readlines() print lines
20
by: Levi Campbell | last post by:
Hi, I'm working on a random number generator using the internet as a way to gather entropy, I have two questions. 1. is there a way to capture the internet stream? 2. how would I skip every 2nd,...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
2
by: JS | last post by:
Hello all! I have come on to a problem for which I am not able to find a solution searching the web. What I am trying to do is reading a log-file with a size of 1.3 GB. When reading it using...
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
4
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
0
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
9
by: peter.bremer | last post by:
Hi all, I've got a SQL Server database that contains zipped information stored in (binary) image fields. To complicate things, this zipped data is combined with plain-text data. I've verified...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
4
by: knuckels23 | last post by:
Hi All, I have a Random access file which is written using VB 6.0. I need to read this file using C#. The record used in VB to write the Random access file is as follows Type AA aa1 As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.