C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

reading data from text file

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Santah
Guest





PostPosted: Mon Jul 28, 2003 7:39 am    Post subject: reading data from text file Reply with quote



hi
I'm new to C++
and I'm currently working on Visual C++ 6.0

I'm trying to open a text file, and read some data from it

part of the text file looks like this:

--------

Stoichiometry C3H7NO
Framework group C1[X(C3H7NO)]
Deg. of freedom 30
Full point group C1 NOp 1
Largest Abelian subgroup C1 NOp 1
Largest concise Abelian subgroup C1 NOp 1
Standard orientation:
---------------------------------------------------------------------
Center Atomic Atomic Coordinates (Angstroms)
Number Number Type X Y Z
---------------------------------------------------------------------
1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052
---------------------------------------------------------------------
Rotational constants (GHZ): 8.3231162 3.9152127
2.8710745
Isotopes: N-14,C-12,H-1,C-12,O-16,C-12,H-1,H-1,H-1,H-1,H-1,H-1
Standard basis: VSTO-3G (5D, 7F)
There are 27 symmetry adapted basis functions of A symmetry.
Crude estimate of integral set expansion from redundant
integrals=1.000.

--------


what I need, is the values:

1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052


but I don't know how to fetch them :(

here's what I've done so far .... (I know that it's not good nor
working Smile)

CFile file1("test.txt", CFile::modeRead );
DWORD dwLen = file1.GetLength();

char *pbuf = new char[dwLen] ;

ffile1.ReadHuge( pbuf, dwLen );

CString sText(pbuf);

delete []pbuf;
// sText.Find("Standard orientation:");


so I have the whole file in a string, and now I need only to get the
needed values from the string but I don't know how:(

any help is welcomed Smile)
Back to top
zot
Guest





PostPosted: Mon Jul 28, 2003 11:41 am    Post subject: Re: reading data from text file Reply with quote



Has the visual c++
a class to find regular expression similar to QT's regexp?
If so you can use it.
If not:
Another point: probably it's better to fetch the file one line at a time.
You can use the standard funtions : readline.
Now you can write a function that fetches
a floating number startinng from a char* (the ponter to the string),
and stores it in a double var.
This function should return error if it is impossible to parse the number.
Suppose you call it f(char*,double).
If it is impossible to fetch a number of int equal to the
number of columns in your table then you are parsing a bad line ( a line
extraneous to the table):

Now you can write a loop:


for(int i=0; i < NUMBER OF COL; i++)
if ( f(string,number)== error)
continue on next line;

Hope this help.
I have assumed you can write such a function, but if you want I can write it
next time.
Sorry but I haven't so much time at the moment....



"Santah" news:ed9bdbcb.0307272339.3d78ed64 (AT) posting (DOT) google.com...
Quote:
hi
I'm new to C++
and I'm currently working on Visual C++ 6.0

I'm trying to open a text file, and read some data from it

part of the text file looks like this:

--------

Stoichiometry C3H7NO
Framework group C1[X(C3H7NO)]
Deg. of freedom 30
Full point group C1 NOp 1
Largest Abelian subgroup C1 NOp 1
Largest concise Abelian subgroup C1 NOp 1
Standard orientation:
---------------------------------------------------------------------
Center Atomic Atomic Coordinates (Angstroms)
Number Number Type X Y Z
---------------------------------------------------------------------
1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052
---------------------------------------------------------------------
Rotational constants (GHZ): 8.3231162 3.9152127
2.8710745
Isotopes: N-14,C-12,H-1,C-12,O-16,C-12,H-1,H-1,H-1,H-1,H-1,H-1
Standard basis: VSTO-3G (5D, 7F)
There are 27 symmetry adapted basis functions of A symmetry.
Crude estimate of integral set expansion from redundant
integrals=1.000.

--------


what I need, is the values:

1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052


but I don't know how to fetch them :(

here's what I've done so far .... (I know that it's not good nor
working Smile)

CFile file1("test.txt", CFile::modeRead );
DWORD dwLen = file1.GetLength();

char *pbuf = new char[dwLen] ;

ffile1.ReadHuge( pbuf, dwLen );

CString sText(pbuf);

delete []pbuf;
// sText.Find("Standard orientation:");


so I have the whole file in a string, and now I need only to get the
needed values from the string but I don't know how:(

any help is welcomed Smile)



Back to top
Thomas Matthews
Guest





PostPosted: Mon Jul 28, 2003 3:56 pm    Post subject: Re: reading data from text file Reply with quote



