/* The coefficient file "koeff_compr_bis_10.dat.gz" that you can download */
/* from this site contains all non zero coefficients C(m) upto and */
/* including order ten for the effective Hamiltonian published in Eur. Phys. */
/* J. B 13, 209-225 (2000) in Eq. (25a). Note that these coefficients apply */
/* for the case N=2 in Eq. (2) of that paper. */

/* The file "koeff_compr_bis_10.dat.gz"  is twofold compressed: */
/* We used standard gzip, which you can gunzip straightforwardly. (Refer to */
/* manuals to find out about the compatibility of your unzip-tool to */
/* gunzip.) After you will have unzipped the downloaded file you end up with a */
/* file that is still compressed by means of symmetry relations (here */
/* we refer to Eqs. (18a) and (18b) in the paper). For your convenience we */
/* provide the programme  "coeff_inflate.c" , which uses the above mentioned */
/* symmetry relations to construct the file "coeff_inflated.dat", which */
/* contains all needed coefficients C(m). This file can be used as an */
/* input file for any further programme of yours. */

/* The programme "coeff_inflate.c" is written in ANSI-C code. You should be */
/* able to compile it with any usual C-compiler. We recommend to compile the */
/* programme with some kind of optimisation to enhance the run time */
/* performance. Once the compilation is finished you can start the */
/* decompression by i.e.: */

/*   a.out name_of_the_symmetry-compressed_but_unzip_coefficient_file */

/* Some words about the format "coeff_inflate" uses to represent the */
/* coefficients C(m) in the output_file "coeff_inflated.dat": */
/* One line in "coeff_inflated.dat" reads */

/*         m C(m) */

/* That means, if  m = m_1,m_2,..,m_i,..,m_k and C(m) = P/Q the output is */

/*         m_1m_2...m_i...m_k P/Q */


/* The programme should be well commented. */
/* We hope you can find your way through it. */

/* Important notes: */ 
/*            1) Your computer system MUST use an */
/*               ASCII-character-table because we make use of */
/*               char to int conversions like: int i = char c - '0' */
/*               and things like that */
/*            2) Your compiler system MUST be able to */
/*               work with variable type long long  int */
/*               or something  similar to be capable to */
/*               treat very big integer numbers as */
/*               they appear in the coefficients */



/* If anything goes wrong or does not work do not hesitate to */
/* contact us: */
/* email: gu@thp.uni-koeln.de  or  */
/*        ck@thp.uni-koeln.de */






/*some headers*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>



/*declare some global variables*/
int s_1[10],s_2[10],s_3[10],ti[10],j,i,i_previous,x;
long long int P,Q;




/*A function needed. For definition see end of source text*/
int potenz_m1(int exp);
















