Graphing with TDatime

so right now i am writing a simple program, in which it reads files that have data of this type [code]

0.0196528006345034 2008 10 13 18 28 10
0.0184036009013653 2008 10 13 18 28 24
0.0188200008124113 2008 10 14 10 40 52
0.0188200008124113 2008 10 14 10 41 10
0.0192364007234573 2008 10 14 10 41 17
0.0221512001007795 2008 10 16 07 35 20
0.0246495995670557 2008 10 16 07 35 30[/code]

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]

#include <iostream.h>
#include <fstream.h>
#include “TGraph.h”
#include <time.h>
#include “TDatime.h”

void deeznutz()

{
char inputFilename[] = “Bdata.txt”;

ifstream inFile;

int x;

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[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;

for(int i=0; i<y;i++)
{
da= new TDatime (year[i], month[i], day[i], hour[i], min[i], sec[i]);

x[i] =  da->Convert(); 

}

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]

so any suggestions?

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.

As a first step, replace your statement

int x; by

float x[1000];

Rene

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”

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;
float year;
float month;
float day;
float hour;
float min;
float sec;

int numRecords = 0;

while (inFile >> BTesla[numRecords] >> year[numRecords] >> month[numRecords] >>day[numRecords] >> hour[numRecords] >> min[numRecords] >> sec[numRecords])
{
numRecords++;
}
int y;
int data;
y = numRecords/7;

data = numRecords - y ;

for(int i=0; i<data;i++)
{
float x[y];
TDatime *da;
da= new TDatime (year[numRecords], month[numRecords], day[numRecords], hour[numRecords], min[numRecords], sec[numRecords]);

x[y] =  da->Convert(); 

}

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();
}