示例#1
0
int Tmlex::readCall(Ttoken &token)
{
    int   ch   = Dinput.get();
    Tstr  posn = Dinput.posn();
    char *pos  = Dbuff;

    while ((EOF != ch) && ('\n' != ch) && (SEP_CALL != ch))
    {
        if (SEP_S_VAR == ch)
        {
            // Posible var
            if (!readVar()) *(pos++) = ch;
        }
        else
        {
            *(pos++) = ch;
        }
        ch = Dinput.get();
    }
    *pos = '\0';

    if (SEP_CALL != ch)
    {
        printE("%s : Unterminated text\n", (char const*)posn);
        if (EOF != ch) Dinput.putBack(ch);
    }

    token.setType(TOK_CALL);
    token.setText(Dbuff);

    return(1);
}
示例#2
0
int readvar_(char *fname, int len)
{ int err;
  char * cname=malloc(len+1);
  fName2c(fname,cname,len);
  err=readVar(cname);
  free(cname);
  return err;
}
示例#3
0
static int w_mdl__(FILE * mode)
{
  int i;

  fprintf(mode,"\n"); 
  for (i = 1; i <= nvar_int; ++i) fprintf(mode,"%10s = %.15E\n",varName_int[i],readVar(i));
  fprintf(mode,"----\n"); 
  return 0;
}
示例#4
0
int main(int argc,char** argv)
{ 
  int err,outP;
  double M,Emin,Ntot,Etot,sigmaV,v=0.001,fi,tab[250];
  
  char mess[100];
  char txt[100];

  if(argc==1)
  {
     printf(" The program needs 1 argument:\n"
            "name of file with parameters\n");
     exit(1);
  }

  err=readVar(argv[1]);
  if(err==-1)     {printf("Can not open the file\n"); exit(2);}
  else if(err>0)  { printf("Wrong file contents at line %d\n",err);exit(3);}


  outP=0;    /* for gamma rays */  
  Emin=0.1;  /* Erergy cut     */
  fi=0;      /* angle of sight */                                                                                                                                                                         

  err=sortOddParticles(mess); 
   if(err) { printf("Can't calculate %s\n",mess); return 1;}  

  sigmaV=calcSpectrum(v,outP,tab,&err);  /* sigma*v in cm^3/sec */    
  
  M=lopmass_();

  spectrInfo(Emin/M,tab, &Ntot,&Etot); 
  sprintf(txt,"%s: N=%.2e,<E/2M>=%.2f,vsc=%.2e sm^3/sec,M(%s)=%.2e", 
  outNames[outP],Ntot,Etot,sigmaV,mess,M); 

  spectrTable(tab,"tab",txt, Emin/M ,300);

  system("../CalcHEP_src/bin/tab_view < tab&");

  
  printf("gamma flux [ph/cm^2/s/sr] =%.2E\n",
        HaloFactor(fi,rhoQisotermic)*sigmaV*Ntot/M/M);
        
{ double e[6];
  int i;
  printf("Check of energy conservation:\n"); 
  for(i=0;i<6;i++)
  {    
     sigmaV=calcSpectrum(v,i,tab,&err);
     spectrInfo(Emin/M,tab, NULL,e+i);
  } 
  printf("1 = %.2f\n",e[0]+2*(e[1]+e[2]+e[3]+e[4]+e[5]) );
}     

  return 0;
}
示例#5
0
int Logic::getSync() {
	uint32 id = readVar(ID);

	for (int i = 0; i < ARRAYSIZE(_syncList); i++) {
		if (_syncList[i].id == id)
			return i;
	}

	return -1;
}
示例#6
0
void Logic::sendSync(uint32 id, uint32 sync) {
	for (int i = 0; i < ARRAYSIZE(_syncList); i++) {
		if (_syncList[i].id == 0) {
			debug(5, "%d sends sync %d to %d", readVar(ID), sync, id);
			_syncList[i].id = id;
			_syncList[i].sync = sync;
			return;
		}
	}

	// The original code didn't even check for this condition, so maybe
	// it should be a fatal error?

	warning("No free sync slot");
}
示例#7
0
int Tmlex::readVar()
{
    TstrBuf buff;

    int           ch   = Dinput.get();
    Tstr          posn = Dinput.posn();
    unsigned long pos  = 0;

    if ('{' == ch)
    {
        ch = Dinput.get();
        while (isIdent(ch) || (SEP_S_VAR == ch)) // 009
        {
            if (SEP_S_VAR == ch)                  // 009
            {
                readVar();  // Recursivly expand the variable
            }
            else
            {
                buff[pos++] = ch;
            }
            ch = Dinput.get();
        }
        buff[pos++] = '\0';

        if ('}' != ch)
        {
            // Bad variable name
            Dinput.putBack((char const*)buff);
            Dinput.putBack('{');
            return(0);
        }
        else
        {
            // Look up the variable and do a put back on its value
            substitute((char const*)buff);

            return(1);
        }
    }
    else
    {
        // Bad variable name
        Dinput.putBack(ch);
        return(0);
    }
}
示例#8
0
void NSParser::readVarList(Symbol *symbol, QStringList& varList)
{
	if (symbol->type == NON_TERMINAL)
	{
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		for(Symbol* child: nt->children)
		{
			switch(child->symbolIndex)
			{
				case SYM_VAR:
					varList << readVar(child);
					break;
				case SYM_VARLIST:
					readVarList(child, varList);
					break;
			}
		}
	}
}
示例#9
0
bool NSParser::readRectVar(Symbol* symbol, VariableList &variables, QRectF &r)
{
	bool result = false;
	QString varName = readVar(symbol);
	if (variables.contains(varName))
	{
		DeclaredVariable& var = variables[varName];
		if (var.isRect())
		{
			r = var.toRect();
			result = true;
		}
		else
			addError(NSParsingError::invalidVariableTypeError(varName, "rect", symbol));
	}
	else
		addError(NSParsingError::undeclaredVariableError(varName, symbol));

	return result;
}
示例#10
0
bool NSParser::readAx12Var(Symbol *symbol, NSParser::VariableList &variables, int &ax12Id)
{
	bool result = false;
	QString varName = readVar(symbol);
	if (variables.contains(varName))
	{
		DeclaredVariable& var = variables[varName];
		if (var.isAx12())
		{
			ax12Id = var.toAx12();
			result = true;
		}
		else
			addError(NSParsingError::invalidVariableTypeError(varName, "ax12", symbol));
	}
	else
		addError(NSParsingError::undeclaredVariableError(varName, symbol));

	return result;
}
示例#11
0
bool NSParser::readActionVar(Symbol *symbol, NSParser::VariableList &variables, int &actionId, int &param, int &time)
{
	bool result = false;
	QString varName = readVar(symbol);
	if (variables.contains(varName))
	{
		DeclaredVariable& var = variables[varName];
		if (var.isAction())
		{
			var.toAction(actionId, param, time);
			result = true;
		}
		else
			addError(NSParsingError::invalidVariableTypeError(varName, "action", symbol));
	}
	else
		addError(NSParsingError::undeclaredVariableError(varName, symbol));

	return result;
}
示例#12
0
bool NSParser::readPointVar(Symbol* symbol, VariableList& variables, Tools::RPoint &point)
{
	bool result = false;
	QString varName = readVar(symbol);
	if (variables.contains(varName))
	{
		DeclaredVariable& var = variables[varName];
		if (var.isPoint())
		{
			point = var.toPoint();
			result = true;
		}
		else
			addError(NSParsingError::invalidVariableTypeError(varName, "point", symbol));
	}
	else
		addError(NSParsingError::undeclaredVariableError(varName, symbol));

	return result;
}
示例#13
0
bool NSParser::readSensorVar(Symbol *symbol, NSParser::VariableList &variables, int &sensorType, int &id)
{
	bool result = false;
	QString varName = readVar(symbol);
	if (variables.contains(varName))
	{
		DeclaredVariable& var = variables[varName];
		if (var.isSensor())
		{
			var.toSensor(id, sensorType);
			result = true;
		}
		else
			addError(NSParsingError::invalidVariableTypeError(varName, "sensor", symbol));
	}
	else
		addError(NSParsingError::undeclaredVariableError(varName, symbol));

	return result;
}
示例#14
0
bool NSParser::readStringVar(Symbol *symbol, NSParser::VariableList &variables, QString &str)
{
	bool result = false;
	QString varName = readVar(symbol);
	if (variables.contains(varName))
	{
		DeclaredVariable& var = variables[varName];
		if (var.isString())
		{
			str = var.toString();
			result = true;
		}
		else
			addError(NSParsingError::invalidVariableTypeError(varName, "string", symbol));
	}
	else
		addError(NSParsingError::undeclaredVariableError(varName, symbol));

	return result;
}
示例#15
0
void ScummEngine_v70he::o70_readINI() {
	byte option[256];
	byte *data;
	const char *entry;
	int len, type;

	convertMessageToString(_scriptPointer, option, sizeof(option));
	len = resStrLen(_scriptPointer);
	_scriptPointer += len + 1;

	type = pop();
	switch (type) {
	case 1: // number
		if (!strcmp((char *)option, "NoPrinting")) {
			push(1);
		} else if (!strcmp((char *)option, "TextOn")) {
			push(ConfMan.getBool("subtitles"));
		} else {
			push(ConfMan.getInt((char *)option));
		}
		break;
	case 2: // string
		entry = (ConfMan.get((char *)option).c_str());

		writeVar(0, 0);
		len = resStrLen((const byte *)entry);
		data = defineArray(0, kStringArray, 0, len);
		memcpy(data, entry, len);

		push(readVar(0));
		break;
	default:
		error("o70_readINI: default type %d", type);
	}
	debug(1, "o70_readINI: Option %s", option);
}
示例#16
0
bool NSParser::readCallArg(Symbol *symbol, VariableList &variables, NSParser::DeclaredVariable& callArgVariable)
{
	bool result = true;
	switch(symbol->symbolIndex)
	{
		case SYM_VAR:
		{
			QString name = readVar(symbol);
			if (variables.contains(name))
				callArgVariable = variables[name];
			else
			{
				addError(NSParsingError::undeclaredVariableError(name, symbol));
				result = false;
			}
			break;
		}
		case SYM_POINT:
		case SYM_FIXED_POINT:
		{
			Tools::RPoint p = readPoint(symbol);
			callArgVariable = DeclaredVariable::fromPoint(p);
			break;
		}
		case SYM_RECT2:
		case SYM_FIXED_RECT:
		{
			QRectF r = readRect(symbol, variables);
			callArgVariable = DeclaredVariable::fromRect(r);
			break;
		}
		case SYM_SENSOR_IDENTIFIER:
		{
			int type = -1, id = 0;
			readSensorIdentifier(symbol, type, id);
			callArgVariable = DeclaredVariable::fromSensor(id, type);
			break;
		}
		case SYM_PARAMETER_IDENTIFIER:
		{
			int paramId = readSubId(symbol);
			callArgVariable = DeclaredVariable::fromParameter(paramId);
			break;
		}
		case SYM_AX12_IDENTIFIER:
		{
			int ax12Id = readSubId(symbol);
			callArgVariable = DeclaredVariable::fromAx12(ax12Id);
			break;
		}
		case SYM_ACTION2:
		{
			int actionId, param, time;
			readAction(symbol, actionId, param, time);
			callArgVariable = DeclaredVariable::fromAction(actionId, param, time);
			break;
		}
		case SYM_STRING:
		{
			QString str = readString(symbol);
			callArgVariable = DeclaredVariable::fromString(str);
			break;
		}
		case SYM_CALLARG:
		{
			if (symbol->type == NON_TERMINAL)
			{
				result = false;
				NonTerminal* nt = static_cast<NonTerminal*>(symbol);
				for(Symbol* child: nt->children)
				{
					readCallArg(child, variables, callArgVariable);
					if (callArgVariable.isValid())
					{
						result = true;
						break;
					}

				}
			}
		}
	}

	return result;
}
示例#17
0
int main(int argc,char** argv)
{   int err;
    char cdmName[10];
    int spin2, charge3,cdim;

    ForceUG=0;  // to Force Unitary Gauge assign 1

    if(argc==1)
    {
        printf(" Correct usage:  ./main  <file with parameters> \n");
        printf("Example: ./main data1.par\n");
        exit(1);
    }

    err=readVar(argv[1]);

    if(err==-1)     {
        printf("Can not open the file\n");
        exit(1);
    }
    else if(err>0)  {
        printf("Wrong file contents at line %d\n",err);
        exit(1);
    }



    err=sortOddParticles(cdmName);



    if(err) {
        printf("Can't calculate %s\n",cdmName);
        return 1;
    }

    qNumbers(cdmName, &spin2, &charge3, &cdim);
    printf("\nDark matter candidate is '%s' with spin=%d/2\n",
           cdmName,       spin2);
    if(charge3) {
        printf("Dark Matter has electric charge %d*3\n",charge3);
        exit(1);
    }
    if(cdim!=1) {
        printf("Dark Matter ia a color particle\n");
        exit(1);
    }
#ifdef MASSES_INFO
    {
        printf("\n=== MASSES OF HIGG AND ODD PARTICLES: ===\n");
        printHiggs(stdout);
        printMasses(stdout,1);
    }
#endif


#ifdef HIGGSBOUNDS
    if(access(HIGGSBOUNDS "/HiggsBounds",X_OK )) system( "cd " HIGGSBOUNDS "; ./configure; make ");
    HBblocks("HB.in");
    system(HIGGSBOUNDS "/HiggsBounds  LandH SLHA 1 0 HB.in HB.out > hb.stdout");
    slhaRead("HB.out",1+4);
    printf("HB result= %.0E  obsratio=%.2E\n",slhaValFormat("HiggsBoundsResults",0.,"1 2 %lf"), slhaValFormat("HiggsBoundsResults",0.,"1 3 %lf" )  );
    {   char hbInfo[100];
        if(0==slhaSTRFormat("HiggsBoundsResults","1 5 ||%[^|]||",hbInfo)) printf("Channel: %s\n",hbInfo);
    }
#endif

#ifdef HIGGSSIGNALS
#define DataSet " latestresults "
//#define Method  " peak "
//#define  Method " mass "
#define  Method " both "
#define PDF  " 2 "  // Gaussian
//#define PDF " 1 "  // box
//#define PDF " 3 "  // box+Gaussia
#define dMh " 2 "
    printf("HiggsSignals:\n");
    if(access(HIGGSSIGNALS "/HiggsSignals",X_OK )) system( "cd " HIGGSSIGNALS "; ./configure; make ");
    system("rm -f HS.in HS.out");
    HBblocks("HS.in");
    system(HIGGSSIGNALS "/HiggsSignals" DataSet Method  PDF  " SLHA 1 0 HS.in > hs.stdout");
    system("grep -A 10000  HiggsSignalsResults HS.in > HS.out");
    slhaRead("HS.out",1+4);
    printf("  Number of observables %.0f\n",slhaVal("HiggsSignalsResults",0.,1,7));
    printf("  total chi^2= %.1E\n",slhaVal("HiggsSignalsResults",0.,1,12));
    printf("  HS p-value = %.1E\n", slhaVal("HiggsSignalsResults",0.,1,13));
#undef dMh
#undef PDF
#undef Method
#undef DataSet

#endif


#ifdef OMEGA
    {   int fast=1;
        double Beps=1.E-5, cut=0.01;
        double Omega,Xf;
        int i;

// to exclude processes with virtual W/Z in DM   annihilation
        VZdecay=0;
        VWdecay=0;
        cleanDecayTable();

// to include processes with virtual W/Z  also  in co-annihilation
//   VZdecay=2; VWdecay=2; cleanDecayTable();

        printf("\n==== Calculation of relic density =====\n");
        Omega=darkOmega(&Xf,fast,Beps);
        printf("Xf=%.2e Omega=%.2e\n",Xf,Omega);
        printChannels(Xf,cut,Beps,1,stdout);

//   VZdecay=1; VWdecay=1; cleanDecayTable();  // restore default

    }
#endif


#ifdef INDIRECT_DETECTION
    {
        int err,i;
        double Emin=1,/* Energy cut  in GeV   */  sigmaV;
        double vcs_gz,vcs_gg;
        char txt[100];
        double SpA[NZ],SpE[NZ],SpP[NZ];
        double FluxA[NZ],FluxE[NZ],FluxP[NZ];
        double * SpNe=NULL,*SpNm=NULL,*SpNl=NULL;
        double Etest=Mcdm/2;

        printf("\n==== Indirect detection =======\n");

        sigmaV=calcSpectrum(4,SpA,SpE,SpP,SpNe,SpNm,SpNl ,&err);
        /* Returns sigma*v in cm^3/sec.     SpX - calculated spectra of annihilation.
           Use SpectdNdE(E, SpX) to calculate energy distribution in  1/GeV units.

           First parameter 1-includes W/Z polarization
                           2-includes gammas for 2->2+gamma
                           4-print cross sections
        */
        printf("sigmav=%.2E[cm^3/s]\n",sigmaV);


        if(SpA)
        {
            double fi=0.1,dfi=0.05; /* angle of sight and 1/2 of cone angle in [rad] */

            gammaFluxTab(fi,dfi, sigmaV, SpA,  FluxA);
            printf("Photon flux  for angle of sight f=%.2f[rad]\n"
                   "and spherical region described by cone with angle %.2f[rad]\n",fi,2*dfi);
#ifdef SHOWPLOTS
            sprintf(txt,"Photon flux[cm^2 s GeV]^{1} at f=%.2f[rad], cone angle %.2f[rad]",fi,2*dfi);
            displaySpectrum(FluxA,txt,Emin,Mcdm);
#endif
            printf("Photon flux = %.2E[cm^2 s GeV]^{-1} for E=%.1f[GeV]\n",SpectdNdE(Etest, FluxA), Etest);
        }

        if(SpE)
        {
            posiFluxTab(Emin, sigmaV, SpE,  FluxE);
#ifdef SHOWPLOTS
            displaySpectrum(FluxE,"positron flux [cm^2 s sr GeV]^{-1}" ,Emin,Mcdm);
#endif
            printf("Positron flux  =  %.2E[cm^2 sr s GeV]^{-1} for E=%.1f[GeV] \n",
                   SpectdNdE(Etest, FluxE),  Etest);
        }

        if(SpP)
        {
            pbarFluxTab(Emin, sigmaV, SpP,  FluxP  );
#ifdef SHOWPLOTS
            displaySpectrum(FluxP,"antiproton flux [cm^2 s sr GeV]^{-1}" ,Emin, Mcdm);
#endif
            printf("Antiproton flux  =  %.2E[cm^2 sr s GeV]^{-1} for E=%.1f[GeV] \n",
                   SpectdNdE(Etest, FluxP),  Etest);
        }
    }
#endif

#ifdef RESET_FORMFACTORS
    {
        /*
           The user has approach to form factors  which specifies quark contents
           of  proton and nucleon via global parametes like
              <Type>FF<Nucleon><q>
           where <Type> can be "Scalar", "pVector", and "Sigma";
                 <Nucleon>     "P" or "N" for proton and neutron
                 <q>            "d", "u","s"

           calcScalarFF( Mu/Md, Ms/Md, sigmaPiN[MeV], sigma0[MeV])
           calculates and rewrites Scalar form factors
        */
        printf("\n======== RESET_FORMFACTORS ======\n");

        printf("protonFF (default) d %.2E, u %.2E, s %.2E\n",ScalarFFPd, ScalarFFPu,ScalarFFPs);
        printf("neutronFF(default) d %.2E, u %.2E, s %.2E\n",ScalarFFNd, ScalarFFNu,ScalarFFNs);

//  To restore default form factors of  version 2  call
//  calcScalarQuarkFF(0.553,18.9,55.,243.5);

        calcScalarFF(0.553,18.9,70.,35.);

        printf("protonFF (new)     d %.2E, u %.2E, s %.2E\n",ScalarFFPd, ScalarFFPu,ScalarFFPs);
        printf("neutronFF(new)     d %.2E, u %.2E, s %.2E\n",ScalarFFNd, ScalarFFNu,ScalarFFNs);


    }
#endif

#ifdef CDM_NUCLEON
    {   double pA0[2],pA5[2],nA0[2],nA5[2];
        double Nmass=0.939; /*nucleon mass*/
        double SCcoeff;
        int i;
        printf("\n==== Calculation of CDM-nucleons amplitudes  =====\n");
        nucleonAmplitudes(CDM1,NULL, pA0,pA5,nA0,nA5);
        printf("CDM[antiCDM]-nucleon micrOMEGAs amplitudes:\n");
        printf("proton:  SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",pA0[0], pA0[1],  pA5[0], pA5[1] );
        printf("neutron: SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",nA0[0], nA0[1],  nA5[0], nA5[1] );

        SCcoeff=4/M_PI*3.8937966E8*pow(Nmass*Mcdm/(Nmass+ Mcdm),2.);
        printf("CDM[antiCDM]-nucleon cross sections[pb]:\n");
        printf(" proton  SI %.3E [%.3E] SD %.3E [%.3E]\n",
               SCcoeff*pA0[0]*pA0[0],SCcoeff*pA0[1]*pA0[1],3*SCcoeff*pA5[0]*pA5[0],3*SCcoeff*pA5[1]*pA5[1]);
        printf(" neutron SI %.3E [%.3E] SD %.3E [%.3E]\n",
               SCcoeff*nA0[0]*nA0[0],SCcoeff*nA0[1]*nA0[1],3*SCcoeff*nA5[0]*nA5[0],3*SCcoeff*nA5[1]*nA5[1]);

    }
#endif

#ifdef CDM_NUCLEUS
    {   double dNdE[300];
        double nEvents;

        printf("\n======== Direct Detection ========\n");

        nEvents=nucleusRecoil(Maxwell,73,Z_Ge,J_Ge73,SxxGe73,NULL,dNdE);

        printf("73Ge: Total number of events=%.2E /day/kg\n",nEvents);
        printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
               cutRecoilResult(dNdE,10,50));

#ifdef SHOWPLOTS
        displayRecoilPlot(dNdE,"Distribution of recoil energy of 73Ge",0,199);
#endif

        nEvents=nucleusRecoil(Maxwell,131,Z_Xe,J_Xe131,SxxXe131,NULL,dNdE);

        printf("131Xe: Total number of events=%.2E /day/kg\n",nEvents);
        printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
               cutRecoilResult(dNdE,10,50));
