Example #1
0
File: HMOFile.C Project: HeyJJ/ball
	bool HMOFile::write(Surface const& surface)
	{
		// we can only write something if the file has been opened correctly
		if (!isOpen() || !(getOpenMode() & MODE_OUT))
		{
			throw File::CannotWrite(__FILE__, __LINE__, name_);
		}

		// write a comment as a header replacement
		if (comments_.size() == 0)
		{
			getFileStream() << "# HYPERMESH file written by BALL::HMOFile" << std::endl << std::endl;
		}
		else
		{
			for (Position i=0; i<comments_.size(); ++i)
			{
				getFileStream() << comments_[i] << std::endl;
			}
			getFileStream() << std::endl;
		}

		writeNodes_(surface);
		writeElements_(surface);

		return true;
	}
Example #2
0
File: HMOFile.C Project: HeyJJ/ball
	bool HMOFile::write(Surface const& surface, AtomContainer const& ac)
	{
		if (!isOpen() || !(getOpenMode() & MODE_OUT))
		{
			throw File::CannotWrite(__FILE__, __LINE__, name_);
		}

		// write a comment as a header replacement
		if (comments_.size() == 0)
		{
			getFileStream() << "# HYPERMESH file for " << ac.getName() << ", written by BALL::HMOFile" << std::endl << std::endl;
		}
		else
		{
			for (Position i=0; i<comments_.size(); ++i)
			{
				getFileStream() << comments_[i] << std::endl;
			}
			getFileStream() << std::endl;
		}

		writeNodes_(surface);
		writeElements_(surface);
		writeCharges_(ac);

		return true;
	}
Example #3
0
File: HMOFile.C Project: HeyJJ/ball
	void HMOFile::writeNodes_(Surface const& surface)
	{
		getFileStream() << "BEG_NODL_DATA" << std::endl;
		getFileStream() << "\t" << surface.vertex.size() << std::endl;

		for (Position i=0; i<surface.vertex.size(); ++i)
		{
			Vector3 const& v = surface.vertex[i];

			getFileStream() << "\t" << i+1 << " " << v.x << " " << v.y << " " << v.z << std::endl;
		}

		getFileStream() << "END_NODL_DATA" << std::endl << std::endl;
	}
Example #4
0
File: HMOFile.C Project: HeyJJ/ball
	void HMOFile::writeCharges_(AtomContainer const& ac)
	{
		getFileStream() << "BEG_CHARGE_DATA" << std::endl;

		Size num_charges = ac.countAtoms();
		getFileStream() << "\t" << num_charges << std::endl;

		Size current_atom = 1;
		for (AtomConstIterator at_it = ac.beginAtom(); +at_it; ++at_it)
		{
			Vector3 const& pos = at_it->getPosition();
			getFileStream() << "\t" << current_atom << " " << pos.x << " " << pos.y << " " << pos.z << " " << at_it->getCharge() << std::endl;
			++current_atom;
		}

		getFileStream() << "END_CHARGE_DATA" << std::endl;
	}
Example #5
0
File: HMOFile.C Project: HeyJJ/ball
	void HMOFile::writeElements_(Surface const& surface)
	{
		getFileStream() << "BEG_ELEM_DATA" << std::endl;

		// NOTE: so far, we only support elements of type T3, and single components
		Size num_triangles = surface.triangle.size();
		getFileStream() << "\t" << num_triangles << " 0 0 " << num_triangles << " 0 0 0 0 0 0 0 0 0" << std::endl;

		for (Position i=0; i<num_triangles; ++i)
		{
			Surface::Triangle const& t = surface.triangle[i];

			getFileStream() << "\t" << i+1 << "\t" << 1 << " " << T3 << "\t";
			getFileStream() << t.v1 << " " << t.v2 << " " << t.v3 << std::endl;
		}

		getFileStream() << "END_ELEM_DATA" << std::endl << std::endl;
	}
