|
void CKuchukDlg::OnAnalyze()
{
int num_layers;
CKuchukDlg MyClass;
MyClass.m_iLayers = num_layers;
int i = 1;
int H_ft[100],kh_md[100], kv_md[100];
float visc_cp[100], por[100], ct_psi[100];
char line[100];
ifstream inputdeck;
inputdeck.open("input.txt", ios::in);
if (inputdeck.fail())
{
AfxMessageBox("File Read Error!", MB_ICONSTOP);
}
else
{
cin.ignore(60, '\n');
cin.ignore(60, '\n');
while (i <= num_layers && cin.getline(line,100))
{
cin>>H_ft[i]>>kh_md[i]>>kv_md[i]>>visc_cp[i]>>por[i]>>ct_psi[i];
i++;
}
}
ofstream outputdeck;
outputdeck.open("output.txt", ios::out);
outputdeck<<"Pressure\n";
extern double pressure(double x);
extern double press;
outputdeck<<press<<endl;
}
In general this code makes no since!
1) You are using unitialize variable, which should cause the compilire generate errors (or crash the program).
2) You open of file for reading and read nothing from it.
3) You declare a global external funciton and then do not call it.
I hate to say this but, you need to do a lot more studying (or find a local tutor) before writing any more code like this.
INTP
|
|
|
|
|
Immediately after my last post, I removed the instance of CKuchukDlg, MyClass; the application stopped closing, but appeared to do nothing. I later checked the folder, and found that "output.txt", had been written, with a header, Pressure, as expected and only one pressure data, "0".
On implementing your corrections[THANKS! Yep, def. a newbie--> new, no formal training, confusing usage of cin and inputdeck for reading files, etc, etc; but very much willing to learn nevertheless...], I implemented the following, with the same result:
void CKuchukDlg::OnAnalyze()
{
// let maximum number of layers = 100: this value can be modified.
int num_layers = 100;//may be discarded later; no apparent need, now
int i = 0; // index to count what line is being read;
extern int K;
int H_ft[100],kh_md[100], kv_md[100];
float visc_cp[100], por[100], ct_psi[100];
char line[100];
ifstream inputdeck;
inputdeck.open("input.txt", ios::in);
if (inputdeck.fail())
{
//cout<<"Error With Files!";
AfxMessageBox("File Read Error!", MB_ICONSTOP);
}
else
{
inputdeck.ignore(60, '\n');
inputdeck.ignore(60, '\n');
while (i <= K && inputdeck.getline(line,100)) //
{
inputdeck>>H_ft[i]>>kh_md[i]>>kv_md[i]>>visc_cp[i]>>por[i]>>ct_psi[i];
i++;
} /* while block */
}
ofstream outputdeck;
outputdeck.open("output.txt", ios:out);
/*code to test that inputdeck.ignore actually works:
outputdeck<<inputdeck.rdbuf();
--> it does! the 1st 2 lines are skipped;
the 1st 2 lines contain explanatory header text, not useful in the computation; the rest of input.txt is a table of data*/
outputdeck<<"Pressure\n";
extern double pressure(double x);
extern double press;
double pressure(double x);
outputdeck<<press;
AfxMessageBox("Output file Generated!", MB_ICONINFORMATION|MB_OK);
}
Would I be correct in assuming my problem would be (1) or (2) below?
1) My code to generate Pressure Data, called "press" is incorrect somewhere;
2) the statement -> outputdeck<<press; is incorrect, or this code in OnAnalyze() is still incorrect somewhere?
i actually expect to see a stream of pressure data, based on my earlier statements.
I'd appreciate your continued response as well as anyone else's.
Thanks a lot!
P.S: SAMPLE OF INPUT.TXT TABLE DATA; FORMATTING MAY BE BAD, BUT ITS A TABLE OF DATA....YOU CAN SEE WHY I'D WANT TO REMOVE THE 1ST 2 LINES.
--------------------------------------------------------------------------
TABLE OF RESERVOIR PARAMETERS
H(ft) kh(md) kv(md) visc(cp) por ct(/psi)
40 160 20 1 0.2 0.00005
20 100 16 1 0.2 0.00005
10 60 12 1 0.2 0.00005
100 100 10 1 0.2 0.00005
30 40 4 1 0.2 0.00005
10 20 2 1 0.2 0.00005
|
|
|
|
|
Remeber a computer is a stupid machine, it does exactly what you tell it and nothing more. Well ok, since we are using libraries written by other peaple, there is a certain level of trust required.
I am still suprised your code compiles at all, let alone runs without crashing.
1) You have introduced a new magic number (extern int K;), do to how you are using it the value of K must be in the range 0-99. (MAGIC NUMBERS ARE BAD AND DANGERIOUS)
2) You have added a new prototype repressenting the same function, but still do not call it. (It does not look like it would do anything any way).
extern double pressure(double x);
double pressure(double x);
--------------------------------------------------------------------------
Here is what you are telling the computer to do:
1) You open the file and read data in (while praying that K < 100). Then you proceed to ignore the data you just read from the file.
2) You open a file for output. Then you write one word to it "Pressure\n" follow by anouther magic number press. If you read this new file into a string buffer the string would consist of the following: "Pressure\n?" (where '?' is magic number).
3) Show a message box saying the file was generated.
--------------------------------------------------------------------------
Lets analyze the problem:
1) The file consist of two lines of informaional text followed by zero or more lines of numerical data. This implies we may need a variable size array to store the numerical data, unless an maximum size is specifed.
Note: To keep it simple we'll assume maximum array size of 100.
2) The numerical (text) data per line consist of 3 interger values and 3 floating point values no more no less. This implies a record of numerical data stored in a text format, which needs to be translated into a binary format.
struct tagMyDataRecord { int H_ft, kh_md, kv_md; float visc_cp, por, ct_psi; };
tagMyDataRecord recArray[100];
inputdeck>>recArray[i].H_ft>>recArray[i].kh_md>>recArray[i].kv_md>>recArray[i].visc_cp>>recArray[i].por>>recArray[i].ct_psi;
3) Once the data has been loaded we to analyze it and output the results to a file. Now since the given code does not analyze the data nor calls any function to do it, I'll assume that all the data is required to produce a single floating point value.
--------------------------------------------------------------------------
Here is rewrite of your code that should work, provided that complete the pressure() function:
struct tagMyDataRecord { int H_ft, kh_md, kv_md; float visc_cp, por, ct_psi; };
double pressure(tagMyDataRecord* precArray, int nSize)
{
double RetValue = 0.0;
for( int i=0; i<nSize; ++i )
{ }
return RetValue;
}
void CKuchukDlg::OnAnalyze()
{
ifstream inputdeck;
inputdeck.open("input.txt", ios::in);
if (inputdeck.fail())
{
AfxMessageBox("Error: Could not open data file!", MB_ICONSTOP);
return;
}
inputdeck.ignore(60, '\n');
inputdeck.ignore(60, '\n');
int recCount = 0;
tagMyDataRecord recArray[100];
while( recCount < 100 && !(inputdeck.fail() || inputdeck.eof()) )
{
inputdeck>>recArray[i].H_ft>>recArray[i].kh_md>>recArray[i].kv_md;
inputdeck>>recArray[i].visc_cp>>recArray[i].por>>recArray[i].ct_psi;
++recCount;
}
if (inputdeck.fail())
{
AfxMessageBox("Error: Data file read!", MB_ICONSTOP);
return;
}
double result = pressure(recArray, recCount);
if (!result)
{
AfxMessageBox("Warning: Pressure = 0.0, this may be an error!", MB_ICONSTOP);
}
ofstream outputdeck;
outputdeck.open("output.txt", ios:out);
if (ofstream.fail())
{
AfxMessageBox("Error: Could not open output file!", MB_ICONSTOP);
return;
}
outputdeck<<"Pressure"<<press<<endl;
AfxMessageBox("Output file Generated!", MB_ICONINFORMATION|MB_OK);
}
INTP
|
|
|
|
|
I created a new class that derived from CEdit. Here is OnChar function:
<br />
void CMyEdit::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags)<br />
{<br />
if( nChar>='a' && nChar<='z')<br />
{<br />
nChar -= 'a'-'A';<br />
}<br />
CEdit::OnChar(nChar, nRepCnt, nFlags);<br />
}<br />
I just wanted to capitalize all typed chars in the edit box. But It seem not to work.
Where is the problem? Please, help.
Thanks for reading.
|
|
|
|
|
try using PreTranslateMessage()
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
Thank you. But does anyone explain more why changing nChar in OnChar function did not effect?
|
|
|
|
|
nguyenvhn wrote:
nChar -= 'a'-'A';
First off you might look at an ascii table before you do some thing this strange. Second I am not even going to calculate what value this will result in.
If you where going to convert ascii characters in this manner you would have to do the following:
if( 'a' <= nChar && nChar <= 'z' )
nChar = 'A' + (nChar - 'a');
To do it properly you would do the following:
nChar = toupper(nChar);
Ok! I lied I (calculated) tried your equation and it worked (mathmaticaly), but don't do it.
INTP
|
|
|
|
|
Perhaps you could just set the ES_UPPERCASE style? To change the style after the control has been created, use SetWindowLong() .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Whell...I Got A lot of questions
First - What's the difference between CAsyncSocket and CSocket?? ANd if CAsyncSocket is better why it doesn't work with CSocketFile???
ANd Another question:
I got two programms - first one is server that handle with database, and another one is client that connected to my server programm, so i recieve the data in my client programm from the database through the server application. If i send the query slowly ( 2 seconds difference) i got everything ok, but if i send to much queries my client application can't recieve anything, but i see in debugger that it sends the query, and my server application recieves that query and sends the result... And My Client Application doesn't recieve anything....
Where can be the problem??? May be my server programm havent sent all the data from last query, and my client tryes to send another query in that time?
Please help... I can send the applications if it will help...
|
|
|
|
|
In my projrct. I create a thread to poll data at about 100ms interval.
MyThread()
{
for(;;)
{
polling port;
process data;
Sleep(100);
}
}
Normally it runs OK. but when there is a operation like open a IDE with many files. the data is lost. that means MyThread did not poll port for more than 150ms. I know Windows is multi-tasking, Sleep() is not guranteed. But I want to try rise this MyThread's priority as TIME_CRITICAL, it still lost data, and then I know the thread priority changes dynamically. Well How Could I let this piece of code (MyThread) run at a about contain interval. I think many people have this knid of problem, There must a certain way.
Thank u in advance.
|
|
|
|
|
|
I'm not request fine control over timing. I just ask how to a thread to run in a regular interval that is 50ms ~ 150ms.
Anyway, My question is how do I rise MyThread's priority?
|
|
|
|
|
To have this kind of timing you need to write a driver program (There is a least one article at CP). In the old days we would just access the hardware directly with are own ISR (or TSR, for multiple programs), but now you need to write its eqivalent (ring 0 - driver).
I recommend purchasing a library designed for real-time data acquasition. If that is not an option then you will need to write a driver(avoid if possible).
INTP
|
|
|
|
|
2 questions:
PostThreadMessage(hThread,Msg,wParam,lParam);
1) how to receive the message inside of thread of hThread?
2) can a message post to process?
thx
includeh10
|
|
|
|
|
You receive it in your main message loop with a HWND value of NULL. If the receiving thread is in a modal loop, the message is lost. MSDN recommends a thread-specific hook for this.
In MFC, you can override CWinApp::PreTranslateMessage to catch the message.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Hi
Do you know how M$ traps the outgoing html request ?
Example: Outlook exp, ver 6 when you load a html email it blocks the parser from getting the photos and other request that may contain harmful data. It also present a toolbar that allows you to deny of allow these request to be processed.
Navigate2 has a member OnNavigateComplete2(LPCTSTR strURL) but this comes too late to catch and insert a menu.
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
CTreeCtrl has a display limit of aprox. 260 chars per item.
Anyone knows how to bypass this limit or how to create a multiline item?
Be well, people
|
|
|
|
|
I can't include afximpl.h
Error message is:
fatal error C1083: Cannot open include file: 'afximpl.h': No such file or directory
|
|
|
|
|
Hello,
Can someone help me figure out how to make my MFC single document application open a specific file type.
I created the MFC single document application using the VS C++ 7.0 Wizard. It defaults to open all file types. I found the ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) in MyProject.cpp.
How do I customize this so I can open a specific file type such as a .txt?
I looked at the scribble example, but that is a multiple document type and I couldn't see how they did this without overriding OnFileOpen().
Is there a better example that I can learn from?
I am assuming I am not supposed to overwrite the OnFileOpen, but where is this stored and once I select the file and click OK... Where is the filename stored?
What is the correct way to do this?
Thanks.
|
|
|
|
|
hi,
U have create own Method for ID_FILE_OEPN
This will help you..
void CAView::OnFileOpen()
{
char szFilters[]= "TXT Files (*.txt)|*.txt|Jpeg File (*.jpg)|*.jpg|Gif file (*.gif)|*.gif|";
CFileDialog dlg (true, "txt", "",OFN_OVERWRITEPROMPT, szFilters, this);
if (dlg.DoModal()==IDOK){
//Add what u want to do when OK button is pressed
}
}
|
|
|
|
|
Thank You for the help. I will try your method.
|
|
|
|
|
hi,
I am doing Project using MFC/C++. I want to develop the Application with better look and feel..
So I want to add a Picture to the Label and transparent with the Text of the Label. I want to do same procedure for Edit Control.
I know that how to change the Backgroung Color and Font Color.
If any one know how to add picture to the Label with transparent Label Text,please send me a reply.??
OR can I override the CStatic class to do this?
Thanks in advance..
|
|
|
|
|
I got an warning saying that TcpListener was deprecated.
so, What to replace it?
P.S. this is a managed C++ project.
Thanks.
<br />
void Server::RunServer()<br />
{<br />
TcpListener *chatListener;<br />
<br />
try <br />
{<br />
chatListener = new TcpListener( 4500 );<br />
chatListener->Start();<br />
<br />
<br />
-----------------------------
C++ without virtual functions is not OO. Programming with classes but without dynamic binding is called "object based", but not "object oriented".
|
|
|
|
|
I know there is a function that will get a file's created or modified date/time and a few other things also, but I can't seem to figure it out. To use the function(s) I need to pass a HANDLE and it seems like the only way to get the handle is to create a CFile object and open the file. But if my program already has the file open as part of the Document/View architecture why would I need to create a CFile object to get the handle? Shouldn't it be readily available somehow through the CDocument class.
Maybe I've missed something?
Thanks in advance for any help you can offer.
|
|
|
|
|
your funny
CFILE is not the only way....anyway I am against MFC in general
You cand also use FindFirstFile() to get the handle.
have fun . . .
gabby
|
|
|
|
|