Thread: How to read chars from a text file and use them in TChart

  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    Waddinxveen, Netherlands
    Posts
    5

    How to read chars from a text file and use them in TChart

    Hi,

    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:

    Code:
    char LowEnergyGainMap[300]; 
    
    
    bool TMainForm::LeesDetectorLowEnergyGainMap()
    {
    fstream inputfile;
    
              inputfile.open("DetectorLowEnergyGainMap.txt"); // 
    
              	FileName = ExtractFileName(OpenDialog->FileName);
              	SourceFileDir = ExtractFileDir(OpenDialog->FileName);
    
              		if(!inputfile) {
                    	UpDateStatusLine(StatusLineRight,"Detector data file niet geladen !!!");
                    	return FALSE;
              		}
    
              		while(!inputfile.eof()) {
                    	inputfile.getline(LowEnergyGainMap, sizeof(LowEnergyGainMap));
              		}
    	
              inputfile.close();
    
              UpDateStatusLine(StatusLineRight,FileName + "  data file geladen !!!");
           return TRUE;
    }

    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.

    Now 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.

    Code:
    if(WhichRange == "NR"){
     for (t=0; t<NumberOfTubes; t++) {  // Normal Range
          PMTGainNRDet1->Add(LowEnergyGainMap,t+1,GetDefaultColor(16));
    }

    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 the text file and display them as bars in the TChart.

    Any suggestions are very welcome. Thanks in advance

    Johan Ditzel

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >char LowEnergyGainMap[300];
    You might change your definition of LowEnergyGainMap to this:
    Code:
    #include <vector>
    .
    .
    vector<double> LowEnergyGainMap;
    > while(!inputfile.eof()) {
    > inputfile.getline(LowEnergyGainMap, sizeof(LowEnergyGainMap));
    > }
    And your read loop to this:
    Code:
              		double num;
              		while (inputfile >> num) {
              		   LowEnergyGainMap.push_back(num);
              		}
    > for (t=0; t<NumberOfTubes; t++) { // Normal Range
    > PMTGainNRDet1->Add(LowEnergyGainMap,t+1,GetDefaultColor(16));
    Then this would be changed to:
    Code:
     for (t=0; t<LowEnergyGainMap.size(); t++) {  // Normal Range
          PMTGainNRDet1->Add(LowEnergyGainMap[t],t+1,GetDefaultColor(16));

Popular pages Recent additions subscribe to a feed