[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] Reading data from a file to a vector
From: |
Kevin Channon |
Subject: |
Re: [Help-gsl] Reading data from a file to a vector |
Date: |
Tue, 27 Jan 2009 14:45:30 +0000 |
Hi Ivan
> What I want to do is reading a plain text file with data in the format
>
> x1 y1
>
> x2 y2
>
> ... and such
If you definitely have the file in this format and you don't mind
using C++ instead of C, then you can read these files really easily
with something like,
[code]
double var1, var2;
std::ifstream myFile("filename.txt", std::ios::in);
while(!myFile.is_open()){
/* read the two elements one row at a time */
myFile << var1 << var2;
/* Insert stuff to get var1 and var2 into the right elements of the
gsl_vector here */
}
[/code]
Obviously, there should be error checking and stuff, but that's the basic idea.
Have fun
Kevin
--
Kevin Channon
School of Chemistry
University of Bristol
UK