Commit d1fd1ece authored by Daniel Brown's avatar Daniel Brown

refs 164 - more mingw updates, windows version now calls both gnuplot and...

refs 164 - more mingw updates, windows version now calls both gnuplot and wgnuplot. Firstly a gnuplot test file is produced, which sets the terminal to unknown so no plots are actually shown, then gnuplot is used to run this test file. This is done as gnuplot actually has an stderr output to show the user of any errors. If no errors are present the proper plot file is run using wgnuplot which is spawned in a new process so that it doesn't block the original process, so now users can have multiple plots open at once as is done on OSX/UNIX with x11
parent 81469d43
......@@ -37,14 +37,16 @@ FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_CLASSES_ROOT\gnuplot\shell\
IF DEFINED appdir (
ECHO Found GNUPLOT %appdir%!
ECHO Adding to kat.ini...
ECHO Adding to end of kat.ini...
echo GNUCOMMAND '%appdir%' >> kat.ini
) ELSE (
ECHO No GNUPLOT installation could be
ECHO found. Please find it manually or
ECHO and add to the GNUCOMMAND to the
ECHO kat.ini file. Or install it and
ECHO re-run findGnuplot.bat.
ECHO and add to the GNUCOMMAND and WGNUCOMMAND
ECHO to the kat.ini file. Or install gnuplot
ECHO using the installer
ECHO http://sourceforge.net/projects/gnuplot/files/latest/download
ECHO and then re-run findGnuplot.bat.
)
echo ---------------------------------------
pause
\ No newline at end of file
......@@ -47,6 +47,7 @@ TARGET=0
TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3
TARGET_WIN64=4
TARGET_CLEAN=6
TARGET_NATIVE=7
......@@ -324,6 +325,7 @@ print_usage()
echo " --build-mac"
echo " --build-mac32"
echo " --build-win32"
echo " --build-win64"
echo " Choose the system which you would like to build an executable for."
echo ""
echo " --clean"
......@@ -366,6 +368,8 @@ elif [[ "$unamestr" == 'Darwin' ]]; then
platform='mac'
elif [[ "$unamestr" == *CYGWIN* ]]; then
platform='win'
elif [[ "$unamestr" == *MINGW32* ]]; then
platform='win'
else
echo "Platform could not be determined" | tee -a $LOGFILE
failure
......@@ -376,56 +380,69 @@ echo 'Running on' $platform
case "$1" in
"--build")
NATIVE="-march=native"
if [[ "$platform" == 'linux' ]]; then
CPUARCH=""
target_arch=$platform
if [[ "$platform" == 'linux' ]]; then
TARGET=$TARGET_LINUX
elif [[ "$platform" == 'mac' ]]; then
TARGET=$TARGET_MAC
elif [[ "$platform" == 'win' ]]; then
TARGET=$TARGET_WIN32
export CFLAGS="$CFLAGS -m64"
CPUARCH=
target_arch=win64
else
echo "Platform Target could not be determined" | tee -a $LOGFILE
failure
fi
CPUARCH=""
target_arch=$platform
echo "Building native Finesse version:" | tee -a $LOGFILE
;;
"--build-linux")
NATIVE=""
TARGET=$TARGET_LINUX
TARGET=$TARGET_LINUX
CPUARCH="-m64"
target_arch="linux"
echo "Building Linux version:" | tee -a $LOGFILE
;;
"--build-linux32")
NATIVE=""
TARGET=$TARGET_LINUX
TARGET=$TARGET_LINUX
CPUARCH="-m32"
target_arch="linux"
echo "Building Linux 32bit version:" | tee -a $LOGFILE
;;
"--build-mac32")
NATIVE=""
TARGET=$TARGET_MAC
TARGET=$TARGET_MAC
CPUARCH="i386"
target_arch="mac"
echo "Building Mac (Intel) 32bit version:" | tee -a $LOGFILE
;;
"--build-mac")
NATIVE=""
TARGET=$TARGET_MAC
TARGET=$TARGET_MAC
CPUARCH=""
target_arch="mac"
echo "Building Mac (Intel) version:" | tee -a $LOGFILE
;;
"--build-win32")
NATIVE=""
TARGET=$TARGET_WIN32
TARGET=$TARGET_WIN32
export CFLAGS="$CFLAGS -m32"
CPUARCH="i686"
target_arch="win"
target_arch="win32"
echo "Building Win32 version:" | tee -a $LOGFILE
;;
"--build-win64")
NATIVE=""
TARGET=$TARGET_WIN32
export CFLAGS="$CFLAGS -m64"
CPUARCH="x86_64"
target_arch="win64"
echo "Building Win64 version:" | tee -a $LOGFILE
;;
"--checkout")
echo ""
echo "ERROR: --checkout is no longer used, use 'git checkout [branch name]' instead." | tee -a $LOGFILE
......@@ -519,7 +536,7 @@ case $TARGET in
;;
$TARGET_WIN32)
check_prerequisites || failure
export CFLAGS="$OPTIM_CFLAGS $NATIVE"
export CFLAGS="$CFLAGS $OPTIM_CFLAGS $NATIVE"
build || failure
;;
......
......@@ -65,27 +65,21 @@ relerr 1E-3 # relative error for Cuba intergations
# PYTHONCOMMAND "python $s 2>/dev/null &"
## For Windows systems
# if you have a space in the path to wgnuplot.exe you need to
#
# Please install Gnuplot from: http://sourceforge.net/projects/gnuplot/files/latest/download
# You can use the findGnuplot.bat file to automatically search and add the gnuplot command.
# If you have a space in the path to wgnuplot.exe you need to
# Note use of ' and " to encapsulate path and GNUCOMMAND
# GNUCOMMAND '"C:\Program Files\gnuplot\bin\Wgnuplot.exe" --persist'
# GNUCOMMAND '"C:\Program Files\gnuplot\bin\Wgnuplot.exe" --persist $s'
# else use
# GNUCOMMAND 'C:\gnuplot\bin\Wgnuplot.exe --persist'
#
# For windows you can also bring up a plot and return to the command
# line to run more Finesse files by using the command:
#
#GNUCOMMAND 'start /b wgnuplot.exe --persist'
#
# However for this to work you need to ensure that wgnuplot.exe is in
# your PATH environment variable. You can check if it is by pressing
# `win+R` keys and typing cmd, then typing `wgnuplot`, if it opens it
# is in your PATH. If not you must add it to your PATH.
#
## Windows --persist vs -persist
# Using -persist brings up the wgnuplot main window for editting the plots
# each time you run Finesse, sometimes this is useful if you want to play
# around with the plot. To hide it use --persist.
# GNUCOMMAND 'C:\gnuplot\bin\Wgnuplot.exe --persist $s'
#
# From FINESSE version 2.1 and above the Windows version should show gnuplot plots
# and allow them plots to be kept open and still use the terminal.
# FINESSE will now internally use a combination of both wgnuplot.exe and gnuplot.exe
# which it expects to be in the same path as stated in the GNUCOMMAND, this is
# irrespective of which binary is actually stated in the GNUCOMMAND variable.
## Python plotting on Windows
# On Windows you should use the pythonw version to call the plotting, this
# ensures that the console window is hidden and only the plot is show.
......@@ -95,7 +89,7 @@ relerr 1E-3 # relative error for Cuba intergations
# If the path to your python executable has a space in make sure that you use single quotes around
# everything and double quotes around the executable path, for example:
#
# PYTHONCOMMAND '"c:\my python path with space\bin\pythonw" $s'
# PYTHONCOMMAND '"c:\my python path with spaces\bin\pythonw" $s'
PLOTTING gnuplot
......@@ -1289,6 +1283,4 @@ SUFFIX gif
set term gif transparent small size 640,480 xffffff x000000 x404040 x9500d3 xdda0dd xff0000 xffa500 x66cdaa xcdb5cd xadd8e6 x0000ff
set nokey
set title
END
GNUCOMMAND '"C:\Program Files (x86)\gnuplot\bin\wgnuplot.exe" -p '
END
\ No newline at end of file
......@@ -526,6 +526,10 @@ int main(int argc, char *argv[]) {
strcat(vglobal.output_fname, ".out");
strcpy(vglobal.gnuplot_fname, inter.basename);
strcat(vglobal.gnuplot_fname, ".gnu");
strcpy(vglobal.gnuplot_test_fname, ".");
strcat(vglobal.gnuplot_test_fname, inter.basename);
strcat(vglobal.gnuplot_test_fname, ".tmp");
strcpy(vglobal.log_fname, inter.basename);
strcat(vglobal.log_fname, ".log");
} else if (argc == 3) { // the input and output file names are specified...
......@@ -537,6 +541,9 @@ int main(int argc, char *argv[]) {
strcpy(vglobal.output_fname, argv[num_options + 2]);
strcpy(vglobal.gnuplot_fname, inter.basename);
strcat(vglobal.gnuplot_fname, ".gnu");
strcpy(vglobal.gnuplot_test_fname, ".");
strcat(vglobal.gnuplot_test_fname, inter.basename);
strcat(vglobal.gnuplot_test_fname, ".tmp");
strcpy(vglobal.log_fname, inter.basename);
strcat(vglobal.log_fname, ".log");
} else if (argc == 4) { // input, output and gnuplot file names are given...
......@@ -547,10 +554,13 @@ int main(int argc, char *argv[]) {
strcpy(vglobal.input_fname, argv[num_options + 1]);
strcpy(vglobal.output_fname, argv[num_options + 2]);
strcpy(vglobal.gnuplot_fname, argv[num_options + 3]);
strcpy(vglobal.gnuplot_test_fname, ".");
strcat(vglobal.gnuplot_test_fname, argv[num_options + 3]);
strcat(vglobal.gnuplot_test_fname, ".tmp");
strcpy(vglobal.log_fname, inter.basename);
strcat(vglobal.log_fname, ".log");
}
int tid_main = startTimer("MAIN");
int tid_startup = startTimer("STARTUP");
......
......@@ -2087,6 +2087,7 @@ typedef struct global_var {
char input_fname[FNAME_LEN]; //!< input file name
char output_fname[FNAME_LEN]; //!< output file name
char gnuplot_fname[FNAME_LEN]; //!< gnuplot file name
char gnuplot_test_fname[FNAME_LEN]; //!< gnuplot file name
char matlab_fname[FNAME_LEN]; //!< matlab file name
char python_fname[FNAME_LEN]; //!< python file name
char log_fname[FNAME_LEN]; //!< log file name
......
......@@ -436,7 +436,7 @@ int system_call(const char* command){
int err = system(command);
if(err != 0)
gerror("Failed to execute system_call: '%s' error: '%s'\n", command, strerror(errno));
gerror("Failed to execute system_call: '%s' error: '%i'\n", command, errno);
return err;
#endif
......@@ -444,7 +444,7 @@ int system_call(const char* command){
#ifdef OSWIN
void create_process(wchar_t* command, wchar_t* args){
ShellExecuteW(GetDesktopWindow(), L"open", command, args, L"" , SW_SHOW);
HINSTANCE hinst = ShellExecuteW(GetDesktopWindow(), L"open", command, args, L"" , SW_SHOW);
}
#endif
......
......@@ -3699,9 +3699,15 @@ void x12_out(void) {
// the *.kat file. This probably should be adjustable with an
// option in the kat.ini file?
open_file_to_write_ascii(vglobal.gnuplot_fname, &gfp);
gnufile(0, gfp, tmp_out_filename);
gnufile(0, gfp, tmp_out_filename, false);
fclose(gfp);
if(strlen(vglobal.gnuplot_test_fname) > 0){
open_file_to_write_ascii(vglobal.gnuplot_test_fname, &gfp);
gnufile(0, gfp, tmp_out_filename, true);
fclose(gfp);
}
open_file_to_write_ascii(vglobal.matlab_fname, &mfp);
matlabfile(mfp, tmp_out_filename);
fclose(mfp);
......@@ -3715,51 +3721,74 @@ void x12_out(void) {
#ifdef OSWIN
wchar_t wargs[LINE_LEN] = {0};
wchar_t tmp[LINE_LEN] = {0};
wchar_t w_command[LINE_LEN] = {0};
wchar_t drive[MAX_PATH];
wchar_t dir[MAX_PATH];
wchar_t name[MAX_PATH];
wchar_t ext[MAX_PATH];
wchar_t wtmp[MAX_PATH] = {0};
wchar_t wgnuplot[MAX_PATH] = {0};
wchar_t gnuplot[MAX_PATH] = {0};
char test_cmd[LINE_LEN] = {0};
strcpy(command, replace_str(init.gnucommand, "$s", vglobal.gnuplot_fname));
strcpy(command, replace_str(init.gnucommand, "$s", ""));
// replace forward slashes by backslashes if on Windows
if (OS == __WIN_32__ || OS == __WIN_64__) {
char *find_slash;
while ((find_slash = strchr(command, '/')) != NULL) {
*find_slash = '\\';
}
}
char *find_slash;
wchar_t w_command[LINE_LEN] = {0};
while ((find_slash = strchr(command, '/')) != NULL) {
*find_slash = '\\';
}
mbstowcs(w_command, command, LINE_LEN);
int nargs;
LPWSTR *argList = CommandLineToArgvW((LPCWSTR)w_command, &nargs);
if(argList == NULL || nargs < 2){
gerror("Could not parse GNUPLOT command: %s", command);
}
_wsplitpath(argList[0], drive, dir, name, ext);
_wmakepath(wtmp, drive, dir, L"wgnuplot", ext);
swprintf(wgnuplot, MAX_PATH, L"\"%s\"", wtmp);
_wmakepath(wtmp, drive, dir, L"gnuplot", ext);
swprintf(gnuplot, MAX_PATH, L"\"%s\"", wtmp);
int n;
for(n=1; n<nargs; n++){
swprintf(tmp, LINE_LEN, L"%s %s", wargs, argList[n]);
wcsncpy(wargs, tmp, LINE_LEN);
wcscat(wargs, argList[n]);
wcscat(wargs, L" ");
}
mbstowcs(wtmp, vglobal.gnuplot_fname, LINE_LEN);
wcscat(wargs, L" ");
wcscat(wargs, wtmp);
message("calling gnuplot...\n");
fflush(stdout);
wcstombs(test_cmd, gnuplot, LINE_LEN);
strcat(test_cmd, " ");
strcat(test_cmd, vglobal.gnuplot_test_fname);
if (inter.debug & 1){
message("(using '%s')\n", command);
message("(testing with '%s')\n", test_cmd);
char tmp[LINE_LEN] = {0};
wcstombs(tmp, wgnuplot, LINE_LEN);
char tmp2[LINE_LEN] = {0};
wcstombs(tmp2, argList[0], LINE_LEN);
message("%s ", tmp2);
wcstombs(tmp2, wargs, LINE_LEN);
message("%s\n", tmp2);
message("(running with '%s %s')\n", tmp, tmp2);
fflush(stdout);
}
create_process(argList[0], wargs);
// firstly run without plotting anything
system_call(test_cmd);
// Finally run the windows version of gnuplot
create_process(wgnuplot, wargs);
LocalFree(argList);
#else
......@@ -3952,7 +3981,7 @@ void x3_out(void) {
if (inter.num_gnuterm_cmds != NO_GNUTERM) {
open_file_to_write_ascii(vglobal.gnuplot_fname, &gfp);
gnufile(i, gfp, vglobal.output_fname);
gnufile(i, gfp, vglobal.output_fname, false);
fclose(gfp);
system_call(command);
......
......@@ -90,7 +90,7 @@ char *otypename(int i) {
* \param fp the file pointer
* \param fname the file name
*/
void gnufile(int step, FILE *fp, char *fname) {
void gnufile(int step, FILE *fp, char *fname, bool test_script) {
char xy1, xy2;
char mytime[30] = {0};
int col;
......@@ -330,6 +330,7 @@ void gnufile(int step, FILE *fp, char *fname) {
strcat(plotname, " : ");
strcpy(title, plotname);
if(test_script) fputs("set term unknown\n", fp);
fputs("splot\\\n", fp);
if (inter.beam.set && inter.beam.swap) {
......@@ -341,6 +342,7 @@ void gnufile(int step, FILE *fp, char *fname) {
}
} // ... but newer gnuplot versions allow to plot multiple surfaces at once
else {
if(test_script) fputs("set term unknown\n", fp);
fputs("splot", fp);
first = 1;
col = 3;
......@@ -425,6 +427,7 @@ void gnufile(int step, FILE *fp, char *fname) {
}
} else {
// ordinary 2D plots
if(test_script) fputs("set term unknown\n", fp);
fputs("plot", fp);
first = 1;
col = 2;
......@@ -522,6 +525,7 @@ void gnufile(int step, FILE *fp, char *fname) {
if (gp->output_is_file) {
fprintf(fp, "set output \"%s\"\n", inter.gnutermfn[k]);
}
if(test_script) fputs("set term unknown\n", fp);
fputs("replot\n", fp);
if (inter.debug & 256) {
......
......@@ -31,7 +31,7 @@
#define KAT_GNU_H
char *otypename(int i);
void gnufile(int step, FILE *fp, char *fname);
void gnufile(int step, FILE *fp, char *fname, bool test_file);
void matlabfile(FILE *fp, char *fname);
void pythonfile(FILE *fp, char *fname);
void python_file_outputs(FILE *fp);
......
......@@ -2001,10 +2001,14 @@ void _debug_msg(const char *function_name, const char *message_string, ...) {
*/
void my_finish(int return_value) {
#ifndef TEST
fflush(stdout);
fflush(stderr);
remove(vglobal.gnuplot_test_fname);
exit(return_value);
// close the log file nicely
if (fp_log != NULL) {
fclose(fp_log);
......
......@@ -20,4 +20,3 @@ pd pow n4
xaxis m2 phi lin -40 40 200
gnuterm x11
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment