Reading random data from file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smk
    New Member
    • Sep 2006
    • 4

    Reading random data from file

    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 .
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    Here's some pseudocode:
    Code:
    while (NOT end of file OR NOT captured data)
    {
      read in a line
      if the first 8 characters are not "Speed = "
       discard the line
      otherwise
      {
        find the last space on that line;
        everything else in between is the speed
    
        read in and discard the next line // CP
    
        read in the next line
        if the first 8 characters are not "Gamma = "
          there is an error
        otherwise
          everything after the 8th character is the gamma value
     
        read in the next line
        if the first 14 characters are not "Gas constant = "
          there is an error
        otherwise
          everything after the 14th character is the gas constant
    
        read in the next line
        if the first 29 characters are not "Exit physical annular flow = "
          there is an error
        otherwise
        {
          find the last space
          everything else in between is the EPA flow
        }
    
        close the file
        captured data is true
      }
    }

    Comment

    • smk
      New Member
      • Sep 2006
      • 4

      #3
      Thank you very much
      I got it

      Comment

      • D_C
        Contributor
        • Jun 2006
        • 293

        #4
        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.

        Comment

        Working...