so every 8 digits, the decimal number is a tesla value and the integers correspond to a time. so what my program does is goes into the file and extracts the info and produces a time vs magnetic field TGraph. but for some reason i cannot get it to work. this is what i have so far. [code]
if (!inFile) {
cerr << "Can’t open input file " << “Bdata.txt” << endl;
exit(1);
}
const int MAX_SIZE = 100000000;
float BTesla[MAX_SIZE];
int year[MAX_SIZE];
int month[MAX_SIZE];
int day[MAX_SIZE];
int hour[MAX_SIZE];
int min[MAX_SIZE];
int sec[MAX_SIZE];
int numRecords = 0;
while (inFile >> BTesla[numRecords] >> year[numRecords] >> month[numRecords] >>day[numRecords] >> hour[numRecords] >> min[numRecords] >> sec[numRecords])
{
numRecords++;
}
int y;
y = numRecords/7;
You should get a clear error message that your call to TGraph is wrong.
The first argument is the number of points
The second argument the array of x coordinates
The third argument the array of y coordinates.
so i applied your suggestion and changed some other things and this is what i have [code] #include <iostream.h> #include <fstream.h> #include “TGraph.h” #include <time.h> #include “TDatime.h”
TGraph *gr;
gr = new TGraph(y, x, BTesla);
gr->Draw(“APL”);
gr->GetXaxis()->SetTimeDisplay(1);
gr->GetXaxis()->SetNdivisions(-10,1);
gr->GetXaxis()->SetTimeFormat("%m-%d");
gr->GetXaxis()->SetTimeOffset(0,“gmt”);
gr->SetTitle(“Magnetic Field History”);
inFile.close();
} [/code] but when i run it i get this error
Error: Non-static-const variable in array dimension deeznutz.C:47:
(cint allows this only in interactive command and special form macro which
is special extension. It is not allowed in source code. Please ignore
subsequent errors.)
Your macro was full of mistakes. I fixed them. For instance BTesla was not dimensioned !! … the following version does not return any error messages. It is syntactically correct. I am not claiming it does what you want, but at least you can start from that and, making a diff with your version, see what you did wrongly.
#include <iostream.h>
#include <fstream.h>
#include "TGraph.h"
#include <time.h>
#include "TDatime.h"
void deeznutz()
{
char inputFilename[] = "Bdata.txt";
ifstream inFile;
inFile.open("Bdata.txt", ios::in);
if (!inFile) {
cerr << "Can't open input file " << "Bdata.txt" << endl;
exit(1);
}
const int MAX_SIZE = 100000000;
float BTesla[100];
float year;
float month;
float day;
float hour;
float min;
float sec;
int numRecords = 0;
while (inFile >> BTesla[numRecords] >> year[numRecords] >> month[numRecords]>
{
numRecords++;
}
int data;
int n = numRecords/7;
if (n>100) {
printf("Enlarge the vector x dimension\n");
exit(1);
}
float x[100];
data = numRecords - n ;
for (int i=0; i<data;i++) {
TDatime *da;
da= new TDatime (year[numRecords], month[numRecords], day[numRecords], ho>
x[n] = da->Convert();
}
TGraph *gr;
gr = new TGraph(n, x, BTesla);
gr->Draw("APL");
gr->GetXaxis()->SetTimeDisplay(1);
gr->GetXaxis()->SetNdivisions(-10,1);
gr->GetXaxis()->SetTimeFormat("%m-%d");
gr->GetXaxis()->SetTimeOffset(0,"gmt");
gr->SetTitle("Magnetic Field History");
inFile.close();
}