void
AuxCalphadEnergy::computeBarrier()
{
  Real first(0);
  Real second(0);
  Real third(0);
  Real fourth(0);
  Real fifth(0);

  Real sixth;
  if(_n_OP_vars == 1)
    sixth = 0;
  else
    sixth = 1;

  for (unsigned int i=0; i<_n_OP_vars; i++)
  {
    first += std::pow((*_OP[i])[_qp], 2);
    second += std::pow((*_OP[i])[_qp], 3);
    third += std::pow((*_OP[i])[_qp], 4);

    Real square_sum(0);
    Real quad_sum(0);
    for (unsigned int j=0; j < _n_OP_vars; j++)
    {
      if (j > i)
        square_sum += std::pow((*_OP[j])[_qp], 2);

      if (j != i)
        quad_sum += std::pow((*_OP[j])[_qp], 4);
    }

    fourth +=  ( std::pow((*_OP[i])[_qp], 2) )*square_sum;
    fifth += ( std::pow((*_OP[i])[_qp], 2) )*quad_sum;

    sixth *= std::pow((*_OP[i])[_qp], 2);
  }

  _g = first - 2*second + third + fourth + fifth + sixth;
}
void init_main_0(const unsigned short & A,
				 const unsigned short & K_min,
				 const unsigned short & K_max,
				 const unsigned short & P,
				 const unsigned short modo_clust,
				 const unsigned short & P_orb){
	
	unsigned short N = A - 1;
	std::string s, s_1;
	std::string s_k,s_cluster;
	std::string s_ext_txt = ".txt";
	std::string s_ext_dat = ".dat";
	std::string s_k_max = "_K_max_" + scrivi(K_max);
	
	std::vector <unsigned short> clus;
	
	if (modo_clust && A==4) {
		clus.push_back(2);
		clus.push_back(2);
		s_cluster = "_Modo_H";
	}
	else {
		clus.push_back(A);
		s_cluster = "";
	}

	Accoppiamenti_Iperangolari_K_max KK (N, 0, 0, K_min,P,clus,P_orb);
	s_k = KK.filename();
	{
		s = "numero_hh_";
		s += s_k + s_k_max + s_cluster  + s_ext_dat;
		s_1 = "numero_hh_";
		s_1 += s_k + s_k_max + s_cluster  + s_ext_txt;
	}
	
		
	std::ofstream myfile;
	std::ofstream myfile_1;
	{
		myfile.open (s.c_str());
		myfile_1.open (s_1.c_str());
		myfile.precision(std::numeric_limits<long double>::digits10); 		
		myfile_1.precision(std::numeric_limits<long double>::digits10); 		
		std::cerr.precision(10);
		std::cout.precision(10);
	}
	
	{		
		myfile_1 << "Numero di HH per " << A << " nucleoni ";
		myfile_1 << std::endl;
	}
	
	boost::timer t6;
	unsigned short incremento = 1;

	for (unsigned short K_max_temp = K_min; K_max_temp <= K_max; K_max_temp+=incremento) {
				
		boost::timer t;
		
		{	
			myfile_1 << std::endl;
			myfile_1 << std::endl;
			myfile_1 << "**************************************************************************";
			myfile_1 << std::endl;
			myfile_1 << " K_max_temp = " << K_max_temp << std::endl;
			std::cerr << " K_max_temp = " << K_max_temp << std::endl;
		}
		KK.PLUS(K_max_temp - KK.K_M(),P,clus);
		if (KK.D()>0) {
			{
				myfile_1 << " N_hh = " << KK.D() << std::endl;
				std::cerr << " N_hh = " << KK.D() << std::endl;
				std::cerr << "Accoppiamenti_Iperangolari_K_max  T = " << t.elapsed() << std::endl;
				myfile << "Accoppiamenti_Iperangolari_K_max  T = " << t.elapsed() << std::endl;
				for (unsigned long i = 0; i < KK.D() ; ++i){
					myfile << i+1 << "	K = " << KK.k(i) << "	 n = [ ";
					for(unsigned short j = 0; j < KK.n(i).size() ; ++j){
						myfile << KK.n(i)[j];
						myfile << " ";
					}
					myfile << "]   l = [ ";
					for(unsigned short j = 0; j < KK.l(i).size() ; ++j){
						myfile << KK.l(i)[j];
						myfile << " ";
					}
					
					myfile << "]  L = [ ";
					for(unsigned short j = 0; j < KK.L(i).size() ; ++j){
						myfile << KK.L(i)[j];
						myfile << " ";
					}
					
					myfile << "]";
					
					myfile << "   parita = [ ";
					for(unsigned short j = 0; j < KK.P_l(i).size() ; ++j){
						myfile << KK.P_l(i)[j];
						myfile << " ";
					}
					myfile << "]	 somma quadra dei coefficienti dello sviluppo = ";
					myfile << quad_sum(KK.cm(i));				
					myfile << std::endl;
				}
				myfile << "Dimensione della base = " << KK.D() << " combinazioni." << std::endl;
			}
		}
	}
	std::cerr << "Esecuzione  T = " << t6.elapsed() << std::endl;
	myfile << "Esecuzione  T = " << t6.elapsed() << std::endl;
	myfile.close();
	myfile_1.close();
	
}
void init_main_0(const unsigned short & A,
				 const unsigned short & m_max,
				 const unsigned short & K_min,
				 const unsigned short & K_max,
				 const Init_Corpi_L & Corpi,
				 const unsigned short & P,
				 const bool & modo_clust,
				 const unsigned short & P_orb){
	
	unsigned short ordine = 200;
	unsigned short N = A - 1;
	
	std::string s, s_0, s_1 , s_l, s_misurabili;
	std::string s_k,s_cluster,s_masse;
	std::string s_ext_txt = ".txt";
	std::string s_ext_dat = ".dat";
	std::string s_k_max = "_K_max_" + scrivi(K_max);
	std::string s_corpi = "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max);
	
	std::vector <unsigned short> clus;
	
	if (modo_clust && A==4) {
		clus.push_back(2);
		clus.push_back(2);
		s_cluster = "_Modo_H";
	}
	else {
		clus.push_back(A);
		s_cluster = "";
	}
	if(Corpi.M_u()){
		s_masse = "_M_u";
	}
	else {
		s_masse = "";
	}
	
	Accoppiamenti_Iperangolari_K_max KK (N, 0, 0, K_min,P,clus,P_orb);
	s_k = KK.filename();
	{
		s = "E_";
		s_0 = "Tabella_E_";
		s_1 = "E_";
		s_l = "Livelli_E_";
		s_misurabili = "Misurabili_";
	}
	{
		s += s_corpi + s_k + s_k_max + s_cluster + s_masse + s_ext_dat;
		s_0 += s_corpi + s_k + s_k_max + s_cluster + s_masse + s_ext_txt;
		s_1 += s_corpi + s_k + s_k_max + s_cluster + s_masse + s_ext_txt;
		s_l += s_corpi + s_k + s_k_max + s_cluster + s_masse + s_ext_txt;
		s_misurabili += s_corpi + s_k + s_k_max + s_cluster + s_masse + s_ext_txt;
	}
	
	std::string s_vec,s_vec_temp,s_vec_temp_c;
	{
		s_vec = "./lista_vettori/Vec_";
		s_vec += s_corpi + s_k + s_k_max + s_cluster + s_masse;
	}
	std::fstream myfile_vec;
	myfile_vec.precision(10); 		
	bool scrivi_vettore;
	bool scrivi_vettore_c;
	
	std::ofstream myfile;
	std::ofstream myfile_1;
	std::ofstream myfile_tabella;
	std::ofstream myfile_livelli;
	std::ofstream myfile_misurabili;
	{
		myfile.open (s.c_str());
		myfile_1.open (s_1.c_str());
		myfile_tabella.open (s_0.c_str());
		myfile_livelli.open (s_l.c_str());
		myfile_misurabili.open (s_misurabili.c_str());
		myfile.precision(std::numeric_limits<long double>::digits10); 		
		myfile_1.precision(std::numeric_limits<long double>::digits10); 		
		myfile_tabella.precision(10); 		
		myfile_livelli.precision(10); 		
		myfile_misurabili.precision(10); 		
		std::cerr.precision(10);
		std::cout.precision(10);
	}
	
	{		
		myfile_1 << "Binding Energy per " << A << " nucleoni : ";
		myfile_tabella << "Binding Energy per " << A << " nucleoni : ";
		myfile_livelli << "Primi Livelli Energetici per " << A << " nucleoni : ";
		for (short i = 0; i<A; ++i) {
			myfile_1<< Corpi.CORPI(i)<< " ";
			myfile_tabella<< Corpi.CORPI(i)<< " ";
			myfile_livelli<< Corpi.CORPI(i)<< " ";
		}
		myfile_1 << std::endl;
		myfile_tabella << std::endl;
		myfile_livelli << std::endl;
		myfile_1 << " m_max = " << m_max << " K_max = " << K_max << "	P = " << P << std::endl;
		myfile_tabella << " m_max = " << m_max << " K_max = " << K_max << "	P = " << P << std::endl;
		myfile_livelli << " m_max = " << m_max << " K_max = " << K_max << "	P = " << P << std::endl;
	}
	if(Corpi.M_u() && A==3)	{
		myfile_tabella << "K_max	N_hh	Parita'		E		E_ppp		E_ppn		E_nnp		E_nnn		E_c" << std::endl;
	}
	else{
		myfile_tabella << "K_max	N_hh	Parita'		E		E_c" << std::endl;
	}
	boost::timer t6;
	unsigned short incremento = 2;
	Gauss_Laguerre G(ordine);
	HyperInt HI(ordine/2);
	Energia_radiale ER ( N, G, HI, K_min, m_max, Corpi.C(), Corpi.M(), Corpi.M_R(), clus);
	Integrazioni_3_P INT_3P(N);
	Energia EN ( HI, &INT_3P , ER, KK );
	
	
	//lancsoz
	VETTORI mygen(m_max + 1);
	VETTORI mygen_c(m_max + 1);
	typedef boost::lagged_fibonacci607 Gen_i;
	typedef ietl::vectorspace<VETTORI> Vecspace;
	Gen_i mygen_i;
	bool primopasso = true;
	bool primopasso_c = true;
	tipo_matrici rel_tol = 500000000*std::numeric_limits<double>::epsilon();
	tipo_matrici abs_tol = 1000000*std::pow(std::numeric_limits<double>::epsilon(),2./3);
	int n_lowest_eigenval = 1;	
	//lancsoz
	
	
	for (unsigned short K_max_temp = K_min; K_max_temp <= K_max; K_max_temp+=incremento) {
		
		//if (K_max_temp == 30) incremento = 10;
		
		boost::timer t;
		
		{	
			myfile_1 << std::endl;
			myfile_1 << std::endl;
			myfile_1 << "**************************************************************************";
			myfile_1 << std::endl;
			myfile_1 << " K_max_temp = " << K_max_temp << std::endl;
			std::cerr << " K_max_temp = " << K_max_temp << std::endl;
		}
		{	
			myfile_livelli << std::endl;
			myfile_livelli << std::endl;
			myfile_livelli << "**************************************************************************";
			myfile_livelli << std::endl;
			myfile_livelli << " K_max_temp = " << K_max_temp << std::endl;
		}	
		KK.PLUS(K_max_temp - KK.K_M(),P,clus);
		{
			myfile_1 << " N_hh = " << KK.D() << std::endl;
			std::cerr << " N_hh = " << KK.D() << std::endl;
			std::cerr << "Accoppiamenti_Iperangolari_K_max  T = " << t.elapsed() << std::endl;
			myfile << "Accoppiamenti_Iperangolari_K_max  T = " << t.elapsed() << std::endl;
			for (unsigned long i = 0; i < KK.D() ; ++i){
				myfile << i+1 << "	K = " << KK.k(i) << "	 n = [ ";
				for(unsigned short j = 0; j < KK.n(i).size() ; ++j){
					myfile << KK.n(i)[j];
					myfile << " ";
				}
				myfile << "]   l = [ ";
				for(unsigned short j = 0; j < KK.l(i).size() ; ++j){
					myfile << KK.l(i)[j];
					myfile << " ";
				}
				
				myfile << "]  L = [ ";
				for(unsigned short j = 0; j < KK.L(i).size() ; ++j){
					myfile << KK.L(i)[j];
					myfile << " ";
				}
				
				myfile << "]    parita = [ ";
				for(unsigned short j = 0; j < KK.P_l(i).size() ; ++j){
					myfile << KK.P_l(i)[j];
					myfile << " ";
				}
				myfile << "]	 somma quadra dei coefficienti dello sviluppo = ";
				myfile << quad_sum(KK.cm(i));				
				myfile << std::endl;
			}
			myfile << "Dimensione della base = " << KK.D() << " combinazioni." << std::endl;
		}
		
		if (KK.D()>0) {
			ER.PLUS((K_max_temp - ER.N_M()),G,HI);
			boost::timer t1;
			EN.PLUS(HI, &INT_3P, ER, KK);
			
			{
				
				std::cerr << "Energia  T = " << t1.elapsed() << std::endl;
				myfile << "Energia  T = " << t1.elapsed() << std::endl;
				
			}
			Accoppiamenti_Parita BASE(KK,ER.D());
			int max_iter = 5*BASE.D();  
			
			std::cerr << "BASE.D() "<< BASE.D() << std::endl;
			
			if(BASE.D()>11500){
				
				std::cerr << " Sto popolando più di 2 Gb, mi fermo" << std::endl;
				{
					std::string s_K_max_temp = "_" + scrivi(K_max_temp);
					s_vec_temp = s_vec + s_K_max_temp + s_ext_txt;
					myfile_vec.open(s_vec_temp.c_str(),std::ios::in);
					if (myfile_vec) {
						myfile_vec >> mygen;
						scrivi_vettore = false;
						primopasso = false;
					}
					else {
						scrivi_vettore = true;
						if (primopasso) {
							mygen.resize(BASE.D());
							ietl::generate_begin(mygen,mygen_i);
							primopasso = false;
						}
						else{
							ietl::regenerate_begin(mygen,mygen_i,BASE.D());					
						}						
					}
					myfile_vec.close();
				}
				{
					std::string s_K_max_temp = "_" + scrivi(K_max_temp) + "_c";
					s_vec_temp_c = s_vec + s_K_max_temp + s_ext_txt;
					myfile_vec.open(s_vec_temp_c.c_str(),std::ios::in);
					if (myfile_vec) {
						myfile_vec >> mygen_c;
						scrivi_vettore_c = false;
						primopasso_c = false;
					}
					else {
						scrivi_vettore_c = true;
						if (primopasso_c) {
							mygen_c.resize(BASE.D());
							ietl::generate_begin(mygen_c,mygen_i);
							primopasso_c = false;
						}
						else{
							ietl::regenerate_begin(mygen_c,mygen_i,BASE.D());					
						}						
					}
					myfile_vec.close();
				}
void init_main_0(const unsigned short & A,
				 const unsigned short & m_max,
				 const unsigned short & K_min,
				 const unsigned short & K_max,
				 const unsigned short & S_tot,
				 const Init_Corpi_LS & Corpi,
				 const bool & modo_clust){
	
	unsigned short ordine = 200;
	unsigned short N = A - 1;
	unsigned short P = 2;
	std::string s, s_0, s_0_p, s_0_d, s_1 , s_l, s_misurabili;
	std::string s_ext_txt = ".txt";
	std::string s_ext_dat = ".dat";
	std::string s_ext_p = "_p";
	std::string s_ext_d = "_d";
	std::string s_completa = "_tot";
	std::string s_cluster,s_masse;
	
	std::vector <unsigned short> clus;
	
	if (modo_clust && A==4) {
		clus.push_back(2);
		clus.push_back(2);
		s_cluster = "_Modo_H";
	}
	else {
		clus.push_back(A);
		s_cluster = "";
	}
	if(Corpi.M_u()){
		s_masse = "_M_u";
	}
	else {
		s_masse = "";
	}
	

	{
		s = "N_HH_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);
		
		s_0 = "N_HH_tab_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);
		
		s_0_p = "N_HH_tab_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);
		
		s_0_d = "N_HH_tab_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);
		
		s_1 = "N_HH_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);

		s_l = "N_HH_Livelli_E_0_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);

		s_misurabili = "N_HH_Misurabili_" + scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_K_max_[" + scrivi(K_min) + "-" + scrivi(K_max) + "]_S_" + scrivi(S_tot);
	}
	{
		s += s_cluster + s_masse + s_ext_dat;
		
		s_0 += s_cluster + s_masse + s_ext_txt;
		
		s_0_p += s_cluster + s_masse + s_ext_p + s_ext_txt;
		
		s_0_d += s_cluster + s_masse + s_ext_d + s_ext_txt;
		
		s_1 += s_cluster + s_masse + s_ext_txt;
		
		s_l += s_cluster + s_masse + s_ext_txt;
		
		s_misurabili += s_cluster + s_masse + s_ext_txt;
	}
	
	std::string s_vec,s_vec_temp,s_vec_temp_c,s_vec_temp_1,s_vec_temp_c_1;
	{
		s_vec = "./lista_vettori/Vec_"+ scrivi(A) + "_" + Corpi.scrivi_corpi() + "__m_max_" + scrivi(m_max) + "_S_" + scrivi(S_tot);
		//s_vec += s_cluster /*+ s_masse*/;
	}
	std::fstream myfile_vec;
	myfile_vec.precision(10); 		
	std::fstream myfile_vec_1;
	myfile_vec_1.precision(10); 		
	bool scrivi_vettore,scrivi_vettore_p,scrivi_vettore_c,scrivi_vettore_pc;
	
	std::ofstream myfile;
	std::ofstream myfile_1;
	std::ofstream myfile_tabella;
	std::ofstream myfile_tabella_p;
	std::ofstream myfile_tabella_d;
	std::ofstream myfile_livelli;
	std::ofstream myfile_misurabili;

	
	

	{
		myfile.open (s.c_str());
		myfile_1.open (s_1.c_str());
		myfile_tabella.open (s_0.c_str());
		myfile_tabella_p.open (s_0_p.c_str());
		myfile_tabella_d.open (s_0_d.c_str());
		myfile_livelli.open (s_l.c_str());
		myfile_misurabili.open (s_misurabili.c_str());
		myfile.precision(std::numeric_limits<long double>::digits10); 		
		myfile_1.precision(std::numeric_limits<long double>::digits10); 		
		myfile_tabella.precision(10); 		
		myfile_tabella_p.precision(10); 		
		myfile_tabella_d.precision(10);
		myfile_livelli.precision(10); 	
		myfile_misurabili.precision(10); 		
		std::cerr.precision(10);
		std::cout.precision(10);
	}
	
	{		
		myfile_1 << "Binding Energy per " << A << " nucleoni : ";
		myfile_tabella << "Binding Energy per " << A << " nucleoni : ";
		myfile_tabella_p << "Binding Energy per " << A << " nucleoni : ";
		myfile_tabella_d << "Binding Energy per " << A << " nucleoni : ";
		myfile_livelli << "Primi Livelli Energetici per " << A << " nucleoni : ";
		for (short i = 0; i<A; ++i) {
			myfile_1<< Corpi.CORPI(i)<< " ";
			myfile_tabella<< Corpi.CORPI(i)<< " ";
			myfile_tabella_p<< Corpi.CORPI(i)<< " ";
			myfile_tabella_d<< Corpi.CORPI(i)<< " ";
			myfile_livelli<< Corpi.CORPI(i)<< " ";
		}
		myfile_1 << std::endl;
		myfile_tabella << std::endl;
		myfile_tabella_p << std::endl;
		myfile_tabella_d << std::endl;
		myfile_livelli << std::endl;
		myfile_1 << " m_max = " << m_max << " K_max = " << K_max << "	S_tot = " << S_tot <<"/2" << std::endl;
		myfile_tabella << " m_max = " << m_max << " K_max = " << K_max << "	S_tot = " << S_tot <<"/2"<< std::endl;
		myfile_tabella_p << " m_max = " << m_max << " K_max = " << K_max << "	S_tot = " << S_tot <<"/2"<< std::endl;
		myfile_tabella_d << " m_max = " << m_max << " K_max = " << K_max << "	S_tot = " << S_tot <<"/2"<< std::endl;
		myfile_livelli << " m_max = " << m_max << " K_max = " << K_max << "	S_tot = " << S_tot <<"/2"<< std::endl;
	}

	if(Corpi.M_u() && A==3)	{
		myfile_tabella << "K_max	N_hh	Parita'		E		E_ppp		E_ppn		E_nnp		E_nnn		E_c" << std::endl;
		myfile_tabella_p << "K_max	N_hh	Parita'		E		E_ppp		E_ppn		E_nnp		E_nnn		E_c" << std::endl;
		myfile_tabella_d << "K_max	N_hh	Parita'		E		E_ppp		E_ppn		E_nnp		E_nnn		E_c" << std::endl;
	}
	else{
		myfile_tabella << "K_max	N_hh	Parita'		E		E_c" << std::endl;
		myfile_tabella_p << "K_max	N_hh	Parita'		E		E_c" << std::endl;
		myfile_tabella_d << "K_max	N_hh	Parita'		E		E_c" << std::endl;
	}
	
	
	boost::timer t6;
	unsigned short incremento = 2;
	Gauss_Laguerre G(ordine);
	HyperInt HI(ordine/2);
	
	Integrazioni_3_P INT_3P(N);
	Accoppiamenti_Spinoriali_S SS (Corpi.D_s(),clus,S_tot,Corpi.D_Z_min());
	Accoppiamenti_Iperangolari_K_max KK (N, 0, 0, K_min,P,clus,0);
	
	//	Energia_radiale_spin ER ( SS, N, G, HI, K_min, m_max, Corpi.C(), Corpi.M(), Corpi.M_R(),clus);
	//  Energia_spin EN ( HI, &INT_3P, ER, KK );
	
	
	//lancsoz
	VETTORI mygen(m_max + 1);
	VETTORI mygen_c(m_max + 1);
	VETTORI mygen1(m_max + 1);
	VETTORI mygen1_c(m_max + 1);
	VETTORI mygen2(m_max + 1);
	VETTORI mygen2_c(m_max + 1);
	typedef boost::lagged_fibonacci607 Gen_i;
	typedef ietl::vectorspace<VETTORI> Vecspace;
	Gen_i mygen_i;
	bool primopasso = true;
	bool primopasso1 = true;
	bool primopasso2 = true;
	bool primopasso_c = true;
	bool primopasso1_c = true;
	bool primopasso2_c = true;	
	tipo_matrici rel_tol = 500000000*std::numeric_limits<double>::epsilon();
	tipo_matrici abs_tol = 1000000*std::pow(std::numeric_limits<double>::epsilon(),2./3);
	int n_lowest_eigenval = 1;		
	//lancsoz
	
	for (unsigned short K_max_temp = K_min; K_max_temp <= K_max; K_max_temp+=incremento) {
		
		//if (K_max_temp == 30) incremento = 10;
		
		boost::timer t;
		
		{	
			myfile_1 << std::endl;
			myfile_1 << std::endl;
			myfile_1 << "**************************************************************************";
			myfile_1 << std::endl;
			myfile_1 << " K_max_temp = " << K_max_temp << std::endl;
			std::cerr << " K_max_temp = " << K_max_temp << std::endl;
		}
		{	
			myfile_livelli << std::endl;
			myfile_livelli << std::endl;
			myfile_livelli << "**************************************************************************";
			myfile_livelli << std::endl;
			myfile_livelli << " K_max_temp = " << K_max_temp << std::endl;
		}	
		KK.PLUS(K_max_temp - KK.K_M(),P,clus);
		
		Accoppiamenti_Parita BASE(KK,SS,m_max + 1);

		{
			myfile_1 << " N_hh = " << KK.D() << std::endl;
			std::cerr << " N_hh = " << KK.D() << std::endl;
			myfile_1 <<  "BASE.D_h()" << BASE.D_h() << std::endl;
			std::cerr << "Accoppiamenti_Iperangolari_K_max  T = " << t.elapsed() << std::endl;
			myfile << "Accoppiamenti_Iperangolari_K_max  T = " << t.elapsed() << std::endl;
			for (unsigned long i = 0; i < KK.D() ; ++i){
				myfile << i+1 << "	K = " << KK.k(i) << "	 n = [ ";
				for(unsigned short j = 0; j < KK.n(i).size() ; ++j){
					myfile << KK.n(i)[j];
					myfile << " ";
				}
				myfile << "]   l = [ ";
				for(unsigned short j = 0; j < KK.l(i).size() ; ++j){
					myfile << KK.l(i)[j];
					myfile << " ";
				}
				
				myfile << "]  L = [ ";
				for(unsigned short j = 0; j < KK.L(i).size() ; ++j){
					myfile << KK.L(i)[j];
					myfile << " ";
				}
				
				myfile << "]";
				
				myfile << "   parita = [ ";
				for(unsigned short j = 0; j < KK.P_l(i).size() ; ++j){
					myfile << KK.P_l(i)[j];
					myfile << " ";
				}
				myfile << "]	 somma quadra dei coefficienti dello sviluppo = ";
				myfile << quad_sum(KK.cm(i));				
				myfile << std::endl;
			}
			myfile << "Dimensione della base = " << KK.D() << " combinazioni." << std::endl;
			for (unsigned long i = 0; i < SS.D() ; ++i){
				myfile << i+1 << "	S = [ ";
				for(unsigned short j = 0; j < SS.D_S(i).size() ; ++j){
					myfile << SS.D_S(i)[j];
					myfile << "	";
				}
				myfile << "]	S_z = [ ";
				myfile << SS.D_Z(i);
				myfile << "	";
				myfile << "]";
				myfile << "	parita = [ ";
				for(unsigned short j = 0; j < SS.P_S(i).size() ; ++j){
					myfile << SS.P_S(i)[j];
					myfile << "	";
				}
				myfile << "]	 somma quadra dei coefficienti dello sviluppo = ";
				myfile << quad_sum(SS.cm(i));				
				myfile << std::endl;
			}
			myfile << "Dimensione della base - SPIN = " << SS.D() << " combinazioni." << std::endl;
		}
		boost::timer t1;
		{
			
			std::cerr << "Energia  T = " << t1.elapsed() << std::endl;
			myfile << "Energia  T = " << t1.elapsed() << std::endl;
			
		}
		int max_iter = 5*BASE.D();  
		myfile_tabella_p << K_max_temp << "	";
		myfile_tabella_d << K_max_temp << "	";
		myfile_tabella_p << BASE.D_h_p() << std::endl;
		myfile_tabella_d << BASE.D_h_d() << std::endl;

	}
	std::cerr << "Esecuzione  T = " << t6.elapsed() << std::endl;
	myfile << "Esecuzione  T = " << t6.elapsed() << std::endl;
	myfile.close();
	myfile_1.close();
	myfile_tabella.close();
	myfile_tabella_p.close();
	myfile_tabella_d.close();
	myfile_livelli.close();
	myfile_misurabili.close();
	
}