Reading in data from file in certain format

This is a discussion on Reading in data from file in certain format within the C++ Programming forums, part of the General Programming Boards category; I have a text file (output of another program, Mathematica) containing the complex values of some function: Code: f[0, 6] ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    5

    Reading in data from file in certain format

    I have a text file (output of another program, Mathematica) containing the complex values of some function:

    Code:
    f[0, 6] = 0.00006639570. - 6.00456*I;
       f[1, 6] = 0.00003602  +0.0039842775.*I;
       f[0, 7] = 0.0000663-  6.00383226386*I; 
      f[1, 7] =  60233709 + 0.00039842*I;
       . 
      .  
    .
    I could rewrite this in some conveinient way if any is better, but basically it boils down to a function of two variables that is complex valued.

    I want to read this into to some c++ code then perhaps store it in some vector/map/hash structure that will easily let me access the complex value given the point in parameter space (x,y).

    I'm able to rewrite the format on the input file anyway you like, e.g.
    entries could look like x, y, cvalue or whatever is best.

    I was thinking of possible storing this in a structure like map, where the key is a pair of doubles, and the value is a complex number, would this be the best way? Then how do I do this inputting?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,717
    Have you considered using the complex class to hold this data?

    Jim

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    5
    Quote Originally Posted by jimblumberg View Post
    Have you considered using the complex class to hold this data?

    Jim
    Yes, of course the value itself will be held in a complex<double> say, but this needs to be indexed by the parameters (x,y) to allow retriveing of correct value for given parameter set.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in data from file in certain format
    By fpghost in forum C Programming
    Replies: 6
    Last Post: 11-22-2012, 12:20 PM
  2. Replies: 2
    Last Post: 03-11-2011, 03:45 AM
  3. How to write image data to binary PGM file format(P5)?
    By tommy_chai in forum C Programming
    Replies: 6
    Last Post: 11-03-2007, 10:52 PM
  4. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  5. reading data format into program
    By lambs4 in forum C Programming
    Replies: 1
    Last Post: 10-23-2003, 02:27 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21