/**
* @file    DataOutput.cpp
* @author  Sanbai Li
* @date 
* @brief   Output results
*
*
* @version
* KarstVolSys, NEU & SINOPEC.
*/

#include "DataOutput.h"


namespace KarstVolSys{
	void OutMultiPolygon(DataBase *ptDB, double* ptBlock2Face, const char* name)
	{
		/*
		Output Mesh
		*/
		//***********[1] Initialize the data file using TECINI
		INTEGER4 I; /* use to check return values */
		INTEGER4 Debug = 0;
		INTEGER4 VIsDouble = 1;
		INTEGER4 FileType = 0;

		char Var[MAX_LENGTH];
		strcpy(Var, "X Y Z ");
		strcat(Var, name);

		char title[MAX_LENGTH];
		Title(title, name);

		I = TECINI112("Example: Multiple polygonal zones showing interplane between EDFs and matrix",
			Var,
			title,
			".", /* scratch directory */
			&FileType,
			&Debug,
			&VIsDouble);

		int NE = ptDB->Nx*ptDB->Ny*ptDB->Nz, NN = (ptDB->Nx + 1)*(ptDB->Ny + 1)*(ptDB->Nz + 1);
		/* TECZNE Parameters */
		INTEGER4 ZoneType = 5; /* FE Polygon */
		INTEGER4 NumPts = NN; /* the number nodes.
							  */
		INTEGER4 NumElems = NE;
		INTEGER4 NumFaces = 0; /* not used
							   */
		INTEGER4 ICellMax = 0; /* not used */
		INTEGER4 JCellMax = 0; /* not used */
		INTEGER4 KCellMax = 0; /* not used */
		double SolutionTime = 360.0;
		INTEGER4 StrandID = 0;
		INTEGER4 ParentZone = 0;
		INTEGER4 IsBlock = 1;

		INTEGER4 NumFaceConnections = 0;
		INTEGER4 FaceNeighborMode = 0;
		INTEGER4 SharConn = 0;

		int *ValueLocation = new int[4];
		ValueLocation[0] = 1;
		ValueLocation[1] = 1;
		ValueLocation[2] = 1;
		ValueLocation[3] = 0;

		char Title_Zonei[MAX_LENGTH] = { 0 };

		//************[2] Create Zones
		I = TECZNE112("Grid blocks",
			&ZoneType,
			&NumPts,
			&NumElems,
			&NumFaces,
			&ICellMax,
			&JCellMax,
			&KCellMax,
			&SolutionTime,
			&StrandID,
			&ParentZone,
			&IsBlock,
			&NumFaceConnections,
			&FaceNeighborMode,
			0,
			0,
			0,
			NULL,
			ValueLocation,
			NULL,
			&SharConn);
		/* TECDAT Parameters */
		double *X = new double[NumPts];
		double *Y = new double[NumPts];
		double *Z = new double[NumPts];
		double *P = new double[NumElems];

		//****************[3] Set up the variable values
		for (int i = 0; i < NN; ++i){
			X[i] = ptDB->Xcoord[i];
			Y[i] = ptDB->Ycoord[i];
			Z[i] = ptDB->Zcoord[i];
		}
		for (int i = 0; i < NE; ++i){
			P[i] = ptBlock2Face[i];
		}

		INTEGER4 IsDouble = 1;
		I = TECDAT112(&NumPts, X, &IsDouble);
		I = TECDAT112(&NumPts, Y, &IsDouble);
		I = TECDAT112(&NumPts, Z, &IsDouble);
		I = TECDAT112(&NumElems, P, &IsDouble);
		I = TECNOD112(ptDB->NodeNumSequence);
		delete X;
		delete Y;
		delete Z;
		delete P;
		delete ValueLocation;

		/*
		Output faces
		*/
		int i = 0;
		int Numbering = 0;
		std::list<EmbdFracs>::iterator iter_frac;
		for (iter_frac = ptDB->Embf_list.begin(); iter_frac != ptDB->Embf_list.end(); ++iter_frac, ++i){ //Loop fractures
			EmbdFracs& follows_frac = *iter_frac;
			int m = 0;
			std::list<EmbfFace>::iterator ite_Faces;
			for (ite_Faces = follows_frac.Faces.begin(); ite_Faces != follows_frac.Faces.end(); ++ite_Faces, ++m){  //Loop faces
				EmbfFace& follows_face = *ite_Faces;
				/* TECZNE Parameters */
				INTEGER4 ZoneType = 6; /* FE Polygon */
				INTEGER4 NumPts = follows_face.nCorner; /* the number of unique
														* nodes in the zone.
														*/
				INTEGER4 NumElems = 1;
				INTEGER4 NumFaces = NumPts; /* the number of unique
											* faces in the zone.
											*/
				INTEGER4 ICellMax = 0; /* not used */
				INTEGER4 JCellMax = 0; /* not used */
				INTEGER4 KCellMax = 0; /* not used */
				double SolutionTime = 360.0;
				INTEGER4 StrandID = 0;
				INTEGER4 ParentZone = 0;
				INTEGER4 IsBlock = 1;

				INTEGER4 NumFaceConnections = 0;
				INTEGER4 FaceNeighborMode = 0;
				INTEGER4 SharConn = 0;
				//INTEGER4 ValueLocation[4] = { 1, 1, 1, 0 };
				/* For a polygonal zone, the total number of face nodes is
				* twice the total number of faces. This is because each face
				* is composed of exactly two nodes.
				*/
				INTEGER4 TotalNumFaceNodes = 2 * NumFaces;
				/* A boundary face is a face that is neighbored by an element
				* or elements in another zone or zone(s). In Zone 1, Face 9,
				* Face 10 and Face 12 have a neighbor in Zone 2. Therefore,
				* the total number of boundary faces is ??
				*/
				INTEGER4 TotalNumBndryFaces = 0;
				/* Each boundary face has one or more boundary connections. A
				* boundary connection is defined as another element in another
				* zone. Face 9 has a boundary connection with Element 1 in
				* Zone 2. In this example, each boundary face is connected to
				* one other element, so the total number of boundary
				* connections is equivalent to the total number of boundary
				* faces (3).
				*/
				INTEGER4 TotalNumBndryConns = 0;
				char Title_Zonei[MAX_LENGTH] = { 0 };
				Title_Naming(Title_Zonei, Numbering);

				//************[2] Create Zones
				I = TECZNE112(Title_Zonei,
					&ZoneType,
					&NumPts,
					&NumElems,
					&NumFaces,
					&ICellMax,
					&JCellMax,
					&KCellMax,
					&SolutionTime,
					&StrandID,
					&ParentZone,
					&IsBlock,
					&NumFaceConnections,
					&FaceNeighborMode,
					&TotalNumFaceNodes,
					&TotalNumBndryFaces,
					&TotalNumBndryConns,
					NULL,
					NULL,
					NULL,
					&SharConn);
				/* TECDAT Parameters */
				double *X = new double[NumPts];
				double *Y = new double[NumPts];
				double *Z = new double[NumPts];
				double *P = new double[NumPts];

				//****************[3] Set up the variable values
				for (int i = 0; i < NumPts; ++i){
					X[i] = follows_face.Corner[i].Xcood;
					Y[i] = follows_face.Corner[i].Ycood;
					Z[i] = follows_face.Corner[i].Zcood;
				}

				double faceVal = ptBlock2Face[Numbering + ptDB->ElementAmt];
				for (int i = 0; i < NumPts; i++)
					P[i] = faceVal;

				I = TECDAT112(&NumPts, X, &VIsDouble);
				I = TECDAT112(&NumPts, Y, &VIsDouble);
				I = TECDAT112(&NumPts, Z, &VIsDouble);
				I = TECDAT112(&NumPts, P, &VIsDouble);
				delete X;
				delete Y;
				delete Z;
				delete P;

				//***************[4] Define the Face Nodes
				INTEGER4 *FaceNodes = new INTEGER4[TotalNumFaceNodes];
				/*
				* Loop over number of sides, and set each side to two
				* consecutive nodes.
				*/
				INTEGER4 ii;
				for (ii = 0; ii < NumFaces; ii++)
				{
					FaceNodes[2 * ii] = ii + 1;
					FaceNodes[2 * ii + 1] = ii + 2;
				}
				FaceNodes[2 * ii - 1] = 1;

				//****************[5] Define the right and left elements of each face
				INTEGER4 *FaceLeftElems = new INTEGER4[NumFaces];
				INTEGER4 *FaceRightElems = new INTEGER4[NumFaces];
				for (INTEGER4 ii = 0; ii < NumFaces; ii++)
				{
					FaceLeftElems[ii] = 0;
					FaceRightElems[ii] = 1;
				}

				//******************[6] Wrriting face data
				I = TECPOLY112(NULL, /* Not used for polygon zones */
					FaceNodes,
					FaceLeftElems,
					FaceRightElems,
					NULL,
					NULL,
					NULL);
				delete FaceNodes;
				delete FaceLeftElems;
				delete FaceRightElems;
				Numbering++;
			}
		}
		//**********************[7] Close the file
		I = TECEND112();
	}

