6 Replies - 283 Views - Last Post: 15 August 2011 - 05:44 AM Rate Topic: -----

#1 Hislow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-August 11

Files Handling Error

Posted 15 August 2011 - 03:20 AM

Hello All, I am kind of confused and I need your help.
In my code, I open some files A.txt and B.txt and then worked with them. In each simulation step, and the results are read to files C.txt and D.txt. The problem is that, the first line of the files C.txt and D.txt contains some results which doesnt make sense. All other lines are correct.

I closed the files after working with them. Is there something I am doing wrong? Thanks for your response.

Is This A Good Question/Topic? 0
  • +

Replies To: Files Handling Error

#2 MathiasVP  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 154
  • Joined: 08-August 10

Re: Files Handling Error

Posted 15 August 2011 - 03:34 AM

It's hard to tell if you're doing something wrong without seeing your code.
Was This Post Helpful? 0
  • +
  • -

#3 paradoxia  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 163
  • Joined: 02-July 11

Re: Files Handling Error

Posted 15 August 2011 - 03:36 AM

I am not fully clear with your question

1: What are you working with the files?
1: What do you mean by saying simulation step?
3: Are you trying to copy contents of the first 2 files to the other 2 files?


And finally, I would be happy if I see the code you attempted

This post has been edited by paradoxia: 15 August 2011 - 03:37 AM

Was This Post Helpful? 0
  • +
  • -

#4 Hislow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-August 11

Re: Files Handling Error

Posted 15 August 2011 - 03:37 AM

View PostMathiasVP, on 15 August 2011 - 03:34 AM, said:

It's hard to tell if you're doing something wrong without seeing your code.

Was This Post Helpful? 0
  • +
  • -

#5 Hislow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-August 11

Re: Files Handling Error

Posted 15 August 2011 - 05:07 AM

View Postparadoxia, on 15 August 2011 - 03:36 AM, said:

I am not fully clear with your question

1: What are you working with the files?
1: What do you mean by saying simulation step?
3: Are you trying to copy contents of the first 2 files to the other 2 files?


And finally, I would be happy if I see the code you attempted



Hi Paradoxia, please see the attached code.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

Re: Files Handling Error

Posted 15 August 2011 - 05:25 AM

Copy and paste your code IN CODE TAGS! Do not attach it (which you did not do anyway).

:code:
Was This Post Helpful? 0
  • +
  • -

#7 Hislow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-August 11

Re: Files Handling Error

Posted 15 August 2011 - 05:44 AM

I am sorry about the mix-up. I thought the code was inserted. Please see the code.

