示例#1
0
文件: NFoutput.cpp 项目: BHIVE/BHIVE
void DumpSystem::dumpHeaderFile(double dumpTime) {
	string dumpFileName = pathToFolder + s->getName()+"_nf."+Util::toString(dumpTime)+".dump.head";

	//cout<<"writing file: "<<dumpFileName<<endl;;

	ofstream ofs;
	//ios_base::out -- Set for output only, instead of for input/output
	//ios_base::trunc --  Truncate the file - that is overwrite anything that was already there
	ofs.open((dumpFileName).c_str(), ios_base::out | ios_base::trunc);

	//Make sure we could open the stream (this is really the only thing that can go around)
	if(!ofs.is_open()) {
		cout<<"--------"<<endl;
		cout<<"-Error dumping header file.";
		cout<<"-Could not open stream to file: '"<<dumpFileName<<"'"<<endl;
		cout<<"-The path is probably incorrect or does not exist."<<endl;
		return;
	}

	ofs<<"## Automatically generated file from NFsim.  Do not edit manually.\n";
	ofs<<"## To read this file and the associated information, use the\n";
	ofs<<"## included Matlab script readNFdump.m.\n\n";

	ofs<<"\n>> Time #######################################\n";
	ofs<<dumpTime<<"\n";

	ofs<<"\n>> MoleculeTypeDef ############################\n";
	ofs<<"##\tindex\tname\tnumOfInstances\tnumOfComponents\n";
	for(int i=0; i<s->getNumOfMoleculeTypes(); i++) {
		MoleculeType *mt = s->getMoleculeType(i);
		ofs<<"\t"<<i<<"\t"<<mt->getName()<<"\t"<<mt->getMoleculeCount()<<"\t";
		ofs<<mt->getNumOfComponents()<<"\t"<<mt->getNumOfTypeIFunctions()<<"\n";
	}

	ofs<<"\n>> MoleculeTypeComponents #####################\n";
	ofs<<"##\ttype\tindex\tname\n";
	for(int i=0; i<s->getNumOfMoleculeTypes(); i++) {
		MoleculeType *mt = s->getMoleculeType(i);
		for(int k=0; k<mt->getNumOfComponents(); k++) {
			ofs<<"\t"<<i<<"\t"<<k<<"\t"<<mt->getComponentName(k)<<"\n";
		}
	}

	ofs<<"\n>> MoleculeTypeFunctions ######################\n";
	ofs<<"##\ttype\tindex\tname\n";
	for(int i=0; i<s->getNumOfMoleculeTypes(); i++) {
		MoleculeType *mt = s->getMoleculeType(i);
		for(int k=0; k<mt->getNumOfTypeIFunctions(); k++) {
			ofs<<"\t"<<i<<"\t"<<k<<"\t"<<mt->getTypeILocalFunction(k)->getName()<<"\n";
		}
	}

	ofs<<"\n>> EOF ##########################################\n";
	ofs.flush();
	ofs.close();
}