• Log in or sign up for an account here: https://www.sythe.org/login

file parser.... thing

rogue poser

Member
Joined
Jul 10, 2005
Sythe Gold
0
Messages
51
alright so, i have a file with 3 columns and 10,000 lines of information. the first column is a time, the second is a volt reading, and the third is an amp reading. what i need to do is parse the file and find the time when the highest voltage occurred, and the time when the highest amperage occurred...

after i open the file im stuck... ive been looking all over the internet for tuts, and have found some information.... its just not what im looking for. does anyone have and idea of what i could do? i was thinking of making a dynamic array and storing all of the info in there, and searching every 3rd slot, and comparing it with the highest running value.... ideas?
 
Do you need:
1) 2 Times, the one with the highest voltage and the one with the highest amperage.
OR
2) The time with the highest voltage and amperage.

I've already got a function I've used to parse an 80,000+ line file, I suppose I could modify it somehow to help you out. PM me your MSN.
 
well i the three colums are set up like this

TIME VOLTAGE AMPERAGE
.0040 9.3454 .034
.0045 9.1234 .029




and so on.....

i need to find the highest and lowest voltage, and the highest and lowest amperage, at any given time.... so pretty much the highest amp (volts dont matter) and time, and the highest volts (amps dont matter) and time....

so to answer ur question, i need number 1

i dont have msn, but ive got aim, and im on at the moment "dirty l3um"
 
Nully, read the file into a file pointer, and use the for loop you used for the ABC project to check for whitespace.
 
if anyone cares i got my first working copy of the code. here she is

Code:
#include <iostream>
#include <fstream>

using namespace std;

///////////////////////
// Declare Variables //
///////////////////////

int main()
{
  float info,amps,time,arraynum,avga,avgv;
  float vlow = 10;
  float alow = 10;
  float ahigh = 0;
  float vhigh = 0;
  char doc[12]="E:/volt.txt";
  int start = 0;
  int total,x,z;
 
/////////////////////
//  Error Message  //
/////////////////////
ifstream infile(doc, ios::in);
fstream outfile(doc, ios::in);
   if (!infile)
	{
	   cout << "cannot open the file...\n";
	}
   if(infile)
	{
   	   cout << "file opened \n";
	}

/////////////////////////////////////
// find the highest and the lowest //
/////////////////////////////////////

x = 1;
cout << "time: .0001 "; 
for(start = 0; start<2749770; start++)
	{
	   arraynum = info;								// searches every byte in the file
	   total = start;
	   outfile.seekp(total);
	   outfile >> time >> info >> amps;
	   

	    if(arraynum != info)
		{

		  if(x%3 == 1)								// displays the voltage
				{
				  cout << " volts: " << info ;
				   if(info > vhigh)
					   vhigh = info;
				   if (info < vlow)
					   vlow = info;
				   avgv = avgv + info;
				}

		  if(x%3 == 2)								// displays the amperage
				{
			      cout << " amps: " << info << endl;

				  if(info > ahigh)
					  ahigh = info;
				  if(info < alow)
					  alow = info;
				  avga = avga + info;
			    }


		  if(x%3 == 0)								// displays the time
			{
			    cout << "time: " << info;
			}
			x++;
					
		}// end if
	
	}//end for	
//avga = avga/10000;
//avgv = avgv/10000;
												// output the information
cout << endl<< endl;
cout << "Highest Voltage: "<< vhigh << "   Highest Amperage: " << ahigh << endl << endl;
cout << "Lowest Voltage: " << vlow <<"   Lowest Amperage: " << alow << endl << endl;
cout << "Average Voltage: " << avgv << "   Average Amperage: " << avga << endl <<endl;


  return 0;
}//end main

im not completely done, i need to get the average working, but thats all i have left....

seemed much harder than it was, once i hit the "grindstone" if you will it took about an hour to make. if your wondering why my for loop is so large its because im checking every byte in the entire file

:-P
 
It's really nice to see that you did it yourself, great work. I modified your code some myself to make a few minor improvements and also fixed the averaging.

Code:
#include <iostream>
#include <fstream>

using namespace std;

///////////////////////
// Declare Variables //
///////////////////////

int main()
{
  float info,amps,time,arraynum;
  float vlow = 10^99;
  float alow = 10^99;
  float ahigh = 0;
  float vhigh = 0;
  float vtotal = 0, atotal = 0;
  int vnum = 0, anum = 0;
  char doc[12]="volt.txt";
  int total,z;
  int x = 1;
 
/////////////////////
//  Error Message  //
/////////////////////
ifstream infile(doc, ios::in);
fstream outfile(doc, ios::in);
   if (!infile)
	{
	   cout << "cannot open the file...\n";
	}
   if(infile)
	{
   	   cout << "file opened \n";
	}

/////////////////////////////////////
// find the highest and the lowest //
/////////////////////////////////////


cout << "time: .0001 "; 
for(int start = 0; start<2749770; start++)
	{
	   arraynum = info;								// searches every byte in the file
	   total = start;
	   outfile.seekp(total);
	   outfile >> time >> info >> amps;
	   

	    if(arraynum != info)
		{

		  if(x%3 == 1)								// displays the voltage
				{
				  cout << " volts: " << info ;
				    vtotal += info;
				    vnum++;
				   if(info > vhigh) {
					   vhigh = info; }
				   if (info < vlow) {
					   vlow = info; }
				}

		  else if(x%3 == 2)								// displays the amperage
				{
			      cout << " amps: " << info << endl;
				   atotal += info;
				   anum++;
				  if(info > ahigh) {
					  ahigh = info; }
				  if(info < alow) {
					  alow = info; }
			    }


		  else if(x%3 == 0)								// displays the time
			{
			    cout << "time: " << info;
			}
			x++;
					
		}// end if
	
	}//end for	

												// output the information
cout << endl<< endl;
cout << "Highest Voltage: "<< vhigh << "   Highest Amperage: " << ahigh << endl << endl;
cout << "Lowest Voltage: " << vlow <<"   Lowest Amperage: " << alow << endl << endl;
cout << "Average Voltage: " << vtotal / vnum << "   Average Amperage: " << atotal / anum << endl <<endl;

  getchar();
  return 0;
}//end main
 
lol apparently i went a bit overkill.... i have recently found out that the fstream library has a function that will read every piece of information in the file. so instread of going byte by byte, i could save everything into a buffer and have it be seperated by the blank spaces.... so that makes the program run in 10 seconds instead of 3 minuites :-p. nothing wrong with re-inventing the wheel i suppose?
 
lol apparently i went a bit overkill.... i have recently found out that the fstream library has a function that will read every piece of information in the file. so instread of going byte by byte, i could save everything into a buffer and have it be seperated by the blank spaces.... so that makes the program run in 10 seconds instead of 3 minuites :-p. nothing wrong with re-inventing the wheel i suppose?
Yeah, I was going to mention that there was a better way but figured that since this did the trick and you thought it up yourself why bother. Great work getting it done on your own for the most part. :)
 
Runescape Gamblingrunescape gambling
Back
Top