//string Load, PV;
	ifstream openfilel("F:\\L-51.txt"); // Opens load profile
	ifstream openfilev("F:\\PV.txt");   // Opens PV profile
	//ifstream openfile1("F:\\BatteryPower1.txt");
	//ifstream openfile2("F:\\BatteryPower2.txt");
	string linel;
	string linev;
	string line1;
	string line2;
	ofstream BatteryPower1,BatteryPower2;
	
	ofstream Transformer;

	
	while (getline(openfilel, linel) && getline(openfilev, linev)) // && getline(openfile1, line1) && getline(openfile2, line2)) 
		{
			istringstream isl(linel);
			istringstream isv(linev);
			istringstream is1(line1);
			istringstream is2(line2);
						
			double Pl, Pv, Pb1,Pb2;			// P and Q of load
			double Ql, Qv, Qb1,Qb2;          // P and Q of PV
		    isl >> Pl >> Ql;            
			isv >> Pv >> Qv;		// Read P and Q separately from the file
			is1 >> Pb1 >> Qb1;
			is2 >> Pb2 >> Qb2;

			double K = 10.0000;		// Assumed network constant(kW/kV)

			//Gets Load elements.
			unsigned long ElementID1[] = {1229797050,1229797541};
			int a;                   
			unsigned long *ID1;
			ID1 = ElementID1;
			GetElements(_T("LOAD"), a, ID1);
			FreeElements(ID1);

			for (a=0; a<2; a++)
			{
				SetParameterDouble(ElementID1[a], _T("Pload"),Pl);  // Set the P of the loads with file value
				SetParameterDouble(ElementID1[a], _T("Qload"),Ql);	// Set the Q of the loads with file value

			}
			swprintf_s(cMessageText, _T("P and Q of loads have been set to profile values"));
			WriteMessageToLogFile(cMessageText);

			//Gets PV elements.
			unsigned long ElementID2[] = {1229795380,1229797568};
			int b;                   // double check here if it needs inititalization
			unsigned long *ID2;
			ID2 = ElementID2;
			GetElements(_T("LOAD"), b, ID2);
			FreeElements(ID2);
			
			for (b=0; b<2; b++)
			{
				SetParameterDouble(ElementID2[b], _T("Pload"),Pv);// Set the P of the PV with file value
				SetParameterDouble(ElementID2[b], _T("Qload"),Qv);// Set the Q of the PV with file value
			}
			swprintf_s(cMessageText, _T("P and Q of PVs have been set to profile values"));
			WriteMessageToLogFile(cMessageText);

			//Here, all Battery values are set to the estimated values

			unsigned long ElementID;

			GetElementByName(_T("LOAD"),_T("Batt1"),ElementID);
			SetParameterDouble(ElementID, _T("Pload"),Pb1);
			SetParameterDouble(ElementID, _T("Qload"),Qb1);

			GetElementByName(_T("LOAD"),_T("Batt2"),ElementID);
			SetParameterDouble(ElementID, _T("Pload"),Pb2);
			SetParameterDouble(ElementID, _T("Qload"),Qb2);

						
				
			RunAnalysisLF();  
			swprintf_s(cMessageText, _T("Run load flow with changed load data"));
			WriteMessageToLogFile(cMessageText);

			
			// Here, all PCC bus voltages are compared and battery capacity estimated.

			double Vref = 0.400000; // 0.4kV is taken as a reference voltage
			double V1, dV,V2;
			
			GetElementByName(_T("BUSBAR-NODE"),_T("N39"),ElementID);
			GetResultDouble(ElementID, _T("V"),V1);
			if(V1 > Vref) 
			{
				swprintf_s(cMessageText, _T("Bus voltage was higher than reference value"));
				WriteMessageToLogFile(cMessageText);
				dV = V1 - Vref;
				Pb1 = K*dV;
				Qb1 = 0;

				ofstream BatteryPower1("F:\\BatteryPower1.txt", ios::out | ios::app);
				BatteryPower1 << Pb1 << "	" << Qb1 <<endl;
			}
			else
			{
				Pb1=0.000000;
				Qb1=0.000000;
				ofstream BatteryPower1("F:\\BatteryPower1.txt", ios::out | ios::app);
				BatteryPower1 << Pb1 << "	" << Qb1 <<endl;
			}

			GetElementByName(_T("BUSBAR-NODE"),_T("N37"),ElementID);
			GetResultDouble(ElementID, _T("V"),V2);
			if(V2 > Vref) 
			{
				swprintf_s(cMessageText, _T("Bus voltage was higher than reference value"));
				WriteMessageToLogFile(cMessageText);
				dV = V2 - Vref;
				Pb2 = K*dV;
				Qb2 = 0.000000;

				ofstream BatteryPower2("F:\\BatteryPower2.txt", ios::out | ios::app);
				BatteryPower2 << Pb2 << "	" << Qb2 <<endl;
			}
			
			else
			{
				Pb2=0.000000;
				Qb2=0.000000;
				ofstream BatteryPower2("F:\\BatteryPower2.txt", ios::out | ios::app);
				BatteryPower2 << Pb2 << "	" << Qb2 <<endl;
			}
		}

			BatteryPower1.close();
			BatteryPower2.close();
	
	if (!openfilel.eof() && !openfilev.eof()) // && !openfile1.eof() && !openfile2.eof())
	{
		swprintf_s(cMessageText, _T("Unable to open data file")); // Message is displayed if one or all of the files cannot be opened
		WriteMessageToLogFile(cMessageText);
	}


MOD EDIT: Added code tags. What part of IN CODE TAGS did you fail to understand???

:code:

This post has been edited by JackOfAllTrades: 15 August 2011 - 07:55 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1