Problem with code "signal SIGABRT"

Dec 20, 2009 at 12:10pm
Hi guys i have written the following code. when completed, it is supposed to read data from a Gmsh mesh file. but i keep receiving a SIGBRT signal right before the while loop in the function "find_preliminary_info_from_file". i would be very thankful if you helped me out

the main body of the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#include "auxiliary_functions.h"

using namespace std;

int main () {
	
	const int max_num_char_in_line = 512;
	std::cout << "This commandline tool has been designed to solve the 2D pure advection problem presented as the term project to the Finite Element Method course by Dr. Manzari. The code has been written by	Bamdad Hosseini 85110129. The code has been written using apples Xcode 3.1 and compiled under  gcc 4.2 and LLVM gcc 4.2 compilers. The problem is solved on a unit square using linear triangular elements generated by Gmsh 2.4.2. \n please push the enter if you wish to run this program." << endl;
	std::cout << endl;
	string mesh_file_address;
	mesh_file_address = "/Users/bamdadhosseini/Desktop/mesh/FEMmesh.txt";
	
	int number_of_nd_ele[2];
	int nd_ele_line[2];
	find_preliminary_info_from_file(mesh_file_address, max_num_char_in_line, nd_ele_line, number_of_nd_ele);
}


the function,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
//header file containing auxiliary functions used to handle various tasks besides mathematical operations

void find_preliminary_info_from_file(string mesh_file_address,int max_num_char_in_line, int nd_ele_line[2], int number_of_nd_ele[2]){
	
	string word;
	string $Nodes ("$Nodes");
	int i =0;
	ifstream file_to_read(mesh_file_address.c_str(), ios::in);
	if (!file_to_read.is_open())
		std::cout << "cannot open file" << endl; 
	while (!file_to_read.eof()) {
		file_to_read >> word;
		if (word.compare($Nodes)==0){
			file_to_read.ignore(max_num_char_in_line, '\n');
			i++;
			nd_ele_line[0] = i;
			file_to_read >> number_of_nd_ele[0];
		}
		i++;
	}
	
};

im using Xcode 3.1
thank you very much.
Dec 20, 2009 at 2:43pm
ok this is getting really frustrating, i gave up on the last function and tried this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#include "auxiliary_functions.h"
#include "math_functions.h"
#include "data_structure.h"

using namespace std;

int main () {
	
	const int max_num_char_in_line = 512;
	std::cout << "This commandline tool has been designed to solve the 2D pure advection problem presented as the term project to the Finite Element Method course by Dr. Manzari. The code has been written by	Bamdad Hosseini 85110129. The code has been written using apples Xcode 3.1 and compiled under  gcc 4.2 and LLVM gcc 4.2 compilers. The problem is solved on a unit square using linear triangular elements generated by Gmsh 2.4.2. \n please push the enter if you wish to run this program." << endl;
	//std::cin.get();
	std::cout << endl;
	//std::cout << "please enter the address of the Gmsh mesh file:" << endl;
	string mesh_file_address;
	//std::cin >> mesh_file_address;
	//std::cin.get();
	mesh_file_address = "/Users/bamdadhosseini/Desktop/mesh/FEMmesh.txt";
	
	int number_of_nd_ele[2];
	node *global_nodes;
	element *global_elements;
	
	int nd_ele_line[2];
	//find_preliminary_info_from_file(mesh_file_address, max_num_char_in_line, nd_ele_line, number_of_nd_ele);
	float x;
	ifstream myfile;
	myfile.open("/Users/bamdadhosseini/Desktop/mesh/FEMmesh.txt");
	while (!myfile.eof()) {
		myfile >> x;
		std::cout << x << endl;
	}
	myfile.close();
}


the text file which is being read is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$MeshFormat
2 0 8
$EndMeshFormat
$Nodes
71
1 -0.5 0.5 0
2 -0.5 -0.5 0
3 0.5 -0.5 0
4 0.5 0.5 0
5 0.5 0.3571428571432537 0
6 0.5 0.2142857142864577 0
7 0.5 0.07142857142951309 0
8 0.5 -0.07142857142762971 0
9 0.5 -0.2142857142849708 0
10 0.5 -0.3571428571424606 0
11 -0.3571428571432537 -0.5 0
12 -0.2142857142864577 -0.5 0


but no matter what i do the code reads 0 instead of anything! what is wrong here? i also used getline and a string but the string variable doesnt read anything. what am i doing wrong?
Last edited on Dec 20, 2009 at 2:45pm
Dec 20, 2009 at 3:55pm
myFile >> x;

with x being a float is going to do nothing since the first line of the file is not of
float format.
Dec 20, 2009 at 5:41pm
that is ture, but the problem is that i changed the .txt to include a number of integers and floats, no text, and still i could not get anything. i tried defining x as a character and i managed to read the files character by character. i still dont understand what im doing wrong. i have checked like 20 sample codes for this purpose and i still cant find the problem. and i have a feeling its one of those bugs that makes you hate your self when you find it :|
Topic archived. No new replies allowed.