zot wrote:
1. Don't top-post.
Quote:
Has the visual c++
a class to find regular expression similar to QT's regexp?
If so you can use it.
If not:
Another point: probably it's better to fetch the file one line at a time.
You can use the standard funtions : readline.
readline is not a standard function. If it is, please quote where

in the C++ specification that you found it.
There is a function, std::getline(), which is part of the Standard
Template Library.


Quote:
Now you can write a function that fetches
a floating number startinng from a char* (the ponter to the string),
and stores it in a double var.
One could use the stringstream functions too.

Or even sscanf().

Quote:
This function should return error if it is impossible to parse the number.
Suppose you call it f(char*,double).
If it is impossible to fetch a number of int equal to the
number of columns in your table then you are parsing a bad line ( a line
extraneous to the table):
But why write a function when one is available?


Quote:

Now you can write a loop:


for(int i=0; i < NUMBER OF COL; i++)
if ( f(string,number)== error)
continue on next line;

Hope this help.
I have assumed you can write such a function, but if you want I can write it
next time.
Sorry but I haven't so much time at the moment....



"Santah" news:ed9bdbcb.0307272339.3d78ed64 (AT) posting (DOT) google.com...


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


Back to top
Santah
Guest





PostPosted: Tue Jul 29, 2003 8:03 am    Post subject: Re: reading data from text file Reply with quote

Thomas Matthews <Thomas_MatthewsHatesSpam (AT) sbcglobal (DOT) net> wrote

Quote:
Santah wrote:

hi
I'm new to C++
and I'm currently working on Visual C++ 6.0

I'm trying to open a text file, and read some data from it

part of the text file looks like this:

--------

Stoichiometry C3H7NO
Framework group C1[X(C3H7NO)]
Deg. of freedom 30
Full point group C1 NOp 1
Largest Abelian subgroup C1 NOp 1
Largest concise Abelian subgroup C1 NOp 1
Standard orientation:
---------------------------------------------------------------------
Center Atomic Atomic Coordinates (Angstroms)
Number Number Type X Y Z
---------------------------------------------------------------------
1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052
---------------------------------------------------------------------
Rotational constants (GHZ): 8.3231162 3.9152127
2.8710745
Isotopes: N-14,C-12,H-1,C-12,O-16,C-12,H-1,H-1,H-1,H-1,H-1,H-1
Standard basis: VSTO-3G (5D, 7F)
There are 27 symmetry adapted basis functions of A symmetry.
Crude estimate of integral set expansion from redundant
integrals=1.000.

--------


what I need, is the values:

1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052


but I don't know how to fetch them :(

here's what I've done so far .... (I know that it's not good nor
working Smile)

CFile file1("test.txt", CFile::modeRead );
DWORD dwLen = file1.GetLength();

char *pbuf = new char[dwLen] ;

ffile1.ReadHuge( pbuf, dwLen );

CString sText(pbuf);

delete []pbuf;
// sText.Find("Standard orientation:");


so I have the whole file in a string, and now I need only to get the
needed values from the string but I don't know how:(

any help is welcomed Smile)

I'm in a good mood, so here is a foundation. :-)

#include <fstream
#include #include using std::ifstream;
using std::string;
using std::getline;
using std::cerr;

int main(void)
{
ifstream inp_data("test.txt"); // ifstream defaults to text files
if (!inp_data)
{
cerr << "Error opening 'test.txt'n";
return EXIT_FAILURE;
}

//------------------------------------------------------------
// Skip past all the junk.
//------------------------------------------------------------
string text_line;
unsigned int dashed_line_count = 2;
while (getline(inp_data, text_line, 'n'))
{
if ((text_line.length() > 1)
&& (text_line[0] == '-'))
{
--dashed_line_count;
if (dashed_line_count == 0)
break;
}
}

if (!inp_data || (dashed_line_count > 0))
{
cerr << "Data table not found.n";
return EXIT_FAILURE;
}

//------------------------------------------------------------
// At this point, the next text line should be the
// first row of data.
//------------------------------------------------------------
unsigned int center_number;
unsigned int atomic_number;
unsigned int atomic_type;
double x_ord;
double y_ord;
double z_ord;
while (inp_data >> center_number)
{
inp_data >> atomic_number >> atomic_type
x_ord >> y_ord >> z_ord;
Process_The_Data(center_number, atomic_number, atomic_type,
x_ord, y_ord, z_ord);
}
return EXIT_SUCCESS;
}


