diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index add21ab83..478669a89 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -7,36 +7,36 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: -# build-and-push-image: -# runs-on: ubuntu-latest -# permissions: -# contents: read -# packages: write -# -# steps: -# - name: Checkout repository -# uses: actions/checkout@v3 -# -# - name: Log in to the Container registry -# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 -# with: -# registry: ${{ env.REGISTRY }} -# username: ${{ github.actor }} -# password: ${{ secrets.GITHUB_TOKEN }} -# -# - name: Extract metadata (tags, labels) for Docker -# id: meta -# uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 -# with: -# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} -# -# - name: Build and push Docker image -# uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc -# with: -# context: . -# push: true -# tags: ${{ steps.meta.outputs.tags }} -# labels: ${{ steps.meta.outputs.labels }} + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} native-build: name: @@ -44,16 +44,17 @@ jobs: strategy: fail-fast: false matrix: - # platform: [macos-latest, windows-latest, ubuntu-18.04] - platform: [macos-latest] + platform: [macos-13, windows-latest, ubuntu-latest, macos-14] + + runs-on: ${{ matrix.platform }} steps: - name: checkout vcell-solvers repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Install MacOS dependencies - if: matrix.platform == 'macos-latest' + - name: Install Intel MacOS dependencies + if: matrix.platform == 'macos-13' shell: bash run: | brew install boost @@ -62,7 +63,25 @@ jobs: brew install llvm echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/runner/.bash_profile - ln -s /usr/local/bin/gfortran-12 /usr/local/bin/gfortran + source /Users/runner/.bash_profile + + gcc --version + gfortran --version + cmake --version + brew info boost + brew info hdf5 + + - name: Install ARM MacOS dependencies + if: matrix.platform == 'macos-14' + shell: bash + run: | + brew install boost + brew install hdf5 + brew install ninja + + brew install llvm + echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> /Users/runner/.bash_profile + ln -s /opt/homebrew/bin/gfortran-14 /usr/local/bin/gfortran gcc --version gfortran --version @@ -70,8 +89,39 @@ jobs: brew info boost brew info hdf5 - - name: Build Macos - if: matrix.platform == 'macos-latest' + - name: Build Macos ARM + if: matrix.platform == 'macos-14' + run: | + platform=macos + echo "working dir is $PWD" + + mkdir build + cd build + + export PATH="/opt/homebrew/opt/llvm/bin:$PATH" + + cmake \ + -G Ninja \ + -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \ + -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ \ + -DOPTION_MINGW=ON \ + -DOPTION_TARGET_MESSAGING=OFF \ + -DOPTION_TARGET_PARALLEL=OFF \ + -DOPTION_TARGET_CHOMBO2D_SOLVER=OFF \ + -DOPTION_TARGET_CHOMBO3D_SOLVER=OFF \ + -DOPTION_TARGET_SMOLDYN_SOLVER=ON \ + -DOPTION_TARGET_FV_SOLVER=ON \ + -DOPTION_TARGET_STOCHASTIC_SOLVER=ON \ + -DOPTION_TARGET_NFSIM_SOLVER=ON \ + -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=ON \ + -DOPTION_TARGET_SUNDIALS_SOLVER=ON \ + -DOPTION_TARGET_HY3S_SOLVERS=OFF \ + -B . -S .. + + ninja + + - name: Build Macos Intel + if: matrix.platform == 'macos-13' run: | platform=macos echo "working dir is $PWD" @@ -85,6 +135,7 @@ jobs: -G Ninja \ -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang \ -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ \ + -DOPTION_MINGW=ON \ -DOPTION_TARGET_MESSAGING=OFF \ -DOPTION_TARGET_PARALLEL=OFF \ -DOPTION_TARGET_CHOMBO2D_SOLVER=OFF \ @@ -93,7 +144,7 @@ jobs: -DOPTION_TARGET_FV_SOLVER=ON \ -DOPTION_TARGET_STOCHASTIC_SOLVER=ON \ -DOPTION_TARGET_NFSIM_SOLVER=ON \ - -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=OFF \ + -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=ON \ -DOPTION_TARGET_SUNDIALS_SOLVER=ON \ -DOPTION_TARGET_HY3S_SOLVERS=OFF \ -B . -S .. @@ -101,7 +152,7 @@ jobs: ninja - name: Test Macos - if: matrix.platform == 'macos-latest' + if: matrix.platform == 'macos-13' || matrix.platform == 'macos-14' run: | platform=macos echo "working dir is $PWD" @@ -126,150 +177,165 @@ jobs: echo "------ running ziptool ------" ./bin/ziptool || true +# - name: Setup tmate session +# uses: mxschmitt/action-tmate@v3 +# with: +# limit-access-to-actor: false + + + - name: Install Windows Dependencies + if: matrix.platform == 'windows-latest' + uses: msys2/setup-msys2@v2 + with: + msystem: CLANG64 + update: true + install: > + zip + git + mingw-w64-clang-x86_64-curl + mingw-w64-clang-x86_64-toolchain + mingw-w64-clang-x86_64-flang + mingw-w64-clang-x86_64-cmake + mingw-w64-clang-x86_64-boost + mingw-w64-clang-x86_64-hdf5 + mingw-w64-clang-x86_64-libzip + mingw-w64-clang-x86_64-netcdf + mingw-w64-clang-x86_64-zlib + mingw-w64-clang-x86_64-libaec -# - name: Install Windows Dependencies -# if: matrix.platform == 'windows-latest' -# uses: msys2/setup-msys2@v2 +# - name: Setup tmate session +# uses: mxschmitt/action-tmate@v3 # with: -# msystem: CLANG64 -# update: true -# install: > -# git -# mingw-w64-clang-x86_64-toolchain -# mingw-w64-clang-x86_64-flang -# mingw-w64-clang-x86_64-cmake -# mingw-w64-clang-x86_64-boost -# mingw-w64-clang-x86_64-hdf5 -# mingw-w64-clang-x86_64-libzip -# mingw-w64-clang-x86_64-netcdf -# -# - name: Build Windows -# if: matrix.platform == 'windows-latest' -# shell: msys2 {0} -# run: | -# platform=windows -# echo "working dir is $PWD" -# -# mkdir build -# cd build -# -# PATH="/c/Program Files/LLVM/bin:$PATH" -# -# cmake \ -# -G Ninja \ -# -DCMAKE_C_COMPILER=clang \ -# -DCMAKE_CXX_COMPILER=clang++ \ -# -DOPTION_TARGET_MESSAGING=OFF \ -# -DOPTION_TARGET_PARALLEL=OFF \ -# -DOPTION_TARGET_CHOMBO2D_SOLVER=OFF \ -# -DOPTION_TARGET_CHOMBO3D_SOLVER=OFF \ -# -DOPTION_TARGET_SMOLDYN_SOLVER=ON \ -# -DOPTION_TARGET_FV_SOLVER=ON \ -# -DOPTION_TARGET_STOCHASTIC_SOLVER=ON \ -# -DOPTION_TARGET_NFSIM_SOLVER=ON \ -# -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=OFF \ -# -DOPTION_TARGET_SUNDIALS_SOLVER=ON \ -# -DOPTION_TARGET_HY3S_SOLVERS=OFF \ -# -B . -S .. -# -# ninja -j 1 -# -# - name: Test Windows -# if: matrix.platform == 'windows-latest' -# shell: msys2 {0} -# run: | -# platform=windows -# echo "working dir is $PWD" -# -# cd build -# -# ctest -VV -# -# echo "------ running FiniteVolume_x64 ------" -# ./bin/FiniteVolume_x64 || true -# echo -# echo "------ running NFsim_x64 ------" -# ./bin/NFsim_x64 || true -# echo "------ running SundialsSolverStandalone_x64 ------" -# ./bin/SundialsSolverStandalone_x64 || true -# echo "------ running VCellStoch_x64 ------" -# ./bin/VCellStoch_x64 || true -# echo "------ running smoldyn_x64 ------" -# ./bin/smoldyn_x64 || true -# echo "------ running testzip ------" -# ./bin/testzip || true -# echo "------ running ziptool ------" -# ./bin/ziptool || true - -# - name: Install Linux Dependencies -# if: matrix.platform == 'ubuntu-18.04' -# run: | -# sudo apt-get update -# sudo apt-get install -y libboost-all-dev -# sudo apt-get install -y libhdf5-dev -# sudo apt-get install -y ninja-build -# -# gcc --version -# gfortran --version -# cmake --version -# dpkg -s libboost-all-dev -# dpkg -s libhdf5-dev -# -# - name: Build Linux -# if: matrix.platform == 'ubuntu-18.04' -# run: | -# platform=linux -# echo "working dir is $PWD" -# -# mkdir build -# cd build -# -# cmake \ -# -G Ninja \ -# -DOPTION_TARGET_MESSAGING=OFF \ -# -DOPTION_TARGET_PARALLEL=OFF \ -# -DOPTION_TARGET_CHOMBO2D_SOLVER=OFF \ -# -DOPTION_TARGET_CHOMBO3D_SOLVER=OFF \ -# -DOPTION_TARGET_SMOLDYN_SOLVER=ON \ -# -DOPTION_TARGET_FV_SOLVER=ON \ -# -DOPTION_TARGET_STOCHASTIC_SOLVER=ON \ -# -DOPTION_TARGET_NFSIM_SOLVER=ON \ -# -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=OFF \ -# -DOPTION_TARGET_SUNDIALS_SOLVER=ON \ -# -DOPTION_TARGET_HY3S_SOLVERS=OFF \ -# -B . -S .. -# -# ninja -# -# - name: Test Linux -# if: matrix.platform == 'ubuntu-18.04' -# run: | -# platform=linux -# echo "working dir is $PWD" -# -# cd build -# -# ctest -VV -# -# echo "------ running FiniteVolume_x64 ------" -# ./bin/FiniteVolume_x64 || true -# echo -# echo "------ running NFsim_x64 ------" -# ./bin/NFsim_x64 || true -# echo "------ running SundialsSolverStandalone_x64 ------" -# ./bin/SundialsSolverStandalone_x64 || true -# echo "------ running VCellStoch_x64 ------" -# ./bin/VCellStoch_x64 || true -# echo "------ running smoldyn_x64 ------" -# ./bin/smoldyn_x64 || true -# echo "------ running testzip ------" -# ./bin/testzip || true -# echo "------ running ziptool ------" -# ./bin/ziptool || true -# +# limit-access-to-actor: false + + - name: Build Windows + if: matrix.platform == 'windows-latest' + shell: msys2 {0} + run: | + platform=windows + echo "working dir is $PWD" + + mkdir build + cd build + + PATH="/c/Program\ Files/LLVM/bin:$PATH" + + cmake \ + -G Ninja \ + -DCMAKE_C_COMPILER="clang.exe" \ + -DCMAKE_CXX_COMPILER="clang++.exe" \ + -DOPTION_TARGET_MESSAGING=OFF \ + -DOPTION_TARGET_PARALLEL=OFF \ + -DOPTION_TARGET_CHOMBO2D_SOLVER=OFF \ + -DOPTION_TARGET_CHOMBO3D_SOLVER=OFF \ + -DOPTION_TARGET_SMOLDYN_SOLVER=ON \ + -DOPTION_TARGET_FV_SOLVER=ON \ + -DOPTION_TARGET_STOCHASTIC_SOLVER=ON \ + -DOPTION_TARGET_NFSIM_SOLVER=ON \ + -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=OFF \ + -DOPTION_TARGET_SUNDIALS_SOLVER=ON \ + -DOPTION_TARGET_HY3S_SOLVERS=OFF \ + -DOPTION_TARGET_DOCS=OFF \ + -B . -S .. + + ninja -j 1 + + - name: Test Windows + if: matrix.platform == 'windows-latest' + shell: msys2 {0} + run: | + platform=windows + echo "working dir is $PWD" + + cd build + + ctest -VV + + echo "------ running FiniteVolume_x64 ------" + ./bin/FiniteVolume_x64 || true + echo + echo "------ running NFsim_x64 ------" + ./bin/NFsim_x64 || true + echo "------ running SundialsSolverStandalone_x64 ------" + ./bin/SundialsSolverStandalone_x64 || true + echo "------ running VCellStoch_x64 ------" + ./bin/VCellStoch_x64 || true + echo "------ running smoldyn_x64 ------" + ./bin/smoldyn_x64 || true + echo "------ running testzip ------" + ./bin/testzip || true + echo "------ running ziptool ------" + ./bin/ziptool || true + + - name: Install Linux Dependencies + if: matrix.platform == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -y libboost-all-dev + sudo apt-get install -y libhdf5-dev + sudo apt-get install -y ninja-build + + gcc --version + gfortran --version + cmake --version + dpkg -s libboost-all-dev + dpkg -s libhdf5-dev + + - name: Build Linux + if: matrix.platform == 'ubuntu-latest' + run: | + platform=linux + echo "working dir is $PWD" + + mkdir build + cd build + + cmake \ + -G Ninja \ + -DOPTION_TARGET_MESSAGING=OFF \ + -DOPTION_TARGET_PARALLEL=OFF \ + -DOPTION_TARGET_CHOMBO2D_SOLVER=OFF \ + -DOPTION_TARGET_CHOMBO3D_SOLVER=OFF \ + -DOPTION_TARGET_SMOLDYN_SOLVER=ON \ + -DOPTION_TARGET_FV_SOLVER=ON \ + -DOPTION_TARGET_STOCHASTIC_SOLVER=ON \ + -DOPTION_TARGET_NFSIM_SOLVER=ON \ + -DOPTION_TARGET_MOVINGBOUNDARY_SOLVER=ON \ + -DOPTION_TARGET_SUNDIALS_SOLVER=ON \ + -DOPTION_TARGET_HY3S_SOLVERS=OFF \ + -B . -S .. + + ninja + + - name: Test Linux + if: matrix.platform == 'ubuntu-latest' + run: | + platform=linux + echo "working dir is $PWD" + + cd build + + ctest -VV + + echo "------ running FiniteVolume_x64 ------" + ./bin/FiniteVolume_x64 || true + echo + echo "------ running NFsim_x64 ------" + ./bin/NFsim_x64 || true + echo "------ running SundialsSolverStandalone_x64 ------" + ./bin/SundialsSolverStandalone_x64 || true + echo "------ running VCellStoch_x64 ------" + ./bin/VCellStoch_x64 || true + echo "------ running smoldyn_x64 ------" + ./bin/smoldyn_x64 || true + echo "------ running testzip ------" + ./bin/testzip || true + echo "------ running ziptool ------" + ./bin/ziptool || true + - name: fix Macos shared object paths - if: matrix.platform == 'macos-latest' + if: matrix.platform == 'macos-13' || matrix.platform == 'macos-14' shell: bash run: | mkdir build/upload @@ -283,49 +349,59 @@ jobs: ../../.github/scripts/install_name_tool_macos.sh tar czvf ../upload/mac64.tgz --dereference . -# - name: handle shared object paths for Windows native build -# if: matrix.platform == 'windows-latest' -# shell: msys2 {0} -# run: | -# cd build/bin -# ls *_x64 | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true -# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true -# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true -# chmod u+w,+x * -# tar czvf ../linux64.tgz --dereference . -# cd ../.. -# fi -# -# - name: handle shared object paths for Linux native build -# if: matrix.platform == 'ubuntu-18.04' -# shell: bash -# run: | -# cd build/bin -# ls *_x64 | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true -# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true -# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true -# chmod u+w,+x * -# tar czvf ../linux64.tgz --dereference . -# cd ../.. -# fi -# - - name: Upload Macos binaries - if: matrix.platform == 'macos-latest' - uses: actions/upload-artifact@v3 + - name: handle shared object paths for Windows native build + if: matrix.platform == 'windows-latest' + shell: msys2 {0} + run: | + mkdir build/upload + cd build/bin + rm hello_test TestVCellStoch testzip ziptool || true + ls *.exe | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep '=> /' | grep -v build | grep -iv windows | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true + ls *.dll | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep '=> /' | grep -v build | grep -iv windows | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true + ls *.dll | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep '=> /' | grep -v build | grep -iv windows | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true + chmod u+w,+x * + zip ../upload/win64.zip ./* + cd ../.. + # fi + + - name: handle shared object paths for Linux native build + if: matrix.platform == 'ubuntu-latest' + shell: bash + run: | + mkdir build/upload + cd build/bin + rm hello_test TestVCellStoch testzip ziptool || true + ls *_x64 | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true + ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true + ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true + chmod u+w,+x * + tar czvf ../upload/linux64.tgz --dereference . + cd ../.. + + - name: Upload Intel Macos binaries + if: matrix.platform == 'macos-13' + uses: actions/upload-artifact@v4 + with: + name: macos_x86_64.tgz + path: build/upload/mac64.tgz + + - name: Upload ARM Macos binaries + if: matrix.platform == 'macos-14' + uses: actions/upload-artifact@v4 with: - name: mac64.tgz + name: macos_arm64.tgz path: build/upload/mac64.tgz - name: Upload Windows binaries if: matrix.platform == 'windows-latest' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: win64.tgz - path: build/upload/win64.tgz + name: win64.zip + path: build/upload/win64.zip - name: Upload Linux binaries - if: matrix.platform == 'ubuntu-18.04' - uses: actions/upload-artifact@v3 + if: matrix.platform == 'ubuntu-latest' + uses: actions/upload-artifact@v4 with: name: linux64.tgz path: build/upload/linux64.tgz diff --git a/.gitignore b/.gitignore index b48515a9f..2c0fede2f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ /build-dockcross-win64/ /.project /.cproject -/svnversion.txt /build-win64/ /.DS_Store /build-linux64/ @@ -14,6 +13,7 @@ /singularity/ /cmake-build* /build* +/debug-build* /.idea/ /nfsim/ /all_solvers/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 35b77a97c..22c78cfb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,17 @@ # ############################################## if (APPLE) - set(CMAKE_OSX_ARCHITECTURES "x86_64") + execute_process(COMMAND uname -m OUTPUT_VARIABLE PROCESSOR_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) + message("Processor Architecture: ${PROCESSOR_ARCHITECTURE}") + if (PROCESSOR_ARCHITECTURE STREQUAL "arm64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__arm64__") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__arm64__") + set(CMAKE_OSX_ARCHITECTURES "arm64") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__x86_64__") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__x86_64__") + set(CMAKE_OSX_ARCHITECTURES "x86_64") + endif() # set(CMAKE_Fortran_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=10.7" CACHE PATH "") # set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7" CACHE PATH "") ############################################# @@ -31,7 +41,7 @@ elseif (LINUX) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64") set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -m64") - endif() + endif() endif() cmake_minimum_required(VERSION 3.13) @@ -45,10 +55,6 @@ if(POLICY CMP0057) cmake_policy(SET CMP0057 NEW) endif() -set(SVERSION "unversionedbuild") -message("svnversion ${SVERSION}") -add_definitions(-DSVNVERSION=svn${SVERSION}) - #include (LocalJNI.cmake) set(RULE_MESSAGES OFF) @@ -152,10 +158,8 @@ endif() set(WINDOWS FALSE) if (${CMAKE_SYSTEM_NAME} MATCHES Windows) set(WINDOWS TRUE) -# set(WIN32 TRUE) - if (${CMAKE_GENERATOR} MATCHES "Unix Makefiles") - set(MINGW TRUE) - endif (${CMAKE_GENERATOR} MATCHES "Unix Makefiles") + set(WIN32 TRUE) + set(MINGW TRUE) endif() set (ARCH_64bit FALSE) @@ -240,6 +244,9 @@ if (${OPTION_TARGET_MOVINGBOUNDARY_SOLVER} OR add_subdirectory(hdf5-1.8.11) else() set(HDF5_USE_STATIC_LIBRARIES ON) + if(WINDOWS OR WIN32 OR WIN64) + set(HDF5_USE_STATIC_LIBRARIES OFF) + endif () #CMakeList.txt that comes with hdf5 switches library name if compiled with debug find_package(HDF5 COMPONENTS HL CXX C) set(HDF_VERSION ${HDF5_VERSION}) diff --git a/ExpressionParser/DivideByZeroException.h b/ExpressionParser/DivideByZeroException.h index 66aa0be5d..33bc0f630 100644 --- a/ExpressionParser/DivideByZeroException.h +++ b/ExpressionParser/DivideByZeroException.h @@ -1,5 +1,5 @@ #ifndef DIVIDEBYZEROEXCEPTION_H -#define DIVIDEBYZEROEXCEPTION_CPP +#define DIVIDEBYZEROEXCEPTION_H #include "ExpressionException.h" diff --git a/FronTierLib/front/fgb3d.c b/FronTierLib/front/fgb3d.c index 6c202f05e..2bef685a4 100644 --- a/FronTierLib/front/fgb3d.c +++ b/FronTierLib/front/fgb3d.c @@ -38,6 +38,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include +#ifdef WIN64 +double drand48_windows() +{ + const long NUM_RAND = RAND_MAX+1; + const double RAND_TOTAL_MAX = NUM_RAND*NUM_RAND - 1.0; + long r = (NUM_RAND)*rand()+rand(); + return r / RAND_TOTAL_MAX; +} +#define drand48 drand48_windows +#endif + LOCAL boolean track_comp_and_repair3d(int*,int*,int*,INTERFACE*,Front*); LOCAL boolean repair_intfc3d_in_box(INTERFACE*,int*,int*,Front*); LOCAL boolean set_reconstruction_boxes(int*,int*,int**,int,RECT_BOX**, diff --git a/FronTierLib/front/fprotos.h b/FronTierLib/front/fprotos.h index 50c2e0a92..a4a52409a 100644 --- a/FronTierLib/front/fprotos.h +++ b/FronTierLib/front/fprotos.h @@ -703,6 +703,7 @@ IMPORT void strip_bdry_curves(INTERFACE*, int); IMPORT void cut_surface(SURFACE*,boolean (*func)(POINTER,double*),POINTER,boolean); IMPORT void install_hsbdry_on_surface(SURFACE*,int); IMPORT boolean surfaces_matched(SURFACE*,SURFACE*); +IMPORT void install_subdomain_bdry_curves(INTERFACE*); /* fscat3d2.c*/ IMPORT boolean f_intfc_communication3d2(Front*); @@ -888,6 +889,7 @@ IMPORT void tangent(POINT*,BOND*,CURVE*,double*,Front*); IMPORT void user_print_rp_node(RP_NODE*,RPROBLEM*); IMPORT void user_print_rproblem(RPROBLEM*); IMPORT void user_free_rp_node(RP_NODE*,RPROBLEM*); +IMPORT void assign_curve_boundary_type(CURVE*,int,int*); #if defined(USE_OVERTURE) /* foverture_patch.c */ diff --git a/FronTierLib/intfc/imksurf.c b/FronTierLib/intfc/imksurf.c index f50bdf68d..ca49c0f0c 100644 --- a/FronTierLib/intfc/imksurf.c +++ b/FronTierLib/intfc/imksurf.c @@ -39,6 +39,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include +#include LOCAL void assign_blk_crx(BLK_CRX*,int,int,int,const EG_CRX*,boolean); LOCAL void assign_two_comp_domain(double (*func)(POINTER,double*),POINTER, diff --git a/FronTierLib/util/simpleio.c b/FronTierLib/util/simpleio.c index 368736a08..5470467fc 100644 --- a/FronTierLib/util/simpleio.c +++ b/FronTierLib/util/simpleio.c @@ -64,6 +64,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #ifndef WIN32 #include +#else +#include +#define getpid _getpid #endif static const char *scan_float_fmt = "%lf"; diff --git a/IDAWin/VCellCVodeSolver.cpp b/IDAWin/VCellCVodeSolver.cpp index c174b97b8..ef4832c1c 100644 --- a/IDAWin/VCellCVodeSolver.cpp +++ b/IDAWin/VCellCVodeSolver.cpp @@ -436,7 +436,7 @@ void VCellCVodeSolver::cvodeSolve(bool bPrintProgress, FILE* outputFile, void (* if (outputCount * (NEQ + 1) * bytesPerSample > MaxFileSizeBytes){ /* if more than one gigabyte, then fail */ char msg[100]; - sprintf(msg, "output exceeded maximum %ld bytes", MaxFileSizeBytes); + sprintf(msg, "output exceeded maximum %d bytes", MaxFileSizeBytes); throw VCell::Exception(msg); } writeData(Time, outputFile); diff --git a/MBSolver/CMakeLists.txt b/MBSolver/CMakeLists.txt index 3e2690cd8..174dc4635 100644 --- a/MBSolver/CMakeLists.txt +++ b/MBSolver/CMakeLists.txt @@ -9,6 +9,11 @@ if (SUPPORTS_MATLAB) option(BUILD_INCLUDE_MATLAB_DIRS "Include matlab integration directory" OFF) endif (SUPPORTS_MATLAB) +if (MINGW) + add_definitions(-DMINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMINGW") +endif (MINGW) + if(DEFINED CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") else() diff --git a/MBSolver/Solver/include/CoordVect.h b/MBSolver/Solver/include/CoordVect.h index 3097bda3f..21b63995b 100644 --- a/MBSolver/Solver/include/CoordVect.h +++ b/MBSolver/Solver/include/CoordVect.h @@ -2,6 +2,7 @@ #define _COORDVECT_H_ #include +#include #include #include namespace moving_boundary diff --git a/MBSolver/Solver/include/Distance.h b/MBSolver/Solver/include/Distance.h index 569187d9b..5a8b79dc4 100644 --- a/MBSolver/Solver/include/Distance.h +++ b/MBSolver/Solver/include/Distance.h @@ -1,5 +1,6 @@ #ifndef Distance_h #define Distance_h +#include #include #include #include diff --git a/MBSolver/Solver/include/IndexVect.h b/MBSolver/Solver/include/IndexVect.h index 76b2a73db..66673a0dc 100644 --- a/MBSolver/Solver/include/IndexVect.h +++ b/MBSolver/Solver/include/IndexVect.h @@ -2,6 +2,8 @@ #define _INDEXVECT_H_ #include +#include +#include #include class IndexVect @@ -13,7 +15,7 @@ class IndexVect IndexVect (); IndexVect (int a, int b); IndexVect (const IndexVect& rhs); - IndexVect(std::array p); + explicit IndexVect(std::array p); IndexVect& operator= (const IndexVect& rhs); diff --git a/MBSolver/Solver/include/MBridge/MBPatch.h b/MBSolver/Solver/include/MBridge/MBPatch.h index 6cd2a01ca..4f17acd9a 100644 --- a/MBSolver/Solver/include/MBridge/MBPatch.h +++ b/MBSolver/Solver/include/MBridge/MBPatch.h @@ -1,5 +1,6 @@ #ifndef MBPatch_h #define MBPatch_h +#include #include #include #include diff --git a/MBSolver/Solver/include/MPoint.h b/MBSolver/Solver/include/MPoint.h index e8f3a8a67..1b6ac3158 100644 --- a/MBSolver/Solver/include/MPoint.h +++ b/MBSolver/Solver/include/MPoint.h @@ -1,6 +1,7 @@ #ifndef MPoint_h #define MPoint_h #pragma warning ( disable : 4996) +#include #include #include #include diff --git a/MBSolver/Solver/include/Modulo.h b/MBSolver/Solver/include/Modulo.h index 2c4ef6bcf..266fe2ea3 100644 --- a/MBSolver/Solver/include/Modulo.h +++ b/MBSolver/Solver/include/Modulo.h @@ -1,6 +1,8 @@ #ifndef Modulo_h #define Modulo_h +#include + namespace vcell_util { /** * modulo integer type diff --git a/MBSolver/Solver/include/World.h b/MBSolver/Solver/include/World.h index 1193cc9fe..8374bb1a7 100644 --- a/MBSolver/Solver/include/World.h +++ b/MBSolver/Solver/include/World.h @@ -1,6 +1,7 @@ #ifndef World_h #define World_h #include +#include #include #include #include diff --git a/MBSolver/Solver/include/version.h b/MBSolver/Solver/include/version.h deleted file mode 100644 index 6e5b968e6..000000000 --- a/MBSolver/Solver/include/version.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef version_h -#define version_h -#include -/** -* return string representing SVN version of code -*/ -namespace vcell_util { - struct Version { - const std::string svn; - const std::string compileDate; - const std::string compileTime; - static const Version & get( ); - private: - Version( ); - }; -} -#endif diff --git a/MBSolver/Solver/src/CoordVect.cpp b/MBSolver/Solver/src/CoordVect.cpp index 55382fe56..51d8b2fb8 100644 --- a/MBSolver/Solver/src/CoordVect.cpp +++ b/MBSolver/Solver/src/CoordVect.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/MBSolver/Solver/src/IndexVect.cpp b/MBSolver/Solver/src/IndexVect.cpp index 8f823c44a..39e83cbd3 100644 --- a/MBSolver/Solver/src/IndexVect.cpp +++ b/MBSolver/Solver/src/IndexVect.cpp @@ -26,7 +26,7 @@ IndexVect::IndexVect (const IndexVect &iv) } } -IndexVect::IndexVect(std::array p) +IndexVect::IndexVect(std::array p) { for (int i = 0; i < DIM; ++ i) { diff --git a/MBSolver/Solver/src/MapTable.cpp b/MBSolver/Solver/src/MapTable.cpp index 38b915b19..b1f247d40 100644 --- a/MBSolver/Solver/src/MapTable.cpp +++ b/MBSolver/Solver/src/MapTable.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,7 +8,7 @@ using VCell::MTExpression; double MapTable::operator[](std::string name) const { auto iter = values.find(name); if (iter == values.end( )) { - throw new std::domain_error("no such name"); + throw std::domain_error("no such name"); } return iter->second; } diff --git a/MBSolver/Solver/src/Mesh.cpp b/MBSolver/Solver/src/Mesh.cpp index cecde5b2a..91c92f7f0 100644 --- a/MBSolver/Solver/src/Mesh.cpp +++ b/MBSolver/Solver/src/Mesh.cpp @@ -1,5 +1,6 @@ #include #include +#include #pragma warning ( disable: 4018 ) #include #include diff --git a/MBSolver/Solver/src/MeshElementNode.cpp b/MBSolver/Solver/src/MeshElementNode.cpp index 36cd138f5..48025876e 100644 --- a/MBSolver/Solver/src/MeshElementNode.cpp +++ b/MBSolver/Solver/src/MeshElementNode.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/MBSolver/Solver/src/MovingBoundaryParabolicProblem.cpp b/MBSolver/Solver/src/MovingBoundaryParabolicProblem.cpp index 24d22d655..63dc09ace 100644 --- a/MBSolver/Solver/src/MovingBoundaryParabolicProblem.cpp +++ b/MBSolver/Solver/src/MovingBoundaryParabolicProblem.cpp @@ -1,10 +1,12 @@ //#pragma warning ( disable: 4996 ) #pragma warning ( disable: 4244 ) #pragma warning ( disable: 4267 ) +#include #include #include #include #include +#include #include #include #include @@ -28,7 +30,6 @@ #include #include -#include #include #include #include diff --git a/MBSolver/Solver/src/Polygon.cpp b/MBSolver/Solver/src/Polygon.cpp index bffcf82b2..0ec496273 100644 --- a/MBSolver/Solver/src/Polygon.cpp +++ b/MBSolver/Solver/src/Polygon.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -16,7 +17,8 @@ namespace { template struct vectorWriter { std::ostream &os; - vectorWriter(std::ostream &os_) + + explicit vectorWriter(std::ostream &os_) :os(os_) {} void operator( )(V v) { vcell_persist::save(os,v); diff --git a/MBSolver/Solver/src/ReportClient.cpp b/MBSolver/Solver/src/ReportClient.cpp index 8d054fbb0..2b12e1179 100644 --- a/MBSolver/Solver/src/ReportClient.cpp +++ b/MBSolver/Solver/src/ReportClient.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -13,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +27,7 @@ #include #include #include +#include #pragma GCC diagnostic ignored "-Winvalid-offsetof" using moving_boundary::World ; using moving_boundary::CoordinateType; @@ -804,11 +805,8 @@ namespace { H5::DataSet runTime = vcellH5::primitiveWrite(baseGroup,"runTime",totalTime); //annotate version info - we place on runTime node to allow easy exclusion when doing //h5diff (see --exclude-path) - const vcell_util::Version & version = vcell_util::Version::get( ); - vcellH5::writeAttribute(runTime,"svnVersion",version.svn); - vcellH5::writeAttribute(runTime,"compileDate",version.compileDate); - vcellH5::writeAttribute(runTime,"compileTime",version.compileTime); - + std::string gitVersion(g_GIT_DESCRIBE); + vcellH5::writeAttribute(runTime,"gitVersion", gitVersion); unsigned int lastTimeIndex = static_cast(genTimes.size( )); vcellH5::primitiveWrite(baseGroup,"lastTimeIndex",lastTimeIndex); diff --git a/MBSolver/Solver/src/Voronoi32.cpp b/MBSolver/Solver/src/Voronoi32.cpp index 93e7683a2..002e32f84 100644 --- a/MBSolver/Solver/src/Voronoi32.cpp +++ b/MBSolver/Solver/src/Voronoi32.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "Voronoi.h" #include "SVector.h" #include "algo.h" diff --git a/MBSolver/Solver/src/World.cpp b/MBSolver/Solver/src/World.cpp index defd35b13..d69a18ad6 100644 --- a/MBSolver/Solver/src/World.cpp +++ b/MBSolver/Solver/src/World.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -224,7 +225,7 @@ namespace moving_boundary { template struct WorldMax; template struct WorldMax; template struct WorldMax; - + #ifdef COMPILE_64 template struct World; template struct WorldMax; diff --git a/MBSolver/Solver/src/driver.cpp b/MBSolver/Solver/src/driver.cpp index ab75b7d09..aec179eb3 100644 --- a/MBSolver/Solver/src/driver.cpp +++ b/MBSolver/Solver/src/driver.cpp @@ -3,15 +3,12 @@ #include #include #include -#include #include #include #include #include -#include -#include -#include #include +#include /** * usings and typedefs @@ -88,10 +85,9 @@ namespace { int main(int argc, char *argv[]) { - const vcell_util::Version & version = vcell_util::Version::get( ); - std::cout - << "MovingBoundarySolver version $URL$" - << "revision " << version.svn << ' ' << version.compileDate << std::endl; + std::cout + << "MovingBoundarySolver version " << g_GIT_DESCRIBE + << std::endl; std::string filename; std::string outname; @@ -119,7 +115,7 @@ int main(int argc, char *argv[]) namespace tclap = TCLAP; try { using namespace TCLAP; - CmdLine cmd("Moving boundary solve",' ',version.svn); + CmdLine cmd("Moving boundary solve",' ',g_GIT_DESCRIBE); cmd.setExceptionHandling(false); ValueArg config("c","config","Input XML file name",false,"","string",cmd); ValueArg output("o","output","HDF5 output file name",false,"","string",cmd); diff --git a/MBSolver/Solver/src/intersection.cpp b/MBSolver/Solver/src/intersection.cpp index f70606b5e..0707cc260 100644 --- a/MBSolver/Solver/src/intersection.cpp +++ b/MBSolver/Solver/src/intersection.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/MBSolver/Solver/src/version.cpp b/MBSolver/Solver/src/version.cpp deleted file mode 100644 index 23642f46f..000000000 --- a/MBSolver/Solver/src/version.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#if !defined(SVNVERSION) -#error SVNVERSION version not defined -#endif - -#define VCELLSVNQ(x) #x -#define VCELLSVNQUOTE(x) VCELLSVNQ(x) -using vcell_util::Version; -namespace { - std::string svnRev( ) { - std::string rval(VCELLSVNQUOTE(SVNVERSION)); - //macro adds quotes to either end, so strip those off - std::string rvo = rval.substr(1,rval.length( ) - 2); - return rvo; - } -} - - -Version::Version( ) - :svn(svnRev( )), - compileDate(__DATE__), - compileTime(__TIME__) {} - -const Version & Version::get( ) { - static Version v; - return v; -} diff --git a/MBSolver/Tests/CMakeLists.txt b/MBSolver/Tests/CMakeLists.txt index 7f7aa0150..50d4fc46b 100644 --- a/MBSolver/Tests/CMakeLists.txt +++ b/MBSolver/Tests/CMakeLists.txt @@ -31,8 +31,7 @@ set(SRC_FILES vcellutil.cpp vdemo.cpp vectortest.cpp - versiontest.cpp - vi64.cpp + vi64.cpp voltest.cpp worldtest.cpp ) diff --git a/MBSolver/Tests/clippertest.cpp b/MBSolver/Tests/clippertest.cpp index ea4326bb1..dbd4c3f28 100644 --- a/MBSolver/Tests/clippertest.cpp +++ b/MBSolver/Tests/clippertest.cpp @@ -1,348 +1,349 @@ -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "gtest/gtest.h" -#include "clipper.hpp" -#include "Angle.h" -#include "intersection.h" -//these were names used in previous version of clipper -typedef ClipperLib::Path Polygon; -typedef ClipperLib::Paths Polygons; - -template -void populate(matlabBridge::TPolygon & mpoly, const ClipperLib::Path & poly) { - typedef ClipperLib::Path cprPgon; - for (cprPgon::const_iterator iter = poly.begin( );iter != poly.end( ); ++iter) { - //mpoly.add(static_cast(iter->X),static_cast(iter->Y)); - mpoly.add(iter->X,iter->Y); - } -} - -ClipperLib::Path build(int count, long long *x,long long *y) { - ClipperLib::Path rval; - for (int i = 0; i < count; i++) { - rval.push_back(ClipperLib::IntPoint(x[i],y[i])); - } - rval.push_back(ClipperLib::IntPoint(x[0],y[0])); - return rval; -} - -TEST(clipper,largenum){ - using namespace ClipperLib; - cInt hiRange = 0x3FFFFFFFFFFFFFFFLL; - cInt maxLong = std::numeric_limits::max( ); - std::cout << hiRange << ' ' << maxLong << ' ' << (hiRange == maxLong) << std::endl; - std::cout << "max value is " << std::numeric_limits::max( ) << std::endl; - /* - Polygon1.x = [4387414506071, 4157630003224, 3891577094948, 3591914093955, 3261635133897, -3870280929772] - Polygon1.y = [2108535817006, 2483323859773, 2833299351411, 3154965452493, 3445108181668, -440] - - Polygon2.x = [5717460464435, 3518437208883, 3518437208883, 5717460464435] - Polygon2.y = [4398046511104, 4398046511104, 2199023255552, 2199023255552] - */ - cInt x1[] = {4387414506071, 4157630003224, 3891577094948, 3591914093955, 3261635133897, -3870280929772}; - cInt y1[] = {2108535817006, 2483323859773, 2833299351411, 3154965452493, 3445108181668, -440}; - - cInt x2[] = {5717460464435, 3518437208883, 3518437208883, 5717460464435}; - cInt y2[] = {4398046511104, 4398046511104, 2199023255552, 2199023255552}; - ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); - ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); - std::reverse(p2.begin( ), p2.end( )); - - CleanPolygon(p1,p1); - CleanPolygon(p2,p2); - - Clipper c; - bool ap = c.AddPath(p1,ptSubject,true); - ASSERT_TRUE(ap); - ap = c.AddPath(p2,ptClip,true); - ASSERT_TRUE(ap); - Paths results; - /* - PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; - const int ntypes = sizeof(types)/sizeof(types[0]); - for (int i = 0 ; i b1("g+-"); - matlabBridge::TPolygon b2("b+-"); - populate(b1,p1); - populate(b2,p2); - script << matlabBridge::FigureName("clipperLarge") << b1 << b2; - for (Polygons::const_iterator iter = results.begin( ); iter != results.end( );++iter) { - matlabBridge::TPolygon a("r+-"); - populate(a,*iter); - script << a; - } - //reply from Clipper developer - /* - ClipperLib::Path a; - a.push_back(IntPoint(3518437208883, 2199023255552)); - a.push_back(IntPoint(3518437208883, 3219513263720)); - a.push_back(IntPoint(3261635133897, 3445108181668)); - a.push_back(IntPoint(682043251292, 2199023255552)); - matlabBridge::TPolygon b3("r+-"); - populate(b3,a); - script << b3; - */ -} - -TEST(clipper,small){ - using namespace ClipperLib; - /* - Polygon1.x = [4387414506071, 4157630003224, 3891577094948, 3591914093955, 3261635133897, -3870280929772] - Polygon1.y = [2108535817006, 2483323859773, 2833299351411, 3154965452493, 3445108181668, -440] - - Polygon2.x = [5717460464435, 3518437208883, 3518437208883, 5717460464435] - Polygon2.y = [4398046511104, 4398046511104, 2199023255552, 2199023255552] - */ - cInt x1[] = {0,5,5,0}; - cInt y1[] = {0,0,5,5}; - - cInt x2[] = {-1,6,6,-1}; - cInt y2[] = {2,2,4,4}; - ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); - ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); - - Clipper c; - c.AddPath(p1,ptSubject,true); - c.AddPath(p2,ptClip,true); - Polygons results; - ClipperLib::Path answer; - PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; - const int ntypes = sizeof(types)/sizeof(types[0]); - for (int i = 0 ; i 0) { - std::cout << r << ',' << results.size( ) << "i is " << i << ", j is " << j << std::endl; - answer = results.front( ); - } - } - } - std::ofstream script("clippersmall.m"); - matlabBridge::TPolygon b1("g"); - matlabBridge::TPolygon b2("b"); - matlabBridge::TPolygon a("r+"); - populate(b1,p1); - populate(b2,p2); - populate(a,answer); - script << matlabBridge::FigureName("clipperFail") << b1 << b2 << a << std::flush; -} -TEST(clipper,request){ - using namespace ClipperLib; - long long x1[] = {4721014781795280, 4721014781795280, 5438484791397062, 5438484791397062}; - long long y1[] = {1947418597490553, 1879088120385621, 1879088120385621, 1947418597490551}; - long long x2[] = {4814313922692160, 4800114314395577, 4785679378820044, 4771009946699843, 4710004338769085, -3792559502082542}; - long long y2[] = {1856220285199938, 1887294857627051, 1918260815746161, 1949116377458356, 2071399242770190, -450359}; - - ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); - ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); - - Clipper c; - c.AddPath(p1,ptSubject,true); - c.AddPath(p2,ptClip,true); - Polygons results; - ClipperLib::Path answer; - PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; - const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); - assert(r); - typedef ClipperLib::Path::const_iterator PIter; - if (results.size( ) > 0) { - answer = results.front( ); - std::ofstream log("results.txt"); - for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { - log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; - } - } - std::ofstream script("clipperReq.m"); - matlabBridge::TPolygon b1("g+-"); - matlabBridge::TPolygon b2("b+-"); - matlabBridge::TPolygon a("r"); - populate(b1,p1); - populate(b2,p2); - populate(a,answer); - b1.close( ); - b2.close( ); - a.close( ); - script << matlabBridge::FigureName("clipperReq") << b1 << b2 << a << std::flush; -} - -TEST(clipper,miss){ - using namespace ClipperLib; - cInt x1[] = {0,5,5,0}; - cInt y1[] = {0,0,5,5}; - - cInt x2[] = {14,16,16,14}; - cInt y2[] = {2,2,4,4}; - ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); - ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); - Clipper c; - - - c.AddPath(p1,ptSubject,true); - c.AddPath(p2,ptClip,true); - Polygons results; - ClipperLib::Path answer; - PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; - const int ntypes = sizeof(types)/sizeof(types[0]); - for (int i = 0 ; i 0) { - std::cout << r << ',' << results.size( ) << " i is " << i << ", j is " << j << std::endl; - answer = results.front( ); - - } - } - } - std::ofstream script("clippermiss.m"); - matlabBridge::TPolygon b1("g"); - matlabBridge::TPolygon b2("b"); - matlabBridge::TPolygon a("r+"); - populate(b1,p1); - populate(b2,p2); - populate(a,answer); - script << matlabBridge::FigureName("clipperFail") << b1 << b2 << a << std::flush; -} - -namespace { - using spatial::Point2D; - using spatial::Angle; - - std::vector ellipse(double centerX, double centerY, double a, double b, const spatial::Angle & angleOfMajor, - int increment = 10) { - std::vector rval; - const double axisCos = angleOfMajor.cos( ); - const double axisSin = angleOfMajor.sin( ); - for (int d = 0; d < 360; d+=increment) { - spatial::DegAngle sweep(d); - double x = centerX + a * sweep.cos( ) * axisCos - b * sweep.sin( ) * axisSin; - double y = centerY + a * sweep.cos( ) * axisSin - b * sweep.sin( ) * axisCos; - rval.push_back(Point2D(x,y)); - } - return rval; - } -} - -#ifdef FIXUP -TEST(clipper,intersection){ -#ifdef TIMEIT - LARGE_INTEGER tps; - QueryPerformanceFrequency(&tps); - std::cout << "The system does " << tps.QuadPart << " ticks per second" << std::endl; -#endif - typedef std::vector OurPolyType; - OurPolyType a; - OurPolyType b; - spatial::Volume vol; - for (int i = 20; i > 0; --i) { - a = ellipse(0,0,0.8,0.4,spatial::DegAngle(0),i); - b = ellipse(0,0,0.8,0.4,spatial::DegAngle(90),i); - spatial::intersections(vol,a,b); - } - matlabBridge::Polygon pA("g+"); - matlabBridge::Polygon pB("b+"); - frontTierAdapt::copyVectorInto(pA,a); - frontTierAdapt::copyVectorInto(pB,b); - std::ofstream script("clipperellipse.m"); - script << matlabBridge::writeDateTime << matlabBridge::FigureName("Ellipse intersection") << pA << pB; - spatial::Volume::VectorOfVectors vOfV = vol.points( ); - for (spatial::Volume::VectorOfVectors::const_iterator vvIter = vOfV.begin( ); vvIter != vOfV.end( );++vvIter) { - matlabBridge::Polygon pPoly("k",3); - frontTierAdapt::copyVectorInto(pPoly,*vvIter); - script << pPoly; - } - -} -#endif - -TEST(clipper,size) { - std::cout << "Clipper integer values range from " << std::numeric_limits::min( ) - << " to " << std::numeric_limits::max( ) << std::endl; -} - -TEST(clipper,example){ - using namespace ClipperLib; - - ClipperLib::Path a; - ClipperLib::Path b; - - a.push_back(IntPoint(9081931755000444,3852088701037340)); - a.push_back(IntPoint(9223372036854776,4261755592555446)); - a.push_back(IntPoint(8899528943709485,4784327748787467)); - a.push_back(IntPoint(5665663308460032,9168595685557330)); - a.push_back(IntPoint(6920856759147015,4512437454088893)); - a.push_back(IntPoint(6128204351779665,2903238065584625)); - a.push_back(IntPoint(4119204340890290,-4142963787133938)); - a.push_back(IntPoint(8746542643914421,3787478073965549)); - a.push_back(IntPoint(9043878658276244,3593034637283243)); - a.push_back(IntPoint(9081931755000444,3852088701037340)); - a.push_back(IntPoint(9081931755000444,3852088701037340)); - - b.push_back(IntPoint(6410775356470902,2942958277678163)); - b.push_back(IntPoint(6286170965356830,7405526866037764)); - b.push_back(IntPoint(1298773977681875,9202139602414040)); - b.push_back(IntPoint(-684110545974676,4585850964304698)); - b.push_back(IntPoint(-160563237570624,1552192686524017)); - b.push_back(IntPoint(1159040607476757,-3928434943053781)); - b.push_back(IntPoint(6771193485403109,-2127809313692678)); - b.push_back(IntPoint(6410775356470902,2942958277678163)); - b.push_back(IntPoint(6410775356470902,2942958277678163)); - - Clipper c; - c.AddPath(a,ptSubject,true); - c.AddPath(b,ptClip,true); - Polygons results; - const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); - assert(r); - /* - typedef ClipperLib::Path::const_iterator PIter; - if (results.size( ) > 0) { - answer = results.front( ); - std::ofstream log("example.txt"); - for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { - log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; - } - } - */ - - std::ofstream script("clipperExample.m"); - matlabBridge::TPolygon b1("g+-"); - matlabBridge::TPolygon b2("b+-"); - populate(b1,a); - populate(b2,b); - b1.close( ); - b2.close( ); - script << matlabBridge::FigureName("clipperReq") << b1 << b2; - for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { - matlabBridge::TPolygon ans("r"); - ClipperLib::Path answer = *pIter; - populate(ans,answer); - ans.close( ); - script << ans; - } - script << std::flush; -} -TEST(clipper,m85a){ - using namespace ClipperLib; - - ClipperLib::Path a; - ClipperLib::Path b; +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" +#include "clipper.hpp" +#include "Angle.h" +#include "intersection.h" +//these were names used in previous version of clipper +typedef ClipperLib::Path Polygon; +typedef ClipperLib::Paths Polygons; + +template +void populate(matlabBridge::TPolygon & mpoly, const ClipperLib::Path & poly) { + typedef ClipperLib::Path cprPgon; + for (cprPgon::const_iterator iter = poly.begin( );iter != poly.end( ); ++iter) { + //mpoly.add(static_cast(iter->X),static_cast(iter->Y)); + mpoly.add(iter->X,iter->Y); + } +} + +ClipperLib::Path build(int count, long long *x,long long *y) { + ClipperLib::Path rval; + for (int i = 0; i < count; i++) { + rval.push_back(ClipperLib::IntPoint(x[i],y[i])); + } + rval.push_back(ClipperLib::IntPoint(x[0],y[0])); + return rval; +} + +TEST(clipper,largenum){ + using namespace ClipperLib; + cInt hiRange = 0x3FFFFFFFFFFFFFFFLL; + cInt maxLong = std::numeric_limits::max( ); + std::cout << hiRange << ' ' << maxLong << ' ' << (hiRange == maxLong) << std::endl; + std::cout << "max value is " << std::numeric_limits::max( ) << std::endl; + /* + Polygon1.x = [4387414506071, 4157630003224, 3891577094948, 3591914093955, 3261635133897, -3870280929772] + Polygon1.y = [2108535817006, 2483323859773, 2833299351411, 3154965452493, 3445108181668, -440] + + Polygon2.x = [5717460464435, 3518437208883, 3518437208883, 5717460464435] + Polygon2.y = [4398046511104, 4398046511104, 2199023255552, 2199023255552] + */ + cInt x1[] = {4387414506071, 4157630003224, 3891577094948, 3591914093955, 3261635133897, -3870280929772}; + cInt y1[] = {2108535817006, 2483323859773, 2833299351411, 3154965452493, 3445108181668, -440}; + + cInt x2[] = {5717460464435, 3518437208883, 3518437208883, 5717460464435}; + cInt y2[] = {4398046511104, 4398046511104, 2199023255552, 2199023255552}; + ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); + ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); + std::reverse(p2.begin( ), p2.end( )); + + CleanPolygon(p1,p1); + CleanPolygon(p2,p2); + + Clipper c; + bool ap = c.AddPath(p1,ptSubject,true); + ASSERT_TRUE(ap); + ap = c.AddPath(p2,ptClip,true); + ASSERT_TRUE(ap); + Paths results; + /* + PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; + const int ntypes = sizeof(types)/sizeof(types[0]); + for (int i = 0 ; i b1("g+-"); + matlabBridge::TPolygon b2("b+-"); + populate(b1,p1); + populate(b2,p2); + script << matlabBridge::FigureName("clipperLarge") << b1 << b2; + for (Polygons::const_iterator iter = results.begin( ); iter != results.end( );++iter) { + matlabBridge::TPolygon a("r+-"); + populate(a,*iter); + script << a; + } + //reply from Clipper developer + /* + ClipperLib::Path a; + a.push_back(IntPoint(3518437208883, 2199023255552)); + a.push_back(IntPoint(3518437208883, 3219513263720)); + a.push_back(IntPoint(3261635133897, 3445108181668)); + a.push_back(IntPoint(682043251292, 2199023255552)); + matlabBridge::TPolygon b3("r+-"); + populate(b3,a); + script << b3; + */ +} + +TEST(clipper,small){ + using namespace ClipperLib; + /* + Polygon1.x = [4387414506071, 4157630003224, 3891577094948, 3591914093955, 3261635133897, -3870280929772] + Polygon1.y = [2108535817006, 2483323859773, 2833299351411, 3154965452493, 3445108181668, -440] + + Polygon2.x = [5717460464435, 3518437208883, 3518437208883, 5717460464435] + Polygon2.y = [4398046511104, 4398046511104, 2199023255552, 2199023255552] + */ + cInt x1[] = {0,5,5,0}; + cInt y1[] = {0,0,5,5}; + + cInt x2[] = {-1,6,6,-1}; + cInt y2[] = {2,2,4,4}; + ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); + ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); + + Clipper c; + c.AddPath(p1,ptSubject,true); + c.AddPath(p2,ptClip,true); + Polygons results; + ClipperLib::Path answer; + PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; + const int ntypes = sizeof(types)/sizeof(types[0]); + for (int i = 0 ; i 0) { + std::cout << r << ',' << results.size( ) << "i is " << i << ", j is " << j << std::endl; + answer = results.front( ); + } + } + } + std::ofstream script("clippersmall.m"); + matlabBridge::TPolygon b1("g"); + matlabBridge::TPolygon b2("b"); + matlabBridge::TPolygon a("r+"); + populate(b1,p1); + populate(b2,p2); + populate(a,answer); + script << matlabBridge::FigureName("clipperFail") << b1 << b2 << a << std::flush; +} +TEST(clipper,request){ + using namespace ClipperLib; + long long x1[] = {4721014781795280, 4721014781795280, 5438484791397062, 5438484791397062}; + long long y1[] = {1947418597490553, 1879088120385621, 1879088120385621, 1947418597490551}; + long long x2[] = {4814313922692160, 4800114314395577, 4785679378820044, 4771009946699843, 4710004338769085, -3792559502082542}; + long long y2[] = {1856220285199938, 1887294857627051, 1918260815746161, 1949116377458356, 2071399242770190, -450359}; + + ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); + ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); + + Clipper c; + c.AddPath(p1,ptSubject,true); + c.AddPath(p2,ptClip,true); + Polygons results; + ClipperLib::Path answer; + PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; + const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); + assert(r); + typedef ClipperLib::Path::const_iterator PIter; + if (results.size( ) > 0) { + answer = results.front( ); + std::ofstream log("results.txt"); + for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { + log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; + } + } + std::ofstream script("clipperReq.m"); + matlabBridge::TPolygon b1("g+-"); + matlabBridge::TPolygon b2("b+-"); + matlabBridge::TPolygon a("r"); + populate(b1,p1); + populate(b2,p2); + populate(a,answer); + b1.close( ); + b2.close( ); + a.close( ); + script << matlabBridge::FigureName("clipperReq") << b1 << b2 << a << std::flush; +} + +TEST(clipper,miss){ + using namespace ClipperLib; + cInt x1[] = {0,5,5,0}; + cInt y1[] = {0,0,5,5}; + + cInt x2[] = {14,16,16,14}; + cInt y2[] = {2,2,4,4}; + ClipperLib::Path p1 = build(sizeof(x1)/sizeof(x1[0]),x1,y1); + ClipperLib::Path p2 = build(sizeof(x2)/sizeof(x2[0]),x2,y2); + Clipper c; + + + c.AddPath(p1,ptSubject,true); + c.AddPath(p2,ptClip,true); + Polygons results; + ClipperLib::Path answer; + PolyFillType types[] = {pftPositive,pftNegative,pftNegative,pftEvenOdd}; + const int ntypes = sizeof(types)/sizeof(types[0]); + for (int i = 0 ; i 0) { + std::cout << r << ',' << results.size( ) << " i is " << i << ", j is " << j << std::endl; + answer = results.front( ); + + } + } + } + std::ofstream script("clippermiss.m"); + matlabBridge::TPolygon b1("g"); + matlabBridge::TPolygon b2("b"); + matlabBridge::TPolygon a("r+"); + populate(b1,p1); + populate(b2,p2); + populate(a,answer); + script << matlabBridge::FigureName("clipperFail") << b1 << b2 << a << std::flush; +} + +namespace { + using spatial::Point2D; + using spatial::Angle; + + std::vector ellipse(double centerX, double centerY, double a, double b, const spatial::Angle & angleOfMajor, + int increment = 10) { + std::vector rval; + const double axisCos = angleOfMajor.cos( ); + const double axisSin = angleOfMajor.sin( ); + for (int d = 0; d < 360; d+=increment) { + spatial::DegAngle sweep(d); + double x = centerX + a * sweep.cos( ) * axisCos - b * sweep.sin( ) * axisSin; + double y = centerY + a * sweep.cos( ) * axisSin - b * sweep.sin( ) * axisCos; + rval.push_back(Point2D(x,y)); + } + return rval; + } +} + +#ifdef FIXUP +TEST(clipper,intersection){ +#ifdef TIMEIT + LARGE_INTEGER tps; + QueryPerformanceFrequency(&tps); + std::cout << "The system does " << tps.QuadPart << " ticks per second" << std::endl; +#endif + typedef std::vector OurPolyType; + OurPolyType a; + OurPolyType b; + spatial::Volume vol; + for (int i = 20; i > 0; --i) { + a = ellipse(0,0,0.8,0.4,spatial::DegAngle(0),i); + b = ellipse(0,0,0.8,0.4,spatial::DegAngle(90),i); + spatial::intersections(vol,a,b); + } + matlabBridge::Polygon pA("g+"); + matlabBridge::Polygon pB("b+"); + frontTierAdapt::copyVectorInto(pA,a); + frontTierAdapt::copyVectorInto(pB,b); + std::ofstream script("clipperellipse.m"); + script << matlabBridge::writeDateTime << matlabBridge::FigureName("Ellipse intersection") << pA << pB; + spatial::Volume::VectorOfVectors vOfV = vol.points( ); + for (spatial::Volume::VectorOfVectors::const_iterator vvIter = vOfV.begin( ); vvIter != vOfV.end( );++vvIter) { + matlabBridge::Polygon pPoly("k",3); + frontTierAdapt::copyVectorInto(pPoly,*vvIter); + script << pPoly; + } + +} +#endif + +TEST(clipper,size) { + std::cout << "Clipper integer values range from " << std::numeric_limits::min( ) + << " to " << std::numeric_limits::max( ) << std::endl; +} + +TEST(clipper,example){ + using namespace ClipperLib; + + ClipperLib::Path a; + ClipperLib::Path b; + + a.push_back(IntPoint(9081931755000444,3852088701037340)); + a.push_back(IntPoint(9223372036854776,4261755592555446)); + a.push_back(IntPoint(8899528943709485,4784327748787467)); + a.push_back(IntPoint(5665663308460032,9168595685557330)); + a.push_back(IntPoint(6920856759147015,4512437454088893)); + a.push_back(IntPoint(6128204351779665,2903238065584625)); + a.push_back(IntPoint(4119204340890290,-4142963787133938)); + a.push_back(IntPoint(8746542643914421,3787478073965549)); + a.push_back(IntPoint(9043878658276244,3593034637283243)); + a.push_back(IntPoint(9081931755000444,3852088701037340)); + a.push_back(IntPoint(9081931755000444,3852088701037340)); + + b.push_back(IntPoint(6410775356470902,2942958277678163)); + b.push_back(IntPoint(6286170965356830,7405526866037764)); + b.push_back(IntPoint(1298773977681875,9202139602414040)); + b.push_back(IntPoint(-684110545974676,4585850964304698)); + b.push_back(IntPoint(-160563237570624,1552192686524017)); + b.push_back(IntPoint(1159040607476757,-3928434943053781)); + b.push_back(IntPoint(6771193485403109,-2127809313692678)); + b.push_back(IntPoint(6410775356470902,2942958277678163)); + b.push_back(IntPoint(6410775356470902,2942958277678163)); + + Clipper c; + c.AddPath(a,ptSubject,true); + c.AddPath(b,ptClip,true); + Polygons results; + const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); + assert(r); + /* + typedef ClipperLib::Path::const_iterator PIter; + if (results.size( ) > 0) { + answer = results.front( ); + std::ofstream log("example.txt"); + for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { + log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; + } + } + */ + + std::ofstream script("clipperExample.m"); + matlabBridge::TPolygon b1("g+-"); + matlabBridge::TPolygon b2("b+-"); + populate(b1,a); + populate(b2,b); + b1.close( ); + b2.close( ); + script << matlabBridge::FigureName("clipperReq") << b1 << b2; + for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { + matlabBridge::TPolygon ans("r"); + ClipperLib::Path answer = *pIter; + populate(ans,answer); + ans.close( ); + script << ans; + } + script << std::flush; +} +TEST(clipper,m85a){ + using namespace ClipperLib; + + ClipperLib::Path a; + ClipperLib::Path b; a.push_back(IntPoint(955761822,-241173480)); a.push_back(IntPoint(866438292,-223308774)); a.push_back(IntPoint(669926526,-223308774)); @@ -1339,47 +1340,47 @@ TEST(clipper,m85a){ b.push_back(IntPoint(325351769,292403333)); b.push_back(IntPoint(322692079,292707573)); b.push_back(IntPoint(320030083,292990926)); - - - Clipper c; - c.AddPath(a,ptSubject,true); - c.AddPath(b,ptClip,true); - Polygons results; - const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); - assert(r); - /* - typedef ClipperLib::Path::const_iterator PIter; - if (results.size( ) > 0) { - answer = results.front( ); - std::ofstream log("example.txt"); - for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { - log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; - } - } - */ - - std::ofstream script("clipper85a.m"); - matlabBridge::TPolygon b1("g+-"); - matlabBridge::TPolygon b2("b+-"); - populate(b1,a); - populate(b2,b); - b1.close( ); - b2.close( ); - script << matlabBridge::FigureName("85a") << b1 << b2; - for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { - matlabBridge::TPolygon ans("r"); - ClipperLib::Path answer = *pIter; - populate(ans,answer); - ans.close( ); - script << ans; - } - script << std::flush; -} -TEST(clipper,m85b){ - using namespace ClipperLib; - - ClipperLib::Path a; - ClipperLib::Path b; + + + Clipper c; + c.AddPath(a,ptSubject,true); + c.AddPath(b,ptClip,true); + Polygons results; + const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); + assert(r); + /* + typedef ClipperLib::Path::const_iterator PIter; + if (results.size( ) > 0) { + answer = results.front( ); + std::ofstream log("example.txt"); + for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { + log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; + } + } + */ + + std::ofstream script("clipper85a.m"); + matlabBridge::TPolygon b1("g+-"); + matlabBridge::TPolygon b2("b+-"); + populate(b1,a); + populate(b2,b); + b1.close( ); + b2.close( ); + script << matlabBridge::FigureName("85a") << b1 << b2; + for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { + matlabBridge::TPolygon ans("r"); + ClipperLib::Path answer = *pIter; + populate(ans,answer); + ans.close( ); + script << ans; + } + script << std::flush; +} +TEST(clipper,m85b){ + using namespace ClipperLib; + + ClipperLib::Path a; + ClipperLib::Path b; a.push_back(IntPoint(759250056,-205444067)); a.push_back(IntPoint(669926526,-205444068)); @@ -2378,134 +2379,134 @@ TEST(clipper,m85b){ b.push_back(IntPoint(322692079,292707573)); b.push_back(IntPoint(320030083,292990926)); - - Clipper c; - c.AddPath(a,ptSubject,true); - c.AddPath(b,ptClip,true); - Polygons results; - const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); - assert(r); - /* - typedef ClipperLib::Path::const_iterator PIter; - if (results.size( ) > 0) { - answer = results.front( ); - std::ofstream log("example.txt"); - for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { - log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; - } - } - */ - - std::ofstream script("clipper85b.m"); - matlabBridge::TPolygon b1("g+-"); - matlabBridge::TPolygon b2("b+-"); - populate(b1,a); - populate(b2,b); - b1.close( ); - b2.close( ); - script << matlabBridge::FigureName("clipper85b") << b1 << b2; - for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { - matlabBridge::TPolygon ans("r"); - ClipperLib::Path answer = *pIter; - populate(ans,answer); - ans.close( ); - script << ans; - } - script << std::flush; -} -/** -* intersection precision testing -*/ -TEST(algo,intersectp) { -#ifdef HOLD_FOR_NOW - typedef std::vector TestPoly; - const double centerx = 1.0/7; - const double centery = 2.0/13; - spatial::SVector down(0,-1); - spatial::SVector right(0.5,0); - Point2D topLeft(centerx - 0.5, 1); - Point2D topRight = spatial::displacement(topLeft,right * 2); - Point2D topCenter = spatial::displacement(topLeft,right); - - Point2D bottomLeft = spatial::displacement(topLeft, down); - Point2D bottomCenter = spatial::displacement(bottomLeft,right); - Point2D bottomRight = spatial::displacement(bottomLeft,right *2); - - - - TestPoly box; - box.push_back(bottomCenter); - box.push_back(bottomLeft); - box.push_back(topLeft); - box.push_back(topCenter); - - TestPoly box2; - box2.push_back(bottomCenter); - box2.push_back(topCenter); - box2.push_back(topRight); - box2.push_back(bottomRight); - - //std::vector e = ellipse(double centerX, double centerY, double a, double b, const spatial::Angle & angleOfMajor, - TestPoly e = ellipse(centerx, centery, 1, 0.5, spatial::DegAngle(0),1); - spatial::Volume result; - spatial::intersections(result,box,e); - ASSERT_TRUE(result.volume( ) > 0); - - spatial::Volume result2; - spatial::intersections(result2,box2,e); - ASSERT_TRUE(result2.volume( ) > 0); - - std::ofstream script("intersectp.m"); - script << matlabBridge::FigureName("Intersect p") << matlabBridge::clearFigure; - - matlabBridge::Polygon pbox("g",3); - matlabBridge::Polygon pbox2("y",3); - matlabBridge::Polygon pe("m",3); - frontTierAdapt::copyVectorInto(pbox,box); - frontTierAdapt::copyVectorInto(pbox2,box2); - frontTierAdapt::copyVectorInto(pe,e); - script << pbox << pbox2 << pe; - spatial::Volume::VectorOfVectors vOfV = result.points( ); - for (spatial::Volume::VectorOfVectors::const_iterator vvIter = vOfV.begin( ); vvIter != vOfV.end( );++vvIter) { - matlabBridge::Polygon pPoly("k",3); - frontTierAdapt::copyVectorInto(pPoly,*vvIter); - for (spatial::Volume::PointVector::const_iterator vIter = vvIter->begin( ); vIter != vvIter->end( );++vIter) { - const Point2D &p = *vIter; - //std::cout << p << " dist " << spatial::distance(p,bottomCenter) << std::endl; - if (spatial::distance(p,bottomCenter) < 0.01) { - std::cout << "hit " << &bottomCenter << ", " << &p << std::endl; - } - } - script << pPoly; - } - //std::cout << "second verse" << std::endl; - vOfV = result2.points( ); - for (spatial::Volume::VectorOfVectors::const_iterator vvIter = vOfV.begin( ); vvIter != vOfV.end( );++vvIter) { - matlabBridge::Polygon pPoly("b",3); - frontTierAdapt::copyVectorInto(pPoly,*vvIter); - for (spatial::Volume::PointVector::const_iterator vIter = vvIter->begin( ); vIter != vvIter->end( );++vIter) { - const Point2D &p = *vIter; - //std::cout << p << " dist " << spatial::distance(p,bottomCenter) << std::endl; - if (spatial::distance(p,bottomCenter) == 0) { - std::cout << "hit " << &bottomCenter << ", " << &p << std::endl; - } - } - script << pPoly; - script << pPoly; - } -} -namespace { - void scaledown(ClipperLib::Path &p) { - for (ClipperLib::Path::iterator iter = p.begin( ); iter != p.end( );++iter) { - iter->X /=2; - iter->Y /=2; - } - } -} -TEST(clipper,testcase) { - using namespace ClipperLib; - Polygon polyA; + Clipper c; + c.AddPath(a,ptSubject,true); + c.AddPath(b,ptClip,true); + Polygons results; + const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); + assert(r); + /* + typedef ClipperLib::Path::const_iterator PIter; + if (results.size( ) > 0) { + answer = results.front( ); + std::ofstream log("example.txt"); + for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { + log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; + } + } + */ + + std::ofstream script("clipper85b.m"); + matlabBridge::TPolygon b1("g+-"); + matlabBridge::TPolygon b2("b+-"); + populate(b1,a); + populate(b2,b); + b1.close( ); + b2.close( ); + script << matlabBridge::FigureName("clipper85b") << b1 << b2; + for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { + matlabBridge::TPolygon ans("r"); + ClipperLib::Path answer = *pIter; + populate(ans,answer); + ans.close( ); + script << ans; + } + script << std::flush; +} +/** +* intersection precision testing +*/ +TEST(algo,intersectp) { +#ifdef HOLD_FOR_NOW + typedef std::vector TestPoly; + const double centerx = 1.0/7; + const double centery = 2.0/13; + spatial::SVector down(0,-1); + spatial::SVector right(0.5,0); + Point2D topLeft(centerx - 0.5, 1); + Point2D topRight = spatial::displacement(topLeft,right * 2); + Point2D topCenter = spatial::displacement(topLeft,right); + + Point2D bottomLeft = spatial::displacement(topLeft, down); + Point2D bottomCenter = spatial::displacement(bottomLeft,right); + Point2D bottomRight = spatial::displacement(bottomLeft,right *2); + + + + TestPoly box; + box.push_back(bottomCenter); + box.push_back(bottomLeft); + box.push_back(topLeft); + box.push_back(topCenter); + + TestPoly box2; + box2.push_back(bottomCenter); + box2.push_back(topCenter); + box2.push_back(topRight); + box2.push_back(bottomRight); + + //std::vector e = ellipse(double centerX, double centerY, double a, double b, const spatial::Angle & angleOfMajor, + TestPoly e = ellipse(centerx, centery, 1, 0.5, spatial::DegAngle(0),1); + spatial::Volume result; + spatial::intersections(result,box,e); + ASSERT_TRUE(result.volume( ) > 0); + + spatial::Volume result2; + spatial::intersections(result2,box2,e); + ASSERT_TRUE(result2.volume( ) > 0); + + std::ofstream script("intersectp.m"); + script << matlabBridge::FigureName("Intersect p") << matlabBridge::clearFigure; + + matlabBridge::Polygon pbox("g",3); + matlabBridge::Polygon pbox2("y",3); + matlabBridge::Polygon pe("m",3); + frontTierAdapt::copyVectorInto(pbox,box); + frontTierAdapt::copyVectorInto(pbox2,box2); + frontTierAdapt::copyVectorInto(pe,e); + script << pbox << pbox2 << pe; + spatial::Volume::VectorOfVectors vOfV = result.points( ); + for (spatial::Volume::VectorOfVectors::const_iterator vvIter = vOfV.begin( ); vvIter != vOfV.end( );++vvIter) { + matlabBridge::Polygon pPoly("k",3); + frontTierAdapt::copyVectorInto(pPoly,*vvIter); + for (spatial::Volume::PointVector::const_iterator vIter = vvIter->begin( ); vIter != vvIter->end( );++vIter) { + const Point2D &p = *vIter; + //std::cout << p << " dist " << spatial::distance(p,bottomCenter) << std::endl; + if (spatial::distance(p,bottomCenter) < 0.01) { + std::cout << "hit " << &bottomCenter << ", " << &p << std::endl; + } + } + script << pPoly; + } + //std::cout << "second verse" << std::endl; + vOfV = result2.points( ); + for (spatial::Volume::VectorOfVectors::const_iterator vvIter = vOfV.begin( ); vvIter != vOfV.end( );++vvIter) { + matlabBridge::Polygon pPoly("b",3); + frontTierAdapt::copyVectorInto(pPoly,*vvIter); + for (spatial::Volume::PointVector::const_iterator vIter = vvIter->begin( ); vIter != vvIter->end( );++vIter) { + const Point2D &p = *vIter; + //std::cout << p << " dist " << spatial::distance(p,bottomCenter) << std::endl; + if (spatial::distance(p,bottomCenter) == 0) { + std::cout << "hit " << &bottomCenter << ", " << &p << std::endl; + } + } + script << pPoly; + script << pPoly; + } +} +namespace { + void scaledown(ClipperLib::Path &p) { + for (ClipperLib::Path::iterator iter = p.begin( ); iter != p.end( );++iter) { + iter->X /=2; + iter->Y /=2; + } + } +} + +TEST(clipper,testcase) { + using namespace ClipperLib; + Polygon polyA; Polygon polyB; polyA.push_back(IntPoint(-350111673235712000,-7939286986110536704)); polyA.push_back(IntPoint(-350111672573059776,-1163274266659200768)); @@ -2922,56 +2923,56 @@ TEST(clipper,testcase) { polyB.push_back(IntPoint(-837398005472809984,-1017293493612283520)); polyB.push_back(IntPoint(-821624237135682048,-1030056918296435200)); polyB.push_back(IntPoint(-805645495940844032,-1042562189840885120)); - int scaleCount = 0; - Polygons results; - for (;;) { - Clipper c; - bool goodAdd = c.AddPath(polyA,ptSubject,true); - goodAdd = c.AddPath(polyB,ptClip,true); - const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); - assert(r); - if (results.size( ) > 0) { - break; - } - scaledown(polyA); - scaledown(polyB); - ++scaleCount; - std::cout << "scaled down " << scaleCount << std::endl; - } - /* - typedef ClipperLib::Path::const_iterator PIter; - if (results.size( ) > 0) { - answer = results.front( ); - std::ofstream log("example.txt"); - for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { - log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; - } - } - */ - - std::ofstream script("clipperExample2.m"); - matlabBridge::TPolygon b1("g+-"); - matlabBridge::TPolygon b2("b+-"); - populate(b1,polyA); - populate(b2,polyB); - b1.close( ); - b2.close( ); - script << matlabBridge::FigureName("clipperReq2") << b1 << b2; - for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { - matlabBridge::TPolygon ans("r"); - ClipperLib::Path answer = *pIter; - populate(ans,answer); - ans.close( ); - script << ans; - } - script << std::flush; -#endif -} -TEST(clipper,dual){ - using namespace ClipperLib; - - ClipperLib::Path a; - ClipperLib::Path b; + int scaleCount = 0; + Polygons results; + for (;;) { + Clipper c; + bool goodAdd = c.AddPath(polyA,ptSubject,true); + goodAdd = c.AddPath(polyB,ptClip,true); + const bool r = c.Execute(ctIntersection ,results,pftEvenOdd,pftEvenOdd); + assert(r); + if (results.size( ) > 0) { + break; + } + scaledown(polyA); + scaledown(polyB); + ++scaleCount; + std::cout << "scaled down " << scaleCount << std::endl; + } + /* + typedef ClipperLib::Path::const_iterator PIter; + if (results.size( ) > 0) { + answer = results.front( ); + std::ofstream log("example.txt"); + for (PIter iter = answer.begin( ); iter != answer.end( ); ++iter) { + log << '(' << iter->X << ',' << iter->Y << ") " << std::endl; + } + } + */ + + std::ofstream script("clipperExample2.m"); + matlabBridge::TPolygon b1("g+-"); + matlabBridge::TPolygon b2("b+-"); + populate(b1,polyA); + populate(b2,polyB); + b1.close( ); + b2.close( ); + script << matlabBridge::FigureName("clipperReq2") << b1 << b2; + for (ClipperLib::Paths::const_iterator pIter = results.begin( ); pIter != results.end( );++pIter) { + matlabBridge::TPolygon ans("r"); + ClipperLib::Path answer = *pIter; + populate(ans,answer); + ans.close( ); + script << ans; + } + script << std::flush; +#endif +} +TEST(clipper,dual){ + using namespace ClipperLib; + + ClipperLib::Path a; + ClipperLib::Path b; ClipperLib::Path c; a.push_back(IntPoint(955761822,-241173480)); b.push_back(IntPoint(320030083,292990926)); @@ -3965,12 +3966,12 @@ TEST(clipper,dual){ b.push_back(IntPoint(325351769,292403333)); b.push_back(IntPoint(322692079,292707573)); b.push_back(IntPoint(320030083,292990926)); - + a.push_back(IntPoint(955761822,-241173480)); a.push_back(IntPoint(866438292,-223308774)); a.push_back(IntPoint(669926526,-223308774)); a.push_back(IntPoint(669926526,-241173480)); - + c.push_back(IntPoint(759250056,-205444067)); c.push_back(IntPoint(669926526,-205444068)); c.push_back(IntPoint(669926526,-223308774)); @@ -3978,50 +3979,50 @@ TEST(clipper,dual){ c.push_back(IntPoint(759250056,-223308774)); c.push_back(IntPoint(759250056,-205444067)); - - Clipper c1; - bool r = c1.AddPath(a,ptSubject,true); - assert(r); - r = c1.AddPath(b,ptClip,true); - assert(r); - Polygons results1; - r = c1.Execute(ctIntersection ,results1,pftEvenOdd,pftEvenOdd); - assert(r); - - Clipper c2; - r = c2.AddPath(c,ptSubject,true); - assert(r); - r = c2.AddPath(b,ptClip,true); - assert(r); - Polygons results2; - r = c2.Execute(ctIntersection ,results2,pftEvenOdd,pftEvenOdd); - assert(r); - - - std::ofstream script("dual.m"); - matlabBridge::TPolygon b1("g+"); - matlabBridge::TPolygon b2("b+"); - matlabBridge::TPolygon b3("c+"); - populate(b1,a); - populate(b2,b); - populate(b3,c); - b1.close( ); - b2.close( ); - b2.close( ); - script << matlabBridge::FigureName("dual") << b2 << b1 << b3; - for (ClipperLib::Paths::const_iterator pIter = results1.begin( ); pIter != results1.end( );++pIter) { - matlabBridge::TPolygon ans1("r+-"); - ClipperLib::Path answer = *pIter; - populate(ans1,answer); - ans1.close( ); - script << ans1; - } - for (ClipperLib::Paths::const_iterator pIter = results2.begin( ); pIter != results2.end( );++pIter) { - matlabBridge::TPolygon ans2("k+-"); - ClipperLib::Path answer = *pIter; - populate(ans2,answer); - ans2.close( ); - script << ans2; - } - script << std::flush; -} + + Clipper c1; + bool r = c1.AddPath(a,ptSubject,true); + assert(r); + r = c1.AddPath(b,ptClip,true); + assert(r); + Polygons results1; + r = c1.Execute(ctIntersection ,results1,pftEvenOdd,pftEvenOdd); + assert(r); + + Clipper c2; + r = c2.AddPath(c,ptSubject,true); + assert(r); + r = c2.AddPath(b,ptClip,true); + assert(r); + Polygons results2; + r = c2.Execute(ctIntersection ,results2,pftEvenOdd,pftEvenOdd); + assert(r); + + + std::ofstream script("dual.m"); + matlabBridge::TPolygon b1("g+"); + matlabBridge::TPolygon b2("b+"); + matlabBridge::TPolygon b3("c+"); + populate(b1,a); + populate(b2,b); + populate(b3,c); + b1.close( ); + b2.close( ); + b2.close( ); + script << matlabBridge::FigureName("dual") << b2 << b1 << b3; + for (ClipperLib::Paths::const_iterator pIter = results1.begin( ); pIter != results1.end( );++pIter) { + matlabBridge::TPolygon ans1("r+-"); + ClipperLib::Path answer = *pIter; + populate(ans1,answer); + ans1.close( ); + script << ans1; + } + for (ClipperLib::Paths::const_iterator pIter = results2.begin( ); pIter != results2.end( );++pIter) { + matlabBridge::TPolygon ans2("k+-"); + ClipperLib::Path answer = *pIter; + populate(ans2,answer); + ans2.close( ); + script << ans2; + } + script << std::flush; +} diff --git a/MBSolver/Tests/distancetest.cpp b/MBSolver/Tests/distancetest.cpp index 6a97c4c2b..1638de060 100644 --- a/MBSolver/Tests/distancetest.cpp +++ b/MBSolver/Tests/distancetest.cpp @@ -1,3 +1,4 @@ +#include #include "gtest/gtest.h" #include using std::cout; @@ -8,8 +9,10 @@ TEST(distance,basic) { int64_t biggest = std::numeric_limits::max( ); int64_t okay = DefaultDistancePolicy::convert(biggest); ASSERT_TRUE(okay == biggest); - // jcs: switched test to long double, a double cannot hold int64_t max+1 without underflow, using long double + // jcs: switched test to long double, a double cannot hold int64_t max+1 without overflow, using long double long double tooBig = static_cast(biggest) + 1; +#ifndef __arm64__ // jcs: arm64 does has only 64-bit long double, so this test will fail ASSERT_THROW(DefaultDistancePolicy::convert(tooBig),std::domain_error); +#endif cout << okay << endl; } diff --git a/MBSolver/Tests/hdf5test.cpp b/MBSolver/Tests/hdf5test.cpp index 50bf97a0e..77c1bdae8 100644 --- a/MBSolver/Tests/hdf5test.cpp +++ b/MBSolver/Tests/hdf5test.cpp @@ -1,5 +1,6 @@ #pragma warning ( disable : 4996 ) #include +#include #include "gtest/gtest.h" #include #include diff --git a/MBSolver/Tests/numerictest.cpp b/MBSolver/Tests/numerictest.cpp index f8268d47f..645bbfd7e 100644 --- a/MBSolver/Tests/numerictest.cpp +++ b/MBSolver/Tests/numerictest.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include using std::cout; using std::endl; @@ -22,26 +23,26 @@ TEST(vcell_util,convert) { ASSERT_TRUE(ConvertUp(4.1) == 4.1); ASSERT_TRUE(ConvertDown(4.1) == 4.1); } -TEST(vcell_util,valid) { - short maxS = std::numeric_limits::max( ); - short f1 = 30; - short f2 = maxS / f1; - ASSERT_TRUE(validMultiply(f1,f2)); - ++f2; - ASSERT_FALSE(validMultiply(f1,f2)); - -} -//namespace { -// void testc(const char *c) { -// char *end; -// unsigned long ul = std::strtoul(c,&end,10); -// int len = end - c; -// cout << "in " << c << " out " << ul << " length " << len << endl; -// } -//} -//TEST(vcell_util,conversion) { -// testc("4"); -// testc("3dognight"); -// testc("-4"); -// testc("cat"); -//} +TEST(vcell_util,valid) { + short maxS = std::numeric_limits::max( ); + short f1 = 30; + short f2 = maxS / f1; + ASSERT_TRUE(validMultiply(f1,f2)); + ++f2; + ASSERT_FALSE(validMultiply(f1,f2)); + +} +//namespace { +// void testc(const char *c) { +// char *end; +// unsigned long ul = std::strtoul(c,&end,10); +// int len = end - c; +// cout << "in " << c << " out " << ul << " length " << len << endl; +// } +//} +//TEST(vcell_util,conversion) { +// testc("4"); +// testc("3dognight"); +// testc("-4"); +// testc("cat"); +//} diff --git a/MBSolver/Tests/v64.cpp b/MBSolver/Tests/v64.cpp index 10e684fc1..83a244445 100644 --- a/MBSolver/Tests/v64.cpp +++ b/MBSolver/Tests/v64.cpp @@ -1,6 +1,7 @@ #ifdef LATER #pragma warning (disable: 4996 4267) #include +#include #include #include #include diff --git a/MBSolver/Tests/versiontest.cpp b/MBSolver/Tests/versiontest.cpp deleted file mode 100644 index 03a5d7b43..000000000 --- a/MBSolver/Tests/versiontest.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include "gtest/gtest.h" -TEST(version,basic) { - const vcell_util::Version & version = vcell_util::Version::get( ); - std::cout << version.svn << ' ' << version.compileDate << ' ' << version.compileTime << std::endl; - -} diff --git a/MBSolver/Tests/worldtest.cpp b/MBSolver/Tests/worldtest.cpp index 9f8cf56f4..a1fef1bd7 100644 --- a/MBSolver/Tests/worldtest.cpp +++ b/MBSolver/Tests/worldtest.cpp @@ -1,4 +1,5 @@ #include +#include #include "gtest/gtest.h" #include #include diff --git a/MBSolver/matlab/CMakeLists.txt b/MBSolver/matlab/CMakeLists.txt index 1b2fc0c1e..fe94510cf 100755 --- a/MBSolver/matlab/CMakeLists.txt +++ b/MBSolver/matlab/CMakeLists.txt @@ -24,7 +24,6 @@ else (MSVC11) endif (MSVC11) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC") -add_definitions(-DSVNVERSION="16888") include_directories(${MATLAB_INCLUDE_DIR}) add_subdirectory(util) diff --git a/MBSolver/matlab/clipperLink/matlabClipper.cpp b/MBSolver/matlab/clipperLink/matlabClipper.cpp index eabbab773..cb0df4abd 100644 --- a/MBSolver/matlab/clipperLink/matlabClipper.cpp +++ b/MBSolver/matlab/clipperLink/matlabClipper.cpp @@ -1,6 +1,4 @@ #include -#include -#include "svnversion.h" #include "matlabStruct.h" #include #include "explore.h" diff --git a/MBSolver/matlab/clipperLink/mexClipper.cpp b/MBSolver/matlab/clipperLink/mexClipper.cpp index 11c97f39a..ec0bbd976 100644 --- a/MBSolver/matlab/clipperLink/mexClipper.cpp +++ b/MBSolver/matlab/clipperLink/mexClipper.cpp @@ -1,6 +1,4 @@ #include -#include -#include "svnversion.h" #include "matlabStruct.h" #include #include "explore.h" @@ -11,7 +9,6 @@ #define WIN32_LEAN_AND_MEAN #include #endif -SVN_VERSION_TAG using spatial::Point2D; void mexFunctionClipper(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { @@ -39,7 +36,7 @@ void mexFunctionClipper(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs { const bool showVer = mls.boolean("version", false); if (showVer) { - mexPrintf("Moving Boundary version %s\n",svn_version_string); + mexPrintf("Moving Boundary version %s\n","unknown - integrate with github version - TODO"); } } typedef matlabLink::MData DS; diff --git a/MBSolver/matlab/fronTierLink/flink.cpp b/MBSolver/matlab/fronTierLink/flink.cpp index 24a2d628e..fa007ac62 100755 --- a/MBSolver/matlab/fronTierLink/flink.cpp +++ b/MBSolver/matlab/fronTierLink/flink.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include //#include using std::vector; @@ -18,7 +17,6 @@ namespace Frontier { } } namespace { - SVN_VERSION_TAG; //slot in std::vector fronts; @@ -292,7 +290,7 @@ void showHelp( ) { const char * const variant = "debug"; #endif - help << "link library " << svn_version_string << ' ' << variant << endl; + help << "link library " << variant << endl; help << std::ends; std::string helpString = help.str( ); // create string on stack to keep c_str pointer valid until end of function diff --git a/MBSolver/matlab/fronTierLink/winbuild.m b/MBSolver/matlab/fronTierLink/winbuild.m index 2db780f38..cab032c84 100755 --- a/MBSolver/matlab/fronTierLink/winbuild.m +++ b/MBSolver/matlab/fronTierLink/winbuild.m @@ -3,4 +3,4 @@ %% Fei's command -mex fronTierCmd.cpp flink.cpp ../util/matlabStruct.cpp ../util/VCDictionary.cpp ../util/mlAssert.cpp -I../util -I../../Solver/include -I../../FronTierLib -I../../FronTierLib/util -I../../vcommons/include -DSVNVERSION="16888" ../FronTierReference/FronTier_64b.lib \ No newline at end of file +mex fronTierCmd.cpp flink.cpp ../util/matlabStruct.cpp ../util/VCDictionary.cpp ../util/mlAssert.cpp -I../util -I../../Solver/include -I../../FronTierLib -I../../FronTierLib/util -I../../vcommons/include ../FronTierReference/FronTier_64b.lib \ No newline at end of file diff --git a/MBSolver/matlab/util/matlabStruct.cpp b/MBSolver/matlab/util/matlabStruct.cpp index f099bf374..87ce39198 100644 --- a/MBSolver/matlab/util/matlabStruct.cpp +++ b/MBSolver/matlab/util/matlabStruct.cpp @@ -1,9 +1,7 @@ #include #include "matlabStruct.h" #include "matlabAssert.h" -#include "svnversion.h" #include "vcGccCompat.h" -SVN_VERSION_TAG using matlabLink::MatlabStruct; using matlabLink::MData; diff --git a/MBSolver/matlab/util/svnversion.h b/MBSolver/matlab/util/svnversion.h deleted file mode 100644 index 72ab4ac6f..000000000 --- a/MBSolver/matlab/util/svnversion.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef svnversion_h -#define svnversion_h -#if !defined(SVNVERSION) -#error SVNVERSION version not defined -#endif -#define VCELLSVNQ(x) #x -#define VCELLSVNQUOTE(x) VCELLSVNQ(x) -//#define SVN_VERSION_TAG static const char * const svn_version_string = __FILE__"SVN_version:"VSTR(SVNVERSION) ; -#define SVN_VERSION_TAG static const char * const svn_version_string = __FILE__ " " __DATE__ "SVN_version: " VCELLSVNQUOTE(SVNVERSION); -#endif diff --git a/NFsim_v1.11/VCell/src/VCellNFSim.cpp b/NFsim_v1.11/VCell/src/VCellNFSim.cpp index 6562606c0..d1807a563 100644 --- a/NFsim_v1.11/VCell/src/VCellNFSim.cpp +++ b/NFsim_v1.11/VCell/src/VCellNFSim.cpp @@ -23,7 +23,7 @@ namespace { bool startupMessaging(int argc, char **argv, vcell::JMSHolder & holder); int nfsimExit(int returnCode, const std::string& errorMsg); void printUsage(); - int parseInteger(const char * input); + int parseTaskId(const char * input); const int unsetTaskId = -1; inline void noop( ) {} /** @@ -102,9 +102,9 @@ void printUsage() { << std::endl; } -int parseInteger(const char * input) { - if (input != 0) { - const int eos = strlen(input); +int parseTaskId(const char * input) { + if (input != nullptr) { + const size_t eos = strlen(input); for (int i = 0; i < eos; i++) { const char c = input[i]; if ((c < '0') || (c > '9')) { @@ -114,6 +114,8 @@ int parseInteger(const char * input) { } return atoi(input); } + // should never reach this code + return unsetTaskId; } /* # JMS_Paramters @@ -166,7 +168,7 @@ bool startupMessaging(int argc, char **argv, vcell::JMSHolder & holder) { const int penultimate = argc - 1; for (int i = 0; i < penultimate; i++) { if (strcmp(argv[i], "-tid") == 0) { - taskId = parseInteger(argv[i + 1]); + taskId = parseTaskId(argv[i + 1]); } if (strcmp(argv[i], "-xml") == 0) { inputFilename = argv[i + 1]; diff --git a/NFsim_v1.11/src/NFcore/NFcore.hh b/NFsim_v1.11/src/NFcore/NFcore.hh index 5108d972e..cf5de0618 100644 --- a/NFsim_v1.11/src/NFcore/NFcore.hh +++ b/NFsim_v1.11/src/NFcore/NFcore.hh @@ -282,14 +282,14 @@ namespace NFcore void setUniversalTraversalLimit(int utl); - bool isUsingVCellCompartments() { return useVCellCompartments; }; - bool setUsingVCellCompartments( bool val ) { useVCellCompartments = val; }; + bool isUsingVCellCompartments() const { return useVCellCompartments; }; + void setUsingVCellCompartments( bool val ) { useVCellCompartments = val; }; - bool hasVCellAnchors() { return this->bHasVCellAnchors; }; - bool setVCellAnchors( bool val ) { this->bHasVCellAnchors = val; }; + bool hasVCellAnchors() const { return this->bHasVCellAnchors; }; + void setVCellAnchors( bool val ) { this->bHasVCellAnchors = val; }; - bool isCheckingProductMaching() { return this->bCheckingProductMatching; }; - bool setCheckingProductMaching( bool val ) { this->bCheckingProductMatching = val; }; + bool isCheckingProductMaching() const { return this->bCheckingProductMatching; }; + void setCheckingProductMaching( bool val ) { this->bCheckingProductMatching = val; }; void setEvaluateComplexScopedLocalFunctions( bool val ) { evaluateComplexScopedLocalFunctions = val; }; bool getEvaluateComplexScopedLocalFunctions( ) const { return evaluateComplexScopedLocalFunctions; }; diff --git a/NFsim_v1.11/src/NFfunction/muParser/muParserBase.cpp b/NFsim_v1.11/src/NFfunction/muParser/muParserBase.cpp index 5db154684..0ea56541e 100644 --- a/NFsim_v1.11/src/NFfunction/muParser/muParserBase.cpp +++ b/NFsim_v1.11/src/NFfunction/muParser/muParserBase.cpp @@ -48,7 +48,7 @@ namespace mu When defining custom binary operators with #AddOprt(...) make sure not to choose names conflicting with these definitions. */ - char_type* ParserBase::c_DefaultOprt[] = + const char_type* ParserBase::c_DefaultOprt[] = { _T("<="), _T(">="), _T("!="), _T("=="), _T("<"), _T(">"), diff --git a/NFsim_v1.11/src/NFfunction/muParser/muParserBase.h b/NFsim_v1.11/src/NFfunction/muParser/muParserBase.h index ae7f56270..e4f6b7cac 100644 --- a/NFsim_v1.11/src/NFfunction/muParser/muParserBase.h +++ b/NFsim_v1.11/src/NFfunction/muParser/muParserBase.h @@ -194,7 +194,7 @@ friend class ParserTokenReader; virtual void InitConst() = 0; virtual void InitOprt() = 0; - static char_type *c_DefaultOprt[]; + static const char_type *c_DefaultOprt[]; private: @@ -244,7 +244,7 @@ friend class ParserTokenReader; mutable stringbuf_type m_vStringBuf; ///< String buffer, used for storing string function arguments stringbuf_type m_vStringVarBuf; - std::auto_ptr m_pTokenReader; ///< Managed pointer to the token reader object. + std::unique_ptr m_pTokenReader; ///< Managed pointer to the token reader object. funmap_type m_FunDef; ///< Map of function names and pointers. funmap_type m_PostOprtDef; ///< Postfix operator callbacks diff --git a/NFsim_v1.11/src/NFfunction/muParser/muParserToken.h b/NFsim_v1.11/src/NFfunction/muParser/muParserToken.h index bf0ca9754..f5fe14c06 100644 --- a/NFsim_v1.11/src/NFfunction/muParser/muParserToken.h +++ b/NFsim_v1.11/src/NFfunction/muParser/muParserToken.h @@ -78,7 +78,7 @@ namespace mu TString m_strTok; ///< Token string TString m_strVal; ///< Value for string variables value_type m_fVal; - std::auto_ptr m_pCallback; + std::unique_ptr m_pCallback; public: diff --git a/NFsim_v1.11/src/NFfunction/muParser/muParserTokenReader.cpp b/NFsim_v1.11/src/NFfunction/muParser/muParserTokenReader.cpp index 1b42621e3..92cbade30 100644 --- a/NFsim_v1.11/src/NFfunction/muParser/muParserTokenReader.cpp +++ b/NFsim_v1.11/src/NFfunction/muParser/muParserTokenReader.cpp @@ -145,7 +145,7 @@ namespace mu */ ParserTokenReader* ParserTokenReader::Clone(ParserBase *a_pParent) const { - std::auto_ptr ptr(new ParserTokenReader(*this)); + std::unique_ptr ptr(new ParserTokenReader(*this)); ptr->SetParent(a_pParent); return ptr.release(); } @@ -807,7 +807,7 @@ namespace mu m_pParser->m_vStringBuf.push_back(strTok); // Store string in internal buffer a_Tok.SetString(strTok, m_pParser->m_vStringBuf.size()); - m_iPos += (int)strTok.length() + 2 + (int)iSkip; // +2 wg Anführungszeichen; +iSkip für entfernte escape zeichen + m_iPos += (int)strTok.length() + 2 + (int)iSkip; // +2 wg Anf�hrungszeichen; +iSkip f�r entfernte escape zeichen m_iSynFlags = m_iSynFlags = noANY ^ ( noARG_SEP | noBC | noOPT | noEND ); return true; diff --git a/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp b/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp index ee6de8db7..f787168bc 100644 --- a/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp +++ b/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp @@ -124,6 +124,7 @@ TransformationSet::getTemplateMolecule( unsigned int reactantIndex ) const { return addmol[reactantIndex-n_reactants]; } + return nullptr; } diff --git a/NFsim_v1.11/src/NFscheduler/Scheduler.cpp b/NFsim_v1.11/src/NFscheduler/Scheduler.cpp index 208fec135..a8e1fefdd 100644 --- a/NFsim_v1.11/src/NFscheduler/Scheduler.cpp +++ b/NFsim_v1.11/src/NFscheduler/Scheduler.cpp @@ -268,20 +268,6 @@ void findandreplace(string &source, string find, string replace) { } } -const char* itoa(int inNum) { - stringstream strout; - strout << inNum; - strout.flush(); - return strout.str().data(); -} - -const char* dtoa(double inNum) { - stringstream strout; - strout << inNum; - strout.flush(); - return strout.str().data(); -} - // MPI communication routines void send_to_slave(int slave, int tag, int datalen, char *data) { msg.src = MASTER; @@ -333,25 +319,25 @@ void recv_from_master() { #endif } -void job2str(job& j, char* p) { - sprintf(p, "%s,", j.filename.c_str()); p += strlen(p); - sprintf(p, "%d,", j.processors); p += strlen(p); +void job2str(job &j, char *p, size_t buf_size) { + snprintf(p, buf_size, "%s,", j.filename.c_str()); buf_size -= strlen(p); p += strlen(p); + snprintf(p, buf_size, "%d,", j.processors); buf_size -= strlen(p); p += strlen(p); int argc = j.argument.size(); - sprintf(p, "%d,", argc); p += strlen(p); + snprintf(p, buf_size, "%d,", argc); buf_size -= strlen(p); p += strlen(p); if (argc > 0) { for (int i = 0; i < argc; ++i) { - sprintf(p, "%s,", j.argument[i].c_str()); p += strlen(p); - sprintf(p, "%s,", j.argval[i].c_str()); p += strlen(p); + snprintf(p, buf_size, "%s,", j.argument[i].c_str()); buf_size -= strlen(p); p += strlen(p); + snprintf(p, buf_size, "%s,", j.argval[i].c_str()); buf_size -= strlen(p); p += strlen(p); } } int n = j.parameters.size(); - sprintf(p, "%d,", n); p += strlen(p); + snprintf(p, buf_size, "%d,", n); buf_size -= strlen(p); p += strlen(p); if (n > 0) { for (int i = 0; i < n; ++i) { - sprintf(p, "%s,", j.parameters[i].c_str()); p += strlen(p); - sprintf(p, "%lg,", j.values[i]); p += strlen(p); + snprintf(p, buf_size, "%s,", j.parameters[i].c_str()); buf_size -= strlen(p); p += strlen(p); + snprintf(p, buf_size, "%lg,", j.values[i]); buf_size -= strlen(p); p += strlen(p); } } } @@ -533,7 +519,7 @@ void DynamicParallel (map argMap,int rank,int size) { if (!done) { printf("master: assigning work #%d to slave #%d \n", jcount, msg.src); char str[MSG_DATA_SIZE]; - job2str(jnow, str); + job2str(jnow, str, MSG_DATA_SIZE); slave_assignment[msg.src] = pjob; send_to_slave(msg.src, cmd_job, strlen(str)+1, str); } else { @@ -577,7 +563,7 @@ void DynamicParallel (map argMap,int rank,int size) { slave_work(rank, jnow); for (int i = 0; i < slave_filenames.size(); ++i) { - sprintf(str, "%d,%s", slave_buffers[i].length()+1, slave_filenames[i].c_str()); + snprintf(str, sizeof(str), "%zu,%s", slave_buffers[i].length()+1, slave_filenames[i].c_str()); send_to_master(rank, rpt_pre_data, strlen(str)+1, str); recv_from_master(); if (msg.tag != cmd_pre_data_ack) perr("Error: expecting cmd_pre_data_ack"); diff --git a/NFsim_v1.11/src/nauty24/nauty.c b/NFsim_v1.11/src/nauty24/nauty.c index 26adcdfe0..1047a1029 100644 --- a/NFsim_v1.11/src/nauty24/nauty.c +++ b/NFsim_v1.11/src/nauty24/nauty.c @@ -881,7 +881,7 @@ processnode(int *lab, int *ptn, int level, int numcells) (*dispatch.isautom)(g,workperm,digraph,M,n)) code = 1; } - if (code == 0) + if (code == 0) { if (getcanon) { sr = 0; @@ -910,6 +910,7 @@ processnode(int *lab, int *ptn, int level, int numcells) } else code = 4; + } } if (code != 0 && level > stats->maxlevel) stats->maxlevel = level; diff --git a/Stochastic/CMakeLists.txt b/Stochastic/CMakeLists.txt index 960a40255..a6c6faa26 100644 --- a/Stochastic/CMakeLists.txt +++ b/Stochastic/CMakeLists.txt @@ -35,12 +35,18 @@ endif() #include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../vcommons/include) #include_directories(${VCELL_MESSAGING_INCLUDE_DIR}) if (APPLE) - link_directories("/usr/local/Cellar/hdf5/1.14.1/lib") + execute_process(COMMAND uname -m OUTPUT_VARIABLE PROCESSOR_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) + message("Processor Architecture: ${PROCESSOR_ARCHITECTURE}") + if (PROCESSOR_ARCHITECTURE STREQUAL "arm64") + link_directories("/opt/homebrew/lib") + else () + link_directories("/usr/local/Cellar/hdf5/1.14.3_1/lib") + endif() endif() # PETSC_ARCH is defined as ENV var in https://hub.docker.com/r/virtualcell/vcell-solvers/dockerfile basefile -# we must be in the docker vcell-solvers environment if PETSC_ARCH is defined -if (DEFINED ENV{PETSC_ARCH}) +# so we must be in the docker vcell-solvers environment if PETSC_ARCH is defined +if (DEFINED ENV{PETSC_ARCH} OR LINUX) include_directories(/usr/include/hdf5/serial) link_directories("/usr/lib/x86_64-linux-gnu/hdf5/serial") endif() diff --git a/Stochastic/Tests/statstest.cpp b/Stochastic/Tests/statstest.cpp index faf219f94..927de3116 100644 --- a/Stochastic/Tests/statstest.cpp +++ b/Stochastic/Tests/statstest.cpp @@ -97,63 +97,62 @@ const std::map expected_S0 = { }; TEST(statstest,test1) { - char *temp_input_file_name = new char[200] {0}; - char *temp_output_file_name = new char[200] {0}; - std::string in_prefix = testing::TempDir() + "input_XXXXXX"; - std::string out_prefix = testing::TempDir() + "output_XXXXXX"; - strncpy(temp_input_file_name, in_prefix.c_str(), in_prefix.length()); - strncpy(temp_output_file_name, out_prefix.c_str(), out_prefix.length()); - assert(mkstemp(temp_input_file_name) != -1); - assert(mkstemp(temp_output_file_name) != -1); - std::ofstream input_file (temp_input_file_name); - bool bWroteFile = false; - if (input_file.is_open()){ - input_file << input_file_contents; - input_file.close(); - bWroteFile = true; - } - ASSERT_TRUE(bWroteFile); - - Gibson *gb= new Gibson(temp_input_file_name, temp_output_file_name); + std::string inputFileName = std::tmpnam(nullptr); + std::string outputFileName = std::tmpnam(nullptr); + std::map results; + std::fstream inputFileStream; + inputFileStream.open(inputFileName, std::fstream::out); + if (inputFileStream.fail()) { + std::perror(("File <" + inputFileName + "> could not be created.").c_str()); + ASSERT_FALSE(inputFileStream.fail()); + } + std::fstream outputFileStream; + outputFileStream.open(outputFileName, std::fstream::out); + if (outputFileStream.fail()) { + std::perror(("File <" + inputFileName + "> could not be created.").c_str()); + ASSERT_FALSE(outputFileStream.fail()); + } + + // Setup the Gibson Solver input file + if (outputFileStream.is_open()) outputFileStream.close(); + inputFileStream << input_file_contents; + inputFileStream.close(); + + // Create the Gibson Solver + auto *gb = new Gibson(inputFileName.c_str(), outputFileName.c_str()); + + // Launch the test gb->march(); - // verify file contents - std::ifstream outfile(temp_output_file_name); - string line; - getline(outfile, line); // remove header line -// std::cout << line << std::endl; -// std::cout.flush(); - - std::map results; - int i = 0; - while (getline(outfile, line)){ - // if index found in expected_S0 map, store in results map - if (expected_S0.find(i) != expected_S0.end()){ - float t, s0, s1, s2; - // extract space separated values for t, s0, s1 and s2 from line - std::stringstream line_stream(line); - line_stream >> t >> s0 >> s1 >> s2; - results[i] = s0; -// std::cout << line << std::endl; -// std::cout.flush(); - } - i++; - } - // compare the expected and actual values - double accum_error = 0.0; - double max_error = 0.0; + // Verify file contents + outputFileStream.open(outputFileName, std::fstream::in); + std::string line; + std::getline(outputFileStream, line); // remove header line + for (int i = 0; !outputFileStream.eof(); i++) { + std::getline(outputFileStream, line); + // if index found in expected_S0 map, store in results map + if (expected_S0.find(i) != expected_S0.end()){ + float t, s0, s1, s2; + // extract space separated values for t, s0, s1 and s2 from line + std::stringstream line_stream(line); + line_stream >> t >> s0 >> s1 >> s2; + results[i] = s0; + } + } + outputFileStream.close(); + + // compare the expected and actual values + double accumulatedError = 0.0, maxIndividualError = 0.0; for (auto const& expected : expected_S0){ - double s0_given = expected.second; - double s0_computed = results[expected.first]; - double abserr = std::abs(s0_given - s0_computed); -// std::cout << "t=" << expected.first << " expected=" << s0_given << " computed=" << s0_computed << " abserr=" << abserr << std::endl; - accum_error += abserr; - max_error = std::max(max_error, abserr); + double absoluteError = std::abs(expected.second - results[expected.first]); + // std::cout << "t=" << expected.first << " expected=" << expected.second << " computed=" << results[expected.first] << " abserr=" << abserr << std::endl; + accumulatedError += absoluteError; + maxIndividualError = std::max(maxIndividualError, absoluteError); } - assert(accum_error < 0.015); - assert(max_error < 0.005); + assert(accumulatedError < 0.015); + assert(maxIndividualError < 0.005); delete gb; - delete[] temp_input_file_name; - delete[] temp_output_file_name; + if (inputFileStream.is_open()) inputFileStream.close(); + if (outputFileStream.is_open()) outputFileStream.close(); } \ No newline at end of file diff --git a/Stochastic/VCellStoch/include/Gibson.h b/Stochastic/VCellStoch/include/Gibson.h index ea8b27a4f..3e1f62666 100644 --- a/Stochastic/VCellStoch/include/Gibson.h +++ b/Stochastic/VCellStoch/include/Gibson.h @@ -3,7 +3,6 @@ #include #include -using std::ofstream; #include "StochModel.h" #include "MultiTrialStats.h" @@ -39,7 +38,7 @@ class Gibson : public StochModel{ private: IndexedTree *Tree; //the data structure(binary tree) to store all the processes and make each parent smaller than it's children. double* currvals;//array of variable values to be used by expression parser. variables are stored in vector listOfVars. - ofstream outfile; //the output file stream where the results are saved. + std::ofstream outfile; //the output file stream where the results are saved. const char* outfilename;//the output file name. bool flag_savePeriod;//the flag for using save period. int finalizeSampleRow(int,double);//central location to call to complete 1 output sample to file diff --git a/Stochastic/VCellStoch/src/Gibson.cpp b/Stochastic/VCellStoch/src/Gibson.cpp index 9f50aa25f..1461c1192 100644 --- a/Stochastic/VCellStoch/src/Gibson.cpp +++ b/Stochastic/VCellStoch/src/Gibson.cpp @@ -10,13 +10,14 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include #include using namespace std; -#include +#include #include "../include/IndexedTree.h" #ifdef USE_MESSAGING @@ -26,18 +27,19 @@ using namespace std; const double double_infinity = numeric_limits::infinity(); const double EPSILON = 1E-12; const string Gibson::MY_T_STR = "t"; + /* *Empty constructor of Gibson. It will use the defalt settings in StochModel. */ Gibson::Gibson() - :StochModel(), - savedSampleCount(1), - lastTime (std::numeric_limits::min( )) -{ - Tree=NULL; - currvals=NULL; + : savedSampleCount(1), lastTime (std::numeric_limits::min()) { + Tree = NULL; + currvals = NULL; generator = new std::mt19937_64(); distribution = new std::uniform_real_distribution(0.0,1.0); +#ifdef USE_MESSAGING + SimulationMessaging::create(); +#endif }//end of constructor Gibson() /* @@ -46,17 +48,8 @@ Gibson::Gibson() *Input para: srting, the input file(name), where the model info. is read. * string, the output file(name), where the results are saved. */ -Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) - :StochModel(), - savedSampleCount(1), - lastTime (std::numeric_limits::min( )) -{ - Tree=NULL; - currvals=NULL; - generator = new std::mt19937_64(); - distribution = new std::uniform_real_distribution(0.0,1.0); - - outfilename=arg_outfilename; +Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) : Gibson(){ // Use delegating constructor + this->outfilename = arg_outfilename; ifstream infile; string instring; @@ -69,56 +62,33 @@ Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) while(infile >> instring) { //load control info. - if (instring == "STARTING_TIME") - { + if (instring == "STARTING_TIME"){ infile >> STARTING_TIME; - } - else if (instring == "BMULTIBUTNOTHISTO") - { + } else if (instring == "BMULTIBUTNOTHISTO"){ infile >> bMultiButNotHisto; - } - else if (instring == "ENDING_TIME") - { + } else if (instring == "ENDING_TIME"){ infile >> ENDING_TIME; - } - else if (instring == "SAVE_PERIOD") - { + } else if (instring == "SAVE_PERIOD"){ infile >> SAVE_PERIOD; flag_savePeriod=true; - } - else if (instring == "MAX_ITERATION") - { + } else if (instring == "MAX_ITERATION"){ infile >> MAX_ITERATION; - } - else if (instring == "TOLERANCE") - { + } else if (instring == "TOLERANCE"){ infile >> TOLERANCE; - } - else if (instring == "SAMPLE_INTERVAL") - { + } else if (instring == "SAMPLE_INTERVAL"){ infile >> SAMPLE_INTERVAL; - } - else if (instring == "MAX_SAVE_POINTS") - { + } else if (instring == "MAX_SAVE_POINTS"){ infile >> MAX_SAVE_POINTS; - } - else if (instring == "NUM_TRIAL") - { + } else if (instring == "NUM_TRIAL"){ infile >> NUM_TRIAL; - } - else if (instring == "SEED") - { + } else if (instring == "SEED"){ infile >> SEED; - } - //load listofvars - else if (instring == "TotalVars") - { + } else if (instring == "TotalVars"){ //load listofvars int varCount; infile >> varCount; string name; double amount; - for(int i=0;i> name; infile >> amount; listOfVarNames.push_back(name); @@ -126,10 +96,7 @@ Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) StochVar *var=new StochVar((uint64_t)amount); listOfVars.push_back(var); } - } - //load listOfProcesses - else if (instring == "TotalProcesses") - { + } else if (instring == "TotalProcesses"){ //load listOfProcesses int pCount; infile >> pCount; string name; @@ -140,15 +107,11 @@ Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) Jump *jp=new Jump(); listOfProcesses.push_back(jp); } - } - //load process description to set up processes - else if (instring == "TotalDescriptions") - { + } else if (instring == "TotalDescriptions") { //load process description to set up processes int dCount,idx; infile >> dCount; string name,str; - for(int i=0;i> name >> name;// "process name" //find the process in listOfProcesses using it's name idx=getProcessIndex(name); @@ -201,10 +164,9 @@ Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) } } //setup IndexedTree - Tree=new IndexedTree(); - for(int i=0;iaddProcess(listOfProcesses[i]); + Tree = new IndexedTree(); + for(auto & listOfProcesse : listOfProcesses){ + Tree->addProcess(listOfProcesse); } infile.close(); if (NUM_TRIAL > MAX_ALLOWED_POINTS) { @@ -214,7 +176,6 @@ Gibson::Gibson(const char* arg_infilename, const char* arg_outfilename) VCELL_EXCEPTION(invalid_argument,"Stochastic initialization: Server save points " << MAX_SAVE_POINTS << " exceeds limit of " << MAX_ALLOWED_POINTS); } - if(NUM_TRIAL > 1 && !bMultiButNotHisto){ //this must be a gibson 'histogram' sim, //java gui not allow setting of MAX_SAVE_POINTS and default is too low @@ -270,12 +231,12 @@ Gibson::~Gibson() //delete indexedTree delete Tree; //delete variables - for(int i=0;ioutfile.open (this->outfilename, ofstream::out);//"c:/gibson_deploy/gibson_deploy/output/gibson_singleTrial.txt" + this->outfile << setprecision(10); // set precision to output file + if(this->bMultiButNotHisto){ // char thebyte[1]; // thebyte[0]=49;//progress char "1" // string ofProg(outfilename); @@ -630,29 +589,28 @@ void Gibson::march() // ofstream outfileProg; // outfileProg.open (ofProg.c_str(),ios::out | ios::app | ios::binary); - numMultiNonHisto = NUM_TRIAL; - NUM_TRIAL = 1;//set to 1 to use single trajectory logic in 'core' + this->numMultiNonHisto = this->NUM_TRIAL; + this->NUM_TRIAL = 1;//set to 1 to use single trajectory logic in 'core' //output file header description for time and variable names - outfile << "t:"; - for (int i = 0; i < listOfVarNames.size(); i++) { - outfile << listOfVarNames.at(i) << ":"; + this->outfile << "t:"; + for (const auto & varName : this->listOfVarNames) { + this->outfile << varName << ":"; } - outfile << endl; + this->outfile << endl; //Execute NUM_TRIALS of core and accumulate the results - for (currMultiNonHistoIter=0; currMultiNonHistoIter < numMultiNonHisto; currMultiNonHistoIter++) - { - generator->seed(currMultiNonHistoIter+SEED); + for (this->currMultiNonHistoIter = 0; this->currMultiNonHistoIter < this->numMultiNonHisto; this->currMultiNonHistoIter++){ + this->generator->seed(this->currMultiNonHistoIter+SEED); //run the simulation - core(); + this->core(); //reset to initial values before next simulation - savedSampleCount = 1; - for(int i=0;isetCurr(listOfIniValues.at(i)); + this->savedSampleCount = 1; + for(int i = 0; i < this->listOfIniValues.size(); i++){ + this->listOfVars[i]->setCurr(this->listOfIniValues.at(i)); } - for(int i=0;isetProcess(i,listOfProcesses.at(i)); + for(int i = 0; i < this->listOfProcesses.size(); i++){ + this->Tree->setProcess(i, this->listOfProcesses.at(i)); } // outfileProg.write((char *)&thebyte,1); // outfileProg.flush(); @@ -660,46 +618,42 @@ void Gibson::march() // outfileProg.close(); //Calc and save averages of accumulated data - for (int timeIndex = 0; timeIndex < multiTrialStats->getNumTimePoints(); ++timeIndex) { + for (int timeIndex = 0; timeIndex < this->multiTrialStats->getNumTimePoints(); ++timeIndex) { //timepoint - outfile << multiTrialStats->getTimePoint(timeIndex) << "\t"; - for (int varIndex = 0; varIndex < multiTrialStats->getNumVars(); ++varIndex) { - outfile << multiTrialStats->getMean(varIndex, timeIndex) << "\t"; + this->outfile << this->multiTrialStats->getTimePoint(timeIndex) << "\t"; + for (int varIndex = 0; varIndex < this->multiTrialStats->getNumVars(); ++varIndex) { + this->outfile << this->multiTrialStats->getMean(varIndex, timeIndex) << "\t"; } - outfile << endl; + this->outfile << endl; } - multiTrialStats->writeHDF5(outfilename, listOfVarNames); + this->multiTrialStats->writeHDF5(this->outfilename, this->listOfVarNames); - } - else if(NUM_TRIAL==1) - { - generator->seed(SEED); + } else if(this->NUM_TRIAL==1){ + this->generator->seed(this->SEED); //output file header - outfile << "t:"; - for(int i=0;ioutfile << "t:"; + for(const auto & listOfVarName : this->listOfVarNames){ + this->outfile << listOfVarName << ":"; } - outfile <outfile << endl; //output initial condition at STARTING_TIME - outfile << STARTING_TIME << "\t"; - for(int i=0;ioutfile << this->STARTING_TIME << "\t"; + for(const unsigned long long listOfIniValue : this->listOfIniValues){ + this->outfile << listOfIniValue << "\t"; } outfile << endl; //run the simulation core(); - } - else if (NUM_TRIAL > 1) - { + } else if (this->NUM_TRIAL > 1){ //output file header - outfile << "TrialNo:"; - for(int i=0;ioutfile << "TrialNo:"; + for(const auto & listOfVarName : this->listOfVarNames){ + this->outfile<< listOfVarName << ":"; } - outfile <outfile << endl; + for (long j = this->SEED; j < this->NUM_TRIAL + this->SEED; j++) { #ifdef USE_MESSAGING if (SimulationMessaging::getInstVar()->isStopRequested()) { @@ -710,21 +664,19 @@ void Gibson::march() #ifdef DEBUG cout << "Trial No. " << j <seed(j); + this->generator->seed(j); //output trial number. PS:results after each trial are printed in core() function. - outfile << j-SEED+1;//this expression should evaluate equal to 'savedSampleCount' - core();//this will save 1 row of data ( + this->outfile << j - this->SEED + 1;//this expression should evaluate equal to 'savedSampleCount' + this->core();//this will save 1 row of data ( //reset to initial values before next simulation - for(int i=0;isetCurr(listOfIniValues.at(i)); + for(int i=0; i < this->listOfIniValues.size();i++){ + this->listOfVars[i]->setCurr(this->listOfIniValues.at(i)); } - for(int i=0;isetProcess(i,listOfProcesses.at(i)); + for(int i=0;i < this->listOfProcesses.size();i++){ + this->Tree->setProcess(i, this->listOfProcesses.at(i)); } } - } - else - { + } else { VCELL_EXCEPTION(invalid_argument, "Number of trial smaller than 1!"); } #ifdef DEBUG @@ -734,9 +686,10 @@ void Gibson::march() ntime = (ntime2.QuadPart-ntime1.QuadPart)/(freq.QuadPart/1000); cout << endl << "Total time used(ms): " << ntime; #endif - outfile.close(); + this->outfile.close(); #ifdef USE_MESSAGING + std::cout << "Arrived at goalpost 6" << std::endl; if (!SimulationMessaging::getInstVar()->isStopRequested()) { SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_COMPLETED, 1, ENDING_TIME)); } diff --git a/Stochastic/VCellStoch/src/MultiTrialStats.cpp b/Stochastic/VCellStoch/src/MultiTrialStats.cpp index 990dfb76a..a67e5823b 100644 --- a/Stochastic/VCellStoch/src/MultiTrialStats.cpp +++ b/Stochastic/VCellStoch/src/MultiTrialStats.cpp @@ -5,9 +5,15 @@ #include "MultiTrialStats.h" #include #include +#include +#include #ifdef __APPLE__ -#include "/usr/local/opt/hdf5/include/hdf5.h" + #if __arm__ || __arm64__ + #include "/opt/homebrew/opt/hdf5/include/hdf5.h" + #else + #include "/usr/local/opt/hdf5/include/hdf5.h" + #endif #else #include #endif diff --git a/VCell/include/VCELL/FVDataSet.h b/VCell/include/VCELL/FVDataSet.h index 2404dcc86..869a4df30 100644 --- a/VCell/include/VCELL/FVDataSet.h +++ b/VCell/include/VCELL/FVDataSet.h @@ -12,8 +12,8 @@ class Variable; class FVDataSet { public: - static void read(char *filename, Simulation *sim); - static void write(char *filename, SimulationExpression *sim, bool bCompress); + static void read(const char *filename, Simulation *sim); + static void write(const char *filename, SimulationExpression *sim, bool bCompress); static void convolve(Simulation* sim, Variable* var, double* values); static void readRandomVariables(char* filename, SimulationExpression* sim); }; diff --git a/VCell/include/VCELL/PostProcessingHdf5Writer.h b/VCell/include/VCELL/PostProcessingHdf5Writer.h index 79d44f990..5ef0418c1 100644 --- a/VCell/include/VCELL/PostProcessingHdf5Writer.h +++ b/VCell/include/VCELL/PostProcessingHdf5Writer.h @@ -20,7 +20,7 @@ namespace H5 { class PostProcessingHdf5Writer { public: - PostProcessingHdf5Writer(char* fileName, PostProcessingBlock* postProcessingBlock); + PostProcessingHdf5Writer(std::string fileName, PostProcessingBlock* postProcessingBlock); virtual ~PostProcessingHdf5Writer(); void writeOutput(); diff --git a/VCell/include/VCELL/SimTool.h b/VCell/include/VCELL/SimTool.h index 459988fb3..c584ab0d1 100644 --- a/VCell/include/VCELL/SimTool.h +++ b/VCell/include/VCELL/SimTool.h @@ -122,6 +122,7 @@ class SimTool { void updateLog(double progress,double time,int iteration); void clearLog(); int getZipCount(char* zipFileName); + int getZipCount(const std::string* zipFileName); void start1(); void copyParticleCountsToConcentration(); diff --git a/VCell/include/VCELL/Simulation.h b/VCell/include/VCELL/Simulation.h index 03834462e..22dccbb85 100644 --- a/VCell/include/VCELL/Simulation.h +++ b/VCell/include/VCELL/Simulation.h @@ -50,8 +50,8 @@ class Simulation virtual void advanceTimeOn(); virtual void advanceTimeOff(); - virtual void writeData(char *filename, bool bCompress)=0; - virtual void readData(char *filename); + virtual void writeData(const char *filename, bool bCompress)=0; + virtual void readData(const char *filename); Variable* getVariable(int index); diff --git a/VCell/include/VCELL/SimulationExpression.h b/VCell/include/VCELL/SimulationExpression.h index 22a3b7e37..04283a36b 100644 --- a/VCell/include/VCELL/SimulationExpression.h +++ b/VCell/include/VCELL/SimulationExpression.h @@ -35,7 +35,7 @@ class SimulationExpression : public Simulation void advanceTimeOn(); void advanceTimeOff(); - void writeData(char *filename, bool bCompress); + void writeData(const char *filename, bool bCompress); void addFieldData(FieldData* fd) { fieldDataList.push_back(fd); diff --git a/VCell/src/CartesianMesh.cpp b/VCell/src/CartesianMesh.cpp index 61863bc06..399b2c22f 100644 --- a/VCell/src/CartesianMesh.cpp +++ b/VCell/src/CartesianMesh.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using std::stringstream; using std::cout; using std::endl; diff --git a/VCell/src/DataGenerator.cpp b/VCell/src/DataGenerator.cpp index 66c683637..76c967003 100644 --- a/VCell/src/DataGenerator.cpp +++ b/VCell/src/DataGenerator.cpp @@ -2,6 +2,7 @@ * (C) Copyright University of Connecticut Health Center 2001. * All rights reserved. */ +#include #include #include #include diff --git a/VCell/src/FVDataSet.cpp b/VCell/src/FVDataSet.cpp index b73f1c4ef..457f59955 100644 --- a/VCell/src/FVDataSet.cpp +++ b/VCell/src/FVDataSet.cpp @@ -100,7 +100,7 @@ static string extractVarNameFromQualifiedName(char* varName) { return str; } -void FVDataSet::read(char *filename, Simulation *sim) +void FVDataSet::read(const char *filename, Simulation *sim) { FILE *fp=NULL; FileHeader fileHeader; @@ -267,7 +267,7 @@ void FVDataSet::convolve(Simulation* sim, Variable* var, double* values) { } } -void FVDataSet::write(char *filename, SimulationExpression *sim, bool bCompress) +void FVDataSet::write(const char *filename, SimulationExpression *sim, bool bCompress) { FILE *fp=NULL; FileHeader fileHeader; diff --git a/VCell/src/PostProcessingHdf5Writer.cpp b/VCell/src/PostProcessingHdf5Writer.cpp index 259ca2c07..2167ea131 100644 --- a/VCell/src/PostProcessingHdf5Writer.cpp +++ b/VCell/src/PostProcessingHdf5Writer.cpp @@ -11,6 +11,7 @@ #include #include #include +#include using std::cout; using std::endl; #include @@ -20,8 +21,8 @@ using std::endl; const char* PostProcessingHdf5Writer::PPGroupName = POST_PROCESSING_ROOT; const char* PostProcessingHdf5Writer::TimesDataSetName = POST_PROCESSING_ROOT"/Times"; -PostProcessingHdf5Writer::PostProcessingHdf5Writer(char* fileName, PostProcessingBlock* ppb) { - this->h5PPFileName = fileName; +PostProcessingHdf5Writer::PostProcessingHdf5Writer(std::string fileName, PostProcessingBlock* ppb) { + this->h5PPFileName = std::move(fileName); this->postProcessingBlock = ppb; h5PPFile = NULL; timesDataSet = NULL; @@ -67,7 +68,7 @@ bool PostProcessingHdf5Writer::loadFinal(int numTimes) { // the max time in log file is numTimes // hdf5 is missing times if (timesDim < numTimes) { - cout << "post processing hdf5 times don't match" << endl; + std::cout << "post processing hdf5 times don't match" << std::endl; return false; } double* times = new double[int(timesDim)]; @@ -101,7 +102,7 @@ bool PostProcessingHdf5Writer::loadFinal(int numTimes) { } hdf5Copy.close(); } catch(H5::Exception error ) { - cout << "failed to reload post processing block: " << error.getDetailMsg() << endl; + std::cout << "failed to reload post processing block: " << error.getDetailMsg() << std::endl; // recreate the file later } diff --git a/VCell/src/SimTool.cpp b/VCell/src/SimTool.cpp index f44d36491..621556451 100644 --- a/VCell/src/SimTool.cpp +++ b/VCell/src/SimTool.cpp @@ -3,6 +3,7 @@ * All rights reserved. */ +#include #include #include using std::stringstream; @@ -28,9 +29,9 @@ using std::endl; #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -272,10 +273,9 @@ static FILE* openFileWithRetry(const char* fileName, const char* mode) { return fp; } -static bool zipUnzipWithRetry(bool bZip, char* zipFileName, char* simFileName, char* errmsg) { - bool bSuccess = true; - int retcode = 0; - for (int retry = 0; retry < numRetries; retry ++) { +static bool zipUnzipWithRetry(bool bZip, const char* zipFileName, const char* simFileName, std::string* errmsg) { + bool bSuccess = false; + for (int attemptNum = 0; attemptNum <= numRetries; attemptNum++) { try { if (bZip) { // retcode = zip32(1, zipFileName, simFileName); @@ -284,21 +284,24 @@ static bool zipUnzipWithRetry(bool bZip, char* zipFileName, char* simFileName, c // retcode = unzip32(zipFileName, simFileName, NULL); extractFileFromZip(zipFileName, simFileName); } + bSuccess = true; break; } catch (const char* ziperr) { - sprintf(errmsg, "%s", ziperr); + errmsg->clear(); + errmsg->append(ziperr); } catch (...) { - sprintf(errmsg, "SimTool::updateLog(), adding .sim to .zip failed."); - } - bSuccess = false; - if (retry < numRetries - 1) { - retryWait(retryWaitSeconds); - cout << "SimTool::updateLog(), adding .sim to .zip failed, trying again" << endl; + errmsg->clear(); + errmsg->append("SimTool::updateLog(), adding .sim to .zip failed."); } + if (attemptNum == numRetries) continue; + retryWait(retryWaitSeconds); + cout << "SimTool::updateLog(), adding .sim to .zip failed (attempt " + << (attemptNum + 1) << "), trying again" << endl; + } - if (bSuccess && retcode != 0) { - sprintf(errmsg, "Writing zip file <%s> failed, return code is %d", zipFileName, retcode); - bSuccess = false; + if (!bSuccess) { + errmsg->clear(); + errmsg->append("Writing zip file <").append(zipFileName).append("> failed."); } return bSuccess; } @@ -321,21 +324,21 @@ void SimTool::loadFinal() bool bStartOver = true; - char logFileName[128]; - char zipFileName[128]; - char dataFileName[128]; + std::string logFileName{baseFileName}; + logFileName.append(LOG_FILE_EXT); + std::string zipFileName{baseFileName}; + const std::string dataFileName; - sprintf(logFileName,"%s%s", baseFileName, LOG_FILE_EXT); FILE* tidFP = lockForReadWrite(); - FILE* logFP = fopen(logFileName, "r"); + FILE* logFP = fopen(logFileName.c_str(), "r"); if (logFP != NULL) { bStartOver = false; // log file exists, there is old data - struct stat buf; - sprintf(zipFileName,"%s00%s", baseFileName, ZIP_FILE_EXT); - if (stat(zipFileName, &buf)) { + zipFileName.append("00").append(ZIP_FILE_EXT); + + if (stat(zipFileName.c_str(), &buf)) { bSimZip = false; NUM_TOKENS_PER_LINE = 3; } else { @@ -362,13 +365,13 @@ void SimTool::loadFinal() // int numTokens = 0; if (bSimZip) { - numTokens = sscanf(logBuffer, "%d %s %s %lg", &tempIteration, dataFileName, zipFileName, &simStartTime); + numTokens = sscanf(logBuffer, "%d %s %s %lg", &tempIteration, dataFileName.c_str(), zipFileName.c_str(), &simStartTime); } else { - numTokens = sscanf(logBuffer, "%d %s %lg", &tempIteration, dataFileName, &simStartTime); + numTokens = sscanf(logBuffer, "%d %s %lg", &tempIteration, dataFileName.c_str(), &simStartTime); } if (numTokens != NUM_TOKENS_PER_LINE){ - printf("SimTool::load(), error reading log file %s, reading iteration\n", logFileName); - printf("error in line %d = '%s'\n",tempFileCount,logBuffer); + printf("SimTool::load(), error reading log file %s, reading iteration\n", logFileName.c_str()); + printf("error in line %d = '%s'\n", tempFileCount, logBuffer); bStartOver = true; break; } @@ -386,30 +389,28 @@ void SimTool::loadFinal() if (!bStartOver) { if (bSimZip) { // check if zip file exists - char zipFileAbsoluteName[512]; - if (strchr(zipFileName, DIRECTORY_SEPARATOR) != 0) { - strcpy(zipFileAbsoluteName,zipFileName); + std::string zipFileAbsoluteName; + const bool needs_path_completion = + strchr(zipFileName.c_str(), DIRECTORY_SEPARATOR) == 0 && baseDirName != 0; + if (needs_path_completion) { + zipFileAbsoluteName = std::string(baseDirName) + zipFileName; } else { - if (baseDirName == 0) { // current directory - strcpy(zipFileAbsoluteName, zipFileName); - } else { - sprintf(zipFileAbsoluteName,"%s%s",baseDirName, zipFileName); // Jim Schaff made this change ... look at it. - } + zipFileAbsoluteName = std::string(zipFileName); } - if (stat(zipFileAbsoluteName, &buf)) { + if (stat(zipFileAbsoluteName.c_str(), &buf)) { cout << "SimTool::loadFinal(), unable to open zip file <" << zipFileAbsoluteName << ">" << endl; bStartOver = true; } else { // unzip the file (without directory) into exdir, currently we // unzip the file to the current working directory - char errmsg[128]; - zipUnzipWithRetry(false, zipFileAbsoluteName, dataFileName, errmsg); + std::string errmsg; + zipUnzipWithRetry(false, zipFileAbsoluteName.c_str(), dataFileName.c_str(), &errmsg); } } if (!bStartOver) { // otherwise check if sim file exists - if (stat(dataFileName, &buf)) { + if (stat(dataFileName.c_str(), &buf)) { cout << "SimTool::loadFinal(), unable to open sim file <" << dataFileName << ">" << endl; bStartOver = true; } else { @@ -419,7 +420,7 @@ void SimTool::loadFinal() } if (!bStartOver) { - FVDataSet::read(dataFileName, simulation); + FVDataSet::read(dataFileName.c_str(), simulation); simulation->setCurrIteration(tempIteration); // set start time on sundials if (isSundialsPdeSolver() || isVCellPetscSolver()) { @@ -428,14 +429,14 @@ void SimTool::loadFinal() simFileCount = tempFileCount; if (bSimZip) { - remove(dataFileName); - zipFileCount = getZipCount(zipFileName); + remove(dataFileName.c_str()); + zipFileCount = getZipCount(&zipFileName); // wrong zip file Name if (zipFileCount < 0) { // should never happen bStartOver = true; } else { // check if this zip file is already big enough - if (stat(zipFileName, &buf) == 0) { + if (stat(zipFileName.c_str(), &buf) == 0) { if (buf.st_size > ZIP_FILE_LIMIT) { zipFileCount ++; } @@ -471,28 +472,28 @@ void SimTool::checkTaskIdLockFile(){ } FILE* SimTool::lockForReadWrite() { - int myTaskID = SimulationMessaging::getInstVar()->getTaskID(); - if (myTaskID < 0) { - return 0; - } + const int myTaskID = SimulationMessaging::getInstVar()->getTaskID(); + if (myTaskID < 0) return 0; - char tidFileName[128]; - sprintf(tidFileName,"%s%s", baseFileName, TID_FILE_EXT); + + std::string tidFileName{baseFileName}; + tidFileName.append(TID_FILE_EXT); bool bExist = false; struct stat buf; - if (stat(tidFileName, &buf) == 0) { // if exists + if (stat(tidFileName.c_str(), &buf) == 0) { // if exists bExist = true; } - FILE* fp = openFileWithRetry(tidFileName, bExist ? "r+" : "w+"); + FILE* fp = openFileWithRetry(tidFileName.c_str(), bExist ? "r+" : "w+"); if (fp == 0){ - char errmsg[512]; - sprintf(errmsg, "SimTool::lockForReadWrite() - error opening .tid file <%s>", tidFileName); - throw errmsg; + std::string errMsg; + errMsg.append("SimTool::lockForReadWrite() - error opening .tid file <").append(tidFileName).append(">"); + throw errMsg.c_str(); } + if (bExist) { int taskIDInFile = 0; int numRead = fscanf(fp, "%d", &taskIDInFile); @@ -515,41 +516,24 @@ FILE* SimTool::lockForReadWrite() { return fp; } -std::string getFileName(const std::string& path) -{ - size_t i = path.length() - 1; - while (i>0) - { - if (path[i] == '/' || path[i] == '\\') - { - return path.substr(i+1); - } - i--; - if (i == 0){ - break; - } - } - - return path; +std::string getFileName(const std::string& path){ + return path.substr(1 + path.find_first_of("\\/")); } void SimTool::updateLog(double progress, double time, int iteration) { if (bStoreEnable) { FILE *logFP; - char simFileName[128]; - char logFileName[128]; - char zipFileName[128]; - char particleFileName[128]; + std::string simFileName; bool bSuccess = true; - char errmsg[512]; + std::string errorMsg; FILE* tidFP = lockForReadWrite(); struct stat buf; #if ( defined(WIN32) || defined(WIN64) ) // Windows wstring TempPath; - wchar_t wcharPath[128]; + wchar_t wcharPath[128]; // This needs to be fixed when on windows. if (GetTempPathW(128, wcharPath)){ TempPath = wcharPath; }else{ @@ -579,38 +563,45 @@ void SimTool::updateLog(double progress, double time, int iteration) bFirstTimeUpdateLog = false; } + std::stringstream simFileNameStream; // write sim files to local if (bSimZip && bUseTempDir) { - sprintf(simFileName,"%s%s%.4d%s", tempDir.c_str(), getFileName(baseSimName).c_str(), simFileCount, SIM_FILE_EXT); + simFileNameStream << tempDir << getFileName(baseSimName) << std::setfill('0') << std::setw(4) << simFileCount << SIM_FILE_EXT; } else { - sprintf(simFileName,"%s%.4d%s",baseFileName, simFileCount, SIM_FILE_EXT); + simFileNameStream << baseFileName << std::setfill('0') << std::setw(4) << simFileCount << SIM_FILE_EXT; } + simFileName = simFileNameStream.str(); std::cout << "sim file name is " << simFileName << std::endl; - sprintf(particleFileName,"%s%s",simFileName, PARTICLE_FILE_EXT); - simulation->writeData(simFileName,bSimFileCompress); + std::string particleFileName{simFileName}; + particleFileName.append(PARTICLE_FILE_EXT); + + simulation->writeData(simFileName.c_str(), bSimFileCompress); - sprintf(logFileName,"%s%s",baseFileName, LOG_FILE_EXT); + std::string logFileName{baseFileName}; + logFileName.append(LOG_FILE_EXT); - logFP = openFileWithRetry(logFileName, "a"); + logFP = openFileWithRetry(logFileName.c_str(), "a"); if (logFP == 0) { - sprintf(errmsg, "SimTool::updateLog() - error opening log file <%s>", logFileName); + errorMsg.append("SimTool::updateLog() - error opening log file <").append(logFileName).append(">"); bSuccess = false; } else { // write zip file first, then write log file, in case that // zipping fails if (bSimZip) { - sprintf(zipFileName,"%s%.2d%s",baseFileName, zipFileCount, ZIP_FILE_EXT); - int retcode = 0; - if (stat(particleFileName, &buf) == 0) { // has particle + //int retcode = 0; + std::stringstream zipFileNameStream; + zipFileNameStream << baseFileName << std::setfill('0') << std::setw(2) << zipFileCount << ZIP_FILE_EXT; + std::string zipFileName{zipFileNameStream.str()}; + if (stat(particleFileName.c_str(), &buf) == 0) { // has particle // retcode = zip32(2, zipFileName, simFileName, particleFileName); - addFilesToZip(zipFileName, simFileName, particleFileName); - remove(particleFileName); + addFilesToZip(zipFileName.c_str(), simFileName.c_str(), particleFileName.c_str()); + remove(particleFileName.c_str()); } else { - bSuccess = zipUnzipWithRetry(true, zipFileName, simFileName, errmsg); + bSuccess = zipUnzipWithRetry(true, zipFileName.c_str(), simFileName.c_str(), &errorMsg); } - remove(simFileName); + remove(simFileName.c_str()); // write the log file if (bSuccess) { @@ -619,22 +610,29 @@ void SimTool::updateLog(double progress, double time, int iteration) postProcessingHdf5Writer->writeOutput(); } - char zipFileNameWithoutPath[512]; - sprintf(zipFileNameWithoutPath,"%s%.2d%s",baseSimName, zipFileCount, ZIP_FILE_EXT); - char simFileNameWithoutPath[512]; - sprintf(simFileNameWithoutPath,"%s%.4d%s", baseSimName, simFileCount, SIM_FILE_EXT); - fprintf(logFP,"%4d %s %s %.15lg\n", iteration, simFileNameWithoutPath, zipFileNameWithoutPath, time); - if (stat(zipFileName, &buf) == 0) { // if exists + + std::stringstream zipFileNameWithoutPathStream; + zipFileNameWithoutPathStream << baseSimName << std::setfill('0') << std::setw(2) << + zipFileCount << ZIP_FILE_EXT; + std::stringstream simFileNameWithoutPathStream; + simFileNameWithoutPathStream << baseSimName << std::setfill('0') << std::setw(4) << + simFileCount << SIM_FILE_EXT; + fprintf(logFP,"%4d %s %s %.15lg\n", iteration, simFileNameWithoutPathStream.str().c_str(), + zipFileNameWithoutPathStream.str().c_str(), time); + + if (stat(zipFileName.c_str(), &buf) == 0) { // if exists if (buf.st_size > ZIP_FILE_LIMIT) { zipFileCount ++; } } } } else { // old format, no zip - char simFileNameWithoutPath[512]; - sprintf(simFileNameWithoutPath,"%s%.4d%s",baseSimName, simFileCount, SIM_FILE_EXT); - fprintf(logFP,"%4d %s %.15lg\n", iteration, simFileNameWithoutPath, time); + std::stringstream simFileNameWithoutPathStream; + simFileNameWithoutPathStream << baseSimName << std::setfill('0') << std::setw(4) << + simFileCount << SIM_FILE_EXT; + fprintf(logFP,"%4d %s %.15lg\n", iteration, + simFileNameWithoutPathStream.str().c_str(), time); } } // close log file @@ -646,7 +644,7 @@ void SimTool::updateLog(double progress, double time, int iteration) if (bSuccess) { simFileCount++; } else { - throw errmsg; + throw errorMsg.c_str(); } } else{ // write hdf5 post processing before writing log entry @@ -671,6 +669,13 @@ int SimTool::getZipCount(char* zipFileName) { return atoi(str); } +int SimTool::getZipCount(const std::string* zipFileName) { + // We need a char buffer because underlying ststr() call needs non-const char-ptr + char buffer[zipFileName->size()]; // C99 is great + strcpy(buffer, zipFileName->c_str()); + return this->getZipCount(buffer); +} + void SimTool::clearLog() { simStartTime = 0; @@ -682,65 +687,75 @@ void SimTool::clearLog() } FILE *fp; - char logFileName[256]; - char buffer[256]; + std::string logFileName; + std::string buffer; // remove mesh file - sprintf(buffer,"%s%s",baseFileName, MESH_FILE_EXT); - remove(buffer); + buffer.append(baseFileName).append(MESH_FILE_EXT); + remove(buffer.c_str()); + buffer.clear(); - sprintf(buffer,"%s%s",baseFileName, MESHMETRICS_FILE_EXT); - remove(buffer); + buffer.append(baseFileName).append(MESHMETRICS_FILE_EXT); + remove(buffer.c_str()); + buffer.clear(); - sprintf(buffer,"%s%s",baseFileName, ZIP_FILE_EXT); - remove(buffer); + buffer.append(baseFileName).append(ZIP_FILE_EXT); + remove(buffer.c_str()); + buffer.clear(); - sprintf(buffer,"%s00%s",baseFileName, ZIP_FILE_EXT); - remove(buffer); + buffer.append(baseFileName).append("00").append(ZIP_FILE_EXT); + remove(buffer.c_str()); + buffer.clear(); - sprintf(logFileName,"%s%s",baseFileName, LOG_FILE_EXT); + logFileName.append(baseFileName).append(LOG_FILE_EXT); - if ((fp=fopen(logFileName, "r"))==NULL){ - printf("error opening log file <%s>\n", logFileName); + if ((fp=fopen(logFileName.c_str(), "r")) == NULL){ + printf("error opening log file <%s>\n", logFileName.c_str()); return; } - char simFileName[128]; - char zipFileName[128]; - int iteration, oldCount=-1, count; + std::string simFileName; + std::string zipFileName; + int iteration, oldCount=-1; double time; while (true) { int numTokens = 0; if (bSimZip) { - numTokens = fscanf(fp,"%d %s %s %lg\n", &iteration, simFileName, zipFileName, &time); + numTokens = fscanf(fp,"%d %s %s %lg\n", &iteration, simFileName.c_str(), zipFileName.c_str(), &time); } else { - numTokens = fscanf(fp,"%d %s %lg\n", &iteration, simFileName, &time); + numTokens = fscanf(fp,"%d %s %lg\n", &iteration, simFileName.c_str(), &time); } if (numTokens != NUM_TOKENS_PER_LINE){ break; } - char *dotSim = strstr(simFileName,SIM_FILE_EXT); - if (!dotSim) { - continue; - } + + char simFileNameCharArray[simFileName.size()]; + strcpy(simFileNameCharArray, simFileName.c_str()); + char *dotSim = strstr(simFileNameCharArray, SIM_FILE_EXT); + if (!dotSim) continue; + *dotSim = '\0'; - sprintf(buffer,"%s%s", simFileName, SIM_FILE_EXT); - remove(buffer); - sprintf(buffer,"%s%s%s",simFileName, SIM_FILE_EXT, PARTICLE_FILE_EXT); - remove(buffer); - if (bSimZip) { - count = getZipCount(zipFileName); - if (oldCount != count && count >= 0) { - remove(zipFileName); - oldCount = count; - } + + buffer.append(baseFileName).append(SIM_FILE_EXT); + remove(buffer.c_str()); + buffer.clear(); + + buffer.append(baseFileName).append(SIM_FILE_EXT).append(PARTICLE_FILE_EXT); + remove(buffer.c_str()); + buffer.clear(); + + if (!bSimZip) continue; + const int count = getZipCount(&zipFileName); + if (oldCount != count && count >= 0) { + remove(zipFileName.c_str()); + oldCount = count; } } fclose(fp); - printf("SimTool::clearLog(), removing log file %s\n",logFileName); - remove(logFileName); + printf("SimTool::clearLog(), removing log file %s\n",logFileName.c_str()); + remove(logFileName.c_str()); } bool SimTool::isSundialsPdeSolver() { @@ -804,8 +819,8 @@ void SimTool::start1() { // create post processing hdf5 writer if (simulation->getPostProcessingBlock() != NULL) { if (postProcessingHdf5Writer == NULL) { - char h5PPFileName[128]; - sprintf(h5PPFileName, "%s%s", baseFileName, HDF5_FILE_EXT); + std::string h5PPFileName; + h5PPFileName.append(baseFileName).append(HDF5_FILE_EXT); postProcessingHdf5Writer = new PostProcessingHdf5Writer(h5PPFileName, simulation->getPostProcessingBlock()); } } @@ -833,9 +848,9 @@ void SimTool::start1() { throw "Invalid base file name for dataset"; } - char message[256]; - sprintf(message, "simulation [%s] started", baseSimName); - SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_STARTING, message)); + std::string message; + message.append("simulation [").append(baseSimName).append("] started"); + SimulationMessaging::getInstVar()->setWorkerEvent(new WorkerEvent(JOB_STARTING, message.c_str())); // // destroy any partial results from unfinished iterations @@ -849,21 +864,22 @@ void SimTool::start1() { // write .mesh and .meshmetrics file if (bStoreEnable){ FILE *fp = NULL; - char filename[128]; - sprintf(filename, "%s%s", baseFileName, MESH_FILE_EXT); - if ((fp=fopen(filename,"w"))==NULL){ - char errMsg[256]; - sprintf(errMsg, "cannot open mesh file %s for writing", filename); - throw errMsg; + std::string filename; + filename.append(baseFileName).append(MESH_FILE_EXT); + if ((fp=fopen(filename.c_str(),"w")) == NULL){ + std::string errorMessage; + errorMessage.append("cannot open mesh file ").append(filename).append(" for writing"); + throw errorMessage.c_str(); } simulation->getMesh()->write(fp); fclose(fp); - sprintf(filename, "%s%s", baseFileName, MESHMETRICS_FILE_EXT); - if ((fp=fopen(filename,"w"))==NULL){ - char errMsg[256]; - sprintf(errMsg, "cannot open mesh metrics file %s for writing", filename); - throw errMsg; + filename.erase(strlen(baseFileName), 5); + filename.append(MESHMETRICS_FILE_EXT); + if ((fp=fopen(filename.c_str(),"w")) == NULL){ + std::string errorMessage; + errorMessage.append("cannot open mesh metrics file ").append(filename).append(" for writing"); + throw errorMessage.c_str(); } simulation->getMesh()->writeMeshMetrics(fp); fclose(fp); diff --git a/VCell/src/Simulation.cpp b/VCell/src/Simulation.cpp index 7c0332d8d..a94bc518e 100644 --- a/VCell/src/Simulation.cpp +++ b/VCell/src/Simulation.cpp @@ -145,7 +145,7 @@ Solver *Simulation::getSolverFromVariable(Variable *var) // globalParticleList.push_back(particle); //} -void Simulation::readData(char *filename) +void Simulation::readData(const char *filename) { // // all processes read data diff --git a/VCell/src/SimulationExpression.cpp b/VCell/src/SimulationExpression.cpp index ea4adfea1..b75a1882b 100644 --- a/VCell/src/SimulationExpression.cpp +++ b/VCell/src/SimulationExpression.cpp @@ -646,7 +646,7 @@ void SimulationExpression::populateRegionSizeVariableValues(double *darray, bool } } -void SimulationExpression::writeData(char *filename, bool bCompress) +void SimulationExpression::writeData(const char *filename, bool bCompress) { //bool hasParticles = false; //VCellModel *model = SimTool::getInstance()->getModel(); diff --git a/VCell/src/SundialsPdeScheduler.cpp b/VCell/src/SundialsPdeScheduler.cpp index 991851e43..baa52d16f 100644 --- a/VCell/src/SundialsPdeScheduler.cpp +++ b/VCell/src/SundialsPdeScheduler.cpp @@ -1182,7 +1182,7 @@ void SundialsPdeScheduler::regionApplyVolumeOperatorConstant(int regionID, doubl double reactionRate = 0; if (bDirichlet && var->isDiffusing()) {// pde dirichlet rhs[vectorIndex] = 0; - if (mask & (NEIGHBOR_XP_BOUNDARY || NEIGHBOR_YP_BOUNDARY || NEIGHBOR_ZP_BOUNDARY)) { + if (mask & (NEIGHBOR_XP_BOUNDARY | NEIGHBOR_YP_BOUNDARY | NEIGHBOR_ZP_BOUNDARY)) { continue; } } else { @@ -1362,7 +1362,7 @@ void SundialsPdeScheduler::regionApplyVolumeOperatorVariable(int regionID, doubl double reactionRate = 0; if (bDirichlet && var->isDiffusing()) {// pde dirichlet rhs[vectorIndex] = 0; - if (mask & (NEIGHBOR_XP_BOUNDARY || NEIGHBOR_YP_BOUNDARY || NEIGHBOR_ZP_BOUNDARY)) { + if (mask & (NEIGHBOR_XP_BOUNDARY | NEIGHBOR_YP_BOUNDARY | NEIGHBOR_ZP_BOUNDARY)) { continue; } } else { @@ -1987,7 +1987,7 @@ int SundialsPdeScheduler::pcSolve(realtype t, N_Vector y, N_Vector fy, N_Vector bRetry = true; } catch (...) { char errMsg[128]; - sprintf(errMsg, "SundialsPDESolver:: Out of Memory : pcg_workspace allocating (%ld)", nsp); + snprintf(errMsg, 128, "SundialsPDESolver:: Out of Memory : pcg_workspace allocating (%ld)", nsp); throw errMsg; } } diff --git a/VCell/src/VariableStatisticsDataGenerator.cpp b/VCell/src/VariableStatisticsDataGenerator.cpp index 1a45ed8c2..f829867f4 100644 --- a/VCell/src/VariableStatisticsDataGenerator.cpp +++ b/VCell/src/VariableStatisticsDataGenerator.cpp @@ -170,12 +170,12 @@ void VariableStatisticsDataGenerator::writeAttributeComponent(H5::Group& dataGen char attrValue[64]; //write name and unit - sprintf(attrName, "comp_%d_name", componentIndex); + snprintf(attrName, 64, "comp_%d_name", componentIndex); H5::Attribute attribute = dataGeneratorGroup.createAttribute(attrName, attributeStrType, attributeDataSpace); - sprintf(attrValue, "%s_%s", varName, dataName); + snprintf(attrValue, 64, "%s_%s", varName, dataName); attribute.write(attributeStrType, attrValue); - sprintf(attrName, "comp_%d_unit", componentIndex); + snprintf(attrName, 64, "comp_%d_unit", componentIndex); attribute = dataGeneratorGroup.createAttribute(attrName, attributeStrType, attributeDataSpace); attribute.write(attributeStrType, unit.c_str()); } diff --git a/VCellMessaging/include/VCELL/SimulationMessaging.h b/VCellMessaging/include/VCELL/SimulationMessaging.h index de8018eff..20979cced 100644 --- a/VCellMessaging/include/VCELL/SimulationMessaging.h +++ b/VCellMessaging/include/VCELL/SimulationMessaging.h @@ -5,7 +5,6 @@ #ifdef USE_MESSAGING #include #include -#include #include #endif diff --git a/VCellMessaging/src/SimulationMessaging.cpp b/VCellMessaging/src/SimulationMessaging.cpp index 8ea4bb400..4747cb85d 100644 --- a/VCellMessaging/src/SimulationMessaging.cpp +++ b/VCellMessaging/src/SimulationMessaging.cpp @@ -1,13 +1,13 @@ #include -#include #include #include #include +#include using std::cerr; using std::cout; using std::endl; -#include +#include #ifdef USE_MESSAGING #if ( !defined(WIN32) && !defined(WIN64) ) // UNIX #include @@ -43,22 +43,18 @@ static const double WORKEREVENT_MESSAGE_MIN_TIME_SECONDS = 15.0; SimulationMessaging *SimulationMessaging::m_inst = NULL; -SimulationMessaging::SimulationMessaging() - :events( ) - { - bStopRequested = false; +SimulationMessaging::SimulationMessaging(){ + this->bStopRequested = false; #ifdef USE_MESSAGING - m_taskID = -1; - bStarted = false; + this->m_taskID = -1; + this->bStarted = false; #endif - workerEventOutputMode = WORKEREVENT_OUTPUT_MODE_STDOUT; + this->workerEventOutputMode = WORKEREVENT_OUTPUT_MODE_STDOUT; } #ifdef USE_MESSAGING SimulationMessaging::SimulationMessaging(const char* broker, const char* smqusername, const char* passwd, const char*qname, - const char* tname, const char* vcusername, int simKey, int jobIndex, int taskID, int ttl_low, int ttl_high) - :events( ) -{ + const char* tname, const char* vcusername, int simKey, int jobIndex, int taskID, int ttl_low, int ttl_high){ m_broker = const_cast(broker); m_smqusername = const_cast( smqusername ); m_password = const_cast(passwd ); @@ -177,13 +173,13 @@ void SimulationMessaging::sendStatus() { fflush(stdout); break; case JOB_STARTING: - cout<< workerEvent->eventMessage << endl; + std::cout<< workerEvent->eventMessage << std::endl; break; case JOB_COMPLETED: - cerr << "Simulation Complete in Main() ... " << endl; + std::cerr << "Simulation Complete in Main() ... " << std::endl; break; case JOB_FAILURE: - cerr << workerEvent->eventMessage << endl; + std::cerr << workerEvent->eventMessage << std::endl; break; } return; diff --git a/bridgeVCellSmoldyn/SimpleMesh.h b/bridgeVCellSmoldyn/SimpleMesh.h index 3b253da79..01529000d 100644 --- a/bridgeVCellSmoldyn/SimpleMesh.h +++ b/bridgeVCellSmoldyn/SimpleMesh.h @@ -4,10 +4,10 @@ #include class SimpleMesh : public AbstractMesh { -public: - void getCenterCoordinates(int volIndex, double* coords); - void getDeltaXYZ(double* delta); - void getNumXYZ(int* num); +public: + void getCenterCoordinates(int volIndex, double* coords); + void getDeltaXYZ(double* delta); + void getNumXYZ(int* num); private: }; diff --git a/bridgeVCellSmoldyn/vcell_smoldyn.cpp b/bridgeVCellSmoldyn/vcell_smoldyn.cpp index 5899285fb..c04da430e 100644 --- a/bridgeVCellSmoldyn/vcell_smoldyn.cpp +++ b/bridgeVCellSmoldyn/vcell_smoldyn.cpp @@ -4,6 +4,10 @@ Copyright 2003-2011 by Steven Andrews. This work is distributed under the terms of the Gnu General Public License (GPL). */ +#include "opengl2.h" +#include "smoldyn.h" +#include "random2.h" +#include "smoldynfuncs.h" #include #include @@ -14,10 +18,6 @@ #include #include #include -#include "opengl2.h" -#include "smoldyn.h" -#include "random2.h" -#include "smoldynfuncs.h" #include "SimpleValueProvider.h" #include "SimpleMesh.h" #include "vcellhybrid.h" diff --git a/libzip-1.2.0/lib/mkstemp.c b/libzip-1.2.0/lib/mkstemp.c index 2ccd3a487..c1e81004f 100644 --- a/libzip-1.2.0/lib/mkstemp.c +++ b/libzip-1.2.0/lib/mkstemp.c @@ -40,6 +40,10 @@ #include #ifdef _WIN32 #include +#include +#define getpid _getpid +#else +#include #endif #include #include diff --git a/qhull/mem.h b/qhull/mem.h index e1fe42971..b79d179b7 100644 --- a/qhull/mem.h +++ b/qhull/mem.h @@ -62,7 +62,8 @@ using std::ostream; On 64-bit machines, a pointer may be larger than an 'int'. qh_meminit() checks that 'long' holds a 'void*' */ -typedef unsigned long ptr_intT; +//typedef unsigned long ptr_intT; +typedef unsigned long long ptr_intT; /*---------------------------------- diff --git a/smoldyn-2.38/CMakeLists.txt b/smoldyn-2.38/CMakeLists.txt index ec62b8546..e4fd33ffe 100644 --- a/smoldyn-2.38/CMakeLists.txt +++ b/smoldyn-2.38/CMakeLists.txt @@ -119,7 +119,6 @@ set_source_files_properties(${MAIN_FILES} PROPERTIES LANGUAGE CXX ) include_directories(source/lib source/Smoldyn source/NextSubVolume source/vtk ${CMAKE_CURRENT_BINARY_DIR}) - ####### Build for debugging or release ########## if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -164,10 +163,10 @@ elseif (OPTION_MINGW) include_directories(${MINGWDIR}/include windows) link_directories(${MINGWDIR}/lib) #list(APPEND DEP_LIBS opengl32 glu32 freeglut z) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") - set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static -s") - set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static -s") +# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") +# set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static -s") +# set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static -s") endif() set(APPLE_BUILD 0) diff --git a/smoldyn-2.38/source/lib/SimCommand.c b/smoldyn-2.38/source/lib/SimCommand.c index f7bbf2173..7641d309f 100644 --- a/smoldyn-2.38/source/lib/SimCommand.c +++ b/smoldyn-2.38/source/lib/SimCommand.c @@ -451,7 +451,7 @@ int scmdnextcmdtime(cmdssptr cmds,double time,Q_LONGLONG iter,enum CMDcode type, /* scmdoutput */ void scmdoutput(cmdssptr cmds) { int fid,i; - queue cmdq; + queue_c cmdq; cmdptr cmd; void* voidptr; char string[STRCHAR],string2[STRCHAR]; diff --git a/smoldyn-2.38/source/lib/SimCommand.h b/smoldyn-2.38/source/lib/SimCommand.h index e7a4836a5..3ea9960b8 100644 --- a/smoldyn-2.38/source/lib/SimCommand.h +++ b/smoldyn-2.38/source/lib/SimCommand.h @@ -32,8 +32,8 @@ typedef struct cmdstruct { } *cmdptr; typedef struct cmdsuperstruct { - queue cmd; // queue of normal run-time commands - queue cmdi; // queue of integer time commands + queue_c cmd; // queue of normal run-time commands + queue_c cmdi; // queue of integer time commands enum CMDcode (*cmdfn)(void*,cmdptr,char*); // function that runs commands void *cmdfnarg; // function argument (e.g. sim) int iter; // number of times integer commands have run diff --git a/smoldyn-2.38/source/lib/queue.c b/smoldyn-2.38/source/lib/queue.c index 9607d4509..7bd3196b6 100644 --- a/smoldyn-2.38/source/lib/queue.c +++ b/smoldyn-2.38/source/lib/queue.c @@ -9,12 +9,12 @@ of the Gnu Lesser General Public License (LGPL). */ #define CHECK(A) if(!(A)) {goto failure;} else (void)0 -queue q_alloc(int n,enum Q_types type,int (*keycmp)(void *,void *)) { - queue q; +queue_c q_alloc(int n,enum Q_types type,int (*keycmp)(void *,void *)) { + queue_c q; int i; if(n<0) return NULL; - q=(queue) malloc(sizeof(struct qstruct)); + q=(queue_c) malloc(sizeof(struct qstruct)); if(!q) return NULL; q->type=type; @@ -52,7 +52,7 @@ queue q_alloc(int n,enum Q_types type,int (*keycmp)(void *,void *)) { -int q_expand(queue q,int addspace) { +int q_expand(queue_c q,int addspace) { int i,j,num,nnew; void **xnew,**kvnew; int *kinew; @@ -111,7 +111,7 @@ int q_expand(queue q,int addspace) { -void q_free(queue q,int freek,int freex) { +void q_free(queue_c q,int freek,int freex) { int i; if(!q) return; @@ -128,12 +128,12 @@ void q_free(queue q,int freek,int freex) { -void q_null(queue q) { +void q_null(queue_c q) { q->f=q->b=0; } -int q_enqueue(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q) { +int q_enqueue(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue_c q) { int sp; if(q->type==Qvoid) q->kv[q->b]=kv; @@ -148,7 +148,7 @@ int q_enqueue(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q) { -int q_push(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q) { +int q_push(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue_c q) { int sp; q->f=(q->n+q->f-1)%q->n; @@ -163,7 +163,7 @@ int q_push(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q) { -int q_insert(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q) { +int q_insert(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue_c q) { int i,n,sp,im1; n=q->n; @@ -197,7 +197,7 @@ int q_insert(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q) { -void q_front(queue q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr) { +void q_front(queue_c q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr) { if(q->f==q->b) { if(kvptr) *kvptr=NULL; if(kiptr) *kiptr=0; @@ -214,7 +214,7 @@ void q_front(queue q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,voi -int q_pop(queue q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr) { +int q_pop(queue_c q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr) { if(q->f==q->b) { if(kvptr) *kvptr=NULL; if(kiptr) *kiptr=0; @@ -233,17 +233,17 @@ int q_pop(queue q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void * -int q_length(queue q) { +int q_length(queue_c q) { return (q->n+q->b-q->f)%q->n; } -int q_maxlength(queue q) { +int q_maxlength(queue_c q) { return q->n-1; } -int q_next(int i,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr,queue q) { +int q_next(int i,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr,queue_c q) { int f,b; f=q->f; diff --git a/smoldyn-2.38/source/lib/queue.h b/smoldyn-2.38/source/lib/queue.h index 80909c640..f4828445e 100644 --- a/smoldyn-2.38/source/lib/queue.h +++ b/smoldyn-2.38/source/lib/queue.h @@ -30,25 +30,25 @@ typedef struct qstruct{ void **x; int n; int f; - int b; } *queue; + int b; } *queue_c; #define q_frontkeyV(q) ((q)->b==(q)->f?NULL:(q)->kv[(q)->f]) #define q_frontkeyI(q) ((q)->b==(q)->f?0:(q)->ki[(q)->f]) #define q_frontkeyD(q) ((q)->b==(q)->f?0:(q)->kd[(q)->f]) #define q_frontkeyL(q) ((q)->b==(q)->f?0:(q)->kl[(q)->f]) -queue q_alloc(int n,enum Q_types type,int (*keycmp)(void *,void *)); -int q_expand(queue q,int addspace); -void q_free(queue q,int freek,int freex); -void q_null(queue q); -int q_enqueue(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q); -int q_push(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q); -int q_insert(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue q); -void q_front(queue q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr); -int q_pop(queue q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr); -int q_length(queue q); -int q_maxlength(queue q); -int q_next(int i,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr,queue q); +queue_c q_alloc(int n,enum Q_types type,int (*keycmp)(void *,void *)); +int q_expand(queue_c q,int addspace); +void q_free(queue_c q,int freek,int freex); +void q_null(queue_c q); +int q_enqueue(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue_c q); +int q_push(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue_c q); +int q_insert(void *kv,int ki,double kd,Q_LONGLONG kl,void *x,queue_c q); +void q_front(queue_c q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr); +int q_pop(queue_c q,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr); +int q_length(queue_c q); +int q_maxlength(queue_c q); +int q_next(int i,void **kvptr,int *kiptr,double *kdptr,Q_LONGLONG *klptr,void **xptr,queue_c q); #endif diff --git a/sundials/CMakeLists.txt b/sundials/CMakeLists.txt index 31474739c..4d322a545 100644 --- a/sundials/CMakeLists.txt +++ b/sundials/CMakeLists.txt @@ -5,7 +5,7 @@ add_subdirectory(src/ida) add_subdirectory(src/nvec_ser) add_subdirectory(src/sundials) -file(WRITE ${CMAKE_BINARY_DIR}/dummy.c "") +file(WRITE ${CMAKE_BINARY_DIR}/dummy.c "const char* sundials_dummy = \"dummy\";") add_library(sundials ${CMAKE_BINARY_DIR}/dummy.c) target_link_libraries(sundials sundials_cvode sundials_ida sundials_nvecserial sundials_lib)