//### //***************************************************************************** // * // Program Name: therm * // * // File Name: therm.cpp * // * // Purpose: This is the start of the Thermodynamic Equilibrium * // Program * // * // Author: Robert L. Reese * // * // Date: June 1, 1973 * // * // Language: Borland C++ Compiler, Version 4.5 * // * // Hardware: IBM Compatible PC * // * // Operating System: Microsoft Windows 98 * // * // Update History: * // * // Name Date Revision Changes * // ---- ---- --------- ------- * // * // R.L. Reese 06/01/73 0 Initial Release * // R.L. Reese 11/23/03 A Converted to C++ * // R.L. Reese 04/12/06 B Added new_thermo parameter * // for inputing type of thermo * // file * // * //----------------------------------------------------------------------------* // * // Execution Command: * // * // therm Where: * // * // No Parameters * // * // Program will request name of input parameter file and output * // listing file. The program will expect the thermodynamic data * // file to be named THERMODAT * // * //----------------------------------------------------------------------------* // * // Definitions: * // * // Local Variables: * // --------------- * // * // adata - Character buffer containing data returned from * // init_read * // break_flag - Logical flag indicating if error occurred in * // function file_open * // break_value - Integer value indicating if break from loop is * // required upon return from a function * // eof - Integer value of status returned from init_read * // empty_file - Integer value of status returned from init_read * // file_error_inp - Logical flag indicating if error on input file * // open * // file_error_out - Logical flag indicating if error on output file * // open * // file_error_scr - Logical flag indicating if error on scratch file * // open * // file_error_thr - Logical flag indicating if error on thermo file * // open * // first_time - Logical flag indicating if first time through * // outer loop * // i - Integer for loop index * // j - Integer for loop index * // k - Integer for loop index * // nbytes - Integer value of number of bytes from init_read * // read_status - Integer status of read operation * // stop_or_go - Integer value input by user to stop or go * // * // Pointers: * // -------- * // * // adata_pt - Character pointer to data from init_read * // break_value - Integer pointer to value indicating if error * // occurred in called function * // empty_file_pt - Integer pointer to empty file value from * // init_read * // eof_pt - Integer pointer to eof value from init_read * // nbytes_pt - Integer pointer to number of bytes read from * // init_read * // read_status_pt - Integer pointer to current read status * // * // Global Variables: * // ---------------- * // * // local(extern.h) * // aa - Double precision array used to store increment * // value of reactant mole fraction * // bb - Real array used to store base value of reactant * // mole fraction * // fco - Real value of fugacity of CO * // fco2 - Real value of fugacity of CO2 * // fh2 - Real value of fugacity of H2 * // fh2o - Real value of fugacity of H2O * // ll - Integer variable used to determine what reactants * // are to be added or removed * // removed - Integer variable used to determine if the first * // reactant in a ternary system is to be removed * // to - Real array used to store final value of reactant * // mole fraction * // local - used by therm and loop_read * // pressure_index - Integer do loop index for processing pressure * // inputs * // processed_react- Logical flag indicating if the react records * // have been read * // read_error - Logical flag indicating if read error occurred * // read_loop - Logical flag controlling the read loop * // temp_index - Integer do loop index for processing temperature * // inputs * // indx.h * // alter - Logical variable used to indicate reactant mole * // mole fractions with unequal top and base values * // are to be altered * // newmol - Integer value used in react to determine if * // reactant records have been read * // nomit - Integer value of number of species to be omitted * // plus - Logical variable used to indicate if reactants * // are to be added to the system or if a ternary * // system is being considered * // systm - Logical variable used to denote that a ternary * // system is being considered * // misc.h * // noconv - Integer value of accumulative number of times * // there is to no solution to a T-P point * // points.h * // gas_input - Logical variable used to determine if gas is used * // rsize - Real value used to determine size of mole fraction * // values for gas specie to be output * // tem - Logical variable used to denote that for each * // assigned T there is an assigned P * // speces.h * // ensert - Character*4 variable containing ith specie of n * // species which are specified to be considered or * // input * // omit - Character*4 variable containing ith specie of n * // to be omitted from current system * // * // Constants: * // --------- * // * // local * // FALSE - Defines value of logical false = 0 * // TRUE - Defines value of logical true = 1 * // arrays.h * // adata_len - Integer value for length of adata buffer * // element_max - Integer containing maximum number of elements allowed * // size_char - Integer value used as len of char to replace default * // length of 4 characters in one word for FORTRAN 4 and * // FORTRAN 77 conversion * // species_max - Integer value of maximum number of species allowed * // stop_or_go_len - Integer value of length of stop_or_go character * // sub_size - Integer variable used as size of species name segment * // total_char - Integer value of length of species character names * // constant.h * // iblank - Character*1 containing a blank * // * // Include Files: * // -------------- * // * // arrays.h - Contains sizes for include files * // constant.h - Contains constants and sizes * // double.h - Contains double precision variables * // (externals here) * // extern.h - Contains all variables used as externals in * // the other functions used by therm * // indx.h - Contains index variables (externals here) * // iostream.h - Contains C++ I/O routines * // misc.h - Contains miscellaneous variables (externals * // here) * // points.h - Contains temperature and pressure variables * // (externals here) * // speces.h - Contains species variables (externals here) * // stdio.h - Contains C++ I/O routines * // stdlib.h - Contains C++ standard library routines * // string.h - Contains C++ string routines * // * // External Software: * // ----------------- * // * // extern_init - Routine to initialize all variables in include files * // file_open - Routine to open input and output files * // loop_read - Routine to read and process input records * // * // Files: * // ----- * // * // Input Files: * // * // infile - Input parameter file - FILE *input_unit * // 'THERMODAT' - Input thermodynamic data file- FILE *thermo_unit * // * // Intermediate Files: * // * // 'SCRATCH' - Temporary file for storing thermodynamic data * // FILE * scratch_unit * // * // Output Files: * // * // outfile - Output listing file - FILE * output_unit * // * //***************************************************************************** //### #include "arrays.h" #include #include #include #include #define FALSE 0 #define TRUE 1 void extern_init(void); void file_open(int *break_flag_pt, int *file_error_inp_pt, int *file_error_out_pt, int *file_error_scr_pt, int *file_error_thr_pt); void loop_read(FILE *input_unit, FILE *output_unit, FILE *scratch_unit, FILE *therm_unit, int *read_status_pt, int *eof_pt, char *adata_pt, int *empty_file_pt, int *nbytes_pt, int *break_value_pt); FILE *input_unit; FILE *output_unit; FILE *scratch_unit; FILE *therm_unit; // extern.h contains all variables used as externals in the other functions #include "extern.h" // externals for function loop_read int pressure_index ; int processed_react ; int read_error; int read_loop ; int temp_index ; int main(void) { #include "constant.h" int break_flag; int break_value; int eof; int empty_file; int file_error_inp ; int file_error_out ; int file_error_scr ; int file_error_thr ; int i ; int j ; int k ; int nbytes; int read_status ; // pointers char *adata_pt; int *break_value_pt; int *empty_file_pt; int *eof_pt; int *nbytes_pt; int *read_status_pt; char adata[adata_len]; char stop_or_go[stop_or_go_len] ; static int first_time = TRUE ; // initialize pointers adata_pt = &adata[0]; break_value_pt = &break_value; empty_file_pt = &empty_file; eof_pt = &eof; nbytes_pt = &nbytes; read_status_pt = &read_status; //start outer_loop for (;;) { extern_init(); read_error = FALSE; // start first_test if(! first_time) { cout << " TYPE 1 TO CONTINUE, ZERO TO STOP : " ; cin >> stop_or_go ; // start all_done if(stop_or_go[0] == '0') { // exit outer_loop break; } else if(stop_or_go[0] != '1') { // exit outer_loop read_error = TRUE; cout << " Input error! "< #include #include #include #define FALSE 0 #define TRUE 1 char dum1; char dum2; char dum3; void check_limits(FILE *output_unit, int *break_value_pt, int *read_error_pt); void check_systems(FILE *output_unit, int *break_value_pt, int *read_status_pt); void init_read(char *idata, int *eof, FILE *opu, FILE *inp_unit, int *empty_file, int *nbytes_pt); void check_input(FILE *input_unit, FILE *output_unit, int *break_value_pt, int *read_error_pt) { #include "constant.h" int empty_file; int eof; int i; int j; int nbytes; int nmove; int read_status; char adata[adata_len]; char blank[blank_length]; char real_buf[real_buf_len]; // pointers char *adata_pt; char *end_ptr = "abcde"; int *eof_pt; int *empty_file_pt; int *nbytes_pt; int *read_status_pt; char *real_buf_pt; //start initialize blank for(i=0;i kase_test) { nmove = kase_moves; } else { nmove = *nbytes_pt - (kase_inc+1); } // end compute_kase_moves strncpy(real_buf_pt,adata_pt+kase_inc,nmove); // start kase_find_blanks for(j=kase_loop;j>=0;j=j-1) { // start kase_found_nonblank if(*(real_buf_pt+j) != iblank) { // exit kase_find_blanks break; } // end kase_found_nonblank } // end kase_find_blanks strncpy(real_buf_pt,adata_pt+kase_inc,nmove); kase = strtol(real_buf_pt,&end_ptr,num_radix); // start kase_error if(end_ptr != (real_buf_pt+(j+1))) { fprintf(output_unit," Error in KASE Number\n"); cout << " Error in KASE Number"< rsize_test) { nmove = rsize_moves; } else { nmove = *nbytes_pt - (rsize_inc+1); } // end compute_rsize_moves strncpy(real_buf_pt,adata_pt+rsize_inc,nmove); // start rsize_find_blanks for(j=rsize_loop;j>=0;j=j-1) { // start rsize_found_nonblank if(*(real_buf_pt+j) != iblank) { // exit rsize_find_blanks break; } // end rsize_found_nonblank } // end rsize_find_blanks strncpy(real_buf_pt,adata_pt+rsize_inc,nmove); rsize = strtod(real_buf_pt,&end_ptr); // start rsize_error if(end_ptr != (real_buf_pt+(j+1))) { fprintf(output_unit," Error in RSIZE Value\n"); cout << " Error in RSIZE Value"< tri_test) { nmove = tri_moves; } else { nmove = *nbytes_pt - (tri_inc+1); } // end compute_tri_moves strncpy(real_buf_pt,adata_pt+tri_inc,nmove); // start tri_find_blanks for(j=tri_loop;j>=0;j=j-1) { // start tri_found_nonblank if(*(real_buf_pt+j) != iblank) { // exit tri_find_blanks break; } // end tri_found_nonblank } // end tri_find_blanks tri = strtod(real_buf_pt,&end_ptr); // start tri_error if(end_ptr != (real_buf_pt+(j+1))) { cout << " Error in TRI Value"< #include "points.h" #include #define FALSE 0 #define TRUE 1 extern char dum1; extern char dum2; extern char dum3; void check_limits(FILE *output_unit, int *break_value_pt, int *read_error_pt) { #include "constant.h" *break_value_pt = FALSE; //start do_while_loop for(;;) { // start rsize_range if(rsize < 0.0) { fprintf(output_unit, " Error - RSIZE value must be greater than or equal to zero\n"); cout << " Error - RSIZE value must be greater than or equal to zero" << endl; *read_error_pt = TRUE; // exit do_while_loop *break_value_pt = TRUE; break; } // end rsize_range // start tem_check if(dum1 == yes_flag) { tem = TRUE; } else if(dum1 != not_flag) { fprintf(output_unit," Error in TEM Value\n"); cout << " Error in TEM Value" << endl; *read_error_pt = TRUE; // exit do_while_loop *break_value_pt = TRUE; break; } // end tem_check // start gas_input_check if(dum2 == yes_flag) { gas_input = TRUE; } else if(dum2 != not_flag) { fprintf(output_unit," Error in GAS INPUT Value\n"); cout << " Error in GAS INPUT Value" << endl; *read_error_pt = TRUE; // exit do_while_loop *break_value_pt = TRUE; break; } // end gas_input_check gas_input = TRUE ; dum2 = yes_flag; // start new_thermo_check if(dum3 == yes_flag) { new_thermo = TRUE; } else if(dum3 != not_flag) { fprintf(output_unit," Error in NEW_THERMO Value\n"); cout << " Error in NEW_THERMO Value" << endl; *read_error_pt = TRUE; // exit do_while_loop *break_value_pt = TRUE; break; } // end new_thermo_check // exit do_while_loop break; } // end do_while_loop } // end function check_limits //### //***************************************************************************** // * // Function Name: check_omit * // * // File Name: check_omit.cpp * // * // Purpose: Process the species names in the omit records and stores * // them. * // * // Author: Robert L. Reese * // * // Date: January 08, 2004 * // * // Language: Borland C++ Compiler, Version 4.5 * // * // Hardware: IBM Compatible PC * // * // Operating System: Microsoft Windows 98 * // * // Update History: * // * // Name Date Revision Changes * // ---- ---- --------- ------- * // * // R.L. Reese 01/07/04 0 Initial Release * // * //----------------------------------------------------------------------------* // * // Usage: * // * // check_omit(adata_pt, * // nbytes_pt) * // where: * // * // adata_pt - Integer pointer to current record being processed * // nbytes_pt - Integer pointer to number of bytes in current record * // * //----------------------------------------------------------------------------* // * // Definitions: * // * // Local Variables: * // ---------------- * // * // i - Integer for loop index * // j - Integer for loop index * // kount - Integer value pointing to current element in record * // * // Pointers * // ----------------- * // * // None * // * // Global Variables: * // ----------------- * // * // indx.h * // nomit - Integer value of number of species listed on omit * // records * // speces.h * // omit - Character*4 variable containing ith specie of n * // species which are specified to be considered for * // omitting * // * // Constants: * // --------- * // * // constant.h * // first_name - Integer value of number of characters in name * // first_start - Integer value of start of first name * // iblank - Character*1 containing a blank * // max_names - Integer value of maximum number of names in one * // record * // second_check - Integer value for check if second name present * // second_name - Integer value for start of second name * // * // Include Files: * // ------------- * // * // arrays.h - Contains sizes for include files * // constant.h - Contains various constants and sizes * // indx.h - Contains index variables * // speces.h - Contains species variables * // * // * // External Software: * // ----------------- * // * // None * // * // Files: * // ----- * // * // Input Files: * // * // None * // * // Intermediate Files: * // * // None * // * // Output Files: * // * // None * // * //***************************************************************************** //### #include "arrays.h" #include "constant.h" #include "indx.h" #include "speces.h" void check_omit(char *adata_pt, int *nbytes_pt) { int i; int j; int kount; kount = first_name; //start check_omit_name for(i = 0; i< max_names;i++) { // start check_omit_test if(*(adata_pt+kount) != iblank) { // start check_omit_letters for(j = 0;j < first_start ;j++) { omit[j][nomit] = iblank; // start get_check_omit_name if(kount < ((*nbytes_pt)-1)) { omit[j][nomit] = *(adata_pt+kount) ; kount++; } else { // exit check_omit_letters break; } // end get_check_omit_name } // end check_omit_letters kount = second_name; } // end check_omit_test nomit = nomit+1 ; // start second_omit if(*nbytes_pt < second_check) { // exit check_omit_name break; } // end second_omit } // end check_omit_name } // end function check_omit //### //***************************************************************************** // * // Function Name: check_systems * // * // File Name: check_systems.cpp * // * // Purpose: Verify the correct base, top, add and tri values for the * // Alter, Systm and Plus problems * // * // Author: Robert L. Reese * // * // Date: January 08, 2004 * // * // Language: Borland C++ Compiler, Version 4.5 * // * // Hardware: IBM Compatible PC * // * // Operating System: Microsoft Windows 98 * // * // Update History: * // * // Name Date Revision Changes * // ---- ---- --------- ------- * // * // R.L. Reese 01/07/04 0 Initial Release * // * //----------------------------------------------------------------------------* // * // Usage: * // * // check_systems(output_unit, * // break_value_pt, * // read_status_pt) * // where: * // * // output_unit - FILE pointer to logical output listing unit * // break_value - Integer logical pointer indicating if loop needs to * // be exited upon return * // read_status_pt - Integer pointer to read error flag * // = 0, no error * // = 1, error * // * //----------------------------------------------------------------------------* // * // Definitions: * // * // Local Variables: * // ---------------- * // * // i - Integer for loop index * // * // Pointers * // ----------------- * // * // None * // * // Global Variables: * // ----------------- * // * // indx.h * // nreac - Integer value of number of reactant records read * // plus - Logical variable used to indicate if reactants * // are to be added to the system or if a ternary * // system is being considered * // systm - Logical variable used to denote that a ternary * // system is being considered * // misc.h * // add - Real array containing increment of ith reactant mole * // fraction * // base - Real array containing first value of mole fraction of * // ith reactant * // top - Real array containing final value of mole fraction of * // ith reactant * // tri - Real value of increment of mole fraction for all * // reactants of ternary system * // * // Constants: * // --------- * // * // local * // FALSE - Defined value for false logical test = 0 * // TRUE - Defined value for true logical test = 1 * // constant.h * // nreac_test - Integer value of number of reactants for ternary * // system * // third_add_indx - Integer value of index to third add value in ternary * // system * // * // Include Files: * // ------------- * // * // arrays.h - Contains sizes for include files * // constant.h - Contains constants and sizes * // indx.h - Contains index variables * // iostream.h - Contains I/O routines * // misc.h - Contains miscellaneous variables * // stdio.h - Contains FILE declaration * // * // * // External Software: * // ----------------- * // * // None * // * // Files: * // ----- * // * // Input Files: * // * // None * // * // Intermediate Files: * // * // None * // * // Output Files: * // * // output_unit - logical device for output listings * // * //***************************************************************************** //### #include "arrays.h" #include "indx.h" #include #include "misc.h" #include #define FALSE 0 #define TRUE 1 void check_systems(FILE *output_unit, int *break_value_pt, int *read_status_pt) { #include "constant.h" int i; *break_value_pt = FALSE; *read_status_pt = 0; //start do_while_loop for(;;) { // start systm_tri_error if(systm) { // start tri_check if(tri <= 0.0) { cout << " Error - SYSTM problem must have positive non-zero tri value" << endl; fprintf(output_unit, " Error - SYSTM problem must have positive non-zero tri value\n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } else if(add[0] != -(tri)) { cout << " Error - SYSTM problem first add must be equal to negative tri value" << endl; fprintf(output_unit, " Error - SYSTM problem first add must be equal to negative tri value\n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } else if(add[1] != tri) { cout << " Error - SYSTM problem second add must equal positive tri value" << endl; fprintf(output_unit, " Error - SYSTM problem second add must equal positivetri value\n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } // end tri_check } // end systm_tri_error // Verify base, top and add values for Plus Problems with zero tri value // start plus_no_tri if(plus && tri == 0.0) { // start loop_plus for(i=0;i= top[1]) { cout << " Error - PLUS (non-zero tri) problem second base must be less than top " << endl; fprintf(output_unit, " Error - PLUS (non-zero tri) problem second base must be less than top \n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } else if(add[1] != 0.0) { cout << " Error - PLUS (non-zero tri) problem second add must equal zero " << endl; fprintf(output_unit, " Error - PLUS (non-zero tri) problem second add must equal zero \n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } else if(add[third_add_indx] <= 0.0) { cout << " Error - PLUS (non-zero tri) problem third add must be greater than zero " << endl; fprintf(output_unit, " Error - PLUS (non-zero tri) problem third add must be greater than zero \n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } else if(add[third_add_indx] != tri) { cout << " Error - PLUS (non-zero tri) problem third add must equal tri value " << endl; fprintf(output_unit, " Error - PLUS (non-zero tri) problem third add must equal tri value \n"); *read_status_pt = 1; // exit do_while_loop *break_value_pt = TRUE; break; } // end test_plus_tri } // end plus_tri // exit do_while_loop break; } // end do_while_loop } // end function check_systems //### //***************************************************************************** // * // Function Name: clear_arrays * // * // File Name: clear_arrays.cpp * // * // Purpose: This function is called from react and clears specified * // arrays before processing the reac records. * // * // Author: Robert L. Reese * // * // Date: January 28, 2004 * // * // Language: Borland C++ Compiler, Version 4.5 * // * // Hardware: IBM Compatible PC * // * // Operating System: Microsoft Windows 98 * // * // Update History: * // * // Name Date Revision Changes * // ---- ---- --------- ------- * // * // R.L. Reese 01/28/04 0 Initial Release * // * //----------------------------------------------------------------------------* // * // Usage: * // * // clear_arrays(adata) where: * // * // adata - real pointer to real array used in react * // * // * //----------------------------------------------------------------------------* // * // Definitions: * // * // Local Variables: * // ---------------- * // * // i - Integer variable used as do loop index * // j - Integer variable used as do loop index * // n - Integer variable used as do loop index * // * // Pointers * // ----------------- * // * // None * // * // Global Variables: * // ----------------- * // * // indx.h * // alter - Logical variable indicating reactant mole factions with * // unequal top and base values are to be altered * // newmol - Integer variable used to determine if reactant records * // have been read, and if type of mixture problem has been * // determined. * // misc.h * // anum - Real array containing stochiometric coefficients of * // elements on reactant records * // bo - Real array containing assigned Kg-atoms of element i per* // Kg of total reactant * // llmt - Character*4 containing alphameric symbols for the * // elements in the system being studied * // name - Character*4 containing alphameric symbols for the * // elements as given in the reactant records * // * // Constants: * // --------- * // * // arrays.h * // element_max - Integer containing maximum number of elements allowed* // reacts_max - Integer containing maximum number of reactants in a * // record * // size_char - Integer value used as len of char to replace default * // length of 4 characters in one word for FORTRAN 4 and * // FORTRAN 77 conversion * // constant.h * // iblank - Character*1 containing a blank * // * // Include Files: * // ------------- * // * // arrays.h - Contains sizes for include files * // constants.h - Contains various constants * // indx.h - Contains index variables * // misc.h - Contains miscellaneous variables * // * // External Software: * // ----------------- * // * // None * // * // Files: * // ----- * // * // Input Files: * // * // None * // * // Intermediate Files: * // * // None * // * // Output Files: * // * // None * // * //***************************************************************************** //### #include "arrays.h" #include "indx.h" #include "misc.h" void clear_arrays(float *adata) { #include "constant.h" int i; int j; int n; //start first_time if(newmol == 0) { // start init_anum1 for(i=0;i #include "speces.h" #include #include #include #define FALSE 0 #define TRUE 1 void init_read(char *adata, int *eof, FILE *opu, FILE *inp_unit, int *empty_file, int *nbytes_pt); void coeff_read(FILE *read_unit, FILE *output_unit, int *empty_file_pt, char *adata_pt, int *nbytes_pt, int *begin_loop_pt, int *eof_pt, char *ibuf_pt, char *blank_pt) { #include "constant.h" extern char nam[size_char][sub_size] ; int i; int j; int jj; int k; int kk; int kount ; int m; int num_coeff; char *end_ptr = "abcde"; // read three sets of coefficients //start coeff_read_17a for(m=0;m full_record && m < partial_index) ||(*nbytes_pt > partial_record && m == partial_index)) { fprintf(output_unit," Warning - Coefficient record too long for:\n"); fprintf(output_unit,"%s\n",adata_pt); cout << " Warning - Coefficient record too long for:"<=0;kk=kk-1) { // start coef_found_nonblank if(*(ibuf_pt+kk) != iblank) { // exit coef_find_blanks break; } // end coef_found_nonblank } // end coef_find_blanks // start find_missing_E_plus for(jj=0;jj