int main(int argc, char *argv[])
{
  /*FILE-pointer declarations for input and output files*/
  FILE *dat_input, *dat_output;

  
  /*check if the programme was startet correctly*/
  if(argc != 2)
    {
      printf("\nUsage: <inflate_program_name> <compressed_coefficients_file_name> !!!\n\n"),fflush(stdout);
      exit(1);
    }
      
  
  
  
  /* open the file specified by the first (and only) argument, which */
  /*contains the compressed coefficients */
  dat_input = fopen(argv[1], "r");
  if (dat_input == NULL)
    printf("\nFile error, cannot open input file %s\n",argv[1]),exit(1);
  
  
  /*open the output file*/
  dat_output = fopen("coeff_inflated.dat", "w");
  if (dat_output == NULL)
    printf("\nFile error, cannot open output file\n"),exit(1);
  
  
  
  /*get the first character from the input file*/
  x=getc(dat_input);
  







  i=0;

  /*main-loop: Read the file as long as the end is not reached*/
  while(x != EOF)
    {
      /*safe the value of the order of the current line in i_previous*/
      i_previous=i;
      

      i=0; /*i counts the order (length) of the current m*/

      
      /*initialize the ti vector*/
      j=0;
      while(j < 10)
	{
	  ti[j]=0;
	  ++j;
	}


      /*read in the Multiindex m and store it in vector ti[]*/
      while(x != ' ')
	{
	  if(x == '-')
	    {
	      x=getc(dat_input);
	      ti[i]=-(x-'0');
	    }
	  else
	    ti[i]=x-'0';
	  x=getc(dat_input);
	  ++i;
	}


      /*now there are two blanks left to be read*/
      x=getc(dat_input);
      x=getc(dat_input);



      /*read numerator and denominator associated to the current m*/
      fscanf(dat_input,"%lld/%lld",&P,&Q);



      /*this lines enshures that all unnecessary characters are ignored*/
      x=getc(dat_input);
      while((x < 45) && (x != EOF))
	x=getc(dat_input);
      /*maybe x is now EOF then the next while condition will stop the prog*/
      /*otherwise x contains the next importend value*/

    

      /*if the current line contains m and c(m) of the next order*/
      /*print a blank line in the output_file*/
      if(i > i_previous)
	fprintf(dat_output,"\n"),fflush(dat_output);





      /*write m, -m, m~ and -m~ to the output file*/
      /*the applied format is: <m> <numerator>/<denominator>*/
      /*example: 020000-2 -5/128  for a 7th order m, c(m)*/
      


      /*First write out m*/
      j=0;
      while(j < i)  /*remember: i is the currend order=length of m*/
	{
	  fprintf(dat_output,"%d",ti[j]),fflush(dat_output);
	  ++j;
	}
      fprintf(dat_output," %lld/%lld\n",P,Q),fflush(dat_output);





      /*initialize the s_i vectors*/
      j=0;
      while(j < 10)
	{
	  s_1[j]=0;
	  s_2[j]=0;
	  s_3[j]=0;
	  ++j;
	}






      /*calculate -m and store it in vector s_1[]*/
      j=0;
      while(j < i)
	{
	  s_1[j]=-ti[j];
	  ++j;
	}
      
      /*is m = -m, if so do not print -m, else print -m*/
      if(s_1[0]==ti[0]&&s_1[1]==ti[1]&&s_1[2]==ti[2]&&s_1[3]==ti[3]&&s_1[4]==ti[4]&&s_1[5]==ti[5]&&s_1[6]==ti[6]&&s_1[7]==ti[7]&&s_1[8]==ti[8]&&s_1[9]==ti[9])
	;
      else
	{	
	  j=0;
	  while(j < i) /*remember: i is the currend order=length of m*/
	    {
	      fprintf(dat_output,"%d",s_1[j]),fflush(dat_output);
	      ++j;
	    }
	  fprintf(dat_output," %lld/%lld\n",potenz_m1(i+1)*P,Q),fflush(dat_output);
	}













      /*calculate -m~ and store it in vector s_2[]*/
      j=0;
      while(j < i)
	{
	  s_2[j]=-ti[i-1-j];
	  ++j;
	}

      /*is -m~ = -m or m, if so do not print -m~, else print -m~*/
      if((s_2[0]==s_1[0]&&s_2[1]==s_1[1]&&s_2[2]==s_1[2]&&s_2[3]==s_1[3]&&s_2[4]==s_1[4]&&s_2[5]==s_1[5]&&s_2[6]==s_1[6]&&s_2[7]==s_1[7]&&s_2[8]==s_1[8]&&s_2[9]==s_1[9]) || (s_2[0]==ti[0]&&s_2[1]==ti[1]&&s_2[2]==ti[2]&&s_2[3]==ti[3]&&s_2[4]==ti[4]&&s_2[5]==ti[5]&&s_2[6]==ti[6]&&s_2[7]==ti[7]&&s_2[8]==ti[8]&&s_2[9]==ti[9]))
	; 
      else 
	{
	  j=0;
	  while(j < i) /*remember: i is the currend order=length of m*/
	    {
	      fprintf(dat_output,"%d",s_2[j]),fflush(dat_output);
	      ++j;
	    }
	  fprintf(dat_output," %lld/%lld\n",P,Q),fflush(dat_output);
	}











      /*calculate m~*/
      j=0;
      while(j < 10)
	{
	  s_3[j]=ti[i-1-j];
	  ++j;
	}

      /*is m~ = -m or -m~ or m, if so do not print m~, else print m~*/
      if((s_3[0]==s_1[0]&&s_3[1]==s_1[1]&&s_3[2]==s_1[2]&&s_3[3]==s_1[3]&&s_3[4]==s_1[4]&&s_3[5]==s_1[5]&&s_3[6]==s_1[6]&&s_3[7]==s_1[7]&&s_3[8]==s_1[8]&&s_3[9]==s_1[9]) || (s_3[0]==s_2[0]&&s_3[1]==s_2[1]&&s_3[2]==s_2[2]&&s_3[3]==s_2[3]&&s_3[4]==s_2[4]&&s_3[5]==s_2[5]&&s_3[6]==s_2[6]&&s_3[7]==s_2[7]&&s_3[8]==s_2[8]&&s_3[9]==s_2[9]) || (s_3[0]==ti[0]&&s_3[1]==ti[1]&&s_3[2]==ti[2]&&s_3[3]==ti[3]&&s_3[4]==ti[4]&&s_3[5]==ti[5]&&s_3[6]==ti[6]&&s_3[7]==ti[7]&&s_3[8]==ti[8]&&s_3[9]==ti[9]))
	;	
      else
	{
	  j=0;
	  while(j < i) /*remember: i is the currend order=length of m*/
	    {
	      fprintf(dat_output,"%d",s_3[j]),fflush(dat_output);
	      ++j;
	    }
	  fprintf(dat_output," %lld/%lld\n",potenz_m1(i+1)*P,Q),fflush(dat_output);
	  
	}
    }



  /*close the opened files*/
  fclose(dat_input);
  
  fprintf(dat_output,"\n"),fflush(dat_output);
  
  fclose(dat_output);
  return 0;
}


/*definition of the potenz-function*/
int potenz_m1(int exp)
{
  int erg;
  
  if(exp % 2 == 0)
    return(1);
  else
    return(-1);
}
