Is there a way to catch a "program.exe stopped working" Windows error?

I am not sure what to look for, or even where to look, in my code. I have the code repeat a rather complicated algorithm using different data several times. It runs fine for 27 iterations and then Windows stops the console based application. If I start the program again, using the data set from just before it stopped, the program cycles through the data just fine and ends as expected. This has happended several times, and always in the same place with the same data set.

I have tested the program by having it analyze the same data set for 50 times (using a data set that analyzed without problem before) and it runs to completion as expected. This makes me think that I do not have a memory leak error that I am somehow failing to catch and/or correct.

I then tested the the program by having it analyze the data where it stops, cycling through just that data 50 times. It runs to completion as expected. This makes me think that there is not a problem with that particular data set.

So, is there some way to catch these Windows errors in a C++ code? If so, what do I do about it??

Is this merely a Windows problem, or can something like this happen in different operating systems?

Recommended Answers

All 3 Replies

You need to post your source code here. Also, if you run your program in the debugger, does it still fail? If it does, then you will be able to see where it fails and can look at data values. You may have a buffer overrun or memory exhaustion issue. Without the source to review, there is no way to tell.

OK, here is the code of the relevant function. The program actually runs this function successfully to the end, but does not return from the function. And, this does not happen all the time.

void FA3 (const string project,
                     const string activity,
                     const string trial,
                     const string subject,
                     const string joint,
                     string RotationSequence,
                     const string choice) // for translation output)
 {
  Log.report("\n  Analyzing Joint: "); Log.report(joint); Log.report(" Trial "); Log.report(trial);
  Log.report("\n  for motion: "); Log.report(activity);
  Log.report("\n  Rotation Sequence: "); Log.report(RotationSequence); Log.report("\n");
  fstream data;
  char primaryaxis, secondaryaxis, tertiaryaxis;
  char chosenprimary, chosensecondary, chosentertiary;
  double primaryrange, secondaryrange, tertiaryrange;
  primaryrange=secondaryrange=tertiaryrange=0;
  string ChosenSequence=RotationSequence;
  Matrix MA1(4,4), BA1, MA2, BA2, MA3, BA3;
  MakeMissing(MA1); BA1=MA2=BA2=MA3=BA3=MA1;
  Vector m1(3), m2, m3, b1, b2, b3;
  MakeMissing(m1); b1=b2=b2=m3=m2=m1;
  int frames=0;
  Vector Out1(6), Out2(6), Out3(6), OutE(6), OutO(6);
  bool Sxyz, Sxzy, Syxz, Syzx, Szxy, Szyx;
  Sxyz=Sxzy=Syxz=Syzx=Szxy=Szyx=false;
  string line;
  string source=project+"."+activity+"."+trial+"."+ subject+"." +joint; // data file name

  if ((RotationSequence!=XYZ) && (RotationSequence!=XZY) &&
      (RotationSequence!=YXZ) && (RotationSequence!=YZX) &&
      (RotationSequence!=ZXY) && (RotationSequence!=ZYX))
    {
     Log.report("\nERROR: Supplied axis order ");
     Log.report(RotationSequence);
     Log.report(" does not report a valid rotation sequence.\n");
     Log.ProgramExit();
    }
  //establishing data source
  string datasource= HOME+"Joints/" + activity + '/' + source + ".csv";
  //read number of datasource frames
  data.open(datasource.c_str(), ios::in);
  if (!MYgetline(data,line)) // read over header
   {
      Log.report("\n     Requested Data file:\n        ");
      Log.report(datasource);
      Log.report("\n     could not be found.");
      Log.ProgramExit();
   }

  bool isCycled=false;
  // count the number of frames in the data
  while (MYgetline(data,line))
   {
       int skip=1;
       frames++; // lines of data
       if (!Missing(comma_read(skip,line))) isCycled=true;
   }
  data.close(); //start over
  data.open(datasource.c_str(), ios::in); // data re-opened for reading in analysis

  //create input and output variables
  vector <Matrix> J;
  vector <Matrix> Jsecondary;
  vector <Matrix> Jtertiary;
  vector <Matrix> E;
  vector <Vector> F1;
  vector <Vector> F2;
  vector <Vector> F3;
  vector <double> Cycle;
  vector <int> Frame;
  vector <Matrix> temp;
  temp.push_back(I(4));

  //read in the J matrix data
  MYgetline(data,line); // read over header
  if (isCycled)
  {
    while (MYgetline(data,line))
    {
     double FR, CY;
     Vector A(6);
     int skip=0; // 0=frame number
     FR=comma_read(skip,line);
     CY=comma_read(skip,line);
     if (!Missing(CY))
     {
         Frame.push_back(FR);
         Cycle.push_back(CY);
         A(0)=comma_read(skip,line);
         A(1)=comma_read(skip,line);
         A(2)=comma_read(skip,line);
         A(3)=comma_read(skip,line);
         A(4)=comma_read(skip,line);
         A(5)=comma_read(skip,line);
         //J1[i]=A.make4x4(DEGREES);
         J.push_back(A.make4x4(DEGREES));
     }
    }
  }
  else
  {
    while (MYgetline(data,line))
    {
     Vector A(6);
     int skip=0; // 0=frame number
     Frame.push_back(comma_read(skip,line));
     Cycle.push_back(comma_read(skip,line));
     A(0)=comma_read(skip,line);
     A(1)=comma_read(skip,line);
     A(2)=comma_read(skip,line);
     A(3)=comma_read(skip,line);
     A(4)=comma_read(skip,line);
     A(5)=comma_read(skip,line);
     //J1[i]=A.make4x4(DEGREES);
     J.push_back(A.make4x4(DEGREES));
      }
  }
  data.close();
  frames=Frame.size();
  string alignments;
  if (!DirectoryExists(HOME+"Alignments"))
   if (!make_directory(HOME+"Alignments"))
   {Log.report("\nERROR: Alignment Directory could not be made."); Log.ProgramExit();}
  chosenprimary=primaryaxis = RotationSequence[x];
  chosentertiary=tertiaryaxis= RotationSequence[y];
  chosensecondary=secondaryaxis=RotationSequence[z];
  RotationSequence=Sequence(primaryaxis, tertiaryaxis,secondaryaxis);
  Matrix MA(4,4); // rotation matrix that aligns the move segment
  Matrix BA(4,4); // rotation matrix that aligns the base segment
  Vector m(3); // rotational axis from the move perspective
  Vector b(3); // rotational axis from the base perspective
  vector <Matrix> F;
  try {

  do // identify proper secondary and tertiary axis check for removal of secondary
  {
      do // identify proper secondary axis
        {
         Jsecondary.clear();
         F.clear();
         do // identify proper primary and secondary axis check for removal of primary
            {
                do // identify proper primary axis
                {
                    RotationSequence=Sequence(primaryaxis, tertiaryaxis,secondaryaxis);
                    SequenceUpdate(RotationSequence, Sxyz, Sxzy, Syxz, Syzx, Szxy, Szyx);
                    Log.report("   Primary Axis "); Log.report(primaryaxis); Log.report(" in ");
                    Log.report(RotationSequence); Log.report("\n");
                } while (primarycheck (J, choice, m, b, MA, BA, primaryaxis, tertiaryaxis, secondaryaxis)); // calculating and identifying primary axis
            } while (primarysecondarycheck (J, F, MA, BA, primaryaxis, tertiaryaxis, secondaryaxis, primaryrange)); // end of primary and secondary axis identification
         Out1=Ranger(F, RotationSequence, DEGREES);
         primaryrange=removeprimaryaxis(F, Jsecondary, F1, RotationSequence, MA, BA);
         MA1=MA; BA1=BA;
         if (primaryaxis==chosenprimary)
            { m1=m; b1=b;}
         else
            { Log.report("    Calculating axis orientation for chosen primary axis\n");  Align(J, chosenprimary, choice, m1, b1, MA, BA); }
         Log.report("   Secondary Axis "); Log.report(secondaryaxis); Log.report(" in ");
         Log.report(RotationSequence); Log.report("\n");
        } while (secondarycheck (Jsecondary, choice, m, b, MA, BA, primaryaxis, tertiaryaxis, secondaryaxis)); // calculating and identifying secondary axis
      RotationSequence=Sequence(primaryaxis, tertiaryaxis,secondaryaxis);
      SequenceUpdate(RotationSequence, Sxyz, Sxzy, Syxz, Syzx, Szxy, Szyx);
  } while (secondarytertiarycheck (Jsecondary, F, MA, BA, primaryaxis, tertiaryaxis, secondaryaxis, secondaryrange));
  Out2=Ranger(F, RotationSequence, DEGREES);
  secondaryrange=removesecondaryaxis(F, Jtertiary, F2, RotationSequence, MA, BA);
  MA2=MA; BA2=BA;
  if (secondaryaxis==chosensecondary)
     { m2=m; b2=b;}
  else
     { Log.report("    Calculating axis orientation for chosen secondary axis\n");  Align(Jsecondary, chosensecondary, choice, m2, b2, MA, BA); }
  F.clear();
  //sequence should now be appropriate
  Log.report("   Tertiary Axis "); Log.report(tertiaryaxis); Log.report(" in ");
  Log.report(RotationSequence); Log.report("\n");
  Align (Jtertiary, tertiaryaxis, choice, m, b, MA, BA);
  for (unsigned i=0; i<Jtertiary.size(); i++)
     F.push_back(BA.inverse() * Jtertiary[i] * MA);
  char referentaxis;
  if (upcase(choice)=="BASE") referentaxis=referent(b);
    else referentaxis=referent(m);
  if (referentaxis!=tertiaryaxis)
      {
       Log.report("Functional Alignment ERROR: Tertiary axis could not be assigned.\n"); Log.ProgramExit();
       // HOW COULD THIS HAPPEN???
      }
  Out3=Ranger(F, RotationSequence, DEGREES);
  tertiaryrange=removetertiaryaxis(F, E, F3, RotationSequence, MA, BA);
  OutE=Ranger(E, RotationSequence, DEGREES);
  MA3=MA; BA3=BA;
  if (tertiaryaxis==chosentertiary)
     { m3=m; b3=b;}
  else
     { Log.report("    Calculating FA for chosen tertiary axis\n");  Align(Jtertiary, chosentertiary, choice, m3, b3, MA, BA); }
  SequenceUpdate(RotationSequence, Sxyz, Sxzy, Syxz, Syzx, Szxy, Szyx);
  }
  catch(bad_alloc ex)
  {
     cout << "Windows Memory Error\n"; exit(0);
  }
  vector<Matrix>().swap(F); // clears memory in F
  vector<Matrix>().swap(Jsecondary); // clears memory in Jsecondary
  vector<Matrix>().swap(Jtertiary); // clears memory in Jtertiary

  //Output Results

  Log.report("Three Axis Functional Alignment found for rotation sequence: "); Log.report(RotationSequence); Log.report("\n");
  OutO=Ranger(J, RotationSequence, DEGREES);
  Log.report("Unaligned Range: X= ");
  Log.report(OutO(0)); Log.report("\tY= "); Log.report(OutO(1));Log.report("\tZ= "); Log.report(OutO(2)); Log.report(" degrees \n");
  Log.report("                 X= "); Log.report(OutO(3)); Log.report("\tY= "); Log.report(OutO(4));
  Log.report("\tZ= "); Log.report(OutO(5)); Log.report(" mm\n");
  Log.report("Primary Range:   X= ");
  Log.report(Out1(0)); Log.report("\tY= "); Log.report(Out1(1));Log.report("\tZ= "); Log.report(Out1(2)); Log.report(" degrees \n");
  Log.report("                 X= "); Log.report(Out1(3)); Log.report("\tY= "); Log.report(Out1(4));
  Log.report("\tZ= "); Log.report(Out1(5)); Log.report(" mm\n");
  Log.report("Secondary Range: X= ");
  Log.report(Out2(0)); Log.report("\tY= "); Log.report(Out2(1));Log.report("\tZ= "); Log.report(Out2(2)); Log.report(" degrees\n");
  Log.report("                 X= "); Log.report(Out2(3)); Log.report("\tY= "); Log.report(Out2(4));
  Log.report("\tZ= "); Log.report(Out2(5)); Log.report(" mm\n");
  Log.report("Tertiary Range:  X= ");
  Log.report(Out3(0)); Log.report("\tY= "); Log.report(Out3(1));Log.report("\tZ= "); Log.report(Out3(2)); Log.report(" degrees \n");
  Log.report("                 X= "); Log.report(Out3(3)); Log.report("\tY= "); Log.report(Out3(4));
  Log.report("\tZ= "); Log.report(Out3(5)); Log.report(" mm\n");
  Log.report("Error Range:     X= ");
  Log.report(OutE(0)); Log.report("\tY= "); Log.report(OutE(1));Log.report("\tZ= "); Log.report(OutE(2)); Log.report(" degrees \n");
  Log.report("                 X= "); Log.report(OutE(3)); Log.report("\tY= "); Log.report(OutE(4));
  Log.report("\tZ= "); Log.report(OutE(5)); Log.report(" mm\n");

  if (degrees(fabs(primaryrange-secondaryrange))<1.0)
     {Log.report("\nWARNING: Primary and Secondary Axes are very similar based on observed ranges.\n");
      Log.report("         Analysis starting with another rotation sequence may be appropriate.\n");
      Log.report("         Available Sequences: ");
      if (!Sxyz) Log.report("XYZ "); if (!Sxzy) Log.report("XZY "); if (!Syxz) Log.report("YXZ ");
      if (!Syzx) Log.report("YZX "); if (!Szxy) Log.report("ZXY "); if (!Szyx) Log.report("ZYX ");
      Log.report("\n");}
  if (degrees(fabs(secondaryrange-tertiaryrange))<1.0)
     {Log.report("\nWARNING: Secondary and Tertiary Axes are very similar based on observed ranges.\n");
      Log.report("         Analysis starting with another rotation sequence may be appropriate.\n");
      Log.report("         Available Sequences: ");
      if (!Sxyz) Log.report("XYZ "); if (!Sxzy) Log.report("XZY "); if (!Syxz) Log.report("YXZ ");
      if (!Syzx) Log.report("YZX "); if (!Szxy) Log.report("ZXY "); if (!Szyx) Log.report("ZYX ");
      Log.report("\n");}
  if (degrees(fabs(primaryrange-tertiaryrange))<1.0)
     {Log.report("\nWARNING: Primary and Tertiary Axes are very similar based on observed ranges.\n");
      Log.report("         Analysis starting with another rotation sequence may be appropriate.\n");
      Log.report("         Available Sequences: ");
      if (!Sxyz) Log.report("XYZ "); if (!Sxzy) Log.report("XZY "); if (!Syxz) Log.report("YXZ ");
      if (!Syzx) Log.report("YZX "); if (!Szxy) Log.report("ZXY "); if (!Szyx) Log.report("ZYX ");
      Log.report("\n");}

  if (referent(RotationalAxis(MA1, primaryaxis))!=referent(RotationalAxis(BA1, primaryaxis)))
  {
    Log.report("\nWARNING: Move and Base referents are not equal for the primary axis.\n");
    Log.report("         Move is: "); Log.report(referent(RotationalAxis(MA1, primaryaxis)));
    Log.report(" and Base is: ");     Log.report(referent(RotationalAxis(BA1, primaryaxis)));Log.report("\n");
  }
  if (referent(RotationalAxis(MA2, secondaryaxis))!=referent(RotationalAxis(BA2, secondaryaxis)))
  {
    Log.report("\nWARNING: Move and Base referents are not equal for the secondary axis.\n");
    Log.report("         Move is: "); Log.report(referent(RotationalAxis(MA2, secondaryaxis)));
    Log.report(" and Base is: ");     Log.report(referent(RotationalAxis(BA2, secondaryaxis)));Log.report("\n");
  }
  if (referent(RotationalAxis(MA3, tertiaryaxis))!=referent(RotationalAxis(BA3, tertiaryaxis)))
  {
    Log.report("\nWARNING: Move and Base referents are not equal for the tertiary axis.\n");
    Log.report("         Move is: "); Log.report(referent(RotationalAxis(MA3, tertiaryaxis)));
    Log.report(" and Base is: ");     Log.report(referent(RotationalAxis(BA3, tertiaryaxis))); Log.report("\n");
  }

  //WriteOutputs
  fstream out;
  string outputresult, outfile;

  //output aligned rotations
  outputresult=HOME+"Aligned_Joints/";
  make_directory(outputresult); outputresult=outputresult + activity;
  make_directory(outputresult); outputresult=outputresult + "/ThreeAxis";
  if (!make_directory(outputresult))
  {
    Log.report("\nDirectory:\n");
    Log.report(outputresult);
    Log.report("\ncould not be made!");
    Log.ProgramExit();
  }
  outfile=outputresult + '/' + source + '-' + chosenprimary +".csv";
  out.open(outfile.c_str(), fstream::out);
  if (out.is_open()) out << "frame, cycle, AVx, AVy, AVz, Tx, Ty, Tz\n"; // header with three elements of attitude vector three elements of translation
  else {Log.report("ERROR: Could not open output file\n  "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  if (chosenprimary==X)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ", " << F1[f](0) << ",0,0," << F1[f](1) << ","  << F1[f](2) << ","<< F1[f](3)<< endl;}
  else if (chosenprimary==Y)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ", 0," << F1[f](0) << ",0," << F1[f](1) << ","  << F1[f](2) << ","<< F1[f](3) << endl;}
  else //(chosenprimary==Z)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ", 0,0," << F1[f](0) << "," << F1[f](1) << ","  << F1[f](2) << ","<< F1[f](3) << endl;}
  out.close();

  outfile=outputresult + '/' + source + '-' +chosensecondary +".csv";
    out.open(outfile.c_str(), fstream::out);
  if (out.is_open()) out << "frame, cycle, AVx, AVy, AVz, Tx, Ty, Tz\n"; // header with three elements of attitude vector three elements of translation
  else {Log.report("ERROR: Could not open output file\n  "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  if (chosensecondary==X)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ", " << F2[f](0) << ",0,0," << F2[f](1) << ","  << F2[f](2) << ","<< F2[f](3) << endl;}
  else if (chosensecondary==Y)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ",0," << F2[f](0) << ",0," << F2[f](1) <<","  << F2[f](2) << ","<< F2[f](3) << endl;}
  else //(chosensecondary==Z)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ",0,0, " << F2[f](0) << "," << F2[f](1) << ","  << F2[f](2) << ","<< F2[f](3) << endl;}
  out.close();

  outfile=outputresult + '/' + source + '-' + chosentertiary +".csv";
  out.open(outfile.c_str(), fstream::out);
  if (out.is_open()) out << "frame, cycle, AVx, AVy, AVz, Tx, Ty, Tz\n"; // header with three elements of attitude vector three elements of translation
  else {Log.report("ERROR: Could not open output file\n  "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  if (chosentertiary==X)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ", " << F3[f](0) << ",0,0," << F3[f](1) << ","  << F3[f](2) << ","<< F3[f](3) << endl;}
  else if (chosentertiary==Y)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ",0," << F3[f](0) << ",0," << F3[f](1) << ","  << F3[f](2) << ","<< F3[f](3) << endl;}
  else //(chosentertiary==Z)
    for (int f=0; f<frames; f++)
      { out<<Frame[f] << ", " << Cycle[f] << ",0,0," << F3[f](0) << "," << F3[f](1) << ","  << F3[f](2) << ","<< F3[f](3) << endl;}
  out.close();

  outputresult=HOME + "ERROR/";
  make_directory(outputresult); outputresult=outputresult + activity;
  make_directory(outputresult); outputresult=outputresult + "/ThreeAxis";
  if (!make_directory(outputresult))
  {
    Log.report("\nDirectory:\n");
    Log.report(outputresult);
    Log.report("\ncould not be made!");
    Log.ProgramExit();
  }
  outfile=outputresult + '/' + source + '-' + "error.csv";
  out.open(outfile.c_str(), fstream::out);
  if (out.is_open()) out << "frame, cycle, AVx, AVy, AVz, Tx, Ty, Tz\n"; // header with three elements of attitude vector three elements of translation
  else {Log.report("ERROR: Could not open output file\n  "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  for (int f=0; f<frames; f++)
   {   if (E[f].inner().isRotationMatrix())
       {out<<Frame[f] << ", " << Cycle[f] << ", "; E[f].Make6vector(DEGREES).dump(out); out << endl; }
       else
       {
           cout << f << "fails as I\n";
           Matrix ED=E[f].inner();
           (ED.transpose()*ED).dump(16,18); getch();
       }
   }
  out.close();

  //output alignment matrices
  outputresult=HOME+"Alignments/";
  make_directory(outputresult);
  if (!make_directory(outputresult))
  {
    Log.report("\nDirectory:\n");
    Log.report(outputresult);
    Log.report("\ncould not be made!");
    Log.ProgramExit();
  }
  //primary axis alignment
  outfile=outputresult + '/' + source + '-' + primaryaxis + ".csv";
  out.open(outfile.c_str(), fstream::out);
  if (out.is_open())
    {
     MA1.Make6vector(DEGREES).dump(out); out <<", ::, ";
     BA1.Make6vector(DEGREES).dump(out); out <<", ::, ";
     out << RotationSequence << endl;
    }
  else {Log.report("ERROR: Could not write FA1 alignments to alignment file:\n   "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  out.close();

  //secondary axis alignment
  outfile=outputresult + '/' + source + '-' + secondaryaxis  + ".csv";
  out.open(outfile.c_str(), fstream::out);
  if (out.is_open())
    {
     MA2.Make6vector(DEGREES).dump(out); out <<", ::, ";
     BA2.Make6vector(DEGREES).dump(out); out <<", ::, ";
     out << RotationSequence << endl;
    }
  else {Log.report("ERROR: Could not write FA1 alignments to alignment file:\n   "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  out.close();

  //tertiary axis alignment
  outfile=outputresult + '/' + source + '-' + tertiaryaxis  + ".csv";
  out.open(outfile.c_str(), fstream::out);
  if (out.is_open())
    {
     MA3.Make6vector(DEGREES).dump(out); out <<", ::, ";
     BA3.Make6vector(DEGREES).dump(out); out <<", ::, ";
     out << RotationSequence << endl;
    }
  else {Log.report("ERROR: Could not write FA1 alignments to alignment file:\n   "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}
  out.close();

  //write axis results
  time_t now = time(0);
  tm *ltm = localtime(&now);
  outputresult=HOME+"Axes/";
  make_directory(outputresult);
  if (!make_directory(outputresult))
  {
    Log.report("\nDirectory:\n");
    Log.report(outputresult);
    Log.report("\ncould not be made!");
    Log.ProgramExit();
  }
  //write primary axes
  outfile=outputresult + '/' + source + '-' + chosenprimary +".csv";
  if (FileExists(outfile)) { out.open(outfile.c_str(), fstream::out | fstream::app);}
  else
    {
     out.open(outfile.c_str(), fstream::out);
     out << "Time, Date, Project, Motion, Trial, Subject, Joint, Referent, Move x, Move y, Move z, ,Base x, Base y, Base z,,  Chosen Sequence, Found Sequence\n";
    }
  if (out.is_open())
   {
    out << ltm->tm_hour << ":" << 1 + ltm->tm_min <<", "; // time
    out << 1900 + ltm->tm_year << "-" << 1 + ltm->tm_mon << "-" <<  ltm->tm_mday << ", ";
    out << project << ", " << activity << ", " << trial << ", " << subject << ", " << joint << "-3, " <<chosenprimary << ", ";
    m1.dump(out);
    out << ",::,";
    b1.dump(out);
    out << ",::," << ChosenSequence << "," << RotationSequence << endl;
    out.close();
   }
  else
   {Log.report("ERROR: Could not write axis results to:\n       "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}

  //write secondary axes
  outfile=outputresult + '/' + source + '-' + chosensecondary +".csv";
  if (FileExists(outfile)) { out.open(outfile.c_str(), fstream::out | fstream::app);}
  else
    {
     out.open(outfile.c_str(), fstream::out);
     out << "Time, Date, Project, Motion, Trial, Subject, Joint, Referent, Move x, Move y, Move z, ,Base x, Base y, Base z,, Chosen Sequence, Found Sequence\n";
    }
  if (out.is_open())
   {
    out << ltm->tm_hour << ":" << 1 + ltm->tm_min <<", "; // time
    out << 1900 + ltm->tm_year << "-" << 1 + ltm->tm_mon << "-" <<  ltm->tm_mday << ", ";
    out << project << ", " << activity << ", " << trial << ", " << subject << ", " << joint << "-3, " <<chosensecondary<< ", ";
    m2.dump(out);
    out << ",::,";
    b2.dump(out);
    out << ",::," << ChosenSequence << "," << RotationSequence << endl;
    out.close();
   }
  else
   {Log.report("ERROR: Could not write axis results to:\n       "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}

  //write tertiary axes
  outfile=outputresult + '/' + source + '-' + chosentertiary +".csv";
  if (FileExists(outfile)) { out.open(outfile.c_str(), fstream::out | fstream::app);}
  else
    {
     out.open(outfile.c_str(), fstream::out);
     out << "Time, Date, Project, Motion, Trial, Subject, Joint, Referent, Move x, Move y, Move z, ,Base x, Base y, Base z,, Chosen Sequence, Found Sequence\n";
    }
  if (out.is_open())
   {
    out << ltm->tm_hour << ":" << 1 + ltm->tm_min <<", "; // time
    out << 1900 + ltm->tm_year << "-" << 1 + ltm->tm_mon << "-" <<  ltm->tm_mday << ", ";
    out << project << ", " << activity << ", " << trial << ", " << subject << ", " << joint << "-3, " <<chosentertiary << ", ";
    m3.dump(out);
    out << ",::,";
    b3.dump(out);
    out << ",::," << ChosenSequence << "," << RotationSequence << endl;
    out.close();
   }
  else
   {Log.report("ERROR: Could not write axis results to:\n       "); Log.report(outfile); Log.report("\n"); Log.ProgramExit();}

   vector<Vector>().swap(F1); // clears memory in F1
   vector<Vector>().swap(F2); // clears memory in F2
   vector<Vector>().swap(F3); // clears memory in F3
 } // end function

I haven't gotten many views since I added the relevant code, so I am bumping this question up to the top in hopes that it might still receive an answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.