Look Ma, no $#@!&*# MFC library required.
And its portable too.
{The code above has not been compiled nor tested.}

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book



thanks that you took the time to try to help me, but....
I can't make your source work ...
because:
1. I haven't seen anywhere in your source the string "Standard
Orientation", and that is the keystring wich I should use to locate
the table, because the text file is not with a fixed rows, and there
can be many things above that table, but when there is the "Standard
Orientation" string, I know that the table follows.....
2. The way you added values to those variables (atomic_number etc.)
are they arrays or single values? because I need all the values from
the table stored....

sorry if I missunderstood something, I'm not that good in programming,
and thanks again for taking the time to read this Smile bye

Back to top
Karl Heinz Buchegger
Guest





PostPosted: Tue Jul 29, 2003 2:14 pm    Post subject: Re: reading data from text file Reply with quote



Karl Heinz Buchegger wrote:
Quote:

[snip]
then one could use (referring to Mathews code again)

Apologies to Thomas.
When writing the reply I was under the impression that your
first name is Mathews, while in fact Matthews is your surname
and is spelled differently.

--
Karl Heinz Buchegger
[email]kbuchegg (AT) gascad (DOT) at[/email]

Back to top
Thomas Matthews
Guest





PostPosted: Tue Jul 29, 2003 2:17 pm    Post subject: Re: reading data from text file Reply with quote

Santah wrote:
Quote:
Thomas Matthews <Thomas_MatthewsHatesSpam (AT) sbcglobal (DOT) net> wrote


Santah wrote:


hi
I'm new to C++
and I'm currently working on Visual C++ 6.0

I'm trying to open a text file, and read some data from it

part of the text file looks like this:

--------

Stoichiometry C3H7NO
Framework group C1[X(C3H7NO)]
Deg. of freedom 30
Full point group C1 NOp 1
Largest Abelian subgroup C1 NOp 1
Largest concise Abelian subgroup C1 NOp 1
Standard orientation:
---------------------------------------------------------------------
Center Atomic Atomic Coordinates (Angstroms)
Number Number Type X Y Z
---------------------------------------------------------------------
1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052
---------------------------------------------------------------------
Rotational constants (GHZ): 8.3231162 3.9152127
2.8710745
Isotopes: N-14,C-12,H-1,C-12,O-16,C-12,H-1,H-1,H-1,H-1,H-1,H-1
Standard basis: VSTO-3G (5D, 7F)
There are 27 symmetry adapted basis functions of A symmetry.
Crude estimate of integral set expansion from redundant
integrals=1.000.

--------


what I need, is the values:

1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052


but I don't know how to fetch them :(

here's what I've done so far .... (I know that it's not good nor
working Smile)

CFile file1("test.txt", CFile::modeRead );
DWORD dwLen = file1.GetLength();

char *pbuf = new char[dwLen] ;

ffile1.ReadHuge( pbuf, dwLen );

CString sText(pbuf);

delete []pbuf;
// sText.Find("Standard orientation:");


so I have the whole file in a string, and now I need only to get the
needed values from the string but I don't know how:(

any help is welcomed Smile)

I'm in a good mood, so here is a foundation. :-)

#include <fstream
#include #include using std::ifstream;
using std::string;
using std::getline;
using std::cerr;

int main(void)
{
ifstream inp_data("test.txt"); // ifstream defaults to text files
if (!inp_data)
{
cerr << "Error opening 'test.txt'n";
return EXIT_FAILURE;
}

//------------------------------------------------------------
// Skip past all the junk.
//------------------------------------------------------------
string text_line;
unsigned int dashed_line_count = 2;
while (getline(inp_data, text_line, 'n'))
{
if ((text_line.length() > 1)
&& (text_line[0] == '-'))
{
--dashed_line_count;
if (dashed_line_count == 0)
break;
}
}

if (!inp_data || (dashed_line_count > 0))
{
cerr << "Data table not found.n";
return EXIT_FAILURE;
}

//------------------------------------------------------------
// At this point, the next text line should be the
// first row of data.
//------------------------------------------------------------
unsigned int center_number;
unsigned int atomic_number;
unsigned int atomic_type;
double x_ord;
double y_ord;
double z_ord;
while (inp_data >> center_number)
{
inp_data >> atomic_number >> atomic_type
x_ord >> y_ord >> z_ord;
Process_The_Data(center_number, atomic_number, atomic_type,
x_ord, y_ord, z_ord);
}
return EXIT_SUCCESS;
}


