mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
PHRQ_base has not been added to the C++ classes yet. PHRQ_io is implemented enough to run. Need to work on reimplementing logic by moving some things that were in phreeqc_files.cpp (now implemented as PHRQ_io class) to PHRQ_io_output, which is derived from output.cpp. PHRQ_io_output has methods of Phreeqc class and knows the data in the phreeqc class. PHRQ_io does not know about the phreeqc class. The ifdef USE_OLD_IO should cause io to revert to the old way of doing it. I have only worked on ClrClass_debug to now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5627 1feff8c3-07ed-0310-ac33-dd36852eb9cd
226 lines
5.1 KiB
C++
226 lines
5.1 KiB
C++
#include "Phreeqc.h"
|
||
#include "output.h"
|
||
#include "phrqproto.h"
|
||
#include "input.h"
|
||
#include "NameDouble.h"
|
||
#include "Solution.h"
|
||
#include "Reaction.h"
|
||
#include "PPassemblage.h"
|
||
#include "Exchange.h"
|
||
#include "Surface.h"
|
||
#include "GasPhase.h"
|
||
#include "SSassemblage.h"
|
||
#include "cxxKinetics.h"
|
||
|
||
|
||
/* ----------------------------------------------------------------------
|
||
* MAIN
|
||
* ---------------------------------------------------------------------- */
|
||
int
|
||
main(int argc, char *argv[])
|
||
/*
|
||
* Main program for PHREEQC
|
||
*/
|
||
{
|
||
|
||
//int errors;
|
||
#if defined(WIN32_MEMORY_DEBUG)
|
||
int tmpDbgFlag;
|
||
|
||
/*
|
||
* Set the debug-heap flag to keep freed blocks in the
|
||
* heap's linked list - This will allow us to catch any
|
||
* inadvertent use of freed memory
|
||
*/
|
||
tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||
//tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
|
||
tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
|
||
///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF;
|
||
_CrtSetDbgFlag(tmpDbgFlag);
|
||
//_crtBreakAlloc = 9482;
|
||
#endif
|
||
|
||
/*if (svnid == NULL)
|
||
fprintf(stderr, " ");*/
|
||
|
||
|
||
Phreeqc phreeqc_instance;
|
||
phreeqc_instance.main_method(argc, argv);
|
||
#ifdef CHARTxxx
|
||
if (phreeqc_instance.u_g)
|
||
{
|
||
System::Diagnostics::Process^ currentProcess = System::Diagnostics::Process::GetCurrentProcess();
|
||
//System::Console::WriteLine(currentProcess->Threads->Count);
|
||
while (currentProcess->Threads->Count > 8)
|
||
{
|
||
currentProcess->Refresh();
|
||
//System::Console::WriteLine(currentProcess->Threads->Count);
|
||
System::Threading::Thread::CurrentThread->Sleep(100);
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
|
||
|
||
int CLASS_QUALIFIER
|
||
main_method(int argc, char *argv[])
|
||
/*
|
||
* Main program for PHREEQC
|
||
*/
|
||
{
|
||
|
||
int errors;
|
||
void *db_cookie = NULL;
|
||
void *input_cookie = NULL;
|
||
#if defined(WIN32_MEMORY_DEBUG)
|
||
int tmpDbgFlag;
|
||
|
||
/*
|
||
* Set the debug-heap flag to keep freed blocks in the
|
||
* heap's linked list - This will allow us to catch any
|
||
* inadvertent use of freed memory
|
||
*/
|
||
tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||
//tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
|
||
tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
|
||
///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF;
|
||
_CrtSetDbgFlag(tmpDbgFlag);
|
||
//_crtBreakAlloc = 9482;
|
||
#endif
|
||
|
||
//if (svnid == NULL)
|
||
// fprintf(stderr, " ");
|
||
phast = FALSE;
|
||
/*
|
||
* Add callbacks for error_msg and warning_msg
|
||
*/
|
||
#ifdef USE_OLD_IO
|
||
if (add_output_callback(phreeqc_handler, this) != OK)
|
||
{
|
||
fprintf(stderr, "ERROR: %s\n",
|
||
"NULL pointer returned from malloc or realloc.");
|
||
fprintf(stderr, "ERROR: %s\n", "Program terminating.");
|
||
return -1;
|
||
}
|
||
#endif
|
||
|
||
/*
|
||
* Open input/output files
|
||
*/
|
||
errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE);
|
||
if (errors != 0)
|
||
{
|
||
//clean_up();
|
||
return errors;
|
||
}
|
||
#ifdef DOS
|
||
write_banner();
|
||
#endif
|
||
|
||
/*
|
||
* Initialize arrays
|
||
*/
|
||
errors = do_initialize();
|
||
if (errors != 0)
|
||
{
|
||
//clean_up();
|
||
return errors;
|
||
}
|
||
/*
|
||
* Load database into memory
|
||
*/
|
||
#if defined(MERGE_INCLUDE_FILES)
|
||
this->set_cookie((std::ifstream *) db_cookie);
|
||
errors = read_database(PHRQ_io::istream_getc, db_cookie);
|
||
this->clear_cookie();
|
||
#else
|
||
errors = read_database(getc_callback, db_cookie);
|
||
#endif
|
||
if (errors != 0)
|
||
{
|
||
//clean_up();
|
||
return errors;
|
||
}
|
||
|
||
/*
|
||
* Read input data for simulation
|
||
*/
|
||
#if defined(MERGE_INCLUDE_FILES)
|
||
this->set_cookie((std::ifstream *)input_cookie);
|
||
errors = run_simulations(PHRQ_io::istream_getc, input_cookie);
|
||
this->clear_cookie();
|
||
#else
|
||
errors = run_simulations(getc_callback, input_cookie);
|
||
#endif
|
||
if (errors != 0)
|
||
{
|
||
//clean_up();
|
||
return errors;
|
||
}
|
||
|
||
|
||
/*
|
||
* Display successful status
|
||
*/
|
||
errors = do_status();
|
||
if (errors != 0)
|
||
{
|
||
//clean_up();
|
||
return errors;
|
||
}
|
||
|
||
|
||
//clean_up();
|
||
//close_input_files();
|
||
//close_output_files();
|
||
|
||
return 0;
|
||
}
|
||
|
||
|
||
#ifdef DOS
|
||
/* ---------------------------------------------------------------------- */
|
||
int CLASS_QUALIFIER
|
||
write_banner(void)
|
||
/* ---------------------------------------------------------------------- */
|
||
{
|
||
char buffer[80];
|
||
int len, indent;
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> <20>\n");
|
||
|
||
/* version */
|
||
len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@");
|
||
indent = (44 - len) / 2;
|
||
output_msg(OUTPUT_SCREEN, "%14c<34>%*c%s%*c<>\n", ' ', indent, ' ', buffer,
|
||
44 - indent - len, ' ');
|
||
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> <20>\n");
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> A hydrogeochemical transport model <20>\n");
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> <20>\n");
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> by <20>\n");
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> D.L. Parkhurst and C.A.J. Appelo <20>\n");
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20> <20>\n");
|
||
|
||
|
||
/* date */
|
||
len = sprintf(buffer, "%s", "@VER_DATE@");
|
||
indent = (44 - len) / 2;
|
||
output_msg(OUTPUT_SCREEN, "%14c<34>%*c%s%*c<>\n", ' ', indent, ' ', buffer,
|
||
44 - indent - len, ' ');
|
||
|
||
output_msg(OUTPUT_SCREEN,
|
||
" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n\n");
|
||
|
||
return 0;
|
||
}
|
||
#endif
|