By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,655 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,655 IT Pros & Developers. It's quick & easy.

Reading random data from file

P: 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
Share this Question
Share on Google+
3 Replies


100+
P: 293
D_C
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

P: 4
smk
Thank you very much
I got it
Sep 21 '06 #3

100+
P: 293
D_C
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

Post your reply

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