Look Ma, no $#@!&*# MFC library required.
And its portable too.
{The code above has not been compiled nor tested.}

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book




thanks that you took the time to try to help me, but....
I can't make your source work ...
because:
1. I haven't seen anywhere in your source the string "Standard
Orientation", and that is the keystring wich I should use to locate
the table, because the text file is not with a fixed rows, and there
can be many things above that table, but when there is the "Standard
Orientation" string, I know that the table follows.....
Instead of comparing the text line read in to a '-',

use the find() method of std::string to search for "Standard
Orientation". That loop ignores all text until a marker is found.

Quote:
2. The way you added values to those variables (atomic_number etc.)
are they arrays or single values? because I need all the values from
the table stored....
If you need _all_ the values stored before processing, then create

a structure and use a vector of the structure:
struct Atomic_Record
{
unsigned int center_number;
unsigned int atomic_number;
//... and so on
};

#include <vector>
using std::vector;

typedef vector<Atomic_Record> Atomic_Vector;
Atomic_Vector atom_info;

//----------------------------
The input fragment will look like:
Atomic_Record inp_record;
while (inp_data >> inp_record.center_number)
{
// Fill in the fields of the structure
inp_data >> inp_record.atomic_number
Quote:
inp_record.atomic_type
// and so on ...
inp_record.z_ord;

// Save the record in the array:
atom_info.push_back(inp_record);
}

Quote:

sorry if I missunderstood something, I'm not that good in programming,
and thanks again for taking the time to read this Smile bye

A better method would be to overload the operator>> (stream
extraction) for the Atomic_Record structure and use that.
With the overloaded operator, your input loop is simplified as:
while (inp_data >> inp_record)
{
atom_info.push_back(inp_record);
}

Now, I am not writing your program for you, but illustrating some
concepts, such as searching for a key string and reading variables
from a text file. Your challenge is to adapt this information
for your needs.

Read the FAQ and welcome.txt below for some great information.

By the way, do the world a favor and don't prefix your
structure and class names with a 'C' or 'T'. These are
the nomenclature for Microsoft and Borland libraries.
Be more creative.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


Back to top
Thomas Matthews
Guest





PostPosted: Tue Jul 29, 2003 3:59 pm    Post subject: Re: reading data from text file Reply with quote

Karl Heinz Buchegger wrote:
Quote:

Karl Heinz Buchegger wrote:

[snip]

then one could use (referring to Mathews code again)


Apologies to Thomas.
When writing the reply I was under the impression that your
first name is Mathews, while in fact Matthews is your surname
and is spelled differently.


Apology accepted.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


Back to top
Santah
Guest





PostPosted: Thu Jul 31, 2003 12:54 pm    Post subject: Re: reading data from text file Reply with quote

Thomas Matthews <Thomas_MatthewsHatesSpam (AT) sbcglobal (DOT) net> wrote

Quote:
Santah wrote:
Thomas Matthews <Thomas_MatthewsHatesSpam (AT) sbcglobal (DOT) net> wrote


Santah wrote:


hi
I'm new to C++
and I'm currently working on Visual C++ 6.0

I'm trying to open a text file, and read some data from it

part of the text file looks like this:

--------

Stoichiometry C3H7NO
Framework group C1[X(C3H7NO)]
Deg. of freedom 30
Full point group C1 NOp 1
Largest Abelian subgroup C1 NOp 1
Largest concise Abelian subgroup C1 NOp 1
Standard orientation:
---------------------------------------------------------------------
Center Atomic Atomic Coordinates (Angstroms)
Number Number Type X Y Z
---------------------------------------------------------------------
1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052
---------------------------------------------------------------------
Rotational constants (GHZ): 8.3231162 3.9152127
2.8710745
Isotopes: N-14,C-12,H-1,C-12,O-16,C-12,H-1,H-1,H-1,H-1,H-1,H-1
Standard basis: VSTO-3G (5D, 7F)
There are 27 symmetry adapted basis functions of A symmetry.
Crude estimate of integral set expansion from redundant
integrals=1.000.

--------


what I need, is the values:

1 7 0 -0.471842 1.385033 -0.179367
2 6 0 -0.441998 0.034984 0.352626
3 1 0 -0.532368 0.028578 1.492181
4 6 0 0.817945 -0.768835 0.128492
5 8 0 1.897598 -0.056037 -0.129721
6 6 0 -1.600140 -0.811575 -0.187269
7 1 0 -1.521476 -1.844231 0.228333
8 1 0 -2.577732 -0.368082 0.117451
9 1 0 -1.563751 -0.866827 -1.300932
10 1 0 0.330252 1.899884 0.122288
11 1 0 -1.306000 1.857479 0.102977
12 1 0 2.638344 -0.681170 -0.232052


