├── .github ├── dependabot.yml └── workflows │ ├── basictest.yml │ ├── basictest_intel.yml │ ├── basictest_pip.yml │ ├── basictest_wincmake.yml │ ├── encodings.yml │ ├── extra.yml │ ├── fixme.yml │ ├── freebsd.yml │ ├── mcpldevtoolchecks.yml │ └── pypi.yml ├── .gitignore ├── CHANGELOG ├── CMakeLists.txt ├── INSTALL.md ├── LICENSE ├── NOTICE.md ├── README.md ├── VERSION ├── devel ├── bin │ └── mcpldevtool ├── misc │ ├── bldlocal_ninjamulticfg.x │ ├── ctest.x │ ├── ctest_core.x │ ├── test_encodings.log │ ├── test_encodings.x │ └── test_standards │ │ ├── CMakeLists.txt │ │ └── main.c ├── pypath │ └── mcpl_repo_tools │ │ ├── __init__.py │ │ ├── _check_copies.py │ │ ├── _check_fixme.py │ │ ├── _check_license.py │ │ ├── _check_misc.py │ │ ├── _check_readme.py │ │ ├── _check_ruff.py │ │ ├── _check_toml.py │ │ ├── _check_versions.py │ │ ├── _check_yaml.py │ │ ├── _cli_mcpldevtool.py │ │ ├── _climode_check.py │ │ ├── _climode_cmake.py │ │ ├── _climode_find.py │ │ ├── _climode_graph.py │ │ ├── _climode_grep.py │ │ ├── _climode_nprocs.py │ │ ├── _climode_replace.py │ │ ├── _climode_verifytag.py │ │ ├── _cliutils_common.py │ │ ├── check_runner.py │ │ ├── cmake.py │ │ ├── dirs.py │ │ ├── license.py │ │ ├── mdsimpleparser.py │ │ ├── srciter.py │ │ ├── testinfo.py │ │ ├── toml.py │ │ └── util.py ├── reqs │ └── requirements_devel.txt └── setup.sh ├── examples ├── downstream_cmake │ ├── CMakeLists.txt │ └── main.c ├── example.mcpl ├── example_filtermcpl.c ├── example_readmcpl.c ├── example_writemcpl.c └── pyexample_readmcpl ├── mcpl_core ├── CMakeLists.txt ├── LICENSE ├── README.md ├── app_config │ └── main.c ├── app_tool │ └── mcpltool_app.c ├── cmake │ ├── MCPLConfig.cmake.in │ ├── modules │ │ ├── mcpl_cfgapp.cmake │ │ ├── mcpl_coretests.cmake │ │ ├── mcpl_headercreate.cmake │ │ ├── mcpl_options.cmake │ │ ├── mcpl_zlib.cmake │ │ └── mctools_utils.cmake │ ├── template_mcplconfig.h │ └── template_pymod.py.in ├── empty_pypkg │ ├── LICENSE │ ├── README.md │ └── pyproject.toml ├── include │ └── mcpl.h.in ├── pyproject.toml ├── src │ ├── mcpl.c │ ├── mcpl_fileutils.c │ └── mcpl_fileutils.h └── tests │ └── src │ └── app_testwritegzip │ └── main.c ├── mcpl_extra ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake │ └── modules │ │ └── mctools_utils.cmake ├── pyproject.toml ├── pywrapper │ └── _mcpl_extra │ │ ├── __init__.py │ │ └── cli.py └── src │ ├── phits │ ├── app_mcpl2phits │ │ └── main.c │ ├── app_phits2mcpl │ │ └── main.c │ └── common │ │ ├── phitsmcpl.c │ │ ├── phitsmcpl.h │ │ ├── phitsread.c │ │ └── phitsread.h │ └── ssw │ ├── app_mcpl2ssw │ └── main.c │ ├── app_ssw2mcpl │ └── main.c │ └── common │ ├── sswmcpl.c │ ├── sswmcpl.h │ ├── sswread.c │ └── sswread.h ├── mcpl_metapkg ├── LICENSE ├── README.md └── pyproject.toml ├── mcpl_python ├── LICENSE ├── README.md ├── pyproject.toml └── src │ └── mcpl │ ├── __init__.py │ ├── __main__.py │ └── mcpl.py └── tests ├── CMakeLists.txt ├── README.md ├── cmake ├── mctools_testlauncher.py └── mctools_testutils.cmake ├── data ├── ref │ ├── difficult_unitvector.mcpl.gz │ ├── gammas_uw.mcpl.gz │ ├── miscphys.mcpl.gz │ ├── ref_statsum.mcpl.gz │ ├── ref_statsum_crash.mcpl │ ├── ref_statunsupported.mcpl.gz │ ├── reffile_1.mcpl │ ├── reffile_10.mcpl │ ├── reffile_11.mcpl │ ├── reffile_12.mcpl │ ├── reffile_13.mcpl │ ├── reffile_14.mcpl │ ├── reffile_15.mcpl │ ├── reffile_16.mcpl │ ├── reffile_2.mcpl │ ├── reffile_2.mcpl.gz │ ├── reffile_3.mcpl │ ├── reffile_4.mcpl │ ├── reffile_5.mcpl │ ├── reffile_5.mcpl.gz │ ├── reffile_6.mcpl │ ├── reffile_7.mcpl │ ├── reffile_8.mcpl │ ├── reffile_9.mcpl │ ├── reffile_bad1.mcpl │ ├── reffile_bad1.mcpl.gz │ ├── reffile_bad2.mcpl │ ├── reffile_bad2.mcpl.gz │ ├── reffile_bad3.mcpl │ ├── reffile_bad3.mcpl.gz │ ├── reffile_bad4.mcpl │ ├── reffile_bad4.mcpl.gz │ ├── reffile_bad_duplicatestatsumkeys.mcpl │ ├── reffile_crash.mcpl │ ├── reffile_crash.mcpl.gz │ ├── reffile_empty.mcpl │ ├── reffile_empty.mcpl.gz │ ├── reffile_encodings.mcpl.gz │ ├── reffile_notreallygz.mcpl.gz │ ├── reffile_skip123.mcpl │ ├── reffile_skip123.mcpl.gz │ ├── reffile_truncated.mcpl │ ├── reffile_truncated.mcpl.gz │ ├── reffile_userflags_is_pos.mcpl.gz │ └── reffile_uw.mcpl.gz └── reffmt2 │ ├── miscphys.mcpl.gz │ ├── reffile_1.mcpl │ ├── reffile_10.mcpl │ ├── reffile_11.mcpl │ ├── reffile_12.mcpl │ ├── reffile_13.mcpl │ ├── reffile_14.mcpl │ ├── reffile_15.mcpl │ ├── reffile_16.mcpl │ ├── reffile_2.mcpl │ ├── reffile_2.mcpl.gz │ ├── reffile_3.mcpl │ ├── reffile_4.mcpl │ ├── reffile_5.mcpl │ ├── reffile_5.mcpl.gz │ ├── reffile_6.mcpl │ ├── reffile_7.mcpl │ ├── reffile_8.mcpl │ ├── reffile_9.mcpl │ ├── reffile_crash.mcpl │ ├── reffile_crash.mcpl.gz │ ├── reffile_empty.mcpl │ ├── reffile_empty.mcpl.gz │ ├── reffile_skip123.mcpl │ └── reffile_skip123.mcpl.gz ├── extra ├── data │ └── .empty ├── pypath │ └── MCPLExtraTestUtils │ │ ├── __init__.py │ │ └── dirs.py ├── scripts │ ├── basic.log │ ├── basic.py │ ├── phitsuc.log │ └── phitsuc.py └── src │ ├── app_phitspdgcode │ ├── main.c │ └── test.log │ └── app_sswpdgcode │ ├── main.c │ └── test.log ├── include ├── mcpltestmodutils.h └── mcpltestutils.h ├── modules └── lib_statsum │ └── lib.c ├── pypath └── MCPLTestUtils │ ├── __init__.py │ ├── checkasciicompat.py │ ├── common.py │ ├── dirs.py │ ├── loadlib.py │ ├── stdout_redirect.py │ └── toolcheck_common.py ├── scripts ├── a.log ├── a.py ├── b.log ├── b.py ├── c.log ├── c.py ├── forcemerge.log ├── forcemerge.py ├── pystat.log ├── pystat.py ├── statsum.log ├── statsum.py ├── tool.log ├── tool.py ├── toolfmt2.log ├── toolfmt2.py ├── tooluc.log └── tooluc.py └── src ├── app_bigfile ├── main.cc └── test.log ├── app_bigfilenogz ├── main.cc └── test.log ├── app_bighdr ├── main.cc └── test.log ├── app_cppmcpltool ├── main.cc └── test.log ├── app_example ├── main.c └── test.log ├── app_examples ├── example_filtermcpl.h ├── example_readmcpl.h ├── example_writemcpl.h ├── main.c └── test.log ├── app_file2mem ├── main.cc └── test.log ├── app_fopen └── main.c ├── app_genisotrop ├── main.c └── test.log ├── app_miscphys ├── main.c └── test.log ├── app_print ├── main.c └── test.log ├── app_readgzref ├── main.c └── test.log ├── app_readref ├── main.c └── test.log ├── app_seek ├── main.c └── test.log ├── app_smallfile ├── main.cc └── test.log ├── app_statsum ├── main.c └── test.log ├── app_unicodenames ├── main.c └── test.log ├── app_writegzip ├── main.c └── test.log ├── app_writempi ├── main.c └── test.log └── app_writempi1 ├── main.c └── test.log /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | target-branch: "develop" 8 | -------------------------------------------------------------------------------- /.github/workflows/basictest_pip.yml: -------------------------------------------------------------------------------- 1 | name: basictest_pip 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | mcpldevtool_check: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v4 13 | with: 14 | path: src 15 | - name: Enable parallel cmake 16 | run: python ./src/devel/bin/mcpldevtool nprocs --enable-github-parallel 17 | - name: Pip install packages for mcpldevtool 18 | run: pip install -r ./src/devel/reqs/requirements_devel.txt 19 | - name: mcpldevtool checks 20 | run: ./src/devel/bin/mcpldevtool check -n "fix""me" 21 | 22 | build: 23 | needs: [ mcpldevtool_check ] 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | os: [ ubuntu-latest, windows-latest, macos-latest, windows-11-arm, ubuntu-24.04-arm, macos-13 ] 28 | name: ${{ matrix.os }} 29 | runs-on: ${{ matrix.os }} 30 | 31 | steps: 32 | - name: Checkout 33 | uses: actions/checkout@v4 34 | with: 35 | path: src 36 | 37 | - name: Setup python 38 | uses: actions/setup-python@v5 39 | with: 40 | python-version: 3.11 41 | 42 | - name: Enable parallel cmake 43 | run: python ./src/devel/bin/mcpldevtool nprocs --enable-github-parallel 44 | 45 | - name: pip install of mcpl-core 46 | run: python3 -m pip install -v ./src/mcpl_core 47 | 48 | - name: mcpl-config summary 49 | run: mcpl-config --summary 50 | 51 | - name: mcpltool 52 | run: mcpltool ./src/examples/example.mcpl 53 | 54 | - name: Check client C/CXX standards (cfg) 55 | run: cmake -S "./src/devel/misc/test_standards" -B bldstd 56 | 57 | - name: Check client C/CXX standards (build) 58 | run: cmake --build bldstd --config Debug -v 59 | 60 | - name: Check client C/CXX standards (ctest) 61 | run: ctest --test-dir bldstd --build-config Debug 62 | 63 | #Enable cl.exe usage: 64 | - name: Setup VS in shell 65 | if: runner.os == 'Windows' && matrix.os != 'windows-11-arm' 66 | uses: ilammy/msvc-dev-cmd@v1 67 | 68 | - name: Setup VS in shell 69 | if: runner.os == 'Windows' && matrix.os == 'windows-11-arm' 70 | uses: ilammy/msvc-dev-cmd@v1 71 | with: 72 | arch: arm64 73 | 74 | 75 | - name: Test downstream compilation and build flags 76 | if: runner.os == 'Windows' 77 | shell: cmd 78 | run: | 79 | 80 | echo "Set BUILDFLAGS variable via mcpl-config --show buildflags" 81 | if %errorlevel% neq 0 exit /b %errorlevel% 82 | mcpl-config --show buildflags > buildflags.txt 83 | if %errorlevel% neq 0 exit /b %errorlevel% 84 | set /p BUILDFLAGS=" 24 | echo "====> RUNNING TESTS WITH PYIO: $pyio LC/LANG: $loc (output goes to $log)" 25 | echo "======================================>" 26 | if [ "x$loc" != "xdonothing" ]; then 27 | export LC_ALL=$loc 28 | export LC_CTYPE=$loc 29 | export LANG=$loc 30 | export LANGUAGE=$loc 31 | fi 32 | cmd="pymcpltool ${REPOROOT}/tests/data/ref/reffile_encodings.mcpl.gz" > $log 33 | $cmd >> $log 34 | $cmd -nl3 >> $log 35 | for bk in asciidata asciidata_empty utf8data binarydata 'utf8bløbkey' `echo -ne "notutf8key_\xff\xfe_"`; do 36 | echo "=====> dumping blob key \"${bk}\"" >> $log 37 | $cmd -b"${bk}" >> $log 38 | echo >> $log 39 | echo -n md5sum: >> $log 40 | 41 | 42 | 43 | $cmd -b"${bk}" > tmpfile.txt 44 | md5sum tmpfile.txt >> $log 45 | done 46 | if [ "x$loc" != "xC" -a "x$pyio" != "xnone" ]; then 47 | diff -a output_pyio_none_lang_C.txt $log 48 | fi 49 | done 50 | done 51 | 52 | echo "======================================>" 53 | echo "====> All tests produced identical output, reproduced here:" 54 | echo "======================================>" 55 | cat output_pyio_none_lang_C.txt 56 | -------------------------------------------------------------------------------- /devel/misc/test_standards/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | cmake_minimum_required(VERSION 3.21...3.31) 23 | 24 | project( TestMCPLStandards VERSION 0.0.1 LANGUAGES C CXX ) 25 | 26 | if( NOT DEFINED "MCPL_DIR" ) 27 | execute_process( 28 | COMMAND mcpl-config --show cmakedir 29 | OUTPUT_VARIABLE "MCPL_DIR" OUTPUT_STRIP_TRAILING_WHITESPACE 30 | ) 31 | endif() 32 | find_package( MCPL 2.0.0 REQUIRED ) 33 | 34 | set( origsrc "${PROJECT_SOURCE_DIR}/main.c" ) 35 | 36 | set( 37 | CMAKE_MODULE_PATH 38 | ${CMAKE_MODULE_PATH} 39 | "${CMAKE_CURRENT_LIST_DIR}/../../../mcpl_core/cmake/modules" 40 | ) 41 | include( mctools_utils ) 42 | 43 | enable_testing() 44 | 45 | foreach( extensions ON OFF ) 46 | foreach( lang C CXX ) 47 | if ( lang STREQUAL C ) 48 | if ( WIN32 ) 49 | #C23 seems to not be supported yet (March 2025) with MSVC. At least not 50 | #in our platforms at github: 51 | set( stds "90;99;11;17" ) 52 | else() 53 | set( stds "90;99;11;17;23" ) 54 | endif() 55 | else() 56 | set( stds "98;11;14;17;20;23" ) 57 | endif() 58 | foreach( std ${stds} ) 59 | set( bn "${lang}_${std}_extensions${extensions}" ) 60 | set( src "${PROJECT_BINARY_DIR}/main_${bn}.${lang}" ) 61 | file( COPY_FILE "${origsrc}" "${src}" ) 62 | set( props 63 | LANGUAGE ${lang} 64 | ${lang}_STANDARD ${std} 65 | "${lang}_STANDARD_REQUIRED" ON ${lang}_EXTENSIONS ${extensions} 66 | ) 67 | set_source_files_properties ( ${src} PROPERTIES ${props} ) 68 | add_executable( "test_${bn}" "${src}" ) 69 | target_link_libraries( "test_${bn}" MCPL::MCPL ) 70 | set_target_properties( "test_${bn}" PROPERTIES ${props} ) 71 | mctools_apply_strict_comp_properties( "test_${bn}" ) 72 | add_test( 73 | NAME "test_${bn}" 74 | COMMAND "test_${bn}" 75 | "${PROJECT_SOURCE_DIR}/../../../examples/example.mcpl" ) 76 | endforeach() 77 | endforeach() 78 | endforeach() 79 | -------------------------------------------------------------------------------- /devel/misc/test_standards/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include 24 | 25 | int main(int argc,char**argv) { 26 | 27 | if (argc!=2) { 28 | printf("Please supply input filename\n"); 29 | return 1; 30 | } 31 | 32 | const char * filename = argv[1]; 33 | 34 | //Open the file: 35 | mcpl_file_t f = mcpl_open_file(filename); 36 | 37 | //For fun, access and print a bit of the info found in the header (see mcpl.h for more): 38 | 39 | printf("Opened MCPL file produced with %s\n",mcpl_hdr_srcname(f)); 40 | unsigned i; 41 | for (i = 0; i < mcpl_hdr_ncomments(f); ++i) 42 | printf("file had comment: '%s'\n",mcpl_hdr_comment(f,i)); 43 | printf("File contains %lu particles\n",(unsigned long)mcpl_hdr_nparticles(f)); 44 | 45 | //Now, loop over particles and print some info: 46 | 47 | const mcpl_particle_t* p; 48 | unsigned n; 49 | n = 0; 50 | while ( ( p = mcpl_read(f) ) ) { 51 | ++n; 52 | //print some info (see the mcpl_particle_t struct in mcpl.h for more fields): 53 | printf(" found particle with pdgcode %i and time-stamp %g ms with weight %g\n", 54 | p->pdgcode, p->time, p->weight); 55 | 56 | 57 | } 58 | if ( n != 1006 ) 59 | return 1; 60 | mcpl_close_file(f); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/devel/pypath/mcpl_repo_tools/__init__.py -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_check_copies.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | # For checking some file that must be kept completely synchronised. 23 | 24 | def get_content( relpath ): 25 | from .dirs import reporoot 26 | print(f' {relpath}') 27 | return reporoot.joinpath(relpath).read_text() 28 | 29 | def check_same( reffile, *otherfiles ): 30 | assert len(otherfiles) > 0 31 | print(' Checking for same contents:') 32 | ref = get_content( reffile ) 33 | for o in otherfiles: 34 | if get_content(o) != ref: 35 | print() 36 | raise SystemExit(f'ERROR: Content of {o} and {reffile} differs') 37 | 38 | def main(): 39 | #check_same( 'README.md', 40 | # 'mcpl_metapkg/README.md' ) 41 | 42 | check_same( 'mcpl_core/README.md', 43 | 'mcpl_core/empty_pypkg/README.md' ) 44 | 45 | check_same( 'LICENSE', 46 | 'mcpl_core/LICENSE', 47 | 'mcpl_core/empty_pypkg/LICENSE', 48 | 'mcpl_python/LICENSE', 49 | 'mcpl_metapkg/LICENSE', 50 | 'mcpl_extra/LICENSE', 51 | ) 52 | 53 | check_same( 'mcpl_core/cmake/modules/mctools_utils.cmake', 54 | 'mcpl_extra/cmake/modules/mctools_utils.cmake' ) 55 | 56 | for e in ['filter','read','write']: 57 | check_same(f'examples/example_{e}mcpl.c', 58 | f'tests/src/app_examples/example_{e}mcpl.h') 59 | 60 | if __name__=='__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_check_ruff.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def main(): 23 | from .srciter import all_files_iter 24 | import subprocess 25 | import shutil 26 | ruff = shutil.which('ruff') 27 | if not ruff: 28 | raise SystemExit('ERROR: ruff command not available') 29 | files = list(all_files_iter('py')) 30 | rv = subprocess.run(['ruff','check']+ files ) 31 | if rv.returncode!=0: 32 | raise SystemExit(1) 33 | 34 | if __name__=='__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_check_yaml.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def main(): 23 | import yaml 24 | from .srciter import all_files_iter 25 | from .dirs import reporoot 26 | 27 | for f in all_files_iter('yaml'): 28 | print(" Trying to load %s"%f.relative_to(reporoot)) 29 | with f.open() as fh: 30 | yaml.safe_load(fh) 31 | 32 | print('all ok') 33 | 34 | if __name__=='__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_climode_check.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def short_description(): 23 | return 'Run static code checks (use before committing)' 24 | 25 | def main( parser ): 26 | parser.init( """Launch all or some of the various source code checks 27 | (defined in /devel/pypath/mcpl_repo_tools/_check_*.py). The 28 | default is to run all of them.""" ) 29 | 30 | parser.add_argument( 31 | '-l','--list', action='store_true', 32 | help="""List all available checks and exit.""" 33 | ) 34 | parser.add_argument( 35 | 'CHECK', nargs='*', 36 | help="""Run this check (runs all checks if nothing is explicitly 37 | requested).""" 38 | ) 39 | parser.add_argument( 40 | '-n','--negate', action='store_true', 41 | help="""Will run all checks EXCEPT those listed.""" 42 | ) 43 | 44 | args = parser.parse_args() 45 | from . import check_runner 46 | all_checks = check_runner.get_available_checks_list() 47 | if args.list: 48 | for t in all_checks: 49 | print(t) 50 | return 51 | 52 | for c in args.CHECK: 53 | if c not in all_checks: 54 | candidates = [e for e in all_checks if ( c in e ) or ( e in c ) ] 55 | advice='' 56 | if len(candidates)==1: 57 | advice = ' (perhaps you meant "%s"?)'%candidates[0] 58 | raise SystemExit(f'Unknown check "{c}"{advice}. Run with --list ' 59 | 'to see available checks.') 60 | 61 | check_list = args.CHECK or all_checks 62 | if args.negate and args.CHECK: 63 | check_list = [ c for c in all_checks if c not in args.CHECK ] 64 | 65 | done = set() 66 | for c in check_list: 67 | if c not in done: 68 | check_runner.run_check(c) 69 | done.add(c) 70 | print() 71 | print("DONE: Ran %s checks succesfully"%( len(check_list) 72 | if args.CHECK 73 | else '%i (all)'%len(check_list))) 74 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_climode_find.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def short_description(): 23 | return 'List MCPL files based on provided parameters' 24 | 25 | def main( parser ): 26 | from . import _cliutils_common as common 27 | common.main_find( parser ) 28 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_climode_grep.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def short_description(): 23 | return 'Grep in MCPL files based on provided parameters' 24 | 25 | def main( parser ): 26 | from . import _cliutils_common as common 27 | common.main_grep( parser ) 28 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_climode_nprocs.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def short_description(): 23 | return 'Output number of processes available for multiprocessing' 24 | 25 | def main( parser ): 26 | parser.init( short_description() ) 27 | parser.add_argument( 28 | '--enable-github-parallel', action='store_true', 29 | help="""Appends CMAKE_BUILD_PARALLEL_LEVEL= to $GITHUB_ENV""" 30 | ) 31 | 32 | args = parser.parse_args() 33 | from .util import get_nprocs 34 | n = get_nprocs( nice_factor = 1.0 ) 35 | if args.enable_github_parallel: 36 | import os 37 | import pathlib 38 | p = pathlib.Path(os.environ['GITHUB_ENV']) 39 | kv = [] 40 | kv.append( ('CMAKE_BUILD_PARALLEL_LEVEL',str(n) ) ) 41 | #kv.append( ('CTEST_PARALLEL_LEVEL',str(n) ) ) 42 | s = '' 43 | for k,v in kv: 44 | print(f"Appending {k}={v} to " "${GITHUB_ENV}") 45 | s += f'{k}={v}\n' 46 | with p.open('at') as fh: 47 | fh.write(s) 48 | else: 49 | print( n ) 50 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/_climode_replace.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def short_description(): 23 | return 'Replace strings in MCPL files based on provided parameters' 24 | 25 | def main( parser ): 26 | from . import _cliutils_common as common 27 | common.main_replace( parser ) 28 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/check_runner.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def get_available_checks_list(): 23 | import pathlib 24 | return sorted( [ f.name[7:-3] for f in 25 | pathlib.Path(__file__).parent.glob('_check_*.py') ] ) 26 | 27 | def run_check( name ): 28 | print() 29 | print(f">>>>> Running check: {name}") 30 | print() 31 | import importlib 32 | pymodname = '_check_%s'%name 33 | mod = importlib.import_module(f'..{pymodname}', __name__) 34 | assert hasattr(mod,'main') 35 | mod.main() 36 | 37 | def run_all_checks(): 38 | for c in get_available_checks_list(): 39 | run_check(c) 40 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/dirs.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | import pathlib 23 | 24 | devpymoddir = pathlib.Path(__file__).absolute().resolve().parent 25 | reporoot = devpymoddir.parent.parent.parent 26 | coreroot = reporoot / 'mcpl_core' 27 | coreroot_include = coreroot / 'include' 28 | coreroot_src = coreroot / 'src' 29 | pyroot = reporoot / 'mcpl_python' 30 | testroot = reporoot / 'tests' 31 | 32 | def is_empty_dir( path ): 33 | return path.is_dir() and not any( True for p in path.iterdir() ) 34 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/mdsimpleparser.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def parse_markdown( f ): 23 | if hasattr(f,'__fspath__') or '\n' not in f: 24 | import pathlib 25 | f = pathlib.Path(f) 26 | assert f.is_file() 27 | t = f.read_text() 28 | return parse_markdown( t ) 29 | 30 | import re 31 | 32 | lines = f.splitlines() 33 | nlines = len(lines) 34 | def is_header_underline( t ): 35 | t = (t or '').strip() 36 | return bool(re.match('\\A----+',t) or re.match('\\A====+',t)) 37 | 38 | def is_header( iline ): 39 | assert iline < nlines 40 | line = lines[iline] 41 | nextline = lines[iline+1] if iline+1= (3, 11): 35 | import tomllib as mod 36 | else: 37 | import tomli as mod 38 | import pathlib 39 | with pathlib.Path(path).open("rb") as f: 40 | try: 41 | data = mod.load(f) 42 | except mod.TOMLDecodeError as e: 43 | if not prefer_sys_exit: 44 | raise 45 | print() 46 | print('TOMLDecodeError:') 47 | print() 48 | print(f' File: {path}') 49 | print() 50 | print(f' Problem: {e}') 51 | print() 52 | raise SystemExit(1) 53 | 54 | return data 55 | -------------------------------------------------------------------------------- /devel/pypath/mcpl_repo_tools/util.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | from contextlib import contextmanager as _ctxmgr 23 | 24 | def get_nprocs( nice_factor = 0.9 ): 25 | import os 26 | if hasattr(os,'sched_getaffinity'): 27 | n = len(os.sched_getaffinity(0)) 28 | else: 29 | import multiprocessing 30 | n = multiprocessing.cpu_count() 31 | n = min(1024,max(1,n)) 32 | if n >= 4: 33 | #Be nice, leave a tiny bit for other tasks on the machine: 34 | n = round( n * nice_factor ) 35 | return n 36 | 37 | @_ctxmgr 38 | def change_dir( path ): 39 | """Context manager for working in a directory (automatically 40 | created if doesn't exist) and then switching back""" 41 | import pathlib 42 | import os 43 | 44 | the_cwd = os.getcwd() 45 | p = pathlib.Path(path) 46 | p.mkdir( parents = True, exist_ok = True ) 47 | try: 48 | os.chdir( p ) 49 | yield 50 | finally: 51 | os.chdir( the_cwd ) 52 | return 53 | 54 | @_ctxmgr 55 | def work_in_tmpdir(): 56 | """Context manager for working in a temporary directory (automatically 57 | created+cleaned) and then switching back""" 58 | import os 59 | import tempfile 60 | the_cwd = os.getcwd() 61 | 62 | with tempfile.TemporaryDirectory() as tmpdir: 63 | try: 64 | os.chdir(tmpdir) 65 | yield 66 | finally: 67 | os.chdir(the_cwd)#Important to leave tmpdir *before* deletion, to 68 | #avoid PermissionError on Windows. 69 | 70 | def path_is_relative_to( p, pother ): 71 | #Path.is_relative_to(..) was introduced in Python 3.9, this function lets us 72 | #support python 3.8. 73 | import pathlib 74 | assert isinstance( p, pathlib.Path ) 75 | if hasattr(p,'is_relative_to'): 76 | #Python 3.9+: 77 | return p.is_relative_to(pother) 78 | else: 79 | #Python 3.8: 80 | try: 81 | p.relative_to(pother) 82 | return True 83 | except ValueError: 84 | return False 85 | -------------------------------------------------------------------------------- /devel/reqs/requirements_devel.txt: -------------------------------------------------------------------------------- 1 | PyYAML>=6.0.0 2 | matplotlib>=3.6.0 3 | numpy>=1.22 4 | ruff>=0.8.1 5 | tomli>=2.0.0; python_version < "3.11" 6 | -------------------------------------------------------------------------------- /devel/setup.sh: -------------------------------------------------------------------------------- 1 | #Support bash and zsh, and enable mcpldevtool bash completions on first keyword, 2 | #in case of bash4 (i.e. not osx shipped bash): 3 | 4 | if [ "x${BASH_VERSION:-}" != "x" ]; then 5 | export PATH="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/bin:${PATH}" 6 | if ((BASH_VERSINFO >= 4)); then 7 | type complete compgen 1>/dev/null 2>/dev/null 8 | if [ $? == 0 ]; then 9 | _mcpldevtool_completions () 10 | { 11 | if [ $COMP_CWORD -eq 1 ]; then 12 | COMPREPLY=($(compgen -W "$(mcpldevtool --show-completion-list)" "${COMP_WORDS[1]}")) 13 | else 14 | COMPREPLY=() 15 | fi 16 | } 17 | complete -o bashdefault -o default -F _mcpldevtool_completions mcpldevtool 18 | fi 19 | fi 20 | elif [ "x${ZSH_VERSION:-}" != "x" ]; then 21 | export PATH="${0:a:h}/bin:${PATH}" 22 | else 23 | echo "ERROR: This script only supports bash or zsh for now. You will" 24 | echo " have to manually add /devel/bin to your PATH" 25 | fi 26 | -------------------------------------------------------------------------------- /examples/downstream_cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | cmake_minimum_required(VERSION 3.16...3.31) 23 | 24 | project( ExampleMCPLProject VERSION 0.0.1 LANGUAGES C ) 25 | 26 | #Find MCPL: 27 | 28 | if( NOT DEFINED "MCPL_DIR" ) 29 | #Need to invoke "mcpl-config --show cmakedir" if we want to be able to 30 | #work with mcpl-core installed via python wheels: 31 | execute_process( 32 | COMMAND mcpl-config --show cmakedir 33 | OUTPUT_VARIABLE "MCPL_DIR" OUTPUT_STRIP_TRAILING_WHITESPACE 34 | ) 35 | endif() 36 | find_package( MCPL 2.0.0 REQUIRED ) 37 | 38 | #Add our own targets, and link to MCPL as appropriate: 39 | 40 | add_executable( "testapp" "main.c" ) 41 | target_link_libraries( "testapp" MCPL::MCPL ) 42 | install (TARGETS "testapp" RUNTIME DESTINATION bin) 43 | -------------------------------------------------------------------------------- /examples/downstream_cmake/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | // A small standalone example of how to one might read particles from an MCPL 23 | // file into a C programme. 24 | 25 | #include "mcpl.h" 26 | #include 27 | 28 | int main(int argc,char**argv) { 29 | 30 | if (argc!=2) { 31 | printf("Please supply input filename\n"); 32 | return 1; 33 | } 34 | 35 | const char * filename = argv[1]; 36 | 37 | //Open the file: 38 | mcpl_file_t f = mcpl_open_file(filename); 39 | 40 | //For fun, access and print a bit of the info found in the header (see mcpl.h for more): 41 | 42 | printf("Opened MCPL file produced with %s\n",mcpl_hdr_srcname(f)); 43 | unsigned i; 44 | for (i = 0; i < mcpl_hdr_ncomments(f); ++i) 45 | printf("file had comment: '%s'\n",mcpl_hdr_comment(f,i)); 46 | printf("File contains %llu particles\n",(unsigned long long)mcpl_hdr_nparticles(f)); 47 | 48 | //Now, loop over particles and print some info: 49 | 50 | const mcpl_particle_t* p; 51 | while ( ( p = mcpl_read(f) ) ) { 52 | 53 | //print some info (see the mcpl_particle_t struct in mcpl.h for more fields): 54 | printf(" found particle with pdgcode %i and time-stamp %g ms with weight %g\n", 55 | p->pdgcode, p->time, p->weight); 56 | 57 | 58 | } 59 | 60 | mcpl_close_file(f); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /examples/example.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/examples/example.mcpl -------------------------------------------------------------------------------- /examples/example_readmcpl.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | // A small standalone example of how to one might read particles from an MCPL 23 | // file into a C programme. 24 | 25 | #include "mcpl.h" 26 | #include 27 | #include 28 | #include 29 | 30 | int main(int argc,char**argv) { 31 | 32 | if (argc!=2) { 33 | printf("Please supply input filename\n"); 34 | return 1; 35 | } 36 | 37 | const char * filename = argv[1]; 38 | 39 | //Open the file: 40 | mcpl_file_t f = mcpl_open_file(filename); 41 | 42 | //For fun, access and print a bit of the info found in the header (see mcpl.h 43 | //for more): 44 | 45 | printf("Opened MCPL file produced with %s\n",mcpl_hdr_srcname(f)); 46 | unsigned i; 47 | for (i = 0; i < mcpl_hdr_ncomments(f); ++i) 48 | printf( "file had comment: '%s'\n", mcpl_hdr_comment(f,i) ); 49 | printf( "File contains %llu particles\n", 50 | (unsigned long long)mcpl_hdr_nparticles(f) ); 51 | 52 | //Now, loop over particles and print some info: 53 | 54 | const mcpl_particle_t* p; 55 | while ( 1 ) { 56 | p = mcpl_read(f); 57 | if ( !p ) 58 | break; 59 | 60 | //print some info (see the mcpl_particle_t struct in mcpl.h for all fields): 61 | printf( " found particle with " 62 | "pdgcode %i and time-stamp %g ms with weight %g\n", 63 | p->pdgcode, p->time, p->weight ); 64 | 65 | } 66 | 67 | mcpl_close_file(f); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /examples/pyexample_readmcpl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ################################################################################ 4 | ## ## 5 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 6 | ## ## 7 | ## Copyright 2015-2025 MCPL developers. ## 8 | ## ## 9 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 10 | ## you may not use this file except in compliance with the License. ## 11 | ## You may obtain a copy of the License at ## 12 | ## ## 13 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 14 | ## ## 15 | ## Unless required by applicable law or agreed to in writing, software ## 16 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 17 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 18 | ## See the License for the specific language governing permissions and ## 19 | ## limitations under the License. ## 20 | ## ## 21 | ################################################################################ 22 | 23 | # Simple example with comments, showing how one can use the mcpl Python API to 24 | # access MCPL files. 25 | 26 | import mcpl 27 | import sys 28 | 29 | #Get name of input file to open from command line: 30 | inputfile = sys.argv[1] 31 | 32 | #Uncomment next line for module documentation: 33 | #help(mcpl) 34 | 35 | #Open the file: 36 | f = mcpl.MCPLFile(inputfile) 37 | 38 | #Dump entire header to stdout: 39 | f.dump_hdr() 40 | 41 | #Or access relevant parts: 42 | print( 'Number of particles in file: %i' % f.nparticles ) 43 | print( 'Numbers are in single-precision: %s' % f.opt_singleprec ) 44 | for c in f.comments: 45 | print( "Some comment: %s" % c ) 46 | 47 | #Loop over all particles and print their positions and energies: 48 | for p in f.particles: 49 | print( p.x, p.y, p.z, p.ekin ) 50 | #help(p) #<-- uncomment to see all field names 51 | 52 | #Same, but each iteration will be over a big "block" of 10000 particles, so all 53 | #fields are now numpy arrays of length 10000: 54 | 55 | for p in f.particle_blocks: 56 | print( p.x, p.y, p.z, p.ekin ) 57 | 58 | #NB: change blocklength to, say, 1000, by opening file with: 59 | # mcpl.MCPLFile('example.mcpl',blocklength=1000) 60 | -------------------------------------------------------------------------------- /mcpl_core/app_tool/mcpltool_app.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | 24 | #ifdef _WIN32 25 | int wmain( int argc, wchar_t *argv[ ] ) 26 | { 27 | return mcpl_wrap_wmain( argc, argv, mcpl_tool ); 28 | } 29 | #else 30 | int main ( int argc, char** argv ) 31 | { 32 | return mcpl_tool(argc,argv); 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /mcpl_core/cmake/modules/mcpl_coretests.cmake: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | # Tests which can be run when only mcpl_core is built, and which is even OK 23 | # to use before an installation step (this is not the case with the tests in 24 | # /tests). 25 | 26 | include_guard() 27 | 28 | function( mcpl_core_setup_tests ) 29 | # set_source_files_properties( 30 | # "${Project_SOURCE_DIR}/app_test/main.cc" 31 | # PROPERTIES LANGUAGE CXX 32 | # ) 33 | add_executable( "testapp_testwritegzip" "${PROJECT_SOURCE_DIR}/tests/src/app_testwritegzip/main.c" ) 34 | target_link_libraries( "testapp_testwritegzip" PRIVATE MCPL::MCPL ) 35 | add_test( NAME "testapp_testwritegzip" COMMAND "testapp_testwritegzip" ) 36 | set_property( TEST "testapp_testwritegzip" PROPERTY TIMEOUT "$,20,7>" ) 37 | endfunction() 38 | 39 | mcpl_core_setup_tests() 40 | -------------------------------------------------------------------------------- /mcpl_core/cmake/modules/mcpl_headercreate.cmake: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | include_guard() 23 | 24 | function( mcpl_create_header resvar_includepath ) 25 | #Generate mcpl.h via both configure_file (for non-config specific variables) 26 | #and then file(GENERATE ..) (for generator expressions) based on the 27 | #mcpl.h.in template. 28 | set( srctemplate "${PROJECT_SOURCE_DIR}/include/mcpl.h.in" ) 29 | set( tgtincdir "${PROJECT_BINARY_DIR}/autogen_include_mcplh" ) 30 | set( tgtdir "${tgtincdir}" ) 31 | set( tgtfile "${tgtdir}/mcpl.h" ) 32 | file( MAKE_DIRECTORY "${tgtdir}" ) 33 | set( t1 "1000000 * ${MCPL_VERSION_MAJOR}" ) 34 | set( t2 "1000 * ${MCPL_VERSION_MINOR}" ) 35 | set( t3 "${MCPL_VERSION_PATCH}" ) 36 | math(EXPR version_int "(${t1})+(${t2})+(${t3})" ) 37 | set( ncapidefs "" ) 38 | string( APPEND ncapidefs "#define MCPL_VERSION_MAJOR ${MCPL_VERSION_MAJOR}\n" ) 39 | string( APPEND ncapidefs "#define MCPL_VERSION_MINOR ${MCPL_VERSION_MINOR}\n" ) 40 | string( APPEND ncapidefs "#define MCPL_VERSION_PATCH ${MCPL_VERSION_PATCH}\n" ) 41 | string( APPEND ncapidefs "#define MCPL_VERSION ${version_int}\n" ) 42 | string( APPEND ncapidefs "#define MCPL_VERSION_STR \"${MCPL_VERSION}\"\n" ) 43 | set( MCPL_HOOK_FOR_ADDING_DEFINES 44 | " -- CMake definitions begin -- */\n\n${ncapidefs}\n/* -- CMake definitions end --" ) 45 | configure_file( "${srctemplate}" "${tgtfile}" @ONLY ) 46 | set( "${resvar_includepath}" "${tgtincdir}" PARENT_SCOPE ) 47 | endfunction() 48 | 49 | -------------------------------------------------------------------------------- /mcpl_core/cmake/template_mcplconfig.h: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************/ 3 | /* */ 4 | /* This file is part of MCPL (see https://mctools.github.io/mcpl/) */ 5 | /* */ 6 | /* Copyright 2015-2025 MCPL developers. */ 7 | /* */ 8 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 | /* you may not use this file except in compliance with the License. */ 10 | /* You may obtain a copy of the License at */ 11 | /* */ 12 | /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 | /* */ 14 | /* Unless required by applicable law or agreed to in writing, software */ 15 | /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 | /* See the License for the specific language governing permissions and */ 18 | /* limitations under the License. */ 19 | /* */ 20 | /******************************************************************************/ 21 | 22 | //Note about this template: At CMake configuration time, the AT-SIGN enclosed 23 | //CMake variables are expanded. Then at CMake build time, the Generator 24 | //expressions are expanded. 25 | 26 | const char * mcplcfg_const_bin2libdir(void) { return "@MCPL_relpath_BINDIR2LIBDIR@"; } 27 | const char * mcplcfg_const_bin2shlibdir(void) { return "@MCPL_relpath_BINDIR2SHLIBDIR@"; } 28 | const char * mcplcfg_const_libname(void) { return "@MCPL_libname_genexp@"; }//NB: generator expression 29 | const char * mcplcfg_const_shlibname(void) { return "@MCPL_shlibname_genexp@"; }//NB: generator expression 30 | const char * mcplcfg_const_bin2libpath(void) { return "@MCPL_relpath_BINDIR2LIBDIR@/@MCPL_libname_genexp@"; } 31 | const char * mcplcfg_const_bin2shlibpath(void) { return "@MCPL_relpath_BINDIR2SHLIBDIR@/@MCPL_shlibname_genexp@"; } 32 | const char * mcplcfg_const_bin2incdir(void) { return "@MCPL_relpath_BINDIR2INCDIR@"; } 33 | const char * mcplcfg_const_bin2cmakedir(void) { return "@MCPL_relpath_BINDIR2CMAKEDIR@"; } 34 | const char * mcplcfg_const_version(void) { return "@MCPL_VERSION@"; } 35 | const char * mcplcfg_const_intversion(void) { return "@mcplcfgapp_intversion@"; } 36 | //const char * mcplcfg_const_namespace(void) { return "@MCPL_NAMESPACE@"; } 37 | const char * mcplcfg_const_cmakebuildtype(void) { return "$"; }//NB: generator expression 38 | int mcplcfg_boolopt_expects_shlibdir_override(void) { return @mcplcfgapp_expect_shlibdir_override_01@; } 39 | -------------------------------------------------------------------------------- /mcpl_core/empty_pypkg/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | # A pyproject.toml for injecting an empty mcpl-core package. In case mcpl-core 23 | # is installed in a non-python aware fashion, installing this empty mcpl-core 24 | # package can be used to ensure that subsequent pip installations of packages 25 | # needing mcpl-core will not cause pip to pull down mcpl-core from pypi. Of 26 | # course, this is not bullet-proof, since "pip uninstall mcpl-core" will only 27 | # uninstall the empty package, not all of mcpl-core content. 28 | 29 | [build-system] 30 | requires = ["setuptools>=75.3.2"] 31 | build-backend = "setuptools.build_meta" 32 | 33 | [project] 34 | name = "mcpl-core" 35 | version = "2.2.0" 36 | requires-python = ">=3.8" 37 | readme = "README.md" 38 | license = {text = "Apache-2.0"} 39 | authors = [ 40 | { name="MCPL developers (Thomas Kittelmann, et. al.)" }, 41 | ] 42 | description = "Utilities and API for accessing MCPL (.mcpl) files" 43 | classifiers = [ 44 | "Programming Language :: Python :: 3", 45 | "License :: OSI Approved :: Apache Software License", 46 | ] 47 | 48 | [project.urls] 49 | "Homepage" = "https://mctools.github.io/mcpl/" 50 | "Bug Tracker" = "https://github.com/mctools/mcpl/issues" 51 | -------------------------------------------------------------------------------- /mcpl_core/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | [project] 23 | name = "mcpl-core" 24 | version = "2.2.0" 25 | requires-python = ">=3.8" 26 | readme = "README.md" 27 | license = {text = "Apache-2.0"} 28 | authors = [ 29 | { name="MCPL developers (Thomas Kittelmann, et. al.)" }, 30 | ] 31 | description = "Utilities and API for accessing MCPL (.mcpl) files" 32 | classifiers = [ 33 | "Programming Language :: Python :: 3", 34 | "License :: OSI Approved :: Apache Software License", 35 | ] 36 | 37 | [project.urls] 38 | "Homepage" = "https://mctools.github.io/mcpl/" 39 | "Bug Tracker" = "https://github.com/mctools/mcpl/issues" 40 | 41 | [project.scripts] 42 | mcpl-config = "_mcpl_core.info:_mcpl_config_cli_wrapper" 43 | mcpltool = "_mcpl_core.info:_mcpl_tool_cli_wrapper" 44 | 45 | [build-system] 46 | requires = ["scikit-build-core>=0.11.0"] 47 | build-backend = "scikit_build_core.build" 48 | 49 | [tool.scikit-build] 50 | logging.level = "INFO" 51 | minimum-version = "build-system.requires" 52 | wheel.packages = ['skbld_autogen/_mcpl_core'] 53 | sdist.include = ["/src/","/include/","/cmake/", 54 | '/app_config/','/CMakeLists.txt','/pyproject.toml', 55 | '/skbld_autogen/' 56 | ] 57 | sdist.cmake = true 58 | wheel.py-api = "py3" # as close to "noarch" as possible (ABI3) 59 | 60 | [tool.cibuildwheel.linux] 61 | #No 32bit wheels, since it gives problems with files >2GB. 62 | archs = ["auto64"] 63 | -------------------------------------------------------------------------------- /mcpl_core/tests/src/app_testwritegzip/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include 24 | #include 25 | 26 | int main(int argc,char**argv) { 27 | (void)argc; 28 | (void)argv; 29 | 30 | //Create file with some rather fake content: 31 | mcpl_outfile_t f = mcpl_create_outfile("out.mcpl"); 32 | mcpl_hdr_set_srcname(f,"CustomTest"); 33 | mcpl_enable_universal_pdgcode(f,2112);//all particles are neutrons 34 | mcpl_hdr_add_comment(f,"Some comment."); 35 | mcpl_hdr_add_comment(f,"Another comment."); 36 | mcpl_particle_t * particle = mcpl_get_empty_particle(f); 37 | for (int i = 0; i < 50000; ++i) { 38 | particle->position[0] = i*1.0; 39 | particle->position[1] = i*2.0; 40 | particle->position[2] = i*3.0; 41 | particle->ekin = i*0.1; 42 | particle->direction[0] = 0.0; 43 | particle->direction[1] = 0.0; 44 | particle->direction[2] = 1.0; 45 | particle->time = i*0.01; 46 | particle->weight = 1.0; 47 | mcpl_add_particle(f,particle); 48 | } 49 | 50 | //close up and gzip: 51 | mcpl_closeandgzip_outfile(f); 52 | 53 | //Check file: 54 | mcpl_dump("out.mcpl.gz", 0,0,20); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /mcpl_extra/README.md: -------------------------------------------------------------------------------- 1 | MCPL - Monte Carlo Particle Lists 2 | ================================= 3 | 4 | MCPL files, with extensions `.mcpl` and `.mcpl.gz` is a binary format for usage 5 | in physics particle simulations. It contains lists of particle state 6 | information, and can be used to interchange or reuse particles between various 7 | Monte Carlo simulation applications. The format itself is formally described in: 8 | 9 | T. Kittelmann, et al., Monte Carlo Particle Lists: MCPL, Computer Physics 10 | Communications 218, 17-42 (2017), https://doi.org/10.1016/j.cpc.2017.04.012 11 | 12 | All MCPL code is provided under the highly liberal open source Apache 2.0 13 | license (http://www.apache.org/licenses/LICENSE-2.0), and further instructions 14 | and documentation can be found at https://mctools.github.io/mcpl/. 15 | 16 | 17 | 18 | The mcpl-extra package 19 | ---------------------- 20 | 21 | The `mcpl-extra` package is intended to provide tools and conversion utilities 22 | related to MCPL files, beyond what is available in the `mcpl-core` package. This 23 | currently includes converters to and from file formats related to PHITS and 24 | MCNP(5/X/6). 25 | 26 | For more details about how to use these converters, refer to the 27 | https://mctools.github.io/mcpl/hooks_mcnp and 28 | https://mctools.github.io/mcpl/hooks_phits pages. 29 | 30 | 31 | 32 | Scientific reference 33 | -------------------- 34 | 35 | Copyright 2015-2025 MCPL developers. 36 | 37 | This software was mainly developed at the European Spallation Source ERIC (ESS) 38 | and the Technical University of Denmark (DTU). This work was supported in part 39 | by the European Union's Horizon 2020 research and innovation programme under 40 | grant agreement No 676548 (the BrightnESS project). 41 | 42 | All MCPL files are distributed under the Apache 2.0 license, available at 43 | http://www.apache.org/licenses/LICENSE-2.0, as well as in the LICENSE file found 44 | in the source distribution. 45 | 46 | A substantial effort went into developing MCPL. If you use it for your work, we 47 | would appreciate it if you would use the following reference in your work: 48 | 49 | T. Kittelmann, et al., Monte Carlo Particle Lists: MCPL, Computer Physics 50 | Communications 218, 17-42 (2017), https://doi.org/10.1016/j.cpc.2017.04.012 51 | 52 | 53 | 54 | Support for specific third party applications 55 | --------------------------------------------- 56 | 57 | Note that some users might also wish to additionally install the `mcpl-extra` 58 | package, which contains cmdline tools for converting between the binary data 59 | files native to some third-party Monte Carlo applications (currently PHITS and 60 | MCNP[X/5/6]). Users of Geant4 might wish to install the `mcpl-geant4` package, 61 | which provides C++ classes (and CMake configuration code) for integrating MCPL 62 | I/O into Geant4 simulations. Finally, many Monte Carlo applications have 63 | directly integrated support for MCPL I/O into their codes. At the time of 64 | writing, the list of applications with known support from MCPL I/O includes: 65 | 66 | * McStas (built in) 67 | * McXtrace (built in) 68 | * OpenMC (built in) 69 | * Cinema/Prompt (built in) 70 | * VITESS (built in) 71 | * RESTRAX/SIMRES (built in) 72 | * McVine (built in) 73 | * MCNPX, MCNP5, MCNP6 (based on `ssw2mcpl`/`mcpl2ssw` from the `mcpl-extra` package) 74 | * PHITS (based on `phits2mcpl`/`mcpl2phits` from the `mcpl-extra` package) 75 | * Geant4 (based on C++/CMake code from the `mcpl-geant4` package) 76 | 77 | Note that instructions for installation and setup of third-party products like 78 | those listed above are beyond the scope of the MCPL project. Please refer to the 79 | products own instructions for more information. 80 | -------------------------------------------------------------------------------- /mcpl_extra/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | [project] 23 | name = "mcpl-extra" 24 | version = "2.2.0" 25 | dependencies = [ 'mcpl-core==2.2.0' ] 26 | requires-python = ">=3.8" 27 | readme = "README.md" 28 | license = {text = "Apache-2.0"} 29 | authors = [ 30 | { name="MCPL developers (Thomas Kittelmann, et. al.)" }, 31 | ] 32 | description = "Various tools and conversion utilities related to MCPL files." 33 | classifiers = [ 34 | "Programming Language :: Python :: 3", 35 | "License :: OSI Approved :: Apache Software License", 36 | ] 37 | 38 | [project.urls] 39 | "Homepage" = "https://mctools.github.io/mcpl/" 40 | "Bug Tracker" = "https://github.com/mctools/mcpl/issues" 41 | 42 | [project.scripts] 43 | ssw2mcpl = "_mcpl_extra.cli:cli_wrapper_ssw2mcpl" 44 | mcpl2ssw = "_mcpl_extra.cli:cli_wrapper_mcpl2ssw" 45 | phits2mcpl = "_mcpl_extra.cli:cli_wrapper_phits2mcpl" 46 | mcpl2phits = "_mcpl_extra.cli:cli_wrapper_mcpl2phits" 47 | 48 | [build-system] 49 | requires = ["scikit-build-core>=0.11.0","mcpl-core==2.2.0"] 50 | build-backend = "scikit_build_core.build" 51 | 52 | [tool.scikit-build] 53 | logging.level = "INFO" 54 | minimum-version = "build-system.requires" 55 | wheel.packages = ['pywrapper/_mcpl_extra'] 56 | sdist.include = ["/src/",'/CMakeLists.txt','/pyproject.toml','/pywrapper/'] 57 | #sdist.cmake = true 58 | wheel.py-api = "py3" # as close to "noarch" as possible (ABI3) 59 | 60 | [tool.cibuildwheel.linux] 61 | #No 32bit wheels, since it gives problems with files >2GB. 62 | archs = ["auto64"] 63 | -------------------------------------------------------------------------------- /mcpl_extra/pywrapper/_mcpl_extra/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/mcpl_extra/pywrapper/_mcpl_extra/__init__.py -------------------------------------------------------------------------------- /mcpl_extra/pywrapper/_mcpl_extra/cli.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | # Module which expose the actual binary cmdline scripts. 23 | 24 | def cli_wrapper_mcpl2ssw(): 25 | _run('mcpl2ssw') 26 | 27 | def cli_wrapper_ssw2mcpl(): 28 | _run('ssw2mcpl') 29 | 30 | def cli_wrapper_mcpl2phits(): 31 | _run('mcpl2phits') 32 | 33 | def cli_wrapper_phits2mcpl(): 34 | _run('phits2mcpl') 35 | 36 | def _get_mcpl_shlibdir_unix(): 37 | import subprocess 38 | rv = subprocess.run( ['mcpl-config','--show','shlibdir'], 39 | check = True, capture_output = True ) 40 | if rv.returncode or rv.stderr: 41 | raise RuntimeError('Problems invoking mcpl-config for shlibdir') 42 | import pathlib 43 | return pathlib.Path(rv.stdout.decode().strip()).absolute().resolve() 44 | 45 | def _run(toolname): 46 | import subprocess 47 | import pathlib 48 | import sys 49 | import platform 50 | a = sys.argv[:] 51 | a[0] = pathlib.Path(__file__).parent.joinpath('data','bin',toolname) 52 | sysname = platform.system() 53 | if sysname != 'Windows': 54 | #Inject libmcpl.so in (DY)LD_LIBRARY_PATH, just in case: 55 | import os 56 | env = os.environ.copy() 57 | d = _get_mcpl_shlibdir_unix() 58 | n = 'DYLD_LIBRARY_PATH' if sysname == 'Darwin' else 'LD_LIBRARY_PATH' 59 | v = env.get(n) 60 | if v: 61 | env[n] = '%s:%s'%(d,v) 62 | else: 63 | env[n] = str(d) 64 | else: 65 | #On windows MCPL.dll should already be in PATH: 66 | env = None 67 | rv = subprocess.run( a, env = env ) 68 | raise SystemExit(rv.returncode) 69 | -------------------------------------------------------------------------------- /mcpl_extra/src/phits/app_mcpl2phits/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "phitsmcpl.h" 23 | #include "mcpl.h" 24 | 25 | #ifdef _WIN32 26 | int wmain( int argc, wchar_t *argv[ ] ) 27 | { 28 | return mcpl_wrap_wmain( argc, argv, mcpl2phits_app ); 29 | } 30 | #else 31 | int main(int argc,char** argv) { 32 | return mcpl2phits_app(argc,argv); 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /mcpl_extra/src/phits/app_phits2mcpl/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "phitsmcpl.h" 23 | #include "mcpl.h" 24 | 25 | #ifdef _WIN32 26 | int wmain( int argc, wchar_t *argv[ ] ) 27 | { 28 | return mcpl_wrap_wmain( argc, argv, phits2mcpl_app ); 29 | } 30 | #else 31 | int main(int argc,char** argv) { 32 | return phits2mcpl_app(argc,argv); 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /mcpl_extra/src/ssw/app_mcpl2ssw/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "sswmcpl.h" 23 | #include "mcpl.h" 24 | 25 | #ifdef _WIN32 26 | int wmain( int argc, wchar_t *argv[ ] ) 27 | { 28 | return mcpl_wrap_wmain( argc, argv, mcpl2ssw_app ); 29 | } 30 | #else 31 | int main(int argc,char** argv) { 32 | return mcpl2ssw_app(argc,argv); 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /mcpl_extra/src/ssw/app_ssw2mcpl/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "sswmcpl.h" 23 | #include "mcpl.h" 24 | 25 | #ifdef _WIN32 26 | int wmain( int argc, wchar_t *argv[ ] ) 27 | { 28 | return mcpl_wrap_wmain( argc, argv, ssw2mcpl_app ); 29 | } 30 | #else 31 | int main ( int argc, char** argv ) 32 | { 33 | return ssw2mcpl_app(argc,argv); 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /mcpl_metapkg/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | [build-system] 23 | requires = ["setuptools>=75.3.2"] 24 | build-backend = "setuptools.build_meta" 25 | 26 | [project] 27 | name = "mcpl" 28 | version = "2.2.0" 29 | dependencies = [ 'mcpl-core==2.2.0', 'mcpl-python==2.2.0' ] 30 | requires-python = ">=3.8" 31 | readme = "README.md" 32 | license = {text = "Apache-2.0"} 33 | authors = [ 34 | { name="MCPL developers (Thomas Kittelmann, et. al.)" }, 35 | ] 36 | description = "Utilities and API for accessing MCPL (.mcpl) files" 37 | classifiers = [ 38 | "Programming Language :: Python :: 3", 39 | "License :: OSI Approved :: Apache Software License", 40 | ] 41 | 42 | [project.urls] 43 | "Homepage" = "https://mctools.github.io/mcpl/" 44 | "Bug Tracker" = "https://github.com/mctools/mcpl/issues" 45 | -------------------------------------------------------------------------------- /mcpl_python/pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | [build-system] 23 | requires = ["setuptools>=75.3.2"] 24 | build-backend = "setuptools.build_meta" 25 | 26 | [tool.setuptools.dynamic] 27 | version = {attr = "mcpl.__version__"} 28 | 29 | [project] 30 | name = "mcpl-python" 31 | dynamic = [ 'version' ] 32 | requires-python = ">=3.8" 33 | dependencies = [ 'numpy>=1.22' ] 34 | readme = "README.md" 35 | license = {text = "Apache-2.0"} 36 | authors = [ 37 | { name="MCPL developers (Thomas Kittelmann, et. al.)" }, 38 | ] 39 | description = "Utilities and API for accessing MCPL (.mcpl) files" 40 | classifiers = [ 41 | "Programming Language :: Python :: 3", 42 | "License :: OSI Approved :: Apache Software License", 43 | ] 44 | 45 | [project.urls] 46 | "Homepage" = "https://mctools.github.io/mcpl/" 47 | "Bug Tracker" = "https://github.com/mctools/mcpl/issues" 48 | 49 | [project.scripts] 50 | pymcpltool = "mcpl.mcpl:main" 51 | -------------------------------------------------------------------------------- /mcpl_python/src/mcpl/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | """Python module for accessing MCPL files. 23 | 24 | The MCPL (Monte Carlo Particle Lists) format is thoroughly documented on the 25 | project homepage, from where it is also possible to download the entire MCPL 26 | distribution: 27 | 28 | https://mctools.github.io/mcpl/ 29 | 30 | Specifically, more documentation about how to use the present python module to 31 | access MCPL files can be found at: 32 | 33 | https://mctools.github.io/mcpl/usage_python/ 34 | 35 | This file can freely used as per the terms in the LICENSE file distributed with 36 | MCPL, also available at https://github.com/mctools/mcpl/blob/master/LICENSE . 37 | 38 | A substantial effort went into developing MCPL. If you use it for your work, we 39 | would appreciate it if you would use the following reference in your work: 40 | 41 | T. Kittelmann, et al., Monte Carlo Particle Lists: MCPL, Computer Physics 42 | Communications 218, 17-42 (2017), https://doi.org/10.1016/j.cpc.2017.04.012 43 | 44 | mcpl.py written by Thomas Kittelmann, 2017-2022. The work was supported by the 45 | European Union's Horizon 2020 research and innovation programme under grant 46 | agreement No 676548 (the BrightnESS project) 47 | """ 48 | 49 | __all__ = [ 'MCPLFile', 50 | 'MCPLParticle', 51 | 'MCPLParticleBlock', 52 | 'MCPLError', 53 | 'dump_file', 54 | 'convert2ascii', 55 | 'app_pymcpltool', 56 | 'collect_stats', 57 | 'dump_stats', 58 | 'plot_stats', 59 | 'encode_stat_sum', 60 | 'is_valid_stat_sum_key' 61 | ] 62 | 63 | __version__ = '2.2.0' 64 | 65 | from .mcpl import ( MCPLFile, 66 | MCPLParticle, 67 | MCPLParticleBlock, 68 | MCPLError, 69 | dump_file, 70 | convert2ascii, 71 | app_pymcpltool, 72 | collect_stats, 73 | dump_stats, 74 | plot_stats, 75 | encode_stat_sum, 76 | is_valid_stat_sum_key ) 77 | -------------------------------------------------------------------------------- /mcpl_python/src/mcpl/__main__.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | if __name__ == '__main__': 23 | from .mcpl import main 24 | main() 25 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | MCPL unit tests 2 | --------------- 3 | 4 | This subdirectory adds a suite of unit tests for MCPL. The primary way to 5 | exercise them is to configure and build (but not install) the CMake project at 6 | the root of the repository (i.e. one level up from here), with the option 7 | `MCPL_ENABLE_TESTING=ON`, and then subsequently launch the tests via 8 | ctest. Additionally, the `MCPLEXTRA_ADDITIONAL_TESTS` option can be used to add 9 | extra tests not residing in this repository. 10 | 11 | Alternatively, one can also use the developer command `mcpldevtool` from the 12 | folder at `/devel/bin` (on unix one can inject it into the PATH by 13 | sourcing the script at `/devel/setup.sh`). With that, one can simply 14 | launch the tests via the command `mcpldevtool cmake`. 15 | 16 | Note that in addition to the tests here, the command `ncdevtool check` provides 17 | several fast checks of the repository based on static code inspection. 18 | -------------------------------------------------------------------------------- /tests/data/ref/difficult_unitvector.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/difficult_unitvector.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/gammas_uw.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/gammas_uw.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/miscphys.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/miscphys.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/ref_statsum.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/ref_statsum.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/ref_statsum_crash.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/ref_statsum_crash.mcpl -------------------------------------------------------------------------------- /tests/data/ref/ref_statunsupported.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/ref_statunsupported.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_1.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_1.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_10.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_10.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_11.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_11.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_12.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_12.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_13.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_13.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_14.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_14.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_15.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_15.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_16.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_16.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_2.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_2.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_2.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_2.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_3.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_3.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_4.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_4.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_5.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_5.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_5.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_5.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_6.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_6.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_7.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_7.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_8.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_8.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_9.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_9.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad1.mcpl: -------------------------------------------------------------------------------- 1 | MPLC1234lalalalal 2 | -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad1.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_bad1.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad2.mcpl: -------------------------------------------------------------------------------- 1 | MCPL001Llalalalal 2 | -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad2.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_bad2.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad3.mcpl: -------------------------------------------------------------------------------- 1 | MCPL999Llalalalal 2 | -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad3.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_bad3.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad4.mcpl: -------------------------------------------------------------------------------- 1 | MCPL003Glalalalal 2 | -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad4.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_bad4.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_bad_duplicatestatsumkeys.mcpl: -------------------------------------------------------------------------------- 1 | MCPL003L$unknown%stat:sum:bla: 4%stat:sum:bla: 1.2%stat:sum:bla: 3.4 -------------------------------------------------------------------------------- /tests/data/ref/reffile_crash.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_crash.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_crash.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_crash.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_empty.mcpl: -------------------------------------------------------------------------------- 1 | MCPL003L`MyMCAppBlaData0123456789 2 | 345678Bl 3 | -------------------------------------------------------------------------------- /tests/data/ref/reffile_empty.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_empty.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_encodings.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_encodings.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_notreallygz.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_notreallygz.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_skip123.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_skip123.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_skip123.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_skip123.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_truncated.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_truncated.mcpl -------------------------------------------------------------------------------- /tests/data/ref/reffile_truncated.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_truncated.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_userflags_is_pos.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_userflags_is_pos.mcpl.gz -------------------------------------------------------------------------------- /tests/data/ref/reffile_uw.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/ref/reffile_uw.mcpl.gz -------------------------------------------------------------------------------- /tests/data/reffmt2/miscphys.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/miscphys.mcpl.gz -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_1.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_1.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_10.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_10.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_11.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_11.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_12.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_12.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_13.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_13.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_14.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_14.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_15.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_15.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_16.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_16.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_2.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_2.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_2.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_2.mcpl.gz -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_3.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_3.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_4.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_4.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_5.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_5.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_5.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_5.mcpl.gz -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_6.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_6.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_7.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_7.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_8.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_8.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_9.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_9.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_crash.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_crash.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_crash.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_crash.mcpl.gz -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_empty.mcpl: -------------------------------------------------------------------------------- 1 | MCPL002L`MyMCAppBlaData0123456789 2 | 345678Bl 3 | -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_empty.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_empty.mcpl.gz -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_skip123.mcpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_skip123.mcpl -------------------------------------------------------------------------------- /tests/data/reffmt2/reffile_skip123.mcpl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/data/reffmt2/reffile_skip123.mcpl.gz -------------------------------------------------------------------------------- /tests/extra/data/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/extra/data/.empty -------------------------------------------------------------------------------- /tests/extra/pypath/MCPLExtraTestUtils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/extra/pypath/MCPLExtraTestUtils/__init__.py -------------------------------------------------------------------------------- /tests/extra/pypath/MCPLExtraTestUtils/dirs.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | def _find_data_dir(extra): 23 | import pathlib 24 | d = pathlib.Path(__file__).resolve().absolute().parent.parent.parent 25 | if not extra: 26 | d = d.parent 27 | ddir = d.joinpath('data') 28 | assert ddir.is_dir() 29 | return ddir 30 | 31 | def _find_cmd(envvar): 32 | import os 33 | import pathlib 34 | f=pathlib.Path(os.environ[envvar]) 35 | assert f.is_file() 36 | return f 37 | 38 | extra_test_data_dir = _find_data_dir(extra=True) 39 | core_test_data_dir = _find_data_dir(extra=False) 40 | mcpl2ssw_cmd = _find_cmd('MCPL2SSW_FILE') 41 | ssw2mcpl_cmd = _find_cmd('SSW2MCPL_FILE') 42 | mcpl2phits_cmd = _find_cmd('MCPL2PHITS_FILE') 43 | phits2mcpl_cmd = _find_cmd('PHITS2MCPL_FILE') 44 | mcpltool_cmd = _find_cmd('MCPL_TOOL_FILE') 45 | 46 | -------------------------------------------------------------------------------- /tests/extra/scripts/basic.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | from MCPLTestUtils.dirs import test_data_dir as test_data_dir_ref 23 | from MCPLTestUtils.dirs import mcpltool_cmd as mcpltool_cmd_ref 24 | 25 | from MCPLExtraTestUtils.dirs import ( extra_test_data_dir, 26 | core_test_data_dir, 27 | mcpl2ssw_cmd, 28 | ssw2mcpl_cmd, 29 | mcpltool_cmd ) 30 | import subprocess 31 | import sys 32 | 33 | def main(): 34 | 35 | assert extra_test_data_dir.is_dir() 36 | assert core_test_data_dir.is_dir() 37 | assert mcpl2ssw_cmd.is_file() 38 | assert ssw2mcpl_cmd.is_file() 39 | assert mcpltool_cmd.is_file() 40 | 41 | assert test_data_dir_ref == core_test_data_dir 42 | assert mcpltool_cmd_ref == mcpltool_cmd 43 | for cmdname, cmd in [ ('mcpl2ssw',mcpl2ssw_cmd), 44 | ('ssw2mcpl',ssw2mcpl_cmd), 45 | ('mcpltool',mcpltool_cmd) ]: 46 | print(f"\n\nLAUNCHING {cmdname} --help:\n\n") 47 | rv = subprocess.run([cmd,'--help'],check=True,capture_output=True) 48 | assert not rv.stderr 49 | assert rv.returncode == 0 50 | print(end='',flush=True) 51 | sys.stdout.buffer.write(rv.stdout) 52 | print(end='',flush=True) 53 | #print(rv.stdout.decode(),end='',flush=True) 54 | 55 | main() 56 | -------------------------------------------------------------------------------- /tests/extra/scripts/phitsuc.log: -------------------------------------------------------------------------------- 1 | Run mcpl2phits 2 | Opened MCPL file produced with "MyMCApp" (contains 5 particles) 3 | Creating (or overwriting) output PHITS file. 4 | Initiating particle conversion loop. 5 | Ending particle conversion loop. 6 | Created føø/hellø.dmp with 5 particles. 7 | Size of fake_cfg_file: 30 bytes 8 | Size of fake_dumpsummary_file: 38 bytes 9 | Run phits2mcpl 10 | MCPL: Compressing file hellø2.mcpl 11 | MCPL: Compressed file into hellø2.mcpl.gz 12 | Created føø/hellø2.mcpl.gz 13 | Run mcpltool 14 | Opened MCPL file hellø2.mcpl.gz: 15 | 16 | Basic info 17 | Format : MCPL-3 18 | No. of particles : 5 19 | Header storage : 220 bytes 20 | Data storage : 240 bytes 21 | 22 | Custom meta data 23 | Source : "PHITS" 24 | Number of comments : 1 25 | -> comment 0 : "Converted from PHITS with phits2mcpl" 26 | Number of blobs : 2 27 | -> 30 bytes of data with key "phits_input_deck" 28 | -> 38 bytes of data with key "phits_dump_summary_file" 29 | 30 | Particle data format 31 | User flags : no 32 | Polarisation info : yes 33 | Fixed part. type : no 34 | Fixed part. weight : no 35 | FP precision : single 36 | Endianness : little 37 | Storage : 48 bytes/particle 38 | 39 | index pdgcode ekin[MeV] x[cm] y[cm] z[cm] ux uy uz time[ms] weight pol-x pol-y pol-z 40 | 0 2112 1.234 0 0 0 0 1 0 0 1 0 0 0 41 | 1 2112 0 0 0 0.01 0.01 0 -0.99995 0 1 0 0 0 42 | 2 2112 1.234 0 0 0.02 0.02 0 0.9998 0 1 0 0 0 43 | 3 2112 0 0 0 0.03 0.03 -0.99955 0 0 1 0 0 0 44 | 4 2112 1.234 0 0 0.04 0.04 0 0.9992 0 1 0 0 0 45 | All ok 46 | -------------------------------------------------------------------------------- /tests/extra/src/app_phitspdgcode/test.log: -------------------------------------------------------------------------------- 1 | PHITS(2212)->PDG(2212), PDG(2212)->PHITS(2212) 2 | PHITS(2112)->PDG(2112), PDG(2112)->PHITS(2112) 3 | PHITS(0)->PDG(0), PDG(2113)->PHITS(0) 4 | PHITS(-211)->PDG(-211), PDG(-211)->PHITS(-211) 5 | PHITS(1000002)->PDG(1000010020), PDG(1000010020)->PHITS(1000002) 6 | PHITS(2000004)->PDG(1000020040), PDG(1000020040)->PHITS(2000004) 7 | PHITS(0)->PDG(0), PDG(1000020041)->PHITS(0) 8 | PHITS(0)->PDG(0), PDG(1010020040)->PHITS(0) 9 | PHITS(0)->PDG(0), PDG(-1000020040)->PHITS(0) 10 | PHITS(6000012)->PDG(1000060120), PDG(1000060120)->PHITS(6000012) 11 | PHITS(22)->PDG(22), PDG(22)->PHITS(22) 12 | PHITS(0)->PDG(0), PDG(-22)->PHITS(0) 13 | PHITS(11)->PDG(11), PDG(11)->PHITS(11) 14 | PHITS(-11)->PDG(-11), PDG(-11)->PHITS(-11) 15 | PHITS(-2212)->PDG(-2212), PDG(-2212)->PHITS(-2212) 16 | PHITS(-2112)->PDG(-2112), PDG(-2112)->PHITS(-2112) 17 | PHITS(111)->PDG(111), PDG(111)->PHITS(111) 18 | PHITS(0)->PDG(0), PDG(-111)->PHITS(0) 19 | PHITS(331)->PDG(331), PDG(331)->PHITS(331) 20 | PHITS(0)->PDG(0), PDG(-331)->PHITS(0) 21 | PHITS(0)->PDG(0), PDG(112)->PHITS(0) 22 | PHITS(3334)->PDG(3334), PDG(3334)->PHITS(3334) 23 | PHITS(-3334)->PDG(-3334), PDG(-3334)->PHITS(-3334) 24 | PHITS(0)->PDG(0), PDG(3335)->PHITS(0) 25 | PHITS(0)->PDG(0), PDG(6)->PHITS(0) 26 | PHITS(0)->PDG(0), PDG(0)->PHITS(0) 27 | PHITS(0)->PDG(0), PDG(1)->PHITS(0) 28 | PHITS(0)->PDG(0), PDG(10)->PHITS(0) 29 | Finished without errors! 30 | -------------------------------------------------------------------------------- /tests/extra/src/app_sswpdgcode/test.log: -------------------------------------------------------------------------------- 1 | conv_mcnpx_ssw2pdg(420) = -211 2 | conv_mcnpx_ssw2pdg(20) = 211 3 | conv_mcnpx_ssw2pdg(4) = 13 4 | conv_mcnpx_ssw2pdg(404) = -13 5 | conv_mcnpx_ssw2pdg(3) = 11 6 | conv_mcnpx_ssw2pdg(403) = -11 7 | conv_mcnpx_ssw2pdg(6) = 12 8 | conv_mcnpx_ssw2pdg(406) = -12 9 | conv_mcnpx_ssw2pdg(26057035) = 1000270570 10 | conv_mcnpx_ssw2pdg(26060035) = 1000270600 11 | conv_mcnpx_ssw2pdg(54137035) = 1000551370 12 | conv_mcnpx_ssw2pdg(31) = 1000010020 13 | conv_mcnpx_ssw2pdg(33) = 1000020030 14 | conv_mcnpx_ssw2pdg(34) = 1000020040 15 | conv_mcnpx_ssw2pdg(1) = 2112 16 | conv_mcnpx_ssw2pdg(2) = 22 17 | conv_mcnpx_ssw2pdg(402) = 22 18 | conv_mcnpx_ssw2pdg(9) = 2212 19 | conv_mcnpx_ssw2pdg(401) = -2112 20 | conv_mcnpx_ssw2pdg(409) = -2212 21 | conv_mcnpx_ssw2pdg(203) = 11 22 | conv_mcnpx_ssw2pdg(603) = -11 23 | conv_mcnpx_ssw2pdg(403) = -11 24 | conv_mcnpx_ssw2pdg(202) = 22 25 | conv_mcnpx_ssw2pdg(602) = 22 26 | conv_mcnpx_ssw2pdg(402) = 22 27 | conv_mcnpx_ssw2pdg(26057235) = 1000270570 28 | conv_mcnpx_ssw2pdg(26057435) = -1000270570 29 | conv_mcnpx_ssw2pdg(26057635) = -1000270570 30 | conv_mcnp6_ssw2pdg(70) = -211 31 | conv_mcnp6_ssw2pdg(40) = 211 32 | conv_mcnp6_ssw2pdg(8) = 13 33 | conv_mcnp6_ssw2pdg(7304) = 13 34 | conv_mcnp6_ssw2pdg(7688) = 13 35 | conv_mcnp6_ssw2pdg(17544) = 13 36 | conv_mcnp6_ssw2pdg(32) = -13 37 | conv_mcnp6_ssw2pdg(6) = 11 38 | conv_mcnp6_ssw2pdg(7) = -11 39 | conv_mcnp6_ssw2pdg(16) = -11 40 | conv_mcnp6_ssw2pdg(12) = 12 41 | conv_mcnp6_ssw2pdg(34) = -12 42 | conv_mcnp6_ssw2pdg(14) = 14 43 | conv_mcnp6_ssw2pdg(36) = -14 44 | conv_mcnp6_ssw2pdg(1776842) = 1000270570 45 | conv_mcnp6_ssw2pdg(1777226) = 1000270600 46 | conv_mcnp6_ssw2pdg(3622090) = 1000551370 47 | conv_mcnp6_ssw2pdg(62) = 1000010020 48 | conv_mcnp6_ssw2pdg(7358) = 1000010020 49 | conv_mcnp6_ssw2pdg(7742) = 1000010020 50 | conv_mcnp6_ssw2pdg(17598) = 1000010020 51 | conv_mcnp6_ssw2pdg(66) = 1000020030 52 | conv_mcnp6_ssw2pdg(7362) = 1000020030 53 | conv_mcnp6_ssw2pdg(7746) = 1000020030 54 | conv_mcnp6_ssw2pdg(17602) = 1000020030 55 | conv_mcnp6_ssw2pdg(68) = 1000020040 56 | conv_mcnp6_ssw2pdg(7364) = 1000020040 57 | conv_mcnp6_ssw2pdg(7748) = 1000020040 58 | conv_mcnp6_ssw2pdg(17604) = 1000020040 59 | conv_mcnp6_ssw2pdg(2) = 2112 60 | conv_mcnp6_ssw2pdg(4) = 22 61 | conv_mcnp6_ssw2pdg(5) = 22 62 | conv_mcnp6_ssw2pdg(18) = 2212 63 | conv_mcnp6_ssw2pdg(10) = -2112 64 | conv_mcnp6_ssw2pdg(38) = -2212 65 | -------------------------------------------------------------------------------- /tests/include/mcpltestmodutils.h: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************/ 3 | /* */ 4 | /* This file is part of MCPL (see https://mctools.github.io/mcpl/) */ 5 | /* */ 6 | /* Copyright 2015-2025 MCPL developers. */ 7 | /* */ 8 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 | /* you may not use this file except in compliance with the License. */ 10 | /* You may obtain a copy of the License at */ 11 | /* */ 12 | /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 | /* */ 14 | /* Unless required by applicable law or agreed to in writing, software */ 15 | /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 | /* See the License for the specific language governing permissions and */ 18 | /* limitations under the License. */ 19 | /* */ 20 | /******************************************************************************/ 21 | 22 | #ifndef MCPL_testmodutils_h 23 | #define MCPL_testmodutils_h 24 | 25 | /* inline functions for implementing compiled test modules (to be loaded with */ 26 | /* the Lib class from loadlib.py. */ 27 | 28 | #if defined (_WIN32) || defined (__CYGWIN__) || defined (WIN32) 29 | # define MCPLTEST_API __declspec(dllexport) 30 | #elif defined(__GNUC__) || defined(__clang__) 31 | # define MCPLTEST_API __attribute__ ((visibility ("default"))) 32 | #else 33 | # define MCPLTEST_API 34 | #endif 35 | #ifdef __cplusplus 36 | # define MCPLTEST_CTYPES extern "C" MCPLTEST_API 37 | #else 38 | # define MCPLTEST_CTYPES MCPLTEST_API 39 | #endif 40 | 41 | #define MCPLTEST_CTYPE_DICTIONARY MCPLTEST_CTYPES const char * mcpltest_ctypes_dictionary(void) 42 | 43 | #ifndef MCPLTESTMODUTILS_NO_MCPL_INCLUDE 44 | # include "mcpl.h" 45 | #endif 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | MCPLTEST_CTYPES void mcpltestdetail_set_print_handler(void (*handler)(const char *)) 52 | { 53 | mcpl_set_print_handler(handler); 54 | } 55 | 56 | MCPLTEST_CTYPES void mcpltestdetail_set_error_handler(void (*handler)(const char *)) 57 | { 58 | mcpl_set_error_handler(handler); 59 | } 60 | 61 | MCPLTEST_CTYPES void mcpltestdetail_exit1(void) 62 | { 63 | exit(1); 64 | } 65 | 66 | 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /tests/include/mcpltestutils.h: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************/ 3 | /* */ 4 | /* This file is part of MCPL (see https://mctools.github.io/mcpl/) */ 5 | /* */ 6 | /* Copyright 2015-2025 MCPL developers. */ 7 | /* */ 8 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 | /* you may not use this file except in compliance with the License. */ 10 | /* You may obtain a copy of the License at */ 11 | /* */ 12 | /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 | /* */ 14 | /* Unless required by applicable law or agreed to in writing, software */ 15 | /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 | /* See the License for the specific language governing permissions and */ 18 | /* limitations under the License. */ 19 | /* */ 20 | /******************************************************************************/ 21 | 22 | #ifndef mcpltestutils_h 23 | #define mcpltestutils_h 24 | 25 | #include 26 | #include 27 | 28 | #if 1 29 | #ifdef _MSC_VER 30 | # pragma warning( push ) 31 | # pragma warning( disable : 4996 ) 32 | #endif 33 | const char * mcpltests_find_data( const char * subpath1, const char * subpath2 ) 34 | { 35 | //Quick and dirty, not MT safe. 36 | const char * datadir = getenv("MCPL_TESTDATA_DIR"); 37 | if (!datadir) 38 | return "MCPL_TESTDATA_DIR/NOT/SET"; 39 | static char buffer[32768+1]; 40 | buffer[0] = '\0'; 41 | strncat(buffer,datadir,16384); 42 | #ifdef _WIN32 43 | const char * sep = "\\"; 44 | #else 45 | const char * sep = "/"; 46 | #endif 47 | if ( subpath1 ) { 48 | strncat(buffer,sep,2); 49 | strncat(buffer,subpath1,16384); 50 | } 51 | if ( subpath2 ) { 52 | strncat(buffer,sep,2); 53 | strncat(buffer,subpath2,16384); 54 | } 55 | return buffer; 56 | } 57 | #ifdef _MSC_VER 58 | # pragma warning( pop ) 59 | #endif 60 | 61 | 62 | #else 63 | //If only we could use the common C fileutils: 64 | const char * mcpltests_find_data( const char * subpath1, const char * subpath2 ) 65 | { 66 | //Quick and dirty, not MT safe. 67 | mcu8str varname = mcu8str_view_cstr("MCPL_TESTDATA_DIR"); 68 | mcu8str f = mctools_getenv( &varname ); 69 | if (!f.c_str) 70 | return "MCPL_TESTDATA_DIR/NOT/SET"; 71 | #ifdef _WIN32 72 | const char * sep = "\\"; 73 | #else 74 | const char * sep = "/"; 75 | #endif 76 | if ( subpath1 ) { 77 | mcu8str_append_cstr( &f, sep ); 78 | mcu8str_append_cstr( &f, subpath1 ); 79 | } 80 | if ( subpath2 ) { 81 | mcu8str_append_cstr( &f, sep ); 82 | mcu8str_append_cstr( &f, subpath2 ); 83 | } 84 | char buf[4096]; 85 | if ( sizeof(buf) < f.size + 1 ) { 86 | printf("ERROR: mcpltests_find_data buffer too small"); 87 | exit(1); 88 | } 89 | memcpy(buf,f.c_str,f.size+1); 90 | mcu8str_dealloc(&f); 91 | return buf; 92 | } 93 | #endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /tests/modules/lib_statsum/lib.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpltestmodutils.h" 23 | 24 | MCPLTEST_CTYPE_DICTIONARY 25 | { 26 | return 27 | "void mcpltest_createstatsumfile( const char *, const char *, double, " 28 | " const char *, const char*, unsigned );" 29 | "void mcpltest_dump( const char * );" 30 | ; 31 | } 32 | 33 | MCPLTEST_CTYPES void mcpltest_createstatsumfile( const char * filename, 34 | const char * statsumname, 35 | double statsumvalue, 36 | const char * customcomment1, 37 | const char * customcomment2, 38 | unsigned nparticles ) 39 | { 40 | mcpl_outfile_t f = mcpl_create_outfile( filename ); 41 | if ( strcmp(statsumname,"") != 0 ) 42 | mcpl_hdr_add_stat_sum(f,statsumname,statsumvalue); 43 | if ( strcmp(customcomment1,"") != 0 ) 44 | mcpl_hdr_add_comment(f,customcomment1); 45 | if ( strcmp(customcomment2,"") != 0 ) 46 | mcpl_hdr_add_comment(f,customcomment2); 47 | 48 | if ( nparticles ) { 49 | mcpl_particle_t * particle = mcpl_get_empty_particle(f); 50 | particle->direction[0] = 0.0; 51 | particle->direction[1] = 1.0; 52 | particle->direction[2] = 0.0; 53 | particle->ekin = 0.025; 54 | particle->pdgcode = 212; 55 | particle->weight = 0.123; 56 | for( unsigned i = 0; i < nparticles; ++i ) 57 | mcpl_add_particle(f,particle); 58 | } 59 | mcpl_close_outfile(f); 60 | } 61 | 62 | MCPLTEST_CTYPES void mcpltest_dump( const char * filename ) 63 | { 64 | mcpl_dump(filename,0,0,0); 65 | } 66 | -------------------------------------------------------------------------------- /tests/pypath/MCPLTestUtils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mctools/mcpl/5a9a3827aaa903a13914edb72b95d1c1abd500ff/tests/pypath/MCPLTestUtils/__init__.py -------------------------------------------------------------------------------- /tests/pypath/MCPLTestUtils/common.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | import sys 23 | import contextlib as _contextlib 24 | 25 | def flush(): 26 | sys.stderr.flush() 27 | sys.stdout.flush() 28 | 29 | @_contextlib.contextmanager 30 | def work_in_tmpdir(): 31 | """Context manager for working in a temporary directory (automatically 32 | created+cleaned) and then switching back""" 33 | import os 34 | import tempfile 35 | the_cwd = os.getcwd() 36 | with tempfile.TemporaryDirectory() as tmpdir: 37 | try: 38 | os.chdir(tmpdir) 39 | yield 40 | finally: 41 | os.chdir(the_cwd)#Important to leave tmpdir *before* deletion, to 42 | #avoid PermissionError on Windows. 43 | 44 | def calc_md5hexdigest( str_or_bytes, / ): 45 | import hashlib 46 | if hasattr(str_or_bytes,'encode'): 47 | data = str_or_bytes.encode('utf8',errors='backslashreplace') 48 | else: 49 | data = str_or_bytes 50 | return hashlib.md5( data ).hexdigest() 51 | 52 | def print_text_file_with_snipping(content, 53 | nstart=30, 54 | nend=20, 55 | prefix=''): 56 | """Prints text files, but snips out the middle part of larger 57 | files. Printout includes a checksum of the snipped part.""" 58 | nstart = max(3,nstart) 59 | nend = max(3,nend) 60 | lines=content.splitlines() 61 | if len(lines) < int((nstart+nend)*1.5+1): 62 | for line in lines: 63 | print(f'{prefix}{line}') 64 | else: 65 | for i in range(nstart): 66 | print(f'{prefix}{lines[i]}') 67 | md5 = calc_md5hexdigest( '\n'.join(lines[nstart:-nend]) ) 68 | def nleading_spaces( s ): 69 | return len(s)-len(s.lstrip(' ')) 70 | nspaces = min(nleading_spaces(lines[nstart-1]), 71 | nleading_spaces(lines[-nend])) 72 | spaces = ' '*nspaces 73 | print(f"{prefix}{spaces}<<>>") 75 | for i in range(nend): 76 | print(f'{prefix}{lines[-nend+i]}') 77 | -------------------------------------------------------------------------------- /tests/pypath/MCPLTestUtils/dirs.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | """ 23 | 24 | Module providing directories needed during testing. 25 | 26 | """ 27 | 28 | 29 | def _find_data_dir(): 30 | import pathlib 31 | _pymoddir = pathlib.Path(__file__).resolve().absolute().parent 32 | #from .modeinfo import is_simplebuild_mode 33 | if False:#is_simplebuild_mode(): 34 | #import os 35 | ddir = None#pathlib.Path(os.environ['SBLD_DATA_DIR'])/'NCTestUtils' 36 | else: 37 | ddir = _pymoddir.parent.parent.joinpath('data') 38 | assert ddir.is_dir() 39 | return ddir 40 | 41 | def _find_mcpltool_cmd(): 42 | import os 43 | import pathlib 44 | f=pathlib.Path(os.environ['MCPL_TOOL_FILE']).absolute() 45 | assert f.is_file() 46 | return f 47 | 48 | def _find_mcpllib(): 49 | import os 50 | import pathlib 51 | f=pathlib.Path(os.environ['MCPL_LIB']).absolute() 52 | assert f.is_file() 53 | return f 54 | 55 | test_data_dir = _find_data_dir() 56 | mcpltool_cmd = _find_mcpltool_cmd() 57 | mcpllib = _find_mcpllib() 58 | -------------------------------------------------------------------------------- /tests/pypath/MCPLTestUtils/stdout_redirect.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | import sys 23 | from .common import flush 24 | 25 | class RedirectStdout(): 26 | def __init__(self,filename): 27 | flush() 28 | self._f = open(filename, 'w') 29 | self._true_stdout = sys.stdout 30 | sys.stdout = self._f 31 | flush() 32 | def __enter__(self): 33 | return self 34 | def __exit__(self,*args): 35 | flush() 36 | self._f.close() 37 | sys.stdout = self._true_stdout 38 | flush() 39 | -------------------------------------------------------------------------------- /tests/scripts/a.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | # NEEDS: numpy 23 | 24 | from MCPLTestUtils.dirs import test_data_dir 25 | import gzip 26 | import pathlib 27 | import os 28 | 29 | def run_pymcpltool(*args): 30 | from mcpldev.mcpl import app_pymcpltool 31 | ec = None 32 | try: 33 | app_pymcpltool(['pymcpltool']+[str(e) for e in args]) 34 | except SystemExit as e: 35 | if str(e).isdigit(): 36 | ec = int(str(e)) 37 | else: 38 | raise 39 | print('') 40 | print(f"--> ENDED IN EXIT CODE: {ec}") 41 | 42 | def main(): 43 | os.environ['PYMCPLTOOL_FAKE_PYVERSION']='1' 44 | run_pymcpltool('-h') 45 | run_pymcpltool('-v') 46 | f1 = test_data_dir.joinpath('ref','reffile_1.mcpl') 47 | f2 = test_data_dir.joinpath('ref','reffile_12.mcpl') 48 | assert f1.is_file() 49 | assert f2.is_file() 50 | run_pymcpltool(f1) 51 | run_pymcpltool('-n','-s3','-l5',f1) 52 | run_pymcpltool('-j',f1) 53 | pathlib.Path('example.mcpl.gz').write_bytes(gzip.compress(f1.read_bytes())) 54 | run_pymcpltool('example.mcpl.gz') 55 | run_pymcpltool(f2) 56 | run_pymcpltool(f2,'-bBlaData') 57 | print() 58 | run_pymcpltool(f2,'--stats') 59 | 60 | if __name__ == '__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /tests/scripts/pystat.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | # NEEDS: numpy 23 | 24 | def files_for_testing(): 25 | from MCPLTestUtils.dirs import test_data_dir as tdir 26 | import itertools 27 | for p in itertools.chain( tdir.joinpath('ref').glob('*.mcpl*'), 28 | tdir.joinpath('reffmt2').glob('*.mcpl*') ): 29 | if 'bad' in p.name or 'truncated' in p.name or 'crash' in p.name: 30 | continue 31 | yield p 32 | 33 | def main(): 34 | import mcpldev as mcpl 35 | for path in sorted( files_for_testing(), 36 | key = lambda f : (f.parent.name,f.name,f) ): 37 | with mcpl.MCPLFile(path) as f: 38 | nparticles = f.nparticles 39 | for blocklength in sorted({max(1,nparticles),nparticles+1,max(1,nparticles-1)}): 40 | print('\n'*3+'='*100+'\n'*3) 41 | fnprint = '/'.join(path.parts[-2:]) 42 | print(f'Testing {fnprint} ' 43 | f'(nparticles={nparticles}) with blocklength={blocklength}') 44 | with mcpl.MCPLFile(path,blocklength=blocklength) as f: 45 | #print (path,blocklength) 46 | assert f.blocklength == blocklength 47 | for p in f.particle_blocks: 48 | lens = [ len(p.x),len(p.y),len(p.z), 49 | len(p.ux),len(p.uy),len(p.uz), 50 | len(p.polx),len(p.poly),len(p.polz), 51 | len(p.pdgcode),len(p.weight),len(p.userflags), 52 | len(p.position),len(p.polarisation),len(p.direction), 53 | len(p.time),len(p.ekin) ] 54 | #print (lens) 55 | assert len(set(lens))==1 56 | assert lens[0]<=blocklength 57 | assert blocklength>=1 58 | if nparticles>0: 59 | s=mcpl.collect_stats(f) 60 | mcpl.dump_stats(s) 61 | 62 | if __name__ == '__main__': 63 | main() 64 | -------------------------------------------------------------------------------- /tests/scripts/tooluc.log: -------------------------------------------------------------------------------- 1 | Opened MCPL file hellø.mcpl: 2 | 3 | Basic info 4 | Format : MCPL-3 5 | No. of particles : 5 6 | Header storage : 59 bytes 7 | Data storage : 340 bytes 8 | 9 | Custom meta data 10 | Source : "MyMCApp" 11 | Number of comments : 0 12 | Number of blobs : 0 13 | 14 | Particle data format 15 | User flags : no 16 | Polarisation info : no 17 | Fixed part. type : no 18 | Fixed part. weight : no 19 | FP precision : double 20 | Endianness : little 21 | Storage : 68 bytes/particle 22 | 23 | index pdgcode ekin[MeV] x[cm] y[cm] z[cm] ux uy uz time[ms] weight 24 | 0 2112 1.234 0 0 0 0 1 0 0 1 25 | 1 2112 0 0 0 0.01 0.01 0 -0.99995 0 1 26 | 2 2112 1.234 0 0 0.02 0.02 0 0.9998 0 1 27 | 3 2112 0 0 0 0.03 0.03 -0.99955 0 0 1 28 | 4 2112 1.234 0 0 0.04 0.04 0 0.9992 0 1 29 | All ok 30 | -------------------------------------------------------------------------------- /tests/scripts/tooluc.py: -------------------------------------------------------------------------------- 1 | 2 | ################################################################################ 3 | ## ## 4 | ## This file is part of MCPL (see https://mctools.github.io/mcpl/) ## 5 | ## ## 6 | ## Copyright 2015-2025 MCPL developers. ## 7 | ## ## 8 | ## Licensed under the Apache License, Version 2.0 (the "License"); ## 9 | ## you may not use this file except in compliance with the License. ## 10 | ## You may obtain a copy of the License at ## 11 | ## ## 12 | ## http://www.apache.org/licenses/LICENSE-2.0 ## 13 | ## ## 14 | ## Unless required by applicable law or agreed to in writing, software ## 15 | ## distributed under the License is distributed on an "AS IS" BASIS, ## 16 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## 17 | ## See the License for the specific language governing permissions and ## 18 | ## limitations under the License. ## 19 | ## ## 20 | ################################################################################ 21 | 22 | from MCPLTestUtils.dirs import ( test_data_dir, mcpltool_cmd ) 23 | import pathlib 24 | import sys 25 | 26 | def main(): 27 | f = test_data_dir.joinpath('ref','reffile_1.mcpl') 28 | assert f.is_file() 29 | oslash = '\u00f8' 30 | o = pathlib.Path('.').joinpath(f'f{oslash}{oslash}',f'hell{oslash}.mcpl') 31 | o.parent.mkdir() 32 | o.write_bytes( f.read_bytes() ) 33 | 34 | import subprocess 35 | rv = subprocess.run( [ mcpltool_cmd, f'f{oslash}{oslash}/hell{oslash}.mcpl' ], 36 | capture_output = True ) 37 | sys.stdout.buffer.write(rv.stdout) 38 | if rv.stderr: 39 | sys.stdout.buffer.write(rv.stderr) 40 | if rv.stderr or rv.returncode: 41 | raise SystemExit(1) 42 | print("All ok",flush=True) 43 | 44 | if __name__ == '__main__': 45 | main() 46 | -------------------------------------------------------------------------------- /tests/src/app_cppmcpltool/main.cc: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | //Test that the following mini-main code for the mcpltool also compiles with C++ 23 | //(which is less liberal regarding const-ness when passing in argv): 24 | 25 | #include "mcpl.h" 26 | 27 | int main ( int, char** ) 28 | { 29 | const char * fake_argv_const[] = { "mcpltool", "--help" }; 30 | int fake_argc = sizeof(fake_argv_const)/sizeof(*fake_argv_const); 31 | char** fake_argv = const_cast(fake_argv_const); 32 | return mcpl_tool(fake_argc,fake_argv); 33 | } 34 | -------------------------------------------------------------------------------- /tests/src/app_cppmcpltool/test.log: -------------------------------------------------------------------------------- 1 | Tool for inspecting or modifying Monte Carlo Particle List (.mcpl) files. 2 | 3 | The default behaviour is to display the contents of the FILE in human readable 4 | format (see Dump Options below for how to modify what is displayed). 5 | 6 | This installation supports direct reading of gzipped files (.mcpl.gz). 7 | 8 | Usage: 9 | mcpltool [dump-options] FILE 10 | mcpltool --merge [merge-options] FILE1 FILE2 11 | mcpltool --extract [extract-options] FILE1 FILE2 12 | mcpltool --repair FILE 13 | mcpltool --version 14 | mcpltool --help 15 | 16 | Dump options: 17 | By default include the info in the FILE header plus the first ten contained 18 | particles. Modify with the following options: 19 | -j, --justhead : Dump just header info and no particle info. 20 | -n, --nohead : Dump just particle info and no header info. 21 | -lN : Dump up to N particles from the file (default 10). You 22 | can specify -l0 to disable this limit. 23 | -sN : Skip past the first N particles in the file (default 0). 24 | -bKEY : Dump binary blob stored under KEY to standard output. 25 | 26 | Merge options: 27 | -m, --merge FILEOUT FILE1 FILE2 ... FILEN 28 | Creates new FILEOUT with combined particle contents from 29 | specified list of N existing and compatible files. 30 | -m, --merge --inplace FILE1 FILE2 ... FILEN 31 | Appends the particle contents in FILE2 ... FILEN into 32 | FILE1. Note that this action modifies FILE1! 33 | --forcemerge [--keepuserflags] FILEOUT FILE1 FILE2 ... FILEN 34 | Like --merge but works with incompatible files as well, at the 35 | heavy price of discarding most metadata like comments and blobs. 36 | Userflags will be discarded unless --keepuserflags is specified. 37 | 38 | Extract options: 39 | -e, --extract FILE1 FILE2 40 | Extracts particles from FILE1 into a new FILE2. 41 | -lN, -sN : Select range of particles in FILE1 (as above). 42 | -pPDGCODE : Select particles of type given by PDGCODE. 43 | 44 | Other options: 45 | -r, --repair FILE 46 | Attempt to repair FILE which was not properly closed, by up- 47 | dating the file header with the correct number of particles. 48 | -t, --text MCPLFILE OUTFILE 49 | Read particle contents of MCPLFILE and write into OUTFILE 50 | using a simple ASCII-based format. 51 | -v, --version : Display version of MCPL installation. 52 | -h, --help : Display this usage information (ignores all other options). 53 | -------------------------------------------------------------------------------- /tests/src/app_examples/example_readmcpl.h: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | // A small standalone example of how to one might read particles from an MCPL 23 | // file into a C programme. 24 | 25 | #include "mcpl.h" 26 | #include 27 | #include 28 | #include 29 | 30 | int main(int argc,char**argv) { 31 | 32 | if (argc!=2) { 33 | printf("Please supply input filename\n"); 34 | return 1; 35 | } 36 | 37 | const char * filename = argv[1]; 38 | 39 | //Open the file: 40 | mcpl_file_t f = mcpl_open_file(filename); 41 | 42 | //For fun, access and print a bit of the info found in the header (see mcpl.h 43 | //for more): 44 | 45 | printf("Opened MCPL file produced with %s\n",mcpl_hdr_srcname(f)); 46 | unsigned i; 47 | for (i = 0; i < mcpl_hdr_ncomments(f); ++i) 48 | printf( "file had comment: '%s'\n", mcpl_hdr_comment(f,i) ); 49 | printf( "File contains %llu particles\n", 50 | (unsigned long long)mcpl_hdr_nparticles(f) ); 51 | 52 | //Now, loop over particles and print some info: 53 | 54 | const mcpl_particle_t* p; 55 | while ( 1 ) { 56 | p = mcpl_read(f); 57 | if ( !p ) 58 | break; 59 | 60 | //print some info (see the mcpl_particle_t struct in mcpl.h for all fields): 61 | printf( " found particle with " 62 | "pdgcode %i and time-stamp %g ms with weight %g\n", 63 | p->pdgcode, p->time, p->weight ); 64 | 65 | } 66 | 67 | mcpl_close_file(f); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /tests/src/app_fopen/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | 24 | #ifdef _MSC_VER 25 | # pragma warning( push ) 26 | # pragma warning( disable : 4996 ) 27 | #endif 28 | int main(int argc, char** argv) 29 | { 30 | (void)argc; 31 | (void)argv; 32 | { 33 | printf("Calling fopen wb\n"); 34 | FILE * fh = fopen( "bla.txt","wb"); 35 | if (!fh) 36 | return 1; 37 | char data[5] = { 'h','e','l','l','o' }; 38 | printf("Writing data\n"); 39 | if ( fwrite(data, 1, sizeof(data), fh) != sizeof(data) ) 40 | return 1; 41 | printf("Calling fflush\n"); 42 | fflush(fh); 43 | printf("Calling fclose\n"); 44 | fclose(fh); 45 | } 46 | 47 | //Time to modify: 48 | { 49 | printf("Calling fopen r+b\n"); 50 | FILE * fh = fopen( "bla.txt","r+b"); 51 | if (!fh) 52 | return 1; 53 | printf("Calling fseek 3\n"); 54 | #ifdef _WIN32 55 | int notok = _fseeki64(fh,(__int64)(3), SEEK_SET); 56 | #else 57 | int notok = fseek(fh,(ssize_t)(3), SEEK_SET); 58 | #endif 59 | if (notok) 60 | return 1; 61 | 62 | char data[4] = { 'y','i','h','a' }; 63 | printf("Writing data\n"); 64 | if ( fwrite(data, 1, sizeof(data), fh) != sizeof(data) ) 65 | return 1; 66 | printf("Calling fflush\n"); 67 | fflush(fh); 68 | printf("Calling fclose\n"); 69 | fclose(fh); 70 | } 71 | 72 | return 0; 73 | } 74 | #ifdef _MSC_VER 75 | # pragma warning( pop ) 76 | #endif 77 | -------------------------------------------------------------------------------- /tests/src/app_print/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include "mcpltestutils.h" 24 | #include 25 | 26 | 27 | void mcpltests_custom_print_handler( const char * msg ) 28 | { 29 | printf("%s\n",msg); 30 | } 31 | 32 | int main(int argc,char**argv) { 33 | //Avoid unused warnings (can't simply omit the names in C): 34 | (void)argc; 35 | (void)argv; 36 | mcpl_set_print_handler(mcpltests_custom_print_handler); 37 | mcpl_dump(mcpltests_find_data("ref","reffile_1.mcpl"),0,0,10); 38 | mcpl_set_print_handler(NULL); 39 | mcpl_dump(mcpltests_find_data("ref","reffile_1.mcpl"),0,0,10); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tests/src/app_print/test.log: -------------------------------------------------------------------------------- 1 | Opened MCPL file reffile_1.mcpl: 2 | 3 | 4 | Basic info 5 | 6 | Format : MCPL-3 7 | 8 | No. of particles : 5 9 | 10 | Header storage : 59 bytes 11 | 12 | Data storage : 340 bytes 13 | 14 | 15 | Custom meta data 16 | 17 | Source : "MyMCApp" 18 | 19 | Number of comments : 0 20 | 21 | Number of blobs : 0 22 | 23 | 24 | Particle data format 25 | 26 | User flags : no 27 | 28 | Polarisation info : no 29 | 30 | Fixed part. type : 31 | no 32 | 33 | Fixed part. weight : 34 | no 35 | 36 | FP precision : double 37 | 38 | Endianness : little 39 | 40 | Storage : 68 bytes/particle 41 | 42 | 43 | index pdgcode ekin[MeV] x[cm] y[cm] z[cm] ux uy uz time[ms] 44 | weight 45 | 46 | 47 | 0 2112 1.234 0 0 0 0 1 0 0 48 | 1 49 | 50 | 51 | 1 2112 0 0 0 0.01 0.01 0 -0.99995 0 52 | 1 53 | 54 | 55 | 2 2112 1.234 0 0 0.02 0.02 0 0.9998 0 56 | 1 57 | 58 | 59 | 3 2112 0 0 0 0.03 0.03 -0.99955 0 0 60 | 1 61 | 62 | 63 | 4 2112 1.234 0 0 0.04 0.04 0 0.9992 0 64 | 1 65 | 66 | 67 | Opened MCPL file reffile_1.mcpl: 68 | 69 | Basic info 70 | Format : MCPL-3 71 | No. of particles : 5 72 | Header storage : 59 bytes 73 | Data storage : 340 bytes 74 | 75 | Custom meta data 76 | Source : "MyMCApp" 77 | Number of comments : 0 78 | Number of blobs : 0 79 | 80 | Particle data format 81 | User flags : no 82 | Polarisation info : no 83 | Fixed part. type : no 84 | Fixed part. weight : no 85 | FP precision : double 86 | Endianness : little 87 | Storage : 68 bytes/particle 88 | 89 | index pdgcode ekin[MeV] x[cm] y[cm] z[cm] ux uy uz time[ms] weight 90 | 0 2112 1.234 0 0 0 0 1 0 0 1 91 | 1 2112 0 0 0 0.01 0.01 0 -0.99995 0 1 92 | 2 2112 1.234 0 0 0.02 0.02 0 0.9998 0 1 93 | 3 2112 0 0 0 0.03 0.03 -0.99955 0 0 1 94 | 4 2112 1.234 0 0 0.04 0.04 0 0.9992 0 1 95 | -------------------------------------------------------------------------------- /tests/src/app_readgzref/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include "mcpltestutils.h" 24 | 25 | int main(int argc,char**argv) { 26 | //Avoid unused warnings (can't simply omit the names in C): 27 | (void)argc; 28 | (void)argv; 29 | 30 | //NB: reading of reffile_crash.mcpl.gz is not supported. 31 | mcpl_dump(mcpltests_find_data("ref","reffile_2.mcpl.gz"),0,0,0); 32 | mcpl_dump(mcpltests_find_data("ref","reffile_5.mcpl.gz"),0,0,0); 33 | mcpl_dump(mcpltests_find_data("ref","reffile_empty.mcpl.gz"),0,0,0); 34 | 35 | mcpl_dump(mcpltests_find_data("reffmt2","reffile_2.mcpl.gz"),0,0,0); 36 | mcpl_dump(mcpltests_find_data("reffmt2","reffile_5.mcpl.gz"),0,0,0); 37 | mcpl_dump(mcpltests_find_data("reffmt2","reffile_empty.mcpl.gz"),0,0,0); 38 | } 39 | -------------------------------------------------------------------------------- /tests/src/app_readref/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include "mcpltestutils.h" 24 | #include 25 | #include 26 | 27 | #ifdef _MSC_VER 28 | # pragma warning( push ) 29 | # pragma warning( disable : 4996 ) 30 | #endif 31 | void mcpltests_simple_copy_file( const char * src, 32 | const char * tgt ) 33 | { 34 | //No error checking, not unicode support on windows!! 35 | char buf[4096]; 36 | FILE * fh_in = fopen( src, "rb" ); 37 | FILE * fh_out = fopen( tgt, "wb" ); 38 | size_t n; 39 | while ( (n=fread(buf,1,4096,fh_in)) != 0 ) 40 | fwrite( buf, 1, n, fh_out ); 41 | fclose(fh_in); 42 | fclose(fh_out); 43 | } 44 | #ifdef _MSC_VER 45 | # pragma warning( pop ) 46 | #endif 47 | 48 | void mcpltests_test_datafolder( const char* folder ) 49 | { 50 | char filename[128]; 51 | for (unsigned count = 1;count<=16;++count) { 52 | snprintf(filename, sizeof(filename), "reffile_%i.mcpl",count); 53 | mcpl_dump(mcpltests_find_data(folder,filename),0,0,0); 54 | } 55 | mcpl_dump(mcpltests_find_data(folder,"reffile_crash.mcpl"),0,0,0); 56 | mcpl_dump(mcpltests_find_data(folder,"reffile_empty.mcpl"),0,0,0); 57 | 58 | mcpltests_simple_copy_file( mcpltests_find_data(folder,"reffile_7.mcpl"), 59 | "reffile_7_copy.mcpl" ); 60 | mcpl_merge_inplace("reffile_7_copy.mcpl",mcpltests_find_data(folder,"reffile_7.mcpl")); 61 | mcpl_dump("reffile_7_copy.mcpl",0,0,0); 62 | } 63 | 64 | int main(int argc,char**argv) { 65 | //Avoid unused warnings (can't simply omit the names in C): 66 | (void)argc; 67 | (void)argv; 68 | mcpltests_test_datafolder("ref"); 69 | mcpltests_test_datafolder("reffmt2"); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /tests/src/app_unicodenames/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | // Test if using unicodes in filenames works OK everywhere (in particular on Windows). 23 | 24 | #include "mcpl.h" 25 | #include 26 | #include 27 | //#include 28 | 29 | int main(int argc,char**argv) { 30 | (void) argc; 31 | (void) argv; 32 | const char * filename = "r\xc3\xb8""dgr\xc3\xb8""d.mcpl"; 33 | const char * filenamegz = "r\xc3\xb8""dgr\xc3\xb8""d.mcpl.gz"; 34 | 35 | { 36 | mcpl_outfile_t f = mcpl_create_outfile(filename); 37 | mcpl_particle_t * particle = mcpl_get_empty_particle(f); 38 | particle->pdgcode = 22; 39 | particle->position[0] = 1.0; 40 | particle->position[1] = 2.0; 41 | particle->position[2] = 3.0; 42 | particle->direction[0] = 0.0; 43 | particle->direction[1] = 1.0; 44 | particle->direction[2] = 0.0; 45 | particle->time = 4.56; 46 | particle->weight = 0.123; 47 | mcpl_add_particle(f,particle); 48 | mcpl_closeandgzip_outfile(f); 49 | } 50 | 51 | //Verify that filename without .gz has disappeared: 52 | { 53 | mcpl_generic_filehandle_t fh = mcpl_generic_fopen_try(filename); 54 | if ( fh.internal ) { 55 | mcpl_generic_fclose( &fh ); 56 | printf("ERROR: %s did not disappear upon gzip\n",filename); 57 | return 1; 58 | } 59 | } 60 | { 61 | mcpl_file_t f = mcpl_open_file(filenamegz); 62 | mcpl_close_file(f); 63 | } 64 | 65 | return 0; 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /tests/src/app_unicodenames/test.log: -------------------------------------------------------------------------------- 1 | MCPL: Compressing file rødgrød.mcpl 2 | MCPL: Compressed file into rødgrød.mcpl.gz 3 | -------------------------------------------------------------------------------- /tests/src/app_writegzip/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include 24 | #include 25 | 26 | int main(int argc,char**argv) { 27 | (void)argc; 28 | (void)argv; 29 | 30 | //Create file with some rather fake content: 31 | mcpl_outfile_t f = mcpl_create_outfile("out.mcpl"); 32 | mcpl_hdr_set_srcname(f,"CustomTest"); 33 | mcpl_enable_universal_pdgcode(f,2112);//all particles are neutrons 34 | mcpl_hdr_add_comment(f,"Some comment."); 35 | mcpl_hdr_add_comment(f,"Another comment."); 36 | mcpl_particle_t * particle = mcpl_get_empty_particle(f); 37 | for (int i = 0; i < 50000; ++i) { 38 | particle->position[0] = i*1.0; 39 | particle->position[1] = i*2.0; 40 | particle->position[2] = i*3.0; 41 | particle->ekin = i*0.1; 42 | particle->direction[0] = 0.0; 43 | particle->direction[1] = 0.0; 44 | particle->direction[2] = 1.0; 45 | particle->time = i*0.01; 46 | particle->weight = 1.0; 47 | mcpl_add_particle(f,particle); 48 | } 49 | 50 | //close up and gzip: 51 | mcpl_closeandgzip_outfile(f); 52 | 53 | //Verify that out.mcpl has disappeared: 54 | { 55 | mcpl_generic_filehandle_t fh = mcpl_generic_fopen_try("out.mcpl"); 56 | if ( fh.internal ) { 57 | mcpl_generic_fclose( &fh ); 58 | printf("ERROR: out.mcpl did not disappear upon gzip\n"); 59 | return 1; 60 | } 61 | } 62 | 63 | //Check file: 64 | mcpl_dump("out.mcpl.gz", 0,0,20); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /tests/src/app_writegzip/test.log: -------------------------------------------------------------------------------- 1 | MCPL: Compressing file out.mcpl 2 | MCPL: Compressed file into out.mcpl.gz 3 | Opened MCPL file out.mcpl.gz: 4 | 5 | Basic info 6 | Format : MCPL-3 7 | No. of particles : 50000 8 | Header storage : 99 bytes 9 | Data storage : 1600000 bytes 10 | 11 | Custom meta data 12 | Source : "CustomTest" 13 | Number of comments : 2 14 | -> comment 0 : "Some comment." 15 | -> comment 1 : "Another comment." 16 | Number of blobs : 0 17 | 18 | Particle data format 19 | User flags : no 20 | Polarisation info : no 21 | Fixed part. type : yes (pdgcode 2112) 22 | Fixed part. weight : no 23 | FP precision : single 24 | Endianness : little 25 | Storage : 32 bytes/particle 26 | 27 | index pdgcode ekin[MeV] x[cm] y[cm] z[cm] ux uy uz time[ms] weight 28 | 0 2112 0 0 0 0 0 0 1 0 1 29 | 1 2112 0.1 1 2 3 0 0 1 0.01 1 30 | 2 2112 0.2 2 4 6 0 0 1 0.02 1 31 | 3 2112 0.3 3 6 9 0 0 1 0.03 1 32 | 4 2112 0.4 4 8 12 0 0 1 0.04 1 33 | 5 2112 0.5 5 10 15 0 0 1 0.05 1 34 | 6 2112 0.6 6 12 18 0 0 1 0.06 1 35 | 7 2112 0.7 7 14 21 0 0 1 0.07 1 36 | 8 2112 0.8 8 16 24 0 0 1 0.08 1 37 | 9 2112 0.9 9 18 27 0 0 1 0.09 1 38 | 10 2112 1 10 20 30 0 0 1 0.1 1 39 | 11 2112 1.1 11 22 33 0 0 1 0.11 1 40 | 12 2112 1.2 12 24 36 0 0 1 0.12 1 41 | 13 2112 1.3 13 26 39 0 0 1 0.13 1 42 | 14 2112 1.4 14 28 42 0 0 1 0.14 1 43 | 15 2112 1.5 15 30 45 0 0 1 0.15 1 44 | 16 2112 1.6 16 32 48 0 0 1 0.16 1 45 | 17 2112 1.7 17 34 51 0 0 1 0.17 1 46 | 18 2112 1.8 18 36 54 0 0 1 0.18 1 47 | 19 2112 1.9 19 38 57 0 0 1 0.19 1 48 | -------------------------------------------------------------------------------- /tests/src/app_writempi1/main.c: -------------------------------------------------------------------------------- 1 | 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // This file is part of MCPL (see https://mctools.github.io/mcpl/) // 5 | // // 6 | // Copyright 2015-2025 MCPL developers. // 7 | // // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); // 9 | // you may not use this file except in compliance with the License. // 10 | // You may obtain a copy of the License at // 11 | // // 12 | // http://www.apache.org/licenses/LICENSE-2.0 // 13 | // // 14 | // Unless required by applicable law or agreed to in writing, software // 15 | // distributed under the License is distributed on an "AS IS" BASIS, // 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 17 | // See the License for the specific language governing permissions and // 18 | // limitations under the License. // 19 | // // 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | #include "mcpl.h" 23 | #include 24 | #include 25 | 26 | int main(int argc,char**argv) { 27 | (void)argc; 28 | (void)argv; 29 | 30 | //Test mpi interface with nproc=1 31 | 32 | mcpl_outfile_t f = mcpl_create_outfile_mpi( "foobar", 0, 1 ); 33 | mcpl_hdr_set_srcname(f,"CustomMPITest"); 34 | mcpl_enable_universal_pdgcode(f,2112); 35 | mcpl_hdr_add_comment(f,"Some comment."); 36 | mcpl_hdr_add_comment(f,"Another comment."); 37 | mcpl_hdr_add_stat_sum(f,"foostat", -1.0 ); 38 | 39 | //mpi: add particles: 40 | mcpl_particle_t * particle = mcpl_get_empty_particle(f); 41 | for (int i = 0; i < 2; ++i) { 42 | particle->position[0] = i*1.0; 43 | particle->position[1] = i*2.0; 44 | particle->position[2] = i*3.0; 45 | particle->ekin = i*0.1; 46 | particle->direction[0] = 0.0; 47 | particle->direction[1] = 0.0; 48 | particle->direction[2] = 1.0; 49 | particle->time = i*0.01; 50 | particle->weight = 0.0; 51 | mcpl_add_particle(f,particle); 52 | } 53 | 54 | //mpi: close files 55 | mcpl_hdr_add_stat_sum(f,"foostat", 10.0 ); 56 | mcpl_closeandgzip_outfile(f); 57 | 58 | //Merge: 59 | mcpl_merge_outfiles_mpi( "foobar", 1 ); 60 | 61 | //Dump: 62 | mcpl_dump("foobar.mcpl.gz", 0, 0, 0); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /tests/src/app_writempi1/test.log: -------------------------------------------------------------------------------- 1 | MCPL: Compressing file foobar.mcpl 2 | MCPL: Compressed file into foobar.mcpl.gz 3 | Opened MCPL file foobar.mcpl.gz: 4 | 5 | Basic info 6 | Format : MCPL-3 7 | No. of particles : 2 8 | Header storage : 147 bytes 9 | Data storage : 64 bytes 10 | 11 | Custom meta data 12 | Source : "CustomMPITest" 13 | Number of comments : 3 14 | -> comment 0 : "Some comment." 15 | -> comment 1 : "Another comment." 16 | -> comment 2 : "stat:sum:foostat: 10" 17 | Number of blobs : 0 18 | 19 | Particle data format 20 | User flags : no 21 | Polarisation info : no 22 | Fixed part. type : yes (pdgcode 2112) 23 | Fixed part. weight : no 24 | FP precision : single 25 | Endianness : little 26 | Storage : 32 bytes/particle 27 | 28 | index pdgcode ekin[MeV] x[cm] y[cm] z[cm] ux uy uz time[ms] weight 29 | 0 2112 0 0 0 0 0 0 1 0 0 30 | 1 2112 0.1 1 2 3 0 0 1 0.01 0 31 | --------------------------------------------------------------------------------