- Main Page
- Namespaces
- Data Structures
- Files

- Search for |

- File List
- Globals

# HydroSDL/hydro_source/return_results_to_file.cpp

Go to the documentation of this file.

    00001
    00009 #include <vector>
    00010
    00011 #include "Datas.h"
    00012 #include "return_results_to_file.h"
    00013
    00014 #include "../CVODEincludes.h"  // ODE solver includes
    00015
    00016
    00017 #include <stdio.h>
    00018
    00019
    00020 using namespace std;
    00021
    00022
    00023 #ifndef PI_DEF
    00024 #define pi 3.141592653589793
    00025 #define PI 3.141592653589793
    00026 #endif
    00027
    00028 #define Ith(v,i)    NV_Ith_S(v,i)       /* Ith numbers components 1..NEQ */
    00029
    00030
    00031
    00032
    00033  vector <double> sout00;
    00034  vector <double> sout01;
    00035  vector <double> sout02;
    00036  vector <double> sout03;
    00037  vector <double> sout04;
    00038  vector <double> sout05;
    00039  vector <double> sout06;
    00040  vector <double> sout07;
    00041  vector <double> sout08;
    00042  vector <double> sout09;
    00043  vector <double> sout10;
    00044  vector <double> sout11;
    00045  vector <double> timev;
    00046
    00047 void store_state_for_file(double time, N_Vector state_at_t)
    00048 {
    00049         sout00.push_back(Ith(state_at_t,0));
    00050         sout01.push_back(Ith(state_at_t,1));
    00051         sout02.push_back(Ith(state_at_t,2));
    00052         sout03.push_back(Ith(state_at_t,3));
    00053         sout04.push_back(Ith(state_at_t,4));
    00054         sout05.push_back(Ith(state_at_t,5));
    00055         sout06.push_back(Ith(state_at_t,6));
    00056         sout07.push_back(Ith(state_at_t,7));
    00057         sout08.push_back(Ith(state_at_t,8));
    00058         sout09.push_back(Ith(state_at_t,9));
    00059         sout10.push_back(Ith(state_at_t,10));
    00060         sout11.push_back(Ith(state_at_t,11));
    00061         timev.push_back(time);
    00062 }
    00063
    00064
    00065 int write_results_to_file()
    00066 {
    00067         long Nelem, k;
    00068         int sizeElem;
    00069         FILE *fp;
    00070
    00071
    00072         Nelem = (long) sout00.size();
    00073         sizeElem = sizeof(double);
    00074
    00075         // Write to file:
    00076         fp=fopen("SimResults.sim", "wb");
    00077
    00078         if (fp!=NULL)
    00079         {
    00080                 // Respect that order when reading!!!!!
    00081                 fwrite(&Nelem, sizeof(Nelem),1,fp);  // Store the number of vector elements that will be stored after
    00082                 printf("Nelem = %d \n", Nelem);
    00083
    00084 //  !!!!!!!!   VECTORS ARE STORED IN REVERSE ORDER     !!!!!!!!
    00085                 for (k=0; k<Nelem; k++) {fwrite(&sout00.back(), sizeElem, 1, fp); sout00.pop_back();}
    00086                 for (k=0; k<Nelem; k++) {fwrite(&sout01.back(), sizeElem, 1, fp); sout01.pop_back();}
    00087                 for (k=0; k<Nelem; k++) {fwrite(&sout02.back(), sizeElem, 1, fp); sout02.pop_back();}
    00088                 for (k=0; k<Nelem; k++) {fwrite(&sout03.back(), sizeElem, 1, fp); sout03.pop_back();}
    00089                 for (k=0; k<Nelem; k++) {fwrite(&sout04.back(), sizeElem, 1, fp); sout04.pop_back();}
    00090                 for (k=0; k<Nelem; k++) {fwrite(&sout05.back(), sizeElem, 1, fp); sout05.pop_back();}
    00091                 for (k=0; k<Nelem; k++) {fwrite(&sout06.back(), sizeElem, 1, fp); sout06.pop_back();}
    00092                 for (k=0; k<Nelem; k++) {fwrite(&sout07.back(), sizeElem, 1, fp); sout07.pop_back();}
    00093                 for (k=0; k<Nelem; k++) {fwrite(&sout08.back(), sizeElem, 1, fp); sout08.pop_back();}
    00094                 for (k=0; k<Nelem; k++) {fwrite(&sout09.back(), sizeElem, 1, fp); sout09.pop_back();}
    00095                 for (k=0; k<Nelem; k++) {fwrite(&sout10.back(), sizeElem, 1, fp); sout10.pop_back();}
    00096                 for (k=0; k<Nelem; k++) {fwrite(&sout11.back(), sizeElem, 1, fp); sout11.pop_back();}
    00097                 for (k=0; k<Nelem; k++) {fwrite(&timev.back(), sizeElem, 1, fp); timev.pop_back();}
    00098 //  !!!!!!!!   VECTORS ARE STORED IN REVERSE ORDER     !!!!!!!!
    00099
    00100
    00101                 if (fclose(fp)) printf("Could not close the file!! \n");
    00102                 else printf("Writing to file 'SimResult.sim' done sucessfully. \n");
    00103         }
    00104         else
    00105         {
    00106                 fprintf(stderr, "Could not open file stream (folder does not exist or is write protected), aborting... \n");
    00107                 return 1; // Write abort
    00108         }
    00109
    00110         return 0; //all OK
    00111 }