#ifdef SHOWPLOTS
        displayRecoilPlot(dNdE,"Distribution of recoil energy of 131Xe",0,199);
#endif

        nEvents=nucleusRecoil(Maxwell,23,Z_Na,J_Na23,SxxNa23,NULL,dNdE);

        printf("23Na: Total number of events=%.2E /day/kg\n",nEvents);
        printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
               cutRecoilResult(dNdE,10,50));
#ifdef SHOWPLOTS
        displayRecoilPlot(dNdE,"Distribution of recoil energy of 23Na",0,199);
#endif

        nEvents=nucleusRecoil(Maxwell,127,Z_I,J_I127,SxxI127,NULL,dNdE);

        printf("I127: Total number of events=%.2E /day/kg\n",nEvents);
        printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
               cutRecoilResult(dNdE,10,50));
#ifdef SHOWPLOTS
        displayRecoilPlot(dNdE,"Distribution of recoil energy of 127I",0,199);
#endif

    }
#endif
#ifdef NEUTRINO
    {   double nu[NZ], nu_bar[NZ],mu[NZ];
        double Ntot;
        int forSun=1;
        double Emin=0.01;

        printf("\n===============Neutrino Telescope=======  for  ");
        if(forSun) printf("Sun\n");
        else printf("Earth\n");

        err=neutrinoFlux(Maxwell,forSun, nu,nu_bar);
#ifdef SHOWPLOTS
        displaySpectrum(nu,"nu flux from Sun [1/Year/km^2/GeV]",Emin,Mcdm);
        displaySpectrum(nu_bar,"nu-bar from Sun [1/Year/km^2/GeV]",Emin,Mcdm);
#endif
        {   double Ntot;
            double Emin=10; //GeV
            spectrInfo(Emin/Mcdm,nu, &Ntot,NULL);
            printf(" E>%.1E GeV neutrino flux       %.3E [1/Year/km^2] \n",Emin,Ntot);
            spectrInfo(Emin/Mcdm,nu_bar, &Ntot,NULL);
            printf(" E>%.1E GeV anti-neutrino flux  %.3E [1/Year/km^2]\n",Emin,Ntot);
        }

        /* Upward events */

        muonUpward(nu,nu_bar, mu);
#ifdef SHOWPLOTS
        displaySpectrum(mu,"Upward muons[1/Year/km^2/GeV]",1,Mcdm/2);
#endif
        {   double Ntot;
            double Emin=1; //GeV
            spectrInfo(Emin/Mcdm,mu, &Ntot,NULL);
            printf(" E>%.1E GeV Upward muon flux    %.3E [1/Year/km^2]\n",Emin,Ntot);
        }

        /* Contained events */
        muonContained(nu,nu_bar,1., mu);
#ifdef SHOWPLOTS
        displaySpectrum(mu,"Contained  muons[1/Year/km^3/GeV]",Emin,Mcdm);
#endif
        {   double Ntot;
            double Emin=1; //GeV
            spectrInfo(Emin/Mcdm,mu, &Ntot,NULL);
            printf(" E>%.1E GeV Contained muon flux %.3E [1/Year/km^3]\n",Emin,Ntot);
        }
    }
#endif

#ifdef DECAYS
    {
        txtList L;
        double width,br;
        char * pname;
        printf("\n================= Decays ==============\n");

        pname = "H";
        width=pWidth(pname,&L);
        printf("\n%s :   total width=%.2E \n and Branchings:\n",pname,width);
        printTxtList(L,stdout);

        pname = "~W+";
        width=pWidth(pname,&L);
        printf("\n%s :   total width=%.2E \n and Branchings:\n",pname,width);
        printTxtList(L,stdout);
    }
#endif

#ifdef CLEAN
    system("rm -f HB.in HB.out HS.in HS.out hb.stdout hs.stdout debug_channels.txt debug_predratio.txt Key.dat");
    killPlots();
