src/BWRRelax/relaxanalyze.cc
// ______________________________________________________________________
// ********** RELAXATION MATRIX OUTPUT ELEMENT STRING FUNCTIONS *********
// ______________________________________________________________________
RELAXATION MATRIX OUTPUT ELEMENT STRING FUNCTIONS
RELAXATION MATRIX OUTPUT ELEMENT STRING FUNCTIONS
void Rel(std::ostream& ostr, int nterms, std::string* line1, std::string* line2,
	   std::string* line3, int* signs, std::string* Elabel, int add, int ncols)
                               m        m                       m        m
                         - <a|T |b><a'|T |b'> J  (w    ) - <b'|T |a'><b|T |a> J  (w  )
	     	                 1        2      sl  b'a'         1        2     sl  ab
                                                   ---                                      ]
                                                   \               m        m               |
                                                +  /   delta   <g|T |a'><g|T |b'> J  (w   ) |
	     	                                     ---      a,b    1        2      sl  b'g  |
                                                    g                                       ]
    {
    std::string slab[3];					 Array of labels for the signs
    slab[0] = std::string(" - ");				 These will be sign labels
    slab[1] = std::string(" + ");
    slab[2] = std::string("   ");
    std::string sgnspace(3, ' ');				 Spaces the length of printed sign
    std::string elab[3];					 Array of labels for the matrix
    if(add)						 If terms just added to previously
      {							 printed ones, no label, just spaces
      elab[0] = std::string(abs(add)+2, ' ');		 Note that three extra spaces are added
      elab[1] = std::string(abs(add)+2, ' ');		 due to the idea that a " =" was used
      elab[2] = std::string(abs(add)+2, ' ');		 in an earlier printed lines
      }
    else
      {							 Label is to be added in output
      elab[0] = Elabel[0] + std::string(2, ' ');		 Tack on 2 spaces here because of " ="
      elab[1] = Elabel[1] + std::string(" = ");		 Add an " = " to end of input label
      elab[2] = Elabel[2] + std::string(2, ' ');		 Tack on 2 spaces here because of " ="
      }
    std::string espace(elab[1].length(), ' ');		 Space the length of the "label"
    if(!add && !nterms) 				 If the label is to be printed
      {							 yet there are no terms, then just state
      ostr << "\n" << elab[0];			 	 that it is indeed zero
      ostr << "\n" << elab[1] << std::string("0");
      ostr << "\n" << elab[2];
      }
    int term = 0;
    int term, ntermi = 0;
    int i, j;
    for(i=0; i<nterms; i+=ncols)
      {
      ostr << "\n";					 Skip down to Line 1
      for(j=0,term=i; j<ncols && term<nterms; j++)	 Print out Line 1, column j 
        { 						 	If 1st column and 1st term  
        if(j==0 && i==0 && !add) ostr << elab[0]; 		and label added, print the label
	  else if(j==0)  ostr << espace;		 	line 1, else spaces if 1st column
        ostr << sgnspace << line1[term];			Now output spaces for sign and term
        term++;							Increment term count
        }
      ostr << "\n";					 Skip down to Line 2
      for(j=0,term=i; j<ncols && term<nterms; j++)	 Print out Line 2, column j
        { 						 	If 1st column and 1st term  
        if(j==0 && i==0 && !add) ostr << elab[1];	 	and not added, print the label
        else if(j==0) ostr << espace; 			 	line 2, else spaces if 1st column
        if(signs[term])					 Now put in a + or - sign unless it
          { 						 is a positive sign following a label
          if(j==0 && i==0 && !add) ostr << slab[2];		Put out no sign
          else ostr << slab[1];					Put out a + sign
          }
        else ostr << slab[0];				 	Put out a - sign
        ostr << line2[term];					Now output the term
        term++;							Increment term count
        }
      ostr << "\n";					 Skip down to Line 3
      for(j=0,term=i; j<ncols && term<nterms; j++)	 Print out Line 3, column j
        { 						 	If 1st column and 1st term  
        if(j==0 && i==0 && !add) ostr << elab[2]; 		and label added, print the label
	  else if(j==0) ostr << espace;			 	line 3, else spaces if 1st column
        ostr << sgnspace << line3[term];			Now output spaces for sign and term
        term++;							Increment term count
        }
      }
    return;
    }