Example #6
0
void sortFile(char* path, char* fileName){

  FILE* fileToRead = getFileStream(path, fileName);

  Mp3File fileData = malloc(sizeof(*fileData));
  collectFileData(fileData, fileToRead, fileName);

  copyFile(fileData, fileToRead, path);

  free(fileData);
}
Example #7
0
	bool LineBasedFile::readLine()
	{
		if (!isOpen() || getOpenMode() != MODE_IN)
		{
			throw Exception::ParseError(__FILE__, __LINE__, String("File '") + getName() + "' not open for reading" , 
																	"LineBasedFile::readLine");
		}
		line_.getline(getFileStream());
		if (trim_whitespaces_) line_.trim();
		++line_number_;
		return !eof();
	}
Example #8
0
File: CIFFile.C Project: HeyJJ/ball
	bool CIFFile::write()
	{
		if (!isOpen() || getOpenMode() != std::ios::out)
		{
			throw(File::CannotWrite(__FILE__, __LINE__, name_));
		}	
		
		vector<Datablock>::iterator si;
		for (si = datablocks_.begin(); si != datablocks_.end(); si++)
		{
			*si >> getFileStream();
		}

		return true;
	}
Example #9
0
void Document::close()
{
	for (const auto& memory: m_memoryFileList)
	{
		TypeOut typeOut = typeToOut(memory.first);
		if (typeOut != rdo::converter::smr2rdox::UNDEFINED_OUT)
		{
			LPFileStream pFileStream = getFileStream(typeOut);
			ASSERT(pFileStream);
			memory.second->get(*pFileStream.get());
		}
	}
	m_memoryFileList.clear();

	for (const auto& file: m_streamFileList)
		file.second->close();
	m_streamFileList.clear();
}
Example #10
0
/**
 * initialize() Information
 *
 * This function initializes the data logger module.
 */
static void initialize(void)
{
    dataFile = getFileStream();
}
Example #11
0
	bool KCFFile::write(const Molecule& molecule)
		throw(File::CannotWrite)
	{
		if (!isOpen() || getOpenMode() != std::ios::out)
		{
			throw File::CannotWrite(__FILE__, __LINE__, name_);
		}

		// An alias for simplicity's sake...
		std::ostream& os(getFileStream());
		
		// Write ENTRY block
		// number of blanks????  properties are not read, written??? Which ones are there?
		os << ENTRY_TAG << "      " << molecule.getName() << std::endl;
		
		static char buffer[BALL_MAX_LINE_LENGTH];

		// Write NODE block
		// How to create the KEGG atom types? How many blanks?
		// This is not specified in the KCF format description, so we use what we can
    // deduce from example files.
		// First line gets the NODE tag
		os << NODE_TAG << "      " << molecule.countAtoms() << "\n"; 
		Size count = 1;
		AtomConstIterator ai(molecule.beginAtom());
		std::map<const Atom*, Position> atom_to_index;
		for (; +ai; ++ai, ++count)
		{
			// Write the atom line.
			// Blanks????
			String type = ai->getTypeName();
			String comment;
			
			// Make sure the type is in the set of KEGG types????
			// Blanks?
			sprintf(buffer, "             %d %s %s %6.4f %6.4f %s\n", 
							count, type.c_str(), ai->getElement().getSymbol().c_str(), 
							ai->getPosition().x, ai->getPosition().y, comment.c_str());
			os << buffer;
			
			// Remember the index of the current atom to map atom
			// pointers back to indices for the EDGE section.
			atom_to_index[&*ai] = count;
		}
		
		// Write EDGE block. Walk over all bonds to do so.
		// Blanks????
		os << "EDGE    " << molecule.countBonds() << "\n";
		count = 1;
		for (ai = molecule.beginAtom(); +ai; ++ai)
		{
			for (Atom::BondConstIterator bi(ai->beginBond()); +bi; ++bi)
			{
				Position index1 = atom_to_index[bi->getFirstAtom()];
				Position index2 = atom_to_index[bi->getSecondAtom()];
				String comment;
		
				// Write every bond just once				
				if (bi->getFirstAtom() == &*ai)
				{
					sprintf(buffer, "          %4d %4d %4d %1d%s\n", 
									count, index1, index2, bi->getOrder(), comment.c_str());
					os << buffer;
					++count;
				}
			}
		}
		
		// Write the DELIMITER block
		os << DELIMITER_TAG << std::endl;
		
		return true;
	}