Beispiel #1
0
int ex2(struct parser* p)
{
    int label_1 = label_count++;
    int stop = 0;

    if (ex3(p)) {
        out3("BF", label_1);
    }
    else if (output(p)) {
    }
    else {
        stop = 1;
    }

    if (stop) return 0;

    while (!stop) {
        if (ex3(p)) {
            out1("BE");
        }
        else if (output(p)) {
        }
        else {
            stop = 1;
        }
    }

    generate_label(label_1);

    return 1;
}
// test to run processing/example.py
TEST_F(SignalProcessingInterfaceTest, exampleTest) {
    android::String8 functionName("example");
    int nInputs = 8;
    int nOutputs = 4;
    bool inputTypes[8] = { true, true, true, true, false, false, false, false };
    bool outputTypes[4] = { true, true, false, false };

    android::sp<Buffer> in0(new Buffer(16, 16, true));
    char* data0 = in0->getData();
    for (size_t i = 0; i < in0->getSize(); i++) {
        data0[i] = i;
    }
    android::sp<Buffer> in1(new Buffer(16, 16, true));
    char* data1 = in1->getData();
    for (size_t i = 0; i < in1->getSize(); i++) {
        data1[i] = i;
    }
    android::sp<Buffer> in2(new Buffer(8, 8, false));
    char* data2 = in2->getData();
    for (size_t i = 0; i < in2->getSize(); i++) {
        data2[i] = i;
    }
    android::sp<Buffer> in3(new Buffer(8, 8, false));
    char* data3 = in3->getData();
    for (size_t i = 0; i < in3->getSize(); i++) {
        data3[i] = i;
    }
    TaskCase::Value in4((int64_t)100);
    TaskCase::Value in5((int64_t)100);
    TaskCase::Value in6(1.0f);
    TaskCase::Value in7(1.0f);
    void* inputs[8] = { &in0, &in1, &in2, &in3, &in4, &in5, &in6, &in7 };

    android::sp<Buffer> out0(new Buffer(16, 16, true));
    char* outdata0 = out0->getData();
    for (size_t i = 0; i < out0->getSize(); i++) {
        outdata0[i] = 0xaa;
    }
    android::sp<Buffer> out1(new Buffer(8, 8, false));
    char* outdata1 = out1->getData();
    for (size_t i = 0; i < out1->getSize(); i++) {
        outdata1[i] = 0xbb;
    }
    TaskCase::Value out2((int64_t)1000);
    TaskCase::Value out3(-1.0f);
    void *outputs[4] = { &out0, &out1, &out2, &out3 };

    ASSERT_TRUE(mSp->run( functionName,
            nInputs, inputTypes, inputs,
            nOutputs, outputTypes, outputs) == TaskGeneric::EResultOK);
    ASSERT_TRUE(*(in0.get()) == *(out0.get()));
    ASSERT_TRUE(*(in2.get()) == *(out1.get()));
    ASSERT_TRUE(in4 == out2);
    ASSERT_TRUE(in6 == out3);
}
Beispiel #3
0
bool create_output()
{
  coef::EstimateComputed();
  file_name = outfile;
  if (!outfile.empty())
    outfile += ".lst";
  if (!ser.empty())
  {
    if (outfile.empty())
      out_file = &cout;
    else
    {
      off.open(outfile.c_str());
      off.precision(prcsn);
      off.setf(ios::showpoint);
      if (!off)
      {
        cout << CANTCREATE << outfile << endl;
        return false;
      }
      out_file = &off;
    }
    if (!writefile.empty())
    {
      ofstream out((writefile + ".dat").c_str());
      for (iser = ser.begin(); iser != ser.end(); ++iser)
      {
        if ((*iser).hide)
          out << '*';
        out << (*iser).ID << ',' << endl;
        out << (*iser).f.id() << " ";
        for (size_t i = 0; i < (*iser).vs.size(); ++i)
        {
          out << "<var name=" << (*iser).vs[i]
            << " value=" << (*iser).vx[i] << "></var>";
          if (i != (*iser).vs.size() - 1)
            out << endl;
        }
        out << ',' << endl;
        out << (*iser);
        out << endl;
      }
      ofstream out2((writefile + ".axm").c_str());
      errors1(out2, true, true);
      ofstream out3((writefile + ".set").c_str());
      fl_series old = print_series;
      print_series = used_series;
      print_variances(out3, true);
      print_series = old;
    }
  }
  return true;
}
Beispiel #4
0
int main(int, char **)
try
{
    DB::ReadBufferFromFileDescriptor in1(STDIN_FILENO);
    DB::WriteBufferFromFileDescriptor out1(STDOUT_FILENO);
    DB::AsynchronousWriteBuffer out2(out1);
    DB::CompressedWriteBuffer out3(out2);

    DB::copyData(in1, out3);

    return 0;
}
catch (const DB::Exception & e)
{
    std::cerr << e.what() << ", " << e.displayText() << std::endl;
    return 1;
}
Beispiel #5
0
int ex3(struct parser* p)
{
    int label_1 = label_count++;

    whitespace(p);

    if (lstring(p, ".ID")) {
        out1("ID");
        return 1;
    }
    else if (lstring(p, ".NUMBER")) {
        out1("NUM");
        return 1;
    }
    else if (lstring(p, ".STRING")) {
        out1("SR");
        return 1;
    }
    else if (lstring(p, ".EMPTY")) {
        out1("SET");
        return 1;
    }
    else if (lstring(p, "(")) {
        ex1(p);
        lstring(p, ")");
        return 1;
    }
    else if (*(p->buf->begin) == '$') {
        p->buf->begin++;
        generate_label(label_1);
        ex3(p);
        out3("BT", label_1);
        out1("SET");
        return 1;
    }
    else if (identifier(p)) {
        out2("CLL", p->id);
        return 1;
    }
    else if (string(p)) {
        out2("TST", p->id);
        return 1;
    }
    return 0;
}
int main(int argc, char *argv[]) {
	/*
	 * argv[1] - ideal clusters FA
	 * argv[2] - ideal clusters RCM
	 * argv[3] - clusters to evaluation FA
	 * argv[4] - clusters to evaluation RCM
	 */

	if(argc < 3) {
		cout << "Invalid output parameters" << endl <<
				"\targv[1] - file with .rcm for original repertoire (mandatory)" << endl <<
				"\targv[2] - file with .clusters for original repertoire (mandatory)" << endl <<
				"\targv[3] - file with .rcm for constructed repertoire (mandatory)" << endl <<
				"\targv[4] - file with .clusters for constructed repertoire (mandatory)" << endl <<
				"\targv[5] - basename of resulting files";
		return 1;
	}

	ClustersEvaluator evaluator(argv[1], argv[2], argv[3], argv[4]);
	evaluator.Evaluate();
	evaluator.GetMetrics().Print(cout);
	string basename = CreateBaseName(string(argv[3]));
	if(argc > 3)
		basename = string(argv[5]);
	string metrics_fname = basename + ".txt";
	ofstream out(metrics_fname.c_str());
	cout << "Metrics were written to " << metrics_fname << endl;
	evaluator.GetMetrics().Print(out);
	out.close();

	// csv
	metrics_fname = basename + ".csv";
	ofstream out2(metrics_fname.c_str());
	evaluator.GetMetrics().PrintCSV(out2);
	out2.close();

	// size/percentage output
	string length_perc_fname = basename + ".size.perc";
	ofstream out3(length_perc_fname.c_str());
	evaluator.PrintSizeIdentityPercentage(out3);
	out3.close();

	//ClusterSizeHistogramFiller(evaluator.OriginalClusters()).WriteToFile(basename + ".original_clusters_sizes.txt");
	//ClusterSizeHistogramFiller(evaluator.ConstructedClusters()).WriteToFile(basename + ".constructed_clusters_sizes.txt");
}
DEF_TEST(UnflattenWithCustomFactory, r) {
    // Create and flatten the test flattenable
    SkBinaryWriteBuffer writeBuffer;
    sk_sp<SkFlattenable> flattenable1(new IntFlattenable(1, 2, 3, 4));
    writeBuffer.writeFlattenable(flattenable1.get());
    sk_sp<SkFlattenable> flattenable2(new IntFlattenable(2, 3, 4, 5));
    writeBuffer.writeFlattenable(flattenable2.get());
    sk_sp<SkFlattenable> flattenable3(new IntFlattenable(3, 4, 5, 6));
    writeBuffer.writeFlattenable(flattenable3.get());

    // Copy the contents of the write buffer into a read buffer
    sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten());
    writeBuffer.writeToMemory(data->writable_data());
    SkReadBuffer readBuffer(data->data(), data->size());

    // Register a custom factory with the read buffer
    readBuffer.setCustomFactory(SkString("IntFlattenable"), &custom_create_proc);

    // Unflatten and verify the flattenables
    sk_sp<IntFlattenable> out1((IntFlattenable*) readBuffer.readFlattenable(
            SkFlattenable::kSkUnused_Type));
    REPORTER_ASSERT(r, out1);
    REPORTER_ASSERT(r, 2 == out1->a());
    REPORTER_ASSERT(r, 3 == out1->b());
    REPORTER_ASSERT(r, 4 == out1->c());
    REPORTER_ASSERT(r, 5 == out1->d());

    sk_sp<IntFlattenable> out2((IntFlattenable*) readBuffer.readFlattenable(
            SkFlattenable::kSkUnused_Type));
    REPORTER_ASSERT(r, out2);
    REPORTER_ASSERT(r, 3 == out2->a());
    REPORTER_ASSERT(r, 4 == out2->b());
    REPORTER_ASSERT(r, 5 == out2->c());
    REPORTER_ASSERT(r, 6 == out2->d());

    sk_sp<IntFlattenable> out3((IntFlattenable*) readBuffer.readFlattenable(
            SkFlattenable::kSkUnused_Type));
    REPORTER_ASSERT(r, out3);
    REPORTER_ASSERT(r, 4 == out3->a());
    REPORTER_ASSERT(r, 5 == out3->b());
    REPORTER_ASSERT(r, 6 == out3->c());
    REPORTER_ASSERT(r, 7 == out3->d());
}
Beispiel #8
0
int ex1(struct parser* p)
{
    int alt_count=1;
    int label_1 = label_count++;

    printf("                              ; alternation %d\n", alt_count);
    ex2(p);

    while (lstring(p, "/")) {
        alt_count++;
        printf("                              ; alternation %d\n", alt_count);

        out3("BT", label_1);

        if (!ex2(p)) break;
    }
    generate_label(label_1);

    return 1;
}
Beispiel #9
0
void out(FILE* fbin2,double average, int d, unsigned long n_tuples,int n, option_t *opt) {

	double *tscore;
	double* *keyvalue;//score index->index
	tscore = (double*)malloc(n_tuples * sizeof(double));
	keyvalue = (double**)malloc(n_tuples * sizeof(double*));
	int **readin;
	readin = (int**)malloc(n_tuples * sizeof(int*));
	for (int i = 0; i < n_tuples; i++)
		readin[i] = (int*)malloc((d + 5) * sizeof(int));
	for (int i = 0; i < n_tuples; i++) {
		char *buf;
		buf = (char*)malloc((d + 5) * sizeof(char));
		fgets(buf, d + 5, fbin2);
		analyse(buf, sizeof(buf), readin[i]);
		fscanf(fbin2, "%f", &tscore[i]);
		keyvalue[i] = &tscore[i];
		free(buf);
	}
	qsort((void*)keyvalue, n_tuples, sizeof(double*), cmp_1);
	//------------------------------------------------------------------------
	FILE* fout1 = fopen("out1.txt", "w");
	FILE* fout2 = fopen("out2.txt", "w");
	if (n == 0) { fclose(fout1); fclose(fout2); }
	//1---------------------------------------------------------------------
	out1(fout1, n,keyvalue,tscore,d,readin);
	fclose(fout1);
	//2--------------------------------------------------------------------------
	out2(fout2, n, keyvalue, tscore, d, readin,n_tuples);
	fclose(fout2);
	//3--------------------------------------------------------------------------
	FILE* fout3 = fopen("out3.txt", "w");
	out3(fout2, n, keyvalue, tscore, d, readin, n_tuples,opt);
	fclose(fout3);
	//4------------------------------------------------------------------------------
	FILE* fout4 = fopen("out4.txt", "w");
	out4(fout2, n, keyvalue, tscore, d, readin, n_tuples, opt);
	fclose(fout4);
	//
	free(tscore); free(readin); free(keyvalue);
}
	int TetrahedronSetTopologyContainer::getTetrahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4)
	{
		if(!hasTetrahedraAroundVertex())
			createTetrahedraAroundVertexArray();

		sofa::helper::vector<unsigned int> set1 = getTetrahedraAroundVertex(v1);
		sofa::helper::vector<unsigned int> set2 = getTetrahedraAroundVertex(v2);
		sofa::helper::vector<unsigned int> set3 = getTetrahedraAroundVertex(v3);
		sofa::helper::vector<unsigned int> set4 = getTetrahedraAroundVertex(v4);

		sort(set1.begin(), set1.end());
		sort(set2.begin(), set2.end());
		sort(set3.begin(), set3.end());
		sort(set4.begin(), set4.end());	

		// The destination vector must be large enough to contain the result.
		sofa::helper::vector<unsigned int> out1(set1.size()+set2.size());
		sofa::helper::vector<unsigned int>::iterator result1;
		result1 = std::set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),out1.begin());
		out1.erase(result1,out1.end());

		sofa::helper::vector<unsigned int> out2(set3.size()+out1.size());
		sofa::helper::vector<unsigned int>::iterator result2;
		result2 = std::set_intersection(set3.begin(),set3.end(),out1.begin(),out1.end(),out2.begin());
		out2.erase(result2,out2.end());

		sofa::helper::vector<unsigned int> out3(set4.size()+out2.size());
		sofa::helper::vector<unsigned int>::iterator result3;
		result3 = std::set_intersection(set4.begin(),set4.end(),out2.begin(),out2.end(),out3.begin());
		out3.erase(result3,out3.end());

		assert(out3.size()==0 || out3.size()==1);

		if (out3.size()==1)
			return (int) (out3[0]);
		else
			return -1;
	}