#endif
    return 0;
}
示例#18
0
int ScummEngine_v2::getVar() {
	return readVar(fetchScriptByte());
}
示例#19
0
int ScummEngine_v71he::setupStringArray(int size) {
	writeVar(0, 0);
	defineArray(0, kStringArray, 0, size + 1);
	writeArray(0, 0, 0, 0);
	return readVar(0);
}
示例#20
0
int Tmlex::readText(Ttoken &token)
{
    static TstrBuf buff;

    int           ch   = Dinput.get();
    Tstr          posn = Dinput.posn();
    unsigned long pos = 0;

    while ((EOF != ch) && ('\n' != ch) && (SEP_TEXT != ch))
    {
        if (SEP_ESC == ch)                              // 005
        {
            // Escaped Charactor
            ch = Dinput.get();
            if ((EOF != ch) && ('\n' != ch))
            {
                switch (ch)
                {
                case 'n' :
                    buff[pos++] = '\n';
                    break;
                case 'r' :
                    buff[pos++] = '\r';
                    break;
                case 't' :
                    buff[pos++] = '\t';
                    break;
                case 'v' :
                    buff[pos++] = '\v';
                    break;
                case 'b' :
                    buff[pos++] = '\b';
                    break;
                default  :
                    buff[pos++] =  ch;
                    break;
                }
            }
        }
        else if (SEP_S_VAR == ch)
        {
            // Posible var
            if (!readVar()) buff[pos++] = ch;
        }
        else if (SEP_CALL == ch)                       // 005
        {
            // Call argument
            Ttoken token;
            token.setPosn(Dinput.posn());
            readCall(token);
            Dinput.push(new Tpipe(token.text()));
        }
        else if (SEP_WHICH_OPEN == ch)                // 005
        {
            // Posible which argument
            Ttoken token;
            token.setPosn(Dinput.posn());
            Dinput.putBack(findExecs(token.text()));
        }
        else
        {
            buff[pos++] = ch;
        }
        ch = Dinput.get();
    }
    buff[pos++] = '\0';

    if (SEP_TEXT != ch)
    {
        printE("%s : Unterminated text\n", (char const*)posn);
    }

    token.setType(TOK_TEXT);
    token.setText((char const*)buff);

    return(1);
}
示例#21
0
int Tmlex::readIdent(Ttoken &token)
{
    static TstrBuf buff;

    int            ch    = Dinput.get();
    Tstr           posn  = Dinput.posn();
    unsigned long  pos   = 0;
    int            mType = 0;

    while (isIdent(ch) || (SEP_S_VAR == ch))
    {
        if (SEP_S_VAR == ch)
        {
            // Posible var
            if (!readVar())
                buff[pos++] = ch;
        }
        else if ('\\' == ch)
        {
            // Excape any special (or non-special charactors)

            ch = Dinput.get();
            if (isIdent(ch))
            {
                buff[pos++] = ch;
            }
            else
            {
                Dinput.putBack(ch);
            }
        }
        else
        {
            mType = (mType       ||
                     ('+' == ch) ||
                     ('#' == ch) ||
                     ('*' == ch) ||
                     ('?' == ch) ||
                     ('[' == ch) ||
                     (']' == ch) ||
                     ('\004' == ch));
            buff[pos++] = ch;
        }
        ch = Dinput.get();
    }
    buff[pos++] = '\0';

    Dinput.putBack(ch);

    if (mType)
    {
        token.setType(TOK_MATCH);
    }
    else
    {
        // This may be a state command
        if (!strcmp(buff, "echo"))
        {
            token.setType(TOK_ECHO);
        }
        else if (!strcmp(buff, "cd"))
        {
            token.setType(TOK_CHANGE_DIR);
        }
        else if (!strcmp(buff, "pwd"))
        {
            token.setType(TOK_PRINT_DIR);
        }
        else if (!strcmp(buff, "exit"))
        {
            token.setType(TOK_EXIT);
        }
        else if (!strcmp(buff, "IF"))          // 012
        {
            token.setType(TOK_IF);
        }
        else if (!strcmp(buff, "ELSE"))        // 012
        {
            token.setType(TOK_ELSE);
        }
        else if (!strcmp(buff, "ELIF"))        // 012
        {
            token.setType(TOK_ELIF);
        }
        else if (!strcmp(buff, "FI"))          // 012
        {
            token.setType(TOK_ENDIF);
        }
        else if (!strcmp(buff, "NOT"))         // 012
        {
            token.setType(TOK_NOT);
        }
        else if (!strcmp(buff, "IsFILE"))         // 012
        {
            token.setType(TOK_FILE);
        }
        else if (!strcmp(buff, "IsDIR"))         // 012
        {
            token.setType(TOK_DIR);
        }
        else if (!strcmp(buff, "IsEXE"))         // 012
        {
            token.setType(TOK_EXECUTABLE);
        }
        else if (!strcmp(buff, "EXISTS"))         // 012
        {
            token.setType(TOK_EXISTS);
        }
        else
        {
            token.setType(TOK_IDENT);
        }
    }

    token.setText((char const*)buff);

    return(1);
}
示例#22
0
int main(int argc,char** argv)
{  int err;
   char wimpName[10];
   
/* to save RGE input/output files uncomment the next line */
/*delFiles(0);*/

  if(argc==1)
  { 
      printf(" Correct usage:  ./omg <file with parameters> \n");
      exit(1);
  }
                               

  err=readVar(argv[1]);
/*   err=readVarRHNM(argv[1]);*/
  if(err==-1)     {printf("Can not open the file\n"); exit(1);}
  else if(err>0)  { printf("Wrong file contents at line %d\n",err);exit(1);}


  err=sortOddParticles(wimpName);
  if(err) { printf("Can't calculate %s\n",wimpName); return 1;}

/*to print input parameters or model in SLHA format uncomment correspondingly*/
/* 
  printVar(stdout);  
  writeLesH("slha.out"); 
*/

#ifdef MASSES_INFO
{
  printf("\n=== MASSES OF PARTICLES OF ODD SECTOR: ===\n");
  printMasses(stdout,1);
}
#endif

#ifdef CONSTRAINTS
  printf("\n================= CONSTRAINTS =================\n");
#endif

#ifdef OMEGA
{ int fast=1;
  double Beps=1.E-2, cut=0.01;
  double Omega,Xf;   
  printf("\n==== Calculation of relic density =====\n");  

  Omega=darkOmega(&Xf,fast,Beps);
  printf("Xf=%.2e Omega=%.2e\n",Xf,Omega);
  printChannels(Xf,cut,Beps,1,stdout);
}
#endif


#ifdef INDIRECT_DETECTION
{ /* See  hep-ph/0607059 pages 10, 11 for complete explanation  */

  int err,outP;
  double Mwimp,Emin,Ntot,Etot,sigmaV,v=0.001,fi,tab[250];
  char txt[100];

printf("\n==== Indirect detection =======\n");  

  outP=0;    /* 0 for gamma rays  
                1-positron; 2-antiproton; 3,4,5 neutrinos 
                (electron, muon and tau correspondinly)
             */
  Emin=0.1;  /* Energy cut  in GeV   */
  fi=0;      /* angle of sight in radians */                                                                                                                                                                         

  sigmaV=calcSpectrum(v,outP,tab,&err);  
             /* Returns sigma*v in cm^3/sec.  
                tab could be substituted in zInterp(z,tab) to get particle distribution 
                in one collision  dN/dz, where  z=log (E/Mwinp) */  
  printf("sigma*v=%.2E [cm^3/sec]\n", sigmaV);
  Mwimp=lopmass_();

  spectrInfo(Emin/Mwimp,tab, &Ntot,&Etot);
  printf("%.2E %s with E > %.2E are generated at one collision\n",Ntot,outNames[outP],Emin); 

#ifdef SHOWPLOTS 
/*  Spectrum of photons produced in DM annihilation.  */ 
  sprintf(txt,"%s: N=%.2e,<E/2M>=%.2f,vsc=%.2e cm^3/sec,M(%s)=%.2e", 
  outNames[outP],Ntot,Etot,sigmaV,wimpName,Mwimp); 

  displaySpectrum(tab, txt ,Emin/Mwimp);  
#endif
  if(outP==0)
  {
    printf("gamma flux for fi=%.2E[rad] is %.2E[ph/cm^2/s/sr]\n",
       fi, HaloFactor(fi,rhoQisotermic)*sigmaV*Ntot/Mwimp/Mwimp);
  }
/*  Test of energy conservation  */     
/*        
{ double e[6];
  int i;
  printf("Check of energy conservation:\n"); 
  for(i=0;i<6;i++)
  {    
     sigmaV=calcSpectrum(v,i,tab,&err);
     spectrInfo(Emin/Mwimp,tab, NULL,e+i);
  } 
  printf("1 = %.2f\n",e[0]+2*(e[1]+e[2]+e[3]+e[4]+e[5]) );
}     
*/

}
#endif

#ifdef RESET_FORMFACTORS
{
/* 
   The default nucleon form factors can be completely or partially modified 
   by setProtonFF and setNeutronFF. For scalar form factors, one can first call
   getScalarFF( Mu/Md, Ms/Md, sigmaPiN[MeV], sigma0[MeV], protonFF,neutronFF)  
   or set the new coefficients by directly assigning numerical values.
*/
{ double   ffS0P[3]={0.033,0.023,0.26},
           ffS0N[3]={0.042,0.018,0.26},
           ffV5P[3]={-0.427, 0.842,-0.085},
           ffV5N[3]={ 0.842,-0.427,-0.085}; 

  printf("\n=========== Redefinition of form factors  =========\n");         
      
  getScalarFF(0.553,18.9,55.,35.,ffS0P, ffS0N);
  printf("protonFF  d %E, u %E, s %E\n",ffS0P[0],ffS0P[1],ffS0P[2]);                               
  printf("neutronFF d %E, u %E, s %E\n",ffS0N[0],ffS0N[1],ffS0N[2]);

/* Use NULL argument if there is no need for reassignment */
  setProtonFF(ffS0P,ffV5P, NULL);
  setNeutronFF(ffS0N,ffV5N,NULL);
}

/* Option to change parameters of DM velocity  distribution 
*/   
   SetfMaxwell(220.,244.4,600.);
     /* arg1- defines DM velocity distribution in Galaxy rest frame:
            ~exp(-v^2/arg1^2)d^3v
        arg2- Earth velocity with respect to Galaxy
        arg3- Maximal DM velocity in Sun orbit with respect to Galaxy.
        All parameters are  in [km/s] units.
     */
/* In case DM has velocity distribution close to delta-function 
   the DM velocity V[km/s] can be defined by
*/          
   SetfDelta(350.);

/* To reset parameters of Fermi nucleus distribution  */
   SetFermi(1.23,-0.6,0.52);
/*  with half-density radius for Fermi distribution: 
          c=arg1*A^(1/3) + arg2
    and arg3 is the surface thickness.
    All parameter in [fm].      
*/
}
#endif


#ifdef WIMP_NUCLEON
{ double pA0[2],pA5[2],nA0[2],nA5[2];
  double Nmass=0.939; /*nucleon mass*/
  double SCcoeff;        
  double dpA0[2],dnA0[2];
 
printf("\n==== Calculation of WIMP-nucleons amplitudes  =====\n");   

  nucleonAmplitudes(NULL, dpA0,pA5,dnA0,nA5);
printf("====OFF/On======\n");  
  nucleonAmplitudes(NULL, pA0,pA5,nA0,nA5);
  dpA0[0]-=pA0[0];
  dnA0[0]-=nA0[0];  
   
    printf("%s -nucleon amplitudes:\n",wimpName);
    printf("proton:  SI  %.3E  SD  %.3E\n",pA0[0],pA5[0]);
    printf("neutron: SI  %.3E  SD  %.3E\n",nA0[0],nA5[0]); 

  SCcoeff=4/M_PI*3.8937966E8*pow(Nmass*lopmass_()/(Nmass+ lopmass_()),2.);
    printf("%s-nucleon cross sections:\n",wimpName);
    
    printf(" proton  SI %.3E  SD %.3E\n",SCcoeff*pA0[0]*pA0[0],3*SCcoeff*pA5[0]*pA5[0]);
    printf(" neutron SI %.3E  SD %.3E\n",SCcoeff*nA0[0]*nA0[0],3*SCcoeff*nA5[0]*nA5[0]);

 printf(" twist-2 CS proton   %.3E   neutron %.3E \n",
 SCcoeff*dpA0[0]*dpA0[0], SCcoeff*dnA0[0]*dnA0[0]);
 
    printf("anti-%s -nucleon amplitudes:\n",wimpName);
    printf("proton:  SI  %.3E  SD  %.3E\n",pA0[1],pA5[1]);
    printf("neutron: SI  %.3E  SD  %.3E\n",nA0[1],nA5[1]); 

  SCcoeff=4/M_PI*3.8937966E8*pow(Nmass*lopmass_()/(Nmass+ lopmass_()),2.);
    printf("anti-%s-nucleon cross sections:\n",wimpName);
    
    printf(" proton  SI %.3E  SD %.3E\n",SCcoeff*pA0[1]*pA0[1],3*SCcoeff*pA5[1]*pA5[1]);
    printf(" neutron SI %.3E  SD %.3E\n",SCcoeff*nA0[1]*nA0[1],3*SCcoeff*nA5[1]*nA5[1]);

}
#endif
  
#ifdef WIMP_NUCLEUS
{ double dNdE[200];
  double nEvents;
  double rho=0.3; /* DM density GeV/sm^3 */
printf("\n=========== Direct Detection ===============\n");


  nEvents=nucleusRecoil(rho,fDvMaxwell,73,Z_Ge,J_Ge73,S00Ge73,S01Ge73,S11Ge73,NULL,dNdE);
      /* See '../sources/micromegas.h' for description of arguments 
     
        Instead of Maxwell (DvMaxwell) one can use 'fDvDelta' Delta-function 
        velocity distribution.
      */

  printf("73Ge: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));                                   
#ifdef SHOWPLOTS
    displayRecoilPlot(dNdE,"Distribution of recoil energy of 73Ge",0,199);
#endif

  nEvents=nucleusRecoil(rho,fDvMaxwell,131,Z_Xe,J_Xe131,S00Xe131,S01Xe131,S11Xe131,NULL,dNdE);

  printf("131Xe: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));                                   
#ifdef SHOWPLOTS
    displayRecoilPlot(dNdE,"Distribution of recoil energy of 131Xe",0,199);
#endif

/*  If SD form factors are not known or for spin=0 nucleus one can use */
  nEvents=nucleusRecoil0(rho,fDvMaxwell,3,Z_He,J_He3,Sp_He3,Sn_He3,NULL,dNdE);
  printf("\n 3^He: Total number of events=%.2E /day/kg\n",nEvents);
#ifdef SHOWPLOTS
  displayRecoilPlot(dNdE,"Distribution of recoil energy of 3He",0,50);
#endif

}
#endif 

#ifdef CROSS_SECTIONS
{
  double Pcm=500;
  numout* cc;
  double cosmin=-0.99, cosmax=0.99;
  double v=0.002;

printf("\n====== Calculation of widths and cross sections ====\n");  
  decay2Info("Z",stdout);
  decay2Info("H",stdout);

/*  Helicity[0]=0.45;
  Helicity[1]=-0.45;
  printf("Process e,E->2*x at Pcm=%.3E GeV\n",Pcm);
  cc=newProcess("e%,E%->2*x","eE_2x");
  if(cc)
  { int ntot,l;
    char * name[4];
    procInfo1(cc,&ntot,NULL,NULL);
    for(l=1;l<=ntot; l++)
    { int err;
      double cs;
      procInfo2(cc,l,name,NULL);
      printf("%3s,%3s -> %3s %3s  ",name[0],name[1],name[2],name[3]);
      cs= cs22(cc,l,Pcm,cosmin,cosmax,&err);
      if(err) printf("Error\n");
      else if(cs==0.) printf("Zero\n");
      else printf("%.2E [pb]\n",cs); 
    }
  } 
*/
  printf("\n WIMP annihilation at V_rel=%.2E\n",v);
 
  cc=newProcess("",wimpAnnLib());
  assignValW("Q",2*lopmass_());
  if(cc)
  { int ntot,l;
    char * name[4];
    double mass[4];
    procInfo1(cc,&ntot,NULL,NULL);
    for(l=1;l<=ntot; l++)
    { int err;
      double cs;
      procInfo2(cc,l,name,mass);
      if(l==1) { Pcm=mass[0]*v/2; printf("(Pcm=%.2E)\n",Pcm);}
      printf("%3s,%3s -> %3s %3s  ",name[0],name[1],name[2],name[3]);
      cs= cs22(cc,l,Pcm,-1.,1.,&err);
      if(err) printf("Error\n");
      else if(cs==0.) printf("Zero\n");
      else printf("%.2E [pb] ( sigma*v=%.2E [cm^3/sec] )  \n",cs,cs*v*2.9979E-26); 
    }
  }
}

#endif
                          
  return 0;
}
示例#23
0
int main(int argc,char** argv)
{  int err;
   char cdmName[10];
   int spin2, charge3,cdim;

  ForceUG=0;  /* to Force Unitary Gauge assign 1 */
/*
gauss345_arg(ff,Y,0,1,1E-5,&err);
printf("err=%d\n",err);
exit(0);
*/ 
  VZdecay=1; VWdecay=1;

  if(argc==1)
  {
      printf(" Correct usage:  ./main  <file with parameters> \n");
      printf("Example: ./main data1.par\n");
      exit(1);
  }

  err=readVar(argv[1]);

  if(err==-1)     {printf("Can not open the file\n"); exit(1);}
  else if(err>0)  { printf("Wrong file contents at line %d\n",err);exit(1);}



  err=sortOddParticles(cdmName);
  if(err) { printf("Can't calculate %s\n",cdmName); return 1;}

  if(CDM1)
  {
     qNumbers(CDM1, &spin2, &charge3, &cdim);
     printf("\nDark matter candidate is '%s' with spin=%d/2 mass=%.2E\n",CDM1,  spin2,Mcdm1);
     if(charge3) printf("Dark Matter has electric charge %d/3\n",charge3);
     if(cdim!=1) printf("Dark Matter is a color particle\n");
  }
  if(CDM2)
  {
     qNumbers(CDM2, &spin2, &charge3, &cdim);
     printf("\nDark matter candidate is '%s' with spin=%d/2 mass=%.2E\n",CDM2,spin2,Mcdm2);
     if(charge3) printf("Dark Matter has electric charge %d/3\n",charge3);
     if(cdim!=1) printf("Dark Matter is a color particle\n");
  }


#ifdef MASSES_INFO
{
  printf("\n=== MASSES OF HIGGS AND ODD PARTICLES: ===\n");
  printHiggs(stdout);
  printMasses(stdout,1);
}
#endif

#ifdef CONSTRAINTS
{ double csLim;
  if(Zinvisible()) printf("Excluded by Z->invizible\n");
  if(LspNlsp_LEP(&csLim)) printf("LEP excluded by e+,e- -> DM q q-\\bar  Cross Section= %.2E pb\n",csLim);
}
#endif

#ifdef MONOJET
{ double CL=monoJet();
  printf(" Monojet signal exclusion CL is %.3e\n", CL);
}
#endif

#if defined(HIGGSBOUNDS) || defined(HIGGSSIGNALS)
{  int NH0,NHch;  // number of neutral and charged Higgs particles.
   double HB_result,HB_obsratio,HS_observ,HS_chi2, HS_pval;
   char HB_chan[100]={""}, HB_version[50], HS_version[50];
   NH0=hbBlocksMO("HB.in",&NHch);
   system("echo 'BLOCK DMASS\n 25  2  '>> HB.in");
#include "../include/hBandS.inc"
#ifdef HIGGSBOUNDS
   printf("HB(%s): result=%.0f  obsratio=%.2E  channel= %s \n", HB_version,HB_result,HB_obsratio,HB_chan);
#endif
#ifdef HIGGSSIGNALS
   printf("HS(%s): Nobservables=%.0f chi^2 = %.2E pval= %.2E\n",HS_version,HS_observ,HS_chi2, HS_pval);
#endif
}
#endif

#ifdef LILITH
{  double m2logL, m2logL_reference=0,pvalue;
   int exp_ndf,n_par=0,ndf;
   char call_lilith[100], Lilith_version[20];
   if(LilithMO("Lilith_in.xml"))
   {
#include "../include/Lilith.inc"
      if(ndf)
      {
        printf("LILITH(DB%s):  -2*log(L): %.2f; -2*log(L_reference): %.2f; ndf: %d; p-value: %.2E \n",
        Lilith_version,m2logL,m2logL_reference,ndf,pvalue);
      }
   } else printf("LILITH: there is no Higgs candidate\n");
}
#endif


#ifdef SMODELS
{  int result=0;
   double Rvalue=0;
   char analysis[30]={},topology[30]={};
   int LHCrun=LHC8|LHC13;  //  LHC8  - 8TeV; LHC13  - 13TeV; 
#include "../include/SMODELS.inc"
}
#endif

#ifdef OMEGA
{ int fast=1;
  double Beps=1.E-4, cut=0.01;
  double Omega;  
  int i,err; 
  printf("\n==== Calculation of relic density =====\n");   

  if(CDM1 && CDM2) 
  {
  
    Omega= darkOmega2(fast,Beps);
    printf("Omega_1h^2=%.2E\n", Omega*(1-fracCDM2));
    printf("Omega_2h^2=%.2E\n", Omega*fracCDM2);
  } else
  {  double Xf;
     Omega=darkOmega(&Xf,fast,Beps,&err);
     printf("Xf=%.2e Omega=%.2e\n",Xf,Omega);
     if(Omega>0)printChannels(Xf,cut,Beps,1,stdout);
  }
}

#endif



#ifdef FREEZEIN
{
  double TR=1E10;
  double omegaFi;  
  toFeebleList("~s0");
  VWdecay=0; VZdecay=0;
  
  omegaFi=darkOmegaFi(TR,&err);
  printf("omega freeze-in=%.3E\n", omegaFi);
  printChannelsFi(0,0,stdout);
}
#endif
 
#ifdef INDIRECT_DETECTION
{
  int err,i;
  double Emin=1,/* Energy cut  in GeV   */  sigmaV;
  double vcs_gz,vcs_gg;
  char txt[100];
  double SpA[NZ],SpE[NZ],SpP[NZ];
  double FluxA[NZ],FluxE[NZ],FluxP[NZ];
  double * SpNe=NULL,*SpNm=NULL,*SpNl=NULL;
  double Etest=Mcdm/2;

printf("\n==== Indirect detection =======\n");

  sigmaV=calcSpectrum(1+2+4,SpA,SpE,SpP,SpNe,SpNm,SpNl ,&err);
    /* Returns sigma*v in cm^3/sec.     SpX - calculated spectra of annihilation.
       Use SpectdNdE(E, SpX) to calculate energy distribution in  1/GeV units.

       First parameter 1-includes W/Z polarization
                       2-includes gammas for 2->2+gamma
                       4-print cross sections
    */



  {
     double fi=0.1,dfi=0.05; /* angle of sight and 1/2 of cone angle in [rad] */

     gammaFluxTab(fi,dfi, sigmaV, SpA,  FluxA);
     printf("Photon flux  for angle of sight f=%.2f[rad]\n"
     "and spherical region described by cone with angle %.2f[rad]\n",fi,2*dfi);
#ifdef SHOWPLOTS
     sprintf(txt,"Photon flux for angle of sight %.2f[rad] and cone angle %.2f[rad]",fi,2*dfi);
     displayPlot(txt,"E[GeV]",Emin,Mcdm,0,1,"",0,SpectdNdE,FluxA);
#endif
     printf("Photon flux = %.2E[cm^2 s GeV]^{-1} for E=%.1f[GeV]\n",SpectdNdE(Etest, FluxA), Etest);
  }

  {
    posiFluxTab(Emin, sigmaV, SpE,  FluxE);
#ifdef SHOWPLOTS
    displayPlot("positron flux [cm^2 s sr GeV]^{-1}","E[GeV]",Emin,Mcdm,0,1,"",0,SpectdNdE,FluxE);
#endif
    printf("Positron flux  =  %.2E[cm^2 sr s GeV]^{-1} for E=%.1f[GeV] \n",
    SpectdNdE(Etest, FluxE),  Etest);
  }

  {
    pbarFluxTab(Emin, sigmaV, SpP,  FluxP  );
#ifdef SHOWPLOTS
     displayPlot("antiproton flux [cm^2 s sr GeV]^{-1}","E[GeV]",Emin,Mcdm,0,1,"",0,SpectdNdE,FluxP);
#endif
    printf("Antiproton flux  =  %.2E[cm^2 sr s GeV]^{-1} for E=%.1f[GeV] \n",
    SpectdNdE(Etest, FluxP),  Etest);
  }
}
#endif

#ifdef RESET_FORMFACTORS
{
/*
   The user has approach to form factors  which specifies quark contents
   of  proton and nucleon via global parametes like
      <Type>FF<Nucleon><q>
   where <Type> can be "Scalar", "pVector", and "Sigma";
         <Nucleon>     "P" or "N" for proton and neutron
         <q>            "d", "u","s"

   calcScalarQuarkFF( Mu/Md, Ms/Md, sigmaPiN[MeV], sigma0[MeV])
   calculates and rewrites Scalar form factors
*/
  printf("\n======== RESET_FORMFACTORS ======\n");

  printf("protonFF (default) d %.2E, u %.2E, s %.2E\n",ScalarFFPd, ScalarFFPu,ScalarFFPs);
  printf("neutronFF(default) d %.2E, u %.2E, s %.2E\n",ScalarFFNd, ScalarFFNu,ScalarFFNs);
//                    To restore default form factors of  version 2  call
     calcScalarQuarkFF(0.553,18.9,55.,243.5);


  printf("protonFF (new)     d %.2E, u %.2E, s %.2E\n",ScalarFFPd, ScalarFFPu,ScalarFFPs);
  printf("neutronFF(new)     d %.2E, u %.2E, s %.2E\n",ScalarFFNd, ScalarFFNu,ScalarFFNs);

//                    To restore default form factors  current version  call
//  calcScalarQuarkFF(0.56,20.2,34,42);


}
#endif

#ifdef CDM_NUCLEON
{ double pA0[2],pA5[2],nA0[2],nA5[2];
  double Nmass=0.939; /*nucleon mass*/
  double SCcoeff;

printf("\n==== Calculation of CDM-nucleons amplitudes  =====\n");

  if(CDM1)
  {
    nucleonAmplitudes(CDM1, pA0,pA5,nA0,nA5);
    printf("CDM[antiCDM]-nucleon micrOMEGAs amplitudes for %s \n",CDM1);
    printf("proton:  SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",pA0[0], pA0[1],  pA5[0], pA5[1] );
    printf("neutron: SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",nA0[0], nA0[1],  nA5[0], nA5[1] );

  SCcoeff=4/M_PI*3.8937966E8*pow(Nmass*Mcdm/(Nmass+ Mcdm),2.);
    printf("CDM[antiCDM]-nucleon cross sections[pb]:\n");
    printf(" proton  SI %.3E [%.3E] SD %.3E [%.3E]\n",
       SCcoeff*pA0[0]*pA0[0],SCcoeff*pA0[1]*pA0[1],3*SCcoeff*pA5[0]*pA5[0],3*SCcoeff*pA5[1]*pA5[1]);
    printf(" neutron SI %.3E [%.3E] SD %.3E [%.3E]\n",
       SCcoeff*nA0[0]*nA0[0],SCcoeff*nA0[1]*nA0[1],3*SCcoeff*nA5[0]*nA5[0],3*SCcoeff*nA5[1]*nA5[1]);
  }
  if(CDM2)
  {
    nucleonAmplitudes(CDM2, pA0,pA5,nA0,nA5);
    printf("CDM[antiCDM]-nucleon micrOMEGAs amplitudes for %s \n",CDM2);
    printf("proton:  SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",pA0[0], pA0[1],  pA5[0], pA5[1] );
    printf("neutron: SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",nA0[0], nA0[1],  nA5[0], nA5[1] );

  SCcoeff=4/M_PI*3.8937966E8*pow(Nmass*Mcdm/(Nmass+ Mcdm),2.);
    printf("CDM[antiCDM]-nucleon cross sections[pb]:\n");
    printf(" proton  SI %.3E [%.3E] SD %.3E [%.3E]\n",
       SCcoeff*pA0[0]*pA0[0],SCcoeff*pA0[1]*pA0[1],3*SCcoeff*pA5[0]*pA5[0],3*SCcoeff*pA5[1]*pA5[1]);
    printf(" neutron SI %.3E [%.3E] SD %.3E [%.3E]\n",
       SCcoeff*nA0[0]*nA0[0],SCcoeff*nA0[1]*nA0[1],3*SCcoeff*nA5[0]*nA5[0],3*SCcoeff*nA5[1]*nA5[1]);
  }
}
#endif

#ifdef CDM_NUCLEUS
{ double dNdE[300];
  double nEvents;

printf("\n======== Direct Detection ========\n");

  nEvents=nucleusRecoil(Maxwell,73,Z_Ge,J_Ge73,SxxGe73,NULL,dNdE);

  printf("73Ge: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));

#ifdef SHOWPLOTS
    displayPlot("Distribution of recoil energy of 73Ge","E[KeV]",0,200,0,1,"dN/dE",0,dNdERecoil,dNdE);
#endif

  nEvents=nucleusRecoil(Maxwell,131,Z_Xe,J_Xe131,SxxXe131,NULL,dNdE);

  printf("131Xe: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));
#ifdef SHOWPLOTS
    displayPlot("Distribution of recoil energy of 131Xe","E[KeV]",0,200,0,1,"dN/dE",0,dNdERecoil,dNdE);
#endif

  nEvents=nucleusRecoil(Maxwell,23,Z_Na,J_Na23,SxxNa23,NULL,dNdE);

  printf("23Na: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));
#ifdef SHOWPLOTS
    displayPlot("Distribution of recoil energy of 23Na","E[KeV]",0,200,0,1,"dN/dE",0,dNdERecoil,dNdE);
#endif

  nEvents=nucleusRecoil(Maxwell,127,Z_I,J_I127,SxxI127,NULL,dNdE);

  printf("I127: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));
#ifdef SHOWPLOTS
  displayPlot("Distribution of recoil energy of 127I","E[KeV]",0,200,0,1,"dN/dE",0,dNdERecoil,dNdE);
#endif

}
#endif

#ifdef NEUTRINO
if(!CDM1 || !CDM2)
{ double nu[NZ], nu_bar[NZ],mu[NZ];
  double Ntot;
  int forSun=1;
  double Emin=1;

 printf("\n===============Neutrino Telescope=======  for  ");
 if(forSun) printf("Sun\n"); else printf("Earth\n");

  err=neutrinoFlux(Maxwell,forSun, nu,nu_bar);
#ifdef SHOWPLOTS
  displayPlot("neutrino fluxes [1/Year/km^2/GeV]","E[GeV]",Emin,Mcdm,0, 2,"dnu/dE",0,SpectdNdE,nu,"dnu_bar/dE",0,SpectdNdE,nu_bar);
#endif
{
    printf(" E>%.1E GeV neutrino flux       %.2E [1/Year/km^2] \n",Emin,spectrInfo(Emin,nu,NULL));
    printf(" E>%.1E GeV anti-neutrino flux  %.2E [1/Year/km^2]\n",Emin,spectrInfo(Emin,nu_bar,NULL));
}

/* Upward events */

  muonUpward(nu,nu_bar, mu);
#ifdef SHOWPLOTS
  displayPlot("Upward muons[1/Year/km^2/GeV]","E",Emin,Mcdm/2, 0,1,"mu",0,SpectdNdE,mu);
#endif
    printf(" E>%.1E GeV Upward muon flux    %.2E [1/Year/km^2]\n",Emin,spectrInfo(Emin,mu,NULL));

/* Contained events */
  muonContained(nu,nu_bar,1., mu);
#ifdef SHOWPLOTS
  displayPlot("Contained  muons[1/Year/km^3/GeV]","E",Emin,Mcdm,0,1,"",0,SpectdNdE,mu);
#endif
  printf(" E>%.1E GeV Contained muon flux %.2E [1/Year/km^3]\n",Emin,spectrInfo(Emin/Mcdm,mu,NULL));
}
#endif


#ifdef DECAYS
{ char*  pname = pdg2name(25);
  txtList L;
  double width;
  if(pname)
  {
    width=pWidth(pname,&L);
    printf("\n%s :   total width=%E \n and Branchings:\n",pname,width);
    printTxtList(L,stdout);
  }

  pname = pdg2name(24);
  if(pname)
  {
    width=pWidth(pname,&L);
    printf("\n%s :   total width=%E \n and Branchings:\n",pname,width);
    printTxtList(L,stdout);
  }
}
#endif

#ifdef CROSS_SECTIONS
{
  char* next,next_;
  double nextM;

  next=nextOdd(1,&nextM);
  if(next && nextM<1000)
  {
     double cs, Pcm=6500, Qren, Qfact, pTmin=0;
     int nf=3;
     char*next_=antiParticle(next);
     Qren=Qfact=nextM;

     printf("\npp > nextOdd  at sqrt(s)=%.2E GeV\n",2*Pcm);

     Qren=Qfact;
     cs=hCollider(Pcm,1,nf,Qren, Qfact, next,next_,pTmin,1);
     printf("Production of 'next' odd particle: cs(pp-> %s,%s)=%.2E[pb]\n",next,next_, cs);
  }
}

#endif

#ifdef CLEAN
  system("rm -f HB.* HB.* hb.* hs.*  debug_channels.txt debug_predratio.txt  Key.dat");
  system("rm -f Lilith_*   particles.py*");
  system("rm -f   smodels.in  smodels.log  smodels.out  summary.*");
#endif



  killPlots();
  return 0;
}
示例#24
0
NSParser::ConditionInfo NSParser::readCondition(Symbol *symbol, VariableList& variables)
{
	ConditionInfo info;
	if (symbol->type == NON_TERMINAL)
	{
		Symbol* conditionSymbol = nullptr;
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		switch(nt->ruleIndex)
		{
			case PROD_SENSORCONDITION:
			case PROD_IFCONDITION: //sensor
				conditionSymbol = searchChild(symbol, SYM_SENSORCONDITION);
				break;
			case PROD_ORIENTATIONCONDITION_ORIENTATION:
			case PROD_IFCONDITION2: //orientation
				info.type = ConditionInfo::RobotOrientationCondition;
				conditionSymbol = searchChild(symbol, SYM_ORIENTATIONCONDITION);
				break;
			case PROD_POSITIONCONDITION_POSITION:
			case PROD_IFCONDITION3: //position
				info.type = ConditionInfo::RobotPosCondition;
				conditionSymbol = searchChild(symbol, SYM_POSITIONCONDITION);
				break;
			case PROD_OPPONENTCONDITION_OPPONENT:
			case PROD_IFCONDITION4: //opponent
				info.type = ConditionInfo::OpponentPosCondition;
				conditionSymbol = searchChild(symbol, SYM_OPPONENTCONDITION);
				break;
			case PROD_REVERSECONDITION_STRATEGY_REVERSED:
			case PROD_IFCONDITION5: //strategy reversed
				info.type = ConditionInfo::ReversedStrategyCondition;
				conditionSymbol = searchChild(symbol, SYM_REVERSECONDITION);
				break;
			case PROD_IFCONDITION_TRUE: //strategy reversed
				info.type = ConditionInfo::AlwaysTrueCondition;
				break;
			case PROD_IFCONDITION_FALSE: //strategy reversed
				info.type = ConditionInfo::AlwaysFalseCondition;
				break;
		}

		int sensorType = Comm::UnknownedSensor;
		if (conditionSymbol && conditionSymbol->type == NON_TERMINAL)
		{
			NonTerminal* conditionSymbolNt = static_cast<NonTerminal*>(conditionSymbol);
			for(Symbol* c: conditionSymbolNt->children)
			{
				switch(c->symbolIndex)
				{
					case SYM_SENSOR_IDENTIFIER:
					case SYM_SENSOR_OR_VAR:
					{
						readSensorOrVar(c, variables, sensorType, info.sensorId);
						if (sensorType == Comm::ColorSensor)
							info.type = ConditionInfo::ColorSensorValueCondition;
						else if (sensorType == Comm::SharpSensor)
							info.type = ConditionInfo::SharpValueCondition;
						else if (sensorType == Comm::MicroswitchSensor)
							info.type = ConditionInfo::MicroswitchValueCondition;
						break;

						if (info.sensorId <= 0)
						{
							info.setInvalid();
							addError(NSParsingError::invalidSensorId(c));
						}
					}
					case SYM_COLORSENSORVALUE:
					case SYM_MICROSWITCHVALUE:
					case SYM_SHARPVALUE:
					case SYM_SENSORVALUE:
					{
						Comm::SensorType valueSensorType;
						info.sensorValue = readSensorValue(c, valueSensorType);
						if (valueSensorType != sensorType)
						{
							addError(NSParsingError::invalidSensorValueError(readTerminals(c), c));
							info.sensorValue = -1;
							info.setInvalid();
						}
						break;
					}
					case SYM_RECT_OR_VAR:
					case SYM_RECT2:
					case SYM_FIXED_RECT:
						readRectOrVar(c, variables, info.rect);
						break;
					case SYM_ANGLERANGE:
						readAngleRangeInRadian(c, info.angleMin, info.angleMax);
						break;
					case SYM_VAR:
					{
						QString varName = readVar(c);
						if (variables.contains(varName))
						{
							DeclaredVariable& var = variables[varName];
							if (info.type == ConditionInfo::OpponentPosCondition || info.type == ConditionInfo::RobotPosCondition)
							{
								//expected rect
								if (var.isRect())
									info.rect = var.toRect();
								else
								{
									info.setInvalid();
									addError(NSParsingError::invalidVariableTypeError(varName, "rect", c));
								}
							}
							else
							{
								//expected sensor
								if (var.isSensor())
									var.toSensor(info.sensorId, sensorType);
								if (sensorType == Comm::ColorSensor)
									info.type = ConditionInfo::ColorSensorValueCondition;
								else if (sensorType == Comm::SharpSensor)
									info.type = ConditionInfo::SharpValueCondition;
								else if (sensorType == Comm::MicroswitchSensor)
									info.type = ConditionInfo::MicroswitchValueCondition;
								else
								{
									info.setInvalid();
									addError(NSParsingError::invalidVariableTypeError(varName, "sensor", c));
								}

								if (info.sensorId <= 0)
								{
									info.setInvalid();
									addError(NSParsingError::invalidSensorId(c));
								}
							}

						}
						else
						{
							info.setInvalid();
							addError(NSParsingError::undeclaredVariableError(varName, c));
						}
						break;
					}
					case SYM_CONDITIONINOPERATOR:
						info.neg = static_cast<NonTerminal*>(c)->ruleIndex == PROD_CONDITIONINOPERATOR_NOT_IN;
						break;
					case SYM_CONDITIONISOPERATOR:
						info.neg = static_cast<NonTerminal*>(c)->ruleIndex == PROD_CONDITIONISOPERATOR_IS_NOT;
						break;
				}
			}
		}
	}

	return info;
}
int Logic::runScript2(byte *scriptData, byte *objectData, byte *offsetPtr) {
	// Interestingly, unlike our BASS engine the stack is a local variable.
	// I don't know whether or not this is relevant to the working of the
	// BS2 engine.

	int32 stack[STACK_SIZE];
	int32 stackPtr = 0;

	uint32 offset = READ_LE_UINT32(offsetPtr);

	ResHeader header;

	header.read(scriptData);

	scriptData += ResHeader::size() + ObjectHub::size();

	// The script data format:
	//	int32_TYPE	1		Size of variable space in bytes
	//	...				The variable space
	//	int32_TYPE	1		numberOfScripts
	//	int32_TYPE	numberOfScripts	The offsets for each script

	// Initialise some stuff

	uint32 ip = 0;			 // Code pointer
	int scriptNumber;

	// Get the start of variables and start of code

	byte *localVars = scriptData + 4;
	byte *code = scriptData + READ_LE_UINT32(scriptData) + 4;
	uint32 noScripts = READ_LE_UINT32(code);

	code += 4;

	byte *offsetTable = code;

	if (offset < noScripts) {
		ip = READ_LE_UINT32(offsetTable + offset * 4);
		scriptNumber = offset;
		debug(8, "Starting script %d from %d", scriptNumber, ip);
	} else {
		uint i;

		ip = offset;

		for (i = 1; i < noScripts; i++) {
			if (READ_LE_UINT32(offsetTable + 4 * i) >= ip)
				break;
		}

		scriptNumber = i - 1;
		debug(8, "Resuming script %d from %d", scriptNumber, ip);
	}

	// There are a couple of known script bugs related to interacting with
	// certain objects. We try to work around a few of them.

	bool checkMopBug = false;
	bool checkPyramidBug = false;
	bool checkElevatorBug = false;

	if (scriptNumber == 2) {
		if (strcmp((char *)header.name, "mop_73") == 0)
			checkMopBug = true;
		else if (strcmp((char *)header.name, "titipoco_81") == 0)
			checkPyramidBug = true;
		else if (strcmp((char *)header.name, "lift_82") == 0)
			checkElevatorBug = true;
	}

	code += noScripts * 4;

	// Code should now be pointing at an identifier and a checksum
	byte *checksumBlock = code;

	code += 4 * 3;

	if (READ_LE_UINT32(checksumBlock) != 12345678) {
		error("Invalid script in object %s", header.name);
		return 0;
	}

	int32 codeLen = READ_LE_UINT32(checksumBlock + 4);
	int32 checksum = 0;

	for (int i = 0; i < codeLen; i++)
		checksum += (unsigned char) code[i];

	if (checksum != (int32)READ_LE_UINT32(checksumBlock + 8)) {
		debug(1, "Checksum error in object %s", header.name);
		// This could be bad, but there has been a report about someone
		// who had problems running the German version because of
		// checksum errors. Could there be a version where checksums
		// weren't properly calculated?
	}

	bool runningScript = true;

	int parameterReturnedFromMcodeFunction = 0;	// Allow scripts to return things
	int savedStartOfMcode = 0;	// For saving start of mcode commands

	while (runningScript) {
		int i;
		int32 a, b;
		int curCommand, parameter, value; // Command and parameter variables
		int retVal;
		int caseCount;
		bool foundCase;
		byte *ptr;

		curCommand = code[ip++];

		switch (curCommand) {

		// Script-related opcodes

		case CP_END_SCRIPT:
			// End the script
			runningScript = false;

			// WORKAROUND: The dreaded pyramid bug makes the torch
			// untakeable when you speak to Titipoco. This is
			// because one of the conditions for the torch to be
			// takeable is that Titipoco isn't doing anything out
			// of the ordinary. Global variable 913 has to be 0 to
			// signify that he is in his "idle" state.
			//
			// Unfortunately, simply the act of speaking to him
			// sets variable 913 to 1 (probably to stop him from
			// turning around every now and then). The script may
			// then go on to set the variable to different values
			// to trigger various behaviours in him, but if you
			// have run out of these cases the script won't ever
			// set it back to 0 again.
			//
			// So if his click hander finishes, and variable 913 is
			// 1, we set it back to 0 manually.

			if (checkPyramidBug && readVar(913) == 1) {
				warning("Working around pyramid bug: Resetting Titipoco's state");
				writeVar(913, 0);
			}

			// WORKAROUND: The not-so-known-but-should-be-dreaded
			// elevator bug.
			//
			// The click handler for the top of the elevator only
			// handles using the elevator, not examining it. When
			// examining it, the mouse cursor is removed but never
			// restored.

			if (checkElevatorBug && readVar(RIGHT_BUTTON)) {
				warning("Working around elevator bug: Restoring mouse pointer");
				fnAddHuman(NULL);
			}

			debug(9, "CP_END_SCRIPT");
			break;
		case CP_QUIT:
			// Quit out for a cycle
			WRITE_LE_UINT32(offsetPtr, ip);
			debug(9, "CP_QUIT");
			return 0;
		case CP_TERMINATE:
			// Quit out immediately without affecting the offset
			// pointer
			debug(9, "CP_TERMINATE");
			return 3;
		case CP_RESTART_SCRIPT:
			// Start the script again
			ip = FROM_LE_32(offsetTable[scriptNumber]);
			debug(9, "CP_RESTART_SCRIPT");
			break;

		// Stack-related opcodes

		case CP_PUSH_INT32:
			// Push a long word value on to the stack
			Read32ip(parameter);
			push(parameter);
			debug(9, "CP_PUSH_INT32: %d", parameter);
			break;
		case CP_PUSH_LOCAL_VAR32:
			// Push the contents of a local variable
			Read16ip(parameter);
			push(READ_LE_UINT32(localVars + parameter));
			debug(9, "CP_PUSH_LOCAL_VAR32: localVars[%d] => %d", parameter / 4, READ_LE_UINT32(localVars + parameter));
			break;
		case CP_PUSH_GLOBAL_VAR32:
			// Push a global variable
			Read16ip(parameter);
			push(readVar(parameter));
			debug(9, "CP_PUSH_GLOBAL_VAR32: scriptVars[%d] => %d", parameter, readVar(parameter));
			break;
		case CP_PUSH_LOCAL_ADDR:
			// Push the address of a local variable

			// From what I understand, some scripts store data
			// (e.g. mouse pointers) in their local variable space
			// from the very beginning, and use this mechanism to
			// pass that data to the opcode function. I don't yet
			// know the conceptual difference between this and the
			// CP_PUSH_DEREFERENCED_STRUCTURE opcode.

			Read16ip(parameter);
			push_ptr(localVars + parameter);
			debug(9, "CP_PUSH_LOCAL_ADDR: &localVars[%d] => %p", parameter / 4, localVars + parameter);
			break;
		case CP_PUSH_STRING:
			// Push the address of a string on to the stack
			// Get the string size
			Read8ip(parameter);

			// ip now points to the string
			ptr = code + ip;
			push_ptr(ptr);
			debug(9, "CP_PUSH_STRING: \"%s\"", ptr);
			ip += (parameter + 1);
			break;
		case CP_PUSH_DEREFERENCED_STRUCTURE:
			// Push the address of a dereferenced structure
			Read32ip(parameter);
			ptr = objectData + 4 + ResHeader::size() + ObjectHub::size() + parameter;
			push_ptr(ptr);
			debug(9, "CP_PUSH_DEREFERENCED_STRUCTURE: %d => %p", parameter, ptr);
			break;
		case CP_POP_LOCAL_VAR32:
			// Pop a value into a local word variable
			Read16ip(parameter);
			value = pop();
			WRITE_LE_UINT32(localVars + parameter, value);
			debug(9, "CP_POP_LOCAL_VAR32: localVars[%d] = %d", parameter / 4, value);
			break;
		case CP_POP_GLOBAL_VAR32:
			// Pop a global variable
			Read16ip(parameter);
			value = pop();

			// WORKAROUND for bug #1214168: The not-at-all dreaded
			// mop bug.
			//
			// At the London Docks, global variable 1003 keeps
			// track of Nico:
			//
			// 0: Hiding behind the first crate.
			// 1: Hiding behind the second crate.
			// 2: Standing in plain view on the deck.
			// 3: Hiding on the roof.
			//
			// The bug happens when trying to pick up the mop while
			// hiding on the roof. Nico climbs down, the mop is
			// picked up, but the variable remains set to 3.
			// Visually, everything looks ok. But as far as the
			// scripts are concerned, she's still hiding up on the
			// roof. This is not fatal, but leads to a number of
			// glitches until the state is corrected. E.g. trying
			// to climb back up the ladder will cause Nico to climb
			// down again.
			//
			// Global variable 1017 keeps track of the mop. Setting
			// it to 2 means that the mop has been picked up. We
			// use that as the signal that Nico's state needs to be
			// updated as well.

			if (checkMopBug && parameter == 1017 && readVar(1003) != 2) {
				warning("Working around mop bug: Setting Nico's state");
				writeVar(1003, 2);
			}

			writeVar(parameter, value);
			debug(9, "CP_POP_GLOBAL_VAR32: scriptsVars[%d] = %d", parameter, value);
			break;
		case CP_ADDNPOP_LOCAL_VAR32:
			Read16ip(parameter);
			value = READ_LE_UINT32(localVars + parameter) + pop();
			WRITE_LE_UINT32(localVars + parameter, value);
			debug(9, "CP_ADDNPOP_LOCAL_VAR32: localVars[%d] => %d", parameter / 4, value);
			break;
		case CP_SUBNPOP_LOCAL_VAR32:
			Read16ip(parameter);
			value = READ_LE_UINT32(localVars + parameter) - pop();
			WRITE_LE_UINT32(localVars + parameter, value);
			debug(9, "CP_SUBNPOP_LOCAL_VAR32: localVars[%d] => %d", parameter / 4, value);
			break;
		case CP_ADDNPOP_GLOBAL_VAR32:
			// Add and pop a global variable
			Read16ip(parameter);
			value = readVar(parameter) + pop();
			writeVar(parameter, value);
			debug(9, "CP_ADDNPOP_GLOBAL_VAR32: scriptVars[%d] => %d", parameter, value);
			break;
		case CP_SUBNPOP_GLOBAL_VAR32:
			// Sub and pop a global variable
			Read16ip(parameter);
			value = readVar(parameter) - pop();
			writeVar(parameter, value);
			debug(9, "CP_SUBNPOP_GLOBAL_VAR32: scriptVars[%d] => %d", parameter, value);
			break;

		// Jump opcodes

		case CP_SKIPONTRUE:
			// Skip if the value on the stack is true
			Read32ipLeaveip(parameter);
			value = pop();
			if (!value) {
				ip += 4;
				debug(9, "CP_SKIPONTRUE: %d (IS FALSE (NOT SKIPPED))", parameter);
			} else {
				ip += parameter;
				debug(9, "CP_SKIPONTRUE: %d (IS TRUE (SKIPPED))", parameter);
			}
			break;
		case CP_SKIPONFALSE:
			// Skip if the value on the stack is false
			Read32ipLeaveip(parameter);
			value = pop();
			if (value) {
				ip += 4;
				debug(9, "CP_SKIPONFALSE: %d (IS TRUE (NOT SKIPPED))", parameter);
			} else {
				ip += parameter;
				debug(9, "CP_SKIPONFALSE: %d (IS FALSE (SKIPPED))", parameter);
			}
			break;
		case CP_SKIPALWAYS:
			// skip a block
			Read32ipLeaveip(parameter);
			ip += parameter;
			debug(9, "CP_SKIPALWAYS: %d", parameter);
			break;
		case CP_SWITCH:
			// switch
			value = pop();
			Read32ip(caseCount);

			// Search the cases
			foundCase = false;
			for (i = 0; i < caseCount && !foundCase; i++) {
				if (value == (int32)READ_LE_UINT32(code + ip)) {
					// We have found the case, so lets
					// jump to it
					foundCase = true;
					ip += READ_LE_UINT32(code + ip + 4);
				} else
					ip += 4 * 2;
			}

			// If we found no matching case then use the default

			if (!foundCase)
				ip += READ_LE_UINT32(code + ip);

			debug(9, "CP_SWITCH: [SORRY, NO DEBUG INFO]");
			break;
		case CP_SAVE_MCODE_START:
			// Save the start position on an mcode instruction in
			// case we need to restart it again
			savedStartOfMcode = ip - 1;
			debug(9, "CP_SAVE_MCODE_START");
			break;
		case CP_CALL_MCODE:
			// Call an mcode routine
			Read16ip(parameter);
			assert(parameter < ARRAYSIZE(opcodes));
			// amount to adjust stack by (no of parameters)
			Read8ip(value);
			debug(9, "CP_CALL_MCODE: '%s', %d", opcodes[parameter].desc, value);
			stackPtr -= value;
			assert(stackPtr >= 0);
			retVal = (this->*opcodes[parameter].proc)(&stack[stackPtr]);

			switch (retVal & 7) {
			case IR_STOP:
				// Quit out for a cycle
				WRITE_LE_UINT32(offsetPtr, ip);
				return 0;
			case IR_CONT:
				// Continue as normal
				break;
			case IR_TERMINATE:
				// Return without updating the offset
				return 2;
			case IR_REPEAT:
				// Return setting offset to start of this
				// function call
				WRITE_LE_UINT32(offsetPtr, savedStartOfMcode);
				return 0;
			case IR_GOSUB:
				// that's really neat
				WRITE_LE_UINT32(offsetPtr, ip);
				return 2;
			default:
				error("Bad return code (%d) from '%s'", retVal & 7, opcodes[parameter].desc);
			}
			parameterReturnedFromMcodeFunction = retVal >> 3;
			break;
		case CP_JUMP_ON_RETURNED:
			// Jump to a part of the script depending on
			// the return value from an mcode routine

			// Get the maximum value
			Read8ip(parameter);
			debug(9, "CP_JUMP_ON_RETURNED: %d => %d",
				parameterReturnedFromMcodeFunction,
				READ_LE_UINT32(code + ip + parameterReturnedFromMcodeFunction * 4));
			ip += READ_LE_UINT32(code + ip + parameterReturnedFromMcodeFunction * 4);
			break;

		// Operators

		case OP_ISEQUAL:
			b = pop();
			a = pop();
			push(a == b);
			debug(9, "OP_ISEQUAL: RESULT = %d", a == b);
			break;
		case OP_NOTEQUAL:
			b = pop();
			a = pop();
			push(a != b);
			debug(9, "OP_NOTEQUAL: RESULT = %d", a != b);
			break;
		case OP_GTTHAN:
			b = pop();
			a = pop();
			push(a > b);
			debug(9, "OP_GTTHAN: RESULT = %d", a > b);
			break;
		case OP_LSTHAN:
			b = pop();
			a = pop();
			push(a < b);
			debug(9, "OP_LSTHAN: RESULT = %d", a < b);
			break;
		case OP_GTTHANE:
			b = pop();
			a = pop();
			push(a >= b);
			debug(9, "OP_GTTHANE: RESULT = %d", a >= b);
			break;
		case OP_LSTHANE:
			b = pop();
			a = pop();
			push(a <= b);
			debug(9, "OP_LSTHANE: RESULT = %d", a <= b);
			break;
		case OP_PLUS:
			b = pop();
			a = pop();
			push(a + b);
			debug(9, "OP_PLUS: RESULT = %d", a + b);
			break;
		case OP_MINUS:
			b = pop();
			a = pop();
			push(a - b);
			debug(9, "OP_MINUS: RESULT = %d", a - b);
			break;
		case OP_TIMES:
			b = pop();
			a = pop();
			push(a * b);
			debug(9, "OP_TIMES: RESULT = %d", a * b);
			break;
		case OP_DIVIDE:
			b = pop();
			a = pop();
			push(a / b);
			debug(9, "OP_DIVIDE: RESULT = %d", a / b);
			break;
		case OP_ANDAND:
			b = pop();
			a = pop();
			push(a && b);
			debug(9, "OP_ANDAND: RESULT = %d", a && b);
			break;
		case OP_OROR:
			b = pop();
			a = pop();
			push(a || b);
			debug(9, "OP_OROR: RESULT = %d", a || b);
			break;

		// Debugging opcodes, I think

		case CP_DEBUGON:
			debug(9, "CP_DEBUGON");
			break;
		case CP_DEBUGOFF:
			debug(9, "CP_DEBUGOFF");
			break;
		case CP_TEMP_TEXT_PROCESS:
			Read32ip(parameter);
			debug(9, "CP_TEMP_TEXT_PROCESS: %d", parameter);
			break;
		default:
			error("Invalid script command %d", curCommand);
			return 3;
		}
	}

	return 1;
}
示例#26
0
void ScummEngine::checkExecVerbs() {
	int i, over;
	VerbSlot *vs;

	if (_userPut <= 0 || _mouseAndKeyboardStat == 0)
		return;

	if (_mouseAndKeyboardStat < MBS_MAX_KEY) {
		/* Check keypresses */
		if (!(_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD)) {
			// This is disabled in the SegaCD version as the "vs->key" values setup
			// by script-17 conflict with the values expected by the generic keyboard
			// input script. See tracker item #1193185.
			vs = &_verbs[1];
			for (i = 1; i < _numVerbs; i++, vs++) {
				if (vs->verbid && vs->saveid == 0 && vs->curmode == 1) {
					if (_mouseAndKeyboardStat == vs->key) {
						// Trigger verb as if the user clicked it
						runInputScript(kVerbClickArea, vs->verbid, 1);
						return;
					}
				}
			}
		}

		if ((_game.id == GID_INDY4 || _game.id == GID_PASS) && _mouseAndKeyboardStat >= '0' && _mouseAndKeyboardStat <= '9') {
			// To support keyboard fighting in FOA, we need to remap the number keys.
			// FOA apparently expects PC scancode values (see script 46 if you want
			// to know where I got these numbers from). Oddly enough, the The Indy 3
			// part of the "Passport to Adventure" demo expects the same keyboard
			// mapping, even though the full game doesn't.
			static const int numpad[10] = {
				'0',
				335, 336, 337,
				331, 332, 333,
				327, 328, 329
			};
			_mouseAndKeyboardStat = numpad[_mouseAndKeyboardStat - '0'];
		}

		if (_game.platform == Common::kPlatformFMTowns && _game.version == 3) {
			// HACK: In the FM-TOWNS games Indy3, Loom and Zak the most significant bit is set for special keys
			// like F5 (=0x8005) or joystick buttons (mask 0xFE00, e.g. SELECT=0xFE40 for the save/load menu).
			// Hence the distinction with (_mouseAndKeyboardStat < MBS_MAX_KEY) between mouse- and key-events is not applicable
			// to this games, so we have to remap the special keys here.
			if (_mouseAndKeyboardStat == 319) {
				_mouseAndKeyboardStat = 0x8005;
			}
		}

		if ((_game.platform == Common::kPlatformFMTowns && _game.id == GID_ZAK) &&
			(_mouseAndKeyboardStat >= 315 && _mouseAndKeyboardStat <= 318)) {
			// Hack: Handle switching to a person via F1-F4 keys.
			// This feature isn't available in the scripts of the FM-TOWNS version.
			int fKey = _mouseAndKeyboardStat - 314;
			int switchSlot = getVerbSlot(36, 0);
			// check if switch-verb is enabled
			if (_verbs[switchSlot].curmode == 1) {
				// Check if person is available (see script 23 from ZAK_FM-TOWNS and script 4 from ZAK_PC).
				// Zak: Var[144 Bit 15], Annie: Var[145 Bit 0], Melissa: Var[145 Bit 1], Leslie: Var[145 Bit 2]
				if (!readVar(0x890E + fKey)) {
					runInputScript(kVerbClickArea, 36 + fKey, 0);
				}
			}
			return;
		}

		// Generic keyboard input
		runInputScript(kKeyClickArea, _mouseAndKeyboardStat, 1);
	} else if (_mouseAndKeyboardStat & MBS_MOUSE_MASK) {
		VirtScreen *zone = findVirtScreen(_mouse.y);
		const byte code = _mouseAndKeyboardStat & MBS_LEFT_CLICK ? 1 : 2;

		// This could be kUnkVirtScreen.
		// Fixes bug #1536932: "MANIACNES: Crash on click in speechtext-area"
		if (!zone)
			return;

		over = findVerbAtPos(_mouse.x, _mouse.y);
		if (over != 0) {
			// Verb was clicked
			runInputScript(kVerbClickArea, _verbs[over].verbid, code);
		} else {
			// Scene was clicked
			runInputScript((zone->number == kMainVirtScreen) ? kSceneClickArea : kVerbClickArea, 0, code);
		}
	}
}
示例#27
0
QRectF NSParser::readFixedRect(Symbol* symbol, VariableList& variables)
{
	QRectF r(0,0,1,1);
	Tools::RPoint center;
	bool definedByCenter = false;
	double radius = 0;
	int nbParamRead = 0;
	if (symbol->type == NON_TERMINAL)
	{
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		for(Symbol* child: nt->children)
		{
			switch(child->symbolIndex)
			{
				case SYM_NUM:
				{
					double value = readNum(child);
					if (definedByCenter)
						radius = value;
					else if (nbParamRead == 0)
						r.setX(value);
					else if (nbParamRead == 1)
						r.setY(value);
					else if (nbParamRead == 2)
						r.setWidth(value);
					else
						r.setHeight(value);
					++nbParamRead;
					break;
				}
				case SYM_POINT:
				case SYM_FIXED_POINT:
				{
					definedByCenter = true;
					center = readPoint(child);
					break;
				}
				case SYM_VAR:
				{
					QString name = readVar(child);
					if (variables.contains(name))
					{
						DeclaredVariable& var = variables[name];
						if (var.isPoint())
						{
							center = var.toPoint();
							definedByCenter = true;
						}
						else
							addError(NSParsingError::invalidVariableTypeError(name, "point", child));
					}
					else
						addError(NSParsingError::undeclaredVariableError(name, child));


					break;
				}
			}
		}
	}

	if (definedByCenter)
	{
		r.setWidth(radius * 2.0);
		r.setHeight(radius * 2.0);
		r.moveCenter(center.toQPointF());
	}

	return r;
}
示例#28
0
Ttoken *Tmlex::getToken()
{
    Ttoken        *token   = NULL;
    TstrBuf        text    = "";
    unsigned long  textIdx = 0;
    int            found = 0;

    if (NULL != (token = popToken()))
    {
        return(token);
    }
    else
    {
        token = new Ttoken;
    }

    token->setType(TOK_ILLEGAL);

    while (!found)
    {
        int ch = Dinput.get();
        if (EOF != ch) text[textIdx++] = ch;

        if (EOF == ch)
        {
            // End of file
            token->setType(TOK_END);
            token->setText("");
            token->setPosn(Dinput.posn());
            found = 1;
        }
        else if ('\n' == ch)
        {
            token->setType(TOK_EOL);
            token->setText("");
            found = 1;
        }
        else if (isspace(ch))
        {
            // Ignore white space
        }
        else if (SEP_ESC == ch)
        {
            // excape
            ch = Dinput.get();

            if ('\n' == ch)
            {
                // ignore the end-of-line
            }
            else if (SEP_ESC == ch)
            {
                // Litteral
                Dinput.putBack(ch);
                token->setPosn(Dinput.posn());
                found = readIdent(*token);
            }
            else
            {
                // Excaped charactor
                Dinput.putBack(ch);
            }
        }
        else if ('#' == ch)
        {
            // Check for comment
            token->setPosn(Dinput.posn());
            ch = Dinput.get();

            found = readComment(*token);
        }
        else if (SEP_TEXT == ch)
        {
            // Text
            token->setPosn(Dinput.posn());
            found = readText(*token);
        }
        else if (SEP_S_VAR == ch)
        {
            // Start an evaluated variable (define)
            readVar();
        }
        else if (SEP_CALL == ch)
        {
            // Call
            token->setPosn(Dinput.posn());
            found = readCall(*token);
        }
        else if (isSymb(ch))
        {
            // Symbol
            token->setPosn(Dinput.posn());
            Dinput.putBack(ch);
            found = readSymb(*token);
        }
        else if (isIdent(ch))
        {
            // Ident
            token->setPosn(Dinput.posn());
            Dinput.putBack(ch);
            found = readIdent(*token);
        }
        else
        {
            while ((EOF != ch) && !isspace(ch)) ch = Dinput.get();
            if (EOF != ch) Dinput.putBack(ch);
        }
    }

    return(token);
}
示例#29
0
int main(int argc,char** argv)
{  int err;
   char cdmName[10];
   int spin2, charge3,cdim;

  ForceUG=0;  /* to Force Unitary Gauge assign 1 */
  
  if(argc< 2)
  { 
      printf(" Correct usage:  ./main  <file with parameters>    \n");
      printf("Example: ./main data1.par \n");
      exit(1);
  }
                               
  err=readVar(argv[1]);
  
   
  if(err==-1)     {printf("Can not open the file\n"); exit(1);}
  else if(err>0)  { printf("Wrong file contents at line %d\n",err);exit(1);}
           
  err=sortOddParticles(cdmName);
  if(err) { printf("Can't calculate %s\n",cdmName); return 1;}
  
   qNumbers(cdmName, &spin2, &charge3, &cdim);
   printf("\nDark matter candidate is '%s' with spin=%d/2\n",
    cdmName,       spin2); 
   if(charge3) { printf("Dark Matter has electric charge %d*3\n",charge3); exit(1);}
   if(cdim!=1) { printf("Dark Matter ia a color particle\n"); exit(1);}
#ifdef MASSES_INFO
{
  printf("\n=== MASSES OF HIGG AND ODD PARTICLES: ===\n");
  printHiggs(stdout);
  printMasses(stdout,1);
}
#endif

#ifdef OMEGA
{ int fast=1;
  double Beps=1.E-5, cut=0.0001;
  double Omega,Xf;   
//  deltaY=4.4E-13;

// to exclude processes with virtual W/Z in DM   annihilation      
     VZdecay=0; VWdecay=0; cleanDecayTable(); 

// to include processes with virtual W/Z  also  in co-annihilation 
//   VZdecay=2; VWdecay=2; cleanDecayTable(); 

  printf("\n==== Calculation of relic density =====\n");  
  Omega=darkOmega(&Xf,fast,Beps);
  printf("Xf=%.2e Omega=%.2e\n",Xf,Omega);
  printChannels(Xf,cut,Beps,1,stdout);   
  
  VZdecay=1; VWdecay=1; cleanDecayTable();  // restore default
}
#endif

#ifdef INDIRECT_DETECTION
{ 
  int err,i;
  double Emin=1,/* Energy cut  in GeV   */  sigmaV;
  double vcs_gz,vcs_gg;
  char txt[100];
  double SpA[NZ],SpE[NZ],SpP[NZ];
  double FluxA[NZ],FluxE[NZ],FluxP[NZ];
  double * SpNe=NULL,*SpNm=NULL,*SpNl=NULL;
  double Etest=Mcdm/2;
  
printf("\n==== Indirect detection =======\n");  

  sigmaV=calcSpectrum(4,SpA,SpE,SpP,SpNe,SpNm,SpNl ,&err);
    /* Returns sigma*v in cm^3/sec.     SpX - calculated spectra of annihilation.
       Use SpectdNdE(E, SpX) to calculate energy distribution in  1/GeV units.
       
       First parameter 1-includes W/Z polarization
                       2-includes gammas for 2->2+gamma
                       4-print cross sections             
    */
  printf("sigmav=%.2E[cm^3/s] = %.2E[pb] \n", sigmaV, sigmaV/2.9979E-26);  


  if(SpA)
  { 
     double fi=0.1,dfi=0.05; /* angle of sight and 1/2 of cone angle in [rad] */ 

     gammaFluxTab(fi,dfi, sigmaV, SpA,  FluxA);     
     printf("Photon flux  for angle of sight f=%.2f[rad]\n"
     "and spherical region described by cone with angle %.2f[rad]\n",fi,2*dfi);
#ifdef SHOWPLOTS
     sprintf(txt,"Photon flux[cm^2 s GeV]^{1} at f=%.2f[rad], cone angle %.2f[rad]",fi,2*dfi);
     displaySpectrum(FluxA,txt,Emin,Mcdm);
#endif
     printf("Photon flux = %.2E[cm^2 s GeV]^{-1} for E=%.1f[GeV]\n",SpectdNdE(Etest, FluxA), Etest);       
  }

  if(SpE)
  { 
    posiFluxTab(Emin, sigmaV, SpE,  FluxE);
#ifdef SHOWPLOTS     
    displaySpectrum(FluxE,"positron flux [cm^2 s sr GeV]^{-1}" ,Emin,Mcdm);
#endif
    printf("Positron flux  =  %.2E[cm^2 sr s GeV]^{-1} for E=%.1f[GeV] \n",
    SpectdNdE(Etest, FluxE),  Etest);           
  }
  
  if(SpP)
  { 
    pbarFluxTab(Emin, sigmaV, SpP,  FluxP  ); 
#ifdef SHOWPLOTS    
     displaySpectrum(FluxP,"antiproton flux [cm^2 s sr GeV]^{-1}" ,Emin, Mcdm);
#endif
    printf("Antiproton flux  =  %.2E[cm^2 sr s GeV]^{-1} for E=%.1f[GeV] \n",
    SpectdNdE(Etest, FluxP),  Etest);             
  }
}  
#endif

#ifdef RESET_FORMFACTORS
{
/* 
   The user has approach to form factors  which specifies quark contents 
   of  proton and nucleon via global parametes like
      <Type>FF<Nucleon><q>
   where <Type> can be "Scalar", "pVector", and "Sigma"; 
         <Nucleon>     "P" or "N" for proton and neutron
         <q>            "d", "u","s"

   calcScalarQuarkFF( Mu/Md, Ms/Md, sigmaPiN[MeV], sigmaS[MeV])  
   calculates and rewrites Scalar form factors
*/
  printf("\n======== RESET_FORMFACTORS ======\n");
 
  printf("protonFF (default) d %.2E, u %.2E, s %.2E\n",ScalarFFPd, ScalarFFPu,ScalarFFPs);                               
  printf("neutronFF(default) d %.2E, u %.2E, s %.2E\n",ScalarFFNd, ScalarFFNu,ScalarFFNs);

  calcScalarQuarkFF(0.46,27.5,34.,42.);

//  To restore default form factors of  version 2  call 
//  calcScalarQuarkFF(0.553,18.9,55.,243.5);
 
  printf("protonFF (new)     d %.2E, u %.2E, s %.2E\n",ScalarFFPd, ScalarFFPu,ScalarFFPs);                               
  printf("neutronFF(new)     d %.2E, u %.2E, s %.2E\n",ScalarFFNd, ScalarFFNu,ScalarFFNs);
}
#endif

#ifdef CDM_NUCLEON
{ double pA0[2],pA5[2],nA0[2],nA5[2];
  double Nmass=0.939; /*nucleon mass*/
  double SCcoeff;        

printf("\n==== Calculation of CDM-nucleons amplitudes  =====\n");   

    nucleonAmplitudes(CDM1,NULL, pA0,pA5,nA0,nA5);
    printf("CDM[antiCDM]-nucleon micrOMEGAs amplitudes:\n");
    printf("proton:  SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",pA0[0], pA0[1],  pA5[0], pA5[1] );
    printf("neutron: SI  %.3E [%.3E]  SD  %.3E [%.3E]\n",nA0[0], nA0[1],  nA5[0], nA5[1] ); 

  SCcoeff=4/M_PI*3.8937966E8*pow(Nmass*Mcdm/(Nmass+ Mcdm),2.);
    printf("CDM[antiCDM]-nucleon cross sections[pb]:\n");
    printf(" proton  SI %.3E [%.3E] SD %.3E [%.3E]\n",
       SCcoeff*pA0[0]*pA0[0],SCcoeff*pA0[1]*pA0[1],3*SCcoeff*pA5[0]*pA5[0],3*SCcoeff*pA5[1]*pA5[1]);
    printf(" neutron SI %.3E [%.3E] SD %.3E [%.3E]\n",
       SCcoeff*nA0[0]*nA0[0],SCcoeff*nA0[1]*nA0[1],3*SCcoeff*nA5[0]*nA5[0],3*SCcoeff*nA5[1]*nA5[1]);

}
#endif
  
#ifdef CDM_NUCLEUS
{ double dNdE[300];
  double nEvents;

printf("\n======== Direct Detection ========\n");    

  nEvents=nucleusRecoil(Maxwell,73,Z_Ge,J_Ge73,SxxGe73,NULL,dNdE);

  printf("73Ge: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));
                                                                                                         
#ifdef SHOWPLOTS
    displayRecoilPlot(dNdE,"Distribution of recoil energy of 73Ge",0,199);
#endif

  nEvents=nucleusRecoil(Maxwell,131,Z_Xe,J_Xe131,SxxXe131,NULL,dNdE);

  printf("131Xe: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));                                   
#ifdef SHOWPLOTS
    displayRecoilPlot(dNdE,"Distribution of recoil energy of 131Xe",0,199);
#endif

  nEvents=nucleusRecoil(Maxwell,23,Z_Na,J_Na23,SxxNa23,NULL,dNdE);

  printf("23Na: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));                                   
#ifdef SHOWPLOTS
    displayRecoilPlot(dNdE,"Distribution of recoil energy of 23Na",0,199);
#endif

  nEvents=nucleusRecoil(Maxwell,127,Z_I,J_I127,SxxI127,NULL,dNdE);

  printf("I127: Total number of events=%.2E /day/kg\n",nEvents);
  printf("Number of events in 10 - 50 KeV region=%.2E /day/kg\n",
                                   cutRecoilResult(dNdE,10,50));                                   
#ifdef SHOWPLOTS
    displayRecoilPlot(dNdE,"Distribution of recoil energy of 127I",0,199);
#endif
  
}
#endif 

#ifdef NEUTRINO
{ double nu[NZ], nu_bar[NZ],mu[NZ];
  double Ntot;
  int forSun=1;
  double Emin=0.01;

  printf("\n===============Neutrino Telescope=======  for  ");
  if(forSun) printf("Sun\n"); else printf("Earth\n");
  
  err=neutrinoFlux(Maxwell,forSun, nu,nu_bar);
#ifdef SHOWPLOTS
  displaySpectrum(nu,"nu flux from Sun [1/Year/km^2/GeV]",Emin,Mcdm);
  displaySpectrum(nu_bar,"nu-bar from Sun [1/Year/km^2/GeV]",Emin,Mcdm);
#endif
{ double Ntot;
  double Emin=10; //GeV
  spectrInfo(Emin/Mcdm,nu, &Ntot,NULL);
    printf(" E>%.1E GeV neutrino flux       %.3E [1/Year/km^2] \n",Emin,Ntot);
  spectrInfo(Emin/Mcdm,nu_bar, &Ntot,NULL);
    printf(" E>%.1E GeV anti-neutrino flux  %.3E [1/Year/km^2]\n",Emin,Ntot);
}

/* Upward events */

  muonUpward(nu,nu_bar, mu);
#ifdef SHOWPLOTS  
  displaySpectrum(mu,"Upward muons[1/Year/km^2/GeV]",1,Mcdm/2);
#endif
  { double Ntot;
    double Emin=1; //GeV
    spectrInfo(Emin/Mcdm,mu, &Ntot,NULL);
    printf(" E>%.1E GeV Upward muon flux    %.3E [1/Year/km^2]\n",Emin,Ntot);
  }

/* Contained events */
  muonContained(nu,nu_bar,1., mu);
#ifdef SHOWPLOTS  
  displaySpectrum(mu,"Contained  muons[1/Year/km^3/GeV]",Emin,Mcdm);
#endif
  { double Ntot;
    double Emin=1; //GeV
    spectrInfo(Emin/Mcdm,mu, &Ntot,NULL);
    printf(" E>%.1E GeV Contained muon flux %.3E [1/Year/km^3]\n",Emin,Ntot);
  }
}
#endif

#ifdef DECAYS
{  
  txtList L;
   double width,br;
   char * pname;   
   printf("\n================= Decays ==============\n");

   pname = "h";
   width=pWidth(pname,&L);
   printf("\n%s :   total width=%.3E \n and Branchings:\n",pname,width);
   printTxtList(L,stdout);

   pname = "~L";
   width=pWidth(pname,&L);
   printf("\n%s :   total width=%.3E \n and Branchings:\n",pname,width);
   printTxtList(L,stdout);
}
#endif


#ifdef CROSS_SECTIONS
{ double v0=0.001, Pcm=Mcdm*v0/2,cs;
  int err;
  numout*cc;

  cc=newProcess("~n,~N->W+,W-");
  passParameters(cc);
  cs=v0*cs22(cc,1,0.001*Mcdm/2,-1.,1.,&err);
  printf("cs=%e\n",cs);
}
#endif
  killPlots();
  return 0;
}
/*
 * Header format:
 * 
 * Pos Type     Data
 * -------------------------
 * 0   quint8   Type
 * 1   quint32  Optional id
 * 5   quint32  Data size
 * -------------------------
 * Total size: 9 bytes
 */
void LocalSocketPrivate::readData()
{
// 	qDebug("[%p] LocalSocketPrivate::readData()", this);
	
	// Try to read data
	disableReadNotifier();
  // Reset data size
  m_currentReadDataBuffer.clear();
  int numRead = 0;
  int nRead   = 0;
  do {
    // Resize read buffer
    if(m_currentReadDataBuffer.isEmpty()) {
      m_currentReadDataBuffer.resize(1024);
    } else if (readBufferSize() - m_currentReadDataBuffer.size() < 1024) {
      // We cannot use additional 1 KiB space anymore
      break;
    } else {
      // Add 1 KiB up to readBufferSize()
      m_currentReadDataBuffer.resize(m_currentReadDataBuffer.size() + 1024);
    }
    
    nRead	=	read(m_currentReadDataBuffer.data() + m_currentReadDataBuffer.size() - 1024, 1024);
    numRead += nRead;
  } while(nRead == 1024);
	enableReadNotifier();
	
	// Handle read data
	if(numRead > 0)
	{
		m_currentReadData.append(m_currentReadDataBuffer.constData(), numRead);
		
		// Analyze read data
		while(!m_currentReadData.isEmpty())
		{
// 			qDebug("[%p] LocalSocketPrivate::readData() - reading data", this);
			
			// Read package size if available
			if(!m_currentRequiredReadDataSize && m_currentReadData.size() >= HEADER_SIZE)
			{
				memcpy((char*)&m_currentRequiredReadDataSize, m_currentReadData.constData() + (HEADER_SIZE - sizeof(quint32)), sizeof(m_currentRequiredReadDataSize));
				// Add header size
				m_currentRequiredReadDataSize	+=	HEADER_SIZE;
			}
			
			// Check if we can read a package
			if(!m_currentRequiredReadDataSize || m_currentReadData.size() < m_currentRequiredReadDataSize)
			{
// 				qDebug("[%p] LocalSocketPrivate::readData() - Cannot read package yet: %d/%d", this, m_currentReadData.size(), m_currentRequiredReadDataSize);
				break;
			}
			
// 			static	int	_r_count	=	0;
// 			_r_count++;
// 			qDebug("[%p] LocalSocketPrivate::readData() - count: %d", this, _r_count);
			
			// Read meta data
			int					dataPos	=	0;
			quint8			readVarType;
			quint32			readVarOptId;
			quint32			readVarDataSize;
			
			// Type
			memcpy((char*)&readVarType, m_currentReadData.constData() + dataPos, sizeof(readVarType));
			dataPos	+=	sizeof(readVarType);
			// Optional id
			memcpy((char*)&readVarOptId, m_currentReadData.constData() + dataPos, sizeof(readVarOptId));
			dataPos	+=	sizeof(readVarOptId);
			// Data size
			memcpy((char*)&readVarDataSize, m_currentReadData.constData() + dataPos, sizeof(readVarDataSize));
			dataPos	+=	sizeof(readVarDataSize);
			
			Variant		readVar((Variant::Type)readVarType);
			readVar.setOptionalId(readVarOptId);
			
			// Set data
			if(readVarDataSize)
			{
				readVar.setValue(m_currentReadData.mid(dataPos, readVarDataSize));
				dataPos	+=	readVarDataSize;
			}
			
			// Remove data from buffer
			m_currentReadData.remove(0, dataPos);
			m_currentRequiredReadDataSize	=	0;
			
			// Append to temporary read buffer if necessary
			if(readVar.type() == Variant::SocketDescriptor || !m_tempReadBuffer.isEmpty())
				m_tempReadBuffer.append(readVar);
			else
			{
				{
					QWriteLocker	writeLock(&m_readBufferLock);
					m_readBuffer.append(readVar);
				}
				// We have read a package
				emit(readyRead());
			}
		}
	}
	
	checkTempReadData(true);
  
  // Lower read buffer size
  if(m_currentReadDataBuffer.size() > 1024)
    m_currentReadDataBuffer.resize(1024);
	
// 	qDebug("[%p] LocalSocketPrivate::~readData()", this);
}