//	This source and compression method apply to GNU General Public License. 
//		Copyright (C) August , 2010 and later by Jasenko Dzinleski 

//		This program is free software; you can redistribute it
//	and/or modify it under the terms of the GNU General Public License as
//	published by the Free Software Foundation; either version 2 of the
//	License, or (at your option) any later version. 

//	This program is distributed in the hope that it will be useful, but
//	WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//	General Public License for more details. 

//	You should have received a copy of the GNU General Public License along
//	with this program; if not, write to the Free Software Foundation, Inc.,
//	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

//
//			
//			written by Dzinleski Jasenko August , 15 , 2010
//			
//
//			to Dusica and Dzinleski Borce
//
//



#include 	<stdio.h>
#include 	<string.h>
#include 	<math.h>

#define		BuffL				64 	//(128)
#define		BtM				8*256
#define		TBEnd				8

int		b12=((0xffff>>4 )<<4 );
int		b11=((0xffff>>5 )<<5 );
int		b10=((0xffff>>6 )<<6 );
int		b09=((0xffff>>7 )<<7 );
int		b08=((0xffff>>8 )<<8 );
int		b07=((0xffff>>9 )<<9 );
int		b06=((0xffff>>10)<<10);
int		b05=((0xffff>>11)<<11);
int		b04=((0xffff>>12)<<12);

char 		infn[256]="CL2001011101AA.CEL";
char		outfn[256]="t_.txt";
char		outxfn[256]="xd.txt";

char		out1fn[256]="1_.mar";
char		out2fn[256]="2_.mar";
char		out3fn[256]="3_.mar";
char		out4fn[256]="4_.mar";

FILE		*f1,*f2,*f3,*f4,*f5,*f6;

int 		ba16[16][16][16][16][3];		int	ba16i=0;

__int64 	fc=0;
int 		bl08[16][256];				int	bl08i=0;

int		mm[16][3];				
int		md[16][30000][2];			
int		mdi[16];

int		ddf[70000][2];				int	ddfi=0;
int		dd[70000][4];				int	ddi=0;
int		ca[BuffL];				int 	cai=0;
bool		br[BtM];				int	bri=0;
bool		bt32_1[32];				int	bt32i_1=0;
bool		bt32_2[32];				int	bt32i_2=0;

__int64	bitc=0,bc=0,fb=0;
int		bytc=0,bytc1=0;

bool		df=false;
bool		nf=false;
bool		o_f=false;

char		c_l[256]="{[--]}{[hh][ee][cc][dd]}{[AZ][az][09][__][  ][..]}";

double 		mult_=1;
char		n_s[256];
char		p_s[256];