//#define  BUFSIZE 1000
void AAM_Train::getMeanShape()
{
	double threshold=0.002;
	//transplate all the shapes to its gradivity
	for (int i=0;i<shapeNum;i++)
	{
		shape[i]->centerPts(2);
	}

	//normalize shape[0],save as ref
	int refInd=4;

	//namedWindow("1");
	//imshow("1",cvarrToMat(shape[refInd]->hostImage));
	//waitKey();
	//shape[refInd]->normalize(1);
	//if we want to control the complexity, do it here
	double *refshape=new double[shape[refInd]->ptsNum*2];
	for (int i=0;i<shape[refInd]->ptsNum*2;i++)
	{
		refshape[i]=shape[refInd]->ptsForMatlab[i]*1.0;
	}
	shape_scale=normalize(refshape,shape[refInd]->ptsNum);


	//align the shape
	int width=shape[refInd]->ptsNum;
	int height=2;
	int arraysize=width*2*sizeof(double);
	mxArray *referShape = NULL,*curMatMean=NULL,*newMatMean=NULL, *inputShape=NULL,*result = NULL;
	if (!(ep = engOpen("\0"))) {
		fprintf(stderr, "\nCan't start MATLAB engine\n");
		return;
	}
	referShape=mxCreateDoubleMatrix(width,height,mxREAL);
	curMatMean=mxCreateDoubleMatrix(width,height,mxREAL);
	newMatMean=mxCreateDoubleMatrix(width,height,mxREAL);
	inputShape=mxCreateDoubleMatrix(width,height,mxREAL);
	result=mxCreateDoubleMatrix(width,height,mxREAL);
	double *currentMean=new double[width*2];
	double *newMean=new double[width*2];

	//set the default refer shape
	memcpy((void *)mxGetPr(referShape), (void *)refshape, arraysize);
	
	//initialize currentMean to the refer shape
	for (int i=0;i<width*2;i++)
	{
		currentMean[i]=refshape[i];
	}

	ofstream out3("F:/imgdata/AAM training data/train/refshape.txt",ios::out);
	//for (int i=0;i<shapeNum;i++)
	{
		for(int j=0;j<width;j++)
		{
			out3<<refshape[j]<<" "<<refshape[width+j]<<endl;
		}
	}
	out3.close();
	
	//char buffer[BUFSIZE+1];
	engPutVariable(ep, "referShape", referShape);
	engPutVariable(ep, "result", result);
//	engEvalString(ep,"save('F:/imgdata/AAM training data/train/refershape.mat','referShape');");
	
//	engPutVariable(ep, "result", newMatMean);
	while(1)
	{
		//set current mean
		memcpy((void *)mxGetPr(curMatMean), (void *)currentMean, arraysize);
		engPutVariable(ep, "curMatMean", curMatMean);
		//allign all the shapes
		for (int i=0;i<shapeNum;i++)
		{
			memcpy((void *)mxGetPr(inputShape), (void *)shape[i]->ptsForMatlab, arraysize);
			engPutVariable(ep, "inputShape", inputShape);
			engEvalString(ep, "[m,result]=procrustes(curMatMean,inputShape);");
			result = engGetVariable(ep,"result");
//			delete []shape[i]->ptsForMatlab;
			shape[i]->ptsForMatlab=mxGetPr(result);	

			engEvalString(ep,"save('F:/imgdata/AAM training data/train/result.mat','result','curMatMean','inputShape');");
			//shape[i]->scale(shape[i]->scaleParameter,1);//reconver the scale
		}
		//caculate newMean and allign it to ref and normalize
		for (int i=0;i<width*2;i++)
		{
			newMean[i]=0;
		}
		for (int i=0;i<width*2;i++)
		{
			for (int j=0;j<shapeNum;j++)
			{
				newMean[i]+=shape[j]->ptsForMatlab[i];
			}
			newMean[i]/=shapeNum;
		}

		


		memcpy((void *)mxGetPr(newMatMean), (void *)newMean, arraysize);
		engPutVariable(ep, "newMatMean", newMatMean);
		engEvalString(ep, "[m,result]=procrustes(referShape,newMatMean);");
		//engEvalString(ep,"save('F:/imgdata/AAM training data/train/result.mat','result','referShape','newMatMean');");
		//delete []newMean;
		newMean=mxGetPr( engGetVariable(ep,"result"));	
		//normalize newMean
		normalize(newMean,width);

		ofstream out1("F:/imgdata/AAM training data/train/meanshape_ori.txt",ios::out);
		//for (int i=0;i<shapeNum;i++)
		{
			for(int j=0;j<width;j++)
			{
				out1<<newMean[j]<<" "<<newMean[width+j]<<endl;
			}
		}
		out1.close();

		//caculate the diff of means, if smaller than threshold, stop
		double differ=0,n2_newmean=0;
		for (int i=0;i<width;i++)
		{
			differ+=sqrt((newMean[i]-refshape[i])*(newMean[i]-refshape[i])+
				(newMean[width+i]-refshape[width+i])*(newMean[width+i]-refshape[width+i]));
		//	n2_newmean+=sqrt(newMean[i]*newMean[i]+newMean[width+i]*newMean[width+i]);
		}
		cout<<"current difference: "<<differ/shape_scale<<endl;
		if (differ/shape_scale<threshold)
		{

			//ofstream out("meanshape.txt",ios::out);
			//for (int i=0;i<meanShape->ptsNum;i++)
			//{
			//	out<<meanShape->pts[i][0]<<" "<<meanShape->pts[i][1]<<endl;
			//}
			//out.close();
			//save the new mean
			meanShape->getVertex(newMean,width,1,1);
			meanShape->scale(shape_scale,1);
			break;
		}

		//oldmean=newmean
		for (int i=0;i<width*2;i++)
		{
			currentMean[i]=newMean[i];
		}

	}
	//rescale all the shapes

	engClose(ep);

	//for (int i=0;i<shapeNum;i++)
	//{
	//	shape[i]->scale(scaleParameter,2);//scale to normal size,only for traning data
	//}

	//tangent space if needed

	ofstream out("F:/imgdata/AAM training data/train/allignedshape.txt",ios::out);
	for (int i=0;i<shapeNum;i++)
	{
		for(int j=0;j<width;j++)
		{
			out<<shape[i]->ptsForMatlab[j]<<" "<<shape[i]->ptsForMatlab[width+j]<<endl;
		}
	}
	out.close();

	ofstream out1("F:/imgdata/AAM training data/train/meanshape.txt",ios::out);
	//for (int i=0;i<shapeNum;i++)
	{
		for(int j=0;j<width;j++)
		{
			out1<<meanShape->ptsForMatlab[j]<<" "<<meanShape->ptsForMatlab[width+j]<<endl;
		}
	}
	out1.close();
	
	
	//delete []currentMean;
	//delete []newMean;
	//delete []refshape;
}
Beispiel #12
0
void System::createProfile(QString name, std::vector<QString> interfaces, QString defaultPolicyIN, QString defaultPolicyOUT)
{
    //Writing the profile info to the profile file
    QString pathString;
    QTextStream pathStream(&pathString);
    pathStream << this->systemPath << "/profiles/" << name << ".txt";
    QFile newProfile(pathString);
    newProfile.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out1(&newProfile);
    out1 << name << "\n";
    out1 << defaultPolicyIN << "\n";
    out1 << defaultPolicyOUT << "\n";
    out1 << this->currentProfile->getSystemTime() << "\n";
    out1 << this->currentProfile->getSystemTime() << "\n";
    newProfile.close();

    //Adding it to profileNames vector
    this->profileNames.push_back(name);

    //Writing the interfaces to the profile's interface file
    QString pathString2;
    QTextStream pathStream2(&pathString2);
    pathStream2 << this->systemPath << "/profiles/" << name << "-interfaces.txt";
    QFile newProfileInterfaces(pathString2);
    newProfileInterfaces.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out2(&newProfileInterfaces);

    out2 << interfaces.size() << "\n";
    for (unsigned int i=0;i<interfaces.size();i++)
        out2 << interfaces.at(i) << "\n";

    newProfileInterfaces.close();

    //Writing the default services to profile's services file
    QString pathString3;
    QTextStream pathStream3(&pathString3);
    pathStream3 << this->systemPath << "/profiles/" << name << "-services.txt";
    QFile newProfileServices(pathString3);
    newProfileServices.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out3(&newProfileServices);

    out3 << "FTP,21,tcp,drop\n";
    out3 << "FTP,21,tcp,drop\n";
    out3 << "SSH,22,tcp,accept\n";
    out3 << "Telnet,23,tcp,drop\n";
    out3 << "SMTP,25,tcp,drop\n";
    out3 << "DNS,53,tcp/udp,drop\n";
    out3 << "HTTP,80,tcp,accept\n";
    out3 << "HTTPS,443,tcp,drop\n";
    out3 << "NTP,123,udp,drop\n";
    out3 << "IMAP,143,tcp,drop\n";
    out3 << "SNMP,161,udp,drop\n";
    out3 << "SMB,445,tcp,drop\n";
    out3 << "PPTP,1723,tcp,drop\n";
    out3 << "MySQL,3306,tcp,drop\n";

    newProfileServices.close();

    //Wring profile list to profileList.txt
    QString pathString4;
    QTextStream pathStream4(&pathString4);
    pathStream4 << this->systemPath << "/profileList.txt";
    QFile profileList(pathString4);
    profileList.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out4(&profileList);

    int nrOfProfiles = this->profileNames.size();

    out4 << nrOfProfiles << "\n";

    if (this->firstTimeUse == TRUE)
        out4 << name << "\n";
    else
        out4 << this->currentProfile->getName() << "\n";

    for (int i=0;i<nrOfProfiles;i++)
        out4 << this->profileNames.at(i) << "\n";

    profileList.close();

    if (this->firstTimeUse == TRUE) {
        this->changeCurrentProfile(name);
        this->firstTimeUse = FALSE;
    }
}
Beispiel #13
0
bool BotanWrapper::DecryptFile(QString Source, QString Destination)
{
//qDebug() << "\n\n";
    QFileInfo name = Source;
    //qDebug() << Source;
    QString base = name.baseName();
    //qDebug() << base;
    QString encrypted3 = soutput + base + ".serpentdecrypted";
        //qDebug() << soutput;
    QString encrypted4 = tfoutput + base + ".twofishdecrypted";
    //qDebug() << toutput;
    try
    {
        //Setup the key derive functions
        PKCS5_PBKDF2 pbkdf2(new HMAC(new Keccak_1600));
        const u32bit PBKDF2_ITERATIONS = 700000;

        string inFilename3 = Source.toStdString();
        string outFilename3 = encrypted3.toStdString();
        std::ifstream in3(inFilename3.c_str(),std::ios::binary);
        std::ofstream out3(outFilename3.c_str(),std::ios::binary);
        char* salt3 = new char[256];
        in3.read(salt3 , 256 );
        qDebug() << "create salt";
SecureVector<byte> salts3((const byte*)salt3, 256 ) ;
mSalt3 = salts3;

        //Create the KEY and IV
        KDF* kdf3 = get_kdf("KDF2(Tiger)");
    qDebug() << "create master key";
        //Create the master key
        SecureVector<byte> mMaster3 = pbkdf2.derive_key(128, mPassword3.toStdString(), &mSalt3[0], mSalt3.size(),PBKDF2_ITERATIONS).bits_of();
        SymmetricKey mKey3 = kdf3->derive_key(32, mMaster3, "salt1");
        InitializationVector mIV3 = kdf3->derive_key(16, mMaster3, "salt2");

qDebug() << "begin serpent decrypt";
        Pipe pipe3(get_cipher("Serpent/CBC/PKCS7", mKey3, mIV3,DECRYPTION),new DataSink_Stream(out3));
        pipe3.start_msg();
        in3 >> pipe3;
        pipe3.end_msg();

        out3.flush();
        out3.close();
        in3.close();


/*************************TWOFISH DECRYPTION*************************/

        PKCS5_PBKDF2 pbkdf3(new HMAC(new Skein_512));
        string inFilename2 = encrypted3.toStdString();
        string outFilename2 = encrypted4.toStdString();
        std::ifstream in2(inFilename2.c_str(),std::ios::binary);
        std::ofstream out2(outFilename2.c_str(),std::ios::binary);
        char* salt2 = new char[256];
        in2.read(salt2 , 256 );
SecureVector<byte> salts2((const byte*)salt2, 256 ) ;
mSalt2 = salts2;
        //Create the KEY and IV
        KDF* kdf2 = get_kdf("KDF2(Whirlpool)");

        //Create the master key
        SecureVector<byte> mMaster2 = pbkdf3.derive_key(128, mPassword2.toStdString(), &mSalt2[0], mSalt2.size(),PBKDF2_ITERATIONS).bits_of();
        SymmetricKey mKey2 = kdf2->derive_key(32, mMaster2, "salt1");
        InitializationVector mIV2 = kdf2->derive_key(16, mMaster2, "salt2");

qDebug() << "twofish";
        Pipe pipe2(get_cipher("Twofish/CFB", mKey2, mIV2,DECRYPTION),new DataSink_Stream(out2));
        pipe2.start_msg();
        in2 >> pipe2;
        pipe2.end_msg();

        out2.flush();
        out2.close();
        in2.close();


/************AES DECRYPTION*************************/

        string inFilename = encrypted4.toStdString();
        string outFilename = Destination.toStdString();
        std::ifstream in(inFilename.c_str(),std::ios::binary);
        std::ofstream out(outFilename.c_str(),std::ios::binary);
        char* salt = new char[256];
        in.read(salt , 256 );
SecureVector<byte> salts((const byte*)salt, 256 ) ;
mSalt = salts;
        //Create the KEY and IV
        KDF* kdf = get_kdf("KDF2(SHA-512)");

        //Create the master key
        SecureVector<byte> mMaster = pbkdf2.derive_key(128, mPassword.toStdString(), &mSalt[0], mSalt.size(),PBKDF2_ITERATIONS).bits_of();
        SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
        InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");

qDebug() << "AES";
        Pipe pipe(get_cipher("AES-256/EAX", mKey, mIV,DECRYPTION),new DataSink_Stream(out));
        pipe.start_msg();
        in >> pipe;
        pipe.end_msg();

        out.flush();
        out.close();
        in.close();

        QMessageBox msgBox;
        msgBox.setText("Success!");
        msgBox.setInformativeText("File successfully decrypted!");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();

        QFile s(encrypted3), t(encrypted4);
        s.remove(); t.remove();

        return true;
    }
    catch(...)
    {
        return false;
    }
}
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_mcisendstring(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    std::wstring param1;
    types::String* pS = nullptr;

    int out2 = 0;
    std::wstring out3(L"OK");

    wchar_t output[2048];

    if (in.size() != 1)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (_iRetCount < 1 || _iRetCount > 3)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d to %d expected.\n"), fname.data(), 1, 3);
        return types::Function::Error;
    }


    if (in[0]->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    pS = in[0]->getAs<types::String>();
    if (pS->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    param1 = pS->get()[0];
    char* test = wide_string_to_UTF8(param1.data());
    char tout[2048];
    MCIERROR err = mciSendString(test, tout, sizeof(tout), NULL);
    out2 = (int)err;
    if (err)
    {
        wchar_t errtxt[128];

        if (mciGetErrorStringW(err, errtxt, 128) == FALSE)
        {
            os_swprintf(errtxt, L"%ls", L"Unknown MCI error");
        }

        out3 = errtxt;

        out.push_back(types::Bool::False());
    }
    else
    {
        out.push_back(types::Bool::True());
    }

    if (_iRetCount > 1)
    {
        out.push_back(new types::Double(out2));
    }

    if (_iRetCount > 2)
    {
        out.push_back(new types::String(out3.data()));
    }
    return types::Function::OK;
}
Beispiel #15
0
	void matrixCalc(void *outputs)
	{
		TML::Matrix out1(outputs, 0);
		TML::Matrix out2(outputs, 1);
		TML::Matrix out3(outputs, 2);
		TML::Matrix out4(outputs, 3);
		
		xn::DepthMetaData depthMD;
		xn::SceneMetaData sceneMD;
		xn::ImageMetaData imageMD;
		
		depth.GetMetaData(depthMD);
		user.GetUserPixels(0, sceneMD);
		image.GetMetaData(imageMD);
		
		context.WaitNoneUpdateAll();
		
		t_jit_matrix_info tmi;
		memset(&tmi, 0, sizeof(tmi));
		tmi.dimcount = 2;
		tmi.planecount = 1;
		tmi.dimstride[0] = 4;
		tmi.dimstride[1] = depthMD.XRes()*4;
		int width = tmi.dim[0] = depthMD.XRes();
		int height = tmi.dim[1] = depthMD.YRes();
		tmi.type = _jit_sym_float32;
		
		out1.resizeTo(&tmi);
		
		tmi.planecount = 1;
		tmi.dimstride[0] = 1;
		tmi.dimstride[1] = depthMD.XRes();
		tmi.type = _jit_sym_char;
		out2.resizeTo(&tmi);
		
		tmi.planecount = 4;
		tmi.dimstride[0] = 4;
		tmi.dimstride[1] = depthMD.XRes()*4;
		tmi.type = _jit_sym_char;
		out3.resizeTo(&tmi);
		
		const XnDepthPixel* pDepth = depthMD.Data();
		float *depthData = (float*)out1.data();
		
		//Copy depth data
		int x,y;
		for (y=0; y<height; y++)
		{
			for (x=0; x<width; x++)
			{
				depthData[0] = (float)pDepth[0]/powf(2, 15);
				
				depthData++;
				pDepth++;
			}
		}
		
		//Get the users
		unsigned char *userData = (unsigned char*)out2.data();
		const XnLabel* pLabels = sceneMD.Data();
		for (y=0; y<height; y++)
		{
			for (x=0; x<width; x++)
			{
				userData[0] = pLabels[0];
				
				userData++;
				pLabels++;
			}
		}
		
		//Get the colors
		const XnRGB24Pixel* pPixels = imageMD.RGB24Data();
		unsigned char *pixData = (unsigned char*)out3.data();
		for (y=0; y<height; y++)
		{
			for (x=0; x<width; x++)
			{
				pixData[0] = 0;
				pixData[1] = pPixels[0].nRed;
				pixData[2] = pPixels[0].nGreen;
				pixData[3] = pPixels[0].nBlue;
				
				pixData+=4;
				pPixels++;
			}
		}
		
		//For all the users -- output the joint info...
		XnUserID aUsers[15];
		XnUInt16 nUsers = 15;
		user.GetUsers(aUsers, nUsers);
		
		int rUsers = 0;
		
		xn::SkeletonCapability sc = user.GetSkeletonCap();
		
		int i;
		for (i=0; i<nUsers; i++)
		{
			if (user.GetSkeletonCap().IsTracking(aUsers[i]))
				rUsers++;
		}
		
		tmi.dimcount = 2;
		tmi.planecount = 3;
		tmi.dimstride[0] = 3*4;
		tmi.dimstride[1] = 24*3*4;
		tmi.dim[0] = 24;
		tmi.dim[1] = rUsers;
		tmi.type = _jit_sym_float32;
		out4.resizeTo(&tmi);
		
		
		float *sData = (float*)out4.data();
		
			
		if (rUsers == 0)
		{
			int n;
			for (n=0; n<24; n++)
			{					
				sData[0] = 0;
				sData[1] = 0;
				sData[2] = 0;
				
				sData+=3;
			}
		}
		else
		{
			for (i=0; i<nUsers; i++)
			{
				if (user.GetSkeletonCap().IsTracking(aUsers[i]))
				{
					int n;
					for (n=0; n<24; n++)
					{
						XnSkeletonJointPosition jp;
						user.GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], (XnSkeletonJoint)(n+1), jp);
						
						sData[0] = (1280 - jp.position.X) / 2560;
						sData[1] = (1280 - jp.position.Y) / 2560;
						sData[2] = jp.position.Z * 7.8125 / 10000;
						
//						if (n == 0)
//						{
//							post("%f %f %f\n", sData[0], sData[1], sData[2]);
//						}
						
						sData+=3;
					}
				}
			}
		}
		//post("%i\n", rUsers);
	}