	void OutMultiFracs(DataBase *ptDB, double* ptBlock2Face, const char* name)
	{
		/*
		Output Mesh
		*/
		//***********[1] Initialize the data file using TECINI
		INTEGER4 I; /* use to check return values */
		INTEGER4 Debug = 0;
		INTEGER4 VIsDouble = 1;
		INTEGER4 FileType = 0;

		char Var[MAX_LENGTH];
		strcpy(Var, "X Y Z ");
		strcat(Var, name);

		char title[MAX_LENGTH];
		Title(title, name);

		I = TECINI112("Example: Multiple polygonal zones showing EDFs",
			Var,
			title,
			".", /* scratch directory */
			&FileType,
			&Debug,
			&VIsDouble);

		int NE = ptDB->Nx*ptDB->Ny*ptDB->Nz, NN = (ptDB->Nx + 1)*(ptDB->Ny + 1)*(ptDB->Nz + 1);
		/* TECZNE Parameters */
		INTEGER4 ZoneType = 5; /* FE Polygon */
		INTEGER4 NumPts = NN; /* the number nodes.
							  */
		INTEGER4 NumElems = NE;
		INTEGER4 NumFaces = 0; /* not used
							   */
		INTEGER4 ICellMax = 0; /* not used */
		INTEGER4 JCellMax = 0; /* not used */
		INTEGER4 KCellMax = 0; /* not used */
		double SolutionTime = 360.0;
		INTEGER4 StrandID = 0;
		INTEGER4 ParentZone = 0;
		INTEGER4 IsBlock = 1;

		INTEGER4 NumFaceConnections = 0;
		INTEGER4 FaceNeighborMode = 0;
		INTEGER4 SharConn = 0;

		int *ValueLocation = new int[4];
		ValueLocation[0] = 1;
		ValueLocation[1] = 1;
		ValueLocation[2] = 1;
		ValueLocation[3] = 0;

		char Title_Zonei[MAX_LENGTH] = { 0 };

		/*
		Output faces
		*/
		int i = 0;
		int Numbering = 0;
		std::list<EmbdFracs>::iterator iter_frac;
		for (iter_frac = ptDB->Embf_list.begin(); iter_frac != ptDB->Embf_list.end(); ++iter_frac, ++i){ //Loop fractures
			EmbdFracs& follows_frac = *iter_frac;
			int m = 0;
			std::list<EmbfFace>::iterator ite_Faces;
			for (ite_Faces = follows_frac.Faces.begin(); ite_Faces != follows_frac.Faces.end(); ++ite_Faces, ++m){  //Loop faces
				EmbfFace& follows_face = *ite_Faces;
				/* TECZNE Parameters */
				INTEGER4 ZoneType = 6; /* FE Polygon */
				INTEGER4 NumPts = follows_face.nCorner; /* the number of unique
														* nodes in the zone.
														*/
				INTEGER4 NumElems = 1;
				INTEGER4 NumFaces = NumPts; /* the number of unique
											* faces in the zone.
											*/
				INTEGER4 ICellMax = 0; /* not used */
				INTEGER4 JCellMax = 0; /* not used */
				INTEGER4 KCellMax = 0; /* not used */
				double SolutionTime = 360.0;
				INTEGER4 StrandID = 0;
				INTEGER4 ParentZone = 0;
				INTEGER4 IsBlock = 1;

				INTEGER4 NumFaceConnections = 0;
				INTEGER4 FaceNeighborMode = 0;
				INTEGER4 SharConn = 0;
				//INTEGER4 ValueLocation[4] = { 1, 1, 1, 0 };
				/* For a polygonal zone, the total number of face nodes is
				* twice the total number of faces. This is because each face
				* is composed of exactly two nodes.
				*/
				INTEGER4 TotalNumFaceNodes = 2 * NumFaces;
				/* A boundary face is a face that is neighbored by an element
				* or elements in another zone or zone(s). In Zone 1, Face 9,
				* Face 10 and Face 12 have a neighbor in Zone 2. Therefore,
				* the total number of boundary faces is ??
				*/
				INTEGER4 TotalNumBndryFaces = 0;
				/* Each boundary face has one or more boundary connections. A
				* boundary connection is defined as another element in another
				* zone. Face 9 has a boundary connection with Element 1 in
				* Zone 2. In this example, each boundary face is connected to
				* one other element, so the total number of boundary
				* connections is equivalent to the total number of boundary
				* faces (3).
				*/
				INTEGER4 TotalNumBndryConns = 0;
				char Title_Zonei[MAX_LENGTH] = { 0 };
				Title_Naming(Title_Zonei, Numbering);

				//************[2] Create Zones
				I = TECZNE112(Title_Zonei,
					&ZoneType,
					&NumPts,
					&NumElems,
					&NumFaces,
					&ICellMax,
					&JCellMax,
					&KCellMax,
					&SolutionTime,
					&StrandID,
					&ParentZone,
					&IsBlock,
					&NumFaceConnections,
					&FaceNeighborMode,
					&TotalNumFaceNodes,
					&TotalNumBndryFaces,
					&TotalNumBndryConns,
					NULL,
					NULL,
					NULL,
					&SharConn);
				/* TECDAT Parameters */
				double *X = new double[NumPts];
				double *Y = new double[NumPts];
				double *Z = new double[NumPts];
				double *P = new double[NumPts];

				//****************[3] Set up the variable values
				for (int i = 0; i < NumPts; ++i){
					X[i] = follows_face.Corner[i].Xcood;
					Y[i] = follows_face.Corner[i].Ycood;
					Z[i] = follows_face.Corner[i].Zcood;
				}

				double faceVal = ptBlock2Face[Numbering + ptDB->ElementAmt];
				for (int i = 0; i < NumPts; i++)
					P[i] = faceVal;

				I = TECDAT112(&NumPts, X, &VIsDouble);
				I = TECDAT112(&NumPts, Y, &VIsDouble);
				I = TECDAT112(&NumPts, Z, &VIsDouble);
				I = TECDAT112(&NumPts, P, &VIsDouble);
				delete X;
				delete Y;
				delete Z;
				delete P;

				//***************[4] Define the Face Nodes
				INTEGER4 *FaceNodes = new INTEGER4[TotalNumFaceNodes];
				/*
				* Loop over number of sides, and set each side to two
				* consecutive nodes.
				*/
				INTEGER4 ii;
				for (ii = 0; ii < NumFaces; ii++)
				{
					FaceNodes[2 * ii] = ii + 1;
					FaceNodes[2 * ii + 1] = ii + 2;
				}
				FaceNodes[2 * ii - 1] = 1;

				//****************[5] Define the right and left elements of each face
				INTEGER4 *FaceLeftElems = new INTEGER4[NumFaces];
				INTEGER4 *FaceRightElems = new INTEGER4[NumFaces];
				for (INTEGER4 ii = 0; ii < NumFaces; ii++)
				{
					FaceLeftElems[ii] = 0;
					FaceRightElems[ii] = 1;
				}

				//******************[6] Wrriting face data
				I = TECPOLY112(NULL, /* Not used for polygon zones */
					FaceNodes,
					FaceLeftElems,
					FaceRightElems,
					NULL,
					NULL,
					NULL);
				delete FaceNodes;
				delete FaceLeftElems;
				delete FaceRightElems;
				Numbering++;
			}
		}
		//**********************[7] Close the file
		I = TECEND112();
	}