int p_format(double in_n,char fm[256],char arr0[256])
{

int		sig;
char		arr1[256];
double 		iv,fv;
__int64	lv,rv;
char		fa[256];int	fai=0;
int		i,j,k,l,m,n,e;


	if(in_n<0){sig=1;in_n*=-1.0;iv=in_n;}else{sig=0;iv=in_n;}

	for(i=0;i<256;++i){fa[i]='\0';}fai=0;
	for(j=0;j<256;++j){arr0[j]='\0';}

	for(i=1;i<12;++i)
	{
		lv=(long)iv/pow(10,i);//printf("%d %d %d\n",lv,i,(long)pow(10,i));
		if(lv==0){e=i-1;break;}
	}
	if(i==12){printf("Overflow...\n");arr0[0]='0';return(0);}

	if(e-1<0)
	{
		rv=(long)iv/pow(10,e);//printf("!%c",(char)(48+rv));
		fa[fai]=(char)(48+rv);++fai;

	}else{

	rv=(long)iv/pow(10,e);//printf("!%c",(char)(48+rv));
	fa[fai]=(char)(48+rv);++fai;
	rv*=pow(10,e);fv=(long)iv-rv;
	for(i=e-1;i>=0;--i)
	{
		lv=(long)fv/pow(10,i);//printf("!%c",(char)(48+lv));
		fa[fai]=(char)(48+lv);++fai;
		rv+=lv*pow(10,i);fv=iv;fv-=rv;
	}

	}

	//printf("%s\n",fa);

	if(strlen(fm)!=0)
	{

		m=0;l=strlen(fm);
		for(i=strlen(fm)-1;i>=0;--i)
		{if(fm[i]==','||fm[i]=='.'){if(l==strlen(fm)){l=i+1;++m;}else{++m;}}}
		k=(strlen(fm)-((strlen(fm)-l)+m))-strlen(fa);

		if(k>=0)
		{

			j=0;for(i=0;i<k;++i)
			{if(fm[i]=='.'||fm[i]==','){++k;}arr0[j]=fm[i];++j;}n=i;

			for(i=0;i<strlen(fa);++i)
			{
				if(fm[i+n]=='.'||fm[i+n]==','){arr0[j]=fm[i+n];++j;++n;}
				arr0[j]=fa[i];++j;
			}
				
			if(l!=strlen(fm))
			{
				--l;arr0[j]=fm[l];++j;
				for(i=l+1;i<strlen(fm);++i){arr0[j]=fm[i];++j;}

				iv=in_n;
				for(i=0;i<256;++i){fa[i]='\0';}fai=0;

				iv=pow(10,(strlen(fm)-(l+1)))*(iv-(double)((long)iv));

				for(i=1;i<12;++i)
				{
					lv=(long)iv/pow(10,i);//printf("%d %d %d\n",lv,i,(long)pow(10,i));
					if(lv==0){e=i-1;break;}
				}
				if(i==12){printf("Overflow...\n");arr0[0]='0';return(0);}

				if(e-1<0)
				{
					rv=(long)iv/pow(10,e);//printf("!%c",(char)(48+rv));
					fa[fai]=(char)(48+rv);++fai;

				}else{

				rv=(long)iv/pow(10,e);//printf("!%c",(char)(48+rv));
				fa[fai]=(char)(48+rv);++fai;
				rv*=pow(10,e);fv=(long)iv-rv;
				for(i=e-1;i>=0;--i)
				{
					lv=(long)fv/pow(10,i);//printf("!%c",(char)(48+lv));
					fa[fai]=(char)(48+lv);++fai;
					rv+=lv*pow(10,i);fv=iv;fv-=rv;
				}

				}

				//printf("s\n",fa);

				if((strlen(fm)-(l+1))==strlen(fa))
				{

				for(i=strlen(arr0)-1;i>=0;--i)
				{if(arr0[i]=='.'||arr0[i]==','){j=i;break;}}++j;
				for(i=0;i<strlen(fa);++i){arr0[j]=fa[i];++j;}

				}else{

					k=(strlen(fm)-(l+1))-strlen(fa);
					for(i=strlen(arr0)-1;i>=0;--i)
					{if(arr0[i]=='.'||arr0[i]==','){j=i;break;}}++j;
					for(i=0;i<k;++i){arr0[j]='0';++j;}
					for(i=0;i<strlen(fa);++i){arr0[j]=fa[i];++j;}

				}

			}

		}else{

			k=strlen(fa)-(strlen(fm)-((strlen(fm)-l)+m));
			j=0;for(i=0;i<k;++i){arr0[j]=fa[i];++j;}n=i;
			
			for(i=n;i<strlen(fa);++i)
			{
				if(fm[i-n]=='.'||fm[i-n]==','){arr0[j]=fm[i-n];++j;--n;}
				arr0[j]=fa[i];++j;
			}

			if(l!=strlen(fm))
			{
				--l;arr0[j]=fm[l];++j;
				for(i=l+1;i<strlen(fm);++i){arr0[j]=fm[i];++j;}

				iv=in_n;
				for(i=0;i<256;++i){fa[i]='\0';}fai=0;

				iv=pow(10,(strlen(fm)-(l+1)))*(iv-(double)((long)iv));

				for(i=1;i<12;++i)
				{
					lv=(long)iv/pow(10,i);//printf("%d %d %d\n",lv,i,(long)pow(10,i));
					if(lv==0){e=i-1;break;}
				}
				if(i==12){printf("Overflow...\n");arr0[0]='0';return(0);}

				if(e-1<0)
				{
					rv=(long)iv/pow(10,e);//printf("!%c",(char)(48+rv));
					fa[fai]=(char)(48+rv);++fai;

				}else{

				rv=(long)iv/pow(10,e);//printf("!%c",(char)(48+rv));
				fa[fai]=(char)(48+rv);++fai;
				rv*=pow(10,e);fv=(long)iv-rv;
				for(i=e-1;i>=0;--i)
				{
					lv=(long)fv/pow(10,i);//printf("!%c",(char)(48+lv));
					fa[fai]=(char)(48+lv);++fai;
					rv+=lv*pow(10,i);fv=iv;fv-=rv;
				}

				}

				//printf("s\n",fa);

				if((strlen(fm)-(l+1))==strlen(fa))
				{

				for(i=strlen(arr0)-1;i>=0;--i)
				{if(arr0[i]=='.'||arr0[i]==','){j=i;break;}}++j;
				for(i=0;i<strlen(fa);++i){arr0[j]=fa[i];++j;}

				}else{

					k=(strlen(fm)-(l+1))-strlen(fa);
					for(i=strlen(arr0)-1;i>=0;--i)
					{if(arr0[i]=='.'||arr0[i]==','){j=i;break;}}++j;
					for(i=0;i<k;++i){arr0[j]='0';++j;}
					for(i=0;i<strlen(fa);++i){arr0[j]=fa[i];++j;}

				}
				
			}

		}

	}else{

		j=0;for(i=0;i<strlen(fa);++i){arr0[j]=fa[i];++j;}

	}

	for(i=0;i<strlen(arr0);++i){if(arr0[i]=='#'){arr0[i]=' ';}}
	for(i=0;i<strlen(arr0)-1;++i){if((arr0[i]==' ')&&(arr0[i+1]==','||arr0[i+1]=='.')){arr0[i+1]=' ';}}

	if(sig==1)
	{
		for(i=0;i<256;++i){arr1[i]='\0';}
		j=0;arr1[j]='-';++j;
		for(i=0