Help with file streaming

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
icrman
Posts: 3
Joined: April 9th, 2018, 5:38 am

Help with file streaming

Post by icrman » October 30th, 2018, 1:39 am

I'm having trouble with opening files, reading, processing (add and multiply values together), close, and repeat.

Here's the code:https://github.com/icrman14/Directx

And a run down of what the functions do:
MakerName - returns name of the file (returns: marker.1, marker.2, marker.3, and so on)
MarkerOne - starting position of the object
MarkerNext - add to a new file, velocity*deltaT + position from the previous file
(velocity is fort file)

The idea is to do this about 500 times in a loop. But MarkerNext doesn't return any number and just has the file header stuff. I have no idea whats wrong with the code....

Also, I don't know if this is the best way to go about the problem, but what I'm trying to do is get position at all velocities from the fort file and get them into marker files. The fort file has velocities at all the times and the unstruc_surface file is the starting point.

ps
fort format is element number, velocity in x, velocity in y, velocity in z, and same with the unstruc_surface.
Last edited by icrman on October 30th, 2018, 2:28 pm, edited 2 times in total.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Help with file streaming

Post by albinopapa » October 30th, 2018, 9:49 am

Can't run this without test files, so I can't really help. I'm the type of person that needs to step through the debugger most of the time.

However, I will offer my two cents. For storing and reading data from files, it is way faster to store and retrieve binary data than it is to store and retrieve and parse test data. That being said, the draw back would be not being able to edit the files in something like notepad.

What are you skipping with these lines of code?
struc.seekg(10);
prevMark.seekg(112);
fort.seekg(16);

The prevMark.seekg(112); seems like you are trying to skip the 'header', but not sure about the 10 and 16 bytes from beginning of file.

I'd say your next course of action is to set a break point at the beginning of the functions and step through it line by line to figure out what type of information you are getting.

Something you can do to make life a "little" easier to get a line of text at a time, then use std::stringstream, std::string and other STL algorithms instead of using the fstream objects.

Use std::getline(fort, line); to get a line of code, where line is an std::string.

Code: Select all

// Cache the input file: fort
std::vector<std::string> lines
std::string line( 255 );
while( std::getline( fort, line )
{
    if( !line.empty() )lines.push_back( std::move( line ) );
}

// Write cache to std::stringstream

for( const auto& line : lines )
{
    std::stringstream ss_velocities;
    ss_velocities << line;
    ss_velocities >> num >> dx >> dy >> dz;
}
// ... and so on
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

icrman
Posts: 3
Joined: April 9th, 2018, 5:38 am

Re: Help with file streaming

Post by icrman » October 30th, 2018, 2:36 pm

Thanks for replying, I added the files if you wish to debugg. I used seekg in struc and fort because the beginning couple of characters is information about the file. For fort it is the time, dt, and number of lines until next time step. in the struc file it is total number of elements and number of triangles.
Attachments
unstruc_surface_in.zip
(9.18 KiB) Downloaded 131 times
fort.zip
(524.54 KiB) Downloaded 122 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Help with file streaming

Post by albinopapa » October 30th, 2018, 8:17 pm

Sent a pull request to show an example of how I'd do it. You don't have to use the code exactly, but I recommend looking it over and see if it's something worth trying.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply