- Main Page
- Namespaces
- Data Structures
- Files

- Search for |

- File List
- Globals

# HydroSDL/hydro_source/get_file_arguments.cpp

Go to the documentation of this file.

    00001
    00008 #include "get_file_arguments.h"
    00009
    00010
    00011
    00012 #ifndef PI_DEF
    00013 #define pi 3.141592653589793
    00014 #define PI 3.141592653589793
    00015 #endif
    00016
    00017
    00018 struct readStruct
    00019 {
    00020         double SimTime;
    00021         double X0[STATENUM];
    00022         double reltol;
    00023         double abstol[STATENUM];
    00024         double param[PARAMNUM];
    00025         int dirDo[8];
    00026 };
    00027
    00028
    00030
    00034 void initParameters(struct parameters *P) //default values
    00035 {
    00036         int i;
    00037                 for (i=0; i<PARAMNUM; i++) P->param[i] = 0;
    00038                 for (i=0; i<STATENUM; i++) P->abstol[i] = (1e-6);
    00039                 P->reltol = (1.0e-4);
    00040         return;
    00041 }
    00042
    00043
    00045
    00049 void initJoyParameters(struct joy_parameters *jP) //default values
    00050 {
    00051         jP->dirX = 1.0;
    00052         jP->dirY = 1.0;
    00053         jP->dirZ = 1.0;
    00054         jP->dirR = 1.0;
    00055
    00056         jP->doX = TRUE;
    00057         jP->doY = TRUE;
    00058         jP->doZ = TRUE;
    00059         jP->doR = TRUE;
    00060 }
    00061
    00062
    00064
    00071 void print_arguments_values(struct parameters *P, struct joy_parameters *jP, double *state, double *time)
    00072 {
    00073         int i;
    00074         fprintf( stderr,"======================= Arguments from file ========================\n");
    00075         fprintf( stderr,"Simulation time: %f \n Initial state vector:  ", *time);
    00076         for (i=0; i<STATENUM; i++) fprintf( stderr,"%f ", state[i]);
    00077
    00078         fprintf( stderr,"\nP.param: ");
    00079         for (i=0; i<PARAMNUM; i++) fprintf( stderr," %f", P->param[i]);
    00080
    00081         fprintf( stderr,"\nP.abstol: ");
    00082         for (i=0; i<STATENUM; i++) fprintf( stderr," %f", P->abstol[i]);
    00083
    00084         fprintf( stderr,"\nP.reltol: %f", P->reltol);
    00085
    00086         fprintf( stderr,"\njP.dirX: %f",jP->dirX);
    00087         fprintf( stderr,"\njP.dirY: %f",jP->dirY);
    00088         fprintf( stderr,"\njP.dirZ: %f",jP->dirZ);
    00089         fprintf( stderr,"\njP.dirR: %f",jP->dirR);
    00090
    00091         fprintf( stderr,"\njP.doX: %d", (int) jP->doX);
    00092         fprintf( stderr,"\njP.doY: %d", (int) jP->doY);
    00093         fprintf( stderr,"\njP.doZ: %d", (int) jP->doZ);
    00094         fprintf( stderr,"\njP.doR: %d", (int) jP->doR);
    00095
    00096         fprintf( stderr,"\n====================================================================\n");
    00097 }
    00098
    00099
    00100
    00102
    00110 void copy_to_arg(readStruct *rd, struct parameters *P, struct joy_parameters *jP, double *state, double *time)
    00111 {
    00112         int k;
    00113
    00114         *time = rd->SimTime;
    00115         for (k=0;k<STATENUM;k++) state[k] = rd->X0[k];
    00116         P->reltol = rd->reltol;
    00117         for (k=0;k<STATENUM;k++) P->abstol[k] = rd->abstol[k];
    00118         for (k=0;k<PARAMNUM;k++) P->param[k] = rd->param[k];
    00119         jP->dirX = rd->dirDo[0];
    00120         jP->dirY = rd->dirDo[1];
    00121         jP->dirZ = rd->dirDo[2];
    00122         jP->dirR = rd->dirDo[3];
    00123         jP->doX = rd->dirDo[4];
    00124         jP->doY = rd->dirDo[5];
    00125         jP->doZ = rd->dirDo[6];
    00126         jP->doR = rd->dirDo[7];
    00127 }
    00128
    00129
    00131
    00138 int read_arguments_from_file(struct parameters *P, struct joy_parameters *jP, double *state, double *time)
    00139 {
    00140         int i;
    00141         readStruct rd;
    00142
    00143         //Default values in case of error:
    00144         *time = 0.0;
    00145         for (i=0; i<STATENUM; i++) state[i] = 0.0;
    00146         initParameters(P);
    00147         initJoyParameters(jP);
    00148
    00149         FILE *fp = NULL;
    00150
    00151         fp=fopen("InitialConditions.icd", "rb");
    00152
    00153         if (fp!=NULL)
    00154         {
    00155                 fread(&rd.SimTime, sizeof(double), 1, fp);
    00156                 fread(&rd.X0, sizeof(double), STATENUM, fp);
    00157                 fread(&rd.reltol, sizeof(double), 1, fp);
    00158                 fread(&rd.abstol, sizeof(double), STATENUM, fp);
    00159                 fread(&rd.param, sizeof(double), PARAMNUM, fp);
    00160                 fread(&rd.dirDo, sizeof(int), 8, fp);
    00161
    00162                 copy_to_arg(&rd, P, jP, state, time);
    00163
    00164         if (fclose(fp)) fprintf( stderr, "Could not close file... \n");
    00165
    00166                 print_arguments_values(P, jP, state, time);
    00167         }
    00168         else
    00169         {
    00170                 fprintf( stderr, "Could not open 'InitialConditions.icd' file... \n");
    00171         }
    00172
    00173         return 1;
    00174 }