Exemple #1
0
int main(void) {
	int pause;
	char aWord[50];
	ifstream Words("c:\\Shakespear.txt",ios::in);
	if(!Words) {
		cerr << "Couldn't open the file" << endl;
		cin >> pause;
		return -1;
	}
Words AutoComplete::match(const utf8_string& str){
  WordsImpl* w = new WordsImpl();
  w->m_node = nullptr;

  if (str.empty()){
    return Words(w);
  }

  for (size_t i = 0; i != m_nodes.size(); i++){
    ACNode* node = m_nodes[i];
    if (node->m_char == str.front()){
      ACNode* found = node->find(str);
      if (found != nullptr){
        w->m_node = found;
        w->m_base = str;
        break;
      }
    }
  }
  return Words(w);
}
Exemple #3
0
void PrefixPogoda::on_word_update_pressed()
{
    int idx = ui->word_list->currentIndex().row();
    if(idx != -1 && ui->word_input->text() != "" && ui->word_des->text() != "") {
        words[idx] = Words (
                    ui->word_prefix->currentIndex() - 1,
                    ui->word_root->currentIndex() - 1,
                    ui->word_suffix->currentIndex() - 1,
                    ui->word_input->text(),
                    ui->word_des->text()
                    );
        (word_list.first)[idx] = removeSemi(ui->word_input->text());
        word_list.second->setStringList(word_list.first);
    }else {
        QMessageBox::warning(this, "Message", "Please select or add a word first",
                             QMessageBox::Ok);
    }
}
void LCGWSpinBBHNR1::LoadNRdata()
{
	char tmpLine[16384];
	std::vector<char*> Words(0);
	int l, m;
	char fNInHarm[16384];
	LCDataFileRead * tmpDataRead;
	int tmpNRec, tmpNRDataN;
	double tmpNRdatat0, tmpNRdatatend, tmpNRdatadt;
    int NHarmReq;
	

	
	if(ReadNRParam(NRFileName, mrat, eta, chi1, chi2, Phi0, FreqMax, omMInit, toMInitHyb, S1N, S2N, LnN)){
		Cout << "ERROR on LCGWSpinBBHNR1::LoadNRdata : Problem in openning NR main data file " << NRFileName << " ." << Endl;
		throw std::invalid_argument("ERROR on LCGWSpinBBHNR1::LoadNRdata : Problem in openning NR main data file.");
	}
		
	thS1 = S1N.th();
	phS1 = S1N.ph();
	thS2 = S2N.th();
	phS2 = S2N.ph();
	thL = LnN.th();
	phL = LnN.ph();
	
	
	std::ifstream fInMain(NRFileName);
	
	//! **** Pass through fixed parameters 
	int iLine(0);
	do{
		iLine++;
		fInMain.getline(tmpLine,16384,'\n');
		MT->wextract(tmpLine, Words);
	}while((!MT->wcmp(Words[0],"Harmonics"))&&(!fInMain.eof()));
	
	
    NHarmReq=0;
    if((MT->wcmp(Words[0],"Harmonics"))&&(Words.size()>=2)){
        NHarmReq = atoi(Words[1]);
    }else{
        Cout << "ERROR in LCGWSpinBBHNR1::LoadNRdata : We need to know the number of harmonics : 'Harmonics 6' (NEW format !!!)" << Endl;
        throw std::invalid_argument("ERROR in LCGWSpinBBHNR1::LoadNRdata : We need to know the number of harmonics : 'Harmonics 6' (NEW format !!!)" );
    }
    Cout << "Number of harmonics required = " << NHarmReq << Endl;        
    
	//! *** Find the number of harmonics
	lmax = 0;
	NHarm = 0;
	do{
		iLine++;
		fInMain.getline(tmpLine,16384,'\n');
		MT->wextract(tmpLine, Words);		
		l = atoi(Words[0]);
		if(l>lmax)
			lmax = l;
		NHarm++;
	}while((Words.size()>=3)&&(!fInMain.eof())&&(NHarm<NHarmReq));
    Cout << "Number of harmonics read = " << NHarm << Endl; 
 
    if(NHarmReq!=NHarm){
        Cout << "ERROR in LCGWSpinBBHNR1::LoadNRdata :  We do not have the required number of harmonics, " << NHarmReq << " . We found " << NHarm << "harmonics." << Endl;
        throw std::invalid_argument("ERROR in LCGWSpinBBHNR1::LoadNRdata : We do not have the required number of harmonics !" );
    }
	
	fInMain.close();
	fInMain.clear();
	
	
	//! *** Allow memory
	NRdata = (double***) MT->AllocMemory(NHarm*sizeof(double**));
	lHarm = (int*) MT->AllocMemory(NHarm*sizeof(int));
	mHarm = (int*) MT->AllocMemory(NHarm*sizeof(int));
	SpherHarmVal = (dcomplex*) MT->AllocMemory(NHarm*sizeof(dcomplex));
	
	
	//! *** Read harmonic files and load them 
	fInMain.open(NRFileName);
	do{
		fInMain.getline(tmpLine,16384,'\n');
		MT->wextract(tmpLine, Words);	
	}while((!MT->wcmp(Words[0],"Harmonics"))&&(!fInMain.eof()));
    
	for(int iHarm=0; iHarm<NHarm; iHarm++){

		fInMain.getline(tmpLine,16384,'\n');
		MT->wextract(tmpLine, Words);
		
		//Cout << tmpLine << " ==> " << Words[0] << " " << Words[1] << " " << Words[2] << Endl;
		
		lHarm[iHarm] = atoi(Words[0]);
		mHarm[iHarm] = atoi(Words[1]);
		
		tmpDataRead = new LCDataFileRead(MT, Words[2]);
		tmpDataRead->init(NRdata[iHarm], tmpNRec, tmpNRDataN);
		tmpNRdatat0 = tmpDataRead->getx0();
		tmpNRdatatend = tmpDataRead->getxend();
		tmpNRdatadt = tmpDataRead->getdx();
		delete tmpDataRead;
		
		/*
		for(int i=0; i<tmpNRDataN; i++){
			Cout << i ;
			for(int j=0; j<tmpNRec; j++){
				Cout << " " << NRdata[iHarm][j][i];
			}
			Cout << Endl;
		}
		*/
		
		
		
		
		if(tmpNRec != 2){
			Cout << "LCGWSpinBBHNR1::LoadNRdata : The data file should contain only 2 records." << Endl;
			throw std::invalid_argument("LCGWSpinBBHNR1::LoadNRdata : The data file should contain only 2 records.");
		}
		if(iHarm==0){
			NRdataN = tmpNRDataN;
			NRdatat0 = tmpNRdatat0;
			NRdatatend = tmpNRdatatend;
			NRdatadt = tmpNRdatadt;
		}else{
			if(NRdataN != tmpNRDataN){
				Cout << "LCGWSpinBBHNR1::LoadNRdata : The harmonic " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<") don't have the same number of data " << tmpNRDataN << " than the previous one " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<")  " << NRdataN << "  !" << Endl;
				throw std::invalid_argument("LCGWSpinBBHNR1::LoadNRdata : The harmonic don't have the same number of data than the previous one !");
			}
			if(fabs((NRdatat0-tmpNRdatat0)/(NRdatat0+tmpNRdatat0))>1.e-12){
				MT->o->precision(15);
				Cout << "LCGWSpinBBHNR1::LoadNRdata : The harmonic " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<") don't have the same initial time " << tmpNRdatat0 << " than the previous one " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<")  " << NRdatat0 << "  !" << Endl;
				throw std::invalid_argument("LCGWSpinBBHNR1::LoadNRdata : The harmonic don't have the same number of data than the previous one !");
			}
			if(fabs((NRdatatend-tmpNRdatatend)/(NRdatatend+tmpNRdatatend))>1.e-12){
				MT->o->precision(15);
				Cout << "LCGWSpinBBHNR1::LoadNRdata : The harmonic " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<") don't have the same final time " << tmpNRdatatend << " than the previous one " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<")  " << NRdatatend << "  !" << Endl;
				throw std::invalid_argument("LCGWSpinBBHNR1::LoadNRdata : The harmonic don't have the same number of data than the previous one !");
			}
			if(fabs((NRdatadt-tmpNRdatadt)/(NRdatadt+tmpNRdatadt))>1.e-12){
				MT->o->precision(15);
				Cout << "LCGWSpinBBHNR1::LoadNRdata : The harmonic " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<") don't have the same time step " << tmpNRdatadt << " than the previous one " <<iHarm<<" (l="<<lHarm[iHarm]<<",m="<<mHarm[iHarm]<<")  " << NRdatadt << "  !" << Endl;
				throw std::invalid_argument("LCGWSpinBBHNR1::LoadNRdata : The harmonic don't have the same number of data than the previous one !");
			}
		}
		MT->MemDisplay();
		
		//for(int i=0; i<10; i++)
		//	Cout << NRdata[iHarm][0][i] << " " << NRdata[iHarm][1][i] << Endl;
		
	}
	
	
	MemUse += NHarm * (sizeof(double**) + 2*sizeof(int) + sizeof(dcomplex) + 2*( NRdataN*sizeof(double) + sizeof(double*)) );
	
	
	for(int iW=0; iW<Words.size(); iW++)
		MT->Free(Words[iW],256*sizeof(char));
}
pword *
term_to_dbformat(pword *parg, dident mod)
{
    pword **save_tt = TT;
    register word arity = 1, len;
    register word curr_offset = 0, top_offset = 2;	/* in 'word's */
    register pword *queue_tail = (pword *) 0;
    pword *queue_head = (pword *) 0;
    register pword *pw;
    register char *dest, *stop;
    pword *header;
    temp_area	meta_attr;
    int		flag = 0;

    Temp_Create(meta_attr, 4 * ATTR_IO_TERM_SIZE * sizeof(pword));
    header = TG;
    dest = (char *) (header + 1) + 4;	/* space for the TBUFFER pword and for
					 * the external format header	*/

    for(;;)	/* handle <arity> consecutive pwords, starting at <parg> */
    {
	do	/* handle the pword pointed to by parg */
	{
	    pw = parg;

	    /* I need here a slightly modified version of Dereference_(pw)
	     * that stops also at MARKed words. Not very nice, I know.
	     */
	    while (IsRef(pw->tag) && !(pw->tag.kernel & MARK) && !IsSelfRef(pw))
		pw = pw->val.ptr;

	    Reserve_Space(6);

	    if (pw->tag.kernel & MARK)
	    {
		if (SameTypeC(pw->tag,TDE))		/* a suspension */
		{
		    Store_Byte(Tag(pw->tag.kernel));
		    Store_Int32((pw[SUSP_FLAGS].tag.kernel & ~MARK));
		    if (SuspDead(pw)) {
			curr_offset += Words(SUSP_HEADER_SIZE-1);
			parg += SUSP_HEADER_SIZE-1;
			arity -= SUSP_HEADER_SIZE-1;
		    } else {
			Store_Byte(SuspPrio(pw) + (SuspRunPrio(pw) << 4));
			curr_offset += Words(SUSP_GOAL-1);
			parg += SUSP_GOAL-1;
			arity -= SUSP_GOAL-1;
		    }
		}
		else if (pw->val.nint == curr_offset)	/* a nonstd variable */
		{
		    Store_Byte(Tag(pw->tag.kernel));
		    Store_Int(pw->val.nint);
		    if (!IsNamed(pw->tag.kernel))
		    {
			Store_Byte(0);
		    }
		    else		/* store its name */
		    {
			dident vdid = TagDid(pw->tag.kernel);
			len = DidLength(vdid);
			Store_Int(len);
			Reserve_Space(len);
			Store_String(len, DidName(vdid));
		    }
		}
		else	/* just a reference to an already encountered variable */
		{
		    Store_Byte(Tag(TVAR_TAG));
		    Store_Int(pw->val.nint);
		}
	    }
	    else switch (TagType(pw->tag))
	    {
	    case TINT:
#if SIZEOF_CHAR_P > 4
		if (pw->val.nint <  WSUF(-2147483648) || WSUF(2147483648) <= pw->val.nint)
		{
		    /* store as a bignum (to be readable on 32bit machines) */
		    len = tag_desc[pw->tag.kernel].string_size(pw->val, pw->tag, 1);
		    Store_Byte(TBIG);
		    Store_Int(len);
		    Reserve_Space(len+1);
		    stop = dest+len;
		    dest += tag_desc[pw->tag.kernel].to_string(pw->val, pw->tag,
			dest, 1);
		    while (dest <= stop)	/* pad and terminate */
		    	*dest++ = 0;
		    break;
		}
#endif
		Store_Byte(TINT);
#ifdef OLD_FORMAT
		Store_Int32(pw->val.nint);
#else
		Store_Int(pw->val.nint);
#endif
		break;

	    case TNIL:
		Store_Byte(Tag(pw->tag.kernel));
		break;

	    case TDICT:
		len = DidLength(pw->val.did);
		Store_Byte(TDICT);
		Store_Int(DidArity(pw->val.did));
		Store_Int(len);
		Reserve_Space(len);
		Store_String(len, DidName(pw->val.did));
		break;

	    case TDBL:
	    {
		ieee_double d;
		d.as_dbl = Dbl(pw->val);
		Store_Byte(TDBL);
		Store_Byte(sizeof(double)-1);	/* backward compat */
		Reserve_Space(sizeof(double));
		Store_Int32(d.as_struct.mant1);
		Store_Int32(d.as_struct.mant0);
		break;
	    }

	    case TIVL:
	    {
		ieee_double dlwb, dupb;
		dlwb.as_dbl = IvlLwb(pw->val.ptr);
		dupb.as_dbl = IvlUpb(pw->val.ptr);
		Store_Byte(TIVL);
		Reserve_Space(2*sizeof(double));
		Store_Int32(dlwb.as_struct.mant1);
		Store_Int32(dlwb.as_struct.mant0);
		Store_Int32(dupb.as_struct.mant1);
		Store_Int32(dupb.as_struct.mant0);
		break;
	    }

	    case TSTRG:
		len = StringLength(pw->val);
		Store_Byte(TSTRG);
		Store_Int(len);
		Reserve_Space(len);
		Store_String(len, StringStart(pw->val));
		break;

	    case TVAR_TAG:	/* standard variable */
		Store_Byte(Tag(TVAR_TAG));
		Store_Int(curr_offset);
		Trail_(pw);
		pw->val.nint = curr_offset;
		pw->tag.kernel |= MARK;
		break;

	    case TNAME:
	    case TUNIV:
		Store_Byte(Tag(TVAR_TAG));
		Store_Int(top_offset);
		Trail_Tag(pw);
		pw->val.nint = top_offset;
		pw->tag.kernel |= MARK;
		top_offset += 2;
		EnQueue_(pw, 1, 0);
		break;

	    case TMETA:
		Store_Byte(Tag(TVAR_TAG));
		Store_Int(top_offset);
		Trail_Tag(pw);
		pw->val.nint = top_offset;
		pw->tag.kernel |= MARK;
		top_offset += 4;
		EnQueue_(pw, 2, QUEUE_MASK_META);
		break;

	    case TSUSP:
		Store_Byte(Tag(TSUSP));
		pw = pw->val.ptr;
		if (pw->tag.kernel & MARK)	/* not the first encounter */
		{
		    Store_Int(pw->val.nint);
		}
		else
		{
		    Store_Int(top_offset);
		    Trail_Pword(pw);
		    pw->tag.kernel |= MARK;
		    pw->val.nint = top_offset;
		    if (SuspDead(pw))
		    {
			top_offset += Words(SUSP_HEADER_SIZE);	/* for TDE */
			EnQueue_(pw, SUSP_HEADER_SIZE, 0);
		    }
		    else
		    {
			top_offset += Words(SUSP_SIZE);	/* for TDE */
			EnQueue_(pw, SUSP_SIZE, 0);
		    }
		}
		break;

	    case TLIST:
		Store_Byte(Tag(TLIST));
		Store_Int(top_offset);
		top_offset += 4;
		EnQueue_(pw->val.ptr, 2, 0);
		break;

	    case TCOMP:
		Store_Byte(Tag(TCOMP));
		Store_Int(top_offset);
		if (flag) {
		    pword pw_out;
		    (void) transf_meta_out(pw->val, pw->tag,
			    (pword *) TempAlloc(meta_attr, ATTR_IO_TERM_SIZE * sizeof(pword)),
			    D_UNKNOWN, &pw_out);
		    pw = pw_out.val.ptr;
		    len = 1 + DidArity(pw->val.did);
		    EnQueue_(pw, len, 0);
		} else {
		    len = 1 + DidArity(pw->val.ptr->val.did);
		    EnQueue_(pw->val.ptr, len, 0);
		}
		top_offset += 2*len;
		break;

	    default:
		if (TagType(pw->tag) >= 0 && TagType(pw->tag) <= NTYPES)
		{
		    len = tag_desc[TagType(pw->tag)].string_size(pw->val, pw->tag, 1);
		    Store_Byte(Tag(pw->tag.kernel));
		    Store_Int(len);
		    Reserve_Space(len+1);
		    stop = dest+len;
		    dest += tag_desc[TagType(pw->tag)].to_string(pw->val, pw->tag,
			dest, 1);
		    while (dest <= stop)	/* pad and terminate */
		    	*dest++ = 0;
		}
		else
		{
		    p_fprintf(current_err_,
			"bad type in term_to_dbformat: 0x%x\n",
			pw->tag.kernel);
		}
		break;
	    }
	    curr_offset += Words(1);
	    ++parg;
	} while (--arity);
	if (EmptyQueue())
	    break;
	DeQueue_(parg, arity, flag);
    }
					/* # bytes of external representation */
    Store_Byte(0);			/* add a terminating 0		*/
    Set_Buffer_Size(header, dest - (char*) header - sizeof(pword));
    header->tag.kernel = TBUFFER;
    Align();				/* align the global stack pointer */
    TG = (pword *) dest;
    dest = (char *) (header + 1);	/* fill in the external format header */
    Store_Int32(top_offset);		/* (size of term after restoring) */
    Untrail_Variables(save_tt);
    Temp_Destroy(meta_attr);
    return header;
}
Exemple #6
0
/** \brief The executable compute the SNR curve and by product the GW and noise response
 * \author A. Petiteau
 * \version 2.0
 * \date 25/02/2011
 * 
 *
 *
 */
int main (int argc, char * const argv[])
{
	try {
		LCTools MT;
		int nOptions(0);
		char cmd[16384];
		
		long SeedRand((long)time(NULL));
		
		int Nsrc(1);
		int iNStart(0);
		int iRealiStudy(-1);
		int NRand(1);
		
		LCModSig X(&MT), Xp(&MT);
		
		X.Detector = LISA;
		X.GalacticNoise = false;
		X.sSrcType(SPINBBHHHARM);
		
		double SNRth(6.);
		char CharIndPar[1064];
		strcpy(CharIndPar, "None");
		int MCMCNStepMax(100000);
		double MCMCscale(1.);
		double MCMCheat(2.);
		int MCMCFIMRecomp(-1);
		
		
		//! *** Name of TDI observables
		char TDINameAll[16384];
		strcpy(TDINameAll, "X");
		//strcpy(TDINameAll, "Am,Em");
		
		
		// *********** Help *************
		if(((argc>1)&&(strcmp(argv[1],"--help")==0))||((argc>1)&&(strcmp(argv[1],"-h")==0))){
			Coutm << " ----- HELP -----" << Endl;
			Coutm << Endl << "\tExecution :" << Endl;
			Coutm << "\t\t(./)LC2 MCMC [Options] ConfigFile1.xml ConfigFile2.xml ..." << Endl;
			Coutm << Endl << "\tArguments :" << Endl;
			Coutm << Endl << "\t\t * ConfigFileI.xml (required) : Configuration fileX. " << Endl;
			Coutm << Endl << "\tOptions :" << Endl;
			Coutm << "\t\t * -o %sOutFile  : Output file containing results [default: SNRResultX.txt]"  << Endl ;
			
			Coutm << "\t\t * -G key  : Type of GW source. [default : MBHBInsPrecHH ] "  << Endl ;
			Coutm << "\t\t\t GB or GalBin        : galactic binary,"  << Endl ;
			Coutm << "\t\t\t SH or MBHBInsPrecHH : Massive black hole binary inspiral phase with spin precession and higher harmonicX."  << Endl ;
			Coutm << "\t\t * -C %sCatalog : Catalogue containing the list of parameters : if not random source. [default : None] "  << Endl ;
			Coutm << "\t\t * -N %dNSrc    : Number of sources to study (-1 : number of source in catalogue). [default : " << Nsrc << " ]"  << Endl ;
			Coutm << "\t\t * -f %diFSrc   : Fisrt source to study is iFSrc*NSrc. [default : "  << iNStart << "]"  << Endl ;
			Coutm << "\t\t * -R %diReali  : Study only the source from the realization %diReali (-1:not used). [default : "<< iRealiStudy << "]"  << Endl ;
			//Coutm << "\t\t * -r %dNrand   : Make Nrand randomization of free paramters for each source. [default : "<< NRand << "]"  << Endl ;
			
			Coutm << "\t\t * -dt %step : Minimal time step. [default : " << X.dtMesMin << "]"  << Endl ;
			
			Coutm << "\t\t * -D %dConfig : For computing analytic noise : LISA,C1,C2,C3,C4,C5 [default : LISA]"  << Endl ;
			Coutm << "\t\t * -cn         : Include analytic confusion noise  [default : None]"  << Endl ;
			
			
			Coutm << "\t\t * -tdi %sObsName : Names of TDI generators [default : " << TDINameAll << " ]"  << Endl ;
			//Coutm << "\t\t * -S %fSNRth : SNR threshold for selected for FIM compute [default : " << SNRth << "]"  << Endl ;
			Coutm << "\t\t * -P %diP1,%diP2  : Index of parameters to study ('L' before the index mean that we have to use the log). [default : 0,1,14,13,12,4,L5,L15,17,6,7,8,9,10,11 if src MBHBInsPrecHH , 0,1,2,3,L4,6,7 if src GalBin ]"  << Endl ;
			//Coutm << "\t\t * -cv %diP %fDeltaMin %fDeltaMax %fDeltaLogStep : Test convergence for parameter iP with value of Delta between DeltaMin and DeltaMax with step log step of DeltaLogStep [default : None]"  << Endl ;
			Coutm << "\t\t * -M %fMax %sDir : Maximum memory in RAM and directory for swaping [default : Max = " << X.gMaxMemRAM() << ", Dir = " << X.gDirSwapMem() << " ]"  << Endl ;
			
			Coutm << "\t\t * -n %dN : Maximal number of MCMC steps [default : " << MCMCNStepMax << "]"  << Endl ;
			Coutm << "\t\t * -E %fscale : Scale used for MCMC steps [default : " << MCMCscale << "]"  << Endl ;
			Coutm << "\t\t * -F %dFreqFIM : Frequency of FIM recomputation : recompute each %dFreqFIM MCMC accepted steps [default : " << MCMCFIMRecomp << "]"  << Endl ;
			
			
			Coutm << "\t\t * -co       : Write the check output fileX. [default : false]"  << Endl ;
			Coutm << "\t\t * -s %dseed : Seed for random gennerator. [default : current time]"  << Endl ;
			Coutm << "\t\t\t  NB: If not specified the random seed is the time machine." << Endl;
			Coutm << "\t\t * -dn \t\t: No screen display. [default: false]"  << Endl ;
			Coutm << "\t\t * -dl %sfile \t: Write standard output in a file. [default: no file]"  << Endl ;
			Coutm << "\t\t * -v \t\t: Verbose mode : display full details. [default: false]"  << Endl ;
			Coutm << "\t\t * -h \t\t: This help."  << Endl ;
			Coutm << "\t\t * -V \t\t: Version."  << Endl ;
			Coutm << Endl << " ----------------" << Endl;
			return 0;
			
		}
		
		// *********** Version *************
		if(((argc>1)&&(strcmp(argv[1],"--version")==0))||((argc>1)&&(strcmp(argv[1],"-V")==0))){
			Coutm << " ----- VERSION -----" << Endl;
			Coutm << " LC2MCMC : Compute the signal to noise ratio (SNR) and Fisher Matrix (FIM)   - LISACode package - version " << LC::LCVersion << " at " << LC::DateOfLastUpdate << Endl;
			Coutm << " ----------------" << Endl;
			return 0;
		}
		
		
		
		
		
		// ***** Main declaration *****
		
		
		//! *** Output (results) file
		char bNOut[16384];
		strcpy(bNOut, "ResMCMC");
		
		//! *** Catalogue and parameters of sources
		char fNInCatalogue[16384];
		int NRecCat(-1); 
		int NRowsCat(-1);
		std::ifstream fInCatalogue;
		int TypeCat(0);	// 0->standard, 1->result file 
		bool StopEndFile(true);
		std::string junk;
		bool CheckOutput(false);		
		std::vector<char*> Words(0);
		
		//! **** Selection parameters
		//! ** Threshold in mass ratio
		double qth(1./20.);
		qth = 1./50.;
		
		strcpy(fNInCatalogue, "None");
		
		//! *** For SNR, FIM, errors
		LCMatrix FIM;
		LCMatrix CovM;
		double SNR;
		double * Err(NULL);
		double * ptry(NULL);
		
		//! *** Data
		dcomplex ** fDat(NULL);
		int NfDat, NTDI, iFmin;
		double df;
		
		
		//! ********** Read options **********
		
		for(int iarg=1; iarg<argc; iarg++){
			
			if((argc>1)&&(strcmp(argv[iarg],"-o")==0)){
				// *** Read base name of output file in option
				strcpy(bNOut, argv[iarg+1]);
				nOptions +=2;
			}
			
			
			if((argc>1)&&(strcmp(argv[iarg],"-G")==0)){
				bool NotFound(true);
				if( (MT.wcmp(argv[iarg+1],"GB")) || (MT.wcmp(argv[iarg+1],"GalBin")) ){
					X.sSrcType(GALBIN);
					NotFound = false;
				}
				if( (MT.wcmp(argv[iarg+1],"SH")) || (MT.wcmp(argv[iarg+1],"MBHBInsPrecHH")) ){
					X.sSrcType(SPINBBHHHARM);
					NotFound = false;
				}
				if( (MT.wcmp(argv[iarg+1],"NR")) || (MT.wcmp(argv[iarg+1],"NRwave")) ){
					X.sSrcType(NRWAVE);
					NotFound = false;
				}
				if(NotFound){
					Coutm << "ERROR : The source type " << argv[iarg+1] << " is unknown !" << Endl;
					throw std::invalid_argument("ERROR : The source type is unknown !");
				}
				nOptions +=2;
			}
			
			if((argc>1)&&(strcmp(argv[iarg],"-C")==0)){
				strcpy(fNInCatalogue, argv[iarg+1]);
				nOptions +=2;
			}
			
			if((argc>1)&&(strcmp(argv[iarg],"-N")==0)){
				Nsrc = atoi(argv[iarg+1]);
				nOptions +=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-f")==0)){
				iNStart = atoi(argv[iarg+1]);
				nOptions +=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-R")==0)){
				iRealiStudy = atoi(argv[iarg+1]);
				nOptions +=2;
			}
			/*if((argc>1)&&(strcmp(argv[iarg],"-r")==0)){
			 NRand = atoi(argv[iarg+1]);
			 nOptions +=2;
			 }*/
			
			if((argc>1)&&(strcmp(argv[iarg],"-dt")==0)){
				X.dtMesMin = atof(argv[iarg+1]);
				nOptions +=2;
			}
			
			if((argc>1)&&(strcmp(argv[iarg],"-D")==0)){
				X.Detector = UNKNOWNDC;
				if(MT.wcmp(argv[iarg+1], "LISA")){
					X.Detector = LISA;
				}
				if(MT.wcmp(argv[iarg+1], "ELISA")){
					X.Detector = ELISA;
				}
				if(MT.wcmp(argv[iarg+1], "C1")){
					X.Detector = C1;
				}
				if(MT.wcmp(argv[iarg+1], "C2")){
					X.Detector = C2;
				}
				if(MT.wcmp(argv[iarg+1], "C3")){
					X.Detector = C3;
				}
				if(MT.wcmp(argv[iarg+1], "C4")){
					X.Detector = C4;
				}
				if(MT.wcmp(argv[iarg+1], "C5")){
					X.Detector = C5;
				}
				
				if(X.Detector == UNKNOWNDC)
					throw std::invalid_argument("Unknow type of detector.");
				nOptions +=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-cn")==0)){
				X.GalacticNoise = true;
				nOptions ++;
			}
			
			
			if((argc>1)&&(strcmp(argv[iarg],"-tdi")==0)){
				strcpy(TDINameAll, argv[iarg+1]);
				nOptions +=2;
			}
			
			/*if((argc>1)&&(strcmp(argv[iarg],"-S")==0)){
			 SNRth = atof(argv[iarg+1]);
			 nOptions +=2;
			 }*/
			
			
			if((argc>1)&&(strcmp(argv[iarg],"-P")==0)){
				//! **** Read list of parameters to study
				strcpy(CharIndPar, argv[iarg+1]);
				nOptions +=2;
			}
			
			/*if((argc>1)&&(strcmp(argv[iarg],"-cv")==0)){
			 if(argc-iarg<4)
			 throw std::invalid_argument("ERROR : Need 4 parameters for testing the convergence !");
			 ConviP = atoi(argv[iarg+1]);
			 ConvDMin = atof(argv[iarg+2]);
			 ConvDMax = atof(argv[iarg+3]);
			 ConvDLogStep = atof(argv[iarg+4]);
			 NConvStep = MT.ifloor((log10(ConvDMax)-log10(ConvDMin))/ConvDLogStep);
			 nOptions += 5;
			 }*/
			
			if((argc>1)&&(strcmp(argv[iarg],"-M")==0)){
				if(argc-iarg<4)
					throw std::invalid_argument("ERROR : Need 2 parameters (path of directory and max RAM size) for configuring swap !");
				X.sSwap(argv[iarg+2], atof(argv[iarg+1]));
				nOptions +=3;
			}
			
			if((argc>1)&&(strcmp(argv[iarg],"-n")==0)){
				MCMCNStepMax = atoi(argv[iarg+1]);
				nOptions +=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-E")==0)){
				MCMCscale = atof(argv[iarg+1]);
				nOptions +=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-F")==0)){
				MCMCFIMRecomp = atoi(argv[iarg+1]);
				nOptions +=2;
			}
			
			if((argc>1)&&(strcmp(argv[iarg],"-co")==0)){
				CheckOutput = true;
				nOptions++;
			}
			
			if((argc>1)&&(strcmp(argv[iarg],"-s")==0)){
				SeedRand = atoi(argv[iarg+1]);
				nOptions +=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-dn")==0)){
				MT.unsetDisp();
				nOptions++;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-dl")==0)){
				MT.setDispInFile(argv[iarg+1],true);
				nOptions+=2;
			}
			if((argc>1)&&(strcmp(argv[iarg],"-v")==0)){
				MT.setDispDetails();
				nOptions++;
			}
		} 
		MT.setRandSeed(SeedRand);
		
		
		//! **********  Configuration  **********
		
		//! ***** Decode a char string to obtain the list of parameters to study 
		if(MT.wcmp(CharIndPar, "None")){
			if(X.gSrcType()==SPINBBHHHARM)
				strcpy(CharIndPar, "0,1,14,13,12,4,L5,L15,17,6,7,8,9,10,11");
			if(X.gSrcType()==GALBIN)
				strcpy(CharIndPar, "0,1,2,3,L4,6,7");
		}
		X.sParStudy(CharIndPar);
		
		//! ***** Read configuration files in arguments
		for(int ia=1+nOptions; ia<argc; ia++){
			X.addfCfg(argv[ia]);
		}
		
		// ***** Display for checking which files we are using
		Coutm << "Configuration files : " << Endl;
		for(int i=0; i<X.NfNCfg; i++){
			Coutm << "\t + " << X.fNCfg[i] ; MT.CheckFile("", X.fNCfg[i]);
		}
		
		//! *** Read the bloc name of TDI generators and obtain the individual names and the number of generators
		X.sTDI(TDINameAll);
		Coutm << "TDI generators : ";
		for(int i=0; i<X.gNTDI(); i++)
			Coutm << " " << X.gTDIName(i);
		Coutm << Endl;
		
		
		
		//! **********  Initialization  **********
		
		X.AllocBaseMem();
		Xp.CopyBase(X);
		
		
		FIM.init(&MT, X.gNParStudy(), X.gNParStudy());
		CovM.init(&MT, X.gNParStudy(), X.gNParStudy());
		Err = (double*) MT.AllocMemory(X.gNParStudy()*sizeof(double));
		for(int i=0; i<X.gNParStudy();  i++)
			Err[i] = 0.;
		
		
		//! **** Open and analyse the catalogue
		if(!MT.wcmp(fNInCatalogue,"None")){
			Coutm << "Open the catalogue file " << fNInCatalogue << " ... " << Endl;
			fInCatalogue.open(fNInCatalogue);
			if(!fInCatalogue)
				throw std::invalid_argument("Problem in openning parameters file.");
			
			//! ** Count number of record
			while(fInCatalogue.peek() == '#')
				fInCatalogue.ignore(16384,'\n');
			NRecCat = 0;
			while((fInCatalogue.peek() != '\n')&&(!fInCatalogue.eof())){
				fInCatalogue >> junk;
				if(fInCatalogue.peek() == ' '){
					int ipos(fInCatalogue.tellg());
					ipos++;
					fInCatalogue.seekg(ipos);
				}
				NRecCat++;
			}
			fInCatalogue.close();
			fInCatalogue.clear();
			
			
			//! ** Count the number of rows
			fInCatalogue.open(fNInCatalogue);
			char fCatHead[16384];
			while(fInCatalogue.peek() == '#')
				fInCatalogue.getline(fCatHead, 16384,'\n');
			MT.wextract(fCatHead, Words);
			if(Words[4][0]=='z')
				TypeCat = 1;
			NRowsCat = 0;
			while(!fInCatalogue.eof()){
				fInCatalogue.ignore(16384,'\n');
				if(!fInCatalogue.eof()){	
					NRowsCat++;
				}
			}
			fInCatalogue.close();
			fInCatalogue.clear();
			if(Nsrc == -1)
				Nsrc = NRowsCat;
		}
		
		if(NRecCat!=-1){
			fInCatalogue.open(fNInCatalogue);
			while(fInCatalogue.peek() == '#')
				fInCatalogue.ignore(16384,'\n');
			if(iNStart*Nsrc<NRowsCat){
				int iS(0);
				while((!fInCatalogue.eof())&&(iS < iNStart*Nsrc)){
					fInCatalogue.ignore(16384,'\n');
					iS++;
				}
			}
		}
		
		
		//! ***** Prepare the result output file
		
		//! ** Common part
		int iTitCol(0);
		int iTitColBase(0);
		char TitColBase[10000];
		if(X.gSrcType()==SPINBBHHHARM){
			strcpy(TitColBase,"#realID[1] srcID[2] Name[3] iStep[4] z[5] M1[6] q[7] lamS[8] betS[9] phL[10] thL[11] phi0[12] tc[13] a1[14] a2[15] thS1[16] thS2[17] phS1[18] phS2[19] per[20] e[21] DL0[22] Mcz[23] eta[24] thBS1[25] thBS2[26] phBS1[27] phBS2[28]");
			iTitColBase = 29;
		}
		if(X.gSrcType()==GALBIN){
			strcpy(TitColBase,"#realID[1] srcID[2] Name[3] iStep[4] M1[5] M2[6] P[7] Pdot[8] e[9] i[10] lam[11] bet[12] d[13] psi[14] Amp[15] f[16] fdot[17] phi0[18]");
			iTitColBase = 19;
		}
		if(X.gSrcType()==NRWAVE){
			strcpy(TitColBase,"#realID[1] srcID[2] Name[3] RandID[4] z[5] M1[6] q[7] lamS[8] betS[9] phL[10] thL[11] phi0[12] tc[13] a1[14] a2[15] thS1[16] thS2[17] phS1[18] phS2[19] per[20] e[21] DL0[22] Mcz[23] eta[24] thBS1[25] thBS2[26] phBS1[27] phBS2[28]");
			iTitColBase = 29;
		}
		
		//! *** Open file containing error FIM results and write header
		char fNOutErr[10000];
		sprintf(fNOutErr,"%s-Err.txt",bNOut);
		std::ofstream fOutErr(fNOutErr);
		iTitCol = iTitColBase;
		fOutErr << TitColBase;
		for(int i=0; i<X.gNTDI(); i++)
		for(int iP=0; iP<X.gNParStudy(); iP++){
			fOutErr << " Par" << X.giParStudy(iP) << "[" << iTitCol++ << "]";
			fOutErr << " Err" << X.giParStudy(iP) << "[" << iTitCol++ << "]";
		}
		fOutErr << " Likelihood[" << iTitCol++ << "]" << Endl;
		fOutErr.precision(12);
		
		
		//! *** Open FIM output file and write header
		char fNOutFIM[10000];
		sprintf(fNOutFIM, "%s-FIM.txt", bNOut);
		std::ofstream fOutFIM(fNOutFIM);
		iTitCol = iTitColBase;
		fOutFIM << TitColBase;
		for(int iP1=0; iP1<X.gNParStudy(); iP1++)
			for(int iP2=0; iP2<X.gNParStudy(); iP2++)
				fOutFIM << " FIM" << X.giParStudy(iP1) << X.giParStudy(iP2) << "[" << iTitCol++ << "]";
		for(int iP1=0; iP1<X.gNParStudy(); iP1++)
			for(int iP2=0; iP2<X.gNParStudy(); iP2++)
				fOutFIM << " CovM" << X.giParStudy(iP1) << X.giParStudy(iP2) << "[" << iTitCol++ << "]";
		fOutFIM << Endl;
		fOutFIM.precision(12);
		
		
		//! *** Open MCMC output file and write header
		char fNOutMCMC[10000];
		sprintf(fNOutMCMC, "%s-MCMC.txt", bNOut);
		std::ofstream fOutMCMC(fNOutMCMC);
		iTitCol = iTitColBase;
		fOutMCMC << TitColBase << " LogL[" << iTitCol << "] MCMCratio[" << iTitCol+1 << "] MCMCRand[" << iTitCol+2 << "] Accepted[" << iTitCol+3 << "]";
		iTitCol += 4;
		for(int iP=0; iP<X.gNParStudy(); iP++)
			fOutMCMC << " pTry" << X.giParStudy(iP) << "[" << iTitCol++ << "]"; 
		fOutMCMC << Endl;
		fOutMCMC.precision(12);
			
		//! ********** Main part : loop on sources **********
		
		int iSrc(0);
		bool CContinue(true);
		while(CContinue){
			
			int realID(-1), srcID(iSrc);
			double  z(0.), M1(0.), q(0.), betS(0.), lamS(0.), phL(0.), thL(0.), phi0(0.), tc(0.), a1(0.), a2(0.), thS1(0.), thS2(0.), phS1(0.), phS2(0.), per(0.), ecc(0.), DL0(0.), DL0d(0.), Mcz(0.), eta(0.), thBS1(0.), thBS2(0.), phBS1(0.), phBS2(0.);
			char srcName[100];
			double lamSd(0.), betSd(0.), M2(0.), Period(0.), Pdot(0.), inc(0.), incd(0.), psi(0.), Amp(0.), freq(0.), fdot(0.);
			char StrParam[10000];
			
			time_t tstart, tendSNR, tend;
			
			
			//! **** Read source in catalogue
			if((NRecCat!=-1)&&(!fInCatalogue.eof())){
				if(X.gSrcType()==SPINBBHHHARM){
					if(NRecCat>15){
						int iRStart(26);
						//! ** All parameters are in the catalogue
						fInCatalogue >> realID >> srcID;
						if(TypeCat==1){
							fInCatalogue >> junk >> junk;
							iRStart += 2;
						}
						fInCatalogue >> z >> M1 >> q >> lamS >> betS >> phL >> thL >> phi0 >> tc >> a1 >> a2 >> thS1 >> thS2 >> phS1 >> phS2 >> per >> ecc >> DL0d >> Mcz >> eta >> thBS1 >> thBS2 >> phBS1 >> phBS2;
						Coutm << phBS2 << Endl;
						for(int iR=iRStart; iR<NRecCat; iR++){
							fInCatalogue >> junk;
							//Coutm << iR << " --> " << junk << Endl;
						}
						if(TypeCat==1)
							DL0d *= 1.e-3; //! Converion from kpc to Mpc because we use Mpc as input and we write kpc so when we use output of previous run as catalogue, we have to convert
						
					}else{
						//! ** Some parameters are in the catalogue but not the 
						fInCatalogue >> realID >> srcID >> z >> M1 >> q  >> lamSd >> betSd >> phL >> thL >> phi0 >> tc >> DL0d >> Mcz >> eta;
					}
					sprintf(srcName,"Real%d-%d", realID, srcID);
				}