	void OutHydralicallyFracturedBlocks(bool isFracing, string name, DataBase* ptDB){
		if (!isFracing);
		else{
			int NumEle = ptDB->ElementAmt, NumNode = ptDB->NodeAmt;
			ofstream OUTPUT("HydraFracEle" + name + ".dat", ios::out);
			if (!OUTPUT){
				cerr << "open error!" << endl;
				exit(1);
			}
			OUTPUT << "TITLE = \"Example: FE - Volume Brick Data\"" << endl
				<< "VARIABLES = \"X\", \"Y\", \"Z\", \"" << "HydraFracEle" << "\"" << endl
				<< "ZONE NODES =" << NumNode
				<< ", ELEMENTS=" << NumEle
				<< ", DATAPACKING=BLOCK, ZONETYPE=FEBRICK"
				<< ", VARLOCATION=([4," << NumEle    //PROP, YOUNGSM
				<< "] = CELLCENTERED)" << endl;
			for (int i = 0; i < NumNode; i++)
			{
				if (i % 14 == 13)
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Xcoord[i] + RefX << endl;
				else
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Xcoord[i] + RefX << "  ";
			}OUTPUT << endl;

			for (int i = 0; i < NumNode; i++)
			{
				if (i % 14 == 13)
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Ycoord[i] + RefY << endl;
				else
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Ycoord[i] + RefY << "  ";
			}OUTPUT << endl;

			for (int i = 0; i < NumNode; i++)
			{
				if (i % 14 == 13)
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Zcoord[i] + RefZ << endl;
				else
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Zcoord[i] + RefZ << "  ";
			}OUTPUT << endl;
			////////////////////////////////////////////////////////////////////////////////////////
			for (int i = 0; i < NumEle; i++)
			{
				double outSign;
				if (ptDB->isHydraulicFractured[i]) outSign = 0.0;
				else outSign = 1.0;
				if (i % 14 == 13)
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << outSign << endl;
				else
					OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << outSign << "  ";
			}OUTPUT << endl;
			//////////////////////////////////////////////////////////////////////////////////////
			for (int i = 0; i < NumEle; ++i){
				for (int j = 0; j < 8; ++j){
					OUTPUT << setiosflags(ios::scientific) << setprecision(4)
						<< ptDB->NodeNumSequence[i * 8 + j] << "  ";
				}
				OUTPUT << endl;
			}
			OUTPUT.close();
		}
	}