int main() {
    std::string filename = "../data/bottle20_50.table";

    //////////////////// Initialize DENSO controller ////////////////////
    DensoController::DensoController denso;
    denso.bCapEnterProcess();
    BCAP_HRESULT hr;

    //////////////////// Get table from a file ////////////////////
    std::ifstream myfile(filename);
    std::string buff;
    std::vector<std::vector<double> > qvector;
    std::vector<double> q;

    qvector.resize(0);

    while(myfile.good()) {
        getline(myfile, buff, '\n');
        VectorFromString(buff, q);
        qvector.push_back(q);
    }



    // std::ifstream myfile(filename);
    // std::string temp;
    // std::string trajectorystring;
    // std::getline(myfile, temp);
    // trajectorystring += temp;
    // while (std::getline(myfile, temp)) {
    //     trajectorystring += "\n";
    //     trajectorystring += temp;
    // }
    // TOPP::Trajectory *ptraj = new TOPP::Trajectory(trajectorystring);
    // std::vector<double> q(ptraj->dimension);
    // std::vector<double> tmp;

    // //// VERY IMPORTANT :: MOVE TO INITIAL POSE BEFORE EXECUTING TRAJ IN SLAVE MODE ////
    hr = denso.SetExtSpeed("100");
    // std::cout << "Moving to the initial pose...\n";

    // ptraj->Eval(0.0, q);
    std::vector<double> tmp;
    tmp = qvector[0]; //DensoController::VRad2Deg(qvector[0]);
    std::string commandstring;
    const char* command;
    commandstring = "J(" + std::to_string(tmp[0]) + ", " + std::to_string(tmp[1])
                    + ", " + std::to_string(tmp[2]) + ", " + std::to_string(tmp[3])
                    + ", " + std::to_string(tmp[4]) + ", " + std::to_string(tmp[5]) + ")";
    command = commandstring.c_str(); // convert string -> const shar*
    std::cout << commandstring << "\n";
    denso.bCapRobotMove(command, "Speed = 25");
    sleep(2);

    hr = denso.bCapRobotExecute("ClearLog", ""); // enable control logging

    //////////////////// Build a LUT for the Trajectory ////////////////////
    double s = 0.0;
    // double slower = 1.0;
    // double timestep = 8.0*(1e-3)*slower;
    std::stringstream t;
    // std::vector<std::vector<double> > LUT;
    // std::cout << "Building a look-up table for the trajectory. . ." << "\n";
    // while (s < ptraj->duration) {
    //     ptraj->Eval(s, q);
    //     LUT.push_back(q);
    //     t << std::setprecision(17) << s << " ";
    //     s += timestep;
    // }

    int nsteps = qvector.size();

    ////////////////////////////// BEGIN SLAVE MODE //////////////////////////////
    hr = denso.bCapSlvChangeMode("514");

    BCAP_VARIANT vntPose, vntReturn;
    std::vector<BCAP_VARIANT> history;
    history.resize(0);

    std::stringstream trealtime;
    struct timespec tic, toc;

    s = 0.0;
    double step;
    q = qvector[0];
    vntPose = denso.VNTFromVector(q);
    clock_gettime(CLOCK_MONOTONIC, &tic); //TIC
    hr = bCap_RobotExecute2(denso.iSockFD, denso.lhRobot, "slvMove", &vntPose, &vntReturn);
    history.push_back(vntReturn);

    for (int i = 0; i < nsteps; i++) {
        q = qvector[i];
        vntPose = denso.VNTFromVector(q);
        clock_gettime(CLOCK_MONOTONIC, &toc); //TOC
        step = ((toc.tv_sec - tic.tv_sec) + (toc.tv_nsec - tic.tv_nsec)/nSEC_PER_SECOND);
        s += step;
        trealtime << std::setprecision(17) << s << " ";
        clock_gettime(CLOCK_MONOTONIC, &tic); //TIC
        hr = bCap_RobotExecute2(denso.iSockFD, denso.lhRobot, "slvMove", &vntPose, &vntReturn);
        history.push_back(vntReturn);
    }

    clock_gettime(CLOCK_MONOTONIC, &toc); //TOC
    s += (toc.tv_sec - tic.tv_sec) + (toc.tv_nsec - tic.tv_nsec)/nSEC_PER_SECOND;
    trealtime << std::setprecision(17) << s << " ";



    // while (s < ptraj->duration) {
    //     clock_gettime(CLOCK_MONOTONIC, &tic);
    //     clock_gettime(CLOCK_MONOTONIC, &tic1);
    //     ptraj->Eval(s, q);
    //     clock_gettime(CLOCK_MONOTONIC, &toc1);
    //     t << std::setprecision(17) << s << " ";
    //     vntPose = denso.VNTFromRadVector(q);
    //     clock_gettime(CLOCK_MONOTONIC, &tic2);
    //     hr = bCap_RobotExecute2(denso.iSockFD, denso.lhRobot, "slvMove", &vntPose, &vntReturn);
    //     clock_gettime(CLOCK_MONOTONIC, &toc2);
    //     // data collecting
    //     history.push_back(vntReturn);
    //     std::cout << "Eval = " << (toc1.tv_sec - tic1.tv_sec) + (toc1.tv_nsec - tic1.tv_nsec)/nSEC_PER_SECOND << "\n";
    //     std::cout << "Execute = " << (toc2.tv_sec - tic2.tv_sec) + (toc2.tv_nsec - tic2.tv_nsec)/nSEC_PER_SECOND << "\n";
    //     clock_gettime(CLOCK_MONOTONIC, &toc);
    //     s += (toc.tv_sec - tic.tv_sec) + (toc.tv_nsec - tic.tv_nsec)/nSEC_PER_SECOND;
    // }

    ////////////////////////////// STOP SLAVE MODE //////////////////////////////
    hr = denso.bCapSlvChangeMode("0");

    ////////////////////////////// SAVE ENCODER DATA //////////////////////////////
    std::stringstream ss;
    ss << std::setprecision(17) << history[0].Value.DoubleArray[0];
    for (int k = 1; k < 6; k++) {
        ss << " " << std::setprecision(17) << history[0].Value.DoubleArray[k];
    }
    ss << "\n";
    for (int i = 1; i < int(history.size()); i++) {
        ss << std::setprecision(17) << history[i].Value.DoubleArray[0];
        for (int j = 1; j < 6; j++) {
            ss << " " << std::setprecision(17) << history[i].Value.DoubleArray[j];
        }
        ss << "\n";
    }
    std::ofstream out1("densohistory.traj");
    out1 << ss.str();
    out1.close();
    std::cout << "waypoints successfully written in denhistory.traj\n";

    std::ofstream out2("densohistory.timestamp");
    out2 << t.str();
    out2.close();
    std::cout << "timestamp successfully written in denhistory.timestamp\n";

    std::ofstream out3("densohistory.realtimestamp");
    out3 << trealtime.str();
    out3.close();
    std::cout << "realtimestamp successfully written in denhistory.timestamp\n";


    ////////////////////////////// EXIT B-CAP PROCESS //////////////////////////////
    hr = denso.bCapRobotExecute("StopLog", "");
    denso.bCapExitProcess();
}
// ==> createPovRayFile(outputPath)
//  Build a POV-Ray output file based on the camera/light/sections properties
//  The POV-Ray file is always a wrapper for the scene written to a chosen output path under the name "combined.pov"
//  It checks if a section needs to be added and check for the the type of the cross section
//--------------------------------------------------------------------
bool CameraManager::createPovRayFile(QString outputPath)
{
	QFile file(outputPath + "combined.pov");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return 0;

    QTextStream out(&file);
	out << "// POVRAY file created by MCNPXVisualizer\n";
	out << "\n";
		
	out << "#include \"colors.inc\"\n";
	out << "#include \"stones.inc\"\n";
	out << "#include \"camera.pov\"\n";
	out << "#include \"lights.pov\"\n"; 
	out << "\n";
	out << "global_settings\n";
	out << "{\n";
	out << "\tmax_trace_level " << _maxTraceLevel << "\n";
	out << "}\n\n";

	out << "background   { color rgb <" << _backgroundColorRed << ", " << _backgroundColorGreen << ", " << _backgroundColorBlue << "> }\n";
	
	out << "difference{ \n";
	
	out << "\t#include \"" << _inputFileName << "\"\n";
	if (_clippedByImp0)
		out << "\t#include \"" << _inputFileName << "_imp0.pov" << "\"\n";
	out << "\n";

	if (_sections->_useShortCut)
	{
		if (_sections->_typeShortCut == Sections3D::SHORTCUT_X)
		{
			out << "\tplane {x, " << _sections->_shortCutBase << " inverse}\n";
		}
		else if (_sections->_typeShortCut == Sections3D::SHORTCUT_X_INVERSE)
		{
			out << "\tplane {x, " << _sections->_shortCutBase << "}\n";
		}
		else if (_sections->_typeShortCut == Sections3D::SHORTCUT_Y)
		{
			out << "\tplane {y, " << _sections->_shortCutBase << " inverse}\n";
		}
		else if (_sections->_typeShortCut == Sections3D::SHORTCUT_Y_INVERSE)
		{
			out << "\tplane {y, " << _sections->_shortCutBase << "}\n";
		}
		else if (_sections->_typeShortCut == Sections3D::SHORTCUT_Z)
		{
			out << "\tplane {z, " << _sections->_shortCutBase << " inverse}\n";
		}
		else if (_sections->_typeShortCut == Sections3D::SHORTCUT_Z_INVERSE)
		{
			out << "\tplane {z, " << _sections->_shortCutBase << "}\n";
		}
		else
		{
			std::cout << "ERROR (CameraManager::createPovRayFile)" << std::endl;
		}
	}
	else
	{
		if (_sectionsEnabled)
		{
			if (_sections->_typeSections == Sections3D::SECTIONS_RECTANGULAR)
			{
				out << "\tplane {z, " << _sections->_zPlaneMinPos-1 << "}\n";
				out << "\tplane {z, " << _sections->_zPlaneMaxPos-1 << " inverse}\n";
				out << "\tplane {y, " << _sections->_yPlaneMinPos-1 << "}\n";
				out << "\tplane {y, " << _sections->_yPlaneMaxPos-1 << " inverse}\n";
				out << "\tplane {x, " << _sections->_xPlaneMinPos-1 << "}\n";
				out << "\tplane {x, " << _sections->_xPlaneMaxPos-1 << " inverse}\n";
			}
			else if (_sections->_typeSections == Sections3D::SECTIONS_XY)
			{
				bool greaterThan180 = std::abs(_sections->_angleMax - _sections->_angleMin) > 180;
				if (!greaterThan180)
				{
				out << "\tplane {y, 0\n";
				out << "\t\trotate <0,0," << _sections->_angleMin << "> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
				out << "\t}\n";
				out << "\tplane {-y, 0\n";
				out << "\t\trotate <0,0," << _sections->_angleMax << "> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
				out << "\t }\n";
				}
				out << "\tcylinder {\n";
				out << "\t<0,0," << -_sections->_height/2.0 << ">, <0,0," << _sections->_height/2.0 << ">, " << _sections->_radius << " translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << "> inverse}\n";
				
				out << "\t\n";
				if (greaterThan180)
				{
					out << "\tclipped_by {\n";
					out << "\tunion {\n";
					out << "\tplane {-y, 0\n";
					out << "\t\trotate <0,0," << _sections->_angleMin << "> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t }\n";
					out << "\tplane {y, 0\n";
					out << "\t\trotate <0,0," << _sections->_angleMax << "> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t }\n";
					out << "\t }\n";
					out << "\t }\n";
				}
				
			}
			else if (_sections->_typeSections == Sections3D::SECTIONS_YZ)
			{
				bool greaterThan180 = std::abs(_sections->_angleMax - _sections->_angleMin) > 180;
				if (!greaterThan180)
				{
				out << "\tplane {z, 0\n";
				out << "\t\trotate <" << _sections->_angleMin << ",0,0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
				out << "\t}\n";
				out << "\tplane {-z, 0\n";
				out << "\t\trotate <" << _sections->_angleMax << ",0,0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
				out << "\t}\n";
				}
				out << "\tcylinder {\n";
				out << "\t<" << -_sections->_height/2.0 << ",0,0>, <" << _sections->_height/2.0 << ",0,0>, " << _sections->_radius << " translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << "> inverse}\n";
				
				out << "\t\n";
				if (greaterThan180)
				{
					out << "\tclipped_by {\n";
					out << "\tunion {\n";
					out << "\tplane {-z, 0\n";
					out << "\t\trotate <" << _sections->_angleMin << ",0,0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t }\n";
					out << "\tplane {z, 0\n";
					out << "\t\trotate <" << _sections->_angleMax << ",0,0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t }\n";
					out << "\t }\n";
					out << "\t }\n";
				}
			}
			else if (_sections->_typeSections == Sections3D::SECTIONS_XZ)
			{
				bool greaterThan180 = std::abs(_sections->_angleMax - _sections->_angleMin) > 180;
				if (!greaterThan180)
				{
					out << "\tplane {x, 0\n";
					out << "\t\trotate <0," << _sections->_angleMin << ",0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t}\n";
					out << "\tplane {-x, 0\n";
					out << "\t\trotate <0," << _sections->_angleMax << ",0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t}\n";		
				}
				out << "\tcylinder {\n";
				out << "\t<0," << -_sections->_height/2.0 << ",0>, <0," << _sections->_height/2.0 << ",0>, " << _sections->_radius << " translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << "> inverse}\n";
				
				out << "\t\n";
				if (greaterThan180)
				{
					out << "\tclipped_by {\n";
					out << "\tunion {\n";
					out << "\tplane {-x, 0\n";
					out << "\t\trotate <0," << _sections->_angleMin << ",0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t }\n";
					out << "\tplane {x, 0\n";
					out << "\t\trotate <0," << _sections->_angleMax << ",0> translate <" << _sections->_strafeX << "," << _sections->_strafeY << "," << _sections->_strafeZ << ">\n";
					out << "\t }\n";
					out << "\t }\n";
					out << "\t }\n";
				}
			}
		
		}
	}
	
	out << "\n";
	out << "\tcutaway_textures\n";
	out << "} \n";
	
	file.close();

	QFile file2(outputPath + "camera.pov");
    if (!file2.open(QIODevice::WriteOnly | QIODevice::Text))
        return 0;

    QTextStream out2(&file2);
	out2 << "// POVRAY file created by MCNPXVisualizer\n";
	out2 << "\n";
	
	// Writes the camera object to file
	if (_cameraString == "")
	{
		out2 << "camera\n";
		out2 << "{   \n";   
		if (_useOrthographicProjection)
			out << "\torthographic\n";
		out2 << "\tlook_at <" << _camera->_camStrafeX << "," << _camera->_camStrafeY << "," << _camera->_camStrafeZ << ">\n";
		out2 << "\tlocation <" << _camera->_camPosX + _camera->_camStrafeX << "," << _camera->_camPosY + _camera->_camStrafeY << "," << _camera->_camPosZ + _camera->_camStrafeZ << "> \n";   
		out2 << "\tright  <-4/3,0,0>  \n"; 
		out2 << "\tangle 45.0\n";
		
		out2 << "}\n";
	}
	else
	{
		out2 << _cameraString;
	}

	file2.close();

	// Put the light object at the same position as the camera
	QFile file3(outputPath + "lights.pov");
    if (!file3.open(QIODevice::WriteOnly | QIODevice::Text))
        return 0;

    QTextStream out3(&file3);
	out3 << "// POVRAY file created by MCNPXVisualizer\n";
	out3 << "\n";
	if (_lightString == "")
	{
		out3 << "light_source\n";
		out3 << "{\n";
		  out3 << "\t<" << _camera->_camPosX << "," << _camera->_camPosY << "," << _camera->_camPosZ << "> \n";   
		  out3 << "\tcolor White\n";
		out3 << "}\n";
	}
	else
	{
		out3 << _lightString;
	}

	file3.close();
    return 1;
}
Beispiel #18
0
int main (int argc, char * const argv[])
{   
	
  iparam = atoi(argv[1]);
  cout << "iparam= " << iparam;

   cout << "\n\n//////////////////////////////////////////////////" << endl;
    cout << "//////////////////////////////////////////////////" << endl;
    cout << "TDSE Simulation . ..." << endl;
    cout << "//////////////////////////////////////////////////" << endl;
    cout << "//////////////////////////////////////////////////" << endl;
   	
	
	clock_t ct0,ct1;
	
	
	fstream axes("axes.txt",ios::out);
    fstream qaxes("qaxes.txt",ios::out);
	fstream out0("out0.txt",ios::out);
    fstream out1("out1.txt",ios::out);
    fstream out2("out2.txt",ios::out);
    fstream out3("out3.txt",ios::out);    
    fstream out4("out4.txt",ios::out);
    fstream out5("out5.txt",ios::out);	
    fstream out6("out6.txt",ios::out);	
	
	
	fstream B1axes("B1axes.txt",ios::out);
    fstream B1qaxes("B1qaxes.txt",ios::out);
	fstream B1out0("B1out0.txt",ios::out);
    fstream B1out1("B1out1.txt",ios::out);
    fstream B1out2("B1out2.txt",ios::out);
    fstream B1out3("B1out3.txt",ios::out);    
    fstream B1out4("B1out4.txt",ios::out);
    fstream B1out5("B1out5.txt",ios::out);	
    fstream B1out6("B1out6.txt",ios::out);	
	
	
	fstream B2axes("B2axes.txt",ios::out);
    fstream B2qaxes("B2qaxes.txt",ios::out);
	fstream B2out0("B2out0.txt",ios::out);
    fstream B2out1("B2out1.txt",ios::out);
    fstream B2out2("B2out2.txt",ios::out);
    fstream B2out3("B2out3.txt",ios::out);    
    fstream B2out4("B2out4.txt",ios::out);
    fstream B2out5("B2out5.txt",ios::out);	
    fstream B2out6("B2out6.txt",ios::out);	
	
	
	
	FILE *laserout, *out7, *out8, *out9, *out10, *out11;
	laserout=fopen("outa.txt","w");
	
	out7	= fopen("out7.txt","w");
	out8	= fopen("out8.txt","w");
	out9	= fopen("out9.txt","w");
	out10	= fopen("out10.txt","w");
	out11	= fopen("out11.txt","w");	

	//=================================//	
	// LASER OBJECT DEFINITION 
	//.................................//	
	
	//Laser parameters
	double E0		= 0.01 + .01*iparam ;//0.04;
	double I0		= E0*E0*3.5e16;			//Intensity w/cm^2
	double wfreq	= 0.057;//0.55185513-0.38881693 -0.003;//1.634e-3;//0.057;				//fequency a.u.
	
	
	int ncycle		= 4;				//Number Cycles / be equivalent to time-bandwidth
	double cep		= 0*pi/2. ;			//CEP
	double period0  = dospi/wfreq;       // Period
	double ir_period = period0;
	
	
	
	//Creating LASER PULSE	
	int npulses      = 1;	                       // Number of pulses		
	string env_name ="rsin2";              
	
										/**** 
											IMPORTANT The Name of the envelop, may be: 
											rect, sin2, gauss or rsin2.
											*****/ 
	
	double tstart     = 0;					// Start time of the first pulse
	double realdt     = 0.05;				// Temporary increase
	
	double offset     = 55.;					// Time before the pulse atomic unit
	double outset     = 55.;				// Time after the pulse atomic unit
	
	
		
	laser fpulse(npulses);					// Constructor of Laser Pulses
	
	
	
	//First pulse Laser
	fpulse.I0[0]		= I0;					// Intensity W/cm^2 
	fpulse.e[0]			= 0.00;				// Elliptical of the pulse
	fpulse.w0[0]		= wfreq;              // Central frequency
   	fpulse.cycles0[0]	= ncycle;				// Cycles number
   	fpulse.cep0[0]		= cep;				// Carrier Envelop Phase
	fpulse.phi_rel[0]	= 0.;					// Relative phase between the polarization Ex and Ey
	
		
	fpulse.envelope[0]	= env_name;            // Envelop name
	
	
   	fpulse.laser_pulses(realdt, tstart,  offset,  outset);  // Making the linear polarization pulse Ey
	
	
	//Printing laser parameters
	cout << "\n//****************************************//"<<endl;
	cout << "           LASER PARAMETERS     "<<endl;
	cout << "//****************************************//"<<endl;	
	cout << "\nTimeStep= "		<<realdt ;
	cout << "    Ntime=  "		<<fpulse.Nmaxt ;	
	cout << "\nIntensity=  "	<<fpulse.I0[0] ;
	cout << "\nFrequency=  "	<<fpulse.w0[0] ;	
	cout << "\nCycles=  "		<<fpulse.cycles0[0] ;	
	cout << "\nCEP= "			<<fpulse.cep0[0];		
	cout << "\nElliptical= "	<<fpulse.e[0] ;	
	cout << "\nRelative_Elliptical_Phase= "   <<fpulse.phi_rel[0]<<endl;		
	
	
	
	
	// Save the laser pulse
	for (int ktime=0; ktime<fpulse.Nmaxt; ktime++)
		fprintf(laserout,"%e %e %e %e %e %e\n",
				fpulse.g.t[ktime],
				real(fpulse.efield.f[ktime]), real(fpulse.avector.f[ktime]),
				imag(fpulse.efield.f[ktime]), imag(fpulse.avector.f[ktime]),
				imag(fpulse.env[0].f[ktime]));
    //End save the laser pulse	
	
	
	
	
	//Laser parameters // 
	fprintf(out9,"%e %e %e %e %e %e ", 
			fpulse.I0[0], fpulse.w0[0], 
			fpulse.cycles0[0], fpulse.cep0[0], 
			fpulse.e[0], fpulse.phi_rel[0]);
	
	
	
	
	
	
	//=================================//	
	// SPATIAL PARAMETERs 
	//.................................//	
    
	
	int smallNr		  = 300;//1000;//
	int smallNz		  = 600;//3000;//	
	
	
	
	
	int largeNr       = 800;
	int largeNz       = 1600;
    
	
	
	
    double dz		  = 0.3;
    double dr		  = 0.3;
    complex complexdt = realdt;//complex(dr*dr,0.);
    
	
	
	
	
	// Hydrogen parameters     
	double V0		= 7.565;
    double alpha	= 0.160;	
	
	
	
	
	//Rmax parameter and snaper
	double smallRmax  = smallNr*dr;	
	double largeRmax  = largeNr*dr;
	
	int snap          = floor(fpulse.Nmaxt/40);	
	int snaper1       = 4;
	int snaper2       = 4;
	
	
	
	
    //Print out the information on the screen 
	
	//cout.setf(ios::scientific);
	cout.precision(8);
	

	cout << "\n//****************************************//"<<endl;
	cout << "    Grid Parameters     "<<endl;
	cout << "//****************************************//"<<endl;					
	
	cout << "\nsmallNr= "     <<   smallNr      << endl;
	cout << "largeNr= "     <<   largeNr      << endl;	
    cout << "smallNz= "     <<   smallNz      << endl;
    cout << "largeNz= "     <<   largeNz      << endl;	
	cout << "dz= "          <<   dz           << endl;
    cout << "dt= "          <<   abs(complexdt)  << endl;
	cout << "smallRmax= "   <<   smallRmax    << endl;
	cout << "lageRmax= "    <<   largeRmax    << endl;	
    
	
	fprintf(out8,"%e %e %d %d %d %d \n",  dr, dz, smallNr, smallNz, largeNr, largeNz);
	

	
    ////////////////////////
    //  Declare objects  //
    ///////////////////////
	HankelMatrix HGround(smallNr, smallRmax);	
    HankelMatrix HH( largeNr, largeRmax );

	
	
    waveUniform2D w;
	waveUniform2D w0;
    waveUniform2D wg0;
	waveUniform2D wg1;	
    waveUniform2D wg2;
	waveUniform2D wg3;	
	
	waveUniform2D wGround;	
	waveUniform2D wGround0;		
	waveUniform2D wGround1;		
	waveUniform2D wGround2;		
	waveUniform2D wGround3;		
	
	
	
	//Declare Object Hankel wave
	waveH2D w1;
	
	
	
	wGround.initialize(  HGround, smallNz, dz);
	wGround0.initialize( HGround, smallNz, dz);	
	wGround1.initialize( HGround, smallNz, dz);
	wGround2.initialize( HGround, smallNz, dz);	
	wGround3.initialize( HGround, smallNz, dz);	
	
    w.initialize(  HH, largeNz, dz);
    w0.initialize( HH, largeNz, dz);
	w1.initialize( HH, largeNz, dz);

    wg0.initialize( HH, largeNz, dz);
	wg1.initialize( HH, largeNz, dz);	
    wg2.initialize( HH, largeNz, dz);
	wg3.initialize( HH, largeNz, dz);		
	
	//return 0;	
	
	//Load ground state with binary function
	FILE *bwave,*bwave0,*bwave1,*bwave2,*bwave3;
	//bwave=fopen("/Users/alexisagustinchaconsalazar/Dropbox/CODE/BALAS/TestPoshTeller/Bound/Grid300x600/binwave0.bin","rb");
	//bwave=fopen("/Users/alexisagustinchaconsalazar/Dropbox/CODE/BALAS/TestPoshTeller/Bound/Grid1000x3000/Bigbinwave0.bin","rb") ;				
	///Users/alexis/Google Drive/LaserInteraction/BALAS/TestPoshTeller/Bound
	
	
	/*
	bwave=fopen("/Users/alexis/Google\ Drive/LaserInteraction/BALAS/TestPoshTeller/Bound/dr03/Grid300X600/binwave0.bin","rb") ;
	bwave0=fopen("/Users/alexis/Google\ Drive/LaserInteraction/BALAS/TestPoshTeller/Bound/dr03/Grid300X600/binwave0.bin","rb") ;
	bwave1=fopen("/Users/alexis/Google\ Drive/LaserInteraction/BALAS/TestPoshTeller/Bound/dr03/Grid300X600/binwave1.bin","rb") ;
	bwave2=fopen("/Users/alexis/Google\ Drive/LaserInteraction/BALAS/TestPoshTeller/Bound/dr03/Grid300X600/binwave2.bin","rb") ;
	bwave3=fopen("/Users/alexis/Google\ Drive/LaserInteraction/BALAS/TestPoshTeller/Bound/dr03/Grid300X600/binwave2.bin","rb") ;
	*/
	
	bwave=fopen("../Bound/binwave0.bin","rb") ;
	bwave0=fopen("../Bound/binwave0.bin","rb") ;
	bwave1=fopen("../Bound/binwave1.bin","rb") ;
	bwave2=fopen("../Bound/binwave2.bin","rb") ;
	bwave3=fopen("../Bound/binwave2.bin","rb") ;
	
	
	
	
	wGround.binread( bwave);
	wGround0.binread(bwave0);	
	wGround1.binread(bwave1);
	wGround2.binread(bwave2);	
	wGround3.binread(bwave3);	
	
	//wGround.rho_gaussian( 0., 0., 2., 2. );
	
	
    // Set hydrogen potential	
    wGround.set_potential_hlike2D(   1., 0.);
    wGround0.set_potential_hlike2D(  1., 0.);
    wGround1.set_potential_hlike2D(  1., 0.);	
    wGround2.set_potential_hlike2D(  1., 0.);
    wGround3.set_potential_hlike2D(  1., 0.);	
	
	
    w.set_potential_hlike2D(    1., 0.);
    w0.set_potential_hlike2D(   1., 0.); 
	w1.set_potential_hlike2D(	1., 0.);
    
    wg0.set_potential_hlike2D(  1., 0.);
	wg1.set_potential_hlike2D(  1., 0.); 	
    wg2.set_potential_hlike2D(  1., 0.); 
	wg3.set_potential_hlike2D(  1., 0.);
	
	
	
	// Save axes	
    w.saveAxes(axes,snaper1,snaper2);
	w1.saveQAxes(qaxes,snaper1,snaper2);
    
	placeWF( w,   wGround);
	placeWF( wg0, wGround0);
	placeWF( wg1, wGround1);
	placeWF( wg2, wGround2);
	placeWF( wg3, wGround3);	

	
	
	
	
	cout << "\n//****************************************//"<<endl;
	cout << "    Check norm and ground-state eigen energy     "<<endl;
	cout << "//****************************************//"<<endl;					
	
    cout << "\n\nOriginal norm= " << w.norm() << endl;
    w.normalize();
    cout << "Initial norm= " << w.norm();    
	
	
	
	double EnergyTemp	= wGround0.kinetic_energy_finite()+wGround0.potential_energy();
	double EnergyTemp1	= wGround1.kinetic_energy_finite()+wGround1.potential_energy();
	double EnergyTemp2	= wGround2.kinetic_energy_finite()+wGround2.potential_energy();
	double EnergyTemp3	= wGround3.kinetic_energy_finite()+wGround3.potential_energy();
	
	
	
    cout <<"\nE0LargeG= "<<EnergyTemp<<endl;
	cout << "E0SmallG = " << w.kinetic_energy_finite()+w.potential_energy();
	
    cout <<"\nE1LargeG= "<<EnergyTemp1<<endl;
	cout << "E1SmallG = " << wg1.kinetic_energy_finite()+wg1.potential_energy();	

    cout <<"\nE2LargeG= "<<EnergyTemp2<<endl;
	cout << "E2SmallG = " << wg2.kinetic_energy_finite()+wg2.potential_energy();	

    cout <<"\nE3LargeG= "<<EnergyTemp3<<endl;
	cout << "E3SmallG = " << wg3.kinetic_energy_finite()+wg3.potential_energy();	
	
	
	fprintf(out9," %e  %e  %e  %e ",abs(EnergyTemp), EnergyTemp1,EnergyTemp2,EnergyTemp3);
	
    
	
	

	
	//=================================//	
	//		Temporary propagation 
	//.................................//		
	
	// Mask parameters	
    double masc0       = 20.;
    double masc1       = 35.;
	double sigma_masc  = 10. ;
	double Energy1     = 0.0;
	double Energy2     = 0.0;
	
	
	
	
	
	
	cout << "\n//****************************************//"<<endl;
	cout << "    Check norm and ground-state eigen energy     "<<endl;
	cout << "//****************************************//"<<endl;				
	

	cout << "\n\nOriginal norm= " << w.norm() << endl;
    w.normalize();
    cout << "Initial norm= " << w.norm() << endl;
    cout <<"Energy= "<<w.kinetic_energy_finite()+w.potential_energy();	
		
	
	
	
	
	cout << "\n//****************************************//"<<endl;
	cout << "           Real Temporary evolution     "<<endl;
	cout << "//****************************************//"<<endl;			

	
	Energy1 = 0.0;
	complexdt = realdt;//complex(.05,0.);
	cout << "\ndt ="<<complexdt<< "  Ntime= "<<  fpulse.Nmaxt << endl;
	
	
	// ****************************** 
	// Time Flags //
	
	cout << "\nTime Flags \n";
	double t0		= fpulse.g.t[0];
	
	double ir_t0	= fpulse.clock0[1]+fpulse.cycles0[1]*ir_period*.3;
	double ir_tf	= fpulse.clock0[1]+fpulse.cycles0[1]*ir_period*.5;//fpulse.clock2[1];	
	double ir_tfs	= ir_tf + fpulse.cycles0[1]*ir_period;
	

	
	int NtimeEvol   = floor( ( ir_tfs - t0 )/fpulse.dt)+1;
	
	int ir_t0_index = floor( ( ir_t0 - t0 )/fpulse.dt )+1;
	int ir_tf_index = floor( ( ir_tf - t0 )/fpulse.dt )+1;
	
	
	cout << "\nIR-t0= "		<< ir_t0;	
	cout << "    IR-tf= "	<< ir_tf << "  Long-t= " << ir_tf-ir_t0 << endl<<endl;
	cout << "NtimeEvol= "	<< NtimeEvol <<endl;	
	
	
	complex P0, P1, P2, P3;
	
	//Preparing Crank-Nicholson arrrays    
	w.PrepareCrankArraysOnRho(complexdt    );
	w.PrepareCrankArraysOnZ(  complexdt/2. );
	//w.PrepareCrankArraysOnZLaserAV(  complexdt/2. );
	
	double adip		= 0.;
	double TotNorm  = 0.;

	//Start Loop propagation on time    
	for (int ktime=0; ktime<fpulse.Nmaxt; ktime++)
	{
		
		
		//w.parallel_evolution( complexdt);
		
		//Velocity Gauge
		/*
	     w.Zprop_PAG(complexdt/2., imag(fpulse.avector.f[ktime]) );
		 w.Rprop(complexdt);
		 w.Zprop_PAG(complexdt/2., imag(fpulse.avector.f[ktime]) );
		 //*/
		
		
		/*//Length Gauge
		w.Zprop(complexdt/2. );
		w.Rprop_REG( complexdt, imag(fpulse.efield.f[ktime]) );
		w.Zprop(complexdt/2. );
		
		//				w.Rprop(complexdt);*/
		
		
		
		//Velocity Gauge		
		//w.parallel_evolution_laser_PA( complexdt, imag(fpulse.avector.f[ktime]) );


		
		if(ktime==ir_t0_index || ktime==ir_tf_index)
		{			
			snaper1		= 4;
			snaper2		= 4;			
			
			largeNr		= 1500;
			largeNz		= 3000;	
			
			if(ktime==ir_tf_index)
			{
				largeNr=2000;
				largeNz=4000;
			};
			
			largeRmax  = largeNr*dr;			
			
			
			HH.resize_HankelMatrix(largeNr, largeRmax);
			cout << "\nNew size of the function \n ";
			cout << "\nHH-Nr= " << HH.Nr ;
			
			w.resize_waveUniform2D(HH, largeNz, dz );	
			
			cout << "\nNew dr= " << w.dr;
			
			w.set_potential_hlike2D(   1.,  0.);	
			
			
			w.PrepareCrankArraysOnRho(complexdt    );
			w.PrepareCrankArraysOnZ(  complexdt/2. );
			
			
	     	Energy1		= w.kinetic_energy_finite() + w.potential_energy();						
			cout << "\n\nCheking-Resize at ktime = " << ktime << "  Energy = " << Energy1 << "  Norm = " << w.norm() << "  Error in the norm = " << 1.-w.norm() << endl;
			
			
			w0.resize_waveUniform2D(HH, largeNz, dz );						
			w0.set_potential_hlike2D(    1.,  0.);
			
			wg0.resize_waveUniform2D(HH, largeNz, dz );						
			wg0.set_potential_hlike2D(    1.,  0.);	
			
			wg1.resize_waveUniform2D(HH, largeNz, dz );						
			wg1.set_potential_hlike2D(    1.,  0.);
			
			wg2.resize_waveUniform2D(HH, largeNz, dz );						
			wg2.set_potential_hlike2D(    1.,  0.);	
			
			wg3.resize_waveUniform2D(HH, largeNz, dz );						
			wg3.set_potential_hlike2D(    1.,  0.);	
			
			w1.resize_waveH2D(HH, largeNz, dz);
			w1.set_potential_hlike2D(	  1.,  0.);
			
			
			if(ktime==ir_t0_index)
			{
				w.saveAxes(B1axes,snaper1,snaper2);
				w1.saveQAxes(B1qaxes,snaper1,snaper2);	
			};
			
			if(ktime==ir_tf_index)
			{
				w.saveAxes(B2axes,snaper1,snaper2);
				w1.saveQAxes(B2qaxes,snaper1,snaper2);	
			};			
			
			cout << "\n........................\nThe redimension of the wavefunctions have been done succefully ....\n\n";
			
		};
		
		
		
		//Length Gauge
		w.parallel_evolution_laser_RE( complexdt, imag(fpulse.efield.f[ktime]) );
		w.absorber(0.0, 0.05, 0.05, 0.05, 1./6.);	   
		
		if(ktime%100==0)
		{
			
			P0= projection( wg0,  w );			
			P1= projection( wg1,  w );
			P2= projection( wg2,  w );			
			P3= projection( wg3,  w );
			
			TotNorm = w.norm();
			
			fprintf(out10,"%e %e %e %e %e %e %e\n", 
					 fpulse.g.t[ktime], imag(fpulse.efield.f[ktime]) 
					 ,norm(P0),norm(P1),norm(P2),norm(P3),TotNorm);
			
			//cout << "\n\nNorm= " << norm(P0) << "\n";
			
		};
		
		
		//***************************************
	    //     Write the error in the norm      
	    //*************************************** 		
	    if (ktime%snap==0 && ktime<ir_t0_index)
		{						
	     	Energy1 = w.kinetic_energy_finite()+w.potential_energy();						
			cout << "Loop number = " << ktime << "  Energy = " << Energy1 << "  Norm = " << w.norm() << "  Error in the norm = " << 1.-w.norm() << endl;
			
			
			
			w.mask_function2D( w0, masc0, masc1, sigma_masc);				
	       	out1 << ktime << "  " << 1.-w.norm() << " " << Energy1 << endl;			
			out2 << ktime << "  " <<  w.norm() <<"   "<<w0.norm()<<"   "<< 1.-abs(projection(w, wGround ))  << endl;
			
			
			
			//Snapshot full
			w.snapshot(out3, snaper1, snaper2);
			
			
			
			//Snapshot mask
			w0.snapshot(out4, snaper1, snaper2);
			
			

			//Making interpolation to creat Momentum distribution by Hankel Transform
			//interpU2H(w0,w1);
			//w1.qsnapshot(out5,HH, snaper1, snaper2);
			
		
			out6 << ktime <<"  " << fpulse.g.t[ktime] << " " << imag(fpulse.efield.f[ktime]) <<endl;			
			
			
			
		};
				
		
		if (ktime%500==0 && ktime>ir_t0_index &&  ktime<ir_tf_index )
			//if (ktime%5==0 && ktime>ir_t0_index &&  ktime<ir_tf_index )		
		{	
			
	     	Energy1		= w.kinetic_energy_finite() + w.potential_energy();						
			cout << "Loop number = " << ktime << "  Energy = " << Energy1 << "  Norm = " << w.norm() << "  Error in the norm = " << 1.-w.norm() << endl;
			
			
			w.saveAxes(B1axes,	  snaper1,snaper2);
			w1.saveQAxes(B1qaxes, snaper1,snaper2);	
			
			
			w.mask_function2D( w0, masc0, masc1, sigma_masc);				
	       	B1out1 << ktime << "  " << 1.-w.norm()	<< " "	<<	Energy1 << endl;			
			B1out2 << ktime << "  " <<  w.norm()	<<"   "	<<	w0.norm()<<"   "<< 1.-abs(projection(w, wGround ))  << endl;
			
			
			
			//Snapshot full
			w.snapshot(B1out3, snaper1, snaper2);
			
			
			
			//Snapshot mask
			w0.snapshot(B1out4, snaper1, snaper2);
			
			
			
			//Making interpolation to creat Momentum distribution by Hankel Transform
			//interpU2H(w0,w1);
			//w1.qsnapshot(out5,HH, snaper1, snaper2);
			
			
			B1out6 << ktime <<"  " << fpulse.g.t[ktime] << " " << imag(fpulse.efield.f[ktime]) <<endl;			
			
		};		
		
		
		
		if (ktime%snap==0 && ktime>ir_tf_index)
			//if (ktime%10==0 && ktime>ir_tf_index)		
		{						
	     	Energy1		= w.kinetic_energy_finite() + w.potential_energy();						
			cout << "Finals Loop number = " << ktime << "  Energy = " << Energy1 << "  Norm = " << w.norm() << "  Error in the norm = " << 1.-w.norm() << endl;
			
			
			w.mask_function2D( w0, masc0, masc1, sigma_masc);				
	       	B2out1 << ktime << "  " << 1.-w.norm() << " " << Energy1 << endl;			
			B2out2 << ktime << "  " <<  w.norm() <<"   "<<w0.norm()<<"   "<< 1.-abs(projection(w, wGround ))  << endl;
			
			
			
			//Snapshot full
			w.snapshot(B2out3, snaper1, snaper2);
			
			
			
			//Snapshot mask
			w0.snapshot(B2out4, snaper1, snaper2);
			
			
			
			//Making interpolation to creat Momentum distribution by Hankel Transform
			//interpU2H(w0,w1);
			//w1.qsnapshot(out5,HH, snaper1, snaper2);
			
			
			B2out6 << ktime <<"  " << fpulse.g.t[ktime] << " " << imag(fpulse.efield.f[ktime]) <<endl;			
			
		};		
		
		
		
		if (ktime%2==0) 
		{
			adip =dipole_acceleration( w);
			
			fprintf(out7,"%e %e %e \n",fpulse.g.t[ktime], imag(fpulse.efield.f[ktime]), adip);
		};
		//*/
		
	};//End loop propagation on time
	

	

	
/*	
	//Applying mask functions
	w.mask_function2D( w0, masc0, masc1, sigma_masc);		
	out1 << fpulse.Nmaxt << "  " << 1.-w.norm() << " " << Energy1 << endl;	
	out2 << fpulse.Nmaxt << "  " << 1.-w.norm() <<" "<< w.norm()-w0.norm()<<" "<< 1.-abs(projection(w, wGround ))  << endl;
	
	
	
	
	
	//Snapshot full
	w.snapshot(out3,snaper1,snaper2);
	
	
	
	//Snapshot mask
	w0.snapshot(out4,snaper1,snaper2);
	
	
	
	//Making interpolation to creat Momentum distribution by Hankel Transform
	interpU2H(w0,w1);
	w1.qsnapshot(out5,HH,snaper1,snaper2);	
	
	
	//*/
	//Saving binary data whole wavefunction
	FILE *finalwave;
	finalwave=fopen("finalwave.bin","w+") ;
	
	w.binwrite(finalwave);
	
	
	
	
	
	axes.close();
	qaxes.close();
	out0.close();
	out1.close();
	out2.close();
	out3.close();
	out4.close();
	out5.close();
	out6.close();
	
	
	cout << "\nEND OF THE PROGRAM\n"<<endl;
	
}
Beispiel #19
0
void FC_cv::outresults(ofstream & out_stata, ofstream & out_R,
                            const ST::string & pathresults)
  {


  if (pathresults.isvalidfile() != 1)
    {

    FC::outresults(out_stata,out_R,pathresults);

    optionsp->out("  Marshall-Spiegelhalter Cross Validation: \n",true);
    optionsp->out("\n");

    optionsp->out("    Estimated individual observation samples are stored in\n");
    optionsp->out("    " +  pathresults + "\n");
    optionsp->out("\n");


    ST::string pathresults_like = pathresults.substr(0,pathresults.length()-4)+
                                  "_like.res";

    FC_sampled_l.outresults(out_stata,out_R,pathresults_like);

    optionsp->out("    Estimated individual observation likelihoods are stored in\n");
    optionsp->out("    " +  pathresults_like + "\n");
    optionsp->out("\n");



//    unsigned nrobs = sampled_etas.rows();
    unsigned i;

    /*
    ofstream outres(pathresults.strtochar());

    for(j=0;j<sampled_etas.cols();j++)
      outres << "s_eta_" << (j+1) << "  ";

    for(j=0;j<sampled_etas.cols();j++)
      outres << "s_resp_" << (j+1) << "  ";

    outres << endl;

    for (i=0;i<nrobs;i++)
      {

      for(j=0;j<sampled_etas.cols();j++)
        outres << sampled_etas(i,j) << "  ";

      for(j=0;j<sampled_responses.cols();j++)
        outres << sampled_responses(i,j) << "  ";

      outres << endl;

      }
     */

    // Energy score

    double es = compute_energyscore();


    ST::string pathresults_e = pathresults.substr(0,pathresults.length()-4)+
                               "_energy.res";


    ofstream out2(pathresults_e.strtochar());
    out2 << "id   score" << endl;

    for (i=0;i<e_score.rows();i++)
      out2 << effectvalues[i] << "  " << e_score(i,0) << endl;

    // Log-score


    double ls = compute_logscore();

    ST::string pathresults_l = pathresults.substr(0,pathresults.length()-4)+
                               "_logscore.res";

    ofstream out3(pathresults_l.strtochar());
    out3 << "id   score" << endl;

    for (i=0;i<e_score.rows();i++)
      out3 << effectvalues[i] << "  " << log_score(i,0) << endl;

    optionsp->out("    Estimated energy scores are stored in\n");
    optionsp->out("    " +  pathresults_e + "\n");
    optionsp->out("\n");

    optionsp->out("    Estimated log-scores are stored in\n");
    optionsp->out("    " +  pathresults_l + "\n");
    optionsp->out("\n");

    optionsp->out("    Mean energy score: " + ST::doubletostring(es,8) + "\n");
    optionsp->out("    Mean log score: " + ST::doubletostring(ls,8) + "\n");


    }   // end if (pathresults.isvalidfile() != 1)


  }