void Rel ( std :: ostream & ostr , int nterms , std :: string * line1 , std :: string * line2 , std :: string * line3 , int * signs , std :: string * Elabel , int add , int ncols ) { std :: string slab [ 3 ] ; slab [ 0 ] = std :: string ( " " ) ; slab [ 1 ] = std :: string ( " " ) ; slab [ 2 ] = std :: string ( " " ) ; std :: string sgnspace ( 3 , ' ' ) ; std :: string elab [ 3 ] ; if ( add ) { elab [ 0 ] = std :: string ( abs ( add ) + 2 , ' ' ) ; elab [ 1 ] = std :: string ( abs ( add ) + 2 , ' ' ) ; elab [ 2 ] = std :: string ( abs ( add ) + 2 , ' ' ) ; } else { elab [ 0 ] = Elabel [ 0 ] + std :: string ( 2 , ' ' ) ; elab [ 1 ] = Elabel [ 1 ] + std :: string ( " " ) ; elab [ 2 ] = Elabel [ 2 ] + std :: string ( 2 , ' ' ) ; } std :: string espace ( elab [ 1 ] . length ( ) , ' ' ) ; if ( ! add && ! nterms ) { ostr << " \n " << elab [ 0 ] ; ostr << " \n " << elab [ 1 ] << std :: string ( " " ) ; ostr << " \n " << elab [ 2 ] ; } int term = 0 ; int i , j ; for ( i = 0 ; i < nterms ; i += ncols ) { ostr << " \n " ; for ( j = 0 , term = i ; j < ncols && term < nterms ; j ++ ) { if ( j == 0 && i == 0 && ! add ) ostr << elab [ 0 ] ; else if ( j == 0 ) ostr << espace ; ostr << sgnspace << line1 [ term ] ; term ++ ; } ostr << " \n " ; for ( j = 0 , term = i ; j < ncols && term < nterms ; j ++ ) { if ( j == 0 && i == 0 && ! add ) ostr << elab [ 1 ] ; else if ( j == 0 ) ostr << espace ; if ( signs [ term ] ) { if ( j == 0 && i == 0 && ! add ) ostr << slab [ 2 ] ; else ostr << slab [ 1 ] ; } else ostr << slab [ 0 ] ; ostr << line2 [ term ] ; term ++ ; } ostr << " \n " ; for ( j = 0 , term = i ; j < ncols && term < nterms ; j ++ ) { if ( j == 0 && i == 0 && ! add ) ostr << elab [ 2 ] ; else if ( j == 0 ) ostr << espace ; ostr << sgnspace << line3 [ term ] ; term ++ ; } } return ; }
______________________________________________________________________
 RELAXATION MATRIX OUTPUT ELEMENT STRING FUNCTIONS
______________________________________________________________________
______________________________________________________________________ RELAXATION MATRIX OUTPUT ELEMENT STRING FUNCTIONS ______________________________________________________________________
// Input		ostr  : An output stream //      		nterms: Number of terms contributing to <a,aa|R|b,bb> //			line1 : strings for the upper line of the printed element //			line2 : strings for the middle line of the printed element //			line3 : strings for the lower line of the printed element //			signs : Flags for the signs of the components //			Elabel: Relaxation matrix element label //			add   : Flag for whether to add lines or not //				       add = 0  -> Print Element Label //				       add >= 0 -> Don't Print Label, Its Been Done //						   Label had length of add //			cols  : Number of columns to print out // Output		void  : The contribution to <a,a'|R|b,b'> from the //				mechanisms ss and spins sl are sent into //				the output stream ostr. // Note			      : T1s, T2s are assumed in their proper bases // In this routine, the nterms components that contribute to a particular // relaxation matrix element are sent into the output stream ostr.  The element // can be over many relaxation mechanisms, one pair of mechanisms, or one pair of // mechanism in which only particular spins are involved.  This is determined by // the formation of the input string arrays which are generated with other routines // in this module.  Also, the number of terms, or equivalently, how detailed the // element is characterized is also determined by how the string arrays are constructed. //                   --- [ --- //        ss         \   | \                 m       m  // <a,a'|R  |b,b'> = /   | /   delta     <a|T |g><b|T |g> J  (w  ) //	  sl         --- | ---      a',b'    1       2     sl  gb //		      m  [  g // //                               m        m                       m        m //                         - <a|T |b><a'|T |b'> J  (w    ) - <b'|T |a'><b|T |a> J  (w  ) //	     	                 1        2      sl  b'a'         1        2     sl  ab // //                                                   ---                                      ] //                                                   \               m        m               | //                                                +  /   delta   <g|T |a'><g|T |b'> J  (w   ) | //	     	                                     ---      a,b    1        2      sl  b'g  | //                                                    g                                       ] // Array of labels for the signs // These will be sign labels // Spaces the length of printed sign // Array of labels for the matrix // If terms just added to previously // printed ones, no label, just spaces // Note that three extra spaces are added // due to the idea that a " =" was used // in an earlier printed lines // Label is to be added in output // Tack on 2 spaces here because of " =" // Add an " = " to end of input label // Tack on 2 spaces here because of " =" // Space the length of the "label" // If the label is to be printed // yet there are no terms, then just state // that it is indeed zero //    int term, ntermi = 0; // Skip down to Line 1 // Print out Line 1, column j  // 	If 1st column and 1st term   //	and label added, print the label // 	line 1, else spaces if 1st column //	Now output spaces for sign and term //	Increment term count // Skip down to Line 2 // Print out Line 2, column j // 	If 1st column and 1st term   // 	and not added, print the label // 	line 2, else spaces if 1st column // Now put in a + or - sign unless it // is a positive sign following a label //	Put out no sign //	Put out a + sign // 	Put out a - sign //	Now output the term //	Increment term count // Skip down to Line 3 // Print out Line 3, column j // 	If 1st column and 1st term   //	and label added, print the label // 	line 3, else spaces if 1st column //	Now output spaces for sign and term //	Increment term count