	void OutNaturalFracturTips(string name, DataBase* ptDB){
		int NumEle = ptDB->ElementAmt, NumNode = ptDB->NodeAmt;
		ofstream OUTPUT("NaturalFracTips" + name + ".dat", ios::out);
		if (!OUTPUT){
			cerr << "open error!" << endl;
			exit(1);
		}
		OUTPUT << "TITLE = \"Example: FE - Volume Brick Data\"" << endl
			<< "VARIABLES = \"X\", \"Y\", \"Z\", \"" << "NaturalFracTips" << "\"" << endl
			<< "ZONE NODES =" << NumNode
			<< ", ELEMENTS=" << NumEle
			<< ", DATAPACKING=BLOCK, ZONETYPE=FEBRICK"
			<< ", VARLOCATION=([4," << NumEle    //PROP, YOUNGSM
			<< "] = CELLCENTERED)" << endl;
		for (int i = 0; i < NumNode; i++)
		{
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Xcoord[i] + RefX << endl;
			else
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Xcoord[i] + RefX << "  ";
		}OUTPUT << endl;

		for (int i = 0; i < NumNode; i++)
		{
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Ycoord[i] + RefY << endl;
			else 
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Ycoord[i] + RefY << "  ";
		}OUTPUT << endl;

		for (int i = 0; i < NumNode; i++)
		{
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Zcoord[i] + RefZ << endl;
			else 
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Zcoord[i] + RefZ << "  ";
		}OUTPUT << endl;
		////////////////////////////////////////////////////////////////////////////////////////
		for (int i = 0; i < NumEle; i++)
		{
			double outSign;
			if (ptDB->isFrctureTip[i]) outSign = 2.0;
			else outSign = 1.0;
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << outSign << endl;
			else
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << outSign << "  ";
		}OUTPUT << endl;
		//////////////////////////////////////////////////////////////////////////////////////
		for (int i = 0; i < NumEle; ++i){
			for (int j = 0; j < 8; ++j){
				OUTPUT << setiosflags(ios::scientific) << setprecision(4)
					<< ptDB->NodeNumSequence[i * 8 + j] << "  ";
			}
			OUTPUT << endl;
		}
		OUTPUT.close();
	}

	void OutNaturallyFracturedBlocks(string name, DataBase* ptDB){
		int NumEle = ptDB->ElementAmt, NumNode = ptDB->NodeAmt;
		ofstream OUTPUT("NaturalFracEle" + name + ".dat", ios::out);
		if (!OUTPUT){
			cerr << "open error!" << endl;
			exit(1);
		}
		OUTPUT << "TITLE = \"Example: FE - Volume Brick Data\"" << endl
			<< "VARIABLES = \"X\", \"Y\", \"Z\", \"" << "NaturalFracEle" << "\"" << endl
			<< "ZONE NODES =" << NumNode
			<< ", ELEMENTS=" << NumEle
			<< ", DATAPACKING=BLOCK, ZONETYPE=FEBRICK"
			<< ", VARLOCATION=([4," << NumEle    //PROP, YOUNGSM
			<< "] = CELLCENTERED)" << endl;
		for (int i = 0; i < NumNode; i++)
		{
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Xcoord[i] + RefX << endl;
			else
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Xcoord[i] + RefX << "  ";
		}OUTPUT << endl;

		for (int i = 0; i < NumNode; i++)
		{
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Ycoord[i] + RefY << endl;
			else
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Ycoord[i] + RefY << "  ";
		}OUTPUT << endl;

		for (int i = 0; i < NumNode; i++)
		{
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Zcoord[i] + RefZ << endl;
			else
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << ptDB->Zcoord[i] + RefZ << "  ";
		}OUTPUT << endl;
		////////////////////////////////////////////////////////////////////////////////////////
		for (int i = 0; i < NumEle; i++)
		{
			double outSign;
			if (ptDB->isNaturalFractured[i]) outSign = 2.0;
			else outSign = 1.0;
			//////
			//int I = i % ptDB->Nx,
			//	J = (i / ptDB->Nx) % ptDB->Ny,
			//	K = (i / ptDB->Nx) / ptDB->Ny;
			//if (K == 0 || K == 0 || K == ptDB->Nz - 1 || K == ptDB->Nz - 2) outSign = 1.0;
			//else;
			///////
			if (i % 14 == 13)
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << outSign << endl;
			else
				OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << outSign << "  ";
		}OUTPUT << endl;
		//////////////////////////////////////////////////////////////////////////////////////
		for (int i = 0; i < NumEle; ++i){
			for (int j = 0; j < 8; ++j){
				OUTPUT << setiosflags(ios::scientific) << setprecision(4)
					<< ptDB->NodeNumSequence[i * 8 + j] << "  ";
			}
			OUTPUT << endl;
		}
		OUTPUT.close();
	}