but I don't know how to fetch them :(

here's what I've done so far .... (I know that it's not good nor
working Smile)

CFile file1("test.txt", CFile::modeRead );
DWORD dwLen = file1.GetLength();

char *pbuf = new char[dwLen] ;

ffile1.ReadHuge( pbuf, dwLen );

CString sText(pbuf);

delete []pbuf;
// sText.Find("Standard orientation:");


so I have the whole file in a string, and now I need only to get the
needed values from the string but I don't know how:(

any help is welcomed Smile)

I'm in a good mood, so here is a foundation. :-)

#include <fstream
#include #include using std::ifstream;
using std::string;
using std::getline;
using std::cerr;

int main(void)
{
ifstream inp_data("test.txt"); // ifstream defaults to text files
if (!inp_data)
{
cerr << "Error opening 'test.txt'n";
return EXIT_FAILURE;
}

//------------------------------------------------------------
// Skip past all the junk.
//------------------------------------------------------------
string text_line;
unsigned int dashed_line_count = 2;
while (getline(inp_data, text_line, 'n'))
{
if ((text_line.length() > 1)
&& (text_line[0] == '-'))
{
--dashed_line_count;
if (dashed_line_count == 0)
break;
}
}

if (!inp_data || (dashed_line_count > 0))
{
cerr << "Data table not found.n";
return EXIT_FAILURE;
}

//------------------------------------------------------------
// At this point, the next text line should be the
// first row of data.
//------------------------------------------------------------
unsigned int center_number;
unsigned int atomic_number;
unsigned int atomic_type;
double x_ord;
double y_ord;
double z_ord;
while (inp_data >> center_number)
{
inp_data >> atomic_number >> atomic_type
x_ord >> y_ord >> z_ord;
Process_The_Data(center_number, atomic_number, atomic_type,
x_ord, y_ord, z_ord);
}
return EXIT_SUCCESS;
}


Look Ma, no $#@!&*# MFC library required.
And its portable too.
{The code above has not been compiled nor tested.}

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book




thanks that you took the time to try to help me, but....
I can't make your source work ...
because:
1. I haven't seen anywhere in your source the string "Standard
Orientation", and that is the keystring wich I should use to locate
the table, because the text file is not with a fixed rows, and there
can be many things above that table, but when there is the "Standard
Orientation" string, I know that the table follows.....
Instead of comparing the text line read in to a '-',
use the find() method of std::string to search for "Standard
Orientation". That loop ignores all text until a marker is found.

2. The way you added values to those variables (atomic_number etc.)
are they arrays or single values? because I need all the values from
the table stored....
If you need _all_ the values stored before processing, then create
a structure and use a vector of the structure:
struct Atomic_Record
{
unsigned int center_number;
unsigned int atomic_number;
//... and so on
};

#include <vector
using std::vector;

typedef vector Atomic_Vector atom_info;

//----------------------------
The input fragment will look like:
Atomic_Record inp_record;
while (inp_data >> inp_record.center_number)
{
// Fill in the fields of the structure
inp_data >> inp_record.atomic_number
inp_record.atomic_type
// and so on ...
inp_record.z_ord;

// Save the record in the array:
atom_info.push_back(inp_record);
}


sorry if I missunderstood something, I'm not that good in programming,
and thanks again for taking the time to read this Smile bye

A better method would be to overload the operator>> (stream
extraction) for the Atomic_Record structure and use that.
With the overloaded operator, your input loop is simplified as:
while (inp_data >> inp_record)
{
atom_info.push_back(inp_record);
}

Now, I am not writing your program for you, but illustrating some
concepts, such as searching for a key string and reading variables
from a text file. Your challenge is to adapt this information
for your needs.

Read the FAQ and welcome.txt below for some great information.

By the way, do the world a favor and don't prefix your
structure and class names with a 'C' or 'T'. These are
the nomenclature for Microsoft and Borland libraries.
Be more creative.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book



"By the way, do the world a favor and don't prefix your
structure and class names with a 'C' or 'T'. These are
the nomenclature for Microsoft and Borland libraries.
Be more creative."

I'm not doing it, and I'm against it too
If I had pasted some code with class names with "c" or "t" it's
because the code was not mine and I adapted it Smile)

thanks for the help ...

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.