#include "sgm_esl.h"

int SGM_ESL::OutModBlocks(char* filename){
	if (!strcmp(filename,"NULL")) return 0;

	ofstream outfile;
	if (open_outfile(outfile,filename)) return -1;

	outfile<<"$MeshFormat"<<endl<<"2.2 0 8"<<endl<<"$EndMeshFormat"<<endl<<"$Nodes"<<endl<<mod_vertice_num_<<endl;
	for (int i = 0; i < mod_vertice_num_; i++){
		outfile << mod_vertice_[i].id << " " << setprecision(16) << mod_vertice_[i].x << " " << mod_vertice_[i].y << " " << mod_vertice_[i].z << endl;
	}
	outfile<<"$EndNodes"<<endl;
	outfile<<"$Elements"<<endl<<mod_blocks_num_<<endl;
	for (int i = 0; i < mod_blocks_num_; i++){
		outfile << mod_blocks_[i].id << " 3 1 " << mod_blocks_[i].phy_group;
		for (int j = 0; j < 4; j++){
			outfile << " " << mod_blocks_[i].vert[j];
		}
		outfile << endl;
	}
	outfile << "$EndElements"<< endl;
	outfile.close();
	return 0;
}