	void OutMESH(DataBase* ptDB){
		//***********[1] Initialize the data file using TECINI
		INTEGER4 I; /* use to check return values */
		INTEGER4 Debug = 0;
		INTEGER4 VIsDouble = 0;
		INTEGER4 FileType = 0;

		I = TECINI112("Embedded fractures and matrix blocks",
			"X Y Z",
			"Fractures and blocks.plt",
			".", /* scratch directory */
			&FileType,
			&Debug,
			&VIsDouble);
		std::list<EmbdFracs>::iterator iter_frac;

		int NE = ptDB->Nx*ptDB->Ny*ptDB->Nz, NN = (ptDB->Nx + 1)*(ptDB->Ny + 1)*(ptDB->Nz + 1);
		/* TECZNE Parameters */
		INTEGER4 ZoneType = 5; /* FE Polygon */
		INTEGER4 NumPts = NN; /* the number nodes.
							  */
		INTEGER4 NumElems = NE;
		INTEGER4 NumFaces = 0; /* not used
							   */
		INTEGER4 ICellMax = 0; /* not used */
		INTEGER4 JCellMax = 0; /* not used */
		INTEGER4 KCellMax = 0; /* not used */
		double SolutionTime = 360.0;
		INTEGER4 StrandID = 0;
		INTEGER4 ParentZone = 0;
		INTEGER4 IsBlock = 1;

		INTEGER4 NumFaceConnections = 0;
		INTEGER4 FaceNeighborMode = 0;
		INTEGER4 SharConn = 0;

		char Title_Zonei[MAX_LENGTH] = { 0 };

		//************[2] Create Zones
		I = TECZNE112("Grid blocks",
			&ZoneType,
			&NumPts,
			&NumElems,
			&NumFaces,
			&ICellMax,
			&JCellMax,
			&KCellMax,
			&SolutionTime,
			&StrandID,
			&ParentZone,
			&IsBlock,
			&NumFaceConnections,
			&FaceNeighborMode,
			0,
			0,
			0,
			NULL,
			NULL,
			NULL,
			&SharConn);
		/* TECDAT Parameters */
		double *X = new double[NumPts];
		double *Y = new double[NumPts];
		double *Z = new double[NumPts];

		//****************[3] Set up the variable values
		for (int i = 0; i < NN; ++i){
			X[i] = ptDB->Xcoord[i];
			Y[i] = ptDB->Ycoord[i];
			Z[i] = ptDB->Zcoord[i];
		}

		INTEGER4 IsDouble = 1;
		I = TECDAT112(&NumPts, X, &IsDouble);
		I = TECDAT112(&NumPts, Y, &IsDouble);
		I = TECDAT112(&NumPts, Z, &IsDouble);
		I = TECNOD112(ptDB->NodeNumSequence);
		delete X;
		delete Y;
		delete Z;

		//**********************[7] Close the file
		I = TECEND112();
	};

