![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
How can I read a *.txt file from disk and display the values as bars in TChartHi,
Can anyone help me with the following problem: I have to read values from a DetectorLowEnergyGainMap.txt file on the disk that is filled with values like: -128,-10,-30,0, -200 etc. I can read the file with the following code: CPP / C++ / C Code:
So far, everything works fine. If I display the data e.x. with ShowMessage(LowEnergyGainMap) I can see that my array LowEnergyGainMap is filled now with the correct data. However, if I try to display the data in a TChart with the code below, all the bars are displayed as positive bars and not with the data that is in the LowEnergyGainMap. CPP / C++ / C Code:
I know that in the call: Add(LowEnergyGainMap,t+1,GetDefaultColor(16)) LowEnergyGainMap should be declared const double. I think that my problem resides here. So, in general, how can I read the datavalues from my text file and display them as bars in the TChart. Any suggestions are very welcome. Thanks in advance Johan Ditzel |
|
#2
|
|||
|
|||
Re: How can I read a *.txt file from disk and display the values as bars in TChartI have no experience with TChart...but you are reading LowEnergyGainMap as a char array, i.e. a string containing the numbers in the file. You will have to use strtol() or something similar to convert them to doubles.
|
|
#3
|
||||
|
||||
Re: How can I read a *.txt file from disk and display the values as bars in TChartQuote:
Also, this loop CPP / C++ / C Code:
1) it reads each line of the file but does nothing with it. You therefore exit the loop with only the last line of the file as data. You need to process the line after reading. 2) you use .eof() to exit the loop. This is the same as using feof() in C. This won't work as you expect, and here's why __________________
Age is unimportant -- except in cheese |
|
#4
|
|||
|
|||
Re: How can I read a *.txt file from disk and display the values as bars in TChartThanks for the reply and help. Now I am able to read my text file and display the values as bars in TChart. Here is the way I modified my code.
I did not change annything in the code below. CPP / C++ / C Code:
In the following function I added a loop that reads the gainmap with chars and converts it to a map with integers so that Tchart can display it. CPP / C++ / C Code:
Thanks, Johan |
|
#5
|
||||
|
||||
Re: How can I read a *.txt file from disk and display the values as bars in TChartYour formatting needs an overhaul. Indenting just to indent is not a good idea. Check out this info for formatting ideas.
I still want to know what's going on here in this (reformatted) function: CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
|
#6
|
|||
|
|||
Re: How can I read a *.txt file from disk and display the values as bars in TChartHi WaltP,
Thks for the quick response. Since I am a beginner in C/C++ I apreciate yr comments and help. I will check yr info about formatting ideas. In the function LeesDetectorLowEnergyGainMap() I only read the contens of the file on disk and put it in an array of chars named LowEnergyGainMap. In the next function DetNRClick I read the contens of LowEnergyGainMap and convert the chars into int's so that I can call TChart. Now, I tried to read another file from disk and putting it in an array but if I read the array and tried to output its contens nothing is displayed. It has probably to do with explanation of yr previous post. I will tried to change it and let you know. Thanks Johan |
|
#7
|
|||
|
|||
Re: How can I read a *.txt file from disk and display the values as bars in TChartHi all,
I have the following question: With fgets(EnergyMap, sizeof(EnergyMap), fp), I am reading a line from a Text file from disk. The line of chars (a string) in the textfile look like this: e.g. 5 \t 923.000000 \t 10.000000 \n So 5 a TAB 923.000000 a TAB 10.000000 a carrage return. Now I have to decode the string so that I can fill an array with the first number (in this case the 5), an array with the second number (923.000000 ) and an array with the last number (10.000000 ). The file contains 1000 lines. So far I am able to decode the first number (5) and the last number (10.000000), however how can I decode (isolate) the second number, in this case 923.000000 from the string. Here is a part of the code I use to decode the string: CPP / C++ / C Code:
Thanks in advance, Johan |
|
#8
|
||||
|
||||
Re: How can I read a *.txt file from disk and display the values as bars in TChartIf there are only two tabs on the line, you could do something much simpler.
Code:
If some lines are more complex than this, you may have to adjust your processing and this idea may not work well. __________________
Age is unimportant -- except in cheese |
|
#9
|
|||
|
|||
Next basic questionI have to read and convert individual charcters to an int and double, like this:
EnergyMap contains characters like: EnergyMap[0]contains a 1 EnergyMap[1]contains a 2 EnergyMap[2]contains a 3 EnergyMap[3]contains a 4 I have to read/convert the contens of EnergyMap[0 - 3]to an integer or double value like 1234. The idea was first concatenate the 4 characters to a string and then convert it to an integer or double. CPP / C++ / C Code:
But, the compiler is generating the error: [C++ Error] Main.cpp(791): E2034 Cannot convert 'int' to 'const char *' So, how can I read the individual characters from the array of chars and convert it to one integer or double value. Any idea how to solve this?? Thanks in advance. Johan |
|
#10
|
|||
|
|||
Re: How can I read a *.txt file from disk and display the values as bars in TChartstrcat takes a whole string as the second parameter; you only have a single character. in this case, you can just assign str (which only needs to have 5 elements) the elements of EnergyMap directly.
|
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Apache2 config issues | monev | Apache Web Server Forum | 2 | 28-Jun-2004 06:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The