diff --git a/ad4_shared/constants.h b/ad4_shared/constants.h index 50eeb52..dff321d 100644 --- a/ad4_shared/constants.h +++ b/ad4_shared/constants.h @@ -233,9 +233,9 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #define LOGETABLES 7 #define LOGNBINTE 8 // analysis.cc nonbond internal energy table #define LOGNBINTEV 9 // analysis.cc;nbe.cc nonbond internal energy table verbose -const struct { +static const struct { int value; - char *key; + const char *key; } outlev_lookup[] = { {LOGMIN, "min"}, {LOGMINCLUST, "mincluster"}, diff --git a/ad4_shared/openfile.h b/ad4_shared/openfile.h index 92ff938..ed901cb 100644 --- a/ad4_shared/openfile.h +++ b/ad4_shared/openfile.h @@ -47,6 +47,6 @@ int openFile( const char *const filename, const Boole mayExit, FILE *logFile); -FILE *ad_fopen(const char *const path, const char *const mode, FILE *logFile); +FILE *ad_fopen(const char *path, const char *mode, FILE *logFile); #endif diff --git a/ad4_shared/paramdat2h.csh b/ad4_shared/paramdat2h.csh deleted file mode 100644 index d84e4ca..0000000 --- a/ad4_shared/paramdat2h.csh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/csh -f -# -# $Id: paramdat2h.csh,v 1.10 2011/03/08 04:18:37 mp Exp $ -# -# AutoDock -# -# Copyright (C) 1989-2007, Garrett M. Morris, David S. Goodsell, Ruth Huey, Arthur J. Olson, -# All Rights Reserved. -# -# AutoDock is a Trade Mark of The Scripps Research Institute. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -echo 'const char *param_string_4_0[MAX_LINES] = {' -egrep -v '^#|^$' $1 | sed 's/\(.*\)$/"\1\\n", /' -echo ' };' -echo 'const char *param_string_4_1[MAX_LINES] = {' -egrep -v '^#|^$' $2 | sed 's/\(.*\)$/"\1\\n", /' -echo ' };' -echo '// EOF' diff --git a/ad4_shared/paramdat2h.py b/ad4_shared/paramdat2h.py new file mode 100644 index 0000000..e3f6b7a --- /dev/null +++ b/ad4_shared/paramdat2h.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import sys + +if len(sys.argv) != 3: + print("Usage: python paramdat2h.py AD4_parameters.dat AD4.1_bound.dat", file=sys.stderr) + sys.exit(1) + +def format_param_file(filename, array_name): + print(f'const char *{array_name}[MAX_LINES] = {{') + with open(filename, 'r') as f: + for line in f: + line = line.strip() + if line and not line.startswith('#'): + print(f'"{line}\\n", ') + print('};') + +format_param_file(sys.argv[1], 'param_string_4_0') +format_param_file(sys.argv[2], 'param_string_4_1') +print('// EOF') diff --git a/ad4_shared/parse_param_line.cc b/ad4_shared/parse_param_line.cc index 3487d38..903be6e 100644 --- a/ad4_shared/parse_param_line.cc +++ b/ad4_shared/parse_param_line.cc @@ -33,6 +33,10 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include #include "parse_param_line.h" +#ifdef _WIN32 +#include "win_compat.h" +#endif + #ifdef DEBUG extern int debug; extern FILE *logFile; // DEBUG only diff --git a/ad4_shared/printdate.cc b/ad4_shared/printdate.cc index 554497c..1008742 100644 --- a/ad4_shared/printdate.cc +++ b/ad4_shared/printdate.cc @@ -28,7 +28,11 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include #include +#ifdef _WIN32 +#include "win_compat.h" +#else #include +#endif #ifdef HAVE_CONFIG_H # include @@ -37,7 +41,7 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include "printdate.h" // this source file is shared by AutoDock and AutoGrid -void printdate( FILE *const fp, const int flag ) +void printdate(FILE *fp, int flag) { time_t tn; /* tn = "time_now" */ char *StringTimeDate; diff --git a/ad4_shared/printdate.h b/ad4_shared/printdate.h index ace6ff2..91734ac 100644 --- a/ad4_shared/printdate.h +++ b/ad4_shared/printdate.h @@ -32,5 +32,5 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include "autocomm.h" -void printdate( FILE *const fp, const int flag ); +void printdate(FILE *fp, int flag); #endif diff --git a/ad4_shared/read_parameter_library.cc b/ad4_shared/read_parameter_library.cc index 60acdb7..1592417 100644 --- a/ad4_shared/read_parameter_library.cc +++ b/ad4_shared/read_parameter_library.cc @@ -47,6 +47,7 @@ static Boole string_ends_with(const char *const a, const char *const b); static char parameter_library[MAX_CHARS]; +extern "C" { void read_parameter_library( FILE *logFile, const int outlev, @@ -199,9 +200,10 @@ void read_parameter_library( } // while there is another line of parameters to read in } -void setup_parameter_library( FILE *logFile, const int outlev, - const char *const model_text, const Unbound_Model unbound_model, - Linear_FE_Model *AD4) + +void setup_parameter_library(FILE *logFile, int outlev, + const char *model_text, Unbound_Model unbound_model, + Linear_FE_Model *AD4) { static ParameterEntry thisParameter; char parameter_library_line[LINE_LEN]; @@ -382,6 +384,8 @@ void setup_parameter_library( FILE *logFile, const int outlev, } // while there is another line of parameters to read in } +} // extern "C" + const char * report_parameter_library() { return parameter_library; } diff --git a/ad4_shared/read_parameter_library.h b/ad4_shared/read_parameter_library.h index 181127e..f4a4dcf 100644 --- a/ad4_shared/read_parameter_library.h +++ b/ad4_shared/read_parameter_library.h @@ -29,28 +29,35 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include "autocomm.h" +#ifdef __cplusplus +extern "C" { +#endif + void read_parameter_library( - FILE *logFile, - const int outlev, - const char *const FN_parameter_library, - Linear_FE_Model *AD4 - ); + FILE *logFile, + int outlev, + const char *FN_parameter_library, + Linear_FE_Model *AD4 +); void setup_parameter_library( - FILE *logFile, - const int outlev, - const char * model_text, - const Unbound_Model unbound_model, - Linear_FE_Model *AD4 - ); - -// The returned string is not supposed to be changed -const char * report_parameter_library(); - -void setup_distdepdiel( FILE *logFile, - const int outlev, - EnergyTables *const ptr_ad_energy_tables // Holds vdw+Hb, desolvation & dielectric lookup tables - ); - - + FILE *logFile, + int outlev, + const char *model_text, + Unbound_Model unbound_model, + Linear_FE_Model *AD4 +); + +const char *report_parameter_library(); + +void setup_distdepdiel( + FILE *logFile, + int outlev, + EnergyTables *ptr_ad_energy_tables // Holds vdw+Hb, desolvation & dielectric lookup tables +); + +#ifdef __cplusplus +} #endif + +#endif /* _READ_PARAMETER_LIBRARY */ diff --git a/ad4_shared/targetfile.cc b/ad4_shared/targetfile.cc index 8ae929a..652f6cb 100644 --- a/ad4_shared/targetfile.cc +++ b/ad4_shared/targetfile.cc @@ -31,7 +31,11 @@ static const char* const ident[] = {ident[1], "@(#)$Id: targetfile.cc,v 1.1 2020 #include // for fgets() #include // for isspace() #include +#ifdef _WIN32 +#include "win_compat.h" +#else #include // for mkstemps() +#endif #include "autocomm.h" #include "parse_dpf_line.h" #include "dpftoken.h" diff --git a/ad4_shared/threadlog.cc b/ad4_shared/threadlog.cc index 29f1180..f744859 100644 --- a/ad4_shared/threadlog.cc +++ b/ad4_shared/threadlog.cc @@ -36,7 +36,11 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. /* include stdlib.h for "free" and unistd.h for "unlink" */ /* tempnam is in */ #include +#ifdef _WIN32 +#include "win_compat.h" +#else #include +#endif static char **tfilename /*[max_threads]*/; static FILE **tfileptr /*[max_threads]*/; diff --git a/ad4_shared/timesys.cc b/ad4_shared/timesys.cc index 9bd6012..5572d1a 100644 --- a/ad4_shared/timesys.cc +++ b/ad4_shared/timesys.cc @@ -24,7 +24,11 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. */ +#ifdef _WIN32 +#include "win_compat.h" +#else #include +#endif #ifdef HAVE_CONFIG_H # include diff --git a/ad4_shared/timesys.h b/ad4_shared/timesys.h index 6a468fd..9da9b6b 100644 --- a/ad4_shared/timesys.h +++ b/ad4_shared/timesys.h @@ -35,7 +35,7 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include #else #ifdef _WIN32 -#include "mingw_sys_times.h" +#include "win_compat.h" #else #include #endif diff --git a/ad4_shared/timesyshms.cc b/ad4_shared/timesyshms.cc index 688590c..14cf4b2 100644 --- a/ad4_shared/timesyshms.cc +++ b/ad4_shared/timesyshms.cc @@ -31,7 +31,11 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include #include +#ifdef _WIN32 +#include "win_compat.h" +#else #include +#endif #include "timesyshms.h" diff --git a/ad4_shared/timesyshms.h b/ad4_shared/timesyshms.h index 14a1634..7c93e53 100644 --- a/ad4_shared/timesyshms.h +++ b/ad4_shared/timesyshms.h @@ -34,7 +34,7 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include #else #ifdef _WIN32 -#include "mingw_sys_times.h" +#include "win_compat.h" #else #include #endif diff --git a/ad4_shared/win_compat.cc b/ad4_shared/win_compat.cc new file mode 100644 index 0000000..9f468cf --- /dev/null +++ b/ad4_shared/win_compat.cc @@ -0,0 +1,49 @@ +#include +#include +#include +#include "win_compat.h" + +#ifndef CLOCKS_PER_SEC +#define CLOCKS_PER_SEC 1000 +#endif + +clock_t times(struct tms* buffer) { + FILETIME createTime, exitTime, kernelTime, userTime; + if (GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &kernelTime, &userTime)) { + ULARGE_INTEGER u, k; + k.LowPart = kernelTime.dwLowDateTime; + k.HighPart = kernelTime.dwHighDateTime; + u.LowPart = userTime.dwLowDateTime; + u.HighPart = userTime.dwHighDateTime; + buffer->tms_utime = (clock_t)(u.QuadPart / 10000 / (1000 / CLOCKS_PER_SEC)); + buffer->tms_stime = (clock_t)(k.QuadPart / 10000 / (1000 / CLOCKS_PER_SEC)); + buffer->tms_cutime = 0; + buffer->tms_cstime = 0; + } else { + memset(buffer, 0, sizeof(*buffer)); + } + return clock(); +} + +int gettimeofday(struct timeval* tp, void*) { + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + unsigned __int64 t = ((unsigned __int64)ft.dwHighDateTime << 32) + ft.dwLowDateTime; + t -= 116444736000000000ULL; + tp->tv_sec = (long)(t / 10000000ULL); + tp->tv_usec = (long)((t % 10000000ULL) / 10); + return 0; +} + +int gethostname(char* name, size_t len) { + DWORD dlen = static_cast(len); + return GetComputerNameA(name, &dlen) ? 0 : -1; +} + +long sysconf(int name) { + if (name == _SC_CLK_TCK) { + return CLOCKS_PER_SEC; + } else { + return -1L; + } +} diff --git a/ad4_shared/win_compat.h b/ad4_shared/win_compat.h new file mode 100644 index 0000000..13e83d8 --- /dev/null +++ b/ad4_shared/win_compat.h @@ -0,0 +1,48 @@ +#ifdef _WIN32 +#ifndef WIN_COMPAT_H +#define WIN_COMPAT_H + +#include +#include +#include +#include +#include +#include + +// Portable function aliases +#define strcasecmp _stricmp +#define strdup _strdup +#define strncasecmp _strnicmp +#define getcwd _getcwd +#define chdir _chdir +#define access _access +#define unlink _unlink +#define isatty _isatty +#define fileno _fileno + +#ifndef bzero +#define bzero(ptr, size) memset((ptr), 0, (size)) +#endif + +#ifndef HAVE_STRUCT_TMS +#define HAVE_STRUCT_TMS +struct tms { + clock_t tms_utime; + clock_t tms_stime; + clock_t tms_cutime; + clock_t tms_cstime; +}; +#endif + +// Declarations only – definitions go in win_compat.cc +clock_t times(struct tms* buffer); +int gettimeofday(struct timeval* tp, void*); +int gethostname(char* name, size_t len); +long sysconf(int name); + +#ifndef _SC_CLK_TCK +#define _SC_CLK_TCK 3 +#endif + +#endif // WIN_COMPAT_H +#endif // _WIN32 \ No newline at end of file diff --git a/autogrid.h b/autogrid.h index 5c96c4f..3f2e693 100644 --- a/autogrid.h +++ b/autogrid.h @@ -113,7 +113,7 @@ FILE *ad_fopen(const char *path, const char *mode, FILE *logFile); #define INFORMATION 1 #define SUGGESTION 2 -void print_error( FILE *fileptr, int error_level, char *message); +void print_error( FILE *fileptr, int error_level, const char *message); /*----------------------------------------------------------------------------*/ /* EOF. */ diff --git a/banner.cpp b/banner.cpp index 2b1a8b1..fe3090e 100644 --- a/banner.cpp +++ b/banner.cpp @@ -28,7 +28,7 @@ #include #include "autogrid.h" -void banner( char * version_num, FILE *logFile) +void banner(const char *version_num, FILE *logFile) { diff --git a/gpfparser.cpp b/gpfparser.cpp index db88f1e..02d155b 100644 --- a/gpfparser.cpp +++ b/gpfparser.cpp @@ -31,6 +31,10 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include "autogrid.h" #include "constants.h" +#ifdef _WIN32 +#include "win_compat.h" +#endif + int gpfparser( char line[LINE_LEN] ) /******************************************************************************/ diff --git a/main.cpp b/main.cpp index fefd279..5f1aec5 100644 --- a/main.cpp +++ b/main.cpp @@ -23,14 +23,18 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +#ifdef _WIN32 +#include "win_compat.h" +#else #include #include /* long sysconf(int name) */ +#include // for bzero() on Solaris +#endif + #include #include /* tolower,isascii,isdigit */ #ifdef NOTNEEDED #ifdef _WIN32 -#include #include "util.h" #endif #endif @@ -40,12 +44,12 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. #include #include #include -#include // for bzero() on Solaris +#include #include #include #ifndef HAVE_SYSCONF #ifdef _WIN32 -#include "mingw_sysconf.h" // for sysconf(_SC_CLK_TCK) and possibly gethostname +// #include "mingw_sysconf.h" // for sysconf(_SC_CLK_TCK) and possibly gethostname #endif #endif @@ -130,12 +134,12 @@ static double vect_normalize ( double v1[XYZ] ); // print_error() is used with error_level where // error_level is defined in autogrid.h -void print_error( FILE *logFile, int error_level, char *message) +void print_error(FILE *logFile, int error_level, const char *message) // print an error or informational message to a file-pointer or // standard error { char output_message[LINE_LEN]; - char *tag; + const char *tag; switch ( error_level ) { case FATAL_ERROR: @@ -364,7 +368,7 @@ static double solpar[AG_MAX_ATOMS]; static int atom_type[AG_MAX_ATOMS]; static hbond_type hbond[AG_MAX_ATOMS]; static bool disorder[AG_MAX_ATOMS]; -static char * hbtname[] = { "D0", "DS", "D1", "AS", "A1", "A2", "AD", "??" }; /* for table printouts only */ +static const char * hbtname[] = { "D0", "DS", "D1", "AS", "A1", "A2", "AD", "??" }; /* for table printouts only */ // two arrays added 2018-11 for tracking h-bond donor/acceptor neighborhoods // TODO MP make these dynamic and allocated only if disorder_h flag is true @@ -553,7 +557,7 @@ double covbarrier = 1000.0; const double ln_half = log(0.5); #ifndef PACKAGE_VERSION -static char * version_num = "4.2.7.x"; +static const char * version_num = "4.2.7.x"; #else static char * version_num = PACKAGE_VERSION; #endif @@ -2682,7 +2686,7 @@ if (outlev>LOGRUNV) { * Designed 2018-11 by Stefano Forli, coded by MPique */ if (disorder_h) { - int hcountstat[num_receptor_atoms]; /* for disorder table printing only */ + std::vector hcountstat(num_receptor_atoms); fprintf(logFile, "\nSetting list of disordered atom groups.\n"); for (int ia=0; ia #include "autogrid.h" #include "constants.h" +#ifdef _WIN32 +#include "win_compat.h" +#else #include +#endif #include // POSIX definitions of EXIT_SUCCESS and EXIT_FAILURE extern FILE *GPF; @@ -40,7 +44,7 @@ extern int debug; /*----------------------------------------------------------------------------*/ -int setflags( int argc, char **argv, char *version, int use_bhtree, int use_omp, int maxthreads, FILE **logFile /* may be modified here */ ) +int setflags(int argc, char **argv, const char *version, int use_bhtree, int use_omp, int maxthreads, FILE **logFile) /*----------------------------------------------------------------------------*/ diff --git a/strindex.cpp b/strindex.cpp index c055eff..c104e40 100644 --- a/strindex.cpp +++ b/strindex.cpp @@ -28,7 +28,7 @@ Copyright (C) 2009 The Scripps Research Institute. All rights reserved. /*----------------------------------------------------------------------------*/ -int strindex( char s[], char t[]) +int strindex( const char s[], const char t[]) /*----------------------------------------------------------------------------*/