	void OutNatuFracs(DataBase* ptDB){
		/*
		1. Record the generated natural fractures
		*/
		ofstream OUTPUT("NaturalFracsList.dat", ios::out);
		if (!OUTPUT){
			cerr << "open error!" << endl;
			exit(1);
		}
		OUTPUT << "ECHO_OFF" << endl;
		OUTPUT << "NFLIST" << endl;
		OUTPUT << "#    Wf   [m]           X1           Y1           Z1          X2           Y2           Z2           X3           Y3           Z3           X4           Y4           Z4" << endl;
		int i = 0;
		std::list<EmbdFracs>::iterator iteEmbdFracs;
		for (iteEmbdFracs = ptDB->Embf_list.begin(); iteEmbdFracs != ptDB->Embf_list.end(); ++iteEmbdFracs, i++){
			//Output the generated natural fractures
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).filmthick;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[0].Xcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[0].Ycood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[0].Zcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[1].Xcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[1].Ycood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[1].Zcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[2].Xcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[2].Ycood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[2].Zcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[3].Xcood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[3].Ycood;
			OUTPUT << setiosflags(ios::scientific) << setprecision(4) << setw(13) << (*iteEmbdFracs).Corner[3].Zcood << endl;
		}
		OUTPUT << "ECHO_ON" << endl;
		OUTPUT.close();
	}

	void OutNFsGeo(map<int, NF> NFs, DataBase* ptDB)
	{
		/*
		  Output Mesh
		*/
		//***********[1] Initialize the data file using TECINI
		INTEGER4 I; /* use to check return values */
		INTEGER4 Debug = 0;
		INTEGER4 VIsDouble = 0;
		INTEGER4 FileType = 0;

		I = TECINI112("Fractures and blocks",
			"X Y Z",
			"EmbdF2Block_NoTrimming.plt",
			".", /* scratch directory */
			&FileType,
			&Debug,
			&VIsDouble);

		int NE = ptDB->Nx*ptDB->Ny*ptDB->Nz, NN = (ptDB->Nx + 1)*(ptDB->Ny + 1)*(ptDB->Nz + 1);
		/* TECZNE Parameters */
		INTEGER4 ZoneType = 5; /* FE Polygon */
		INTEGER4 NumPts = NN; /* the number nodes.
							  */
		INTEGER4 NumElems = NE;
		INTEGER4 NumFaces = 0; /* not used
							   */
		INTEGER4 ICellMax = 0; /* not used */
		INTEGER4 JCellMax = 0; /* not used */
		INTEGER4 KCellMax = 0; /* not used */
		double SolutionTime = 360.0;
		INTEGER4 StrandID = 0;
		INTEGER4 ParentZone = 0;
		INTEGER4 IsBlock = 1;

		INTEGER4 NumFaceConnections = 0;
		INTEGER4 FaceNeighborMode = 0;
		INTEGER4 SharConn = 0;

		char Title_Zonei[MAX_LENGTH] = { 0 };

		//************[2] Create Zones
		I = TECZNE112("Grid blocks",
			&ZoneType,
			&NumPts,
			&NumElems,
			&NumFaces,
			&ICellMax,
			&JCellMax,
			&KCellMax,
			&SolutionTime,
			&StrandID,
			&ParentZone,
			&IsBlock,
			&NumFaceConnections,
			&FaceNeighborMode,
			0,
			0,
			0,
			NULL,
			NULL,
			NULL,
			&SharConn);
		/* TECDAT Parameters */
		double *X = new double[NumPts];
		double *Y = new double[NumPts];
		double *Z = new double[NumPts];

		//****************[3] Set up the variable values
		for (int i = 0; i < NN; ++i){
			X[i] = ptDB->Xcoord[i];
			Y[i] = ptDB->Ycoord[i];
			Z[i] = ptDB->Zcoord[i];
		}

		INTEGER4 IsDouble = 1;
		I = TECDAT112(&NumPts, X, &IsDouble);
		I = TECDAT112(&NumPts, Y, &IsDouble);
		I = TECDAT112(&NumPts, Z, &IsDouble);
		I = TECNOD112(ptDB->NodeNumSequence);
		delete X;
		delete Y;
		delete Z;

		/*
		Output fractures
		*/
		//I = TECINI112("Embedded fractures and matrix blocks",
		//	"X Y Z",
		//	"Fractures and blocks.plt",
		//	".", /* scratch directory */
		//	&FileType,
		//	&Debug,
		//	&VIsDouble);
		std::list<EmbdFracs>::iterator iter_frac;
		for (int i = 1; i <= NFs.size(); i++){ //Loop fractures
			/* TECZNE Parameters */
			INTEGER4 ZoneType = 6; /* FE Polygon */
			INTEGER4 NumPts = 4; /* the number of unique
													* nodes in the zone.
													*/
			INTEGER4 NumElems = 1;
			INTEGER4 NumFaces = NumPts; /* the number of unique
										* faces in the zone.
										*/
			INTEGER4 ICellMax = 0; /* not used */
			INTEGER4 JCellMax = 0; /* not used */
			INTEGER4 KCellMax = 0; /* not used */
			double SolutionTime = 360.0;
			INTEGER4 StrandID = 0;
			INTEGER4 ParentZone = 0;
			INTEGER4 IsBlock = 1;

			INTEGER4 NumFaceConnections = 0;
			INTEGER4 FaceNeighborMode = 0;
			INTEGER4 SharConn = 0;
			//INTEGER4 ValueLocation[4] = { 1, 1, 1, 0 };
			/* For a polygonal zone, the total number of face nodes is
			* twice the total number of faces. This is because each face
			* is composed of exactly two nodes.
			*/
			INTEGER4 TotalNumFaceNodes = 2 * NumFaces;
			/* A boundary face is a face that is neighbored by an element
			* or elements in another zone or zone(s). In Zone 1, Face 9,
			* Face 10 and Face 12 have a neighbor in Zone 2. Therefore,
			* the total number of boundary faces is ??
			*/
			INTEGER4 TotalNumBndryFaces = 0;
			/* Each boundary face has one or more boundary connections. A
			* boundary connection is defined as another element in another
			* zone. Face 9 has a boundary connection with Element 1 in
			* Zone 2. In this example, each boundary face is connected to
			* one other element, so the total number of boundary
			* connections is equivalent to the total number of boundary
			* faces (3).
			*/
			INTEGER4 TotalNumBndryConns = 0;
			char Title_Zonei[MAX_LENGTH] = { 0 };
			Title_Naming(Title_Zonei, i);

			//************[2] Create Zones
			I = TECZNE112(Title_Zonei,
				&ZoneType,
				&NumPts,
				&NumElems,
				&NumFaces,
				&ICellMax,
				&JCellMax,
				&KCellMax,
				&SolutionTime,
				&StrandID,
				&ParentZone,
				&IsBlock,
				&NumFaceConnections,
				&FaceNeighborMode,
				&TotalNumFaceNodes,
				&TotalNumBndryFaces,
				&TotalNumBndryConns,
				NULL,
				NULL,
				NULL,
				&SharConn);
			/* TECDAT Parameters */
			double *X = new double[NumPts];
			double *Y = new double[NumPts];
			double *Z = new double[NumPts];

			//****************[3] Set up the variable values
			X[0] = NFs.find(i)->second.v1.Xcood;
			Y[0] = NFs.find(i)->second.v1.Ycood;
			Z[0] = NFs.find(i)->second.v1.Zcood;
			X[1] = NFs.find(i)->second.v2.Xcood;
			Y[1] = NFs.find(i)->second.v2.Ycood;
			Z[1] = NFs.find(i)->second.v2.Zcood;
			X[2] = NFs.find(i)->second.v3.Xcood;
			Y[2] = NFs.find(i)->second.v3.Ycood;
			Z[2] = NFs.find(i)->second.v3.Zcood;
			X[3] = NFs.find(i)->second.v4.Xcood;
			Y[3] = NFs.find(i)->second.v4.Ycood;
			Z[3] = NFs.find(i)->second.v4.Zcood;

			INTEGER4 IsDouble = 1;
			I = TECDAT112(&NumPts, X, &IsDouble);
			I = TECDAT112(&NumPts, Y, &IsDouble);
			I = TECDAT112(&NumPts, Z, &IsDouble);
			delete X;
			delete Y;
			delete Z;

			//***************[4] Define the Face Nodes
			INTEGER4 *FaceNodes = new INTEGER4[TotalNumFaceNodes];
			/*
			* Loop over number of sides, and set each side to two
			* consecutive nodes.
			*/
			INTEGER4 ii;
			for (ii = 0; ii < NumFaces; ii++)
			{
				FaceNodes[2 * ii] = ii + 1;
				FaceNodes[2 * ii + 1] = ii + 2;
			}
			FaceNodes[2 * ii - 1] = 1;

			//****************[5] Define the right and left elements of each face
			INTEGER4 *FaceLeftElems = new INTEGER4[NumFaces];
			INTEGER4 *FaceRightElems = new INTEGER4[NumFaces];
			for (INTEGER4 ii = 0; ii < NumFaces; ii++)
			{
				FaceLeftElems[ii] = 0;
				FaceRightElems[ii] = 1;
			}

			//******************[6] Wrriting face data
			I = TECPOLY112(NULL, /* Not used for polygon zones */
				FaceNodes,
				FaceLeftElems,
				FaceRightElems,
				NULL,
				NULL,
				NULL);
			delete FaceNodes;
			delete FaceLeftElems;
			delete FaceRightElems;
		}
		
		//**********************[7] Close the file
		I = TECEND112();
	};

	void OutNFsGeo(DataBase* ptDB)
	{
		/*
		Output Mesh
		*/
		//***********[1] Initialize the data file using TECINI
		INTEGER4 I; /* use to check return values */
		INTEGER4 Debug = 0;
		INTEGER4 VIsDouble = 0;
		INTEGER4 FileType = 0;

		I = TECINI112("Fractures and blocks",
			"X Y Z",
			"EmbdF2Block_NoTrimming.plt",
			".", /* scratch directory */
			&FileType,
			&Debug,
			&VIsDouble);

		int NE = ptDB->Nx*ptDB->Ny*ptDB->Nz, NN = (ptDB->Nx + 1)*(ptDB->Ny + 1)*(ptDB->Nz + 1);
		/* TECZNE Parameters */
		INTEGER4 ZoneType = 5; /* FE Polygon */
		INTEGER4 NumPts = NN; /* the number nodes.
							  */
		INTEGER4 NumElems = NE;
		INTEGER4 NumFaces = 0; /* not used
							   */
		INTEGER4 ICellMax = 0; /* not used */
		INTEGER4 JCellMax = 0; /* not used */
		INTEGER4 KCellMax = 0; /* not used */
		double SolutionTime = 360.0;
		INTEGER4 StrandID = 0;
		INTEGER4 ParentZone = 0;
		INTEGER4 IsBlock = 1;

		INTEGER4 NumFaceConnections = 0;
		INTEGER4 FaceNeighborMode = 0;
		INTEGER4 SharConn = 0;

		char Title_Zonei[MAX_LENGTH] = { 0 };

		//************[2] Create Zones
		I = TECZNE112("Grid blocks",
			&ZoneType,
			&NumPts,
			&NumElems,
			&NumFaces,
			&ICellMax,
			&JCellMax,
			&KCellMax,
			&SolutionTime,
			&StrandID,
			&ParentZone,
			&IsBlock,
			&NumFaceConnections,
			&FaceNeighborMode,
			0,
			0,
			0,
			NULL,
			NULL,
			NULL,
			&SharConn);
		/* TECDAT Parameters */
		double *X = new double[NumPts];
		double *Y = new double[NumPts];
		double *Z = new double[NumPts];

		//****************[3] Set up the variable values
		for (int i = 0; i < NN; ++i){
			X[i] = ptDB->Xcoord[i];
			Y[i] = ptDB->Ycoord[i];
			Z[i] = ptDB->Zcoord[i];
		}

		INTEGER4 IsDouble = 1;
		I = TECDAT112(&NumPts, X, &IsDouble);
		I = TECDAT112(&NumPts, Y, &IsDouble);
		I = TECDAT112(&NumPts, Z, &IsDouble);
		I = TECNOD112(ptDB->NodeNumSequence);
		delete X;
		delete Y;
		delete Z;

		/*
		Output fractures
		*/
		//I = TECINI112("Embedded fractures and matrix blocks",
		//	"X Y Z",
		//	"Fractures and blocks.plt",
		//	".", /* scratch directory */
		//	&FileType,
		//	&Debug,
		//	&VIsDouble);
		std::list<EmbdFracs>::iterator iter_frac = ptDB->Embf_list.begin();
		for (int i = 1; iter_frac != ptDB->Embf_list.end(); i++, iter_frac++){ //Loop fractures
			/* TECZNE Parameters */
			INTEGER4 ZoneType = 6; /* FE Polygon */
			INTEGER4 NumPts = 4; /* the number of unique
								 * nodes in the zone.
								 */
			INTEGER4 NumElems = 1;
			INTEGER4 NumFaces = NumPts; /* the number of unique
										* faces in the zone.
										*/
			INTEGER4 ICellMax = 0; /* not used */
			INTEGER4 JCellMax = 0; /* not used */
			INTEGER4 KCellMax = 0; /* not used */
			double SolutionTime = 360.0;
			INTEGER4 StrandID = 0;
			INTEGER4 ParentZone = 0;
			INTEGER4 IsBlock = 1;

			INTEGER4 NumFaceConnections = 0;
			INTEGER4 FaceNeighborMode = 0;
			INTEGER4 SharConn = 0;
			//INTEGER4 ValueLocation[4] = { 1, 1, 1, 0 };
			/* For a polygonal zone, the total number of face nodes is
			* twice the total number of faces. This is because each face
			* is composed of exactly two nodes.
			*/
			INTEGER4 TotalNumFaceNodes = 2 * NumFaces;
			/* A boundary face is a face that is neighbored by an element
			* or elements in another zone or zone(s). In Zone 1, Face 9,
			* Face 10 and Face 12 have a neighbor in Zone 2. Therefore,
			* the total number of boundary faces is ??
			*/
			INTEGER4 TotalNumBndryFaces = 0;
			/* Each boundary face has one or more boundary connections. A
			* boundary connection is defined as another element in another
			* zone. Face 9 has a boundary connection with Element 1 in
			* Zone 2. In this example, each boundary face is connected to
			* one other element, so the total number of boundary
			* connections is equivalent to the total number of boundary
			* faces (3).
			*/
			INTEGER4 TotalNumBndryConns = 0;
			char Title_Zonei[MAX_LENGTH] = { 0 };
			Title_Naming(Title_Zonei, i);

			//************[2] Create Zones
			I = TECZNE112(Title_Zonei,
				&ZoneType,
				&NumPts,
				&NumElems,
				&NumFaces,
				&ICellMax,
				&JCellMax,
				&KCellMax,
				&SolutionTime,
				&StrandID,
				&ParentZone,
				&IsBlock,
				&NumFaceConnections,
				&FaceNeighborMode,
				&TotalNumFaceNodes,
				&TotalNumBndryFaces,
				&TotalNumBndryConns,
				NULL,
				NULL,
				NULL,
				&SharConn);
			/* TECDAT Parameters */
			double *X = new double[NumPts];
			double *Y = new double[NumPts];
			double *Z = new double[NumPts];

			//****************[3] Set up the variable values
			X[0] = (*iter_frac).Corner[0].Xcood;
			Y[0] = (*iter_frac).Corner[0].Ycood;
			Z[0] = (*iter_frac).Corner[0].Zcood;
			X[1] = (*iter_frac).Corner[1].Xcood;
			Y[1] = (*iter_frac).Corner[1].Ycood;
			Z[1] = (*iter_frac).Corner[1].Zcood;
			X[2] = (*iter_frac).Corner[2].Xcood;
			Y[2] = (*iter_frac).Corner[2].Ycood;
			Z[2] = (*iter_frac).Corner[2].Zcood;
			X[3] = (*iter_frac).Corner[3].Xcood;
			Y[3] = (*iter_frac).Corner[3].Ycood;
			Z[3] = (*iter_frac).Corner[3].Zcood;
			
			//X[0] = NFs.find(i)->second.v1.Xcood;
			//Y[0] = NFs.find(i)->second.v1.Ycood;
			//Z[0] = NFs.find(i)->second.v1.Zcood;
			//X[1] = NFs.find(i)->second.v2.Xcood;
			//Y[1] = NFs.find(i)->second.v2.Ycood;
			//Z[1] = NFs.find(i)->second.v2.Zcood;
			//X[2] = NFs.find(i)->second.v3.Xcood;
			//Y[2] = NFs.find(i)->second.v3.Ycood;
			//Z[2] = NFs.find(i)->second.v3.Zcood;
			//X[3] = NFs.find(i)->second.v4.Xcood;
			//Y[3] = NFs.find(i)->second.v4.Ycood;
			//Z[3] = NFs.find(i)->second.v4.Zcood;

			INTEGER4 IsDouble = 1;
			I = TECDAT112(&NumPts, X, &IsDouble);
			I = TECDAT112(&NumPts, Y, &IsDouble);
			I = TECDAT112(&NumPts, Z, &IsDouble);
			delete X;
			delete Y;
			delete Z;

			//***************[4] Define the Face Nodes
			INTEGER4 *FaceNodes = new INTEGER4[TotalNumFaceNodes];
			/*
			* Loop over number of sides, and set each side to two
			* consecutive nodes.
			*/
			INTEGER4 ii;
			for (ii = 0; ii < NumFaces; ii++)
			{
				FaceNodes[2 * ii] = ii + 1;
				FaceNodes[2 * ii + 1] = ii + 2;
			}
			FaceNodes[2 * ii - 1] = 1;

			//****************[5] Define the right and left elements of each face
			INTEGER4 *FaceLeftElems = new INTEGER4[NumFaces];
			INTEGER4 *FaceRightElems = new INTEGER4[NumFaces];
			for (INTEGER4 ii = 0; ii < NumFaces; ii++)
			{
				FaceLeftElems[ii] = 0;
				FaceRightElems[ii] = 1;
			}

			//******************[6] Wrriting face data
			I = TECPOLY112(NULL, /* Not used for polygon zones */
				FaceNodes,
				FaceLeftElems,
				FaceRightElems,
				NULL,
				NULL,
				NULL);
			delete FaceNodes;
			delete FaceLeftElems;
			delete FaceRightElems;
		}

		//**********************[7] Close the file
		I = TECEND112();
	};

	char* Title_Naming(char* Title_Zonei, int i){
		strcpy(Title_Zonei, "Zone: ");
		int Numbering = i;
		if (Numbering < 62)
			Title_Zonei[6] = FaceNum__[Numbering];
		else if (Numbering < 3844){
			Title_Zonei[6] = FaceNum__[Numbering / 62];
			Title_Zonei[7] = FaceNum__[Numbering % 62];
		}
		else if (Numbering < 238328){
			int a = Numbering / 62;
			Title_Zonei[6] = FaceNum__[a / 62];
			Title_Zonei[7] = FaceNum__[a % 62];
			Title_Zonei[8] = FaceNum__[i % 62];
		}
		else if (i < 14776336){
			int a = Numbering / 62, b = a / 62;
			Title_Zonei[6] = FaceNum__[b / 62];
			Title_Zonei[7] = FaceNum__[b % 62];
			Title_Zonei[8] = FaceNum__[a % 62];
			Title_Zonei[9] = FaceNum__[Numbering % 62];
		}
		else
			std::cout << "The splitting face number exceeds 14776336!" << std::endl;
		strcat(Title_Zonei, "-th face");
		return Title_Zonei;
	}
	char* Title(char* Title_Zonei, const char* VarName){
		strcpy(Title_Zonei, "EmbdF_");
		strcat(Title_Zonei, VarName);
		strcat(Title_Zonei, ".plt");
		return Title_Zonei;
	}

	char* Title_i(char* Title_Zonei, int N, int i){
		int Numbering = i;
		if (Numbering < 10)
			Title_Zonei[N] = FaceNum_[Numbering];
		else if (Numbering < 100){
			Title_Zonei[N] = FaceNum_[Numbering / 10];
			Title_Zonei[N+1] = FaceNum_[Numbering % 10];
		}
		else if (Numbering < 1000){
			int a = Numbering / 10;
			Title_Zonei[N] = FaceNum_[a / 10];
			Title_Zonei[N+1] = FaceNum_[a % 10];
			Title_Zonei[N+2] = FaceNum_[i % 10];
		}
		else if (i < 10000){
			int a = Numbering / 10, b = a / 10;
			Title_Zonei[N] = FaceNum_[b / 10];
			Title_Zonei[N+1] = FaceNum_[b % 10];
			Title_Zonei[N+2] = FaceNum_[a % 10];
			Title_Zonei[N+3] = FaceNum_[Numbering % 10];
		}
		else;
		return Title_Zonei;
	}

}
