Merge branch release-5-1
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 24 Jul 2015 14:40:41 +0000 (16:40 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 24 Jul 2015 14:40:41 +0000 (16:40 +0200)
Conflicts:
src/gromacs/commandline/shellcompletions.cpp
Removed line no longer appropriate, now that zsh completion
is supported. Master had changed the previous line, which
git flags as a merge conflict.

Change-Id: Id9d37615b2bd121b1206ca0e6e8eac62fcf38f01

458 files changed:
cmake/gmxCFlags.cmake
cmake/gmxVersionInfo.cmake
docs/dev-manual/naming.rst
docs/dev-manual/relocatable-binaries.rst
docs/dev-manual/testutils.rst
docs/doxygen/gmxtree.py
docs/doxygen/includesorter.py
docs/doxygen/lib/wrapperbinary.md
docs/doxygen/user/analysisdata.md
docs/doxygen/user/usinglibrary.md
share/template/template.cpp
share/top/gurgle.dat
src/config.h.cmakein
src/contrib/anaf.c [deleted file]
src/contrib/do_multiprot.c
src/contrib/mkice.c
src/contrib/test.c
src/external/thread_mpi/include/thread_mpi/lock.h
src/gromacs/analysisdata.h
src/gromacs/analysisdata/abstractdata.cpp
src/gromacs/analysisdata/abstractdata.h
src/gromacs/analysisdata/analysisdata.h
src/gromacs/analysisdata/datamodule.h
src/gromacs/analysisdata/datamodulemanager.cpp
src/gromacs/analysisdata/datamodulemanager.h
src/gromacs/analysisdata/dataproxy.h
src/gromacs/analysisdata/framelocaldata.h
src/gromacs/analysisdata/modules/frameaverager.h
src/gromacs/analysisdata/tests/analysisdata.cpp
src/gromacs/analysisdata/tests/arraydata.cpp
src/gromacs/analysisdata/tests/datatest.h
src/gromacs/analysisdata/tests/mock_datamodule.cpp
src/gromacs/analysisdata/tests/mock_datamodule.h
src/gromacs/analysisdata/tests/refdata/common-referencedata.xsl
src/gromacs/commandline.h
src/gromacs/commandline/cmdlinehelpcontext.cpp
src/gromacs/commandline/cmdlinehelpcontext.h
src/gromacs/commandline/cmdlinehelpmodule.cpp
src/gromacs/commandline/cmdlinehelpmodule.h
src/gromacs/commandline/cmdlinehelpwriter.cpp
src/gromacs/commandline/cmdlinehelpwriter.h
src/gromacs/commandline/cmdlineinit.cpp
src/gromacs/commandline/cmdlineinit.h
src/gromacs/commandline/cmdlinemodule.h
src/gromacs/commandline/cmdlinemodulemanager.cpp
src/gromacs/commandline/cmdlinemodulemanager.h
src/gromacs/commandline/cmdlineoptionsmodule.cpp
src/gromacs/commandline/cmdlineoptionsmodule.h
src/gromacs/commandline/cmdlineprogramcontext.cpp
src/gromacs/commandline/cmdlineprogramcontext.h
src/gromacs/commandline/pargs.cpp
src/gromacs/commandline/shellcompletions.cpp
src/gromacs/commandline/shellcompletions.h
src/gromacs/commandline/tests/cmdlinehelpmodule.cpp
src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/commandline/tests/cmdlinemodulemanagertest.cpp
src/gromacs/commandline/tests/cmdlinemodulemanagertest.h
src/gromacs/commandline/tests/cmdlineprogramcontext.cpp
src/gromacs/commandline/tests/pargs.cpp
src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml
src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml [new file with mode: 0644]
src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml [deleted file]
src/gromacs/correlationfunctions/CMakeLists.txt
src/gromacs/correlationfunctions/autocorr.cpp [moved from src/gromacs/correlationfunctions/autocorr.c with 97% similarity]
src/gromacs/correlationfunctions/crosscorr.cpp [moved from src/gromacs/correlationfunctions/crosscorr.c with 98% similarity]
src/gromacs/correlationfunctions/expfit.cpp
src/gromacs/correlationfunctions/integrate.cpp [moved from src/gromacs/correlationfunctions/integrate.c with 98% similarity]
src/gromacs/correlationfunctions/manyautocorrelation.cpp [moved from src/gromacs/correlationfunctions/manyautocorrelation.c with 89% similarity]
src/gromacs/correlationfunctions/polynomials.cpp [moved from src/gromacs/correlationfunctions/polynomials.c with 97% similarity]
src/gromacs/fft/fft.cpp
src/gromacs/fft/fft5d.cpp
src/gromacs/fft/fft5d.h
src/gromacs/fft/fft_fftw3.cpp
src/gromacs/fileio/CMakeLists.txt
src/gromacs/fileio/confio.c [deleted file]
src/gromacs/fileio/confio.cpp [new file with mode: 0644]
src/gromacs/fileio/confio.h
src/gromacs/fileio/enxio.cpp [moved from src/gromacs/fileio/enxio.c with 96% similarity]
src/gromacs/fileio/enxio.h
src/gromacs/fileio/espio.cpp [new file with mode: 0644]
src/gromacs/fileio/espio.h [moved from src/gromacs/mdlib/genborn_sse2_single.h with 63% similarity]
src/gromacs/fileio/filenm.cpp [moved from src/gromacs/fileio/filenm.c with 91% similarity]
src/gromacs/fileio/filenm.h
src/gromacs/fileio/g96io.cpp [new file with mode: 0644]
src/gromacs/fileio/g96io.h [new file with mode: 0644]
src/gromacs/fileio/gmx_internal_xdr.cpp [moved from src/gromacs/fileio/gmx_system_xdr.c with 86% similarity]
src/gromacs/fileio/gmx_internal_xdr.h [moved from src/gromacs/fileio/gmx_system_xdr.h with 98% similarity]
src/gromacs/fileio/gmxfio-impl.h [moved from src/gromacs/fileio/gmxfio_int.h with 63% similarity]
src/gromacs/fileio/gmxfio-xdr.cpp [new file with mode: 0644]
src/gromacs/fileio/gmxfio-xdr.h [new file with mode: 0644]
src/gromacs/fileio/gmxfio.cpp [moved from src/gromacs/fileio/gmxfio.c with 71% similarity]
src/gromacs/fileio/gmxfio.h
src/gromacs/fileio/gmxfio_asc.c [deleted file]
src/gromacs/fileio/gmxfio_bin.c [deleted file]
src/gromacs/fileio/gmxfio_rw.c [deleted file]
src/gromacs/fileio/gmxfio_xdr.c [deleted file]
src/gromacs/fileio/groio.cpp [new file with mode: 0644]
src/gromacs/fileio/groio.h [new file with mode: 0644]
src/gromacs/fileio/libxdrf.cpp [moved from src/gromacs/fileio/libxdrf.c with 93% similarity]
src/gromacs/fileio/matio.cpp
src/gromacs/fileio/md5.cpp [moved from src/gromacs/fileio/md5.c with 96% similarity]
src/gromacs/fileio/mdoutf.cpp [moved from src/gromacs/fileio/mdoutf.c with 94% similarity]
src/gromacs/fileio/mtxio.cpp [moved from src/gromacs/fileio/mtxio.c with 92% similarity]
src/gromacs/fileio/pdbio.cpp [moved from src/gromacs/fileio/pdbio.c with 90% similarity]
src/gromacs/fileio/strdb.cpp [moved from src/gromacs/fileio/strdb.c with 94% similarity]
src/gromacs/fileio/tests/CMakeLists.txt
src/gromacs/fileio/tests/confio.cpp [new file with mode: 0644]
src/gromacs/fileio/timecontrol.cpp [moved from src/gromacs/fileio/timecontrol.c with 97% similarity]
src/gromacs/fileio/tngio.cpp
src/gromacs/fileio/tngio_for_tools.cpp
src/gromacs/fileio/tpxio.cpp [moved from src/gromacs/fileio/tpxio.c with 94% similarity]
src/gromacs/fileio/tpxio.h
src/gromacs/fileio/trajectory_writing.cpp [moved from src/gromacs/fileio/trajectory_writing.c with 100% similarity]
src/gromacs/fileio/trnio.h [deleted file]
src/gromacs/fileio/trrio.cpp [moved from src/gromacs/fileio/trnio.c with 64% similarity]
src/gromacs/fileio/trrio.h [new file with mode: 0644]
src/gromacs/fileio/trxio.cpp [moved from src/gromacs/fileio/trxio.c with 97% similarity]
src/gromacs/fileio/trxio.h
src/gromacs/fileio/vmdio.cpp [moved from src/gromacs/fileio/vmdio.c with 98% similarity]
src/gromacs/fileio/writeps.cpp [moved from src/gromacs/fileio/writeps.c with 99% similarity]
src/gromacs/fileio/xdrd.cpp [moved from src/gromacs/fileio/xdrd.c with 89% similarity]
src/gromacs/fileio/xdrf.h
src/gromacs/fileio/xtcio.cpp [moved from src/gromacs/fileio/xtcio.c with 94% similarity]
src/gromacs/fileio/xtcio.h
src/gromacs/fileio/xvgr.cpp
src/gromacs/gmxana/eigio.c
src/gromacs/gmxana/eigio.h
src/gromacs/gmxana/gmx_anaeig.c
src/gromacs/gmxana/gmx_angle.c
src/gromacs/gmxana/gmx_bundle.c
src/gromacs/gmxana/gmx_chi.c
src/gromacs/gmxana/gmx_cluster.c
src/gromacs/gmxana/gmx_clustsize.c
src/gromacs/gmxana/gmx_confrms.c
src/gromacs/gmxana/gmx_covar.c
src/gromacs/gmxana/gmx_current.c
src/gromacs/gmxana/gmx_density.c
src/gromacs/gmxana/gmx_densmap.c
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_disre.c
src/gromacs/gmxana/gmx_do_dssp.c
src/gromacs/gmxana/gmx_dos.c
src/gromacs/gmxana/gmx_dyecoupl.c
src/gromacs/gmxana/gmx_editconf.c
src/gromacs/gmxana/gmx_eneconv.c
src/gromacs/gmxana/gmx_enemat.c
src/gromacs/gmxana/gmx_energy.c
src/gromacs/gmxana/gmx_filter.c
src/gromacs/gmxana/gmx_genion.c
src/gromacs/gmxana/gmx_gyrate.c
src/gromacs/gmxana/gmx_hydorder.c
src/gromacs/gmxana/gmx_make_edi.c
src/gromacs/gmxana/gmx_mdmat.c
src/gromacs/gmxana/gmx_mindist.c
src/gromacs/gmxana/gmx_mk_angndx.c
src/gromacs/gmxana/gmx_morph.c
src/gromacs/gmxana/gmx_msd.c
src/gromacs/gmxana/gmx_nmens.c
src/gromacs/gmxana/gmx_nmtraj.c
src/gromacs/gmxana/gmx_order.c
src/gromacs/gmxana/gmx_polystat.c
src/gromacs/gmxana/gmx_principal.c
src/gromacs/gmxana/gmx_rms.c
src/gromacs/gmxana/gmx_rmsdist.c
src/gromacs/gmxana/gmx_rmsf.c
src/gromacs/gmxana/gmx_rotmat.c
src/gromacs/gmxana/gmx_saltbr.c
src/gromacs/gmxana/gmx_sans.c
src/gromacs/gmxana/gmx_sigeps.c
src/gromacs/gmxana/gmx_sorient.c
src/gromacs/gmxana/gmx_spatial.c
src/gromacs/gmxana/gmx_spol.c
src/gromacs/gmxana/gmx_traj.c
src/gromacs/gmxana/gmx_trjcat.c
src/gromacs/gmxana/gmx_trjconv.c
src/gromacs/gmxana/gmx_trjorder.c
src/gromacs/gmxana/gmx_tune_pme.c
src/gromacs/gmxana/gmx_vanhove.c
src/gromacs/gmxana/gmx_wham.cpp
src/gromacs/gmxana/gmx_xpm2ps.c
src/gromacs/gmxana/nrama.c
src/gromacs/gmxana/sfactor.c
src/gromacs/gmxlib/checkpoint.cpp
src/gromacs/gmxlib/copyrite.cpp
src/gromacs/gmxlib/oenv.cpp
src/gromacs/gmxlib/sighandler.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxpreprocess/CMakeLists.txt
src/gromacs/gmxpreprocess/add_par.cpp [moved from src/gromacs/gmxpreprocess/add_par.c with 96% similarity]
src/gromacs/gmxpreprocess/add_par.h
src/gromacs/gmxpreprocess/calch.cpp [moved from src/gromacs/gmxpreprocess/calch.c with 96% similarity]
src/gromacs/gmxpreprocess/calch.h
src/gromacs/gmxpreprocess/convparm.cpp [moved from src/gromacs/gmxpreprocess/convparm.c with 98% similarity]
src/gromacs/gmxpreprocess/convparm.h
src/gromacs/gmxpreprocess/fflibutil.cpp
src/gromacs/gmxpreprocess/fflibutil.h
src/gromacs/gmxpreprocess/gen_ad.cpp [moved from src/gromacs/gmxpreprocess/gen_ad.c with 97% similarity]
src/gromacs/gmxpreprocess/gen_ad.h
src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp [moved from src/gromacs/gmxpreprocess/gen_maxwell_velocities.c with 96% similarity]
src/gromacs/gmxpreprocess/gen_maxwell_velocities.h
src/gromacs/gmxpreprocess/gen_vsite.cpp [moved from src/gromacs/gmxpreprocess/gen_vsite.c with 97% similarity]
src/gromacs/gmxpreprocess/gen_vsite.h
src/gromacs/gmxpreprocess/genconf.cpp [moved from src/gromacs/gmxpreprocess/genconf.c with 99% similarity]
src/gromacs/gmxpreprocess/genconf.h
src/gromacs/gmxpreprocess/genhydro.cpp [moved from src/gromacs/gmxpreprocess/genhydro.c with 99% similarity]
src/gromacs/gmxpreprocess/genhydro.h
src/gromacs/gmxpreprocess/gmxcpp.cpp [moved from src/gromacs/gmxpreprocess/gmxcpp.c with 98% similarity]
src/gromacs/gmxpreprocess/gmxcpp.h
src/gromacs/gmxpreprocess/gpp_atomtype.cpp [moved from src/gromacs/gmxpreprocess/gpp_atomtype.c with 98% similarity]
src/gromacs/gmxpreprocess/gpp_atomtype.h
src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp [moved from src/gromacs/gmxpreprocess/gpp_bond_atomtype.c with 100% similarity]
src/gromacs/gmxpreprocess/gpp_bond_atomtype.h
src/gromacs/gmxpreprocess/gpp_nextnb.cpp [moved from src/gromacs/gmxpreprocess/gpp_nextnb.c with 99% similarity]
src/gromacs/gmxpreprocess/gpp_nextnb.h
src/gromacs/gmxpreprocess/grompp-impl.h
src/gromacs/gmxpreprocess/grompp.cpp [moved from src/gromacs/gmxpreprocess/grompp.c with 97% similarity]
src/gromacs/gmxpreprocess/grompp.h
src/gromacs/gmxpreprocess/h_db.cpp [moved from src/gromacs/gmxpreprocess/h_db.c with 96% similarity]
src/gromacs/gmxpreprocess/h_db.h
src/gromacs/gmxpreprocess/hackblock.cpp [moved from src/gromacs/gmxpreprocess/hackblock.c with 100% similarity]
src/gromacs/gmxpreprocess/hackblock.h
src/gromacs/gmxpreprocess/hizzie.cpp [moved from src/gromacs/gmxpreprocess/hizzie.c with 97% similarity]
src/gromacs/gmxpreprocess/hizzie.h
src/gromacs/gmxpreprocess/insert-molecules.cpp
src/gromacs/gmxpreprocess/insert-molecules.h
src/gromacs/gmxpreprocess/nm2type.cpp [moved from src/gromacs/gmxpreprocess/nm2type.c with 97% similarity]
src/gromacs/gmxpreprocess/nm2type.h
src/gromacs/gmxpreprocess/pdb2gmx.cpp [moved from src/gromacs/gmxpreprocess/pdb2gmx.c with 98% similarity]
src/gromacs/gmxpreprocess/pdb2gmx.h
src/gromacs/gmxpreprocess/pdb2top.cpp
src/gromacs/gmxpreprocess/pdb2top.h
src/gromacs/gmxpreprocess/pgutil.cpp [moved from src/gromacs/gmxpreprocess/pgutil.c with 100% similarity]
src/gromacs/gmxpreprocess/pgutil.h
src/gromacs/gmxpreprocess/read-conformation.h
src/gromacs/gmxpreprocess/readadress.cpp [moved from src/gromacs/gmxpreprocess/readadress.c with 98% similarity]
src/gromacs/gmxpreprocess/readir.cpp [moved from src/gromacs/gmxpreprocess/readir.c with 98% similarity]
src/gromacs/gmxpreprocess/readir.h
src/gromacs/gmxpreprocess/readpull.cpp [moved from src/gromacs/gmxpreprocess/readpull.c with 98% similarity]
src/gromacs/gmxpreprocess/readrot.cpp [moved from src/gromacs/gmxpreprocess/readrot.c with 93% similarity]
src/gromacs/gmxpreprocess/resall.cpp [moved from src/gromacs/gmxpreprocess/resall.c with 98% similarity]
src/gromacs/gmxpreprocess/resall.h
src/gromacs/gmxpreprocess/solvate.h
src/gromacs/gmxpreprocess/sortwater.cpp [moved from src/gromacs/gmxpreprocess/sortwater.c with 99% similarity]
src/gromacs/gmxpreprocess/sortwater.h
src/gromacs/gmxpreprocess/specbond.cpp [moved from src/gromacs/gmxpreprocess/specbond.c with 97% similarity]
src/gromacs/gmxpreprocess/specbond.h
src/gromacs/gmxpreprocess/ter_db.cpp [moved from src/gromacs/gmxpreprocess/ter_db.c with 91% similarity]
src/gromacs/gmxpreprocess/ter_db.h
src/gromacs/gmxpreprocess/tomorse.cpp [moved from src/gromacs/gmxpreprocess/tomorse.c with 98% similarity]
src/gromacs/gmxpreprocess/tomorse.h
src/gromacs/gmxpreprocess/topdirs.cpp [moved from src/gromacs/gmxpreprocess/topdirs.c with 100% similarity]
src/gromacs/gmxpreprocess/topdirs.h
src/gromacs/gmxpreprocess/topio.cpp [moved from src/gromacs/gmxpreprocess/topio.c with 99% similarity]
src/gromacs/gmxpreprocess/topio.h
src/gromacs/gmxpreprocess/toppush.cpp [moved from src/gromacs/gmxpreprocess/toppush.c with 97% similarity]
src/gromacs/gmxpreprocess/toppush.h
src/gromacs/gmxpreprocess/topshake.cpp [moved from src/gromacs/gmxpreprocess/topshake.c with 96% similarity]
src/gromacs/gmxpreprocess/topshake.h
src/gromacs/gmxpreprocess/toputil.cpp [moved from src/gromacs/gmxpreprocess/toputil.c with 96% similarity]
src/gromacs/gmxpreprocess/toputil.h
src/gromacs/gmxpreprocess/vsite_parm.cpp [moved from src/gromacs/gmxpreprocess/vsite_parm.c with 96% similarity]
src/gromacs/gmxpreprocess/vsite_parm.h
src/gromacs/gmxpreprocess/x2top.cpp [moved from src/gromacs/gmxpreprocess/x2top.c with 98% similarity]
src/gromacs/gmxpreprocess/x2top.h
src/gromacs/gmxpreprocess/xlate.cpp [moved from src/gromacs/gmxpreprocess/xlate.c with 99% similarity]
src/gromacs/gmxpreprocess/xlate.h
src/gromacs/imd/imd.c
src/gromacs/legacyheaders/checkpoint.h
src/gromacs/legacyheaders/copyrite.h
src/gromacs/legacyheaders/oenv.h
src/gromacs/legacyheaders/types/forcerec.h
src/gromacs/listed-forces/bonded.cpp
src/gromacs/listed-forces/listed-forces.cpp
src/gromacs/listed-forces/listed-internal.h
src/gromacs/listed-forces/manage-threading.cpp
src/gromacs/listed-forces/manage-threading.h
src/gromacs/math/utilities.c
src/gromacs/math/vec.h
src/gromacs/mdlib/clincs.cpp
src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/ebin.c
src/gromacs/mdlib/expanded.c
src/gromacs/mdlib/force.cpp
src/gromacs/mdlib/forcerec-threading.h
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/genborn.cpp [moved from src/gromacs/mdlib/genborn.c with 86% similarity]
src/gromacs/mdlib/genborn_allvsall.cpp [moved from src/gromacs/mdlib/genborn_allvsall.c with 97% similarity]
src/gromacs/mdlib/genborn_allvsall_sse2_double.c [deleted file]
src/gromacs/mdlib/genborn_allvsall_sse2_double.h [deleted file]
src/gromacs/mdlib/genborn_allvsall_sse2_single.c [deleted file]
src/gromacs/mdlib/genborn_allvsall_sse2_single.h [deleted file]
src/gromacs/mdlib/genborn_sse2_double.c [deleted file]
src/gromacs/mdlib/genborn_sse2_single.c [deleted file]
src/gromacs/mdlib/mdebin_bar.c
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_file_generator/make_verlet_simd_kernel_files.py
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_file_generator/nbnxn_kernel_simd_2xnn_kernel.c.pre
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_file_generator/nbnxn_kernel_simd_4xn_kernel.c.pre
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_file_generator/nbnxn_kernel_simd_template.c.pre
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_file_generator/nbnxn_kernel_simd_template.h.pre
src/gromacs/mdlib/ns.cpp [moved from src/gromacs/mdlib/ns.c with 97% similarity]
src/gromacs/mdlib/nsgrid.cpp [moved from src/gromacs/mdlib/nsgrid.c with 97% similarity]
src/gromacs/mdlib/qm_gamess.cpp [moved from src/gromacs/mdlib/qm_gamess.c with 95% similarity]
src/gromacs/mdlib/qm_gaussian.cpp [moved from src/gromacs/mdlib/qm_gaussian.c with 97% similarity]
src/gromacs/mdlib/qm_mopac.cpp [moved from src/gromacs/mdlib/qm_mopac.c with 91% similarity]
src/gromacs/mdlib/qm_orca.cpp [moved from src/gromacs/mdlib/qm_orca.c with 98% similarity]
src/gromacs/mdlib/qmmm.cpp [moved from src/gromacs/mdlib/qmmm.c with 94% similarity]
src/gromacs/mdlib/shellfc.cpp
src/gromacs/mdlib/stat.cpp
src/gromacs/mdlib/tables.c
src/gromacs/mdlib/tpi.cpp
src/gromacs/onlinehelp-doc.h
src/gromacs/onlinehelp/helpformat.h
src/gromacs/onlinehelp/helpmanager.cpp
src/gromacs/onlinehelp/helpmanager.h
src/gromacs/onlinehelp/helptopic.cpp
src/gromacs/onlinehelp/helptopic.h
src/gromacs/onlinehelp/helpwritercontext.cpp
src/gromacs/onlinehelp/helpwritercontext.h
src/gromacs/onlinehelp/ihelptopic.h [moved from src/gromacs/onlinehelp/helptopicinterface.h with 90% similarity]
src/gromacs/onlinehelp/tests/helpmanager.cpp
src/gromacs/onlinehelp/tests/mock_helptopic.h
src/gromacs/options/filenameoptionmanager.cpp
src/gromacs/options/filenameoptionmanager.h
src/gromacs/options/optionmanagercontainer.h
src/gromacs/options/options-impl.h
src/gromacs/options/options.cpp
src/gromacs/options/options.h
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/selection/indexutil.cpp
src/gromacs/selection/indexutil.h
src/gromacs/selection/nbsearch.cpp
src/gromacs/selection/parser_internal.h
src/gromacs/selection/parsetree.cpp
src/gromacs/selection/scanner.cpp
src/gromacs/selection/scanner.h
src/gromacs/selection/scanner.l
src/gromacs/selection/scanner_internal.cpp
src/gromacs/selection/scanner_internal.h
src/gromacs/selection/selection.cpp
src/gromacs/selection/selectioncollection-impl.h
src/gromacs/selection/selectioncollection.cpp
src/gromacs/selection/selectioncollection.h
src/gromacs/selection/selectionoptionmanager.h
src/gromacs/selection/selhelp.cpp
src/gromacs/selection/selhelp.h
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesBasicInput.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesContinuation.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesEmptySelections.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesMultiSelectionInputStatus.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesMultipleSelectionsOnLine.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesNoFinalNewline.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesNoninteractiveInput.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInput.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInputNoninteractively.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInputStatus.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesStatusWithExistingSelections.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesStatusWithGroups.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesTwoSelectionInput.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesTwoSelectionInputStatus.xml [new file with mode: 0644]
src/gromacs/selection/tests/refdata/common-referencedata.xsl
src/gromacs/selection/tests/refdata/referencedata.xsl
src/gromacs/selection/tests/selectioncollection.cpp
src/gromacs/selection/tests/toputils.cpp
src/gromacs/statistics/CMakeLists.txt
src/gromacs/statistics/statistics.cpp [moved from src/gromacs/statistics/statistics.c with 78% similarity]
src/gromacs/statistics/statistics_test.c [deleted file]
src/gromacs/swap/swapcoords.cpp
src/gromacs/tools/CMakeLists.txt
src/gromacs/tools/check.cpp [moved from src/gromacs/tools/check.c with 97% similarity]
src/gromacs/tools/check.h
src/gromacs/tools/compare.cpp [moved from src/gromacs/tools/compare.c with 96% similarity]
src/gromacs/tools/convert_tpr.cpp [moved from src/gromacs/tools/convert_tpr.c with 97% similarity]
src/gromacs/tools/convert_tpr.h
src/gromacs/tools/dump.cpp [moved from src/gromacs/tools/dump.c with 92% similarity]
src/gromacs/tools/dump.h
src/gromacs/topology/mtop_util.h
src/gromacs/topology/symtab.cpp
src/gromacs/trajectoryanalysis/analysissettings-impl.h
src/gromacs/trajectoryanalysis/analysissettings.cpp
src/gromacs/trajectoryanalysis/analysissettings.h
src/gromacs/trajectoryanalysis/cmdlinerunner.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/gromacs/trajectoryanalysis/modules/pairdist.cpp
src/gromacs/trajectoryanalysis/modules/rdf.cpp
src/gromacs/trajectoryanalysis/modules/sasa.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/runnercommon.cpp
src/gromacs/trajectoryanalysis/tests/refdata/common-referencedata.xsl
src/gromacs/trajectoryanalysis/tests/test_selection.cpp
src/gromacs/utility.h
src/gromacs/utility/CMakeLists.txt
src/gromacs/utility/cstringutil.cpp [moved from src/gromacs/utility/cstringutil.c with 99% similarity]
src/gromacs/utility/datafilefinder.cpp
src/gromacs/utility/datafilefinder.h
src/gromacs/utility/errorcodes.cpp
src/gromacs/utility/exceptions.cpp
src/gromacs/utility/exceptions.h
src/gromacs/utility/file.cpp [deleted file]
src/gromacs/utility/file.h [deleted file]
src/gromacs/utility/fileredirector.cpp
src/gromacs/utility/fileredirector.h
src/gromacs/utility/filestream.cpp [new file with mode: 0644]
src/gromacs/utility/filestream.h [new file with mode: 0644]
src/gromacs/utility/futil.cpp
src/gromacs/utility/gmxregex.cpp
src/gromacs/utility/mutex.h [moved from src/gromacs/mdlib/genborn_sse2_double.h with 62% similarity]
src/gromacs/utility/nodelete.h [new file with mode: 0644]
src/gromacs/utility/path.cpp
src/gromacs/utility/path.h
src/gromacs/utility/programcontext.cpp
src/gromacs/utility/programcontext.h
src/gromacs/utility/qsort_threadsafe.cpp [moved from src/gromacs/utility/qsort_threadsafe.c with 98% similarity]
src/gromacs/utility/scoped_cptr.h
src/gromacs/utility/smalloc.cpp [moved from src/gromacs/utility/smalloc.c with 95% similarity]
src/gromacs/utility/stringstream.cpp [new file with mode: 0644]
src/gromacs/utility/stringstream.h [new file with mode: 0644]
src/gromacs/utility/stringutil.cpp
src/gromacs/utility/stringutil.h
src/gromacs/utility/tests/CMakeLists.txt
src/gromacs/utility/tests/refdata/TextLineWrapperTest_WrapsCorrectlyWithExtraWhitespace.xml
src/gromacs/utility/tests/refdata/TextWriterTest_WritesLines.xml [new file with mode: 0644]
src/gromacs/utility/tests/refdata/TextWriterTest_WritesLinesInParts.xml [new file with mode: 0644]
src/gromacs/utility/tests/refdata/TextWriterTest_WritesLinesInPartsWithWrapper.xml [new file with mode: 0644]
src/gromacs/utility/tests/refdata/TextWriterTest_WritesWrappedLines.xml [new file with mode: 0644]
src/gromacs/utility/tests/stringutil.cpp
src/gromacs/utility/tests/textwriter.cpp [new file with mode: 0644]
src/gromacs/utility/textreader.cpp [new file with mode: 0644]
src/gromacs/utility/textreader.h [new file with mode: 0644]
src/gromacs/utility/textstream.h [new file with mode: 0644]
src/gromacs/utility/textwriter.cpp [new file with mode: 0644]
src/gromacs/utility/textwriter.h [new file with mode: 0644]
src/gromacs/utility/uniqueptr.h
src/programs/legacymodules.cpp
src/programs/mdrun/md.cpp
src/programs/mdrun/runner.cpp
src/programs/mdrun/tests/moduletest.cpp
src/programs/mdrun/tests/rerun.cpp
src/programs/view/filter.cpp
src/programs/view/view.cpp
src/testutils/CMakeLists.txt
src/testutils/cmdlinetest.cpp
src/testutils/cmdlinetest.h
src/testutils/common-referencedata.xsl
src/testutils/integrationtests.cpp
src/testutils/interactivetest.cpp [new file with mode: 0644]
src/testutils/interactivetest.h [new file with mode: 0644]
src/testutils/stringtest.cpp
src/testutils/stringtest.h
src/testutils/testfileredirector.cpp
src/testutils/testfileredirector.h
src/testutils/testinit.cpp
src/testutils/testoptions.cpp
src/testutils/tests/CMakeLists.txt
src/testutils/tests/interactivetest.cpp [new file with mode: 0644]
src/testutils/tests/refdata_tests.cpp
src/testutils/testutils-doc.h

index 3e8644e843b4065f1eedd0932c65409db7b89586..6ef7b48c447fbb6d9de4a3a1cc12d0da52475f44 100644 (file)
@@ -314,6 +314,8 @@ MACRO(gmx_c_flags)
         if(NOT GMX_OPENMP)
             GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
         endif()
+        # Once we get rid of most extern "C" declarations, this can hopefully go away.
+        GMX_TEST_CXXFLAG(CXXFLAGS_WARN_PEDANTIC "-Wno-return-type-c-linkage" GMXC_CXXFLAGS)
         GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused-function" GMXC_CXXFLAGS)
         GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith" GMXC_CXXFLAGS)
     endif()
index bc0de3b6b334c6984ccb4d5b509d263744bf9510..f7a412b281051f9bc5352f926b4885c2f8873f10 100644 (file)
@@ -211,13 +211,13 @@ endif()
 # The GROMACS convention is that these are the version number of the next
 # release that is going to be made from this branch.
 set(GMX_VERSION_MAJOR 5)
-set(GMX_VERSION_MINOR 1)
+set(GMX_VERSION_MINOR 2)
 set(GMX_VERSION_PATCH 0)
 # The suffix, on the other hand, is used mainly for betas and release
 # candidates, where it signifies the most recent such release from
 # this branch; it will be empty before the first such release, as well
 # as after the final release is out.
-set(GMX_VERSION_SUFFIX "-rc1")
+set(GMX_VERSION_SUFFIX "")
 
 # Conventionally with libtool, any ABI change must change the major
 # version number, the minor version number should change if it's just
@@ -228,7 +228,7 @@ set(GMX_VERSION_SUFFIX "-rc1")
 # here. The important thing is to minimize the chance of third-party
 # code being able to dynamically link with a version of libgromacs
 # that might not work.
-set(LIBRARY_SOVERSION_MAJOR 1)
+set(LIBRARY_SOVERSION_MAJOR 2)
 set(LIBRARY_SOVERSION_MINOR 0)
 set(LIBRARY_VERSION ${LIBRARY_SOVERSION_MAJOR}.${LIBRARY_SOVERSION_MINOR}.0)
 
index 987e19a80f307b835f667b446bdd6f9428f3ec40..f8bdbc56124fef96ecbee49b619b09c58b78d42b 100644 (file)
@@ -87,8 +87,11 @@ C++ code
   You may use an all-lowercase name with underscores if your class closely
   resembles an external construct (e.g., a standard library construct) named
   that way.
-* C++ interfaces are named with a ``Interface`` suffix, and abstract base
-  classes with an ``Abstract`` prefix.
+* C++ interfaces are named with an ``I`` prefix, such as in ICommandLineModule.
+  This keeps interfaces identifiable, without introducing too much clutter
+  (as the interface is typically used quite widely, spelling out
+  ``Interface`` would make many of the names unnecessarily long).
+* Abstract base classes are typically named with an ``Abstract`` prefix.
 * Member variables are named with a trailing underscore.
 * Accessors for a variable ``foo_`` are named ``foo()`` and ``setFoo()``.
 * Global variables are named with a ``g_`` prefix.
index df83d9b37d9996725416e9071679d49692333db5..e29907d2d16e9154278c33035b16cb9f204aca76 100644 (file)
@@ -134,7 +134,7 @@ implementation, which works like this:
 The above logic to find the installation prefix is in
 ``src/gromacs/commandline/cmdlineprogramcontext.cpp``.  Note that code that
 links to ``libgromacs`` can provide an alternative implementation for
-``gmx::ProgramContextInterface`` for locating the data files, and is then fully
+``gmx::IProgramContext`` for locating the data files, and is then fully
 responsible of the above considerations.
 
 Information about the used data directories is printed into the console output
index 3f7ff23536beec5c434feb5a533e6a70a3e9d73c..ba73b398a9d191a3023d60407555fd6ec6d03af2 100644 (file)
@@ -136,7 +136,7 @@ a few parts:
 In addition to ``src/testutils/``, some of the module test directories may
 provide reusable test code that is used in higher-level tests.  For example,
 the ``src/gromacs/analysisdata/tests/`` provides test fixtures, a mock
-implementation for gmx::AnalysisDataModuleInterface, and some helper classes
+implementation for gmx::IAnalysisDataModule, and some helper classes
 that are also used in ``src/gromacs/trajectoryanalysis/tests/``.
 These cases are handled using CMake object libraries that are linked to all the
 test binaries that need them.
index a693fe921a081c1e7372367f6549c1e4e9f74b53..c4126d4bcf0516a9feeb18784b736d0815e3ba5f 100644 (file)
@@ -215,7 +215,7 @@ class File(object):
         """Scan the file contents and initialize information based on it."""
         # TODO: Consider a more robust regex.
         include_re = r'^\s*#\s*include\s+(?P<quote>["<])(?P<path>[^">]*)[">]'
-        define_re = r'^\s*#.*define\s+(\w*)'
+        define_re = r'^\s*#.*define(?:01)?\s+(\w*)'
         current_block = None
         with open(self._abspath, 'r') as scanfile:
             contents = scanfile.read()
index 15de98644641e125b2aac8ac81923f1048bf5bd1..71e59de68040bc5be0ec4a2f2d03cb3448fd1727 100755 (executable)
@@ -174,6 +174,23 @@ class GroupedSorter(object):
             return IncludeGroup.gmx_test
         return IncludeGroup.gmx_general
 
+    def _split_path(self, path):
+        """Split include path into sortable compoments.
+
+        Plain string on the full path in the #include directive causes some
+        unintuitive behavior, so this splits the path into a tuple at
+        points that allow more natural sorting: primary sort criterion is the
+        directory name, followed by the basename (without extension) of the
+        included file.
+        """
+        path_components = list(os.path.split(path))
+        path_components[1] = os.path.splitext(path_components[1])
+        return tuple(path_components)
+
+    def _join_path(self, path_components):
+        """Reconstruct path from the return value of _split_path."""
+        return os.path.join(path_components[0], ''.join(path_components[1]))
+
     def get_sortable_object(self, include):
         """Produce a sortable, opaque object for an include.
 
@@ -210,7 +227,7 @@ class GroupedSorter(object):
             including_file = include.get_including_file()
             group = self._get_gmx_group(including_file, included_file)
             path = self._get_path(included_file, group, including_file)
-        return (group, os.path.split(path), include)
+        return (group, self._split_path(path), include)
 
     def format_include(self, obj, prev):
         """Format an #include directive after sorting."""
@@ -228,9 +245,9 @@ class GroupedSorter(object):
         match = re.match(include_re, line)
         assert match
         if include.is_system():
-            path = '<{0}>'.format(os.path.join(obj[1][0], obj[1][1]))
+            path = '<{0}>'.format(self._join_path(obj[1]))
         else:
-            path = '"{0}"'.format(os.path.join(obj[1][0], obj[1][1]))
+            path = '"{0}"'.format(self._join_path(obj[1]))
         result.append('{0}{1}{2}\n'.format(match.group('head'), path, match.group('tail')))
         return result
 
index 98f6fcc50d49f3488f91e2da8c77c78866297619..23f7ba16cb0561918326318edd4467aeff45a7d0 100644 (file)
@@ -29,14 +29,14 @@ Command line modules
 ====================
 
 All modules within the wrapper binary are implemented as classes that implement
-the gmx::CommandLineModuleInterface interface.  There is generally some helper
+the gmx::ICommandLineModule interface.  There is generally some helper
 class in between:
  * General C++ modules typically use gmx::Options for their command-line
    handling.  Instead of each module implementing parsing and help separately
-   with identical code, they implement gmx::CommandLineOptionsModuleInterface
+   with identical code, they implement gmx::ICommandLineOptionsModule
    instead.  The framework then provides a bridge class that contains the
-   common code and wraps gmx::CommandLineOptionsModuleInterface into a
-   gmx::CommandLineModuleInterface.
+   common code and wraps gmx::ICommandLineOptionsModule into a
+   gmx::ICommandLineModule.
  * For C++ trajectory analysis modules, there is a general implementation for
    running the gmx::TrajectoryAnalysisModule subclasses in cmdlinerunner.cpp.
  * For old C-style %main() functions, see \ref section_wrapperbinary_cmain.
@@ -75,7 +75,7 @@ line manager throws away all the other arguments before passing control to the
 module.
 
 After the above translations, the internal help module handles all the help
-output.  All the help is organized into a hierarchy of gmx::HelpTopicInterface
+output.  All the help is organized into a hierarchy of gmx::IHelpTopic
 instances.  The help module internally creates a root help topic that is
 printed with `gmx help`.  If there are additional words after the `gmx help`
 command, then those are taken to specify the topic to show in the hierarchy.
@@ -83,7 +83,7 @@ command, then those are taken to specify the topic to show in the hierarchy.
 gmx::CommandLineModuleManager internally creates a help topic for each added
 module.  These topics are shown when `gmx help` _module_ is invoked.
 They forward the request to the actual module (to
-gmx::CommandLineModuleInterface::writeHelp()).
+gmx::ICommandLineModule::writeHelp()).
 
 In addition to the topics created internally, gmx::CommandLineModuleManager
 provides methods to add additional help topics.  Currently, this is used to
@@ -104,7 +104,7 @@ of which targets to use for generating the documentation..
 If this option is set, the help module loops through all the modules in the
 binary, writing help for each into a separate file.  The help module writes
 common headers and footers, and asks the actual module to write the
-module-specific content (with gmx::CommandLineModuleInterface::writeHelp(),
+module-specific content (with gmx::ICommandLineModule::writeHelp(),
 using a different help context than for console output).
 
 Additionally, a list of all the modules is generated (`gromacs.7` for man
index 9347285519691485ba14f2c8a49b6791ed65c4ac..dffc1fac05105d5bc9d6f3d46508ac3660cd56b4 100644 (file)
@@ -9,7 +9,7 @@ module is visualized below:
   digraph analysisdata_overview {
     rankdir = BT
     dataobject [label="data object\n(subclass of gmx::AbstractAnalysisData)"]
-    datamodule1 [label="data module\n(implements gmx::AnalysisDataModuleInterface)"]
+    datamodule1 [label="data module\n(implements gmx::IAnalysisDataModule)"]
     datamodule2 [label="data module\nthat also provides data"]
     datamodule3 [label="data module"]
     datamodule1 -> dataobject
@@ -26,7 +26,7 @@ To perform operations on the data, one or more _data modules_ can be attached
 to the data object.  Examples of such operations are averaging, histogramming,
 and plotting the data into a file.  Some data modules are provided by the \ref
 module_analysisdata module.  To implement new ones, it is necessary to create a
-class that implements gmx::AnalysisDataModuleInterface.
+class that implements gmx::IAnalysisDataModule.
 
 In many cases, such data modules also provide data that can be processed
 further, acting as data objects themselves.  This makes it possible to attach
@@ -171,7 +171,7 @@ with a short description.  See the documentation of the individual classes for
 more details.
 Note that this list is manually maintained, so it may not always be up-to-date.
 A comprehensive list can be found by looking at the inheritance graph of
-gmx::AnalysisDataModuleInterface, but the list here is more user-friendly.
+gmx::IAnalysisDataModule, but the list here is more user-friendly.
 
 <dl>
 <dt>gmx::AnalysisDataAverageModule</dt>
index f3498d02a50ccb11fe6648e7211294ddcd92b230..099417fde3b598dd32a28044283b4b87146dde17 100644 (file)
@@ -18,11 +18,11 @@ low-level functions.
    the facilities provided by \ref module_commandline.  There are a few
    different alternatives, depending on how much control you want to give
    \Gromacs:
-    - For C++ code, you can implement gmx::CommandLineOptionsModuleInterface and
+    - For C++ code, you can implement gmx::ICommandLineOptionsModule and
       use gmx::runCommandLineModule() to execute it.  This interface assumes
       the use of the gmx::Options mechanism for declaring command-line options
       (see \ref module_options).
-      For a lower-level interface, gmx::CommandLineModuleInterface can be used,
+      For a lower-level interface, gmx::ICommandLineModule can be used,
       but this requires you to implement `-h` output and command-line parsing
       yourself (possibly using classes that \Gromacs provides).
     - For C code, you can use gmx_run_cmain() to wrap an existing C main
@@ -37,7 +37,7 @@ low-level functions.
       routines.  This allows you to write your own handling for command line
       options from scratch.  This is also discussed in \ref module_commandline.
  - For most control, you can use gmx::init() to do basic initialization, create
-   your own implementation for gmx::ProgramContextInterface, and set that using
+   your own implementation for gmx::IProgramContext, and set that using
    gmx::setProgramContext().  This allows you to customize how the \Gromacs
    library shows the name of the program in messages, as well as how it locates
    its own data files.
index 6ef9e466b5764566615f7be8b006efbea087ec71..3cb55d5e89183b6b5586e9a522e12d6a02d8e7ae 100644 (file)
@@ -101,7 +101,7 @@ AnalysisTemplate::initOptions(Options                    *options,
         "analysis groups."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o")
                            .filetype(eftPlot).outputFile()
index c10a49811a7fc692fea8de572aedc84adcbe0567..d14c7cf03afcd6587b7b9d382fc9d545cef49415 100644 (file)
@@ -1,4 +1,4 @@
-586
+592
 If You Want Something Done You Have to Do It Yourself_(Highlander II)
 I Live the Life They Wish They Did_(Tricky)
 Jesus Built My Hotrod_(Ministry)
@@ -585,3 +585,9 @@ Weaseling out of things is important to learn. It's what separates us from the a
 In science, truth always wins._(Max Perutz)
 Creativity in science, as in art, cannot be organized. It arises spontaneously from individual talent. Well-run laboratories can foster it, but hierarchical organizations, inflexible bureaucratic rules, and mountains of futile paperwork can kill it._(Max Perutz)
 Every electron is sacred._(Greg McMullan, on Cryo-EM detectors)
+Science adjusts its views based on what's observed. Faith is the denial of observation so that belief can be preserved._(Tim Minchin)
+Isn’t this enough? Just this world? Just this beautiful, complex wonderfully unfathomable world? How does it so fail to hold our attention that we have to diminish it with the invention of cheap, man-made myths and monsters?_(Tim Minchin)
+If you open your mind too much, your brains will fall out._(Tim Minchin)
+"Everything organic and natural is good" - ignoring the fact that organic natural substances include arsenic and poo and crocodiles. And everything chemical is bad, ignoring the fact that... everything is chemicals._(Tim Minchin)
+A program that has not been tested does not work._(Bjarne Stroustrup)
+You could give Aristotle a tutorial. And you could thrill him to the core of his being. Such is the privilege of living after Newton, Darwin, Einstein, Planck, Watson, Crick and their colleagues._(Richard Dawkins)
index 59993ea72a1a97a9515c8108d06474831b3adc69..1a03026317599d38606ea9aad795971d30edf017 100644 (file)
 /* IEEE754 floating-point format. Memory layout is defined by macros
  * GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER and GMX_IEEE754_BIG_ENDIAN_WORD_ORDER. 
  */
-#cmakedefine GMX_FLOAT_FORMAT_IEEE754
+#cmakedefine01 GMX_FLOAT_FORMAT_IEEE754
 
 /* Work around broken calloc() */
 #cmakedefine GMX_BROKEN_CALLOC
 
 /* Do not optimize FFTW setups (not needed with SSE FFT kernels) */
-#cmakedefine GMX_DISABLE_FFTW_MEASURE
-
-/* Use Built-in FFTPACK FFT library */
-#cmakedefine GMX_FFT_FFTPACK
+#cmakedefine01 GMX_DISABLE_FFTW_MEASURE
 
 /* Use FFTW3 FFT library */
-#cmakedefine GMX_FFT_FFTW3
-
-/* Use Intel MKL FFT library */
-#cmakedefine GMX_FFT_MKL
+#cmakedefine01 GMX_FFT_FFTW3
 
 /* Target platform is x86 or x86_64 */
 #cmakedefine GMX_TARGET_X86
@@ -80,7 +74,7 @@
 #cmakedefine GMX_CYGWIN
 
 /** Define if we have sufficient C++11 support */
-#cmakedefine GMX_CXX11
+#cmakedefine01 GMX_CXX11
 
 /* GCC bug in AVX maskload/maskstore arguments - worked around internally */
 #cmakedefine GMX_SIMD_X86_AVX_GCC_MASKLOAD_BUG
 #define GMX_SIMD_ACCURACY_BITS_DOUBLE @GMX_SIMD_ACCURACY_BITS_DOUBLE@
 
 /* Integer byte order is big endian. */
-#cmakedefine GMX_INTEGER_BIG_ENDIAN
+#cmakedefine01 GMX_INTEGER_BIG_ENDIAN
 
 /* Use our own instead of system XDR libraries */
-#cmakedefine GMX_INTERNAL_XDR
+#cmakedefine01 GMX_INTERNAL_XDR
 
 /* Compile to use TNG library */
 #cmakedefine GMX_USE_TNG
 
 /* Add support for tracing using Extrae */
-#cmakedefine HAVE_EXTRAE
+#cmakedefine01 HAVE_EXTRAE
 
 /* Use MPI (with mpicc) for parallelization */
 #cmakedefine GMX_LIB_MPI
 /* Maximum number of OpenMP threads supported */
 #define GMX_OPENMP_MAX_THREADS @GMX_OPENMP_MAX_THREADS@
 
-/* Use if can't rename checkpoints */
-#cmakedefine GMX_NO_RENAME
+/* Use if we cannot rename checkpoints */
+#cmakedefine01 GMX_NO_RENAME
 
 /* Use (modified) Gamess-UK for QM-MM calculations */
-#cmakedefine GMX_QMMM_GAMESS
+#cmakedefine01 GMX_QMMM_GAMESS
 
 /* Use (modified) Gaussian0x for QM-MM calculations */
-#cmakedefine GMX_QMMM_GAUSSIAN
+#cmakedefine01 GMX_QMMM_GAUSSIAN
 
 /* Use (modified) Mopac 7 for QM-MM calculations */
-#cmakedefine GMX_QMMM_MOPAC
+#cmakedefine01 GMX_QMMM_MOPAC
 
 /* Use ORCA for QM-MM calculations */
-#cmakedefine GMX_QMMM_ORCA
+#cmakedefine01 GMX_QMMM_ORCA
 
 /* Use the GROMACS software 1/sqrt(x) */
 #cmakedefine GMX_SOFTWARE_INVSQRT
 #cmakedefine HAVE_PTHREAD_SETAFFINITY
 
 /* Define for X-Windows */
-#cmakedefine GMX_X11
+#cmakedefine01 GMX_X11
 
 /* Enable x86 gcc inline assembly */
 #cmakedefine GMX_X86_GCC_INLINE_ASM
 #cmakedefine HAVE_SCHED_H
 
 /* Define to 1 if you have the POSIX <regex.h> header file. */
-#cmakedefine HAVE_POSIX_REGEX
+#cmakedefine01 HAVE_POSIX_REGEX
 
 /* Define to 1 if you have the C++11 <regex> header file. */
-#cmakedefine HAVE_CXX11_REGEX
+#cmakedefine01 HAVE_CXX11_REGEX
 
 /* Define to 1 if you have the sysconf() function */
 #cmakedefine HAVE_SYSCONF
 
 /* Bytes in IEEE fp word are in big-endian order if set, little-endian if not.
    Only relevant when FLOAT_FORMAT_IEEE754 is defined. */
-#cmakedefine GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
+#cmakedefine01 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
 
 /* The two words in a double precision variable are in b ig-endian order if
    set, little-endian if not. Do NOT assume this is the same as the byte
    order! Only relevant when FLOAT_FORMAT_IEEE754 is defined. */
-#cmakedefine GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
+#cmakedefine01 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
 
 /* Define if SIGUSR1 is present */
-#cmakedefine HAVE_SIGUSR1
+#cmakedefine01 HAVE_SIGUSR1
 
 /* Enable gromacs quotes */
-#cmakedefine GMX_COOL_QUOTES
+#cmakedefine01 GMX_COOL_QUOTES
 
 /* default name mangling maybe wrong on exotic plattforms */
 #define F77_FUNC(name,NAME) name ## _
 
 /* Define if we have pipes */
-#cmakedefine HAVE_PIPES
+#cmakedefine01 HAVE_PIPES
 
 /* Define if we have feenableexcept */
-#cmakedefine HAVE_FEENABLEEXCEPT
+#cmakedefine01 HAVE_FEENABLEEXCEPT
 
 /* Define if we have zlib */
-#cmakedefine HAVE_ZLIB
+#cmakedefine01 HAVE_ZLIB
 
 /*! \endcond */
 
diff --git a/src/contrib/anaf.c b/src/contrib/anaf.c
deleted file mode 100644 (file)
index 8997194..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 
- *                This source code is part of
- * 
- *                 G   R   O   M   A   C   S
- * 
- *          GROningen MAchine for Chemical Simulations
- * 
- *                        VERSION 3.3.99_development_20071104
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2006, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
- * 
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- * 
- * For more info, check our website at http://www.gromacs.org
- * 
- * And Hey:
- * Groningen Machine for Chemical Simulation
- */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-#include "macros.h"
-#include "gromacs/utility/futil.h"
-#include "gromacs/commandline/pargs.h"
-#include "copyrite.h"
-#include "txtdump.h"
-#include "gromacs/utility/fatalerror.h"
-#include "gromacs/fileio/xtcio.h"
-#include "gromacs/fileio/enxio.h"
-#include "gromacs/utility/smalloc.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
-#include "txtdump.h"
-#include "gromacs/math/vec.h"
-
-static char *nm[5]  = { "OW", "HW1", "HW2", "DW", "SW" };
-  
-static void list_trn(char *fn)
-{
-  static real mass[5] = { 15.9994, 1.008, 1.008, 0.0, 0.0 };
-  int         i,j=0,m,fpread,fpwrite,nframe;
-  rvec        *x,*v,*f,fmol[2],xcm[2],torque[j],dx;
-  real        mmm,len;
-  matrix      box;
-  t_trnheader trn;
-  gmx_bool        bOK;
-
-  printf("Going to open %s\n",fn);
-  fpread  = open_trn(fn,"r"); 
-  fpwrite = open_tpx(NULL,"w");
-  gmx_fio_setdebug(fpwrite,TRUE);
-  
-  mmm=mass[0]+2*mass[1];
-  for(i=0; (i<5); i++) 
-    mass[i] /= mmm;
-  
-  nframe = 0;
-  while (fread_trnheader(fpread,&trn,&bOK)) {
-    snew(x,trn.natoms);
-    snew(v,trn.natoms);
-    snew(f,trn.natoms);
-    if (fread_htrn(fpread,&trn,
-                  trn.box_size ? box : NULL,
-                  trn.x_size   ? x : NULL,
-                  trn.v_size   ? v : NULL,
-                  trn.f_size   ? f : NULL)) {
-                  
-      if (trn.x_size && trn.f_size) {
-       printf("There are %d atoms\n",trn.natoms);
-       for(j=0; (j<2); j++) {
-         clear_rvec(xcm[j]);
-         clear_rvec(fmol[j]);
-         clear_rvec(torque[j]);
-         for(i=5*j; (i<5*j+5); i++) {
-           rvec_inc(fmol[j],f[i]);
-           for(m=0; (m<DIM); m++)
-             xcm[j][m] += mass[i%5]*x[i][m];
-         }
-         for(i=5*j; (i<5*j+5); i++) {
-           rvec_dec(x[i],xcm[j]);
-           cprod(x[i],f[i],dx);
-           rvec_inc(torque[j],dx);
-           rvec_inc(x[i],xcm[j]);
-         }
-       }
-       pr_rvecs(stdout,0,"FMOL  ",fmol,2);
-       pr_rvecs(stdout,0,"TORQUE",torque,2);
-       printf("Distance matrix Water1-Water2\n%5s","");
-       for(j=0; (j<5); j++) 
-         printf("  %10s",nm[j]);
-       printf("\n");
-       for(j=0; (j<5); j++) {
-         printf("%5s",nm[j]);
-         for(i=5; (i<10); i++) {
-           rvec_sub(x[i],x[j],dx);
-           len = sqrt(iprod(dx,dx));
-           printf("  %10.7f",len);
-         }
-         printf("\n");
-       }
-      }
-    }
-    sfree(x);
-    sfree(v);
-    sfree(f);
-    nframe++;
-  }
-  if (!bOK)
-    fprintf(stderr,"\nWARNING: Incomplete frame header: nr %d, t=%g\n",
-           nframe,trn.t);
-  close_tpx(fpwrite);
-  close_trn(fpread);
-}
-
-int main(int argc,char *argv[])
-{
-  static char *desc[] = {
-    "[TT]gmxdump[tt] reads a run input file ([REF].tpr[ref]),",
-    "a trajectory ([REF].trr[ref]/[REF].xtc[ref]) or an energy",
-    "file ([REF].edr[ref]) and prints that to standard",
-    "output in a readable format. This program is essential for",
-    "checking your run input file in case of problems.[PAR]"
-  };
-  t_filenm fnm[] = {
-    { efTRN, "-f", NULL, ffOPTRD }
-  };
-#define NFILE asize(fnm)
-  char *fn;
-  
-  /* Command line options */
-  
-  CopyRight(stdout,argv[0]);
-  parse_common_args(&argc,argv,0,NFILE,fnm,0,NULL,
-                   asize(desc),desc,0,NULL);
-  
-  if (ftp2bSet(efTRN,NFILE,fnm)) {
-    fn = ftp2fn(efTRN,NFILE,fnm);
-    printf("Going to open %s\n",fn);
-    list_trn(fn);
-  }
-  
-  gmx_thanx(stderr);
-
-  return 0;
-}
index 80474afb71aa50254b82b340ac4b8a854b94cec7..dfd884995431d72b1bf18c42e5de0515cee9e615 100644 (file)
@@ -54,7 +54,6 @@
 #include "gbutil.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/gmxfio.h"
 
 typedef struct {
     int resnr; 
index a60b847cdd9b881be02bcde7221ec663c71cf627..389a20386b4994a70acc4ea2701264e57f9cbc7b 100644 (file)
@@ -50,7 +50,7 @@
 #include "gromacs/math/units.h"
 #include "names.h"
 #include "txtdump.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/fileio/confio.h"
index 865f4b8b476812af1f80dfba784ccab4e7fcfcdc..888ae65950c9e26a8a7c97c44a6bbed5c561ea3b 100644 (file)
@@ -51,7 +51,6 @@
 #include "gromacs/math/units.h"
 #include "names.h"
 #include "txtdump.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/confio.h"
 
 real pot(real x,real qq,real c6,real c12)
index f30e8bf740e594b1f879e7f96479d67dbcb0df6c..84a9794fdd2c0418896292335337db70ed32495f 100644 (file)
 #include "wait.h"
 #include "atomic.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /** Fast (possibly busy-wait-based) lock type
  *
  *  This lock type forms an intermediate between the spinlocks and mutexes:
@@ -102,6 +106,8 @@ int tMPI_Lock_trylock(tMPI_Lock_t *lock);
 TMPI_EXPORT
 int tMPI_Lock_islocked(tMPI_Lock_t *lock);
 
-
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* TMPI_FASTLOCK_H_ */
index 2b0f24601d38f51ccbbaec5546e3f8b9af5c6a87..ac115b6593d8ffd71bcb3ef6a0fc434e016c4770 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -54,9 +54,9 @@
  * gmx::AnalysisData and gmx::AnalysisArrayData.  These classes are used to
  * process and store raw data as produced by the analysis tool.  They also
  * provide an interface to attach data modules that implement
- * gmx::AnalysisDataModuleInterface.
+ * gmx::IAnalysisDataModule.
  *
- * Modules that implement gmx::AnalysisDataModuleInterface form the second part
+ * Modules that implement gmx::IAnalysisDataModule form the second part
  * of the module, and they provide functionality to do processing on the data.
  * These modules can also derive from gmx::AbstractAnalysisData, allowing other
  * modules to be attached to them to form a processing chain that best suits
@@ -70,7 +70,7 @@
  * To use the functionality in this module, you typically declare one or more
  * AnalysisData objects and set its properties.  You then create some module
  * objects and set their properties (see the list of classes that implement
- * gmx::AnalysisDataModuleInterface) and attach them to the data objects or to
+ * gmx::IAnalysisDataModule) and attach them to the data objects or to
  * one another using gmx::AbstractAnalysisData::addModule().  Then you add the
  * actual data values to the gmx::AnalysisData object, which automatically
  * passes it on to the modules.
@@ -87,7 +87,7 @@
  *
  * <H3>Data Modules</H3>
  *
- * Modules that derive from gmx::AnalysisDataModuleInterface can operate in two
+ * Modules that derive from gmx::IAnalysisDataModule can operate in two
  * modes:
  *  - In _serial_ mode, the frames are presented to the module always in the
  *    order of increasing indices, even if they become ready in a different
  *         node [ shape=box ]
  *
  *         start  [ label="dataStarted()",
- *                  URL="\ref gmx::AnalysisDataModuleInterface::dataStarted()" ]
+ *                  URL="\ref gmx::IAnalysisDataModule::dataStarted()" ]
  *         pstart [ label="parallelDataStarted()",
- *                  URL="\ref gmx::AnalysisDataModuleInterface::parallelDataStarted()" ]
+ *                  URL="\ref gmx::IAnalysisDataModule::parallelDataStarted()" ]
  *         subgraph cluster_frame {
  *             label = "for each frame"
  *             framestart   [ label="frameStarted()",
- *                            URL="\ref gmx::AnalysisDataModuleInterface::frameStarted()" ]
+ *                            URL="\ref gmx::IAnalysisDataModule::frameStarted()" ]
  *             pointsadd    [ label="pointsAdded()",
- *                            URL="\ref gmx::AnalysisDataModuleInterface::pointsAdded()" ]
+ *                            URL="\ref gmx::IAnalysisDataModule::pointsAdded()" ]
  *             framefinish  [ label="frameFinished()",
- *                            URL="\ref gmx::AnalysisDataModuleInterface::frameFinished()" ]
+ *                            URL="\ref gmx::IAnalysisDataModule::frameFinished()" ]
  *             serialfinish [ label="frameFinishedSerial()",
- *                            URL="\ref gmx::AnalysisDataModuleInterface::frameFinishedSerial()" ]
+ *                            URL="\ref gmx::IAnalysisDataModule::frameFinishedSerial()" ]
  *         }
  *         finish [ label="dataFinished()",
- *                  URL="\ref gmx::AnalysisDataModuleInterface::dataFinished()" ]
+ *                  URL="\ref gmx::IAnalysisDataModule::dataFinished()" ]
  *
  *         start -> framestart
  *         pstart -> framestart
  *
  * New data modules can be implemented to perform custom operations that are
  * not supported by the modules provided in this module.  This is done by
- * creating a new class that implements gmx::AnalysisDataModuleInterface.
+ * creating a new class that implements gmx::IAnalysisDataModule.
  * If the new module computes values that can be used as input for other
  * modules, the new class should also derive from gmx::AbstractAnalysisData, and
  * preferably use gmx::AnalysisDataStorage internally to implement storage of
index 9d21ccad6c9c8d890e3d43fedea8db140b02017a..94e210389318863e60805ada6aed2487fd0d2e78 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -185,7 +185,7 @@ AbstractAnalysisData::addColumnModule(int col, int span,
 
 
 void
-AbstractAnalysisData::applyModule(AnalysisDataModuleInterface *module)
+AbstractAnalysisData::applyModule(IAnalysisDataModule *module)
 {
     impl_->modules_.applyModule(this, module);
 }
index fd1c99db56fa9a75f27a0da1e918aa112c11c947..ac3a9224d26832a79e5c4eacd2cd3ec16a3dda5f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 namespace gmx
 {
 
-class AnalysisDataModuleInterface;
 class AnalysisDataModuleManager;
 class AnalysisDataFrameHeader;
 class AnalysisDataFrameRef;
 class AnalysisDataPointSetRef;
+class IAnalysisDataModule;
 
 //! Smart pointer for managing a generic analysis data module.
-typedef boost::shared_ptr<AnalysisDataModuleInterface> AnalysisDataModulePointer;
+typedef boost::shared_ptr<IAnalysisDataModule> AnalysisDataModulePointer;
 
 /*! \brief
  * Abstract base class for all objects that provide data.
@@ -318,7 +318,7 @@ class AbstractAnalysisData
          * storage (addModule() has the same problem if called after data is
          * started).
          */
-        void applyModule(AnalysisDataModuleInterface *module);
+        void applyModule(IAnalysisDataModule *module);
 
     protected:
         /*! \cond libapi */
index c04ae1807273ea6819abadcd652f6bd03207bfbe..7d1b1997ed569fab2208f49a7030c3c3b9977814 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -151,7 +151,7 @@ class AnalysisData : public AbstractAnalysisData
          * \throws  std::bad_alloc if out of memory.
          * \throws  APIError if any attached data module is not compatible.
          * \throws  unspecified  Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::dataStarted().
+         *      in IAnalysisDataModule::dataStarted().
          *
          * The caller should retain the returned handle (or a copy of it), and
          * pass it to finishData() after successfully adding all data.
@@ -169,7 +169,7 @@ class AnalysisData : public AbstractAnalysisData
          *
          * \param[in]  frameIndex Index of the frame that has been finished.
          * \throws  unspecified  Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::frameFinishedSerial().
+         *      in IAnalysisDataModule::frameFinishedSerial().
          *
          * This method should be called sequentially for each frame, after data
          * for that frame has been produced.  It is not necessary to call this
@@ -183,7 +183,7 @@ class AnalysisData : public AbstractAnalysisData
          *
          * \param[in]  handle  Handle to destroy.
          * \throws  unspecified  Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::dataFinished().
+         *      in IAnalysisDataModule::dataFinished().
          *
          * \p handle must have been obtained from startData() of this object.
          * The order of the calls with respect to the corresponding startData()
@@ -270,7 +270,7 @@ class AnalysisDataHandle
          * \param[in] dx     Error in x for the frame if applicable.
          *
          * \throws    unspecified  Any exception thrown by attached data
-         *      modules in AnalysisDataModuleInterface::frameStarted().
+         *      modules in IAnalysisDataModule::frameStarted().
          *
          * Each \p index value 0, 1, ..., N (where N is the total number of
          * frames) should be started exactly once by exactly one handle of an
@@ -338,7 +338,7 @@ class AnalysisDataHandle
          *
          * \throws    APIError if any attached data module is not compatible.
          * \throws    unspecified  Any exception thrown by attached data
-         *      modules in AnalysisDataModuleInterface::pointsAdded().
+         *      modules in IAnalysisDataModule::pointsAdded().
          *
          * Must be called after each point set for multipoint data, including
          * the last (i.e., no values must be set between the last call to this
index 3fa7e02fdcac9046cbd2b990ab6a2ccd3da34c74..255f00a2c57e2ac8c5368a112381c625ef7dddd6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -34,7 +34,7 @@
  */
 /*! \file
  * \brief
- * Declares gmx::AnalysisDataModuleInterface and related convenience classes.
+ * Declares gmx::IAnalysisDataModule and related convenience classes.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
@@ -78,7 +78,7 @@ class AnalysisDataPointSetRef;
  * \inlibraryapi
  * \ingroup module_analysisdata
  */
-class AnalysisDataModuleInterface
+class IAnalysisDataModule
 {
     public:
         /*! \brief
@@ -98,7 +98,7 @@ class AnalysisDataModuleInterface
             efAllowMultipleDataSets     = 1<<4
         };
 
-        virtual ~AnalysisDataModuleInterface() {};
+        virtual ~IAnalysisDataModule() {};
 
         /*! \brief
          * Returns properties supported by the module.
@@ -237,7 +237,7 @@ class AnalysisDataModuleInterface
  * \inlibraryapi
  * \ingroup module_analysisdata
  */
-class AnalysisDataModuleSerial : public AnalysisDataModuleInterface
+class AnalysisDataModuleSerial : public IAnalysisDataModule
 {
     public:
         virtual ~AnalysisDataModuleSerial() {}
@@ -267,7 +267,7 @@ class AnalysisDataModuleSerial : public AnalysisDataModuleInterface
  * \inlibraryapi
  * \ingroup module_analysisdata
  */
-class AnalysisDataModuleParallel : public AnalysisDataModuleInterface
+class AnalysisDataModuleParallel : public IAnalysisDataModule
 {
     public:
         virtual ~AnalysisDataModuleParallel() {}
index ab10252807edcbf6598b097e371e10c66568d2b2..f9e4d8dbb3919b8d5be36f2d2b9fb3e7afeffa30 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -104,7 +104,7 @@ class AnalysisDataModuleManager::Impl
          * \param[in] bSet     Value of the property to check against.
          * \throws    APIError if \p module is not compatible with the data.
          */
-        void checkModuleProperty(const AnalysisDataModuleInterface &module,
+        void checkModuleProperty(const IAnalysisDataModule &module,
                                  DataProperty property, bool bSet) const;
         /*! \brief
          * Checks whether a module is compatible with the data properties.
@@ -115,7 +115,7 @@ class AnalysisDataModuleManager::Impl
          * Does not currently check the actual data (e.g., missing values), but
          * only the dimensionality and other preset properties of the data.
          */
-        void checkModuleProperties(const AnalysisDataModuleInterface &module) const;
+        void checkModuleProperties(const IAnalysisDataModule &module) const;
 
         /*! \brief
          * Present data already added to the data object to a module.
@@ -133,7 +133,7 @@ class AnalysisDataModuleManager::Impl
          * been registered to the data object when the data was added.
          */
         void presentData(AbstractAnalysisData        *data,
-                         AnalysisDataModuleInterface *module);
+                         IAnalysisDataModule         *module);
 
         //! List of modules added to the data.
         ModuleList              modules_;
@@ -175,7 +175,7 @@ AnalysisDataModuleManager::Impl::Impl()
 
 void
 AnalysisDataModuleManager::Impl::checkModuleProperty(
-        const AnalysisDataModuleInterface &module,
+        const IAnalysisDataModule &module,
         DataProperty property, bool bSet) const
 {
     bool      bOk   = true;
@@ -183,20 +183,20 @@ AnalysisDataModuleManager::Impl::checkModuleProperty(
     switch (property)
     {
         case eMultipleDataSets:
-            if (bSet && !(flags & AnalysisDataModuleInterface::efAllowMultipleDataSets))
+            if (bSet && !(flags & IAnalysisDataModule::efAllowMultipleDataSets))
             {
                 bOk = false;
             }
             break;
         case eMultipleColumns:
-            if (bSet && !(flags & AnalysisDataModuleInterface::efAllowMulticolumn))
+            if (bSet && !(flags & IAnalysisDataModule::efAllowMulticolumn))
             {
                 bOk = false;
             }
             break;
         case eMultipoint:
-            if ((bSet && !(flags & AnalysisDataModuleInterface::efAllowMultipoint))
-                || (!bSet && (flags & AnalysisDataModuleInterface::efOnlyMultipoint)))
+            if ((bSet && !(flags & IAnalysisDataModule::efAllowMultipoint))
+                || (!bSet && (flags & IAnalysisDataModule::efOnlyMultipoint)))
             {
                 bOk = false;
             }
@@ -212,7 +212,7 @@ AnalysisDataModuleManager::Impl::checkModuleProperty(
 
 void
 AnalysisDataModuleManager::Impl::checkModuleProperties(
-        const AnalysisDataModuleInterface &module) const
+        const IAnalysisDataModule &module) const
 {
     for (int i = 0; i < eDataPropertyNR; ++i)
     {
@@ -221,8 +221,8 @@ AnalysisDataModuleManager::Impl::checkModuleProperties(
 }
 
 void
-AnalysisDataModuleManager::Impl::presentData(AbstractAnalysisData        *data,
-                                             AnalysisDataModuleInterface *module)
+AnalysisDataModuleManager::Impl::presentData(AbstractAnalysisData *data,
+                                             IAnalysisDataModule  *module)
 {
     if (state_ == eNotStarted)
     {
@@ -232,7 +232,7 @@ AnalysisDataModuleManager::Impl::presentData(AbstractAnalysisData        *data,
                        "Cannot apply a modules in mid-frame");
     module->dataStarted(data);
     const bool bCheckMissing = bAllowMissing_
-        && !(module->flags() & AnalysisDataModuleInterface::efAllowMissing);
+        && !(module->flags() & IAnalysisDataModule::efAllowMissing);
     for (int i = 0; i < data->frameCount(); ++i)
     {
         AnalysisDataFrameRef frame = data->getDataFrame(i);
@@ -298,7 +298,7 @@ AnalysisDataModuleManager::addModule(AbstractAnalysisData      *data,
                        "Cannot add a data module in mid-frame");
     impl_->presentData(data, module.get());
 
-    if (!(module->flags() & AnalysisDataModuleInterface::efAllowMissing))
+    if (!(module->flags() & IAnalysisDataModule::efAllowMissing))
     {
         impl_->bAllowMissing_ = false;
     }
@@ -306,8 +306,8 @@ AnalysisDataModuleManager::addModule(AbstractAnalysisData      *data,
 }
 
 void
-AnalysisDataModuleManager::applyModule(AbstractAnalysisData        *data,
-                                       AnalysisDataModuleInterface *module)
+AnalysisDataModuleManager::applyModule(AbstractAnalysisData *data,
+                                       IAnalysisDataModule  *module)
 {
     impl_->checkModuleProperties(*module);
     GMX_RELEASE_ASSERT(impl_->state_ == Impl::eFinished,
index 65c159431692f201ad8c7e21c24c6140d0443e3f..2bc9bdb64b65a1c5e3f154f6b3744bcb22bc349a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -54,7 +54,7 @@ class AnalysisDataParallelOptions;
 /*! \libinternal \brief
  * Encapsulates handling of data modules attached to AbstractAnalysisData.
  *
- * See AnalysisDataModuleInterface and \ref module_analysisdata for more
+ * See IAnalysisDataModule and \ref module_analysisdata for more
  * details on the notifications and the order in which they should be raised.
  *
  * \inlibraryapi
@@ -66,7 +66,7 @@ class AnalysisDataModuleManager
         /*! \brief
          * Identifies data properties to check with data modules.
          *
-         * \see AnalysisDataModuleInterface::Flag
+         * \see IAnalysisDataModule::Flag
          */
         enum DataProperty
         {
@@ -132,8 +132,8 @@ class AnalysisDataModuleManager
          *
          * \see AbstractAnalysisData::applyModule()
          */
-        void applyModule(AbstractAnalysisData        *data,
-                         AnalysisDataModuleInterface *module);
+        void applyModule(AbstractAnalysisData *data,
+                         IAnalysisDataModule  *module);
 
         /*! \brief
          * Notifies attached modules of the start of serial data.
@@ -141,7 +141,7 @@ class AnalysisDataModuleManager
          * \param   data  Data object that is starting.
          * \throws  APIError if any attached data module is not compatible.
          * \throws  unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::dataStarted().
+         *      in IAnalysisDataModule::dataStarted().
          *
          * Should be called once, after data properties have been set with
          * the methods in AbstractAnalysisData, and before any other
@@ -153,7 +153,7 @@ class AnalysisDataModuleManager
          * derived from AbstractAnalysisData.
          *
          * This method initializes all modules for serial processing by calling
-         * AnalysisDataModuleInterface::dataStarted().
+         * IAnalysisDataModule::dataStarted().
          */
         void notifyDataStart(AbstractAnalysisData *data);
         /*! \brief
@@ -163,11 +163,11 @@ class AnalysisDataModuleManager
          * \param[in] options Parallelization properties of the input data.
          * \throws  APIError if any attached data module is not compatible.
          * \throws  unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::parallelDataStarted().
+         *      in IAnalysisDataModule::parallelDataStarted().
          *
          * Can be called instead of notifyDataStart() if \p data supports
          * non-sequential creation of frames.  Works as notifyDataStart(),
-         * but instead calls AnalysisDataModuleInterface::parallelDataStarted()
+         * but instead calls IAnalysisDataModule::parallelDataStarted()
          * and records whether the module supports the parallel mode.
          * Subsequent notification calls then notify the modules according to
          * the mode they accept.
@@ -182,7 +182,7 @@ class AnalysisDataModuleManager
          *
          * \param[in] header  Header information for the frame that is starting.
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::frameStarted().
+         *      in IAnalysisDataModule::frameStarted().
          *
          * Should be called once for each frame, before notifyPointsAdd() calls
          * for that frame.
@@ -193,7 +193,7 @@ class AnalysisDataModuleManager
          *
          * \param[in] header  Header information for the frame that is starting.
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::frameStarted().
+         *      in IAnalysisDataModule::frameStarted().
          *
          * If notifyParallelDataStart() has been called, should be called once
          * for each frame, before notifyParallelPointsAdd() calls for that
@@ -210,7 +210,7 @@ class AnalysisDataModuleManager
          *      frame-level data).
          * \throws    APIError if any attached data module is not compatible.
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::pointsAdded().
+         *      in IAnalysisDataModule::pointsAdded().
          *
          * Can be called zero or more times for each frame.
          * The caller should ensure that any column occurs at most once in the
@@ -228,7 +228,7 @@ class AnalysisDataModuleManager
          *      frame-level data).
          * \throws    APIError if any attached data module is not compatible.
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::pointsAdded().
+         *      in IAnalysisDataModule::pointsAdded().
          *
          * See notifyPointsAdd() for information on the structure of the point
          * sets.
@@ -239,7 +239,7 @@ class AnalysisDataModuleManager
          *
          * \param[in] header  Header information for the frame that is ending.
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::frameFinished().
+         *      in IAnalysisDataModule::frameFinished().
          *
          * Should be called once for each call of notifyFrameStart(), after any
          * notifyPointsAdd() calls for the frame.
@@ -254,7 +254,7 @@ class AnalysisDataModuleManager
          *
          * \param[in] header  Header information for the frame that is ending.
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::frameFinished().
+         *      in IAnalysisDataModule::frameFinished().
          *
          * Should be called once for each call of notifyParallelFrameStart(),
          * after any notifyParallelPointsAdd() calls for the frame.
@@ -266,7 +266,7 @@ class AnalysisDataModuleManager
          * Notifies attached modules of the end of data.
          *
          * \throws    unspecified Any exception thrown by attached data modules
-         *      in AnalysisDataModuleInterface::dataFinished().
+         *      in IAnalysisDataModule::dataFinished().
          *
          * Should be called once, after all the other notification calls.
          */
index 72e6c852ce5c7934a79f34f56b9186986fee6572..1b8f639a0281423f1a75ce51e54bd18e16d25e6d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -56,16 +56,16 @@ namespace gmx
  * Internal implementation class used to implement column modules.
  *
  * This class serves as a proxy between AbstractAnalysisData and the attached
- * AnalysisDataModuleInterface object.  For each notification that
+ * IAnalysisDataModule object.  For each notification that
  * AbstractAnalysisData sends, it maps it such that only the relevant columns
- * are visible to the AnalysisDataModuleInterface.  Similarly, it implements
+ * are visible to the IAnalysisDataModule.  Similarly, it implements
  * the frame access methods of AbstractAnalysisData such that only the relevant
  * columns are returned.
  *
  * \ingroup module_analysisdata
  */
 class AnalysisDataProxy : public AbstractAnalysisData,
-                          public AnalysisDataModuleInterface
+                          public IAnalysisDataModule
 {
     public:
         /*! \brief
index f6fa5ca3a7e74b807b5193c0deca7c6f88655cae..99fb08c6ac52066c7d658f7301aa99ca3d2bab99 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -165,7 +165,7 @@ class AnalysisDataFrameLocalDataHandle
  * data for use in analysis data modules that support parallel processing.
  * The object is initialized by setting the desired dimensionality with
  * setDataSetCount() and setColumnCount(), followed by a call to init(),
- * typically in AnalysisDataModuleInterface::parallelDataStarted(),
+ * typically in IAnalysisDataModule::parallelDataStarted(),
  *
  * After initialization, frameData() can be used to access the data for a given
  * frame, independently from other frames.  This works if the assumptions about
@@ -180,7 +180,7 @@ class AnalysisDataFrameLocalDataHandle
  * over all frames in a lock-free manner.
  *
  * frameDataSet() is provided for convenience when only a single data set
- * needs to be accessed (typically in AnalysisDataModuleInterface::pointsAdded()).
+ * needs to be accessed (typically in IAnalysisDataModule::pointsAdded()).
  *
  * Methods in this class do not throw except where indicated.
  *
index 61867c24c4c084750d1c785d72413bb3675ebb3d..58604f04fe4cb8258991dbbffcb14bd36d290bf5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -87,7 +87,7 @@ class AnalysisDataFrameAverager
          *
          * \throws std::bad_alloc if out of memory.
          *
-         * Typically called from AnalysisDataModuleInterface::dataStarted().
+         * Typically called from IAnalysisDataModule::dataStarted().
          *
          * Must be called exactly once, before setting calling any other method
          * in the class.
@@ -103,7 +103,7 @@ class AnalysisDataFrameAverager
         /*! \brief
          * Accumulates data from a given point set into the average.
          *
-         * Typically called from AnalysisDataModuleInterface::pointsAdded().
+         * Typically called from IAnalysisDataModule::pointsAdded().
          *
          * Each call accumulates the values for those columns that are present
          * in the point set.  Can be called multiple times for a frame, and
@@ -117,7 +117,7 @@ class AnalysisDataFrameAverager
          * addPoints().  Currently, does nothing, but provided as a placeholder
          * for more complex implementation.
          *
-         * Typically called from AnalysisDataModuleInterface::dataFinished().
+         * Typically called from IAnalysisDataModule::dataFinished().
          */
         void finish();
 
index 4332f2764132026f0c21be6b643b5abed29b02f8..4f4eb296cd37ea39a3d7ecfac742fd64984f7c09 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,7 +40,7 @@
  * used in its implementation: gmx::AbstractAnalysisData and
  * gmx::AnalysisDataStorage.
  * Most checking is done using gmx::test::AnalysisDataTestFixture and mock
- * modules that implement gmx::AnalysisDataModuleInterface.
+ * modules that implement gmx::IAnalysisDataModule.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_analysisdata
@@ -120,7 +120,7 @@ TEST(AnalysisDataInitializationTest, ChecksMultiColumnModules)
     EXPECT_THROW_GMX(data.addModule(mod1), gmx::APIError);
 
     MockAnalysisDataModulePointer mod2(
-            new MockAnalysisDataModule(gmx::AnalysisDataModuleInterface::efAllowMulticolumn));
+            new MockAnalysisDataModule(gmx::IAnalysisDataModule::efAllowMulticolumn));
     EXPECT_NO_THROW_GMX(data.addModule(mod2));
 }
 
@@ -138,7 +138,7 @@ TEST(AnalysisDataInitializationTest, ChecksMultipointModules)
     EXPECT_THROW_GMX(data.addModule(mod1), gmx::APIError);
 
     MockAnalysisDataModulePointer mod2(
-            new MockAnalysisDataModule(gmx::AnalysisDataModuleInterface::efAllowMultipoint));
+            new MockAnalysisDataModule(gmx::IAnalysisDataModule::efAllowMultipoint));
     EXPECT_NO_THROW_GMX(data.addModule(mod2));
 }
 
index a1d2755bf48e0f57de17e8d7411f7d498f253d62..daab8ff38a071b0f26c9b061ba9099be660c1e91 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -39,7 +39,7 @@
  * These tests check the functionality of gmx::AnalysisArrayData and its base
  * class gmx::AbstractAnalysisArrayData.
  * Checking is done using gmx::test::AnalysisDataTestFixture and mock
- * modules that implement gmx::AnalysisDataModuleInterface.
+ * modules that implement gmx::IAnalysisDataModule.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_analysisdata
index 6d85dd6b05c080827daef2ca26cb912b77ab9b2b..ebdbf161525102b648137e5c77cb27519a76202e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -343,7 +343,7 @@ class AnalysisDataTestFixture : public ::testing::Test
          * \param      source   Data object to verify.
          *
          * Creates a mock module that verifies that the
-         * AnalysisDataModuleInterface methods are called correctly by
+         * IAnalysisDataModule methods are called correctly by
          * \p source.  Parameters for the calls are verified against \p data.
          * Adds the created module to \p source using \p data->addModule().
          * Any exceptions from the called functions should be caught by the
@@ -361,7 +361,7 @@ class AnalysisDataTestFixture : public ::testing::Test
          * \param      source   Data object to verify.
          *
          * Creates a parallel mock module that verifies that the
-         * AnalysisDataModuleInterface methods are called correctly by
+         * IAnalysisDataModule methods are called correctly by
          * \p source.  Parameters for the calls are verified against \p data.
          * Adds the created module to \p source using \p data->addModule().
          * Any exceptions from the called functions should be caught by the
@@ -386,7 +386,7 @@ class AnalysisDataTestFixture : public ::testing::Test
          * \param      source   Data object to verify.
          *
          * Creates a mock module that verifies that the
-         * AnalysisDataModuleInterface methods are called correctly by
+         * IAnalysisDataModule methods are called correctly by
          * \p source.  Parameters for the calls are verified against \p data.
          * Adds the created module to \p source using
          * \p data->addColumnModule().
@@ -410,7 +410,7 @@ class AnalysisDataTestFixture : public ::testing::Test
          * Works like addStaticCheckerModule(), except that in addition, for
          * each frame, the mock module also checks that previous frames can be
          * accessed using AbstractAnalysisData::getDataFrame().  In the
-         * AnalysisDataModuleInterface::dataStarted() callback, the mock module
+         * IAnalysisDataModule::dataStarted() callback, the mock module
          * calls AbstractAnalysisData::requestStorage() with \p storageCount as
          * the parameter.
          */
@@ -426,7 +426,7 @@ class AnalysisDataTestFixture : public ::testing::Test
          * \param[in]  tolerance Tolerance to use for comparison.
          *
          * Creates a mock module that verifies that the
-         * AnalysisDataModuleInterface methods are called correctly by
+         * IAnalysisDataModule methods are called correctly by
          * \p source.  Parameters for the calls are verified against reference
          * data using a child compound \p id of \p checker.
          * Adds the created module to \p source using \p data->addModule().
index cdd1ec5490679060aaa43cf50916e1370db3b6e7..e1e917e4d6be553b0513258aff0312196f012ec1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -304,7 +304,7 @@ void checkFrame(const AnalysisDataFrameRef       &frame,
  * Functor for checking data frame header against static test input data.
  *
  * This functor is designed to be invoked as a handled for
- * AnalysisDataModuleInterface::frameStarted().
+ * IAnalysisDataModule::frameStarted().
  */
 class StaticDataFrameHeaderChecker
 {
@@ -336,7 +336,7 @@ class StaticDataFrameHeaderChecker
  * Functor for checking data frame points against static test input data.
  *
  * This functor is designed to be invoked as a handled for
- * AnalysisDataModuleInterface::pointsAdded().
+ * IAnalysisDataModule::pointsAdded().
  */
 class StaticDataPointsChecker
 {
@@ -387,7 +387,7 @@ class StaticDataPointsChecker
  * Functor for requesting data storage.
  *
  * This functor is designed to be invoked as a handled for
- * AnalysisDataModuleInterface::dataStarted().
+ * IAnalysisDataModule::dataStarted().
  */
 class DataStorageRequester
 {
@@ -417,7 +417,7 @@ class DataStorageRequester
  * data.
  *
  * This functor is designed to be invoked as a handled for
- * AnalysisDataModuleInterface::pointsAdded().
+ * IAnalysisDataModule::pointsAdded().
  */
 class StaticDataPointsStorageChecker
 {
index ebb4baa2f84b78ede83a17851986b2b01e5c9503..584804fac2562e33db65559dc7f3227229461445 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -34,7 +34,7 @@
  */
 /*! \libinternal \file
  * \brief
- * Declares mock implementation of gmx::AnalysisDataModuleInterface.
+ * Declares mock implementation of gmx::IAnalysisDataModule.
  *
  * Requires Google Mock.
  *
@@ -61,7 +61,7 @@ namespace test
 class AnalysisDataTestInput;
 class TestReferenceChecker;
 
-class MockAnalysisDataModule : public AnalysisDataModuleInterface
+class MockAnalysisDataModule : public IAnalysisDataModule
 {
     public:
         explicit MockAnalysisDataModule(int flags);
index 1ae38d84525b8dfc62b0f5178ad9305cb3948268..b6e9bcfdb67f16b17e6b79715d4980024cf82b08 100644 (file)
@@ -68,4 +68,31 @@ and use the copy_xsl.sh script to copy it to relevant locations.
     <xsl:value-of select="."/>
 </xsl:template>
 
+<xsl:template match="InteractiveSession">
+    <pre>
+        <xsl:for-each select="*">
+            <xsl:choose>
+                <xsl:when test="starts-with(@Name, 'Output')">
+                    <xsl:value-of select="substring(.,2)"/>
+                </xsl:when>
+                <xsl:when test="string-length(.)=1">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:when>
+                <xsl:when test="contains(substring(.,2), '&#10;')">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="translate(substring(.,2), '&#10;', '&#x23ce;')"/>
+                    <xsl:text>&#10;</xsl:text>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="substring(.,2)"/>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:for-each>
+        <xsl:text>[EOF]</xsl:text>
+    </pre>
+</xsl:template>
+
 </xsl:stylesheet>
index 2b1c2df26f50f6d4814de56aa54d84186b84caa0..4032c29882ee3256f7e14500ba7da9b37230d6d2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -47,8 +47,8 @@
  *  - Helper classes/functions for implementing the %main() function.
  *    See \ref page_usinglibrary for an overview of those available for user
  *    programs.  These are declared in cmdlineinit.h
- *    (gmx::CommandLineModuleInterface is declared in cmdlinemodule.h and
- *    gmx::CommandLineOptionsInterface in cmdlineoptionsmodule.h).
+ *    (gmx::ICommandLineModule is declared in cmdlinemodule.h and
+ *    gmx::ICommandLineOptions in cmdlineoptionsmodule.h).
  *    \if libapi
  *
  *    Additionally, for internal \Gromacs use, gmx::CommandLineModuleManager
index cfe32fbf38905227976a8f86633fd6fdb9ace6d6..d1af037ef5898431e6d590d52f98676823d32245 100644 (file)
@@ -74,8 +74,9 @@ class CommandLineHelpContext::Impl
 {
     public:
         //! Creates the implementation class and the low-level context.
-        Impl(File *file, HelpOutputFormat format, const HelpLinks *links)
-            : writerContext_(file, format, links), moduleDisplayName_("gmx"),
+        Impl(TextOutputStream *stream, HelpOutputFormat format,
+             const HelpLinks *links)
+            : writerContext_(stream, format, links), moduleDisplayName_("gmx"),
               completionWriter_(NULL), bHidden_(false)
         {
         }
@@ -97,9 +98,9 @@ class CommandLineHelpContext::Impl
 };
 
 CommandLineHelpContext::CommandLineHelpContext(
-        File *file, HelpOutputFormat format, const HelpLinks *links,
-        const std::string &programName)
-    : impl_(new Impl(file, format, links))
+        TextOutputStream *stream, HelpOutputFormat format,
+        const HelpLinks *links, const std::string &programName)
+    : impl_(new Impl(stream, format, links))
 {
     impl_->writerContext_.setReplacement("[PROGRAM]", programName);
 }
@@ -112,7 +113,7 @@ CommandLineHelpContext::CommandLineHelpContext(
 
 CommandLineHelpContext::CommandLineHelpContext(
         ShellCompletionWriter *writer)
-    : impl_(new Impl(writer->outputFile(), eHelpOutputFormat_Other, NULL))
+    : impl_(new Impl(&writer->outputStream(), eHelpOutputFormat_Other, NULL))
 {
     impl_->completionWriter_ = writer;
 }
index 330f20aa6f486572d71bbf11c57abd27698c4876..be59e70cbb9d7a444108fff3e4503f7442a53a61 100644 (file)
@@ -76,8 +76,8 @@ class CommandLineHelpContext
          *
          * Wraps the constructor of HelpWriterContext.
          */
-        CommandLineHelpContext(File *file, HelpOutputFormat format,
-                               const HelpLinks *links,
+        CommandLineHelpContext(TextOutputStream *stream,
+                               HelpOutputFormat format, const HelpLinks *links,
                                const std::string &programName);
         //! Creates a context for a particular HelpWriterContext.
         explicit CommandLineHelpContext(const HelpWriterContext &writerContext);
index 2a2959cbf86e19b22c25d284f47e7a0d88b339b0..cabe8f1b7a4507c06d13d032352f1f4d2ae654ec 100644 (file)
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/baseversion.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/fileredirector.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/path.h"
 #include "gromacs/utility/programcontext.h"
+#include "gromacs/utility/stringstream.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textreader.h"
+#include "gromacs/utility/textstream.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "shellcompletions.h"
 
@@ -73,7 +77,7 @@ namespace gmx
 
 namespace
 {
-class HelpExportInterface;
+class IHelpExport;
 class RootHelpTopic;
 }   // namespace
 
@@ -84,24 +88,24 @@ class RootHelpTopic;
 class CommandLineHelpModuleImpl
 {
     public:
-        CommandLineHelpModuleImpl(const ProgramContextInterface    &programContext,
+        CommandLineHelpModuleImpl(const IProgramContext            &programContext,
                                   const std::string                &binaryName,
                                   const CommandLineModuleMap       &modules,
                                   const CommandLineModuleGroupList &groups);
 
-        void exportHelp(HelpExportInterface *exporter);
+        void exportHelp(IHelpExport *exporter);
 
         boost::scoped_ptr<RootHelpTopic>  rootTopic_;
-        const ProgramContextInterface    &programContext_;
+        const IProgramContext            &programContext_;
         std::string                       binaryName_;
         const CommandLineModuleMap       &modules_;
         const CommandLineModuleGroupList &groups_;
 
         CommandLineHelpContext           *context_;
-        const CommandLineModuleInterface *moduleOverride_;
+        const ICommandLineModule         *moduleOverride_;
         bool                              bHidden_;
 
-        FileOutputRedirectorInterface    *outputRedirector_;
+        IFileOutputRedirector            *outputRedirector_;
 
         GMX_DISALLOW_COPY_AND_ASSIGN(CommandLineHelpModuleImpl);
 };
@@ -110,7 +114,7 @@ namespace
 {
 
 /********************************************************************
- * HelpExportInterface
+ * IHelpExport
  */
 
 /*! \brief
@@ -118,13 +122,13 @@ namespace
  *
  * \ingroup module_commandline
  */
-class HelpExportInterface
+class IHelpExport
 {
     public:
         //! Shorthand for a list of modules contained in a group.
         typedef CommandLineModuleGroupData::ModuleList ModuleGroupContents;
 
-        virtual ~HelpExportInterface() {};
+        virtual ~IHelpExport() {};
 
         /*! \brief
          * Called once before exporting individual modules.
@@ -142,7 +146,7 @@ class HelpExportInterface
          * \param[in] displayName Display name for the module (gmx something).
          */
         virtual void exportModuleHelp(
-            const CommandLineModuleInterface &module,
+            const ICommandLineModule         &module,
             const std::string                &tag,
             const std::string                &displayName) = 0;
         /*! \brief
@@ -180,7 +184,7 @@ class HelpExportInterface
          *
          * \param[in] topic   Topic to export.
          */
-        virtual void exportTopic(const HelpTopicInterface &topic) = 0;
+        virtual void exportTopic(const IHelpTopic &topic) = 0;
 };
 
 /********************************************************************
@@ -237,7 +241,7 @@ class RootHelpTopic : public AbstractCompositeHelpTopic
             addSubTopic(move(topic));
         }
         //! Exports all the top-level topics with the given exporter.
-        void exportHelp(HelpExportInterface *exporter);
+        void exportHelp(IHelpExport *exporter);
 
         virtual void writeHelp(const HelpWriterContext &context) const;
 
@@ -252,14 +256,14 @@ class RootHelpTopic : public AbstractCompositeHelpTopic
         GMX_DISALLOW_COPY_AND_ASSIGN(RootHelpTopic);
 };
 
-void RootHelpTopic::exportHelp(HelpExportInterface *exporter)
+void RootHelpTopic::exportHelp(IHelpExport *exporter)
 {
     std::vector<std::string>::const_iterator topicName;
     for (topicName = exportedTopics_.begin();
          topicName != exportedTopics_.end();
          ++topicName)
     {
-        const HelpTopicInterface *topic = findSubTopic(topicName->c_str());
+        const IHelpTopic *topic = findSubTopic(topicName->c_str());
         GMX_RELEASE_ASSERT(topic != NULL, "Exported help topic no longer found");
         exporter->exportTopic(*topic);
     }
@@ -285,11 +289,15 @@ void RootHelpTopic::writeHelp(const HelpWriterContext &context) const
         }
         cmdlineContext->setModuleDisplayName(helpModule_.binaryName_);
         optionsHolder.initOptions();
-        Options &options = *optionsHolder.options();
-        options.setDescription(RootHelpText::text);
+        Options                    &options = *optionsHolder.options();
+        ConstArrayRef<const char *> helpText;
+        if (context.outputFormat() != eHelpOutputFormat_Console)
+        {
+            helpText = RootHelpText::text;
+        }
         // TODO: Add <command> [<args>] into the synopsis.
         CommandLineHelpWriter(options)
-            .setShowDescriptions(context.outputFormat() != eHelpOutputFormat_Console)
+            .setHelpText(helpText)
             .writeHelp(*cmdlineContext);
     }
     if (context.outputFormat() == eHelpOutputFormat_Console)
@@ -323,7 +331,7 @@ void RootHelpTopic::writeHelp(const HelpWriterContext &context) const
  *
  * \ingroup module_commandline
  */
-class CommandsHelpTopic : public HelpTopicInterface
+class CommandsHelpTopic : public IHelpTopic
 {
     public:
         /*! \brief
@@ -341,7 +349,7 @@ class CommandsHelpTopic : public HelpTopicInterface
         virtual const char *name() const { return "commands"; }
         virtual const char *title() const { return "List of available commands"; }
         virtual bool hasSubTopics() const { return false; }
-        virtual const HelpTopicInterface *findSubTopic(const char * /*name*/) const
+        virtual const IHelpTopic *findSubTopic(const char * /*name*/) const
         {
             return NULL;
         }
@@ -376,7 +384,7 @@ void CommandsHelpTopic::writeHelp(const HelpWriterContext &context) const
     context.writeTextBlock(
             "Usage: [PROGRAM] [<options>] <command> [<args>][PAR]"
             "Available commands:");
-    File              &file = context.outputFile();
+    TextWriter        &file = context.outputFile();
     TextTableFormatter formatter;
     formatter.addColumn(NULL, maxNameLength + 1, false);
     formatter.addColumn(NULL, 72 - maxNameLength, true);
@@ -404,17 +412,17 @@ void CommandsHelpTopic::writeHelp(const HelpWriterContext &context) const
 /*! \brief
  * Help topic wrapper for a command-line module.
  *
- * This class implements HelpTopicInterface such that it wraps a
- * CommandLineModuleInterface, allowing subcommand "help <command>"
+ * This class implements IHelpTopic such that it wraps a
+ * ICommandLineModule, allowing subcommand "help <command>"
  * to produce the help for "<command>".
  *
  * \ingroup module_commandline
  */
-class ModuleHelpTopic : public HelpTopicInterface
+class ModuleHelpTopic : public IHelpTopic
 {
     public:
         //! Constructs a help topic for a specific module.
-        ModuleHelpTopic(const CommandLineModuleInterface &module,
+        ModuleHelpTopic(const ICommandLineModule         &module,
                         const CommandLineHelpModuleImpl  &helpModule)
             : module_(module), helpModule_(helpModule)
         {
@@ -423,14 +431,14 @@ class ModuleHelpTopic : public HelpTopicInterface
         virtual const char *name() const { return module_.name(); }
         virtual const char *title() const { return NULL; }
         virtual bool hasSubTopics() const { return false; }
-        virtual const HelpTopicInterface *findSubTopic(const char * /*name*/) const
+        virtual const IHelpTopic *findSubTopic(const char * /*name*/) const
         {
             return NULL;
         }
         virtual void writeHelp(const HelpWriterContext &context) const;
 
     private:
-        const CommandLineModuleInterface &module_;
+        const ICommandLineModule         &module_;
         const CommandLineHelpModuleImpl  &helpModule_;
 
         GMX_DISALLOW_COPY_AND_ASSIGN(ModuleHelpTopic);
@@ -486,16 +494,17 @@ void initProgramLinks(HelpLinks *links, const CommandLineHelpModuleImpl &helpMod
  *
  * \ingroup module_commandline
  */
-class HelpExportReStructuredText : public HelpExportInterface
+class HelpExportReStructuredText : public IHelpExport
 {
     public:
         //! Initializes reST exporter.
-        explicit HelpExportReStructuredText(
-            const CommandLineHelpModuleImpl &helpModule);
+        HelpExportReStructuredText(
+            const CommandLineHelpModuleImpl &helpModule,
+            IFileOutputRedirector           *outputRedirector);
 
         virtual void startModuleExport();
         virtual void exportModuleHelp(
-            const CommandLineModuleInterface &module,
+            const ICommandLineModule         &module,
             const std::string                &tag,
             const std::string                &displayName);
         virtual void finishModuleExport();
@@ -505,25 +514,26 @@ class HelpExportReStructuredText : public HelpExportInterface
                                        const ModuleGroupContents &modules);
         virtual void finishModuleGroupExport();
 
-        virtual void exportTopic(const HelpTopicInterface &topic);
+        virtual void exportTopic(const IHelpTopic &topic);
 
     private:
-        FileOutputRedirectorInterface  *outputRedirector_;
+        IFileOutputRedirector          *outputRedirector_;
         const std::string              &binaryName_;
         HelpLinks                       links_;
-        boost::scoped_ptr<File>         indexFile_;
-        boost::scoped_ptr<File>         manPagesFile_;
+        boost::scoped_ptr<TextWriter>   indexFile_;
+        boost::scoped_ptr<TextWriter>   manPagesFile_;
 };
 
 HelpExportReStructuredText::HelpExportReStructuredText(
-        const CommandLineHelpModuleImpl &helpModule)
-    : outputRedirector_(helpModule.outputRedirector_),
+        const CommandLineHelpModuleImpl &helpModule,
+        IFileOutputRedirector           *outputRedirector)
+    : outputRedirector_(outputRedirector),
       binaryName_(helpModule.binaryName_),
       links_(eHelpOutputFormat_Rst)
 {
-    File             linksFile("links.dat", "r");
-    std::string      line;
-    while (linksFile.readLine(&line))
+    TextReader   linksFile("links.dat");
+    std::string  line;
+    while (linksFile.readLineTrimmed(&line))
     {
         links_.addLink("[REF]." + line + "[ref]",
                        formatString(":ref:`.%s <%s>`", line.c_str(), line.c_str()),
@@ -537,47 +547,49 @@ HelpExportReStructuredText::HelpExportReStructuredText(
 void HelpExportReStructuredText::startModuleExport()
 {
     indexFile_.reset(
-            new File(outputRedirector_->openFileForWriting("fragments/byname.rst")));
+            new TextWriter(
+                    outputRedirector_->openTextOutputFile("fragments/byname.rst")));
     indexFile_->writeLine(formatString("* :doc:`%s </onlinehelp/%s>` - %s",
                                        binaryName_.c_str(), binaryName_.c_str(),
                                        RootHelpText::title));
     manPagesFile_.reset(
-            new File(outputRedirector_->openFileForWriting("conf-man.py")));
+            new TextWriter(
+                    outputRedirector_->openTextOutputFile("conf-man.py")));
     manPagesFile_->writeLine("man_pages = [");
 }
 
 void HelpExportReStructuredText::exportModuleHelp(
-        const CommandLineModuleInterface &module,
+        const ICommandLineModule         &module,
         const std::string                &tag,
         const std::string                &displayName)
 {
-    // TODO: Ideally, the file would only be touched if it really changes.
-    // This would make Sphinx reruns much faster.
-    File file(outputRedirector_->openFileForWriting("onlinehelp/" + tag + ".rst"));
-    file.writeLine(formatString(".. _%s:", displayName.c_str()));
+    TextOutputStreamPointer file
+        = outputRedirector_->openTextOutputFile("onlinehelp/" + tag + ".rst");
+    TextWriter              writer(file);
+    writer.writeLine(formatString(".. _%s:", displayName.c_str()));
     if (0 == displayName.compare(binaryName_ + " mdrun"))
     {
         // Make an extra link target for the convenience of
         // MPI-specific documentation
-        file.writeLine(".. _mdrun_mpi:");
+        writer.writeLine(".. _mdrun_mpi:");
     }
-    file.writeLine();
+    writer.writeLine();
 
-    CommandLineHelpContext context(&file, eHelpOutputFormat_Rst, &links_, binaryName_);
+    CommandLineHelpContext context(file.get(), eHelpOutputFormat_Rst, &links_, binaryName_);
     context.enterSubSection(displayName);
     context.setModuleDisplayName(displayName);
     module.writeHelp(context);
 
-    file.writeLine();
-    file.writeLine(".. only:: man");
-    file.writeLine();
-    file.writeLine("   See also");
-    file.writeLine("   --------");
-    file.writeLine();
-    file.writeLine(formatString("   :manpage:`%s(1)`", binaryName_.c_str()));
-    file.writeLine();
-    file.writeLine("   More information about |Gromacs| is available at <http://www.gromacs.org/>.");
-    file.close();
+    writer.writeLine();
+    writer.writeLine(".. only:: man");
+    writer.writeLine();
+    writer.writeLine("   See also");
+    writer.writeLine("   --------");
+    writer.writeLine();
+    writer.writeLine(formatString("   :manpage:`%s(1)`", binaryName_.c_str()));
+    writer.writeLine();
+    writer.writeLine("   More information about |Gromacs| is available at <http://www.gromacs.org/>.");
+    file->close();
 
     indexFile_->writeLine(formatString("* :doc:`%s </onlinehelp/%s>` - %s",
                                        displayName.c_str(), tag.c_str(),
@@ -604,9 +616,11 @@ void HelpExportReStructuredText::finishModuleExport()
 void HelpExportReStructuredText::startModuleGroupExport()
 {
     indexFile_.reset(
-            new File(outputRedirector_->openFileForWriting("fragments/bytopic.rst")));
+            new TextWriter(
+                    outputRedirector_->openTextOutputFile("fragments/bytopic.rst")));
     manPagesFile_.reset(
-            new File(outputRedirector_->openFileForWriting("fragments/bytopic-man.rst")));
+            new TextWriter(
+                    outputRedirector_->openTextOutputFile("fragments/bytopic-man.rst")));
 }
 
 void HelpExportReStructuredText::exportModuleGroup(
@@ -648,14 +662,15 @@ void HelpExportReStructuredText::finishModuleGroupExport()
     manPagesFile_.reset();
 }
 
-void HelpExportReStructuredText::exportTopic(const HelpTopicInterface &topic)
+void HelpExportReStructuredText::exportTopic(const IHelpTopic &topic)
 {
-    const std::string      path("onlinehelp/" + std::string(topic.name()) + ".rst");
-    File                   file(outputRedirector_->openFileForWriting(path));
-    CommandLineHelpContext context(&file, eHelpOutputFormat_Rst, &links_,
-                                   binaryName_);
-    HelpManager            manager(topic, context.writerContext());
+    const std::string       path("onlinehelp/" + std::string(topic.name()) + ".rst");
+    TextOutputStreamPointer file(outputRedirector_->openTextOutputFile(path));
+    CommandLineHelpContext  context(file.get(), eHelpOutputFormat_Rst, &links_,
+                                    binaryName_);
+    HelpManager             manager(topic, context.writerContext());
     manager.writeCurrentTopic();
+    file->close();
 }
 
 /********************************************************************
@@ -667,7 +682,7 @@ void HelpExportReStructuredText::exportTopic(const HelpTopicInterface &topic)
  *
  * \ingroup module_commandline
  */
-class HelpExportCompletion : public HelpExportInterface
+class HelpExportCompletion : public IHelpExport
 {
     public:
         //! Initializes completion exporter.
@@ -675,7 +690,7 @@ class HelpExportCompletion : public HelpExportInterface
 
         virtual void startModuleExport();
         virtual void exportModuleHelp(
-            const CommandLineModuleInterface &module,
+            const ICommandLineModule         &module,
             const std::string                &tag,
             const std::string                &displayName);
         virtual void finishModuleExport();
@@ -685,7 +700,7 @@ class HelpExportCompletion : public HelpExportInterface
                                        const ModuleGroupContents & /*modules*/) {}
         virtual void finishModuleGroupExport() {}
 
-        virtual void exportTopic(const HelpTopicInterface & /*topic*/) {}
+        virtual void exportTopic(const IHelpTopic & /*topic*/) {}
 
     private:
         ShellCompletionWriter    bashWriter_;
@@ -704,7 +719,7 @@ void HelpExportCompletion::startModuleExport()
 }
 
 void HelpExportCompletion::exportModuleHelp(
-        const CommandLineModuleInterface &module,
+        const ICommandLineModule         &module,
         const std::string                 & /*tag*/,
         const std::string                 & /*displayName*/)
 {
@@ -733,7 +748,7 @@ void HelpExportCompletion::finishModuleExport()
  */
 
 CommandLineHelpModuleImpl::CommandLineHelpModuleImpl(
-        const ProgramContextInterface    &programContext,
+        const IProgramContext            &programContext,
         const std::string                &binaryName,
         const CommandLineModuleMap       &modules,
         const CommandLineModuleGroupList &groups)
@@ -744,7 +759,7 @@ CommandLineHelpModuleImpl::CommandLineHelpModuleImpl(
 {
 }
 
-void CommandLineHelpModuleImpl::exportHelp(HelpExportInterface *exporter)
+void CommandLineHelpModuleImpl::exportHelp(IHelpExport *exporter)
 {
     // TODO: Would be nicer to have the file names supplied by the build system
     // and/or export a list of files from here.
@@ -775,12 +790,82 @@ void CommandLineHelpModuleImpl::exportHelp(HelpExportInterface *exporter)
     rootTopic_->exportHelp(exporter);
 }
 
+namespace
+{
+
+/********************************************************************
+ * ModificationCheckingFileOutputStream
+ */
+
+class ModificationCheckingFileOutputStream : public TextOutputStream
+{
+    public:
+        ModificationCheckingFileOutputStream(
+            const char                    *path,
+            IFileOutputRedirector         *redirector)
+            : path_(path), redirector_(redirector)
+        {
+        }
+
+        virtual void write(const char *str) { contents_.write(str); }
+        virtual void close()
+        {
+            const std::string &newContents = contents_.toString();
+            // TODO: Redirect these for unit tests.
+            if (File::exists(path_))
+            {
+                const std::string originalContents_
+                    = TextReader::readFileToString(path_);
+                if (originalContents_ == newContents)
+                {
+                    return;
+                }
+            }
+            TextWriter writer(redirector_->openTextOutputFile(path_));
+            writer.writeString(newContents);
+        }
+
+    private:
+        std::string                     path_;
+        StringOutputStream              contents_;
+        IFileOutputRedirector          *redirector_;
+};
+
+/********************************************************************
+ * ModificationCheckingFileOutputRedirector
+ */
+
+class ModificationCheckingFileOutputRedirector : public IFileOutputRedirector
+{
+    public:
+        explicit ModificationCheckingFileOutputRedirector(
+            IFileOutputRedirector *redirector)
+            : redirector_(redirector)
+        {
+        }
+
+        virtual TextOutputStream &standardOutput()
+        {
+            return redirector_->standardOutput();
+        }
+        virtual TextOutputStreamPointer openTextOutputFile(const char *filename)
+        {
+            return TextOutputStreamPointer(
+                    new ModificationCheckingFileOutputStream(filename, redirector_));
+        }
+
+    private:
+        IFileOutputRedirector  *redirector_;
+};
+
+}   // namespace
+
 /********************************************************************
  * CommandLineHelpModule
  */
 
 CommandLineHelpModule::CommandLineHelpModule(
-        const ProgramContextInterface    &programContext,
+        const IProgramContext            &programContext,
         const std::string                &binaryName,
         const CommandLineModuleMap       &modules,
         const CommandLineModuleGroupList &groups)
@@ -793,7 +878,7 @@ CommandLineHelpModule::~CommandLineHelpModule()
 }
 
 HelpTopicPointer CommandLineHelpModule::createModuleHelpTopic(
-        const CommandLineModuleInterface &module) const
+        const ICommandLineModule &module) const
 {
     return HelpTopicPointer(new ModuleHelpTopic(module, *impl_));
 }
@@ -809,13 +894,13 @@ void CommandLineHelpModule::setShowHidden(bool bHidden)
 }
 
 void CommandLineHelpModule::setModuleOverride(
-        const CommandLineModuleInterface &module)
+        const ICommandLineModule &module)
 {
     impl_->moduleOverride_ = &module;
 }
 
 void CommandLineHelpModule::setOutputRedirector(
-        FileOutputRedirectorInterface *output)
+        IFileOutputRedirector *output)
 {
     impl_->outputRedirector_ = output;
 }
@@ -833,10 +918,11 @@ int CommandLineHelpModule::run(int argc, char *argv[])
     CommandLineParser(&options).parse(&argc, argv);
     if (!exportFormat.empty())
     {
-        boost::scoped_ptr<HelpExportInterface> exporter;
+        ModificationCheckingFileOutputRedirector redirector(impl_->outputRedirector_);
+        boost::scoped_ptr<IHelpExport>           exporter;
         if (exportFormat == "rst")
         {
-            exporter.reset(new HelpExportReStructuredText(*impl_));
+            exporter.reset(new HelpExportReStructuredText(*impl_, &redirector));
         }
         else if (exportFormat == "completion")
         {
@@ -850,7 +936,7 @@ int CommandLineHelpModule::run(int argc, char *argv[])
         return 0;
     }
 
-    File                  &outputFile = impl_->outputRedirector_->standardOutput();
+    TextOutputStream      &outputFile = impl_->outputRedirector_->standardOutput();
     HelpLinks              links(eHelpOutputFormat_Console);
     initProgramLinks(&links, *impl_);
     CommandLineHelpContext context(&outputFile, eHelpOutputFormat_Console, &links,
index 87214a2c0192fdef74fc7d029e34aa27cf7e868f..73cc444360a70b2e3db4e04bf1a53c2bfb1eee74 100644 (file)
@@ -43,7 +43,7 @@
 #define GMX_COMMANDLINE_CMDLINEHELPMODULE_H
 
 #include "gromacs/commandline/cmdlinemodule.h"
-#include "gromacs/onlinehelp/helptopicinterface.h"
+#include "gromacs/onlinehelp/ihelptopic.h"
 #include "gromacs/utility/classhelpers.h"
 
 #include "cmdlinemodulemanager-impl.h"
@@ -52,8 +52,8 @@ namespace gmx
 {
 
 class CommandLineHelpContext;
-class FileOutputRedirectorInterface;
-class ProgramContextInterface;
+class IFileOutputRedirector;
+class IProgramContext;
 
 class CommandLineHelpModuleImpl;
 
@@ -66,7 +66,7 @@ class CommandLineHelpModuleImpl;
  *
  * \ingroup module_commandline
  */
-class CommandLineHelpModule : public CommandLineModuleInterface
+class CommandLineHelpModule : public ICommandLineModule
 {
     public:
         /*! \brief
@@ -79,7 +79,7 @@ class CommandLineHelpModule : public CommandLineModuleInterface
          * \param[in] groups   List of module groups.
          * \throws    std::bad_alloc if out of memory.
          */
-        CommandLineHelpModule(const ProgramContextInterface    &programContext,
+        CommandLineHelpModule(const IProgramContext            &programContext,
                               const std::string                &binaryName,
                               const CommandLineModuleMap       &modules,
                               const CommandLineModuleGroupList &groups);
@@ -96,7 +96,7 @@ class CommandLineHelpModule : public CommandLineModuleInterface
          * safety in CommandLineModuleManager::addModule().
          */
         HelpTopicPointer
-        createModuleHelpTopic(const CommandLineModuleInterface &module) const;
+        createModuleHelpTopic(const ICommandLineModule &module) const;
         /*! \brief
          * Adds a top-level help topic.
          *
@@ -114,7 +114,7 @@ class CommandLineHelpModule : public CommandLineModuleInterface
          * If called, the help module directly prints the help for the given
          * module when called, skipping any other processing.
          */
-        void setModuleOverride(const CommandLineModuleInterface &module);
+        void setModuleOverride(const ICommandLineModule &module);
 
         /*! \brief
          * Sets a file redirector for writing help output.
@@ -122,7 +122,7 @@ class CommandLineHelpModule : public CommandLineModuleInterface
          * Used for unit testing; see
          * CommandLineModuleManager::setOutputRedirector() for more details.
          */
-        void setOutputRedirector(FileOutputRedirectorInterface *output);
+        void setOutputRedirector(IFileOutputRedirector *output);
 
         virtual const char *name() const { return "help"; }
         virtual const char *shortDescription() const
index addc8c8361c0e01a1c100a0d35990088cbd7cd4b..4cda5726782febd7a9ade586a22e492c48fd3b33 100644 (file)
@@ -59,8 +59,8 @@
 #include "gromacs/options/timeunitmanager.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "shellcompletions.h"
 
@@ -74,70 +74,7 @@ namespace
 //! \{
 
 /********************************************************************
- * DescriptionsFormatter
- */
-
-class DescriptionsFormatter : public OptionsVisitor
-{
-    public:
-        /*! \brief
-         * Creates a new description formatter.
-         *
-         * \param[in] context   Help context to use to write the help.
-         */
-        explicit DescriptionsFormatter(const HelpWriterContext &context)
-            : context_(context), title_(NULL), bDidOutput_(false)
-        {
-        }
-
-        //! Formats all section descriptions from a given options.
-        void format(const Options &options, const char *title)
-        {
-            title_      = title;
-            bDidOutput_ = false;
-            visitSubSection(options);
-            if (bDidOutput_)
-            {
-                context_.outputFile().writeLine();
-            }
-        }
-
-        //! Formats the description for a single subsection and handles recursion.
-        virtual void visitSubSection(const Options &section);
-        // This method is not used and never called.
-        virtual void visitOption(const OptionInfo & /*option*/) {}
-
-    private:
-        const HelpWriterContext &context_;
-        const char              *title_;
-        bool                     bDidOutput_;
-
-        GMX_DISALLOW_COPY_AND_ASSIGN(DescriptionsFormatter);
-};
-
-void DescriptionsFormatter::visitSubSection(const Options &section)
-{
-    if (!section.description().empty())
-    {
-        if (bDidOutput_)
-        {
-            context_.outputFile().writeLine();
-        }
-        else if (title_ != NULL)
-        {
-            context_.writeTitle(title_);
-        }
-        // TODO: Print title for the section?
-        context_.writeTextBlock(section.description());
-        bDidOutput_ = true;
-    }
-
-    OptionsIterator iterator(section);
-    iterator.acceptSubSections(this);
-}
-
-/********************************************************************
- * OptionsFormatterInterface
+ * IOptionsFormatter
  */
 
 /*! \brief
@@ -145,10 +82,10 @@ void DescriptionsFormatter::visitSubSection(const Options &section)
  *
  * \see OptionsFilter
  */
-class OptionsFormatterInterface
+class IOptionsFormatter
 {
     public:
-        virtual ~OptionsFormatterInterface() {}
+        virtual ~IOptionsFormatter() {}
 
         //! Formats a single option option.
         virtual void formatOption(const OptionInfo &option) = 0;
@@ -163,7 +100,7 @@ class OptionsFormatterInterface
  *
  * Together with code in CommandLineHelpWriter::writeHelp(), this class
  * implements the common logic for writing out the help.
- * An object implementing the OptionsFormatterInterface must be provided to the
+ * An object implementing the IOptionsFormatter must be provided to the
  * constructor, and does the actual formatting that is specific to the output
  * format.
  */
@@ -198,14 +135,14 @@ class OptionsFilter : public OptionsVisitor
 
         //! Formats selected options using the formatter.
         void formatSelected(FilterType                 type,
-                            OptionsFormatterInterface *formatter,
+                            IOptionsFormatter         *formatter,
                             const Options             &options);
 
         virtual void visitSubSection(const Options &section);
         virtual void visitOption(const OptionInfo &option);
 
     private:
-        OptionsFormatterInterface      *formatter_;
+        IOptionsFormatter              *formatter_;
         FilterType                      filterType_;
         bool                            bShowHidden_;
 
@@ -213,7 +150,7 @@ class OptionsFilter : public OptionsVisitor
 };
 
 void OptionsFilter::formatSelected(FilterType                 type,
-                                   OptionsFormatterInterface *formatter,
+                                   IOptionsFormatter         *formatter,
                                    const Options             &options)
 {
     formatter_  = formatter;
@@ -382,7 +319,7 @@ descriptionWithOptionDetails(const CommonFormatterData &common,
 /*! \brief
  * Formatter implementation for synopsis.
  */
-class SynopsisFormatter : public OptionsFormatterInterface
+class SynopsisFormatter : public IOptionsFormatter
 {
     public:
         //! Creates a helper object for formatting the synopsis.
@@ -413,7 +350,7 @@ void SynopsisFormatter::start(const char *name)
 {
     currentLength_ = std::strlen(name) + 1;
     indent_        = std::min(currentLength_, 13);
-    File &file = context_.outputFile();
+    TextWriter &file = context_.outputFile();
     switch (context_.outputFormat())
     {
         case eHelpOutputFormat_Console:
@@ -436,7 +373,7 @@ void SynopsisFormatter::start(const char *name)
 
 void SynopsisFormatter::finish()
 {
-    File &file = context_.outputFile();
+    TextWriter &file = context_.outputFile();
     file.writeLine();
     file.writeLine();
 }
@@ -456,7 +393,7 @@ void SynopsisFormatter::formatOption(const OptionInfo &option)
     }
     fullOptionText.append(bFormatted_ ? "`]" : "]");
 
-    File       &file = context_.outputFile();
+    TextWriter &file = context_.outputFile();
     currentLength_ += totalLength;
     if (currentLength_ >= lineLength_)
     {
@@ -473,7 +410,7 @@ void SynopsisFormatter::formatOption(const OptionInfo &option)
 /*! \brief
  * Formatter implementation for help export.
  */
-class OptionsListFormatter : public OptionsFormatterInterface
+class OptionsListFormatter : public IOptionsFormatter
 {
     public:
         //! Creates a helper object for formatting options.
@@ -578,17 +515,16 @@ class CommandLineHelpWriter::Impl
 
         //! Options object to use for generating help.
         const Options               &options_;
+        //! Help text.
+        std::string                  helpText_;
         //! List of bugs/knows issues.
         ConstArrayRef<const char *>  bugs_;
         //! Time unit to show in descriptions.
         std::string                  timeUnit_;
-        //! Whether to write descriptions to output.
-        bool                         bShowDescriptions_;
 };
 
 CommandLineHelpWriter::Impl::Impl(const Options &options)
-    : options_(options), timeUnit_(TimeUnitManager().timeUnitAsString()),
-      bShowDescriptions_(false)
+    : options_(options), timeUnit_(TimeUnitManager().timeUnitAsString())
 {
 }
 
@@ -622,16 +558,23 @@ CommandLineHelpWriter::~CommandLineHelpWriter()
 }
 
 CommandLineHelpWriter &
-CommandLineHelpWriter::setShowDescriptions(bool bSet)
+CommandLineHelpWriter::setTimeUnitString(const char *timeUnit)
 {
-    impl_->bShowDescriptions_ = bSet;
+    impl_->timeUnit_ = timeUnit;
     return *this;
 }
 
 CommandLineHelpWriter &
-CommandLineHelpWriter::setTimeUnitString(const char *timeUnit)
+CommandLineHelpWriter::setHelpText(const std::string &help)
 {
-    impl_->timeUnit_ = timeUnit;
+    impl_->helpText_ = help;
+    return *this;
+}
+
+CommandLineHelpWriter &
+CommandLineHelpWriter::setHelpText(const ConstArrayRef<const char *> &help)
+{
+    impl_->helpText_ = joinStrings(help, "\n");
     return *this;
 }
 
@@ -669,10 +612,11 @@ void CommandLineHelpWriter::writeHelp(const CommandLineHelpContext &context)
         synopsisFormatter.finish();
     }
 
-    if (impl_->bShowDescriptions_)
+    if (!impl_->helpText_.empty())
     {
-        DescriptionsFormatter descriptionFormatter(writerContext);
-        descriptionFormatter.format(impl_->options_, "Description");
+        writerContext.writeTitle("Description");
+        writerContext.writeTextBlock(impl_->helpText_);
+        writerContext.outputFile().writeLine();
     }
     CommonFormatterData    common(impl_->timeUnit_.c_str());
     OptionsListFormatter   formatter(writerContext, common, "Options");
index 04fff38c9c7ae09fd20de267232513bbd1ec2b67..93725fa3c86c5361ad5cc21ffc84766669063288 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,6 +43,8 @@
 #ifndef GMX_COMMANDLINE_CMDLINEHELPWRITER_H
 #define GMX_COMMANDLINE_CMDLINEHELPWRITER_H
 
+#include <string>
+
 #include "gromacs/utility/classhelpers.h"
 
 namespace gmx
@@ -54,7 +56,7 @@ class Options;
 template <typename T> class ConstArrayRef;
 
 /*! \brief
- * Writes help information for Options in ascii format.
+ * Writes help information for Options.
  *
  * \inpublicapi
  * \ingroup module_commandline
@@ -70,10 +72,6 @@ class CommandLineHelpWriter
         explicit CommandLineHelpWriter(const Options &options);
         ~CommandLineHelpWriter();
 
-        /*! \brief
-         * Sets whether long descriptions for sections are shown in the help.
-         */
-        CommandLineHelpWriter &setShowDescriptions(bool bShow);
         /*! \brief
          * Sets time unit to show in descriptions.
          *
@@ -85,7 +83,20 @@ class CommandLineHelpWriter
          * If not called, uses a default "ps".
          */
         CommandLineHelpWriter &setTimeUnitString(const char *timeUnit);
-
+        /*! \brief
+         * Sets the help text to print as description.
+         *
+         * \param[in] help  Help text to show.
+         * \throws    std::bad_alloc if out of memory.
+         *
+         * If `help` is empty, or this method is not called, only a list of
+         * options is printed.
+         * Formatting for the help text is described on \ref page_onlinehelp.
+         */
+        CommandLineHelpWriter &setHelpText(const std::string &help);
+        //! \copydoc setHelpText(const std::string &)
+        CommandLineHelpWriter &
+        setHelpText(const ConstArrayRef<const char *> &help);
         /*! \brief
          * Sets the list of known bugs/limitations.
          *
index 49786a1033c78dce1cce4dda3b3fc1120311ca5d..6652cbdd35dc2befa243b23308ff52ac9f5d102c 100644 (file)
@@ -158,16 +158,16 @@ int processExceptionAtExitForCommandLine(const std::exception &ex)
 }
 
 int runCommandLineModule(int argc, char *argv[],
-                         CommandLineModuleInterface *module)
+                         ICommandLineModule *module)
 {
     return CommandLineModuleManager::runAsMainSingleModule(argc, argv, module);
 }
 
 int runCommandLineModule(int argc, char *argv[],
                          const char *name, const char *description,
-                         CommandLineOptionsModuleInterface *(*factory)())
+                         ICommandLineOptionsModule *(*factory)())
 {
-    return CommandLineOptionsModuleInterface::runAsMain(
+    return ICommandLineOptionsModule::runAsMain(
             argc, argv, name, description, factory);
 }
 
index e1fb961a358216638e5efb43201a4f160d9d80d9..f285e0b71013aeaa6bf00c6085327c705ad89cfd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -52,8 +52,8 @@
 namespace gmx
 {
 
-class CommandLineModuleInterface;
-class CommandLineOptionsModuleInterface;
+class ICommandLineModule;
+class ICommandLineOptionsModule;
 
 /*! \brief
  * Initializes the \Gromacs library for command-line use.
@@ -137,7 +137,7 @@ int processExceptionAtExitForCommandLine(const std::exception &ex);
  * Does not throw.  All exceptions are caught and handled internally.
  */
 int runCommandLineModule(int argc, char *argv[],
-                         CommandLineModuleInterface *module);
+                         ICommandLineModule *module);
 /*! \brief
  * Implements a main() method that runs a single module.
  *
@@ -154,12 +154,12 @@ int runCommandLineModule(int argc, char *argv[],
  *
  * Usage:
  * \code
-   class CustomCommandLineOptionsModule : public CommandLineOptionsModuleInterface
+   class CustomCommandLineOptionsModule : public ICommandLineOptionsModule
    {
        // <...>
    };
 
-   static CommandLineOptionsModuleInterface *create()
+   static ICommandLineOptionsModule *create()
    {
        return new CustomCommandLineOptionsModule();
    }
@@ -175,7 +175,7 @@ int runCommandLineModule(int argc, char *argv[],
  */
 int runCommandLineModule(int argc, char *argv[],
                          const char *name, const char *description,
-                         CommandLineOptionsModuleInterface *(*factory)());
+                         ICommandLineOptionsModule *(*factory)());
 
 } // namespace gmx
 
index f4252f1a1aa9e6c8b4266d48c737e2acdab62e52..fd230241d96f5efbb662dff91d88614acc48d7d9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -34,7 +34,7 @@
  */
 /*! \file
  * \brief
- * Declares gmx::CommandLineModuleInterface and supporting classes.
+ * Declares gmx::ICommandLineModule and supporting classes.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inpublicapi
@@ -90,10 +90,10 @@ class CommandLineModuleSettings
  * \inpublicapi
  * \ingroup module_commandline
  */
-class CommandLineModuleInterface
+class ICommandLineModule
 {
     public:
-        virtual ~CommandLineModuleInterface() {}
+        virtual ~ICommandLineModule() {}
 
         //! Returns the name of the module.
         virtual const char *name() const = 0;
@@ -137,7 +137,7 @@ class CommandLineModuleInterface
 
 //! \cond libapi
 /*! \libinternal \brief
- * Helper to implement CommandLineModuleInterface::writeHelp() with a C-like
+ * Helper to implement ICommandLineModule::writeHelp() with a C-like
  * main() function that calls parse_common_args().
  *
  * \param[in] context      Context object for writing the help.
index 95766c0ae7da004862729a90d99bfe21b6a7e1bf..a9fa6a0ad4455e4feae5b38338726e029cc60b82 100644 (file)
@@ -82,10 +82,10 @@ namespace
  */
 
 /*! \brief
- * Implements a CommandLineModuleInterface, given a function with C/C++ main()
+ * Implements a ICommandLineModule, given a function with C/C++ main()
  * signature.
  */
-class CMainCommandLineModule : public CommandLineModuleInterface
+class CMainCommandLineModule : public ICommandLineModule
 {
     public:
         //! \copydoc gmx::CommandLineModuleManager::CMainFunction
@@ -263,7 +263,7 @@ class CommandLineModuleManager::Impl
          * options).  Also finds the module that should be run and the
          * arguments that should be passed to it.
          */
-        CommandLineModuleInterface *
+        ICommandLineModule *
         processCommonOptions(CommandLineCommonOptionsHolder *optionsHolder,
                              int *argc, char ***argv);
 
@@ -292,7 +292,7 @@ class CommandLineModuleManager::Impl
          */
         CommandLineHelpModule       *helpModule_;
         //! If non-NULL, run this module in single-module mode.
-        CommandLineModuleInterface  *singleModule_;
+        ICommandLineModule          *singleModule_;
         //! Stores the value set with setQuiet().
         bool                         bQuiet_;
 
@@ -339,12 +339,12 @@ CommandLineModuleManager::Impl::findModuleByName(const std::string &name) const
     return modules_.find(name);
 }
 
-CommandLineModuleInterface *
+ICommandLineModule *
 CommandLineModuleManager::Impl::processCommonOptions(
         CommandLineCommonOptionsHolder *optionsHolder, int *argc, char ***argv)
 {
     // Check if we are directly invoking a certain module.
-    CommandLineModuleInterface *module = singleModule_;
+    ICommandLineModule *module = singleModule_;
 
     // TODO: It would be nice to propagate at least the -quiet option to
     // the modules so that they can also be quiet in response to this.
@@ -437,13 +437,13 @@ void CommandLineModuleManager::setQuiet(bool bQuiet)
 }
 
 void CommandLineModuleManager::setOutputRedirector(
-        FileOutputRedirectorInterface *output)
+        IFileOutputRedirector *output)
 {
     impl_->ensureHelpModuleExists();
     impl_->helpModule_->setOutputRedirector(output);
 }
 
-void CommandLineModuleManager::setSingleModule(CommandLineModuleInterface *module)
+void CommandLineModuleManager::setSingleModule(ICommandLineModule *module)
 {
     impl_->singleModule_ = module;
 }
@@ -480,7 +480,7 @@ void CommandLineModuleManager::addHelpTopic(HelpTopicPointer topic)
 
 int CommandLineModuleManager::run(int argc, char *argv[])
 {
-    CommandLineModuleInterface    *module;
+    ICommandLineModule            *module;
     const bool                     bMaster = (gmx_node_rank() == 0);
     bool                           bQuiet  = impl_->bQuiet_ || !bMaster;
     CommandLineCommonOptionsHolder optionsHolder;
@@ -562,7 +562,7 @@ int CommandLineModuleManager::run(int argc, char *argv[])
 
 // static
 int CommandLineModuleManager::runAsMainSingleModule(
-        int argc, char *argv[], CommandLineModuleInterface *module)
+        int argc, char *argv[], ICommandLineModule *module)
 {
     CommandLineProgramContext &programContext = gmx::initForCommandLine(&argc, &argv);
     try
index 4214ab1f1b6ff592908c748c0955bfb303ff0289..5271d242f76832b83d255eeedbb8f0097eea1056 100644 (file)
@@ -43,7 +43,7 @@
 #ifndef GMX_COMMANDLINE_CMDLINEMODULEMANAGER_H
 #define GMX_COMMANDLINE_CMDLINEMODULEMANAGER_H
 
-#include "gromacs/onlinehelp/helptopicinterface.h"
+#include "gromacs/onlinehelp/ihelptopic.h"
 #include "gromacs/utility/classhelpers.h"
 #include "gromacs/utility/uniqueptr.h"
 
@@ -52,15 +52,15 @@ namespace gmx
 
 class CommandLineModuleGroup;
 class CommandLineModuleGroupData;
-class CommandLineModuleInterface;
 class CommandLineProgramContext;
-class FileOutputRedirectorInterface;
+class ICommandLineModule;
+class IFileOutputRedirector;
 
 //! \addtogroup module_commandline
 //! \{
 
-//! Smart pointer type for managing a CommandLineModuleInterface.
-typedef gmx_unique_ptr<CommandLineModuleInterface>::type
+//! Smart pointer type for managing a ICommandLineModule.
+typedef gmx_unique_ptr<ICommandLineModule>::type
     CommandLineModulePointer;
 
 /*! \libinternal \brief
@@ -127,7 +127,7 @@ class CommandLineModuleManager
          * Does not throw.  All exceptions are caught and handled internally.
          */
         static int runAsMainSingleModule(int argc, char *argv[],
-                                         CommandLineModuleInterface *module);
+                                         ICommandLineModule *module);
         /*! \brief
          * Implements a main() method that runs a given function.
          *
@@ -206,7 +206,7 @@ class CommandLineModuleManager
          * For tests, there should only be need to call this a single time,
          * right after creating the manager.
          */
-        void setOutputRedirector(FileOutputRedirectorInterface *output);
+        void setOutputRedirector(IFileOutputRedirector *output);
 
         /*! \brief
          * Makes the manager always run a single module.
@@ -217,7 +217,7 @@ class CommandLineModuleManager
          * directly passes all command-line arguments to \p module.
          * Help arguments are an exception: these are still recognized by the
          * manager and translated into a call to
-         * CommandLineModuleInterface::writeHelp().
+         * ICommandLineModule::writeHelp().
          *
          * This is public mainly for unit testing purposes; for other code,
          * runAsMainSingleModule() typically provides the desired
@@ -225,7 +225,7 @@ class CommandLineModuleManager
          *
          * Does not throw.
          */
-        void setSingleModule(CommandLineModuleInterface *module);
+        void setSingleModule(ICommandLineModule *module);
         /*! \brief
          * Adds a given module to this manager.
          *
@@ -266,7 +266,7 @@ class CommandLineModuleManager
          * \throws  std::bad_alloc if out of memory.
          *
          * \p Module must be default-constructible and implement
-         * CommandLineModuleInterface.
+         * ICommandLineModule.
          *
          * This method is provided as a convenient alternative to addModule()
          * for cases where each module is implemented by a different type
index a0cb556813a2f037fdc27945644160e94c89a829..e8249492e8cb8ceb851101cb60818f28f484eb31 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \internal \file
  * \brief
- * Implements supporting routines for gmx::CommandLineOptionsModuleInterface.
+ * Implements supporting routines for gmx::ICommandLineOptionsModule.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_commandline
@@ -50,7 +50,9 @@
 #include "gromacs/commandline/cmdlineparser.h"
 #include "gromacs/options/filenameoptionmanager.h"
 #include "gromacs/options/options.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/stringutil.h"
 
 namespace gmx
 {
@@ -58,15 +60,33 @@ namespace gmx
 namespace
 {
 
+/********************************************************************
+ * CommandLineOptionsModuleSettings
+ */
+
+class CommandLineOptionsModuleSettings : public ICommandLineOptionsModuleSettings
+{
+    public:
+        const std::string &helpText() const { return helpText_; }
+
+        virtual void setHelpText(const ConstArrayRef<const char *> &help)
+        {
+            helpText_ = joinStrings(help, "\n");
+        }
+
+    private:
+        std::string helpText_;
+};
+
 /********************************************************************
  * CommandLineOptionsModule
  */
 
-class CommandLineOptionsModule : public CommandLineModuleInterface
+class CommandLineOptionsModule : public ICommandLineModule
 {
     public:
         //! Shorthand for the factory function pointer type.
-        typedef CommandLineOptionsModuleInterface::FactoryMethod FactoryMethod;
+        typedef ICommandLineOptionsModule::FactoryMethod FactoryMethod;
 
         CommandLineOptionsModule(const char *name, const char *description,
                                  FactoryMethod factory)
@@ -74,7 +94,7 @@ class CommandLineOptionsModule : public CommandLineModuleInterface
         {
         }
         CommandLineOptionsModule(const char *name, const char *description,
-                                 CommandLineOptionsModuleInterface *module)
+                                 ICommandLineOptionsModule *module)
             : name_(name), description_(description), factory_(NULL),
               module_(module)
         {
@@ -92,7 +112,7 @@ class CommandLineOptionsModule : public CommandLineModuleInterface
         const char    *name_;
         const char    *description_;
         FactoryMethod  factory_;
-        boost::scoped_ptr<CommandLineOptionsModuleInterface> module_;
+        boost::scoped_ptr<ICommandLineOptionsModule> module_;
 };
 
 void CommandLineOptionsModule::init(CommandLineModuleSettings *settings)
@@ -114,18 +134,19 @@ int CommandLineOptionsModule::run(int argc, char *argv[])
 
 void CommandLineOptionsModule::writeHelp(const CommandLineHelpContext &context) const
 {
-    boost::scoped_ptr<CommandLineOptionsModuleInterface> moduleGuard;
-    CommandLineOptionsModuleInterface                   *module = module_.get();
+    boost::scoped_ptr<ICommandLineOptionsModule> moduleGuard;
+    ICommandLineOptionsModule                   *module = module_.get();
     if (!module)
     {
         GMX_RELEASE_ASSERT(factory_ != NULL, "Neither factory nor module provided");
         moduleGuard.reset(factory_());
         module = moduleGuard.get();
     }
-    Options options(name(), shortDescription());
-    module->initOptions(&options);
+    Options                          options(name(), shortDescription());
+    CommandLineOptionsModuleSettings settings;
+    module->initOptions(&options, &settings);
     CommandLineHelpWriter(options)
-        .setShowDescriptions(true)
+        .setHelpText(settings.helpText())
         .writeHelp(context);
 }
 
@@ -136,7 +157,8 @@ void CommandLineOptionsModule::parseOptions(int argc, char *argv[])
 
     options.addManager(&fileoptManager);
 
-    module_->initOptions(&options);
+    CommandLineOptionsModuleSettings settings;
+    module_->initOptions(&options, &settings);
     {
         CommandLineParser parser(&options);
         parser.parse(&argc, argv);
@@ -148,23 +170,31 @@ void CommandLineOptionsModule::parseOptions(int argc, char *argv[])
 }   // namespace
 
 /********************************************************************
- * CommandLineOptionsModuleInterface
+ * ICommandLineOptionsModuleSettings
+ */
+
+ICommandLineOptionsModuleSettings::~ICommandLineOptionsModuleSettings()
+{
+}
+
+/********************************************************************
+ * ICommandLineOptionsModule
  */
 
-CommandLineOptionsModuleInterface::~CommandLineOptionsModuleInterface()
+ICommandLineOptionsModule::~ICommandLineOptionsModule()
 {
 }
 
 // static
-CommandLineModuleInterface *
-CommandLineOptionsModuleInterface::createModule(
+ICommandLineModule *
+ICommandLineOptionsModule::createModule(
         const char *name, const char *description, FactoryMethod factory)
 {
     return new CommandLineOptionsModule(name, description, factory);
 }
 
 // static
-int CommandLineOptionsModuleInterface::runAsMain(
+int ICommandLineOptionsModule::runAsMain(
         int argc, char *argv[], const char *name, const char *description,
         FactoryMethod factory)
 {
@@ -173,7 +203,7 @@ int CommandLineOptionsModuleInterface::runAsMain(
 }
 
 // static
-void CommandLineOptionsModuleInterface::registerModule(
+void ICommandLineOptionsModule::registerModule(
         CommandLineModuleManager *manager, const char *name,
         const char *description, FactoryMethod factory)
 {
@@ -182,9 +212,9 @@ void CommandLineOptionsModuleInterface::registerModule(
 }
 
 // static
-void CommandLineOptionsModuleInterface::registerModule(
+void ICommandLineOptionsModule::registerModule(
         CommandLineModuleManager *manager, const char *name,
-        const char *description, CommandLineOptionsModuleInterface *module)
+        const char *description, ICommandLineOptionsModule *module)
 {
     CommandLineModulePointer wrapperModule(
             new CommandLineOptionsModule(name, description, module));
index f44022fb081ed8ce30b411e5b5c6e6918585b475..ae7c004d013224c76fd80c6f2e724de2b46849cf 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \file
  * \brief
- * Declares gmx::CommandLineOptionsModuleInterface and supporting routines.
+ * Declares gmx::ICommandLineOptionsModule and supporting routines.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inpublicapi
 namespace gmx
 {
 
-class CommandLineModuleInterface;
+template <typename T> class ConstArrayRef;
+
 class CommandLineModuleManager;
+class ICommandLineModule;
 class Options;
 
+/*! \brief
+ * Settings to pass information between a CommandLineOptionsModule and generic
+ * code that runs it.
+ *
+ * \inpublicapi
+ * \ingroup module_commandline
+ */
+class ICommandLineOptionsModuleSettings
+{
+    public:
+        /*! \brief
+         * Sets the help text for the module from string array.
+         *
+         * \param[in] help  String array to set as the description.
+         * \throws    std::bad_alloc if out of memory.
+         *
+         * Formatting for the help text is described on \ref page_onlinehelp.
+         *
+         * Example usage:
+         * \code
+           const char *const desc[] = {
+               "This is the description",
+               "for the options"
+           };
+
+           settings->setHelpText(desc);
+           \endcode
+         */
+        virtual void setHelpText(const ConstArrayRef<const char *> &help) = 0;
+
+    protected:
+        // Disallow deletion through the interface.
+        // (no need for the virtual, but some compilers warn otherwise)
+        virtual ~ICommandLineOptionsModuleSettings();
+};
+
 /*! \brief
  * Module that can be run from a command line and uses gmx::Options for
  * argument processing.
  *
  * This class provides a higher-level interface on top of
- * gmx::CommandLineModuleInterface for cases where gmx::Options will be used
+ * gmx::ICommandLineModule for cases where gmx::Options will be used
  * for declaring the command-line arguments.  The module only needs to declare
  * the options it uses, and the framework takes care of command-line parsing
  * and help output.  The module typically consists of the following parts:
  *  - init() allows for some interaction between the module and the framework
- *    when running the module; see CommandLineModuleInterface::init().  If no
+ *    when running the module; see ICommandLineModule::init().  If no
  *    such customization is necessary, an empty implementation is sufficient.
  *  - initOptions() is called both for running the module and for printing help
  *    for the module, and it should add the options that the module
@@ -75,8 +113,8 @@ class Options;
  *    variables.
  *
  * registerModule(), runAsMain(), or createModule() can be used to use modules
- * of this type in all contexts where a gmx::CommandLineModuleInterface is
- * expected.  These methods create a gmx::CommandLineModuleInterface
+ * of this type in all contexts where a gmx::ICommandLineModule is
+ * expected.  These methods create a gmx::ICommandLineModule
  * implementation that contains the common code needed to parse command-line
  * options and write help, based on the information provided from the methods
  * in this class.
@@ -84,7 +122,7 @@ class Options;
  * \inpublicapi
  * \ingroup module_commandline
  */
-class CommandLineOptionsModuleInterface
+class ICommandLineOptionsModule
 {
     public:
         /*! \brief
@@ -96,22 +134,22 @@ class CommandLineOptionsModuleInterface
          *
          * The caller takes responsibility to `delete` the returned pointer.
          */
-        typedef CommandLineOptionsModuleInterface *(*FactoryMethod)();
+        typedef ICommandLineOptionsModule *(*FactoryMethod)();
 
         /*! \brief
-         * Creates a CommandLineModuleInterface to run the specified module.
+         * Creates a ICommandLineModule to run the specified module.
          *
          * \param[in] name        Name for the module.
          * \param[in] description Short description for the module.
          * \param[in] factory     Factory that returns the module to run.
-         * \returns CommandLineModuleInterface object that runs the module
+         * \returns ICommandLineModule object that runs the module
          *     returned by \p factory.  Caller must `delete` the object.
          * \throws  std::bad_alloc if out of memory.
          *
          * This is mainly used by tests that want to bypass
          * CommandLineModuleManager.
          */
-        static CommandLineModuleInterface *
+        static ICommandLineModule *
         createModule(const char *name, const char *description,
                      FactoryMethod factory);
         /*! \brief
@@ -142,7 +180,7 @@ class CommandLineOptionsModuleInterface
          * \param[in] factory     Factory that returns the module to register.
          * \throws  std::bad_alloc if out of memory.
          *
-         * This method internally creates a CommandLineModuleInterface module
+         * This method internally creates a ICommandLineModule module
          * with the given \p name and \p description, and adds that to
          * \p manager.  When run or asked to write the help, the module calls
          * \p factory to get the actual module, and forwards the necessary
@@ -162,26 +200,28 @@ class CommandLineOptionsModuleInterface
          *     The method takes ownership (must have been allocated with `new`).
          * \throws  std::bad_alloc if out of memory.
          *
-         * This method internally creates a CommandLineModuleInterface module
+         * This method internally creates a ICommandLineModule module
          * with the given \p name and \p description, and adds that to
          * \p manager.
          *
          * This method is mainly used by tests that need to have a reference to
-         * the CommandLineOptionsModuleInterface instance (e.g., for mocking).
+         * the ICommandLineOptionsModule instance (e.g., for mocking).
          */
         static void
         registerModule(CommandLineModuleManager *manager,
                        const char *name, const char *description,
-                       CommandLineOptionsModuleInterface *module);
+                       ICommandLineOptionsModule *module);
 
-        virtual ~CommandLineOptionsModuleInterface();
+        virtual ~ICommandLineOptionsModule();
 
-        //! \copydoc gmx::CommandLineModuleInterface::init()
+        //! \copydoc gmx::ICommandLineModule::init()
         virtual void init(CommandLineModuleSettings *settings) = 0;
         /*! \brief
          * Initializes command-line arguments understood by the module.
          *
          * \param[in,out] options  Options object to add the options to.
+         * \param[in,out] settings Settings to communicate information
+         *     to/from generic code running the module.
          *
          * When running the module, this method is called after init().
          * When printing help, there is no call to init(), and this is the only
@@ -190,7 +230,8 @@ class CommandLineOptionsModuleInterface
          * the module to \p options.  Output values from options should be
          * stored in member variables.
          */
-        virtual void initOptions(Options *options)             = 0;
+        virtual void initOptions(Options                           *options,
+                                 ICommandLineOptionsModuleSettings *settings) = 0;
         /*! \brief
          * Called after all option values have been set.
          *
@@ -203,7 +244,7 @@ class CommandLineOptionsModuleInterface
          * If the module needs to call, e.g., Options::isSet(), this is the
          * place to do that.
          */
-        virtual void optionsFinished(Options *options)         = 0;
+        virtual void optionsFinished(Options *options) = 0;
 
         /*! \brief
          * Runs the module.
index 5d98a4ae5166157bc29e6c54046e06ac6405d461..c06b58ac185a40c845836f09bb6f6264aa0793d1 100644 (file)
 
 #include <boost/scoped_ptr.hpp>
 
-#include "thread_mpi/mutex.h"
-
 #include "buildinfo.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/mutex.h"
 #include "gromacs/utility/path.h"
 #include "gromacs/utility/stringutil.h"
 
@@ -88,12 +86,12 @@ std::string quoteIfNecessary(const char *str)
 }
 
 /*! \brief
- * Default implementation for ExecutableEnvironmentInterface.
+ * Default implementation for IExecutableEnvironment.
  *
- * Used if ExecutableEnvironmentInterface is not explicitly provided when
+ * Used if IExecutableEnvironment is not explicitly provided when
  * constructing CommandLineProgramContext.
  */
-class DefaultExecutableEnvironment : public ExecutableEnvironmentInterface
+class DefaultExecutableEnvironment : public IExecutableEnvironment
 {
     public:
         //! Allocates a default environment.
@@ -130,8 +128,8 @@ class DefaultExecutableEnvironment : public ExecutableEnvironmentInterface
  * If a binary with the given name cannot be located, \p invokedName is
  * returned.
  */
-std::string findFullBinaryPath(const std::string                    &invokedName,
-                               const ExecutableEnvironmentInterface &env)
+std::string findFullBinaryPath(const std::string            &invokedName,
+                               const IExecutableEnvironment &env)
 {
     std::string searchName = invokedName;
     // On Windows & Cygwin we need to add the .exe extension,
@@ -322,7 +320,7 @@ class CommandLineProgramContext::Impl
         mutable std::string           fullBinaryPath_;
         mutable std::string           installationPrefix_;
         mutable bool                  bSourceLayout_;
-        mutable tMPI::mutex           binaryPathMutex_;
+        mutable Mutex                 binaryPathMutex_;
 };
 
 CommandLineProgramContext::Impl::Impl()
@@ -415,14 +413,14 @@ const char *CommandLineProgramContext::commandLine() const
 
 const char *CommandLineProgramContext::fullBinaryPath() const
 {
-    tMPI::lock_guard<tMPI::mutex> lock(impl_->binaryPathMutex_);
+    lock_guard<Mutex> lock(impl_->binaryPathMutex_);
     impl_->findBinaryPath();
     return impl_->fullBinaryPath_.c_str();
 }
 
 InstallationPrefixInfo CommandLineProgramContext::installationPrefix() const
 {
-    tMPI::lock_guard<tMPI::mutex> lock(impl_->binaryPathMutex_);
+    lock_guard<Mutex> lock(impl_->binaryPathMutex_);
     if (impl_->installationPrefix_.empty())
     {
         impl_->findBinaryPath();
index e08f3508958a9eb234680abd8f2c2e61ccba1734..11c237cd48daacbf6360f09beefdc9a90de89c0f 100644 (file)
@@ -72,10 +72,10 @@ namespace gmx
  *
  * \inlibraryapi
  */
-class ExecutableEnvironmentInterface
+class IExecutableEnvironment
 {
     public:
-        virtual ~ExecutableEnvironmentInterface() {}
+        virtual ~IExecutableEnvironment() {}
 
         /*! \brief
          * Returns the working directory when the program was launched.
@@ -90,8 +90,8 @@ class ExecutableEnvironmentInterface
         virtual std::vector<std::string> getExecutablePaths() const = 0;
 };
 
-//! Shorthand for a smart pointer to ExecutableEnvironmentInterface.
-typedef boost::shared_ptr<ExecutableEnvironmentInterface>
+//! Shorthand for a smart pointer to IExecutableEnvironment.
+typedef boost::shared_ptr<IExecutableEnvironment>
     ExecutableEnvironmentPointer;
 
 /*! \libinternal \brief
@@ -109,7 +109,7 @@ typedef boost::shared_ptr<ExecutableEnvironmentInterface>
  *
  * \inlibraryapi
  */
-class CommandLineProgramContext : public ProgramContextInterface
+class CommandLineProgramContext : public IProgramContext
 {
     public:
         /*! \brief
@@ -143,13 +143,13 @@ class CommandLineProgramContext : public ProgramContextInterface
          * \param[in] env   Customizes the way the binary name is handled.
          *
          * This overload allows one to customize the way the binary is located
-         * by providing a custom ExecutableEnvironmentInterface implementation.
+         * by providing a custom IExecutableEnvironment implementation.
          * This is mainly useful for testing purposes to make it possible to
          * test different paths without setting environment variables, changing
          * the working directory or doing other process-wide operations.
          * It may also be useful for making Gromacs behave better when linked
          * into a non-Gromacs executable (with possible extensions in
-         * ExecutableEnvironmentInterface).
+         * IExecutableEnvironment).
          */
         CommandLineProgramContext(int argc, const char *const argv[],
                                   ExecutableEnvironmentPointer env);
index 95af8735b70a94fec10328ef034c646b157e41d4..6daf7d554bceab34c6c1c401424a4ec44d5e4b85 100644 (file)
@@ -498,7 +498,6 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
         fileOptManager.disableInputOptionChecking(
                 FF(PCA_NOT_READ_NODE) || FF(PCA_DISABLE_INPUT_FILE_CHECKING));
         options.addManager(&fileOptManager);
-        options.setDescription(gmx::constArrayRefFromArray<const char *>(desc, ndesc));
 
         if (FF(PCA_CAN_SET_DEFFNM))
         {
@@ -567,7 +566,7 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
                                "Help output should be handled higher up and "
                                "only get called only on the master rank");
             gmx::CommandLineHelpWriter(options)
-                .setShowDescriptions(true)
+                .setHelpText(gmx::constArrayRefFromArray<const char *>(desc, ndesc))
                 .setTimeUnitString(timeUnitManager.timeUnitAsString())
                 .setKnownIssues(gmx::constArrayRefFromArray(bugs, nbugs))
                 .writeHelp(*context);
index ce9f08a71779219b18ce4cb5a4786e91d9b17339..520ff469092dfc79a25b7095c878ff35b6aaed9f 100644 (file)
@@ -59,9 +59,9 @@
 #include "gromacs/options/optionsvisitor.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 namespace gmx
 {
@@ -107,7 +107,7 @@ class OptionsListWriter : public OptionsVisitor
 class OptionCompletionWriter : public OptionsVisitor
 {
     public:
-        explicit OptionCompletionWriter(File *out) : out_(*out) {}
+        explicit OptionCompletionWriter(TextWriter *out) : out_(*out) {}
 
         virtual void visitSubSection(const Options &section)
         {
@@ -121,7 +121,7 @@ class OptionCompletionWriter : public OptionsVisitor
         void writeOptionCompletion(const OptionInfo  &option,
                                    const std::string &completion);
 
-        File &out_;
+        TextWriter &out_;
 };
 
 void OptionCompletionWriter::visitOption(const OptionInfo &option)
@@ -196,8 +196,8 @@ class ShellCompletionWriter::Impl
             return formatString("_%s_%s_compl", binaryName_.c_str(), moduleName);
         }
 
-        std::string             binaryName_;
-        boost::scoped_ptr<File> file_;
+        std::string                   binaryName_;
+        boost::scoped_ptr<TextWriter> file_;
 };
 
 ShellCompletionWriter::ShellCompletionWriter(const std::string     &binaryName,
@@ -210,21 +210,21 @@ ShellCompletionWriter::~ShellCompletionWriter()
 {
 }
 
-File *ShellCompletionWriter::outputFile()
+TextOutputStream &ShellCompletionWriter::outputStream()
 {
-    return impl_->file_.get();
+    return impl_->file_->stream();
 }
 
 void ShellCompletionWriter::startCompletions()
 {
-    impl_->file_.reset(new File(impl_->binaryName_ + "-completion.bash", "w"));
+    impl_->file_.reset(new TextWriter(impl_->binaryName_ + "-completion.bash"));
 }
 
 void ShellCompletionWriter::writeModuleCompletions(
         const char    *moduleName,
         const Options &options)
 {
-    File &out = *impl_->file_;
+    TextWriter &out = *impl_->file_;
     out.writeLine(formatString("%s() {", impl_->completionFunctionName(moduleName).c_str()));
     out.writeLine("local IFS=$'\\n'");
     out.writeLine("local c=${COMP_WORDS[COMP_CWORD]}");
index 88435475436e8a4951eaf6e893ebbfccb4f3b15b..f8f11906b6c09f3690baaa3eaf5ebd52c81397b1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -53,8 +53,8 @@ namespace gmx
 {
 
 class CommandLineHelpContext;
-class File;
 class Options;
+class TextOutputStream;
 
 //! \cond internal
 //! \addtogroup module_commandline
@@ -78,7 +78,7 @@ class ShellCompletionWriter
                               ShellCompletionFormat  format);
         ~ShellCompletionWriter();
 
-        File *outputFile();
+        TextOutputStream &outputStream();
 
         void startCompletions();
         void writeModuleCompletions(const char    *moduleName,
index b8cb8eae28e2bc4e658bebe3925ffdc61571a8e6..ba62e55e0393cc399472320a3b5e68b214008497 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/commandline/cmdlinemodulemanager.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/options.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "gromacs/onlinehelp/tests/mock_helptopic.h"
 #include "testutils/cmdlinetest.h"
@@ -74,14 +74,13 @@ TEST_F(CommandLineHelpModuleTest, PrintsGeneralHelp)
     };
     CommandLine       args(cmdline);
     initManager(args, "test");
-    redirectManagerOutput();
     addModule("module", "First module");
     addModule("other", "Second module");
     addHelpTopic("topic", "Test topic");
     int rc = 0;
     ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
     ASSERT_EQ(0, rc);
-    checkRedirectedOutputFiles();
+    checkRedirectedOutput();
 }
 
 TEST_F(CommandLineHelpModuleTest, PrintsHelpOnTopic)
@@ -91,7 +90,6 @@ TEST_F(CommandLineHelpModuleTest, PrintsHelpOnTopic)
     };
     CommandLine       args(cmdline);
     initManager(args, "test");
-    redirectManagerOutput();
     addModule("module", "First module");
     MockHelpTopic &topic = addHelpTopic("topic", "Test topic");
     topic.addSubTopic("sub1", "Subtopic 1", "");
@@ -101,7 +99,7 @@ TEST_F(CommandLineHelpModuleTest, PrintsHelpOnTopic)
     int rc = 0;
     ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
     ASSERT_EQ(0, rc);
-    checkRedirectedOutputFiles();
+    checkRedirectedOutput();
 }
 
 /*! \brief
@@ -109,13 +107,14 @@ TEST_F(CommandLineHelpModuleTest, PrintsHelpOnTopic)
  *
  * \ingroup module_commandline
  */
-void initOptionsBasic(gmx::Options *options)
+void initOptionsBasic(gmx::Options                           *options,
+                      gmx::ICommandLineOptionsModuleSettings *settings)
 {
     const char *const desc[] = {
         "Sample description",
         "for testing [THISMODULE]."
     };
-    options->setDescription(desc);
+    settings->setHelpText(desc);
     options->addOption(gmx::IntegerOption("int"));
 }
 
@@ -125,10 +124,9 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp)
         "test", "help", "-export", "rst"
     };
     // TODO: Find a more elegant solution, or get rid of the links.dat altogether.
-    gmx::File::writeFileFromString("links.dat", "");
-    CommandLine       args(cmdline);
+    gmx::TextWriter::writeFileFromString("links.dat", "");
+    CommandLine        args(cmdline);
     initManager(args, "test");
-    redirectManagerOutput();
     MockOptionsModule &mod1 = addOptionsModule("module", "First module");
     MockOptionsModule &mod2 = addOptionsModule("other", "Second module");
     {
@@ -146,8 +144,8 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp)
     MockHelpTopic &topic2 = addHelpTopic("topic2", "Another topic");
     using ::testing::_;
     using ::testing::Invoke;
-    EXPECT_CALL(mod1, initOptions(_)).WillOnce(Invoke(&initOptionsBasic));
-    EXPECT_CALL(mod2, initOptions(_));
+    EXPECT_CALL(mod1, initOptions(_, _)).WillOnce(Invoke(&initOptionsBasic));
+    EXPECT_CALL(mod2, initOptions(_, _));
     EXPECT_CALL(topic1, writeHelp(_));
     EXPECT_CALL(sub1, writeHelp(_));
     EXPECT_CALL(sub2, writeHelp(_));
@@ -156,7 +154,7 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp)
     int rc = 0;
     ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
     ASSERT_EQ(0, rc);
-    checkRedirectedOutputFiles();
+    checkRedirectedOutput();
     std::remove("links.dat");
 }
 
index 317cc4c9ab8c5dec62e564fb9c3278bd85c7a0a8..886b0b0d18f8f95168d2b8cdb6d0a294c2eda5db 100644 (file)
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/filenameoption.h"
 #include "gromacs/options/options.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/stringstream.h"
 
 #include "testutils/stringtest.h"
-#include "testutils/testfilemanager.h"
 
 namespace
 {
@@ -71,21 +71,19 @@ class CommandLineHelpWriterTest : public ::gmx::test::StringTestBase
 
         void checkHelp(gmx::CommandLineHelpWriter *writer);
 
-        gmx::test::TestFileManager tempFiles_;
         bool                       bHidden_;
 };
 
 void CommandLineHelpWriterTest::checkHelp(gmx::CommandLineHelpWriter *writer)
 {
-    std::string                 filename = tempFiles_.getTemporaryFilePath("helptext.txt");
-    gmx::File                   file(filename, "w");
-    gmx::CommandLineHelpContext context(&file, gmx::eHelpOutputFormat_Console,
+    gmx::StringOutputStream     stream;
+    gmx::CommandLineHelpContext context(&stream, gmx::eHelpOutputFormat_Console,
                                         NULL, "test");
     context.setShowHidden(bHidden_);
     writer->writeHelp(context);
-    file.close();
+    stream.close();
 
-    checkFileContents(filename, "HelpText");
+    checkText(stream.toString(), "HelpText");
 }
 
 
@@ -249,32 +247,22 @@ TEST_F(CommandLineHelpWriterTest, HandlesSelectionOptions)
 #endif
 
 /*
- * Tests help printing for multiple sections.
+ * Tests help output using a help text.
  */
-TEST_F(CommandLineHelpWriterTest, HandlesMultipleSections)
+TEST_F(CommandLineHelpWriterTest, HandlesHelpText)
 {
-    using namespace gmx;
+    const char *const help[] = {
+        "Help text",
+        "for testing."
+    };
+    using gmx::IntegerOption;
 
-    Options options("test", "Main Title");
-    Options subSect1("subsect1", "Subsection 1 Title");
-    Options subSect2("subsect2", "Subsection 2 Title");
-    Options subSect3("subsect3", NULL);
-    options.addSubSection(&subSect1);
-    options.addSubSection(&subSect2);
-    options.addSubSection(&subSect3);
-    options.setDescription("Description for main section.");
-    subSect1.setDescription("Description for subsection 1.");
-    subSect2.setDescription("Description for subsection 2.");
-    subSect3.setDescription("Description for subsection 3.");
-    options.addOption(IntegerOption("main")
-                          .description("Option in main section"));
-    subSect1.addOption(IntegerOption("sub1")
-                           .description("Option in subsection 1"));
-    subSect2.addOption(IntegerOption("sub2")
-                           .description("Option in subsection 2"));
+    gmx::Options options(NULL, NULL);
+    options.addOption(IntegerOption("int").description("Integer option")
+                          .defaultValue(2));
 
-    CommandLineHelpWriter writer(options);
-    writer.setShowDescriptions(true);
+    gmx::CommandLineHelpWriter writer(options);
+    writer.setHelpText(help);
     checkHelp(&writer);
 }
 
index f85cabe057ec0cabe853a08aa1c26f97c32a4843..e5c92f77e36eda90cc47473d184ada3808a3698b 100644 (file)
@@ -56,7 +56,7 @@
 
 #include "gromacs/onlinehelp/tests/mock_helptopic.h"
 #include "testutils/cmdlinetest.h"
-#include "testutils/testfilemanager.h"
+#include "testutils/testfileredirector.h"
 
 namespace gmx
 {
@@ -131,9 +131,9 @@ MockOptionsModule::~MockOptionsModule()
 class CommandLineModuleManagerTestBase::Impl
 {
     public:
+        TestFileOutputRedirector                     redirector_;
         boost::scoped_ptr<CommandLineProgramContext> programContext_;
         boost::scoped_ptr<CommandLineModuleManager>  manager_;
-        TestFileManager                              fileManager_;
 };
 
 CommandLineModuleManagerTestBase::CommandLineModuleManagerTestBase()
@@ -154,6 +154,7 @@ void CommandLineModuleManagerTestBase::initManager(
     impl_->manager_.reset(new gmx::CommandLineModuleManager(
                                   realBinaryName, impl_->programContext_.get()));
     impl_->manager_->setQuiet(true);
+    impl_->manager_->setOutputRedirector(&impl_->redirector_);
 }
 
 MockModule &
@@ -168,7 +169,7 @@ MockOptionsModule &
 CommandLineModuleManagerTestBase::addOptionsModule(const char *name, const char *description)
 {
     MockOptionsModule *module = new MockOptionsModule();
-    gmx::CommandLineOptionsModuleInterface::registerModule(
+    gmx::ICommandLineOptionsModule::registerModule(
             &manager(), name, description, module);
     return *module;
 }
@@ -186,9 +187,9 @@ CommandLineModuleManager &CommandLineModuleManagerTestBase::manager()
     return *impl_->manager_;
 }
 
-void CommandLineModuleManagerTestBase::redirectManagerOutput()
+void CommandLineModuleManagerTestBase::checkRedirectedOutput()
 {
-    impl_->manager_->setOutputRedirector(&initOutputRedirector(&impl_->fileManager_));
+    impl_->redirector_.checkRedirectedFiles(&checker());
 }
 
 } // namespace test
index c156561606b01a59fecd095c6c88743e23042bdc..deb27ddb3a50325d1ec50b6e92aefc575c49f41d 100644 (file)
@@ -60,13 +60,14 @@ namespace test
 
 class CommandLine;
 class MockHelpTopic;
+class TestFileOutputRedirector;
 
 /*! \internal \brief
- * Mock implementation of gmx::CommandLineModuleInterface.
+ * Mock implementation of gmx::ICommandLineModule.
  *
  * \ingroup module_commandline
  */
-class MockModule : public gmx::CommandLineModuleInterface
+class MockModule : public gmx::ICommandLineModule
 {
     public:
         //! Creates a mock module with the given name and description.
@@ -96,18 +97,18 @@ class MockModule : public gmx::CommandLineModuleInterface
 };
 
 /*! \internal \brief
- * Mock implementation of gmx::CommandLineOptionsModuleInterface.
+ * Mock implementation of gmx::ICommandLineOptionsModule.
  *
  * \ingroup module_commandline
  */
-class MockOptionsModule : public gmx::CommandLineOptionsModuleInterface
+class MockOptionsModule : public gmx::ICommandLineOptionsModule
 {
     public:
         MockOptionsModule();
         ~MockOptionsModule();
 
         MOCK_METHOD1(init, void(gmx::CommandLineModuleSettings *settings));
-        MOCK_METHOD1(initOptions, void(gmx::Options *options));
+        MOCK_METHOD2(initOptions, void(gmx::Options *options, gmx::ICommandLineOptionsModuleSettings *settings));
         MOCK_METHOD1(optionsFinished, void(gmx::Options *options));
         MOCK_METHOD0(run, int());
 };
@@ -140,16 +141,14 @@ class CommandLineModuleManagerTestBase : public gmx::test::StringTestBase
         CommandLineModuleManager &manager();
 
         /*! \brief
-         * Redirects all manager output to files.
+         * Checks all output from the manager using reference data.
          *
-         * Can be used to silence tests that would otherwise print out
-         * something, and/or checkRedirectedFileContents() from the base class
-         * can be used to check the output.
+         * Both output to `stdout` and to files is checked.
          *
          * The manager is put into quiet mode by default, so the manager will
          * only print out information if, e.g., help is explicitly requested.
          */
-        void redirectManagerOutput();
+        void checkRedirectedOutput();
 
     private:
         class Impl;
index 3ffdad11aac93099da69399dd704e0c975c8a87b..7f2048933aaa371a1d65902dede95221ae54fae8 100644 (file)
@@ -73,7 +73,7 @@ using gmx::Path;
 namespace
 {
 
-class TestExecutableEnvironment : public gmx::ExecutableEnvironmentInterface
+class TestExecutableEnvironment : public gmx::IExecutableEnvironment
 {
     public:
         TestExecutableEnvironment()
index d74f12f9877b437e37aa97e6dc8a13f98449ba0d..53ea895be10a4677c24204753d5ce2837f869932 100644 (file)
@@ -51,9 +51,9 @@
 #include <gtest/gtest.h>
 
 #include "gromacs/utility/arrayref.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/path.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "testutils/cmdlinetest.h"
 #include "testutils/testasserts.h"
@@ -108,7 +108,7 @@ class ParseCommonArgsTest : public ::testing::Test
                                FileArgumentType type)
         {
             std::string filename(tempFiles_.getTemporaryFilePath(extension));
-            gmx::File::writeFileFromString(filename, "Dummy file");
+            gmx::TextWriter::writeFileFromString(filename, "Dummy file");
             if (name != NULL)
             {
                 args_.append(name);
index 40c8fb826d058692cc38007f8acca1a4a5decf11..df3572fa4125dcb88d65cbd597b8251af100708e 100644 (file)
@@ -1,20 +1,6 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
 <ReferenceData>
-  <String Name="fragments/byname.rst"><![CDATA[
-* :doc:`test </onlinehelp/test>` - molecular dynamics simulation suite
-* :doc:`test help </onlinehelp/test-help>` - Print help information
-* :doc:`test module </onlinehelp/test-module>` - First module
-* :doc:`test other </onlinehelp/test-other>` - Second module
-]]></String>
-  <String Name="conf-man.py"><![CDATA[
-man_pages = [
-    ('onlinehelp/test-help', 'test-help', "Print help information", '', 1),
-    ('onlinehelp/test-module', 'test-module', "First module", '', 1),
-    ('onlinehelp/test-other', 'test-other', "Second module", '', 1),
-    ('onlinehelp/test', 'test', 'molecular dynamics simulation suite', '', 1)
-]
-]]></String>
   <String Name="onlinehelp/test-help.rst"><![CDATA[
 .. _test help:
 
@@ -83,6 +69,20 @@ Synopsis
    :manpage:`test(1)`
 
    More information about |Gromacs| is available at <http://www.gromacs.org/>.
+]]></String>
+  <String Name="fragments/byname.rst"><![CDATA[
+* :doc:`test </onlinehelp/test>` - molecular dynamics simulation suite
+* :doc:`test help </onlinehelp/test-help>` - Print help information
+* :doc:`test module </onlinehelp/test-module>` - First module
+* :doc:`test other </onlinehelp/test-other>` - Second module
+]]></String>
+  <String Name="conf-man.py"><![CDATA[
+man_pages = [
+    ('onlinehelp/test-help', 'test-help', "Print help information", '', 1),
+    ('onlinehelp/test-module', 'test-module', "First module", '', 1),
+    ('onlinehelp/test-other', 'test-other', "Second module", '', 1),
+    ('onlinehelp/test', 'test', 'molecular dynamics simulation suite', '', 1)
+]
 ]]></String>
   <String Name="fragments/bytopic.rst"><![CDATA[
 Group 1
diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml
new file mode 100644 (file)
index 0000000..5ecad2b
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="HelpText"><![CDATA[
+SYNOPSIS
+
+gmx [-int <int>]
+
+DESCRIPTION
+
+Help text for testing.
+
+OPTIONS
+
+Other options:
+
+ -int    <int>              (2)
+           Integer option
+
+]]></String>
+</ReferenceData>
diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml
deleted file mode 100644 (file)
index baa4db0..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
-<ReferenceData>
-  <String Name="HelpText"><![CDATA[
-SYNOPSIS
-
-gmx [-sub1 <int>] [-sub2 <int>] [-main <int>]
-
-DESCRIPTION
-
-Description for main section.
-
-Description for subsection 1.
-
-Description for subsection 2.
-
-Description for subsection 3.
-
-OPTIONS
-
-Other options:
-
- -sub1   <int>
-           Option in subsection 1
- -sub2   <int>
-           Option in subsection 2
- -main   <int>
-           Option in main section
-
-]]></String>
-</ReferenceData>
index 6c6718af5d6b8c522d1604bc3c1624408645bda7..88d3bd88b34f1705d6599700052bdebb7f3ac058 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-file(GLOB GMXCORRFUNC_SOURCES *.c *.cpp)
+file(GLOB GMXCORRFUNC_SOURCES *.cpp)
 file(GLOB LMFIT_SOURCES ${CMAKE_SOURCE_DIR}/src/external/lmfit/*.c)
 
 set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${GMXCORRFUNC_SOURCES}  ${LMFIT_SOURCES} PARENT_SCOPE)
similarity index 97%
rename from src/gromacs/correlationfunctions/autocorr.c
rename to src/gromacs/correlationfunctions/autocorr.cpp
index 72966978ce38d0a90f5fef87c4e35d1f6ffbcf61..7cdf48d57796f5b184fa53249d04a480e270e6ea 100644 (file)
 
 #include "autocorr.h"
 
-#include <math.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/correlationfunctions/expfit.h"
 #include "gromacs/correlationfunctions/integrate.h"
 #include "gromacs/correlationfunctions/manyautocorrelation.h"
@@ -87,16 +90,12 @@ static void low_do_four_core(int nfour, int nframes, real c1[], real cfour[],
                              int nCos)
 {
     int  i = 0;
-    int  fftcode;
-    real aver, *ans;
 
-    aver = 0.0;
     switch (nCos)
     {
         case enNorm:
             for (i = 0; (i < nframes); i++)
             {
-                aver    += c1[i];
                 cfour[i] = c1[i];
             }
             break;
@@ -116,7 +115,7 @@ static void low_do_four_core(int nfour, int nframes, real c1[], real cfour[],
             gmx_fatal(FARGS, "nCos = %d, %s %d", nCos, __FILE__, __LINE__);
     }
 
-    fftcode = many_auto_correl(1, nframes, nfour, &cfour);
+    many_auto_correl(1, nframes, nfour, &cfour);
 }
 
 /*! \brief Routine to comput ACF without FFT. */
@@ -577,8 +576,8 @@ void low_do_autocorr(const char *fn, const output_env_t oenv, const char *title,
     }
     if (bFour)
     {
-        c0 = log((double)nframes)/log(2.0);
-        k  = c0;
+        c0 = std::log(static_cast<double>(nframes))/std::log(2.0);
+        k  = static_cast<int>(c0);
         if (k < c0)
         {
             k++;
@@ -606,10 +605,9 @@ void low_do_autocorr(const char *fn, const output_env_t oenv, const char *title,
      * In this loop the actual correlation functions are computed, but without
      * normalizing them.
      */
-    k = max(1, pow(10, (int)(log(nitem)/log(100))));
-    for (i = 0; i < nitem; i++)
+    for (int i = 0; i < nitem; i++)
     {
-        if (bVerbose && ((i%k == 0 || i == nitem-1)))
+        if (bVerbose && (((i % 100) == 0) || (i == nitem-1)))
         {
             fprintf(stderr, "\rThingie %d", i+1);
         }
@@ -660,10 +658,10 @@ void low_do_autocorr(const char *fn, const output_env_t oenv, const char *title,
         else
         {
             sum = print_and_integrate(fp, nout, dt, c1[0], NULL, 1);
-            if (bVerbose)
-            {
-                printf("Correlation time (integral over corrfn): %g (ps)\n", sum);
-            }
+        }
+        if (bVerbose)
+        {
+            printf("Correlation time (integral over corrfn): %g (ps)\n", sum);
         }
     }
     else
similarity index 98%
rename from src/gromacs/correlationfunctions/crosscorr.c
rename to src/gromacs/correlationfunctions/crosscorr.cpp
index 1911b5b41e176ab0e7e6f67db618efc1e6227c9a..b588bd8f86ad5cec0dd657293f236a1bf8ed0f2f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index 3b201bf2c9798f6a88f3504c8b46190f55aeb3c1..0cc2c148ca0c4be282309d61af26e755e9966d8f 100644 (file)
@@ -862,14 +862,6 @@ real fit_acf(int ncorr, int fitfn, const output_env_t oenv, gmx_bool bVerbose,
     nf_int = std::min(ncorr, (int)(tendfit/dt));
     sum    = print_and_integrate(debug, nf_int, dt, c1, NULL, 1);
 
-    /* Estimate the correlation time for better fitting */
-    ct_estimate = 0.5*c1[0];
-    for (i = 1; (i < ncorr) && (c1[i] > 0); i++)
-    {
-        ct_estimate += c1[i];
-    }
-    ct_estimate *= dt/c1[0];
-
     if (bPrint)
     {
         printf("COR: Correlation time (plain integral from %6.3f to %6.3f ps) = %8.5f ps\n",
similarity index 98%
rename from src/gromacs/correlationfunctions/integrate.c
rename to src/gromacs/correlationfunctions/integrate.cpp
index dc0a7ae0834ee8f834576fe8459b2e447c19b076..d58c5add9d8ba5d2f6d322242450493fedce526d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
similarity index 89%
rename from src/gromacs/correlationfunctions/manyautocorrelation.c
rename to src/gromacs/correlationfunctions/manyautocorrelation.cpp
index c4fb7db465c5716f7d5a32ac7e21759cea165f85..8474c867a35ace234da337d420bee75d393805c8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "manyautocorrelation.h"
 
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/fft/fft.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/utility/gmxomp.h"
@@ -57,7 +60,7 @@ int many_auto_correl(int nfunc, int ndata, int nfft, real **c)
     #pragma omp parallel
     {
         typedef real complex[2];
-        int          i, t, j, fftcode;
+        int          i, j;
         gmx_fft_t    fft1;
         complex     *in, *out;
         int          i0, i1;
@@ -70,9 +73,9 @@ int many_auto_correl(int nfunc, int ndata, int nfft, real **c)
             // fprintf(stderr, "There are %d threads for correlation functions\n", nthreads);
         }
         i0 = thread_id*nfunc/nthreads;
-        i1 = min(nfunc, (thread_id+1)*nfunc/nthreads);
+        i1 = std::min(nfunc, (thread_id+1)*nfunc/nthreads);
 
-        fftcode = gmx_fft_init_1d(&fft1, nfft, GMX_FFT_FLAG_CONSERVATIVE);
+        gmx_fft_init_1d(&fft1, nfft, GMX_FFT_FLAG_CONSERVATIVE);
         /* Allocate temporary arrays */
         snew(in, nfft);
         snew(out, nfft);
@@ -88,7 +91,7 @@ int many_auto_correl(int nfunc, int ndata, int nfft, real **c)
                 in[j][0] = in[j][1] = 0;
             }
 
-            fftcode = gmx_fft_1d(fft1, GMX_FFT_BACKWARD, (void *)in, (void *)out);
+            gmx_fft_1d(fft1, GMX_FFT_BACKWARD, (void *)in, (void *)out);
             for (j = 0; j < nfft; j++)
             {
                 in[j][0] = (out[j][0]*out[j][0] + out[j][1]*out[j][1])/nfft;
@@ -99,7 +102,7 @@ int many_auto_correl(int nfunc, int ndata, int nfft, real **c)
                 in[j][0] = in[j][1] = 0;
             }
 
-            fftcode = gmx_fft_1d(fft1, GMX_FFT_FORWARD, (void *)in, (void *)out);
+            gmx_fft_1d(fft1, GMX_FFT_FORWARD, (void *)in, (void *)out);
             for (j = 0; (j < nfft); j++)
             {
                 c[i][j] = out[j][0]/ndata;
similarity index 97%
rename from src/gromacs/correlationfunctions/polynomials.c
rename to src/gromacs/correlationfunctions/polynomials.cpp
index c5f499a17daf50f92fbd1b2a13d3db484427c02c..18765ab1ff7f8c37c3daee3c9a685cf892314b09 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index 2d8a81e17b58b2df9c82c4429eb7e1bbc966842f..9ead1601ff498473d61d36b4d0f1c8f097db2b95 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 1991-2003 Erik Lindahl, David van der Spoel, University of Groningen.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -53,7 +53,7 @@
  * files like fft_fftw3.c or fft_mkl.c for that.
  */
 
-#ifndef GMX_FFT_FFTW3
+#if !GMX_FFT_FFTW3
 
 struct gmx_many_fft {
     int       howmany;
index 5cd3dfae97cc6cdab74c4c113b4f5e62e636a22a..4982dfbf59656ca99206740cbd802e1255bb187b 100644 (file)
 FILE* debug = 0;
 #endif
 
-#ifdef GMX_FFT_FFTW3
-#include "thread_mpi/mutex.h"
+#if GMX_FFT_FFTW3
 
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/mutex.h"
 /* none of the fftw3 calls, except execute(), are thread-safe, so
    we need to serialize them with this mutex. */
-static tMPI::mutex big_fftw_mutex;
+static gmx::Mutex big_fftw_mutex;
 #define FFTW_LOCK try { big_fftw_mutex.lock(); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
 #define FFTW_UNLOCK try { big_fftw_mutex.unlock(); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
 #endif /* GMX_FFT_FFTW3 */
@@ -452,7 +452,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_
         fprintf(debug, "Running on %d threads\n", nthreads);
     }
 
-#ifdef GMX_FFT_FFTW3
+#if GMX_FFT_FFTW3
     /* Don't add more stuff here! We have already had at least one bug because we are reimplementing
      * the low-level FFT interface instead of using the Gromacs FFT module. If we need more
      * generic functionality it is far better to extend the interface so we can use it for
@@ -614,7 +614,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_
         }
     }
 
-#ifdef GMX_FFT_FFTW3
+#if GMX_FFT_FFTW3
 }
 #endif
     if ((flags&FFT5D_ORDER_YZ))   /*plan->cart is in the order of transposes */
@@ -985,7 +985,7 @@ void fft5d_execute(fft5d_plan plan, int thread, fft5d_time times)
     int    s = 0, tstart, tend, bParallelDim;
 
 
-#ifdef GMX_FFT_FFTW3
+#if GMX_FFT_FFTW3
     if (plan->p3d)
     {
         if (thread == 0)
@@ -1277,7 +1277,7 @@ void fft5d_destroy(fft5d_plan plan)
             plan->oNout[s] = 0;
         }
     }
-#ifdef GMX_FFT_FFTW3
+#if GMX_FFT_FFTW3
     FFTW_LOCK;
 #ifdef FFT5D_MPI_TRANSPOS
     for (s = 0; s < 2; s++)
index ba6753d473e453058e79caa75be20ce7f8fd537c..ceb87ddc89cea61c3b76ef960162eede02218e3d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -53,7 +53,7 @@ double MPI_Wtime();
 #endif
 
 /*currently only special optimization for FFTE*/
-#ifdef GMX_FFT_FFTW3
+#if GMX_FFT_FFTW3
 #include <fftw3.h>
 #endif
 
@@ -93,7 +93,7 @@ struct fft5d_plan_t {
     t_complex *lin;
     t_complex *lout, *lout2, *lout3;
     gmx_fft_t* p1d[3]; /*1D plans*/
-#ifdef GMX_FFT_FFTW3
+#if GMX_FFT_FFTW3
     FFTW(plan) p2d;    /*2D plan: used for 1D decomposition if FFT supports transposed output*/
     FFTW(plan) p3d;    /*3D plan: used for 0D decomposition if FFT supports transposed output*/
     FFTW(plan) mpip[2];
index dee2ff284b473c41aa250438cbde4f824cf9dd53..891a7ee2d9b4bb0e093dfa061d3326512a7d8c27 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 1991-2003 David van der Spoel, Erik Lindahl, University of Groningen.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include <fftw3.h>
 
-#include "thread_mpi/mutex.h"
-
 #include "gromacs/fft/fft.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/mutex.h"
 
 #ifdef GMX_DOUBLE
 #define FFTWPREFIX(name) fftw_ ## name
@@ -56,7 +55,7 @@
 
 /* none of the fftw3 calls, except execute(), are thread-safe, so
    we need to serialize them with this mutex. */
-static tMPI::mutex big_fftw_mutex;
+static gmx::Mutex big_fftw_mutex;
 #define FFTW_LOCK try { big_fftw_mutex.lock(); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
 #define FFTW_UNLOCK try { big_fftw_mutex.unlock(); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
 
@@ -115,7 +114,7 @@ gmx_fft_init_many_1d(gmx_fft_t *        pfft,
     int                    i, j, k;
     int                    fftw_flags;
 
-#ifdef GMX_DISABLE_FFTW_MEASURE
+#if GMX_DISABLE_FFTW_MEASURE
     flags |= GMX_FFT_FLAG_CONSERVATIVE;
 #endif
 
@@ -232,7 +231,7 @@ gmx_fft_init_many_1d_real(gmx_fft_t *        pfft,
     int                    i, j, k;
     int                    fftw_flags;
 
-#ifdef GMX_DISABLE_FFTW_MEASURE
+#if GMX_DISABLE_FFTW_MEASURE
     flags |= GMX_FFT_FLAG_CONSERVATIVE;
 #endif
 
@@ -343,7 +342,7 @@ gmx_fft_init_2d_real(gmx_fft_t *        pfft,
     int                    i, j, k;
     int                    fftw_flags;
 
-#ifdef GMX_DISABLE_FFTW_MEASURE
+#if GMX_DISABLE_FFTW_MEASURE
     flags |= GMX_FFT_FLAG_CONSERVATIVE;
 #endif
 
index 0c638a78a8b7e026bb47f96b48ff3bca28d3bd9b..c3a4552954d9a0b4f4e0e1c6d425c4bbf9569cc3 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2013,2014, by the GROMACS development team, led by
+# Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -53,7 +53,7 @@ gmx_install_headers(
     pdbio.h
     tpxio.h
     trajectory_writing.h
-    trnio.h
+    trrio.h
     trx.h
     trxio.h
     xdr_datatype.h
diff --git a/src/gromacs/fileio/confio.c b/src/gromacs/fileio/confio.c
deleted file mode 100644 (file)
index c8a35d7..0000000
+++ /dev/null
@@ -1,1713 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include "confio.h"
-
-#include <errno.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trx.h"
-#include "gromacs/fileio/trxio.h"
-#include "gromacs/fileio/xdrf.h"
-#include "gromacs/legacyheaders/copyrite.h"
-#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/math/vec.h"
-#include "gromacs/pbcutil/pbc.h"
-#include "gromacs/topology/mtop_util.h"
-#include "gromacs/topology/symtab.h"
-#include "gromacs/topology/topology.h"
-#include "gromacs/utility/cstringutil.h"
-#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/futil.h"
-#include "gromacs/utility/smalloc.h"
-
-#define CHAR_SHIFT 24
-
-static int read_g96_pos(char line[], t_symtab *symtab,
-                        FILE *fp, const char *infile,
-                        t_trxframe *fr)
-{
-    t_atoms   *atoms;
-    gmx_bool   bEnd;
-    int        nwanted, natoms, atnr, resnr = 0, oldres, newres, shift;
-    char       anm[STRLEN], resnm[STRLEN];
-    char       c1, c2;
-    double     db1, db2, db3;
-
-    nwanted = fr->natoms;
-
-    atoms = fr->atoms;
-
-    natoms = 0;
-
-    if (fr->bX)
-    {
-        if (fr->bAtoms)
-        {
-            shift = CHAR_SHIFT;
-        }
-        else
-        {
-            shift = 0;
-        }
-        newres  = -1;
-        oldres  = -666; /* Unlikely number for the first residue! */
-        bEnd    = FALSE;
-        while (!bEnd && fgets2(line, STRLEN, fp))
-        {
-            bEnd = (strncmp(line, "END", 3) == 0);
-            if (!bEnd  && (line[0] != '#'))
-            {
-                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
-                {
-                    gmx_fatal(FARGS, "Did not find 3 coordinates for atom %d in %s\n",
-                              natoms+1, infile);
-                }
-                if ((nwanted != -1) && (natoms >= nwanted))
-                {
-                    gmx_fatal(FARGS,
-                              "Found more coordinates (%d) in %s than expected %d\n",
-                              natoms, infile, nwanted);
-                }
-                if (atoms)
-                {
-                    if (fr->bAtoms &&
-                        (sscanf(line, "%5d%c%5s%c%5s%7d", &resnr, &c1, resnm, &c2, anm, &atnr)
-                         != 6))
-                    {
-                        if (oldres >= 0)
-                        {
-                            resnr = oldres;
-                        }
-                        else
-                        {
-                            resnr    = 1;
-                            strncpy(resnm, "???", sizeof(resnm)-1);
-                        }
-                        strncpy(anm, "???", sizeof(anm)-1);
-                    }
-                    atoms->atomname[natoms] = put_symtab(symtab, anm);
-                    if (resnr != oldres)
-                    {
-                        oldres = resnr;
-                        newres++;
-                        if (newres >= atoms->nr)
-                        {
-                            gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
-                                      infile, atoms->nr);
-                        }
-                        atoms->atom[natoms].resind = newres;
-                        if (newres+1 > atoms->nres)
-                        {
-                            atoms->nres = newres+1;
-                        }
-                        t_atoms_set_resinfo(atoms, natoms, symtab, resnm, resnr, ' ', 0, ' ');
-                    }
-                    else
-                    {
-                        atoms->atom[natoms].resind = newres;
-                    }
-                }
-                if (fr->x)
-                {
-                    fr->x[natoms][0] = db1;
-                    fr->x[natoms][1] = db2;
-                    fr->x[natoms][2] = db3;
-                }
-                natoms++;
-            }
-        }
-        if ((nwanted != -1) && natoms != nwanted)
-        {
-            fprintf(stderr,
-                    "Warning: found less coordinates (%d) in %s than expected %d\n",
-                    natoms, infile, nwanted);
-        }
-    }
-
-    fr->natoms = natoms;
-
-    return natoms;
-}
-
-static int read_g96_vel(char line[], FILE *fp, const char *infile,
-                        t_trxframe *fr)
-{
-    gmx_bool   bEnd;
-    int        nwanted, natoms = -1, shift;
-    double     db1, db2, db3;
-
-    nwanted = fr->natoms;
-
-    if (fr->v && fr->bV)
-    {
-        if (strcmp(line, "VELOCITYRED") == 0)
-        {
-            shift = 0;
-        }
-        else
-        {
-            shift = CHAR_SHIFT;
-        }
-        natoms = 0;
-        bEnd   = FALSE;
-        while (!bEnd && fgets2(line, STRLEN, fp))
-        {
-            bEnd = (strncmp(line, "END", 3) == 0);
-            if (!bEnd && (line[0] != '#'))
-            {
-                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
-                {
-                    gmx_fatal(FARGS, "Did not find 3 velocities for atom %d in %s",
-                              natoms+1, infile);
-                }
-                if ((nwanted != -1) && (natoms >= nwanted))
-                {
-                    gmx_fatal(FARGS, "Found more velocities (%d) in %s than expected %d\n",
-                              natoms, infile, nwanted);
-                }
-                if (fr->v)
-                {
-                    fr->v[natoms][0] = db1;
-                    fr->v[natoms][1] = db2;
-                    fr->v[natoms][2] = db3;
-                }
-                natoms++;
-            }
-        }
-        if ((nwanted != -1) && (natoms != nwanted))
-        {
-            fprintf(stderr,
-                    "Warning: found less velocities (%d) in %s than expected %d\n",
-                    natoms, infile, nwanted);
-        }
-    }
-
-    return natoms;
-}
-
-int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line)
-{
-    t_symtab  *symtab = NULL;
-    gmx_bool   bAtStart, bTime, bAtoms, bPos, bVel, bBox, bEnd, bFinished;
-    int        natoms, nbp;
-    double     db1, db2, db3, db4, db5, db6, db7, db8, db9;
-
-    bAtStart = (ftell(fp) == 0);
-
-    clear_trxframe(fr, FALSE);
-
-    if (!symtab)
-    {
-        snew(symtab, 1);
-        open_symtab(symtab);
-    }
-
-    natoms = 0;
-
-    if (bAtStart)
-    {
-        while (!fr->bTitle && fgets2(line, STRLEN, fp))
-        {
-            fr->bTitle = (strcmp(line, "TITLE") == 0);
-        }
-        if (fr->title == NULL)
-        {
-            fgets2(line, STRLEN, fp);
-            fr->title = gmx_strdup(line);
-        }
-        bEnd = FALSE;
-        while (!bEnd && fgets2(line, STRLEN, fp))
-        {
-            bEnd = (strcmp(line, "END") == 0);
-        }
-        fgets2(line, STRLEN, fp);
-    }
-
-    /* Do not get a line if we are not at the start of the file, *
-     * because without a parameter file we don't know what is in *
-     * the trajectory and we have already read the line in the   *
-     * previous call (VERY DIRTY).                               */
-    bFinished = FALSE;
-    do
-    {
-        bTime  = (strcmp(line, "TIMESTEP") == 0);
-        bAtoms = (strcmp(line, "POSITION") == 0);
-        bPos   = (bAtoms || (strcmp(line, "POSITIONRED") == 0));
-        bVel   = (strncmp(line, "VELOCITY", 8) == 0);
-        bBox   = (strcmp(line, "BOX") == 0);
-        if (bTime)
-        {
-            if (!fr->bTime && !fr->bX)
-            {
-                fr->bStep = bTime;
-                fr->bTime = bTime;
-                do
-                {
-                    bFinished = (fgets2(line, STRLEN, fp) == NULL);
-                }
-                while (!bFinished && (line[0] == '#'));
-                sscanf(line, "%15d%15lf", &(fr->step), &db1);
-                fr->time = db1;
-            }
-            else
-            {
-                bFinished = TRUE;
-            }
-        }
-        if (bPos)
-        {
-            if (!fr->bX)
-            {
-                fr->bAtoms = bAtoms;
-                fr->bX     = bPos;
-                natoms     = read_g96_pos(line, symtab, fp, infile, fr);
-            }
-            else
-            {
-                bFinished = TRUE;
-            }
-        }
-        if (fr->v && bVel)
-        {
-            fr->bV = bVel;
-            natoms = read_g96_vel(line, fp, infile, fr);
-        }
-        if (bBox)
-        {
-            fr->bBox = bBox;
-            clear_mat(fr->box);
-            bEnd = FALSE;
-            while (!bEnd && fgets2(line, STRLEN, fp))
-            {
-                bEnd = (strncmp(line, "END", 3) == 0);
-                if (!bEnd && (line[0] != '#'))
-                {
-                    nbp = sscanf(line, "%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf",
-                                 &db1, &db2, &db3, &db4, &db5, &db6, &db7, &db8, &db9);
-                    if (nbp < 3)
-                    {
-                        gmx_fatal(FARGS, "Found a BOX line, but no box in %s", infile);
-                    }
-                    fr->box[XX][XX] = db1;
-                    fr->box[YY][YY] = db2;
-                    fr->box[ZZ][ZZ] = db3;
-                    if (nbp == 9)
-                    {
-                        fr->box[XX][YY] = db4;
-                        fr->box[XX][ZZ] = db5;
-                        fr->box[YY][XX] = db6;
-                        fr->box[YY][ZZ] = db7;
-                        fr->box[ZZ][XX] = db8;
-                        fr->box[ZZ][YY] = db9;
-                    }
-                }
-            }
-            bFinished = TRUE;
-        }
-    }
-    while (!bFinished && fgets2(line, STRLEN, fp));
-
-    free_symtab(symtab);
-
-    fr->natoms = natoms;
-
-    return natoms;
-}
-
-void write_g96_conf(FILE *out, t_trxframe *fr,
-                    int nindex, const atom_id *index)
-{
-    t_atoms *atoms;
-    int      nout, i, a;
-
-    atoms = fr->atoms;
-
-    if (index)
-    {
-        nout = nindex;
-    }
-    else
-    {
-        nout = fr->natoms;
-    }
-
-    if (fr->bTitle)
-    {
-        fprintf(out, "TITLE\n%s\nEND\n", fr->title);
-    }
-    if (fr->bStep || fr->bTime)
-    {
-        /* Officially the time format is %15.9, which is not enough for 10 ns */
-        fprintf(out, "TIMESTEP\n%15d%15.6f\nEND\n", fr->step, fr->time);
-    }
-    if (fr->bX)
-    {
-        if (fr->bAtoms)
-        {
-            fprintf(out, "POSITION\n");
-            for (i = 0; i < nout; i++)
-            {
-                if (index)
-                {
-                    a = index[i];
-                }
-                else
-                {
-                    a = i;
-                }
-                fprintf(out, "%5d %-5s %-5s%7d%15.9f%15.9f%15.9f\n",
-                        (atoms->resinfo[atoms->atom[a].resind].nr) % 100000,
-                        *atoms->resinfo[atoms->atom[a].resind].name,
-                        *atoms->atomname[a], (i+1) % 10000000,
-                        fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
-            }
-        }
-        else
-        {
-            fprintf(out, "POSITIONRED\n");
-            for (i = 0; i < nout; i++)
-            {
-                if (index)
-                {
-                    a = index[i];
-                }
-                else
-                {
-                    a = i;
-                }
-                fprintf(out, "%15.9f%15.9f%15.9f\n",
-                        fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
-            }
-        }
-        fprintf(out, "END\n");
-    }
-    if (fr->bV)
-    {
-        if (fr->bAtoms)
-        {
-            fprintf(out, "VELOCITY\n");
-            for (i = 0; i < nout; i++)
-            {
-                if (index)
-                {
-                    a = index[i];
-                }
-                else
-                {
-                    a = i;
-                }
-                fprintf(out, "%5d %-5s %-5s%7d%15.9f%15.9f%15.9f\n",
-                        (atoms->resinfo[atoms->atom[a].resind].nr) % 100000,
-                        *atoms->resinfo[atoms->atom[a].resind].name,
-                        *atoms->atomname[a], (i+1) % 10000000,
-                        fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
-            }
-        }
-        else
-        {
-            fprintf(out, "VELOCITYRED\n");
-            for (i = 0; i < nout; i++)
-            {
-                if (index)
-                {
-                    a = index[i];
-                }
-                else
-                {
-                    a = i;
-                }
-                fprintf(out, "%15.9f%15.9f%15.9f\n",
-                        fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
-            }
-        }
-        fprintf(out, "END\n");
-    }
-    if (fr->bBox)
-    {
-        fprintf(out, "BOX\n");
-        fprintf(out, "%15.9f%15.9f%15.9f",
-                fr->box[XX][XX], fr->box[YY][YY], fr->box[ZZ][ZZ]);
-        if (fr->box[XX][YY] || fr->box[XX][ZZ] || fr->box[YY][XX] ||
-            fr->box[YY][ZZ] || fr->box[ZZ][XX] || fr->box[ZZ][YY])
-        {
-            fprintf(out, "%15.9f%15.9f%15.9f%15.9f%15.9f%15.9f",
-                    fr->box[XX][YY], fr->box[XX][ZZ], fr->box[YY][XX],
-                    fr->box[YY][ZZ], fr->box[ZZ][XX], fr->box[ZZ][YY]);
-        }
-        fprintf(out, "\n");
-        fprintf(out, "END\n");
-    }
-}
-
-static int get_espresso_word(FILE *fp, char word[])
-{
-    int  ret, nc, i;
-
-    ret = 0;
-    nc  = 0;
-
-    do
-    {
-        i = fgetc(fp);
-        if (i != EOF)
-        {
-            if (i == ' ' || i == '\n' || i == '\t')
-            {
-                if (nc > 0)
-                {
-                    ret = 1;
-                }
-            }
-            else if (i == '{')
-            {
-                if (nc == 0)
-                {
-                    word[nc++] = '{';
-                }
-                ret = 2;
-            }
-            else if (i == '}')
-            {
-                if (nc == 0)
-                {
-                    word[nc++] = '}';
-                }
-                ret = 3;
-            }
-            else
-            {
-                word[nc++] = (char)i;
-            }
-        }
-    }
-    while (i != EOF && ret == 0);
-
-    word[nc] = '\0';
-
-    /*  printf("'%s'\n",word); */
-
-    return ret;
-}
-
-static int check_open_parenthesis(FILE *fp, int r,
-                                  const char *infile, const char *keyword)
-{
-    int  level_inc;
-    char word[STRLEN];
-
-    level_inc = 0;
-    if (r == 2)
-    {
-        level_inc++;
-    }
-    else
-    {
-        r = get_espresso_word(fp, word);
-        if (r == 2)
-        {
-            level_inc++;
-        }
-        else
-        {
-            gmx_fatal(FARGS, "Expected '{' after '%s' in file '%s'",
-                      keyword, infile);
-        }
-    }
-
-    return level_inc;
-}
-
-static int check_close_parenthesis(FILE *fp, int r,
-                                   const char *infile, const char *keyword)
-{
-    int  level_inc;
-    char word[STRLEN];
-
-    level_inc = 0;
-    if (r == 3)
-    {
-        level_inc--;
-    }
-    else
-    {
-        r = get_espresso_word(fp, word);
-        if (r == 3)
-        {
-            level_inc--;
-        }
-        else
-        {
-            gmx_fatal(FARGS, "Expected '}' after section '%s' in file '%s'",
-                      keyword, infile);
-        }
-    }
-
-    return level_inc;
-}
-
-enum {
-    espID, espPOS, espTYPE, espQ, espV, espF, espMOLECULE, espNR
-};
-const char *esp_prop[espNR] = {
-    "id", "pos", "type", "q", "v", "f",
-    "molecule"
-};
-
-static void read_espresso_conf(const char *infile,
-                               t_atoms *atoms, rvec x[], rvec *v, matrix box)
-{
-    t_symtab *symtab = NULL;
-    FILE     *fp;
-    char      word[STRLEN], buf[STRLEN];
-    int       natoms, level, npar, r, nprop, p, i, m, molnr;
-    int       prop[32];
-    double    d;
-    gmx_bool  bFoundParticles, bFoundProp, bFoundVariable, bMol;
-
-    if (!symtab)
-    {
-        snew(symtab, 1);
-        open_symtab(symtab);
-    }
-
-    clear_mat(box);
-
-    fp = gmx_fio_fopen(infile, "r");
-
-    bFoundParticles = FALSE;
-    bFoundVariable  = FALSE;
-    bMol            = FALSE;
-    level           = 0;
-    while ((r = get_espresso_word(fp, word)))
-    {
-        if (level == 1 && strcmp(word, "particles") == 0 && !bFoundParticles)
-        {
-            bFoundParticles = TRUE;
-            level          += check_open_parenthesis(fp, r, infile, "particles");
-            nprop           = 0;
-            while (level == 2 && (r = get_espresso_word(fp, word)))
-            {
-                bFoundProp = FALSE;
-                for (p = 0; p < espNR; p++)
-                {
-                    if (strcmp(word, esp_prop[p]) == 0)
-                    {
-                        bFoundProp    = TRUE;
-                        prop[nprop++] = p;
-                        /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
-                    }
-                }
-                if (!bFoundProp && word[0] != '}')
-                {
-                    gmx_fatal(FARGS, "Can not read Espresso files with particle property '%s'", word);
-                }
-                if (bFoundProp && p == espMOLECULE)
-                {
-                    bMol = TRUE;
-                }
-                if (r == 3)
-                {
-                    level--;
-                }
-            }
-
-            i = 0;
-            while (level > 0 && (r = get_espresso_word(fp, word)))
-            {
-                if (r == 2)
-                {
-                    level++;
-                }
-                else if (r == 3)
-                {
-                    level--;
-                }
-                if (level == 2)
-                {
-                    for (p = 0; p < nprop; p++)
-                    {
-                        switch (prop[p])
-                        {
-                            case espID:
-                                r = get_espresso_word(fp, word);
-                                /* Not used */
-                                break;
-                            case espPOS:
-                                for (m = 0; m < 3; m++)
-                                {
-                                    r = get_espresso_word(fp, word);
-                                    sscanf(word, "%lf", &d);
-                                    x[i][m] = d;
-                                }
-                                break;
-                            case espTYPE:
-                                r                   = get_espresso_word(fp, word);
-                                atoms->atom[i].type = strtol(word, NULL, 10);
-                                break;
-                            case espQ:
-                                r = get_espresso_word(fp, word);
-                                sscanf(word, "%lf", &d);
-                                atoms->atom[i].q = d;
-                                break;
-                            case espV:
-                                for (m = 0; m < 3; m++)
-                                {
-                                    r = get_espresso_word(fp, word);
-                                    sscanf(word, "%lf", &d);
-                                    v[i][m] = d;
-                                }
-                                break;
-                            case espF:
-                                for (m = 0; m < 3; m++)
-                                {
-                                    r = get_espresso_word(fp, word);
-                                    /* not used */
-                                }
-                                break;
-                            case espMOLECULE:
-                                r     = get_espresso_word(fp, word);
-                                molnr = strtol(word, NULL, 10);
-                                if (i == 0 ||
-                                    atoms->resinfo[atoms->atom[i-1].resind].nr != molnr)
-                                {
-                                    atoms->atom[i].resind =
-                                        (i == 0 ? 0 : atoms->atom[i-1].resind+1);
-                                    atoms->resinfo[atoms->atom[i].resind].nr       = molnr;
-                                    atoms->resinfo[atoms->atom[i].resind].ic       = ' ';
-                                    atoms->resinfo[atoms->atom[i].resind].chainid  = ' ';
-                                    atoms->resinfo[atoms->atom[i].resind].chainnum = molnr; /* Not sure if this is right? */
-                                }
-                                else
-                                {
-                                    atoms->atom[i].resind = atoms->atom[i-1].resind;
-                                }
-                                break;
-                        }
-                    }
-                    /* Generate an atom name from the particle type */
-                    sprintf(buf, "T%d", atoms->atom[i].type);
-                    atoms->atomname[i] = put_symtab(symtab, buf);
-                    if (bMol)
-                    {
-                        if (i == 0 || atoms->atom[i].resind != atoms->atom[i-1].resind)
-                        {
-                            atoms->resinfo[atoms->atom[i].resind].name =
-                                put_symtab(symtab, "MOL");
-                        }
-                    }
-                    else
-                    {
-                        /* Residue number is the atom number */
-                        atoms->atom[i].resind = i;
-                        /* Generate an residue name from the particle type */
-                        if (atoms->atom[i].type < 26)
-                        {
-                            sprintf(buf, "T%c", 'A'+atoms->atom[i].type);
-                        }
-                        else
-                        {
-                            sprintf(buf, "T%c%c",
-                                    'A'+atoms->atom[i].type/26, 'A'+atoms->atom[i].type%26);
-                        }
-                        t_atoms_set_resinfo(atoms, i, symtab, buf, i, ' ', 0, ' ');
-                    }
-
-                    if (r == 3)
-                    {
-                        level--;
-                    }
-                    i++;
-                }
-            }
-            atoms->nres = atoms->nr;
-
-            if (i != atoms->nr)
-            {
-                gmx_fatal(FARGS, "Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms", i, atoms->nr);
-            }
-        }
-        else if (level == 1 && strcmp(word, "variable") == 0 && !bFoundVariable)
-        {
-            bFoundVariable = TRUE;
-            level         += check_open_parenthesis(fp, r, infile, "variable");
-            while (level == 2 && (r = get_espresso_word(fp, word)))
-            {
-                if (level == 2 && strcmp(word, "box_l") == 0)
-                {
-                    for (m = 0; m < 3; m++)
-                    {
-                        r = get_espresso_word(fp, word);
-                        sscanf(word, "%lf", &d);
-                        box[m][m] = d;
-                    }
-                    level += check_close_parenthesis(fp, r, infile, "box_l");
-                }
-            }
-        }
-        else if (r == 2)
-        {
-            level++;
-        }
-        else if (r == 3)
-        {
-            level--;
-        }
-    }
-
-    if (!bFoundParticles)
-    {
-        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
-                infile);
-    }
-
-    gmx_fio_fclose(fp);
-}
-
-static int get_espresso_coordnum(const char *infile)
-{
-    FILE    *fp;
-    char     word[STRLEN];
-    int      natoms, level, r;
-    gmx_bool bFoundParticles;
-
-    natoms = 0;
-
-    fp = gmx_fio_fopen(infile, "r");
-
-    bFoundParticles = FALSE;
-    level           = 0;
-    while ((r = get_espresso_word(fp, word)) && !bFoundParticles)
-    {
-        if (level == 1 && strcmp(word, "particles") == 0 && !bFoundParticles)
-        {
-            bFoundParticles = TRUE;
-            level          += check_open_parenthesis(fp, r, infile, "particles");
-            while (level > 0 && (r = get_espresso_word(fp, word)))
-            {
-                if (r == 2)
-                {
-                    level++;
-                    if (level == 2)
-                    {
-                        natoms++;
-                    }
-                }
-                else if (r == 3)
-                {
-                    level--;
-                }
-            }
-        }
-        else if (r == 2)
-        {
-            level++;
-        }
-        else if (r == 3)
-        {
-            level--;
-        }
-    }
-    if (!bFoundParticles)
-    {
-        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
-                infile);
-    }
-
-    gmx_fio_fclose(fp);
-
-    return natoms;
-}
-
-static void write_espresso_conf_indexed(FILE *out, const char *title,
-                                        t_atoms *atoms, int nx, atom_id *index,
-                                        rvec *x, rvec *v, matrix box)
-{
-    int i, j;
-
-    fprintf(out, "# %s\n", title);
-    if (TRICLINIC(box))
-    {
-        gmx_warning("The Espresso format does not support triclinic unit-cells");
-    }
-    fprintf(out, "{variable {box_l %f %f %f}}\n", box[0][0], box[1][1], box[2][2]);
-
-    fprintf(out, "{particles {id pos type q%s}\n", v ? " v" : "");
-    for (i = 0; i < nx; i++)
-    {
-        if (index)
-        {
-            j = index[i];
-        }
-        else
-        {
-            j = i;
-        }
-        fprintf(out, "\t{%d %f %f %f %d %g",
-                j, x[j][XX], x[j][YY], x[j][ZZ],
-                atoms->atom[j].type, atoms->atom[j].q);
-        if (v)
-        {
-            fprintf(out, " %f %f %f", v[j][XX], v[j][YY], v[j][ZZ]);
-        }
-        fprintf(out, "}\n");
-    }
-    fprintf(out, "}\n");
-}
-
-static void get_coordnum_fp (FILE *in, char *title, int *natoms)
-{
-    char line[STRLEN+1];
-
-    fgets2 (title, STRLEN, in);
-    fgets2 (line, STRLEN, in);
-    if (sscanf (line, "%d", natoms) != 1)
-    {
-        gmx_fatal(FARGS, "gro file does not have the number of atoms on the second line");
-    }
-}
-
-static void get_coordnum (const char *infile, int *natoms)
-{
-    FILE *in;
-    char  title[STRLEN];
-
-    in = gmx_fio_fopen(infile, "r");
-    get_coordnum_fp(in, title, natoms);
-    gmx_fio_fclose (in);
-}
-
-static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
-                           t_symtab *symtab, t_atoms *atoms, int *ndec,
-                           rvec x[], rvec *v, matrix box)
-{
-    char       name[6];
-    char       resname[6], oldresname[6];
-    char       line[STRLEN+1], *ptr;
-    char       buf[256];
-    double     x1, y1, z1, x2, y2, z2;
-    rvec       xmin, xmax;
-    int        natoms, i, m, resnr, newres, oldres, ddist, c;
-    gmx_bool   bFirst, bVel;
-    char      *p1, *p2, *p3;
-
-    newres  = -1;
-    oldres  = NOTSET; /* Unlikely number for the first residue! */
-    ddist   = 0;
-
-    /* Read the title and number of atoms */
-    get_coordnum_fp(in, title, &natoms);
-
-    if (natoms > atoms->nr)
-    {
-        gmx_fatal(FARGS, "gro file contains more atoms (%d) than expected (%d)",
-                  natoms, atoms->nr);
-    }
-    else if (natoms <  atoms->nr)
-    {
-        fprintf(stderr, "Warning: gro file contains less atoms (%d) than expected"
-                " (%d)\n", natoms, atoms->nr);
-    }
-
-    bFirst = TRUE;
-
-    bVel = FALSE;
-
-    resname[0]     = '\0';
-    oldresname[0]  = '\0';
-
-    /* just pray the arrays are big enough */
-    for (i = 0; (i < natoms); i++)
-    {
-        if ((fgets2 (line, STRLEN, in)) == NULL)
-        {
-            gmx_fatal(FARGS, "Unexpected end of file in file %s at line %d",
-                      infile, i+2);
-        }
-        if (strlen(line) < 39)
-        {
-            gmx_fatal(FARGS, "Invalid line in %s for atom %d:\n%s", infile, i+1, line);
-        }
-
-        /* determine read precision from distance between periods
-           (decimal points) */
-        if (bFirst)
-        {
-            bFirst = FALSE;
-            p1     = strchr(line, '.');
-            if (p1 == NULL)
-            {
-                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
-            }
-            p2 = strchr(&p1[1], '.');
-            if (p2 == NULL)
-            {
-                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
-            }
-            ddist = p2 - p1;
-            *ndec = ddist - 5;
-
-            p3 = strchr(&p2[1], '.');
-            if (p3 == NULL)
-            {
-                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
-            }
-
-            if (p3 - p2 != ddist)
-            {
-                gmx_fatal(FARGS, "The spacing of the decimal points in file %s is not consistent for x, y and z", infile);
-            }
-        }
-
-        /* residue number*/
-        memcpy(name, line, 5);
-        name[5] = '\0';
-        sscanf(name, "%d", &resnr);
-        sscanf(line+5, "%5s", resname);
-
-        if (resnr != oldres || strncmp(resname, oldresname, sizeof(resname)))
-        {
-            oldres = resnr;
-            newres++;
-            if (newres >= natoms)
-            {
-                gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
-                          infile, natoms);
-            }
-            atoms->atom[i].resind = newres;
-            t_atoms_set_resinfo(atoms, i, symtab, resname, resnr, ' ', 0, ' ');
-        }
-        else
-        {
-            atoms->atom[i].resind = newres;
-        }
-
-        /* atomname */
-        memcpy(name, line+10, 5);
-        atoms->atomname[i] = put_symtab(symtab, name);
-
-        /* Copy resname to oldresname after we are done with the sanity check above */
-        strncpy(oldresname, resname, sizeof(oldresname));
-
-        /* eventueel controle atomnumber met i+1 */
-
-        /* coordinates (start after residue data) */
-        ptr = line + 20;
-        /* Read fixed format */
-        for (m = 0; m < DIM; m++)
-        {
-            for (c = 0; (c < ddist && ptr[0]); c++)
-            {
-                buf[c] = ptr[0];
-                ptr++;
-            }
-            buf[c] = '\0';
-            if (sscanf (buf, "%lf %lf", &x1, &x2) != 1)
-            {
-                gmx_fatal(FARGS, "Something is wrong in the coordinate formatting of file %s. Note that gro is fixed format (see the manual)", infile);
-            }
-            else
-            {
-                x[i][m] = x1;
-            }
-        }
-
-        /* velocities (start after residues and coordinates) */
-        if (v)
-        {
-            /* Read fixed format */
-            for (m = 0; m < DIM; m++)
-            {
-                for (c = 0; (c < ddist && ptr[0]); c++)
-                {
-                    buf[c] = ptr[0];
-                    ptr++;
-                }
-                buf[c] = '\0';
-                if (sscanf (buf, "%lf", &x1) != 1)
-                {
-                    v[i][m] = 0;
-                }
-                else
-                {
-                    v[i][m] = x1;
-                    bVel    = TRUE;
-                }
-            }
-        }
-    }
-    atoms->nres = newres + 1;
-
-    /* box */
-    fgets2 (line, STRLEN, in);
-    if (sscanf (line, "%lf%lf%lf", &x1, &y1, &z1) != 3)
-    {
-        gmx_warning("Bad box in file %s", infile);
-
-        /* Generate a cubic box */
-        for (m = 0; (m < DIM); m++)
-        {
-            xmin[m] = xmax[m] = x[0][m];
-        }
-        for (i = 1; (i < atoms->nr); i++)
-        {
-            for (m = 0; (m < DIM); m++)
-            {
-                xmin[m] = min(xmin[m], x[i][m]);
-                xmax[m] = max(xmax[m], x[i][m]);
-            }
-        }
-        for (i = 0; i < DIM; i++)
-        {
-            for (m = 0; m < DIM; m++)
-            {
-                box[i][m] = 0.0;
-            }
-        }
-        for (m = 0; (m < DIM); m++)
-        {
-            box[m][m] = (xmax[m]-xmin[m]);
-        }
-        fprintf(stderr, "Generated a cubic box %8.3f x %8.3f x %8.3f\n",
-                box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
-    }
-    else
-    {
-        /* We found the first three values, the diagonal elements */
-        box[XX][XX] = x1;
-        box[YY][YY] = y1;
-        box[ZZ][ZZ] = z1;
-        if (sscanf (line, "%*f%*f%*f%lf%lf%lf%lf%lf%lf",
-                    &x1, &y1, &z1, &x2, &y2, &z2) != 6)
-        {
-            x1 = y1 = z1 = x2 = y2 = z2 = 0.0;
-        }
-        box[XX][YY] = x1;
-        box[XX][ZZ] = y1;
-        box[YY][XX] = z1;
-        box[YY][ZZ] = x2;
-        box[ZZ][XX] = y2;
-        box[ZZ][YY] = z2;
-    }
-
-    return bVel;
-}
-
-static void read_whole_conf(const char *infile, char *title,
-                            t_atoms *atoms, rvec x[], rvec *v, matrix box)
-{
-    FILE    *in;
-    int      ndec;
-    t_symtab symtab;
-
-    /* open file */
-    in = gmx_fio_fopen(infile, "r");
-
-    open_symtab(&symtab);
-    get_w_conf(in, infile, title, &symtab, atoms, &ndec, x, v, box);
-    /* We can't free the symbols, as they are still used in atoms, so
-     * the only choice is to leak them. */
-    free_symtab(&symtab);
-
-    gmx_fio_fclose(in);
-}
-
-static gmx_bool gmx_one_before_eof(FILE *fp)
-{
-    char     data[4];
-    gmx_bool beof;
-
-    if ((beof = fread(data, 1, 1, fp)) == 1)
-    {
-        gmx_fseek(fp, -1, SEEK_CUR);
-    }
-    return !beof;
-}
-
-gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr)
-{
-    t_atoms  atoms;
-    t_symtab symtab;
-    char     title[STRLEN], *p;
-    double   tt;
-    int      ndec = 0, i;
-
-    if (gmx_one_before_eof(status))
-    {
-        return FALSE;
-    }
-
-    open_symtab(&symtab);
-    atoms.nr = fr->natoms;
-    snew(atoms.atom, fr->natoms);
-    atoms.nres = fr->natoms;
-    snew(atoms.resinfo, fr->natoms);
-    snew(atoms.atomname, fr->natoms);
-
-    fr->bV    = get_w_conf(status, title, title, &symtab, &atoms, &ndec, fr->x, fr->v, fr->box);
-    fr->bPrec = TRUE;
-    fr->prec  = 1;
-    /* prec = 10^ndec: */
-    for (i = 0; i < ndec; i++)
-    {
-        fr->prec *= 10;
-    }
-    fr->title  = title;
-    fr->bTitle = TRUE;
-    fr->bX     = TRUE;
-    fr->bBox   = TRUE;
-
-    sfree(atoms.atom);
-    sfree(atoms.resinfo);
-    sfree(atoms.atomname);
-    done_symtab(&symtab);
-
-    if ((p = strstr(title, "t=")) != NULL)
-    {
-        p += 2;
-        if (sscanf(p, "%lf", &tt) == 1)
-        {
-            fr->time  = tt;
-            fr->bTime = TRUE;
-        }
-        else
-        {
-            fr->time  = 0;
-            fr->bTime = FALSE;
-        }
-    }
-
-    if (atoms.nr != fr->natoms)
-    {
-        gmx_fatal(FARGS, "Number of atoms in gro frame (%d) doesn't match the number in the previous frame (%d)", atoms.nr, fr->natoms);
-    }
-
-    return TRUE;
-}
-
-int gro_first_x_or_v(FILE *status, t_trxframe *fr)
-{
-    char title[STRLEN];
-
-    frewind(status);
-    fprintf(stderr, "Reading frames from gro file");
-    get_coordnum_fp(status, title, &fr->natoms);
-    frewind(status);
-    fprintf(stderr, " '%s', %d atoms.\n", title, fr->natoms);
-    fr->bTitle = TRUE;
-    fr->title  = title;
-    if (fr->natoms == 0)
-    {
-        gmx_file("No coordinates in gro file");
-    }
-
-    snew(fr->x, fr->natoms);
-    snew(fr->v, fr->natoms);
-    gro_next_x_or_v(status, fr);
-
-    return fr->natoms;
-}
-
-static void make_hconf_format(int pr, gmx_bool bVel, char format[])
-{
-    int l, vpr;
-
-    /* build format string for printing,
-       something like "%8.3f" for x and "%8.4f" for v */
-    if (pr < 0)
-    {
-        pr = 0;
-    }
-    if (pr > 30)
-    {
-        pr = 30;
-    }
-    l   = pr+5;
-    vpr = pr+1;
-    if (bVel)
-    {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df\n",
-                l, pr, l, pr, l, pr, l, vpr, l, vpr, l, vpr);
-    }
-    else
-    {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df\n", l, pr, l, pr, l, pr);
-    }
-
-}
-
-static void write_hconf_box(FILE *out, int pr, matrix box)
-{
-    char format[100];
-    int  l;
-
-    if (pr < 5)
-    {
-        pr = 5;
-    }
-    l = pr+5;
-
-    if (box[XX][YY] || box[XX][ZZ] || box[YY][XX] || box[YY][ZZ] ||
-        box[ZZ][XX] || box[ZZ][YY])
-    {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df"
-                "%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df\n",
-                l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr);
-        fprintf(out, format,
-                box[XX][XX], box[YY][YY], box[ZZ][ZZ],
-                box[XX][YY], box[XX][ZZ], box[YY][XX],
-                box[YY][ZZ], box[ZZ][XX], box[ZZ][YY]);
-    }
-    else
-    {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df\n", l, pr, l, pr, l, pr);
-        fprintf(out, format,
-                box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
-    }
-}
-
-void write_hconf_indexed_p(FILE *out, const char *title, t_atoms *atoms,
-                           int nx, const atom_id index[], int pr,
-                           rvec *x, rvec *v, matrix box)
-{
-    char resnm[6], nm[6], format[100];
-    int  ai, i, resind, resnr;
-
-    bromacs(format, 99);
-    fprintf (out, "%s\n", (title && title[0]) ? title : format);
-    fprintf (out, "%5d\n", nx);
-
-    make_hconf_format(pr, v != NULL, format);
-
-    for (i = 0; (i < nx); i++)
-    {
-        ai = index[i];
-
-        resind = atoms->atom[ai].resind;
-        strncpy(resnm, " ??? ", sizeof(resnm)-1);
-        if (resind < atoms->nres)
-        {
-            strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
-            resnr = atoms->resinfo[resind].nr;
-        }
-        else
-        {
-            strncpy(resnm, " ??? ", sizeof(resnm)-1);
-            resnr = resind + 1;
-        }
-
-        if (atoms->atom)
-        {
-            strncpy(nm, *atoms->atomname[ai], sizeof(nm)-1);
-        }
-        else
-        {
-            strncpy(nm, " ??? ", sizeof(nm)-1);
-        }
-
-        fprintf(out, "%5d%-5.5s%5.5s%5d", resnr%100000, resnm, nm, (ai+1)%100000);
-        /* next fprintf uses built format string */
-        if (v)
-        {
-            fprintf(out, format,
-                    x[ai][XX], x[ai][YY], x[ai][ZZ], v[ai][XX], v[ai][YY], v[ai][ZZ]);
-        }
-        else
-        {
-            fprintf(out, format,
-                    x[ai][XX], x[ai][YY], x[ai][ZZ]);
-        }
-    }
-
-    write_hconf_box(out, pr, box);
-
-    fflush(out);
-}
-
-static void write_hconf_mtop(FILE *out, const char *title, gmx_mtop_t *mtop,
-                             int pr,
-                             rvec *x, rvec *v, matrix box)
-{
-    char                    format[100];
-    int                     i, resnr;
-    gmx_mtop_atomloop_all_t aloop;
-    t_atom                 *atom;
-    char                   *atomname, *resname;
-
-    bromacs(format, 99);
-    fprintf (out, "%s\n", (title && title[0]) ? title : format);
-    fprintf (out, "%5d\n", mtop->natoms);
-
-    make_hconf_format(pr, v != NULL, format);
-
-    aloop = gmx_mtop_atomloop_all_init(mtop);
-    while (gmx_mtop_atomloop_all_next(aloop, &i, &atom))
-    {
-        gmx_mtop_atomloop_all_names(aloop, &atomname, &resnr, &resname);
-
-        fprintf(out, "%5d%-5.5s%5.5s%5d",
-                resnr%100000, resname, atomname, (i+1)%100000);
-        /* next fprintf uses built format string */
-        if (v)
-        {
-            fprintf(out, format,
-                    x[i][XX], x[i][YY], x[i][ZZ], v[i][XX], v[i][YY], v[i][ZZ]);
-        }
-        else
-        {
-            fprintf(out, format,
-                    x[i][XX], x[i][YY], x[i][ZZ]);
-        }
-    }
-
-    write_hconf_box(out, pr, box);
-
-    fflush(out);
-}
-
-void write_hconf_p(FILE *out, const char *title, t_atoms *atoms, int pr,
-                   rvec *x, rvec *v, matrix box)
-{
-    atom_id *aa;
-    int      i;
-
-    snew(aa, atoms->nr);
-    for (i = 0; (i < atoms->nr); i++)
-    {
-        aa[i] = i;
-    }
-    write_hconf_indexed_p(out, title, atoms, atoms->nr, aa, pr, x, v, box);
-    sfree(aa);
-}
-
-void write_conf_p(const char *outfile, const char *title,
-                  t_atoms *atoms, int pr,
-                  rvec *x, rvec *v, matrix box)
-{
-    FILE *out;
-
-    out = gmx_fio_fopen(outfile, "w");
-    write_hconf_p(out, title, atoms, pr, x, v, box);
-
-    gmx_fio_fclose (out);
-}
-
-static void write_conf(const char *outfile, const char *title, t_atoms *atoms,
-                       rvec *x, rvec *v, matrix box)
-{
-    write_conf_p(outfile, title, atoms, 3, x, v, box);
-}
-
-void write_sto_conf_indexed(const char *outfile, const char *title,
-                            t_atoms *atoms,
-                            rvec x[], rvec *v, int ePBC, matrix box,
-                            atom_id nindex, atom_id index[])
-{
-    FILE       *out;
-    int         ftp;
-    t_trxframe  fr;
-
-    ftp = fn2ftp(outfile);
-    switch (ftp)
-    {
-        case efGRO:
-            out = gmx_fio_fopen(outfile, "w");
-            write_hconf_indexed_p(out, title, atoms, nindex, index, 3, x, v, box);
-            gmx_fio_fclose(out);
-            break;
-        case efG96:
-            clear_trxframe(&fr, TRUE);
-            fr.bTitle = TRUE;
-            fr.title  = title;
-            fr.natoms = atoms->nr;
-            fr.bAtoms = TRUE;
-            fr.atoms  = atoms;
-            fr.bX     = TRUE;
-            fr.x      = x;
-            if (v)
-            {
-                fr.bV = TRUE;
-                fr.v  = v;
-            }
-            fr.bBox = TRUE;
-            copy_mat(box, fr.box);
-            out = gmx_fio_fopen(outfile, "w");
-            write_g96_conf(out, &fr, nindex, index);
-            gmx_fio_fclose(out);
-            break;
-        case efPDB:
-        case efBRK:
-        case efENT:
-        case efPQR:
-            out = gmx_fio_fopen(outfile, "w");
-            write_pdbfile_indexed(out, title, atoms, x, ePBC, box, ' ', -1, nindex, index, NULL, TRUE);
-            gmx_fio_fclose(out);
-            break;
-        case efESP:
-            out = gmx_fio_fopen(outfile, "w");
-            write_espresso_conf_indexed(out, title, atoms, nindex, index, x, v, box);
-            gmx_fio_fclose(out);
-            break;
-        case efTPR:
-            gmx_fatal(FARGS, "Sorry, can not write a topology to %s", outfile);
-            break;
-        default:
-            gmx_incons("Not supported in write_sto_conf_indexed");
-    }
-}
-
-void write_sto_conf(const char *outfile, const char *title, t_atoms *atoms,
-                    rvec x[], rvec *v, int ePBC, matrix box)
-{
-    FILE       *out;
-    int         ftp;
-    t_trxframe  fr;
-
-    ftp = fn2ftp(outfile);
-    switch (ftp)
-    {
-        case efGRO:
-            write_conf(outfile, title, atoms, x, v, box);
-            break;
-        case efG96:
-            clear_trxframe(&fr, TRUE);
-            fr.bTitle = TRUE;
-            fr.title  = title;
-            fr.natoms = atoms->nr;
-            fr.bAtoms = TRUE;
-            fr.atoms  = atoms;
-            fr.bX     = TRUE;
-            fr.x      = x;
-            if (v)
-            {
-                fr.bV = TRUE;
-                fr.v  = v;
-            }
-            fr.bBox = TRUE;
-            copy_mat(box, fr.box);
-            out = gmx_fio_fopen(outfile, "w");
-            write_g96_conf(out, &fr, -1, NULL);
-            gmx_fio_fclose(out);
-            break;
-        case efPDB:
-        case efBRK:
-        case efENT:
-            out = gmx_fio_fopen(outfile, "w");
-            write_pdbfile(out, title, atoms, x, ePBC, box, ' ', -1, NULL, TRUE);
-            gmx_fio_fclose(out);
-            break;
-        case efESP:
-            out = gmx_fio_fopen(outfile, "w");
-            write_espresso_conf_indexed(out, title, atoms, atoms->nr, NULL, x, v, box);
-            gmx_fio_fclose(out);
-            break;
-        case efTPR:
-            gmx_fatal(FARGS, "Sorry, can not write a topology to %s", outfile);
-            break;
-        default:
-            gmx_incons("Not supported in write_sto_conf");
-    }
-}
-
-void write_sto_conf_mtop(const char *outfile, const char *title,
-                         gmx_mtop_t *mtop,
-                         rvec x[], rvec *v, int ePBC, matrix box)
-{
-    int     ftp;
-    FILE   *out;
-    t_atoms atoms;
-
-    ftp = fn2ftp(outfile);
-    switch (ftp)
-    {
-        case efGRO:
-            out = gmx_fio_fopen(outfile, "w");
-            write_hconf_mtop(out, title, mtop, 3, x, v, box);
-            gmx_fio_fclose(out);
-            break;
-        default:
-            /* This is a brute force approach which requires a lot of memory.
-             * We should implement mtop versions of all writing routines.
-             */
-            atoms = gmx_mtop_global_atoms(mtop);
-
-            write_sto_conf(outfile, title, &atoms, x, v, ePBC, box);
-
-            done_atom(&atoms);
-            break;
-    }
-}
-
-void get_stx_coordnum(const char *infile, int *natoms)
-{
-    FILE      *in;
-    int        ftp, tpxver, tpxgen;
-    t_trxframe fr;
-    char       g96_line[STRLEN+1];
-
-    ftp = fn2ftp(infile);
-    range_check(ftp, 0, efNR);
-    switch (ftp)
-    {
-        case efGRO:
-            get_coordnum(infile, natoms);
-            break;
-        case efG96:
-            in        = gmx_fio_fopen(infile, "r");
-            fr.title  = NULL;
-            fr.natoms = -1;
-            fr.atoms  = NULL;
-            fr.x      = NULL;
-            fr.v      = NULL;
-            fr.f      = NULL;
-            *natoms   = read_g96_conf(in, infile, &fr, g96_line);
-            gmx_fio_fclose(in);
-            break;
-        case efPDB:
-        case efBRK:
-        case efENT:
-            in = gmx_fio_fopen(infile, "r");
-            get_pdb_coordnum(in, natoms);
-            gmx_fio_fclose(in);
-            break;
-        case efESP:
-            *natoms = get_espresso_coordnum(infile);
-            break;
-        case efTPR:
-        {
-            t_tpxheader tpx;
-
-            read_tpxheader(infile, &tpx, TRUE, &tpxver, &tpxgen);
-            *natoms = tpx.natoms;
-            break;
-        }
-        default:
-            gmx_fatal(FARGS, "File type %s not supported in get_stx_coordnum",
-                      ftp2ext(ftp));
-    }
-}
-
-void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
-                   rvec x[], rvec *v, int *ePBC, matrix box)
-{
-    FILE       *in;
-    char        buf[256];
-    gmx_mtop_t *mtop;
-    t_topology  top;
-    t_trxframe  fr;
-    int         i, ftp, natoms;
-    real        d;
-    char        g96_line[STRLEN+1];
-
-    if (atoms->nr == 0)
-    {
-        fprintf(stderr, "Warning: Number of atoms in %s is 0\n", infile);
-    }
-    else if (atoms->atom == NULL)
-    {
-        gmx_mem("Uninitialized array atom");
-    }
-
-    if (ePBC)
-    {
-        *ePBC = -1;
-    }
-
-    ftp = fn2ftp(infile);
-    switch (ftp)
-    {
-        case efGRO:
-            read_whole_conf(infile, title, atoms, x, v, box);
-            break;
-        case efG96:
-            fr.title  = NULL;
-            fr.natoms = atoms->nr;
-            fr.atoms  = atoms;
-            fr.x      = x;
-            fr.v      = v;
-            fr.f      = NULL;
-            in        = gmx_fio_fopen(infile, "r");
-            read_g96_conf(in, infile, &fr, g96_line);
-            gmx_fio_fclose(in);
-            copy_mat(fr.box, box);
-            strncpy(title, fr.title, STRLEN);
-            break;
-        case efPDB:
-        case efBRK:
-        case efENT:
-            read_pdb_conf(infile, title, atoms, x, ePBC, box, TRUE, NULL);
-            break;
-        case efESP:
-            read_espresso_conf(infile, atoms, x, v, box);
-            break;
-        case efTPR:
-            snew(mtop, 1);
-            i = read_tpx(infile, NULL, box, &natoms, x, v, NULL, mtop);
-            if (ePBC)
-            {
-                *ePBC = i;
-            }
-
-            strcpy(title, *(mtop->name));
-
-            /* Free possibly allocated memory */
-            done_atom(atoms);
-
-            *atoms = gmx_mtop_global_atoms(mtop);
-            top    = gmx_mtop_t_to_t_topology(mtop);
-            tpx_make_chain_identifiers(atoms, &top.mols);
-
-            sfree(mtop);
-            /* The strings in the symtab are still in use in the returned t_atoms
-             * structure, so we should not free them. But there is no place to put the
-             * symbols; the only choice is to leak the memory...
-             * So we clear the symbol table before freeing the topology structure. */
-            free_symtab(&top.symtab);
-            done_top(&top);
-
-            break;
-        default:
-            gmx_incons("Not supported in read_stx_conf");
-    }
-}
diff --git a/src/gromacs/fileio/confio.cpp b/src/gromacs/fileio/confio.cpp
new file mode 100644 (file)
index 0000000..ac6390b
--- /dev/null
@@ -0,0 +1,477 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gmxpre.h"
+
+#include "confio.h"
+
+#include <cstdio>
+#include <cstring>
+
+#include "gromacs/fileio/espio.h"
+#include "gromacs/fileio/filenm.h"
+#include "gromacs/fileio/g96io.h"
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/groio.h"
+#include "gromacs/fileio/pdbio.h"
+#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/trx.h"
+#include "gromacs/fileio/trxio.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/topology/atomprop.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/block.h"
+#include "gromacs/topology/mtop_util.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
+
+void write_sto_conf_indexed(const char *outfile, const char *title,
+                            t_atoms *atoms,
+                            rvec x[], rvec *v, int ePBC, matrix box,
+                            atom_id nindex, atom_id index[])
+{
+    FILE       *out;
+    int         ftp;
+    t_trxframe  fr;
+
+    ftp = fn2ftp(outfile);
+    switch (ftp)
+    {
+        case efGRO:
+            out = gmx_fio_fopen(outfile, "w");
+            write_hconf_indexed_p(out, title, atoms, nindex, index, 3, x, v, box);
+            gmx_fio_fclose(out);
+            break;
+        case efG96:
+            clear_trxframe(&fr, TRUE);
+            fr.bTitle = TRUE;
+            fr.title  = title;
+            fr.natoms = atoms->nr;
+            fr.bAtoms = TRUE;
+            fr.atoms  = atoms;
+            fr.bX     = TRUE;
+            fr.x      = x;
+            if (v)
+            {
+                fr.bV = TRUE;
+                fr.v  = v;
+            }
+            fr.bBox = TRUE;
+            copy_mat(box, fr.box);
+            out = gmx_fio_fopen(outfile, "w");
+            write_g96_conf(out, &fr, nindex, index);
+            gmx_fio_fclose(out);
+            break;
+        case efPDB:
+        case efBRK:
+        case efENT:
+        case efPQR:
+            out = gmx_fio_fopen(outfile, "w");
+            write_pdbfile_indexed(out, title, atoms, x, ePBC, box, ' ', -1, nindex, index, NULL, TRUE);
+            gmx_fio_fclose(out);
+            break;
+        case efESP:
+            out = gmx_fio_fopen(outfile, "w");
+            write_espresso_conf_indexed(out, title, atoms, nindex, index, x, v, box);
+            gmx_fio_fclose(out);
+            break;
+        case efTPR:
+            gmx_fatal(FARGS, "Sorry, can not write a topology to %s", outfile);
+            break;
+        default:
+            gmx_incons("Not supported in write_sto_conf_indexed");
+    }
+}
+
+void write_sto_conf(const char *outfile, const char *title, t_atoms *atoms,
+                    rvec x[], rvec *v, int ePBC, matrix box)
+{
+    FILE       *out;
+    int         ftp;
+    t_trxframe  fr;
+
+    ftp = fn2ftp(outfile);
+    switch (ftp)
+    {
+        case efGRO:
+            write_conf_p(outfile, title, atoms, 3, x, v, box);
+            break;
+        case efG96:
+            clear_trxframe(&fr, TRUE);
+            fr.bTitle = TRUE;
+            fr.title  = title;
+            fr.natoms = atoms->nr;
+            fr.bAtoms = TRUE;
+            fr.atoms  = atoms;
+            fr.bX     = TRUE;
+            fr.x      = x;
+            if (v)
+            {
+                fr.bV = TRUE;
+                fr.v  = v;
+            }
+            fr.bBox = TRUE;
+            copy_mat(box, fr.box);
+            out = gmx_fio_fopen(outfile, "w");
+            write_g96_conf(out, &fr, -1, NULL);
+            gmx_fio_fclose(out);
+            break;
+        case efPDB:
+        case efBRK:
+        case efENT:
+            out = gmx_fio_fopen(outfile, "w");
+            write_pdbfile(out, title, atoms, x, ePBC, box, ' ', -1, NULL, TRUE);
+            gmx_fio_fclose(out);
+            break;
+        case efESP:
+            out = gmx_fio_fopen(outfile, "w");
+            write_espresso_conf_indexed(out, title, atoms, atoms->nr, NULL, x, v, box);
+            gmx_fio_fclose(out);
+            break;
+        case efTPR:
+            gmx_fatal(FARGS, "Sorry, can not write a topology to %s", outfile);
+            break;
+        default:
+            gmx_incons("Not supported in write_sto_conf");
+    }
+}
+
+void write_sto_conf_mtop(const char *outfile, const char *title,
+                         gmx_mtop_t *mtop,
+                         rvec x[], rvec *v, int ePBC, matrix box)
+{
+    int     ftp;
+    FILE   *out;
+    t_atoms atoms;
+
+    ftp = fn2ftp(outfile);
+    switch (ftp)
+    {
+        case efGRO:
+            out = gmx_fio_fopen(outfile, "w");
+            write_hconf_mtop(out, title, mtop, 3, x, v, box);
+            gmx_fio_fclose(out);
+            break;
+        default:
+            /* This is a brute force approach which requires a lot of memory.
+             * We should implement mtop versions of all writing routines.
+             */
+            atoms = gmx_mtop_global_atoms(mtop);
+
+            write_sto_conf(outfile, title, &atoms, x, v, ePBC, box);
+
+            done_atom(&atoms);
+            break;
+    }
+}
+
+void get_stx_coordnum(const char *infile, int *natoms)
+{
+    FILE      *in;
+    int        ftp, tpxver, tpxgen;
+    t_trxframe fr;
+    char       g96_line[STRLEN+1];
+
+    ftp = fn2ftp(infile);
+    range_check(ftp, 0, efNR);
+    switch (ftp)
+    {
+        case efGRO:
+            get_coordnum(infile, natoms);
+            break;
+        case efG96:
+            in        = gmx_fio_fopen(infile, "r");
+            fr.title  = NULL;
+            fr.natoms = -1;
+            fr.atoms  = NULL;
+            fr.x      = NULL;
+            fr.v      = NULL;
+            fr.f      = NULL;
+            *natoms   = read_g96_conf(in, infile, &fr, g96_line);
+            gmx_fio_fclose(in);
+            break;
+        case efPDB:
+        case efBRK:
+        case efENT:
+            in = gmx_fio_fopen(infile, "r");
+            get_pdb_coordnum(in, natoms);
+            gmx_fio_fclose(in);
+            break;
+        case efESP:
+            *natoms = get_espresso_coordnum(infile);
+            break;
+        case efTPR:
+        {
+            t_tpxheader tpx;
+
+            read_tpxheader(infile, &tpx, TRUE, &tpxver, &tpxgen);
+            *natoms = tpx.natoms;
+            break;
+        }
+        default:
+            gmx_fatal(FARGS, "File type %s not supported in get_stx_coordnum",
+                      ftp2ext(ftp));
+    }
+}
+
+static void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
+{
+    int  m, a, a0, a1, r;
+    char c, chainid;
+    int  chainnum;
+
+    /* We always assign a new chain number, but save the chain id characters
+     * for larger molecules.
+     */
+#define CHAIN_MIN_ATOMS 15
+
+    chainnum = 0;
+    chainid  = 'A';
+    for (m = 0; m < mols->nr; m++)
+    {
+        a0 = mols->index[m];
+        a1 = mols->index[m+1];
+        if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
+        {
+            c = chainid;
+            chainid++;
+        }
+        else
+        {
+            c = ' ';
+        }
+        for (a = a0; a < a1; a++)
+        {
+            atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
+            atoms->resinfo[atoms->atom[a].resind].chainid  = c;
+        }
+        chainnum++;
+    }
+
+    /* Blank out the chain id if there was only one chain */
+    if (chainid == 'B')
+    {
+        for (r = 0; r < atoms->nres; r++)
+        {
+            atoms->resinfo[r].chainid = ' ';
+        }
+    }
+}
+
+void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
+                   rvec x[], rvec *v, int *ePBC, matrix box)
+{
+    FILE       *in;
+    gmx_mtop_t *mtop;
+    t_topology  top;
+    t_trxframe  fr;
+    int         i, ftp, natoms;
+    char        g96_line[STRLEN+1];
+
+    if (atoms->nr == 0)
+    {
+        fprintf(stderr, "Warning: Number of atoms in %s is 0\n", infile);
+    }
+    else if (atoms->atom == NULL)
+    {
+        gmx_mem("Uninitialized array atom");
+    }
+
+    if (ePBC)
+    {
+        *ePBC = -1;
+    }
+
+    ftp = fn2ftp(infile);
+    switch (ftp)
+    {
+        case efGRO:
+            read_whole_conf(infile, title, atoms, x, v, box);
+            break;
+        case efG96:
+            fr.title  = NULL;
+            fr.natoms = atoms->nr;
+            fr.atoms  = atoms;
+            fr.x      = x;
+            fr.v      = v;
+            fr.f      = NULL;
+            in        = gmx_fio_fopen(infile, "r");
+            read_g96_conf(in, infile, &fr, g96_line);
+            gmx_fio_fclose(in);
+            copy_mat(fr.box, box);
+            std::strncpy(title, fr.title, STRLEN);
+            break;
+        case efPDB:
+        case efBRK:
+        case efENT:
+            read_pdb_conf(infile, title, atoms, x, ePBC, box, TRUE, NULL);
+            break;
+        case efESP:
+            read_espresso_conf(infile, title, atoms, x, v, box);
+            break;
+        case efTPR:
+            snew(mtop, 1);
+            i = read_tpx(infile, NULL, box, &natoms, x, v, NULL, mtop);
+            if (ePBC)
+            {
+                *ePBC = i;
+            }
+
+            strcpy(title, *(mtop->name));
+
+            /* Free possibly allocated memory */
+            done_atom(atoms);
+
+            *atoms = gmx_mtop_global_atoms(mtop);
+            top    = gmx_mtop_t_to_t_topology(mtop);
+            tpx_make_chain_identifiers(atoms, &top.mols);
+
+            sfree(mtop);
+            /* The strings in the symtab are still in use in the returned t_atoms
+             * structure, so we should not free them. But there is no place to put the
+             * symbols; the only choice is to leak the memory...
+             * So we clear the symbol table before freeing the topology structure. */
+            free_symtab(&top.symtab);
+            done_top(&top);
+
+            break;
+        default:
+            gmx_incons("Not supported in read_stx_conf");
+    }
+}
+
+static void done_gmx_groups_t(gmx_groups_t *g)
+{
+    int i;
+
+    for (i = 0; (i < egcNR); i++)
+    {
+        if (NULL != g->grps[i].nm_ind)
+        {
+            sfree(g->grps[i].nm_ind);
+            g->grps[i].nm_ind = NULL;
+        }
+        if (NULL != g->grpnr[i])
+        {
+            sfree(g->grpnr[i]);
+            g->grpnr[i] = NULL;
+        }
+    }
+    /* The contents of this array is in symtab, don't free it here */
+    sfree(g->grpname);
+}
+
+gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *ePBC,
+                       rvec **x, rvec **v, matrix box, gmx_bool bMass)
+{
+    t_tpxheader      header;
+    int              natoms, i, version, generation;
+    gmx_bool         bTop, bXNULL = FALSE;
+    gmx_mtop_t      *mtop;
+    gmx_atomprop_t   aps;
+
+    bTop  = fn2bTPX(infile);
+    *ePBC = -1;
+    if (bTop)
+    {
+        read_tpxheader(infile, &header, TRUE, &version, &generation);
+        if (x)
+        {
+            snew(*x, header.natoms);
+        }
+        if (v)
+        {
+            snew(*v, header.natoms);
+        }
+        snew(mtop, 1);
+        *ePBC = read_tpx(infile, NULL, box, &natoms,
+                         (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
+        *top = gmx_mtop_t_to_t_topology(mtop);
+        /* In this case we need to throw away the group data too */
+        done_gmx_groups_t(&mtop->groups);
+        sfree(mtop);
+        std::strcpy(title, *top->name);
+        tpx_make_chain_identifiers(&top->atoms, &top->mols);
+    }
+    else
+    {
+        get_stx_coordnum(infile, &natoms);
+        init_t_atoms(&top->atoms, natoms, (fn2ftp(infile) == efPDB));
+        if (x == NULL)
+        {
+            snew(x, 1);
+            bXNULL = TRUE;
+        }
+        snew(*x, natoms);
+        if (v)
+        {
+            snew(*v, natoms);
+        }
+        read_stx_conf(infile, title, &top->atoms, *x, (v == NULL) ? NULL : *v, ePBC, box);
+        if (bXNULL)
+        {
+            sfree(*x);
+            sfree(x);
+        }
+        if (bMass)
+        {
+            aps = gmx_atomprop_init();
+            for (i = 0; (i < natoms); i++)
+            {
+                if (!gmx_atomprop_query(aps, epropMass,
+                                        *top->atoms.resinfo[top->atoms.atom[i].resind].name,
+                                        *top->atoms.atomname[i],
+                                        &(top->atoms.atom[i].m)))
+                {
+                    if (debug)
+                    {
+                        fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
+                                *top->atoms.resinfo[top->atoms.atom[i].resind].name,
+                                top->atoms.resinfo[top->atoms.atom[i].resind].nr,
+                                *top->atoms.atomname[i]);
+                    }
+                }
+            }
+            gmx_atomprop_destroy(aps);
+        }
+        top->idef.ntypes = -1;
+    }
+
+    return bTop;
+}
index 2b149c23a82b59884c77e6b218554834b8e03e24..2c5dc2dc0e8ff2c80033708c6d47f6ade0f3fa38 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-
 #ifndef GMX_FILEIO_CONFIO_H
 #define GMX_FILEIO_CONFIO_H
 
 #include <stdio.h>
 
-#include "gromacs/fileio/trx.h"
 #include "gromacs/legacyheaders/types/simple.h"
 
 /* For reading coordinate files it is assumed that enough memory
@@ -52,33 +50,7 @@ extern "C" {
 
 struct gmx_mtop_t;
 struct t_atoms;
-
-int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line);
-/* read a Gromos96 coordinate or trajectory file,                       *
- * returns the number of atoms                                          *
- * sets what's in the frame in info                                     *
- * read from fp, infile is only needed for error messages               *
- * nwanted is the number of wanted coordinates,                         *
- * set this to -1 if you want to know the number of atoms in the file   *
- * title, atoms, x, v can all be NULL, in which case they won't be read *
- * line holds the previous line for trajectory reading                  */
-
-void write_g96_conf(FILE *out, t_trxframe *fr, int nindex, const atom_id *index);
-/* write a Gromos96 coordinate file or trajectory frame *
- * index can be NULL                                    */
-
-gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr);
-int gro_first_x_or_v(FILE *status, t_trxframe *fr);
-/* read first/next x and/or v frame from gro file */
-
-void write_hconf_indexed_p(FILE *out, const char *title, struct t_atoms *atoms,
-                           int nx, const atom_id index[], int ndec,
-                           rvec *x, rvec *v, matrix box);
-
-void write_hconf_p(FILE *out, const char *title, struct t_atoms *atoms, int ndec,
-                   rvec *x, rvec *v, matrix box);
-/* Write a Gromos file with precision ndec: number of decimal places in x,
- * v has one place more. */
+struct t_topology;
 
 void write_sto_conf_indexed(const char *outfile, const char *title,
                             struct t_atoms *atoms,
@@ -107,8 +79,17 @@ void read_stx_conf(const char *infile, char *title,
  * If ePBC!=NULL return the type of pbc in *ePBC or -1 if unknown.
  */
 
+gmx_bool read_tps_conf(const char *infile, char *title, struct t_topology *top,
+                       int *ePBC, rvec **x, rvec **v, matrix box, gmx_bool bMass);
+/* Read title, top.atoms, x, v (if not NULL) and box from an STX file,
+ * memory for atoms, x and v will be allocated.
+ * Return TRUE if a complete topology was read.
+ * If infile is a TPX file read the whole top,
+ * else if bMass=TRUE, read the masses into top.atoms from the mass database.
+ */
+
 #ifdef __cplusplus
 }
 #endif
 
-#endif  /* GMX_FILEIO_CONFIO_H */
+#endif
similarity index 96%
rename from src/gromacs/fileio/enxio.c
rename to src/gromacs/fileio/enxio.cpp
index c9b34b1da1f0538caabee990e9f9d6e0caaa1c46..ece8f4eea44334e7271851864b1127f2fb214628 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "enxio.h"
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
 #include "gromacs/fileio/xdrf.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/math/vec.h"
@@ -49,6 +52,7 @@
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 /* The source code in this file should be thread-safe.
@@ -385,9 +389,6 @@ void do_enxnms(ener_file_t ef, int *nre, gmx_enxnm_t **nms)
     XDR     *xdr;
     gmx_bool bRead = gmx_fio_getread(ef->fio);
     int      file_version;
-    int      i;
-
-    gmx_fio_checktype(ef->fio);
 
     xdr = gmx_fio_getxdr(ef->fio);
 
@@ -439,9 +440,8 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr,
 {
     int          magic = -7777777;
     real         first_real_to_check;
-    int          b, i, zero = 0, dum = 0;
+    int          b, zero = 0, dum = 0;
     gmx_bool     bRead      = gmx_fio_getread(ef->fio);
-    int          tempfix_nr = 0;
     int          ndisre     = 0;
     int          startb     = 0;
 #ifndef GMX_DOUBLE
@@ -537,7 +537,7 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr,
         }
         else
         {
-            fr->nsteps = max(1, fr->nsum);
+            fr->nsteps = std::max(1, fr->nsum);
         }
         if (*file_version >= 5)
         {
@@ -597,7 +597,10 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr,
         ((fr->nre > 0 && fr->nre != nre_test) ||
          fr->nre < 0 || ndisre < 0 || fr->nblock < 0))
     {
-        *bWrongPrecision = TRUE;
+        if (bWrongPrecision)
+        {
+            *bWrongPrecision = TRUE;
+        }
         return *bOK;
     }
 
@@ -747,7 +750,17 @@ void close_enx(ener_file_t ef)
     }
 }
 
-static gmx_bool empty_file(const char *fn)
+/*!\brief Return TRUE if a file exists but is empty, otherwise FALSE.
+ *
+ * If the file exists but has length larger than zero, if it does not exist, or
+ * if there is a file system error, FALSE will be returned instead.
+ *
+ * \param fn  File name to test
+ *
+ * \return TRUE if file could be open but is empty, otherwise FALSE.
+ */
+static gmx_bool
+empty_file(const char *fn)
 {
     FILE    *fp;
     char     dum;
@@ -759,13 +772,15 @@ static gmx_bool empty_file(const char *fn)
     bEmpty = feof(fp);
     gmx_fio_fclose(fp);
 
-    return bEmpty;
+    // bEmpty==TRUE but ret!=0 would likely be some strange I/O error, but at
+    // least it's not a normal empty file, so we return FALSE in that case.
+    return (bEmpty && ret == 0);
 }
 
 
 ener_file_t open_enx(const char *fn, const char *mode)
 {
-    int               nre, i;
+    int               nre;
     gmx_enxnm_t      *nms          = NULL;
     int               file_version = -1;
     t_enxframe       *fr;
@@ -777,7 +792,6 @@ ener_file_t open_enx(const char *fn, const char *mode)
     if (mode[0] == 'r')
     {
         ef->fio = gmx_fio_open(fn, mode);
-        gmx_fio_checktype(ef->fio);
         gmx_fio_setprecision(ef->fio, FALSE);
         do_enxnms(ef, &nre, &nms);
         snew(fr, 1);
@@ -798,7 +812,6 @@ ener_file_t open_enx(const char *fn, const char *mode)
         else
         {
             gmx_fio_rewind(ef->fio);
-            gmx_fio_checktype(ef->fio);
             gmx_fio_setprecision(ef->fio, TRUE);
             do_enxnms(ef, &nre, &nms);
             do_eheader(ef, &file_version, fr, nre, &bWrongPrecision, &bOK);
@@ -931,7 +944,6 @@ gmx_bool do_enx(ener_file_t ef, t_enxframe *fr)
         fr->e_size = fr->nre*sizeof(fr->ener[0].e)*4;
         /*d_size = fr->ndisre*(sizeof(real)*2);*/
     }
-    gmx_fio_checktype(ef->fio);
 
     if (!do_eheader(ef, &file_version, fr, -1, NULL, &bOK))
     {
@@ -974,7 +986,7 @@ gmx_bool do_enx(ener_file_t ef, t_enxframe *fr)
     {
         fprintf(stderr, "\nWARNING: there may be something wrong with energy file %s\n",
                 gmx_fio_getname(ef->fio));
-        fprintf(stderr, "Found: step=%"GMX_PRId64 ", nre=%d, nblock=%d, time=%g.\n"
+        fprintf(stderr, "Found: step=%" GMX_PRId64 ", nre=%d, nblock=%d, time=%g.\n"
                 "Trying to skip frame expect a crash though\n",
                 fr->step, fr->nre, fr->nblock, fr->t);
     }
@@ -1049,7 +1061,6 @@ gmx_bool do_enx(ener_file_t ef, t_enxframe *fr)
             }
 
             /* read/write data */
-            bOK1 = TRUE;
             switch (sub->type)
             {
                 case xdr_datatype_float:
@@ -1111,7 +1122,7 @@ static real find_energy(const char *name, int nre, gmx_enxnm_t *enm,
 
     for (i = 0; i < nre; i++)
     {
-        if (strcmp(enm[i].name, name) == 0)
+        if (std::strcmp(enm[i].name, name) == 0)
         {
             return fr->ener[i].e;
         }
@@ -1132,10 +1143,6 @@ void get_enx_state(const char *fn, real t, gmx_groups_t *groups, t_inputrec *ir,
         "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY"
     };
 
-    static const char *pcouplmu_nm[] = {
-        "Pcoupl-Mu-XX", "Pcoupl-Mu-YY", "Pcoupl-Mu-ZZ",
-        "Pcoupl-Mu-YX", "Pcoupl-Mu-ZX", "Pcoupl-Mu-ZY"
-    };
     static const char *baro_nm[] = {
         "Barostat"
     };
index c8434ab2b53135cb6b2c2639b5b4f75f9f14509e..9120feabbad258f23a586638d1dea3628988285a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -37,7 +37,6 @@
 #ifndef GMX_FILEIO_ENXIO_H
 #define GMX_FILEIO_ENXIO_H
 
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/xdr_datatype.h"
 #include "gromacs/legacyheaders/types/energy.h"
 #include "gromacs/legacyheaders/types/inputrec.h"
@@ -48,6 +47,7 @@ extern "C" {
 #endif
 
 struct gmx_groups_t;
+struct t_fileio;
 
 /**************************************************************
  * These are the base datatypes + functions for reading and
@@ -175,7 +175,7 @@ void free_enxframe(t_enxframe *ef);
 
 ener_file_t open_enx(const char *fn, const char *mode);
 
-t_fileio *enx_file_pointer(const ener_file_t ef);
+struct t_fileio *enx_file_pointer(const ener_file_t ef);
 
 void close_enx(ener_file_t ef);
 
diff --git a/src/gromacs/fileio/espio.cpp b/src/gromacs/fileio/espio.cpp
new file mode 100644 (file)
index 0000000..9a90f70
--- /dev/null
@@ -0,0 +1,466 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2005, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gmxpre.h"
+
+#include "espio.h"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
+
+static int get_espresso_word(FILE *fp, char word[])
+{
+    int  ret, nc, i;
+
+    ret = 0;
+    nc  = 0;
+
+    do
+    {
+        i = fgetc(fp);
+        if (i != EOF)
+        {
+            if (i == ' ' || i == '\n' || i == '\t')
+            {
+                if (nc > 0)
+                {
+                    ret = 1;
+                }
+            }
+            else if (i == '{')
+            {
+                if (nc == 0)
+                {
+                    word[nc++] = '{';
+                }
+                ret = 2;
+            }
+            else if (i == '}')
+            {
+                if (nc == 0)
+                {
+                    word[nc++] = '}';
+                }
+                ret = 3;
+            }
+            else
+            {
+                word[nc++] = (char)i;
+            }
+        }
+    }
+    while (i != EOF && ret == 0);
+
+    word[nc] = '\0';
+
+    return ret;
+}
+
+static int check_open_parenthesis(FILE *fp, int r,
+                                  const char *infile, const char *keyword)
+{
+    int  level_inc;
+    char word[STRLEN];
+
+    level_inc = 0;
+    if (r == 2)
+    {
+        level_inc++;
+    }
+    else
+    {
+        r = get_espresso_word(fp, word);
+        if (r == 2)
+        {
+            level_inc++;
+        }
+        else
+        {
+            gmx_fatal(FARGS, "Expected '{' after '%s' in file '%s'",
+                      keyword, infile);
+        }
+    }
+
+    return level_inc;
+}
+
+static int check_close_parenthesis(FILE *fp, int r,
+                                   const char *infile, const char *keyword)
+{
+    int  level_inc;
+    char word[STRLEN];
+
+    level_inc = 0;
+    if (r == 3)
+    {
+        level_inc--;
+    }
+    else
+    {
+        r = get_espresso_word(fp, word);
+        if (r == 3)
+        {
+            level_inc--;
+        }
+        else
+        {
+            gmx_fatal(FARGS, "Expected '}' after section '%s' in file '%s'",
+                      keyword, infile);
+        }
+    }
+
+    return level_inc;
+}
+
+enum {
+    espID, espPOS, espTYPE, espQ, espV, espF, espMOLECULE, espNR
+};
+static const char *const esp_prop[espNR] = {
+    "id", "pos", "type", "q", "v", "f",
+    "molecule"
+};
+
+void read_espresso_conf(const char *infile, char *title,
+                        t_atoms *atoms, rvec x[], rvec *v, matrix box)
+{
+    t_symtab *symtab = NULL;
+    FILE     *fp;
+    char      word[STRLEN], buf[STRLEN];
+    int       level, r, nprop, p, i, m, molnr;
+    int       prop[32];
+    double    d;
+    gmx_bool  bFoundParticles, bFoundProp, bFoundVariable, bMol;
+
+    if (!symtab)
+    {
+        snew(symtab, 1);
+        open_symtab(symtab);
+    }
+    // TODO: The code does not understand titles it writes...
+    title[0] = '\0';
+
+    clear_mat(box);
+
+    fp = gmx_fio_fopen(infile, "r");
+
+    bFoundParticles = FALSE;
+    bFoundVariable  = FALSE;
+    bMol            = FALSE;
+    level           = 0;
+    while ((r = get_espresso_word(fp, word)))
+    {
+        if (level == 1 && std::strcmp(word, "particles") == 0 && !bFoundParticles)
+        {
+            bFoundParticles = TRUE;
+            level          += check_open_parenthesis(fp, r, infile, "particles");
+            nprop           = 0;
+            while (level == 2 && (r = get_espresso_word(fp, word)))
+            {
+                bFoundProp = FALSE;
+                for (p = 0; p < espNR; p++)
+                {
+                    if (strcmp(word, esp_prop[p]) == 0)
+                    {
+                        bFoundProp    = TRUE;
+                        prop[nprop++] = p;
+                        /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
+                    }
+                }
+                if (!bFoundProp && word[0] != '}')
+                {
+                    gmx_fatal(FARGS, "Can not read Espresso files with particle property '%s'", word);
+                }
+                if (bFoundProp && p == espMOLECULE)
+                {
+                    bMol = TRUE;
+                }
+                if (r == 3)
+                {
+                    level--;
+                }
+            }
+
+            i = 0;
+            while (level > 0 && (r = get_espresso_word(fp, word)))
+            {
+                if (r == 2)
+                {
+                    level++;
+                }
+                else if (r == 3)
+                {
+                    level--;
+                }
+                if (level == 2)
+                {
+                    for (p = 0; p < nprop; p++)
+                    {
+                        switch (prop[p])
+                        {
+                            case espID:
+                                r = get_espresso_word(fp, word);
+                                /* Not used */
+                                break;
+                            case espPOS:
+                                for (m = 0; m < 3; m++)
+                                {
+                                    r = get_espresso_word(fp, word);
+                                    sscanf(word, "%lf", &d);
+                                    x[i][m] = d;
+                                }
+                                break;
+                            case espTYPE:
+                                r                   = get_espresso_word(fp, word);
+                                atoms->atom[i].type = std::strtol(word, NULL, 10);
+                                break;
+                            case espQ:
+                                r = get_espresso_word(fp, word);
+                                sscanf(word, "%lf", &d);
+                                atoms->atom[i].q = d;
+                                break;
+                            case espV:
+                                for (m = 0; m < 3; m++)
+                                {
+                                    r = get_espresso_word(fp, word);
+                                    sscanf(word, "%lf", &d);
+                                    v[i][m] = d;
+                                }
+                                break;
+                            case espF:
+                                for (m = 0; m < 3; m++)
+                                {
+                                    r = get_espresso_word(fp, word);
+                                    /* not used */
+                                }
+                                break;
+                            case espMOLECULE:
+                                r     = get_espresso_word(fp, word);
+                                molnr = std::strtol(word, NULL, 10);
+                                if (i == 0 ||
+                                    atoms->resinfo[atoms->atom[i-1].resind].nr != molnr)
+                                {
+                                    atoms->atom[i].resind =
+                                        (i == 0 ? 0 : atoms->atom[i-1].resind+1);
+                                    atoms->resinfo[atoms->atom[i].resind].nr       = molnr;
+                                    atoms->resinfo[atoms->atom[i].resind].ic       = ' ';
+                                    atoms->resinfo[atoms->atom[i].resind].chainid  = ' ';
+                                    atoms->resinfo[atoms->atom[i].resind].chainnum = molnr; /* Not sure if this is right? */
+                                }
+                                else
+                                {
+                                    atoms->atom[i].resind = atoms->atom[i-1].resind;
+                                }
+                                break;
+                        }
+                    }
+                    /* Generate an atom name from the particle type */
+                    sprintf(buf, "T%d", atoms->atom[i].type);
+                    atoms->atomname[i] = put_symtab(symtab, buf);
+                    if (bMol)
+                    {
+                        if (i == 0 || atoms->atom[i].resind != atoms->atom[i-1].resind)
+                        {
+                            atoms->resinfo[atoms->atom[i].resind].name =
+                                put_symtab(symtab, "MOL");
+                        }
+                    }
+                    else
+                    {
+                        /* Residue number is the atom number */
+                        atoms->atom[i].resind = i;
+                        /* Generate an residue name from the particle type */
+                        if (atoms->atom[i].type < 26)
+                        {
+                            sprintf(buf, "T%c", 'A'+atoms->atom[i].type);
+                        }
+                        else
+                        {
+                            sprintf(buf, "T%c%c",
+                                    'A'+atoms->atom[i].type/26, 'A'+atoms->atom[i].type%26);
+                        }
+                        t_atoms_set_resinfo(atoms, i, symtab, buf, i, ' ', 0, ' ');
+                    }
+
+                    if (r == 3)
+                    {
+                        level--;
+                    }
+                    i++;
+                }
+            }
+            atoms->nres = atoms->nr;
+
+            if (i != atoms->nr)
+            {
+                gmx_fatal(FARGS, "Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms", i, atoms->nr);
+            }
+        }
+        else if (level == 1 && std::strcmp(word, "variable") == 0 && !bFoundVariable)
+        {
+            bFoundVariable = TRUE;
+            level         += check_open_parenthesis(fp, r, infile, "variable");
+            while (level == 2 && (r = get_espresso_word(fp, word)))
+            {
+                if (level == 2 && std::strcmp(word, "box_l") == 0)
+                {
+                    for (m = 0; m < 3; m++)
+                    {
+                        r = get_espresso_word(fp, word);
+                        sscanf(word, "%lf", &d);
+                        box[m][m] = d;
+                    }
+                    level += check_close_parenthesis(fp, r, infile, "box_l");
+                }
+            }
+        }
+        else if (r == 2)
+        {
+            level++;
+        }
+        else if (r == 3)
+        {
+            level--;
+        }
+    }
+
+    if (!bFoundParticles)
+    {
+        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
+                infile);
+    }
+
+    gmx_fio_fclose(fp);
+}
+
+int get_espresso_coordnum(const char *infile)
+{
+    FILE    *fp;
+    char     word[STRLEN];
+    int      natoms, level, r;
+    gmx_bool bFoundParticles;
+
+    natoms = 0;
+
+    fp = gmx_fio_fopen(infile, "r");
+
+    bFoundParticles = FALSE;
+    level           = 0;
+    while ((r = get_espresso_word(fp, word)) && !bFoundParticles)
+    {
+        if (level == 1 && strcmp(word, "particles") == 0 && !bFoundParticles)
+        {
+            bFoundParticles = TRUE;
+            level          += check_open_parenthesis(fp, r, infile, "particles");
+            while (level > 0 && (r = get_espresso_word(fp, word)))
+            {
+                if (r == 2)
+                {
+                    level++;
+                    if (level == 2)
+                    {
+                        natoms++;
+                    }
+                }
+                else if (r == 3)
+                {
+                    level--;
+                }
+            }
+        }
+        else if (r == 2)
+        {
+            level++;
+        }
+        else if (r == 3)
+        {
+            level--;
+        }
+    }
+    if (!bFoundParticles)
+    {
+        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
+                infile);
+    }
+
+    gmx_fio_fclose(fp);
+
+    return natoms;
+}
+
+void write_espresso_conf_indexed(FILE *out, const char *title,
+                                 t_atoms *atoms, int nx, atom_id *index,
+                                 rvec *x, rvec *v, matrix box)
+{
+    int i, j;
+
+    fprintf(out, "# %s\n", title);
+    if (TRICLINIC(box))
+    {
+        gmx_warning("The Espresso format does not support triclinic unit-cells");
+    }
+    fprintf(out, "{variable {box_l %f %f %f}}\n", box[0][0], box[1][1], box[2][2]);
+
+    fprintf(out, "{particles {id pos type q%s}\n", v ? " v" : "");
+    for (i = 0; i < nx; i++)
+    {
+        if (index)
+        {
+            j = index[i];
+        }
+        else
+        {
+            j = i;
+        }
+        fprintf(out, "\t{%d %f %f %f %d %g",
+                j, x[j][XX], x[j][YY], x[j][ZZ],
+                atoms->atom[j].type, atoms->atom[j].q);
+        if (v)
+        {
+            fprintf(out, " %f %f %f", v[j][XX], v[j][YY], v[j][ZZ]);
+        }
+        fprintf(out, "}\n");
+    }
+    fprintf(out, "}\n");
+}
similarity index 63%
rename from src/gromacs/mdlib/genborn_sse2_single.h
rename to src/gromacs/fileio/espio.h
index 6753e0e17f8068226d74d8cb77857220a9d9f267..d09ad5fc02b548a5d0658961701bf487b8ab7faa 100644 (file)
@@ -1,9 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2005, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifndef _genborn_sse_h
-#define _genborn_sse_h
+#ifndef GMX_FILEIO_ESPIO_H
+#define GMX_FILEIO_ESPIO_H
 
-#include "gromacs/legacyheaders/typedefs.h"
+#include <cstdio>
 
-float
-calc_gb_chainrule_sse2_single(int natoms, t_nblist *nl, float *dadx, float *dvda,
-                              float *xd, float *f, float *fshift, float *shift_vec,
-                              int gb_algorithm, gmx_genborn_t *born, t_mdatoms *md);
+#include "gromacs/legacyheaders/types/simple.h"
+#include "gromacs/math/vectypes.h"
 
-int
-calc_gb_rad_still_sse2_single(t_commrec *cr, t_forcerec *fr, int natoms, gmx_localtop_t *top,
-                              float *x, t_nblist *nl, gmx_genborn_t *born);
+struct t_atoms;
 
-int
-calc_gb_rad_hct_obc_sse2_single(t_commrec *cr, t_forcerec * fr, int natoms, gmx_localtop_t *top,
-                                float *x, t_nblist *nl, gmx_genborn_t *born, t_mdatoms *md, int gb_algorithm);
+void read_espresso_conf(const char *infile, char *title,
+                        t_atoms *atoms, rvec x[], rvec *v, matrix box);
 
-#endif /* _genborn_sse_h */
+int get_espresso_coordnum(const char *infile);
+
+void write_espresso_conf_indexed(FILE *out, const char *title,
+                                 t_atoms *atoms, int nx, atom_id *index,
+                                 rvec *x, rvec *v, matrix box);
+
+#endif
similarity index 91%
rename from src/gromacs/fileio/filenm.c
rename to src/gromacs/fileio/filenm.cpp
index 782424df600a423c45856ff35feda0a4e24b246c..ca750d220064db2af158549b1828f10ce8439a3a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,8 +38,8 @@
 
 #include "filenm.h"
 
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
 
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
-/* XDR should be available on all platforms now,
- * but we keep the possibility of turning it off...
- */
-#define USE_XDR
-
 /* Use bitflag ... */
 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
 
 enum
 {
-    eftASC, eftBIN, eftXDR, eftTNG, eftGEN, eftNR
+    eftASC, eftXDR, eftTNG, eftGEN, eftNR
 };
 
 /* To support multiple file types with one general (eg TRX) we have
@@ -67,36 +62,28 @@ enum
  */
 static const int trxs[] =
 {
-#ifdef USE_XDR
     efXTC, efTRR, efCPT,
-#endif
     efGRO, efG96, efPDB, efTNG
 };
 #define NTRXS asize(trxs)
 
 static const int trcompressed[] =
 {
-#ifdef USE_XDR
     efXTC,
-#endif
     efTNG
 };
 #define NTRCOMPRESSED asize(trcompressed)
 
 static const int tros[] =
 {
-#ifdef USE_XDR
     efXTC, efTRR,
-#endif
     efGRO, efG96, efPDB, efTNG
 };
 #define NTROS asize(tros)
 
 static const int trns[] =
 {
-#ifdef USE_XDR
     efTRR, efCPT,
-#endif
     efTNG
 };
 #define NTRNS asize(trns)
@@ -107,18 +94,14 @@ static const int stos[] =
 
 static const int stxs[] =
 {
-    efGRO, efG96, efPDB, efBRK, efENT, efESP
-#ifdef USE_XDR
-    , efTPR
-#endif
+    efGRO, efG96, efPDB, efBRK, efENT, efESP,
+    efTPR
 };
 #define NSTXS asize(stxs)
 
 static const int tpss[] =
 {
-#ifdef USE_XDR
     efTPR,
-#endif
     efGRO, efG96, efPDB, efBRK, efENT
 };
 #define NTPSS asize(tpss)
@@ -186,10 +169,6 @@ static const t_deffile
     { eftASC, "", "rundir", NULL, "Run directory" }
 };
 
-#define NZEXT 2
-static const char *z_ext[NZEXT] =
-{ ".gz", ".Z" };
-
 const char *ftp2ext(int ftp)
 {
     if ((0 <= ftp) && (ftp < efNR))
@@ -276,28 +255,22 @@ const char *ftp2desc(int ftp)
     }
 }
 
-const char *ftp2ftype(int ftp)
+gmx_bool ftp_is_text(int ftp)
 {
     if ((ftp >= 0) && (ftp < efNR))
     {
-        switch (deffile[ftp].ftype)
-        {
-            case eftASC:
-                return "ASCII";
-            case eftBIN:
-                return "Binary";
-            case eftXDR:
-                return "XDR portable";
-            case eftTNG:
-                return "TNG";
-            case eftGEN:
-                return "";
-            default:
-                gmx_fatal(FARGS, "Unknown filetype %d in ftp2ftype", deffile[ftp].ftype);
-                break;
-        }
+        return deffile[ftp].ftype == eftASC;
+    }
+    return FALSE;
+}
+
+gmx_bool ftp_is_xdr(int ftp)
+{
+    if ((ftp >= 0) && (ftp < efNR))
+    {
+        return deffile[ftp].ftype == eftXDR;
     }
-    return "unknown";
+    return FALSE;
 }
 
 const char *ftp2defnm(int ftp)
@@ -335,7 +308,7 @@ int fn2ftp(const char *fn)
         return efNR;
     }
 
-    len = strlen(fn);
+    len = std::strlen(fn);
     if ((len >= 4) && (fn[len - 4] == '.'))
     {
         feptr = &(fn[len - 4]);
@@ -365,7 +338,7 @@ const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
 
     for (i = 0; (i < nfile); i++)
     {
-        if (strcmp(opt, fnm[i].opt) == 0)
+        if (std::strcmp(opt, fnm[i].opt) == 0)
         {
             return fnm[i].fns[0];
         }
@@ -455,7 +428,7 @@ gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[])
 
     for (i = 0; (i < nfile); i++)
     {
-        if (strcmp(opt, fnm[i].opt) == 0)
+        if (std::strcmp(opt, fnm[i].opt) == 0)
         {
             return (gmx_bool) IS_SET(fnm[i]);
         }
@@ -472,7 +445,7 @@ const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[])
 
     for (i = 0; (i < nfile); i++)
     {
-        if (strcmp(opt, fnm[i].opt) == 0)
+        if (std::strcmp(opt, fnm[i].opt) == 0)
         {
             if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
             {
@@ -527,7 +500,7 @@ gmx_bool is_set(const t_filenm *fnm)
 
 int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
 {
-    int   i, j, pos;
+    int   i, j;
     char  buf[STRLEN], newname[STRLEN];
     char *extpos;
 
@@ -539,7 +512,7 @@ int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
                for it, just in case... */
             for (j = 0; j < fnm[i].nfiles; j++)
             {
-                strncpy(buf, fnm[i].fns[j], STRLEN - 1);
+                std::strncpy(buf, fnm[i].fns[j], STRLEN - 1);
                 extpos  = strrchr(buf, '.');
                 *extpos = '\0';
                 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
index dbd2bf730b3d3c044736482b8a4e0ad28e57c7a0..283f99f0436175c6e3e57fdfac1bf503d3395602 100644 (file)
@@ -45,8 +45,8 @@
 extern "C" {
 #endif
 
-/* this enum should correspond to the array deffile in gmxlib/filenm.c */
-enum {
+/* this enum should correspond to the array deffile in filenm.cpp */
+enum GromacsFileType {
     efMDP,
     efTRX, efTRO, efTRN, efTRR, efCOMPRESSED, efXTC, efTNG,
     efEDR,
@@ -119,8 +119,8 @@ const char *ftp2defnm(int ftp);
 const char *ftp2defopt(int ftp);
 /* Return default option name for file type */
 
-const char *ftp2ftype(int ftp);
-/* Return Binary or ASCII depending on file type */
+gmx_bool ftp_is_text(int ftp);
+gmx_bool ftp_is_xdr(int ftp);
 
 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[]);
 /* Return the filename belonging to cmd-line option opt, or NULL when
diff --git a/src/gromacs/fileio/g96io.cpp b/src/gromacs/fileio/g96io.cpp
new file mode 100644 (file)
index 0000000..d7404c4
--- /dev/null
@@ -0,0 +1,470 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gmxpre.h"
+
+#include "g96io.h"
+
+#include <cstdio>
+#include <cstring>
+
+#include "gromacs/fileio/trx.h"
+#include "gromacs/fileio/trxio.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
+
+#define CHAR_SHIFT 24
+
+static int read_g96_pos(char line[], t_symtab *symtab,
+                        FILE *fp, const char *infile,
+                        t_trxframe *fr)
+{
+    t_atoms   *atoms;
+    gmx_bool   bEnd;
+    int        nwanted, natoms, atnr, resnr = 0, oldres, newres, shift;
+    char       anm[STRLEN], resnm[STRLEN];
+    char       c1, c2;
+    double     db1, db2, db3;
+
+    nwanted = fr->natoms;
+
+    atoms = fr->atoms;
+
+    natoms = 0;
+
+    if (fr->bX)
+    {
+        if (fr->bAtoms)
+        {
+            shift = CHAR_SHIFT;
+        }
+        else
+        {
+            shift = 0;
+        }
+        newres  = -1;
+        oldres  = -666; /* Unlikely number for the first residue! */
+        bEnd    = FALSE;
+        while (!bEnd && fgets2(line, STRLEN, fp))
+        {
+            bEnd = (std::strncmp(line, "END", 3) == 0);
+            if (!bEnd  && (line[0] != '#'))
+            {
+                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
+                {
+                    gmx_fatal(FARGS, "Did not find 3 coordinates for atom %d in %s\n",
+                              natoms+1, infile);
+                }
+                if ((nwanted != -1) && (natoms >= nwanted))
+                {
+                    gmx_fatal(FARGS,
+                              "Found more coordinates (%d) in %s than expected %d\n",
+                              natoms, infile, nwanted);
+                }
+                if (atoms)
+                {
+                    if (fr->bAtoms &&
+                        (sscanf(line, "%5d%c%5s%c%5s%7d", &resnr, &c1, resnm, &c2, anm, &atnr)
+                         != 6))
+                    {
+                        if (oldres >= 0)
+                        {
+                            resnr = oldres;
+                        }
+                        else
+                        {
+                            resnr    = 1;
+                            strncpy(resnm, "???", sizeof(resnm)-1);
+                        }
+                        strncpy(anm, "???", sizeof(anm)-1);
+                    }
+                    atoms->atomname[natoms] = put_symtab(symtab, anm);
+                    if (resnr != oldres)
+                    {
+                        oldres = resnr;
+                        newres++;
+                        if (newres >= atoms->nr)
+                        {
+                            gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
+                                      infile, atoms->nr);
+                        }
+                        atoms->atom[natoms].resind = newres;
+                        if (newres+1 > atoms->nres)
+                        {
+                            atoms->nres = newres+1;
+                        }
+                        t_atoms_set_resinfo(atoms, natoms, symtab, resnm, resnr, ' ', 0, ' ');
+                    }
+                    else
+                    {
+                        atoms->atom[natoms].resind = newres;
+                    }
+                }
+                if (fr->x)
+                {
+                    fr->x[natoms][0] = db1;
+                    fr->x[natoms][1] = db2;
+                    fr->x[natoms][2] = db3;
+                }
+                natoms++;
+            }
+        }
+        if ((nwanted != -1) && natoms != nwanted)
+        {
+            fprintf(stderr,
+                    "Warning: found less coordinates (%d) in %s than expected %d\n",
+                    natoms, infile, nwanted);
+        }
+    }
+
+    fr->natoms = natoms;
+
+    return natoms;
+}
+
+static int read_g96_vel(char line[], FILE *fp, const char *infile,
+                        t_trxframe *fr)
+{
+    gmx_bool   bEnd;
+    int        nwanted, natoms = -1, shift;
+    double     db1, db2, db3;
+
+    nwanted = fr->natoms;
+
+    if (fr->v && fr->bV)
+    {
+        if (strcmp(line, "VELOCITYRED") == 0)
+        {
+            shift = 0;
+        }
+        else
+        {
+            shift = CHAR_SHIFT;
+        }
+        natoms = 0;
+        bEnd   = FALSE;
+        while (!bEnd && fgets2(line, STRLEN, fp))
+        {
+            bEnd = (strncmp(line, "END", 3) == 0);
+            if (!bEnd && (line[0] != '#'))
+            {
+                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
+                {
+                    gmx_fatal(FARGS, "Did not find 3 velocities for atom %d in %s",
+                              natoms+1, infile);
+                }
+                if ((nwanted != -1) && (natoms >= nwanted))
+                {
+                    gmx_fatal(FARGS, "Found more velocities (%d) in %s than expected %d\n",
+                              natoms, infile, nwanted);
+                }
+                if (fr->v)
+                {
+                    fr->v[natoms][0] = db1;
+                    fr->v[natoms][1] = db2;
+                    fr->v[natoms][2] = db3;
+                }
+                natoms++;
+            }
+        }
+        if ((nwanted != -1) && (natoms != nwanted))
+        {
+            fprintf(stderr,
+                    "Warning: found less velocities (%d) in %s than expected %d\n",
+                    natoms, infile, nwanted);
+        }
+    }
+
+    return natoms;
+}
+
+int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line)
+{
+    t_symtab  *symtab = NULL;
+    gmx_bool   bAtStart, bTime, bAtoms, bPos, bVel, bBox, bEnd, bFinished;
+    int        natoms, nbp;
+    double     db1, db2, db3, db4, db5, db6, db7, db8, db9;
+
+    bAtStart = (ftell(fp) == 0);
+
+    clear_trxframe(fr, FALSE);
+
+    if (!symtab)
+    {
+        snew(symtab, 1);
+        open_symtab(symtab);
+    }
+
+    natoms = 0;
+
+    if (bAtStart)
+    {
+        while (!fr->bTitle && fgets2(line, STRLEN, fp))
+        {
+            fr->bTitle = (std::strcmp(line, "TITLE") == 0);
+        }
+        if (fr->title == NULL)
+        {
+            fgets2(line, STRLEN, fp);
+            fr->title = gmx_strdup(line);
+        }
+        bEnd = FALSE;
+        while (!bEnd && fgets2(line, STRLEN, fp))
+        {
+            bEnd = (std::strcmp(line, "END") == 0);
+        }
+        fgets2(line, STRLEN, fp);
+    }
+
+    /* Do not get a line if we are not at the start of the file, *
+     * because without a parameter file we don't know what is in *
+     * the trajectory and we have already read the line in the   *
+     * previous call (VERY DIRTY).                               */
+    bFinished = FALSE;
+    do
+    {
+        bTime  = (std::strcmp(line, "TIMESTEP") == 0);
+        bAtoms = (std::strcmp(line, "POSITION") == 0);
+        bPos   = (bAtoms || (strcmp(line, "POSITIONRED") == 0));
+        bVel   = (std::strncmp(line, "VELOCITY", 8) == 0);
+        bBox   = (std::strcmp(line, "BOX") == 0);
+        if (bTime)
+        {
+            if (!fr->bTime && !fr->bX)
+            {
+                fr->bStep = bTime;
+                fr->bTime = bTime;
+                do
+                {
+                    bFinished = (fgets2(line, STRLEN, fp) == NULL);
+                }
+                while (!bFinished && (line[0] == '#'));
+                sscanf(line, "%15d%15lf", &(fr->step), &db1);
+                fr->time = db1;
+            }
+            else
+            {
+                bFinished = TRUE;
+            }
+        }
+        if (bPos)
+        {
+            if (!fr->bX)
+            {
+                fr->bAtoms = bAtoms;
+                fr->bX     = bPos;
+                natoms     = read_g96_pos(line, symtab, fp, infile, fr);
+            }
+            else
+            {
+                bFinished = TRUE;
+            }
+        }
+        if (fr->v && bVel)
+        {
+            fr->bV = bVel;
+            natoms = read_g96_vel(line, fp, infile, fr);
+        }
+        if (bBox)
+        {
+            fr->bBox = bBox;
+            clear_mat(fr->box);
+            bEnd = FALSE;
+            while (!bEnd && fgets2(line, STRLEN, fp))
+            {
+                bEnd = (strncmp(line, "END", 3) == 0);
+                if (!bEnd && (line[0] != '#'))
+                {
+                    nbp = sscanf(line, "%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf%15lf",
+                                 &db1, &db2, &db3, &db4, &db5, &db6, &db7, &db8, &db9);
+                    if (nbp < 3)
+                    {
+                        gmx_fatal(FARGS, "Found a BOX line, but no box in %s", infile);
+                    }
+                    fr->box[XX][XX] = db1;
+                    fr->box[YY][YY] = db2;
+                    fr->box[ZZ][ZZ] = db3;
+                    if (nbp == 9)
+                    {
+                        fr->box[XX][YY] = db4;
+                        fr->box[XX][ZZ] = db5;
+                        fr->box[YY][XX] = db6;
+                        fr->box[YY][ZZ] = db7;
+                        fr->box[ZZ][XX] = db8;
+                        fr->box[ZZ][YY] = db9;
+                    }
+                }
+            }
+            bFinished = TRUE;
+        }
+    }
+    while (!bFinished && fgets2(line, STRLEN, fp));
+
+    free_symtab(symtab);
+
+    fr->natoms = natoms;
+
+    return natoms;
+}
+
+void write_g96_conf(FILE *out, t_trxframe *fr,
+                    int nindex, const atom_id *index)
+{
+    t_atoms *atoms;
+    int      nout, i, a;
+
+    atoms = fr->atoms;
+
+    if (index)
+    {
+        nout = nindex;
+    }
+    else
+    {
+        nout = fr->natoms;
+    }
+
+    if (fr->bTitle)
+    {
+        fprintf(out, "TITLE\n%s\nEND\n", fr->title);
+    }
+    if (fr->bStep || fr->bTime)
+    {
+        /* Officially the time format is %15.9, which is not enough for 10 ns */
+        fprintf(out, "TIMESTEP\n%15d%15.6f\nEND\n", fr->step, fr->time);
+    }
+    if (fr->bX)
+    {
+        if (fr->bAtoms)
+        {
+            fprintf(out, "POSITION\n");
+            for (i = 0; i < nout; i++)
+            {
+                if (index)
+                {
+                    a = index[i];
+                }
+                else
+                {
+                    a = i;
+                }
+                fprintf(out, "%5d %-5s %-5s%7d%15.9f%15.9f%15.9f\n",
+                        (atoms->resinfo[atoms->atom[a].resind].nr) % 100000,
+                        *atoms->resinfo[atoms->atom[a].resind].name,
+                        *atoms->atomname[a], (i+1) % 10000000,
+                        fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
+            }
+        }
+        else
+        {
+            fprintf(out, "POSITIONRED\n");
+            for (i = 0; i < nout; i++)
+            {
+                if (index)
+                {
+                    a = index[i];
+                }
+                else
+                {
+                    a = i;
+                }
+                fprintf(out, "%15.9f%15.9f%15.9f\n",
+                        fr->x[a][XX], fr->x[a][YY], fr->x[a][ZZ]);
+            }
+        }
+        fprintf(out, "END\n");
+    }
+    if (fr->bV)
+    {
+        if (fr->bAtoms)
+        {
+            fprintf(out, "VELOCITY\n");
+            for (i = 0; i < nout; i++)
+            {
+                if (index)
+                {
+                    a = index[i];
+                }
+                else
+                {
+                    a = i;
+                }
+                fprintf(out, "%5d %-5s %-5s%7d%15.9f%15.9f%15.9f\n",
+                        (atoms->resinfo[atoms->atom[a].resind].nr) % 100000,
+                        *atoms->resinfo[atoms->atom[a].resind].name,
+                        *atoms->atomname[a], (i+1) % 10000000,
+                        fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
+            }
+        }
+        else
+        {
+            fprintf(out, "VELOCITYRED\n");
+            for (i = 0; i < nout; i++)
+            {
+                if (index)
+                {
+                    a = index[i];
+                }
+                else
+                {
+                    a = i;
+                }
+                fprintf(out, "%15.9f%15.9f%15.9f\n",
+                        fr->v[a][XX], fr->v[a][YY], fr->v[a][ZZ]);
+            }
+        }
+        fprintf(out, "END\n");
+    }
+    if (fr->bBox)
+    {
+        fprintf(out, "BOX\n");
+        fprintf(out, "%15.9f%15.9f%15.9f",
+                fr->box[XX][XX], fr->box[YY][YY], fr->box[ZZ][ZZ]);
+        if (fr->box[XX][YY] || fr->box[XX][ZZ] || fr->box[YY][XX] ||
+            fr->box[YY][ZZ] || fr->box[ZZ][XX] || fr->box[ZZ][YY])
+        {
+            fprintf(out, "%15.9f%15.9f%15.9f%15.9f%15.9f%15.9f",
+                    fr->box[XX][YY], fr->box[XX][ZZ], fr->box[YY][XX],
+                    fr->box[YY][ZZ], fr->box[ZZ][XX], fr->box[ZZ][YY]);
+        }
+        fprintf(out, "\n");
+        fprintf(out, "END\n");
+    }
+}
diff --git a/src/gromacs/fileio/g96io.h b/src/gromacs/fileio/g96io.h
new file mode 100644 (file)
index 0000000..c936883
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_FILEIO_G96IO_H
+#define GMX_FILEIO_G96IO_H
+
+#include <stdio.h>
+
+#include "gromacs/legacyheaders/types/simple.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct t_trxframe;
+
+int read_g96_conf(FILE *fp, const char *infile, struct t_trxframe *fr, char *line);
+/* read a Gromos96 coordinate or trajectory file,                       *
+ * returns the number of atoms                                          *
+ * sets what's in the frame in info                                     *
+ * read from fp, infile is only needed for error messages               *
+ * nwanted is the number of wanted coordinates,                         *
+ * set this to -1 if you want to know the number of atoms in the file   *
+ * title, atoms, x, v can all be NULL, in which case they won't be read *
+ * line holds the previous line for trajectory reading                  */
+
+void write_g96_conf(FILE *out, struct t_trxframe *fr, int nindex, const atom_id *index);
+/* write a Gromos96 coordinate file or trajectory frame *
+ * index can be NULL                                    */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
similarity index 86%
rename from src/gromacs/fileio/gmx_system_xdr.c
rename to src/gromacs/fileio/gmx_internal_xdr.cpp
index 0a86fa9c23f8622eb771487e7d9d8850f35740b6..d711909f3a615032b5db619f086673ff8e22d337 100644 (file)
 
 #include "config.h"
 
-#ifdef GMX_INTERNAL_XDR
+#if GMX_INTERNAL_XDR
 
 
-#include "gmx_system_xdr.h"
+#include "gmx_internal_xdr.h"
 
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
 
 
 /* NB - THIS FILE IS ONLY USED ON MICROSOFT WINDOWS, since that
@@ -103,8 +102,8 @@ static xdr_uint32_t xdr_swapbytes(xdr_uint32_t x)
 {
     xdr_uint32_t y;
     int          i;
-    char        *px = (char *)&x;
-    char        *py = (char *)&y;
+    char        *px = reinterpret_cast<char *>(&x);
+    char        *py = reinterpret_cast<char *>(&y);
 
     for (i = 0; i < 4; i++)
     {
@@ -117,7 +116,7 @@ static xdr_uint32_t xdr_swapbytes(xdr_uint32_t x)
 static xdr_uint32_t xdr_htonl(xdr_uint32_t x)
 {
     short s = 0x0F00;
-    if (*((char *)&s) == (char)0x0F)
+    if (*(reinterpret_cast<char *>(&s)) == static_cast<char>(0x0F))
     {
         /* bigendian, do nothing */
         return x;
@@ -132,7 +131,7 @@ static xdr_uint32_t xdr_htonl(xdr_uint32_t x)
 static xdr_uint32_t xdr_ntohl(xdr_uint32_t x)
 {
     short s = 0x0F00;
-    if (*((char *)&s) == (char)0x0F)
+    if (*(reinterpret_cast<char *>(&s)) == static_cast<char>(0x0F))
     {
         /* bigendian, do nothing */
         return x;
@@ -178,7 +177,7 @@ xdr_int (XDR *xdrs, int *ip)
     switch (xdrs->x_op)
     {
         case XDR_ENCODE:
-            l = (xdr_int32_t) (*ip);
+            l = static_cast<xdr_int32_t>(*ip);
             return xdr_putint32 (xdrs, &l);
 
         case XDR_DECODE:
@@ -186,7 +185,7 @@ xdr_int (XDR *xdrs, int *ip)
             {
                 return FALSE;
             }
-            *ip = (int) l;
+            *ip = static_cast<int>(l);
 
         case XDR_FREE:
             return TRUE;
@@ -206,7 +205,7 @@ xdr_u_int (XDR *xdrs, unsigned int *up)
     switch (xdrs->x_op)
     {
         case XDR_ENCODE:
-            l = (xdr_uint32_t) (*up);
+            l = static_cast<xdr_uint32_t>(*up);
             return xdr_putuint32 (xdrs, &l);
 
         case XDR_DECODE:
@@ -214,7 +213,7 @@ xdr_u_int (XDR *xdrs, unsigned int *up)
             {
                 return FALSE;
             }
-            *up = (unsigned int) l;
+            *up = static_cast<unsigned int>(l);
 
         case XDR_FREE:
             return TRUE;
@@ -236,7 +235,7 @@ xdr_short (XDR *xdrs, short *sp)
     switch (xdrs->x_op)
     {
         case XDR_ENCODE:
-            l = (xdr_int32_t) *sp;
+            l = static_cast<xdr_int32_t>(*sp);
             return xdr_putint32 (xdrs, &l);
 
         case XDR_DECODE:
@@ -244,7 +243,7 @@ xdr_short (XDR *xdrs, short *sp)
             {
                 return FALSE;
             }
-            *sp = (short) l;
+            *sp = static_cast<short>(l);
             return TRUE;
 
         case XDR_FREE:
@@ -265,7 +264,7 @@ xdr_u_short (XDR *xdrs, unsigned short *usp)
     switch (xdrs->x_op)
     {
         case XDR_ENCODE:
-            l = (xdr_uint32_t) *usp;
+            l = static_cast<xdr_uint32_t>(*usp);
             return xdr_putuint32 (xdrs, &l);
 
         case XDR_DECODE:
@@ -273,7 +272,7 @@ xdr_u_short (XDR *xdrs, unsigned short *usp)
             {
                 return FALSE;
             }
-            *usp = (unsigned short) l;
+            *usp = static_cast<unsigned short>(l);
             return TRUE;
 
         case XDR_FREE:
@@ -391,7 +390,7 @@ xdr_opaque (XDR *xdrs, char *cp, unsigned int cnt)
             {
                 return TRUE;
             }
-            return xdr_getbytes (xdrs, (char *)crud, rndup);
+            return xdr_getbytes (xdrs, crud, rndup);
 
         case XDR_ENCODE:
             if (!xdr_putbytes (xdrs, cp, cnt))
@@ -419,11 +418,7 @@ xdr_opaque (XDR *xdrs, char *cp, unsigned int cnt)
  * storage is allocated.  The last parameter is the max allowed length
  * of the string as specified by a protocol.
  */
-bool_t
-xdr_string (xdrs, cpp, maxsize)
-XDR *xdrs;
-char       **cpp;
-unsigned int maxsize;
+bool_t xdr_string (XDR *xdrs, char ** cpp, unsigned int maxsize)
 {
     char        *sp       = *cpp; /* sp is the actual string pointer */
     unsigned int size     = 0;
@@ -445,7 +440,7 @@ unsigned int maxsize;
             {
                 return FALSE;
             }
-            size = strlen (sp);
+            size = std::strlen (sp);
             break;
         case XDR_DECODE:
             break;
@@ -473,7 +468,7 @@ unsigned int maxsize;
             }
             if (sp == NULL)
             {
-                *cpp = sp = (char *) malloc (nodesize);
+                *cpp = sp = static_cast<char *>(std::malloc (nodesize));
             }
             if (sp == NULL)
             {
@@ -498,10 +493,7 @@ unsigned int maxsize;
 
 /* Floating-point stuff */
 
-bool_t
-xdr_float(xdrs, fp)
-XDR *xdrs;
-float *fp;
+bool_t xdr_float(XDR * xdrs, float * fp)
 {
     xdr_int32_t tmp;
 
@@ -509,7 +501,7 @@ float *fp;
     {
 
         case XDR_ENCODE:
-            tmp = *(xdr_int32_t *)fp;
+            tmp = *(reinterpret_cast<xdr_int32_t *>(fp));
             return (xdr_putint32(xdrs, &tmp));
 
             break;
@@ -517,7 +509,7 @@ float *fp;
         case XDR_DECODE:
             if (xdr_getint32(xdrs, &tmp))
             {
-                *(xdr_int32_t *)fp = tmp;
+                *(reinterpret_cast<xdr_int32_t *>(fp)) = tmp;
                 return (TRUE);
             }
 
@@ -530,10 +522,7 @@ float *fp;
 }
 
 
-bool_t
-xdr_double(xdrs, dp)
-XDR *xdrs;
-double *dp;
+bool_t xdr_double(XDR * xdrs, double * dp)
 {
 
     /* Windows and some other systems dont define double-precision
@@ -564,7 +553,7 @@ double *dp;
          *     B           B       3f ef 9a dd 3c 0e 56 b8
          */
 
-        unsigned char ix = *((char *)&x);
+        unsigned char ix = *(reinterpret_cast<char *>(&x));
 
         if (ix == 0xdd || ix == 0x3f)
         {
@@ -588,7 +577,7 @@ double *dp;
     {
 
         case XDR_ENCODE:
-            ip     = (int *)dp;
+            ip     = reinterpret_cast<int *>(dp);
             tmp[0] = ip[!LSW];
             tmp[1] = ip[LSW];
             return (xdr_putint32(xdrs, tmp) &&
@@ -597,7 +586,7 @@ double *dp;
             break;
 
         case XDR_DECODE:
-            ip = (int *)dp;
+            ip = reinterpret_cast<int *>(dp);
             if (xdr_getint32(xdrs, tmp+!LSW) &&
                 xdr_getint32(xdrs, tmp+LSW))
             {
@@ -627,13 +616,8 @@ double *dp;
  * > elemsize: size of each element
  * > xdr_elem: routine to XDR each element
  */
-bool_t
-xdr_vector (xdrs, basep, nelem, elemsize, xdr_elem)
-XDR *xdrs;
-char        *basep;
-unsigned int nelem;
-unsigned int elemsize;
-xdrproc_t    xdr_elem;
+bool_t xdr_vector (XDR * xdrs, char * basep, unsigned int nelem,
+                   unsigned int elemsize, xdrproc_t xdr_elem)
 {
 #define LASTUNSIGNED    ((unsigned int)0-1)
     unsigned int i;
@@ -665,40 +649,6 @@ static bool_t xdrstdio_putint32 (XDR *, xdr_int32_t *);
 static bool_t xdrstdio_getuint32 (XDR *, xdr_uint32_t *);
 static bool_t xdrstdio_putuint32 (XDR *, xdr_uint32_t *);
 
-/*
- * Ops vector for stdio type XDR
- */
-static const struct xdr_ops xdrstdio_ops =
-{
-    xdrstdio_getbytes,  /* deserialize counted bytes */
-    xdrstdio_putbytes,  /* serialize counted bytes */
-    xdrstdio_getpos,    /* get offset in the stream */
-    xdrstdio_setpos,    /* set offset in the stream */
-    xdrstdio_inline,    /* prime stream for inline macros */
-    xdrstdio_destroy,   /* destroy stream */
-    xdrstdio_getint32,  /* deserialize a int */
-    xdrstdio_putint32,  /* serialize a int */
-    xdrstdio_getuint32, /* deserialize a int */
-    xdrstdio_putuint32  /* serialize a int */
-};
-
-/*
- * Initialize a stdio xdr stream.
- * Sets the xdr stream handle xdrs for use on the stream file.
- * Operation flag is set to op.
- */
-void
-xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op)
-{
-    xdrs->x_op = op;
-    /* We have to add the const since the `struct xdr_ops' in `struct XDR'
-       is not `const'.  */
-    xdrs->x_ops     = (struct xdr_ops *) &xdrstdio_ops;
-    xdrs->x_private = (char *) file;
-    xdrs->x_handy   = 0;
-    xdrs->x_base    = 0;
-}
-
 /*
  * Destroy a stdio xdr stream.
  * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
@@ -706,7 +656,7 @@ xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op)
 static void
 xdrstdio_destroy (XDR *xdrs)
 {
-    (void) fflush ((FILE *) xdrs->x_private);
+    fflush (reinterpret_cast<FILE *>(xdrs->x_private));
     /* xx should we close the file ?? */
 }
 
@@ -714,8 +664,8 @@ xdrstdio_destroy (XDR *xdrs)
 static bool_t
 xdrstdio_getbytes (XDR *xdrs, char *addr, unsigned int len)
 {
-    if ((len != 0) && (fread (addr, (int) len, 1,
-                              (FILE *) xdrs->x_private) != 1))
+    if ((len != 0) && (fread (addr, static_cast<int>(len), 1,
+                              reinterpret_cast<FILE *>(xdrs->x_private)) != 1))
     {
         return FALSE;
     }
@@ -725,8 +675,8 @@ xdrstdio_getbytes (XDR *xdrs, char *addr, unsigned int len)
 static bool_t
 xdrstdio_putbytes (XDR *xdrs, char *addr, unsigned int len)
 {
-    if ((len != 0) && (fwrite (addr, (int) len, 1,
-                               (FILE *) xdrs->x_private) != 1))
+    if ((len != 0) && (fwrite (addr, static_cast<int>(len), 1,
+                               reinterpret_cast<FILE *>(xdrs->x_private)) != 1))
     {
         return FALSE;
     }
@@ -736,13 +686,13 @@ xdrstdio_putbytes (XDR *xdrs, char *addr, unsigned int len)
 static unsigned int
 xdrstdio_getpos (XDR *xdrs)
 {
-    return (unsigned int) ftell ((FILE *) xdrs->x_private);
+    return static_cast<int>(ftell (reinterpret_cast<FILE *>(xdrs->x_private)));
 }
 
 static bool_t
 xdrstdio_setpos (XDR *xdrs, unsigned int pos)
 {
-    return fseek ((FILE *) xdrs->x_private, (xdr_int32_t) pos, 0) < 0 ? FALSE : TRUE;
+    return fseek (reinterpret_cast<FILE *>(xdrs->x_private), static_cast<xdr_int32_t>(pos), 0) < 0 ? FALSE : TRUE;
 }
 
 static xdr_int32_t *
@@ -767,7 +717,7 @@ xdrstdio_getint32 (XDR *xdrs, xdr_int32_t *ip)
 {
     xdr_int32_t mycopy;
 
-    if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+    if (fread (&mycopy, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
     {
         return FALSE;
     }
@@ -781,7 +731,7 @@ xdrstdio_putint32 (XDR *xdrs, xdr_int32_t *ip)
     xdr_int32_t mycopy = xdr_htonl (*ip);
 
     ip = &mycopy;
-    if (fwrite ((char *) ip, 4, 1, (FILE *) xdrs->x_private) != 1)
+    if (fwrite (ip, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
     {
         return FALSE;
     }
@@ -793,7 +743,7 @@ xdrstdio_getuint32 (XDR *xdrs, xdr_uint32_t *ip)
 {
     xdr_uint32_t mycopy;
 
-    if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+    if (fread (&mycopy, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
     {
         return FALSE;
     }
@@ -807,14 +757,45 @@ xdrstdio_putuint32 (XDR *xdrs, xdr_uint32_t *ip)
     xdr_uint32_t mycopy = xdr_htonl (*ip);
 
     ip = &mycopy;
-    if (fwrite ((char *) ip, 4, 1, (FILE *) xdrs->x_private) != 1)
+    if (fwrite (ip, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
     {
         return FALSE;
     }
     return TRUE;
 }
 
+/*
+ * Ops vector for stdio type XDR
+ */
+static struct XDR::xdr_ops xdrstdio_ops =
+{
+    xdrstdio_getbytes,  /* deserialize counted bytes */
+    xdrstdio_putbytes,  /* serialize counted bytes */
+    xdrstdio_getpos,    /* get offset in the stream */
+    xdrstdio_setpos,    /* set offset in the stream */
+    xdrstdio_inline,    /* prime stream for inline macros */
+    xdrstdio_destroy,   /* destroy stream */
+    xdrstdio_getint32,  /* deserialize a int */
+    xdrstdio_putint32,  /* serialize a int */
+    xdrstdio_getuint32, /* deserialize a int */
+    xdrstdio_putuint32  /* serialize a int */
+};
+
+/*
+ * Initialize a stdio xdr stream.
+ * Sets the xdr stream handle xdrs for use on the stream file.
+ * Operation flag is set to op.
+ */
+void
+xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op)
+{
+    xdrs->x_op           = op;
+    xdrs->x_ops          = &xdrstdio_ops;
+    xdrs->x_private      = reinterpret_cast<char *>(file);
+    xdrs->x_handy        = 0;
+    xdrs->x_base         = 0;
+}
+
 #else
-int
-    gmx_system_xdr_empty;
-#endif /* GMX_SYSTEM_XDR */
+int gmx_internal_xdr_empty;
+#endif /* GMX_INTERNAL_XDR */
similarity index 98%
rename from src/gromacs/fileio/gmx_system_xdr.h
rename to src/gromacs/fileio/gmx_internal_xdr.h
index 23e156bec7eb487375a8950afacc98d5435abdee..bc38df8afd14a97c2b8c206fcee338d745343696 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_FILEIO_GMX_SYSTEM_XDR_H
 #define GMX_FILEIO_GMX_SYSTEM_XDR_H
 
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
 
 /*
  * This header file is ONLY used on windows systems, since these do
similarity index 63%
rename from src/gromacs/fileio/gmxfio_int.h
rename to src/gromacs/fileio/gmxfio-impl.h
index e7010b15f32fbecc34189362cb6f11e9712f0f16..0b455979dd6fb23c18c77202b81a6fe2e97349c6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifndef GMX_FILEIO_GMXFIO_INT_H
-#define GMX_FILEIO_GMXFIO_INT_H
+/*! \internal \file
+ * \brief
+ * Internal definitions shared by gmxfio*.c files.
+ */
+#ifndef GMX_FILEIO_GMXFIO_IMPL_H
+#define GMX_FILEIO_GMXFIO_IMPL_H
 
 /* This is the new improved and thread safe version of gmxfio.  */
 
 
    WARNING WARNING WARNING WARNING */
 
-
-/* XDR should be available on all platforms now,
- * but we keep the possibility of turning it off...
- */
-#define USE_XDR
-
 #include "thread_mpi/lock.h"
 
 #include "gromacs/fileio/xdrf.h"
 
-/* the reader/writer functions  for t_iotype */
-typedef gmx_bool read_func (t_fileio *fio, void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line);
-typedef gmx_bool write_func (t_fileio *fio, const void *item, int nitem, int eio,
-                             const char *desc, const char *srcfile, int line);
-
-
-/* these are pointers to the actual reading & writing functions */
-typedef struct
-{
-    read_func  *nread;
-    write_func *nwrite;
-} t_iotype;
-
-
-
 struct t_fileio
 {
     FILE           *fp;                /* the file pointer */
-    const t_iotype *iotp;              /* file type */
-    gmx_bool        bOpen,             /* the file is open */
-                    bRead,             /* the file is open for reading */
+    gmx_bool        bRead,             /* the file is open for reading */
                     bDouble,           /* write doubles instead of floats */
-                    bDebug,            /* the file ops should come with debug info */
-                    bStdio,            /* the file is actually stdin or stdout */
                     bReadWrite;        /* the file is open for reading and writing */
     char        *fn;                   /* the file name */
     XDR         *xdr;                  /* the xdr data pointer */
     enum xdr_op  xdrmode;              /* the xdr mode */
     int          iFTP;                 /* the file type identifier */
 
-    const char  *comment;              /* a comment string for debugging */
-
     t_fileio    *next, *prev;          /* next and previous file pointers in the
                                           linked list */
     tMPI_Lock_t  mtx;                  /* content locking mutex. This is a fast lock
@@ -101,30 +77,9 @@ struct t_fileio
                                           a lock */
 };
 
-
-
-extern const t_iotype asc_iotype;
-extern const t_iotype bin_iotype;
-extern const t_iotype xdr_iotype;
-extern const t_iotype dummy_iotype;
-
-extern const char    *eioNames[eioNR];
-
-
-
-#define GMX_FIO_BUFLEN 256
-
-/* make a debug string if that is requested in the fio */
-const char *gmx_fio_dbgstr(t_fileio *fio, const char *desc, char *buf);
-/* check the number of items against the allowed number of items */
-void gmx_fio_check_nitem(int eio, int nitem, const char *file,
-                         int line);
-/* check the output type against allowed values */
-void gmx_fio_fe(t_fileio *fio, int eio, const char *desc, const char *srcfile,
-                int line);
-
-/* lock/unlock the mutex associated with a fio  */
+/** lock the mutex associated with a fio  */
 void gmx_fio_lock(t_fileio *fio);
+/** unlock the mutex associated with a fio  */
 void gmx_fio_unlock(t_fileio *fio);
 
 #endif
diff --git a/src/gromacs/fileio/gmxfio-xdr.cpp b/src/gromacs/fileio/gmxfio-xdr.cpp
new file mode 100644 (file)
index 0000000..0d3b70b
--- /dev/null
@@ -0,0 +1,674 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gmxpre.h"
+
+#include "gmxfio-xdr.h"
+
+#include <cstdio>
+#include <cstring>
+
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/xdrf.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/smalloc.h"
+
+#include "gmxfio-impl.h"
+
+/* Enumerated for data types in files */
+enum {
+    eioREAL, eioFLOAT, eioDOUBLE, eioINT, eioINT64,
+    eioUCHAR, eioNUCHAR, eioUSHORT,
+    eioRVEC, eioNRVEC, eioIVEC, eioSTRING, eioNR
+};
+
+static const char *eioNames[eioNR] =
+{
+    "REAL", "INT", "GMX_STE_T", "UCHAR", "NUCHAR", "USHORT", "RVEC", "NRVEC",
+    "IVEC", "STRING"
+};
+
+void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble)
+{
+    gmx_fio_lock(fio);
+    fio->bDouble = bDouble;
+    gmx_fio_unlock(fio);
+}
+
+XDR *gmx_fio_getxdr(t_fileio *fio)
+{
+    XDR *ret = NULL;
+    gmx_fio_lock(fio);
+    GMX_RELEASE_ASSERT( fio->xdr != NULL, "Implementation error: NULL XDR pointers");
+    ret = fio->xdr;
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+/* check the number of items given against the type */
+static void gmx_fio_check_nitem(int eio, int nitem, const char *file, int line)
+{
+    if ((nitem != 1) && !((eio == eioNRVEC) || (eio == eioNUCHAR)))
+    {
+        gmx_fatal(FARGS,
+                  "nitem (%d) may differ from 1 only for %s or %s, not   for %s"
+                  "(%s, %d)", nitem, eioNames[eioNUCHAR], eioNames[eioNRVEC],
+                  eioNames[eio], file, line);
+    }
+}
+
+/* output a data type error. */
+static void gmx_fio_fe(t_fileio *fio, int eio, const char *desc,
+                       const char *srcfile, int line)
+{
+    gmx_fatal(FARGS, "Trying to %s %s type %d (%s), src %s, line %d",
+              fio->bRead ? "read" : "write", desc, eio,
+              ((eio >= 0) && (eio < eioNR)) ? eioNames[eio] : "unknown",
+              srcfile, line);
+}
+
+/* This is the part that reads xdr files.  */
+
+static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio,
+                       const char *desc, const char *srcfile, int line)
+{
+    unsigned char   ucdum, *ucptr;
+    bool_t          res = 0;
+    float           fvec[DIM];
+    double          dvec[DIM];
+    int             j, m, *iptr, idum;
+    gmx_int64_t     sdum;
+    real           *ptr;
+    unsigned short  us;
+    double          d = 0;
+    float           f = 0;
+
+    GMX_RELEASE_ASSERT( fio->xdr != NULL, "Implementation error: NULL XDR pointers");
+    gmx_fio_check_nitem(eio, nitem, srcfile, line);
+    switch (eio)
+    {
+        case eioREAL:
+            if (fio->bDouble)
+            {
+                if (item && !fio->bRead)
+                {
+                    d = *((real *) item);
+                }
+                res = xdr_double(fio->xdr, &d);
+                if (item)
+                {
+                    *((real *) item) = d;
+                }
+            }
+            else
+            {
+                if (item && !fio->bRead)
+                {
+                    f = *((real *) item);
+                }
+                res = xdr_float(fio->xdr, &f);
+                if (item)
+                {
+                    *((real *) item) = f;
+                }
+            }
+            break;
+        case eioFLOAT:
+            if (item && !fio->bRead)
+            {
+                f = *((float *) item);
+            }
+            res = xdr_float(fio->xdr, &f);
+            if (item)
+            {
+                *((float *) item) = f;
+            }
+            break;
+        case eioDOUBLE:
+            if (item && !fio->bRead)
+            {
+                d = *((double *) item);
+            }
+            res = xdr_double(fio->xdr, &d);
+            if (item)
+            {
+                *((double *) item) = d;
+            }
+            break;
+        case eioINT:
+            if (item && !fio->bRead)
+            {
+                idum = *(int *) item;
+            }
+            res = xdr_int(fio->xdr, &idum);
+            if (item)
+            {
+                *(int *) item = idum;
+            }
+            break;
+        case eioINT64:
+            if (item && !fio->bRead)
+            {
+                sdum = *(gmx_int64_t *) item;
+            }
+            res = xdr_int64(fio->xdr, &sdum);
+            if (item)
+            {
+                *(gmx_int64_t *) item = sdum;
+            }
+            break;
+        case eioUCHAR:
+            if (item && !fio->bRead)
+            {
+                ucdum = *(unsigned char *) item;
+            }
+            res = xdr_u_char(fio->xdr, &ucdum);
+            if (item)
+            {
+                *(unsigned char *) item = ucdum;
+            }
+            break;
+        case eioNUCHAR:
+            ucptr = (unsigned char *) item;
+            res   = 1;
+            for (j = 0; (j < nitem) && res; j++)
+            {
+                res = xdr_u_char(fio->xdr, &(ucptr[j]));
+            }
+            break;
+        case eioUSHORT:
+            if (item && !fio->bRead)
+            {
+                us = *(unsigned short *) item;
+            }
+            res = xdr_u_short(fio->xdr, (unsigned short *) &us);
+            if (item)
+            {
+                *(unsigned short *) item = us;
+            }
+            break;
+        case eioRVEC:
+            if (fio->bDouble)
+            {
+                if (item && !fio->bRead)
+                {
+                    for (m = 0; (m < DIM); m++)
+                    {
+                        dvec[m] = ((real *) item)[m];
+                    }
+                }
+                res = xdr_vector(fio->xdr, (char *) dvec, DIM,
+                                 static_cast<unsigned int>(sizeof(double)),
+                                 (xdrproc_t) xdr_double);
+                if (item)
+                {
+                    for (m = 0; (m < DIM); m++)
+                    {
+                        ((real *) item)[m] = dvec[m];
+                    }
+                }
+            }
+            else
+            {
+                if (item && !fio->bRead)
+                {
+                    for (m = 0; (m < DIM); m++)
+                    {
+                        fvec[m] = ((real *) item)[m];
+                    }
+                }
+                res = xdr_vector(fio->xdr, (char *) fvec, DIM,
+                                 static_cast<unsigned int>(sizeof(float)),
+                                 (xdrproc_t) xdr_float);
+                if (item)
+                {
+                    for (m = 0; (m < DIM); m++)
+                    {
+                        ((real *) item)[m] = fvec[m];
+                    }
+                }
+            }
+            break;
+        case eioNRVEC:
+            ptr = NULL;
+            res = 1;
+            for (j = 0; (j < nitem) && res; j++)
+            {
+                if (item)
+                {
+                    ptr = ((rvec *) item)[j];
+                }
+                res = do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line);
+            }
+            break;
+        case eioIVEC:
+            iptr = (int *) item;
+            res  = 1;
+            for (m = 0; (m < DIM) && res; m++)
+            {
+                if (item && !fio->bRead)
+                {
+                    idum = iptr[m];
+                }
+                res = xdr_int(fio->xdr, &idum);
+                if (item)
+                {
+                    iptr[m] = idum;
+                }
+            }
+            break;
+        case eioSTRING:
+        {
+            char *cptr;
+            int   slen;
+
+            if (item)
+            {
+                if (!fio->bRead)
+                {
+                    slen = strlen((char *) item) + 1;
+                }
+                else
+                {
+                    slen = 0;
+                }
+            }
+            else
+            {
+                slen = 0;
+            }
+
+            if (xdr_int(fio->xdr, &slen) <= 0)
+            {
+                gmx_fatal(FARGS, "wrong string length %d for string %s"
+                          " (source %s, line %d)", slen, desc, srcfile, line);
+            }
+            if (!item && fio->bRead)
+            {
+                snew(cptr, slen);
+            }
+            else
+            {
+                cptr = (char *)item;
+            }
+            if (cptr)
+            {
+                res = xdr_string(fio->xdr, &cptr, slen);
+            }
+            else
+            {
+                res = 1;
+            }
+            if (!item && fio->bRead)
+            {
+                sfree(cptr);
+            }
+            break;
+        }
+        default:
+            gmx_fio_fe(fio, eio, desc, srcfile, line);
+    }
+
+    return (res != 0);
+}
+
+/*******************************************************************
+ *
+ * READ/WRITE FUNCTIONS
+ *
+ *******************************************************************/
+
+gmx_bool gmx_fio_writee_string(t_fileio *fio, const char *item,
+                               const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    void    *it = (void*)item; /* ugh.. */
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, it, 1, eioSTRING, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_real(t_fileio *fio, real *item,
+                          const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioREAL, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+
+}
+
+gmx_bool gmx_fio_doe_float(t_fileio *fio, float *item,
+                           const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioFLOAT, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_double(t_fileio *fio, double *item,
+                            const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioDOUBLE, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+gmx_bool gmx_fio_doe_gmx_bool(t_fileio *fio, gmx_bool *item,
+                              const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+
+    gmx_fio_lock(fio);
+    if (fio->bRead)
+    {
+        int itmp = 0;
+        ret      = do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+        *item    = itmp;
+    }
+    else
+    {
+        int itmp = *item;
+        ret      = do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_int(t_fileio *fio, int *item,
+                         const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioINT, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_int64(t_fileio *fio, gmx_int64_t *item,
+                           const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioINT64, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_uchar(t_fileio *fio, unsigned char *item,
+                           const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioUCHAR, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_ushort(t_fileio *fio, unsigned short *item,
+                            const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioUSHORT, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_rvec(t_fileio *fio, rvec *item,
+                          const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioRVEC, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_ivec(t_fileio *fio, ivec *item,
+                          const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioIVEC, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_doe_string(t_fileio *fio, char *item,
+                            const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret;
+    gmx_fio_lock(fio);
+    ret = do_xdr(fio, item, 1, eioSTRING, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+/* Array reading & writing */
+
+gmx_bool gmx_fio_ndoe_real(t_fileio *fio, real *item, int n,
+                           const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioREAL, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_float(t_fileio *fio, float *item, int n,
+                            const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioFLOAT, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_double(t_fileio *fio, double *item, int n,
+                             const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioDOUBLE, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_gmx_bool(t_fileio *fio, gmx_bool *item, int n,
+                               const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        if (fio->bRead)
+        {
+            int itmp = 0;
+            ret      = ret && do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+            item[i]  = itmp;
+        }
+        else
+        {
+            int itmp = item[i];
+            ret      = ret && do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+        }
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+gmx_bool gmx_fio_ndoe_int(t_fileio *fio, int *item, int n,
+                          const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioINT, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_int64(t_fileio *fio, gmx_int64_t *item, int n,
+                            const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioINT64, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_uchar(t_fileio *fio, unsigned char *item, int n,
+                            const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    gmx_fio_lock(fio);
+    ret = ret && do_xdr(fio, item, n, eioNUCHAR, desc,
+                        srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_ushort(t_fileio *fio, unsigned short *item, int n,
+                             const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioUSHORT, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_rvec(t_fileio *fio, rvec *item, int n,
+                           const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    gmx_fio_lock(fio);
+    ret = ret && do_xdr(fio, item, n, eioNRVEC, desc, srcfile, line);
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_ivec(t_fileio *fio, ivec *item, int n,
+                           const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioIVEC, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
+
+
+
+gmx_bool gmx_fio_ndoe_string(t_fileio *fio, char *item[], int n,
+                             const char *desc, const char *srcfile, int line)
+{
+    gmx_bool ret = TRUE;
+    int      i;
+    gmx_fio_lock(fio);
+    for (i = 0; i < n; i++)
+    {
+        ret = ret && do_xdr(fio, &(item[i]), 1, eioSTRING, desc,
+                            srcfile, line);
+    }
+    gmx_fio_unlock(fio);
+    return ret;
+}
diff --git a/src/gromacs/fileio/gmxfio-xdr.h b/src/gromacs/fileio/gmxfio-xdr.h
new file mode 100644 (file)
index 0000000..982724d
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_FILEIO_GMXFIO_XDR_H
+#define GMX_FILEIO_GMXFIO_XDR_H
+
+#include "gromacs/fileio/xdrf.h"
+#include "gromacs/math/vectypes.h"
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/real.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct t_fileio;
+
+void gmx_fio_setprecision(struct t_fileio *fio, gmx_bool bDouble);
+/* Select the floating point precision for reading and writing files */
+
+XDR *gmx_fio_getxdr(struct t_fileio *fio);
+/* Return the file pointer itself */
+
+gmx_bool gmx_fio_writee_string(struct t_fileio *fio, const char *item,
+                               const char *desc, const char *srcfile, int line);
+
+/* reading or writing, depending on the file's opening mode string */
+gmx_bool gmx_fio_doe_real(struct t_fileio *fio, real *item,
+                          const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_float(struct t_fileio *fio, float *item,
+                           const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_double(struct t_fileio *fio, double *item,
+                            const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_gmx_bool(struct t_fileio *fio, gmx_bool *item,
+                              const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_int(struct t_fileio *fio, int *item,
+                         const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_int64(struct t_fileio *fio, gmx_int64_t *item,
+                           const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_uchar(struct t_fileio *fio, unsigned char *item,
+                           const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_ushort(struct t_fileio *fio, unsigned short *item,
+                            const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_rvec(struct t_fileio *fio, rvec *item,
+                          const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_ivec(struct t_fileio *fio, ivec *item,
+                          const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_string(struct t_fileio *fio, char *item,
+                            const char *desc, const char *srcfile, int line);
+
+/* array reading & writing */
+gmx_bool gmx_fio_ndoe_real(struct t_fileio *fio, real *item, int n,
+                           const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_float(struct t_fileio *fio, float *item, int n,
+                            const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_double(struct t_fileio *fio, double *item, int n,
+                             const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_gmx_bool(struct t_fileio *fio, gmx_bool *item, int n,
+                               const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_int(struct t_fileio *fio, int *item, int n,
+                          const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_int64(struct t_fileio *fio, gmx_int64_t *item, int n,
+                            const char *desc, const char *srcfile,
+                            int line);
+gmx_bool gmx_fio_ndoe_uchar(struct t_fileio *fio, unsigned char *item, int n,
+                            const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_ushort(struct t_fileio *fio, unsigned short *item, int n,
+                             const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_rvec(struct t_fileio *fio, rvec *item, int n,
+                           const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_ivec(struct t_fileio *fio, ivec *item, int n,
+                           const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_string(struct t_fileio *fio, char *item[], int n,
+                             const char *desc, const char *srcfile, int line);
+
+
+
+/* convenience macros */
+#define gmx_fio_write_string(fio, item)         gmx_fio_writee_string(fio, item, (#item), __FILE__, __LINE__)
+
+#define gmx_fio_do_real(fio, item)              gmx_fio_doe_real(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_float(fio, item)             gmx_fio_doe_float(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_double(fio, item)            gmx_fio_doe_double(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_gmx_bool(fio, item)          gmx_fio_doe_gmx_bool(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_int(fio, item)               gmx_fio_doe_int(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_int64(fio, item)             gmx_fio_doe_int64(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_uchar(fio, item)             gmx_fio_doe_uchar(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_ushort(fio, item)            gmx_fio_doe_ushort(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_rvec(fio, item)              gmx_fio_doe_rvec(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_ivec(fio, item)              gmx_fio_doe_ivec(fio, &item, (#item), __FILE__, __LINE__)
+#define gmx_fio_do_string(fio, item)            gmx_fio_doe_string(fio, item, (#item), __FILE__, __LINE__)
+
+
+#define gmx_fio_ndo_real(fio, item, n)              gmx_fio_ndoe_real(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_float(fio, item, n)             gmx_fio_ndoe_float(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_double(fio, item, n)            gmx_fio_ndoe_double(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_gmx_bool(fio, item, n)          gmx_fio_ndoe_gmx_bool(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_int(fio, item, n)               gmx_fio_ndoe_int(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_int64(fio, item, n)             gmx_fio_ndoe_int64(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_uchar(fio, item, n)             gmx_fio_ndoe_uchar(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_ushort(fio, item, n)            gmx_fio_ndoe_ushort(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_rvec(fio, item, n)              gmx_fio_ndoe_rvec(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_ivec(fio, item, n)              gmx_fio_ndoe_ivec(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_string(fio, item, n)            gmx_fio_ndoe_string(fio, item, n, (#item), __FILE__, __LINE__)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
similarity index 71%
rename from src/gromacs/fileio/gmxfio.c
rename to src/gromacs/fileio/gmxfio.cpp
index dc204ec69780e9c990fb7618214383569f8ddcc9..e08f55a1e30496fc39368dcc513915ccce78ee2c 100644 (file)
@@ -40,9 +40,9 @@
 
 #include "config.h"
 
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
 
 #ifdef HAVE_IO_H
 #include <io.h>
 #include "thread_mpi/threads.h"
 
 #include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio_int.h"
 #include "gromacs/fileio/md5.h"
-#include "gromacs/legacyheaders/macros.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
-#include "gromacs/utility/snprintf.h"
+
+#include "gmxfio-impl.h"
 
 /* This is the new improved and thread safe version of gmxfio. */
 
@@ -82,25 +81,6 @@ static t_fileio *open_files = NULL;
    during the simulation. */
 static tMPI_Thread_mutex_t open_file_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
 
-
-/* These simple lists define the I/O type for these files */
-static const int ftpXDR[] =
-{ efTPR, efTRR, efEDR, efXTC, efTNG, efMTX, efCPT };
-static const int ftpASC[] =
-{ efGRO, efPDB, efG96 };
-static const int ftpBIN[] =
-{ efTNG };
-#ifdef HAVE_XML
-static const int ftpXML[] =
-{   efXML};
-#endif
-
-const char *eioNames[eioNR] =
-{
-    "REAL", "INT", "GMX_STE_T", "UCHAR", "NUCHAR", "USHORT", "RVEC", "NRVEC",
-    "IVEC", "STRING"
-};
-
 /******************************************************************
  *
  * Internal functions:
@@ -115,117 +95,10 @@ static int gmx_fio_int_flush(t_fileio* fio)
     {
         rc = fflush(fio->fp);
     }
-    else if (fio->xdr)
-    {
-        rc = fflush((FILE *) fio->xdr->x_private);
-    }
 
     return rc;
 }
 
-/* returns TRUE if the file type ftp is in the set set */
-static gmx_bool in_ftpset(int ftp, int nset, const int set[])
-{
-    int      i;
-    gmx_bool bResult;
-
-    bResult = FALSE;
-    for (i = 0; (i < nset); i++)
-    {
-        if (ftp == set[i])
-        {
-            bResult = TRUE;
-        }
-    }
-
-    return bResult;
-}
-
-
-
-extern void gmx_fio_set_comment(t_fileio *fio, const char *comment)
-{
-    fio->comment = comment;
-}
-
-extern void gmx_fio_unset_comment(t_fileio *fio)
-{
-    fio->comment = NULL;
-}
-
-
-const char *gmx_fio_dbgstr(t_fileio *fio, const char *desc, char *buf)
-{
-    if (!fio->bDebug)
-    {
-        /* set to empty string */
-        buf[0] = 0;
-    }
-    else
-    {
-        snprintf(buf, GMX_FIO_BUFLEN, "  ; %s %s", fio->comment ? fio->comment : "", desc);
-    }
-    return buf;
-}
-
-
-/* check the number of items given against the type */
-void gmx_fio_check_nitem(int eio, int nitem, const char *file, int line)
-{
-    if ((nitem != 1) && !((eio == eioNRVEC) || (eio == eioNUCHAR)))
-    {
-        gmx_fatal(FARGS,
-                  "nitem (%d) may differ from 1 only for %s or %s, not   for %s"
-                  "(%s, %d)", nitem, eioNames[eioNUCHAR], eioNames[eioNRVEC],
-                  eioNames[eio], file, line);
-    }
-}
-
-
-/* output a data type error. */
-void gmx_fio_fe(t_fileio *fio, int eio, const char *desc,
-                const char *srcfile, int line)
-{
-
-    gmx_fatal(FARGS, "Trying to %s %s type %d (%s), src %s, line %d",
-              fio->bRead ? "read" : "write", desc, eio,
-              ((eio >= 0) && (eio < eioNR)) ? eioNames[eio] : "unknown",
-              srcfile, line);
-}
-
-
-/* set the reader/writer functions based on the file type */
-static void gmx_fio_set_iotype(t_fileio *fio)
-{
-    if (in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR))
-    {
-#ifdef USE_XDR
-        fio->iotp = &xdr_iotype;
-#else
-        gmx_fatal(FARGS, "Sorry, no XDR");
-#endif
-    }
-    else if (in_ftpset(fio->iFTP, asize(ftpASC), ftpASC))
-    {
-        fio->iotp = &asc_iotype;
-    }
-    else if (in_ftpset(fio->iFTP, asize(ftpBIN), ftpBIN))
-    {
-        fio->iotp = &bin_iotype;
-    }
-#ifdef HAVE_XMl
-    else if (in_ftpset(fio->iFTP, asize(ftpXML), ftpXML))
-    {
-        fio->iotp = &dummy_iotype;
-    }
-#endif
-    else
-    {
-        fio->iotp = &dummy_iotype;
-    }
-}
-
-
 /* lock the mutex associated with this fio. This needs to be done for every
    type of access to the fio's elements. */
 void gmx_fio_lock(t_fileio *fio)
@@ -308,8 +181,6 @@ static void gmx_fio_insert(t_fileio *fio)
    NOTE: We also assume that the open_file_mutex has been locked */
 static void gmx_fio_remove(t_fileio *fio)
 {
-    t_fileio *prev;
-
     /* lock prev, because we're changing it */
     gmx_fio_lock(fio->prev);
 
@@ -398,35 +269,33 @@ static void gmx_fio_stop_getting_next(t_fileio *fio)
 t_fileio *gmx_fio_open(const char *fn, const char *mode)
 {
     t_fileio *fio = NULL;
-    int       i;
     char      newmode[5];
     gmx_bool  bRead, bReadWrite;
-    int       xdrid;
 
     /* sanitize the mode string */
-    if (strncmp(mode, "r+", 2) == 0)
+    if (std::strncmp(mode, "r+", 2) == 0)
     {
-        strcpy(newmode, "r+");
+        std::strcpy(newmode, "r+");
     }
     else if (mode[0] == 'r')
     {
-        strcpy(newmode, "r");
+        std::strcpy(newmode, "r");
     }
     else if (strncmp(mode, "w+", 2) == 0)
     {
-        strcpy(newmode, "w+");
+        std::strcpy(newmode, "w+");
     }
     else if (mode[0] == 'w')
     {
-        strcpy(newmode, "w");
+        std::strcpy(newmode, "w");
     }
     else if (strncmp(mode, "a+", 2) == 0)
     {
-        strcpy(newmode, "a+");
+        std::strcpy(newmode, "a+");
     }
     else if (mode[0] == 'a')
     {
-        strcpy(newmode, "a");
+        std::strcpy(newmode, "a");
     }
     else
     {
@@ -434,13 +303,9 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
     }
 
     /* Check if it should be opened as a binary file */
-    if (strncmp(ftp2ftype(fn2ftp(fn)), "ASCII", 5))
+    if (!ftp_is_text(fn2ftp(fn)))
     {
-        /* Not ascii, add b to file mode */
-        if ((strchr(newmode, 'b') == NULL) && (strchr(newmode, 'B') == NULL))
-        {
-            strcat(newmode, "b");
-        }
+        strcat(newmode, "b");
     }
 
     snew(fio, 1);
@@ -451,38 +316,17 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
     fio->xdr   = NULL;
     if (fn)
     {
+        if (fn2ftp(fn) == efTNG)
+        {
+            gmx_incons("gmx_fio_open may not be used to open TNG files");
+        }
         fio->iFTP   = fn2ftp(fn);
         fio->fn     = gmx_strdup(fn);
-        fio->bStdio = FALSE;
 
+        fio->fp = gmx_ffopen(fn, newmode);
         /* If this file type is in the list of XDR files, open it like that */
-        if (in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR))
+        if (ftp_is_xdr(fio->iFTP))
         {
-            /* First check whether we have to make a backup,
-             * only for writing, not for read or append.
-             */
-            if (newmode[0] == 'w')
-            {
-#ifndef GMX_FAHCORE
-                /* only make backups for normal gromacs */
-                make_backup(fn);
-#endif
-            }
-            else
-            {
-                /* Check whether file exists */
-                if (!gmx_fexist(fn))
-                {
-                    gmx_open(fn);
-                }
-            }
-            if (fn2ftp(fn) == efTNG)
-            {
-                gmx_incons("gmx_fio_open may not be used to open TNG files");
-            }
-            /* Open the file */
-            fio->fp = gmx_ffopen(fn, newmode);
-
             /* determine the XDR direction */
             if (newmode[0] == 'w' || newmode[0] == 'a')
             {
@@ -492,15 +336,9 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
             {
                 fio->xdrmode = XDR_DECODE;
             }
-
             snew(fio->xdr, 1);
             xdrstdio_create(fio->xdr, fio->fp, fio->xdrmode);
         }
-        else
-        {
-            /* If it is not, open it as a regular file */
-            fio->fp = gmx_ffopen(fn, newmode);
-        }
 
         /* for appending seek to end of file to make sure ftell gives correct position
          * important for checkpointing */
@@ -509,14 +347,14 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
             gmx_fseek(fio->fp, 0, SEEK_END);
         }
     }
+    else
+    {
+        gmx_fatal(FARGS, "Cannot open file with NULL filename string");
+    }
+
     fio->bRead             = bRead;
     fio->bReadWrite        = bReadWrite;
     fio->bDouble           = (sizeof(real) == sizeof(double));
-    fio->bDebug            = FALSE;
-    fio->bOpen             = TRUE;
-
-    /* set the reader/writer functions */
-    gmx_fio_set_iotype(fio);
 
     /* and now insert this file into the list of open files. */
     gmx_fio_insert(fio);
@@ -527,24 +365,17 @@ static int gmx_fio_close_locked(t_fileio *fio)
 {
     int rc = 0;
 
-    if (!fio->bOpen)
-    {
-        gmx_fatal(FARGS, "File %s closed twice!\n", fio->fn);
-    }
-
-    if (in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR))
+    if (fio->xdr != NULL)
     {
         xdr_destroy(fio->xdr);
         sfree(fio->xdr);
     }
 
-    /* Don't close stdin and stdout! */
-    if (!fio->bStdio && fio->fp != NULL)
+    if (fio->fp != NULL)
     {
         rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
 
     }
-    fio->bOpen = FALSE;
 
     return rc;
 }
@@ -557,10 +388,6 @@ int gmx_fio_close(t_fileio *fio)
     /* We don't want two processes operating on the list at the same time */
     tMPI_Thread_mutex_lock(&open_file_mutex);
 
-    if (fio->iFTP == efTNG)
-    {
-        gmx_incons("gmx_fio_close should not be called on a TNG file");
-    }
     gmx_fio_lock(fio);
     /* first remove it from the list */
     gmx_fio_remove(fio);
@@ -580,7 +407,7 @@ int gmx_fio_fp_close(t_fileio *fio)
 {
     int rc = 0;
     gmx_fio_lock(fio);
-    if (!in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR) && !fio->bStdio)
+    if (fio->xdr == NULL)
     {
         rc      = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */
         fio->fp = NULL;
@@ -592,7 +419,7 @@ int gmx_fio_fp_close(t_fileio *fio)
 
 FILE * gmx_fio_fopen(const char *fn, const char *mode)
 {
-    FILE     *fp, *ret;
+    FILE     *ret;
     t_fileio *fio;
 
     fio = gmx_fio_open(fn, mode);
@@ -606,7 +433,6 @@ FILE * gmx_fio_fopen(const char *fn, const char *mode)
 int gmx_fio_fclose(FILE *fp)
 {
     t_fileio *cur;
-    t_fileio *found = NULL;
     int       rc    = -1;
 
     cur = gmx_fio_get_first();
@@ -736,8 +562,6 @@ int gmx_fio_get_file_md5(t_fileio *fio, gmx_off_t offset,
 /* The fio_mutex should ALWAYS be locked when this function is called */
 static int gmx_fio_int_get_file_position(t_fileio *fio, gmx_off_t *offset)
 {
-    char buf[STRLEN];
-
     /* Flush the file, so we are sure it is written */
     if (gmx_fio_int_flush(fio))
     {
@@ -763,11 +587,8 @@ static int gmx_fio_int_get_file_position(t_fileio *fio, gmx_off_t *offset)
 int gmx_fio_get_output_file_positions(gmx_file_position_t **p_outputfiles,
                                       int                  *p_nfiles)
 {
-    int                   i, nfiles, rc, nalloc;
-    int                   pos_hi, pos_lo;
-    long                  pos;
+    int                   nfiles, nalloc;
     gmx_file_position_t * outputfiles;
-    char                  buf[STRLEN];
     t_fileio             *cur;
 
     nfiles = 0;
@@ -781,14 +602,8 @@ int gmx_fio_get_output_file_positions(gmx_file_position_t **p_outputfiles,
     {
         /* Skip the checkpoint files themselves, since they could be open when
            we call this routine... */
-        /* also skip debug files (shoud be the only iFTP==efNR) */
-        if (cur->bOpen &&
-            !cur->bRead &&
-            !cur->bStdio &&
-            cur->iFTP != efCPT &&
-            cur->iFTP != efNR)
+        if (!cur->bRead && cur->iFTP != efCPT)
         {
-            int ret;
             /* This is an output file currently open for writing, add it */
             if (nfiles == nalloc)
             {
@@ -796,7 +611,7 @@ int gmx_fio_get_output_file_positions(gmx_file_position_t **p_outputfiles,
                 srenew(outputfiles, nalloc);
             }
 
-            strncpy(outputfiles[nfiles].filename, cur->fn, STRLEN - 1);
+            std::strncpy(outputfiles[nfiles].filename, cur->fn, STRLEN - 1);
 
             /* Get the file position */
             gmx_fio_int_get_file_position(cur, &outputfiles[nfiles].offset);
@@ -818,60 +633,6 @@ int gmx_fio_get_output_file_positions(gmx_file_position_t **p_outputfiles,
 }
 
 
-void gmx_fio_checktype(t_fileio *fio)
-{
-    if (in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR))
-    {
-        return;
-    }
-    else if (in_ftpset(fio->iFTP, asize(ftpASC), ftpASC))
-    {
-        return;
-    }
-    else if (in_ftpset(fio->iFTP, asize(ftpBIN), ftpBIN))
-    {
-        return;
-    }
-#ifdef HAVE_XMl
-    else if (in_ftpset(fio->iFTP, asize(ftpXML), ftpXML))
-    {
-        return;
-    }
-#endif
-    else
-    {
-        gmx_fatal(FARGS, "Can not read/write topologies to file type %s",
-                  ftp2ext(fio->iFTP));
-    }
-
-}
-
-
-void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble)
-{
-    gmx_fio_lock(fio);
-    fio->bDouble = bDouble;
-    gmx_fio_unlock(fio);
-}
-
-gmx_bool gmx_fio_getdebug(t_fileio *fio)
-{
-    gmx_bool ret;
-
-    gmx_fio_lock(fio);
-    ret = fio->bDebug;
-    gmx_fio_unlock(fio);
-
-    return ret;
-}
-
-void gmx_fio_setdebug(t_fileio *fio, gmx_bool bDebug)
-{
-    gmx_fio_lock(fio);
-    fio->bDebug = bDebug;
-    gmx_fio_unlock(fio);
-}
-
 char *gmx_fio_getname(t_fileio *fio)
 {
     char *ret;
@@ -927,19 +688,11 @@ int gmx_fio_flush(t_fileio* fio)
 static int gmx_fio_int_fsync(t_fileio *fio)
 {
     int rc    = 0;
-    int filen = -1;
-
 
     if (fio->fp)
     {
         rc = gmx_fsync(fio->fp);
     }
-    else if (fio->xdr) /* this should normally not happen */
-    {
-        rc = gmx_fsync((FILE*) fio->xdr->x_private);
-        /* ^ is this actually OK? */
-    }
-
     return rc;
 }
 
@@ -965,11 +718,7 @@ t_fileio *gmx_fio_all_output_fsync(void)
     cur = gmx_fio_get_first();
     while (cur)
     {
-        /* skip debug files (shoud be the only iFTP==efNR) */
-        if (cur->bOpen &&
-            !cur->bRead &&
-            !cur->bStdio &&
-            cur->iFTP != efNR)
+        if (!cur->bRead)
         {
             /* if any of them fails, return failure code */
             int rc = gmx_fio_int_fsync(cur);
@@ -1040,20 +789,6 @@ FILE *gmx_fio_getfp(t_fileio *fio)
     return ret;
 }
 
-XDR *gmx_fio_getxdr(t_fileio* fio)
-{
-    XDR *ret = NULL;
-
-    gmx_fio_lock(fio);
-    if (fio->xdr)
-    {
-        ret = fio->xdr;
-    }
-    gmx_fio_unlock(fio);
-
-    return ret;
-}
-
 gmx_bool gmx_fio_getread(t_fileio* fio)
 {
     gmx_bool ret;
@@ -1065,17 +800,6 @@ gmx_bool gmx_fio_getread(t_fileio* fio)
     return ret;
 }
 
-int xtc_seek_frame(t_fileio *fio, int frame, int natoms)
-{
-    int ret;
-
-    gmx_fio_lock(fio);
-    ret = xdr_xtc_seek_frame(frame, fio->fp, fio->xdr, natoms);
-    gmx_fio_unlock(fio);
-
-    return ret;
-}
-
 int xtc_seek_time(t_fileio *fio, real time, int natoms, gmx_bool bSeekForwardOnly)
 {
     int ret;
index bc656d2ef98fda4fbaae00711778d25d4d713078..d08249e4a15ac045784afb177c6f1d46d60cc510 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifdef __cplusplus
 extern "C" {
 #endif
-/* types */
-
-
-/* Enumerated for different items in files */
-enum {
-    eitemHEADER, eitemIR, eitemBOX,
-    eitemTOP, eitemX, eitemV, eitemF, eitemNR
-};
-
-/* Enumerated for data types in files */
-enum {
-    eioREAL, eioFLOAT, eioDOUBLE, eioINT, eioINT64,
-    eioUCHAR, eioNUCHAR, eioUSHORT,
-    eioRVEC, eioNRVEC, eioIVEC, eioSTRING, eioNR
-};
 
 typedef struct t_fileio t_fileio;
 
@@ -112,9 +97,6 @@ int gmx_fio_fclose(FILE *fp);
  * Change properties of the open file
  ********************************************************/
 
-void gmx_fio_setprecision(t_fileio *fio, gmx_bool bDouble);
-/* Select the floating point precision for reading and writing files */
-
 char *gmx_fio_getname(t_fileio *fio);
 /* Return the filename corresponding to the fio index */
 
@@ -124,19 +106,9 @@ int gmx_fio_getftp(t_fileio *fio);
     was opened as a specific file type and changing that midway is most
     likely an evil hack. */
 
-void gmx_fio_setdebug(t_fileio *fio, gmx_bool bDebug);
-/* Set the debug mode */
-
-gmx_bool gmx_fio_getdebug(t_fileio *fio);
-/* Return  whether debug mode is on in fio  */
-
 gmx_bool gmx_fio_getread(t_fileio *fio);
 /* Return  whether read mode is on in fio  */
 
-
-void gmx_fio_checktype(t_fileio *fio);
-/* Check whether the fio is of a sane type */
-
 /***************************************************
  * FILE Operations
  ***************************************************/
@@ -169,7 +141,7 @@ FILE *gmx_fio_getfp(t_fileio *fio);
  * If you do not have it on some other platform you do not have largefile
  * support at all, and you can define it to int (or better, find out how to
  * enable large files).  */
-typedef struct
+typedef struct gmx_file_position_t
 {
     char          filename[STRLEN];
     gmx_off_t     offset;
@@ -206,239 +178,9 @@ int gmx_fio_get_file_md5(t_fileio *fio, gmx_off_t offset,
                          unsigned char digest[]);
 
 
-int xtc_seek_frame(t_fileio *fio, int frame, int natoms);
-
 int xtc_seek_time(t_fileio *fio, real time, int natoms, gmx_bool bSeekForwardOnly);
 
 
-/* Add this to the comment string for debugging */
-void gmx_fio_set_comment(t_fileio *fio, const char *comment);
-
-/* Remove previously set comment */
-void gmx_fio_unset_comment(t_fileio *fio);
-
-
-
-
-/********************************************************
- * Read and write
- ********************************************************/
-
-
-/* basic reading & writing */
-gmx_bool gmx_fio_reade_real(t_fileio *fio, real *item,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_float(t_fileio *fio, float *item,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_double(t_fileio *fio, double *item,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_int(t_fileio *fio, int *item,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_int64(t_fileio *fio, gmx_int64_t *item,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_uchar(t_fileio *fio, unsigned char *item,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_ushort(t_fileio *fio, unsigned short *item,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_rvec(t_fileio *fio, rvec *item,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_ivec(t_fileio *fio, ivec *item,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_reade_string(t_fileio *fio, char *item,
-                              const char *desc, const char *srcfile, int line);
-
-gmx_bool gmx_fio_writee_real(t_fileio *fio, real item,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_float(t_fileio *fio, float item,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_double(t_fileio *fio, double item,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_int(t_fileio *fio, int item,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_int64(t_fileio *fio, gmx_int64_t item,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_uchar(t_fileio *fio, unsigned char item,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_ushort(t_fileio *fio, unsigned short item,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_rvec(t_fileio *fio, rvec *item,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_ivec(t_fileio *fio, ivec *item,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_writee_string(t_fileio *fio, const char *item,
-                               const char *desc, const char *srcfile, int line);
-
-/* reading or writing, depending on the file's opening mode string */
-gmx_bool gmx_fio_doe_real(t_fileio *fio, real *item,
-                          const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_float(t_fileio *fio, float *item,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_double(t_fileio *fio, double *item,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_gmx_bool(t_fileio *fio, gmx_bool *item,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_int(t_fileio *fio, int *item,
-                         const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_int64(t_fileio *fio, gmx_int64_t *item,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_uchar(t_fileio *fio, unsigned char *item,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_ushort(t_fileio *fio, unsigned short *item,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_rvec(t_fileio *fio, rvec *item,
-                          const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_ivec(t_fileio *fio, ivec *item,
-                          const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_doe_string(t_fileio *fio, char *item,
-                            const char *desc, const char *srcfile, int line);
-
-
-
-
-/* array reading & writing */
-gmx_bool gmx_fio_nreade_real(t_fileio *fio, real *item, int n,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_float(t_fileio *fio, float *item, int n,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_double(t_fileio *fio, double *item, int n,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_int(t_fileio *fio, int *item, int n,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_int64(t_fileio *fio, gmx_int64_t *item, int n,
-                              const char *desc, const char *srcfile,
-                              int line);
-gmx_bool gmx_fio_nreade_uchar(t_fileio *fio, unsigned char *item, int n,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_ushort(t_fileio *fio, unsigned short *item, int n,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_rvec(t_fileio *fio, rvec *item, int n,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_ivec(t_fileio *fio, ivec *item, int n,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nreade_string(t_fileio *fio, char *item[], int n,
-                               const char *desc, const char *srcfile, int line);
-
-gmx_bool gmx_fio_nwritee_real(t_fileio *fio, const real *item, int n,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_float(t_fileio *fio, const float *item, int n,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_double(t_fileio *fio, const double *item, int n,
-                                const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_int(t_fileio *fio, const int *item, int n,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_int64(t_fileio *fio,
-                               const gmx_int64_t *item, int n,
-                               const char *desc, const char *srcfile,
-                               int line);
-gmx_bool gmx_fio_nwritee_uchar(t_fileio *fio, const unsigned char *item, int n,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_ushort(t_fileio *fio, const unsigned short *item, int n,
-                                const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_rvec(t_fileio *fio, const rvec *item, int n,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_ivec(t_fileio *fio, const ivec *item, int n,
-                              const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_nwritee_string(t_fileio *fio, const char *item[], int n,
-                                const char *desc, const char *srcfile, int line);
-
-gmx_bool gmx_fio_ndoe_real(t_fileio *fio, real *item, int n,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_float(t_fileio *fio, float *item, int n,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_double(t_fileio *fio, double *item, int n,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_gmx_bool(t_fileio *fio, gmx_bool *item, int n,
-                               const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_int(t_fileio *fio, int *item, int n,
-                          const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_int64(t_fileio *fio, gmx_int64_t *item, int n,
-                            const char *desc, const char *srcfile,
-                            int line);
-gmx_bool gmx_fio_ndoe_uchar(t_fileio *fio, unsigned char *item, int n,
-                            const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_ushort(t_fileio *fio, unsigned short *item, int n,
-                             const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_rvec(t_fileio *fio, rvec *item, int n,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_ivec(t_fileio *fio, ivec *item, int n,
-                           const char *desc, const char *srcfile, int line);
-gmx_bool gmx_fio_ndoe_string(t_fileio *fio, char *item[], int n,
-                             const char *desc, const char *srcfile, int line);
-
-
-
-/* convenience macros */
-#define gmx_fio_read_real(fio, item)           gmx_fio_reade_real(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_float(fio, item)          gmx_fio_reade_float(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_double(fio, item)         gmx_fio_reade_double(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_int(fio, item)            gmx_fio_reade_int(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_int64(fio, item)          gmx_fio_reade_int64(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_uchar(fio, item)          gmx_fio_reade_uchar(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_ushort(fio, item)         gmx_fio_reade_ushort(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_rvec(fio, item)           gmx_fio_reade_rvec(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_ivec(fio, item)           gmx_fio_reade_ivec(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_read_string(fio, item)         gmx_fio_reade_string(fio, item, (#item), __FILE__, __LINE__)
-
-#define gmx_fio_write_real(fio, item)           gmx_fio_writee_real(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_float(fio, item)          gmx_fio_writee_float(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_double(fio, item)         gmx_fio_writee_double(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_int(fio, item)            gmx_fio_writee_int(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_int64(fio, item)          gmx_fio_writee_int64(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_uchar(fio, item)          gmx_fio_writee_uchar(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_ushort(fio, item)         gmx_fio_writee_ushort(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_rvec(fio, item)           gmx_fio_writee_rvec(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_ivec(fio, item)           gmx_fio_writee_ivec(fio, item, (#item), __FILE__, __LINE__)
-#define gmx_fio_write_string(fio, item)         gmx_fio_writee_string(fio, item, (#item), __FILE__, __LINE__)
-
-#define gmx_fio_do_real(fio, item)              gmx_fio_doe_real(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_float(fio, item)             gmx_fio_doe_float(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_double(fio, item)            gmx_fio_doe_double(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_gmx_bool(fio, item)          gmx_fio_doe_gmx_bool(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_int(fio, item)               gmx_fio_doe_int(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_int64(fio, item)             gmx_fio_doe_int64(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_uchar(fio, item)             gmx_fio_doe_uchar(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_ushort(fio, item)            gmx_fio_doe_ushort(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_rvec(fio, item)              gmx_fio_doe_rvec(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_ivec(fio, item)              gmx_fio_doe_ivec(fio, &item, (#item), __FILE__, __LINE__)
-#define gmx_fio_do_string(fio, item)            gmx_fio_doe_string(fio, item, (#item), __FILE__, __LINE__)
-
-
-
-
-#define gmx_fio_nread_real(fio, item, n)            gmx_fio_nreade_real(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_float(fio, item, n)           gmx_fio_nreade_float(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_double(fio, item, n)          gmx_fio_nreade_double(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_int(fio, item, n)             gmx_fio_nreade_int(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_int64(fio, item, n)           gmx_fio_nreade_int64(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_uchar(fio, item, n)           gmx_fio_nreade_uchar(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_ushort(fio, item, n)          gmx_fio_nreade_ushort(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_rvec(fio, item, n)            gmx_fio_nreade_rvec(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_ivec(fio, item, n)            gmx_fio_nreade_ivec(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nread_string(fio, item, n)          gmx_fio_nreade_string(fio, item, n, (#item), __FILE__, __LINE__)
-
-#define gmx_fio_nwrite_real(fio, item, n)           gmx_fio_nwritee_real(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_float(fio, item, n)          gmx_fio_nwritee_float(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_double(fio, item, n)         gmx_fio_nwritee_double(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_int(fio, item, n)            gmx_fio_nwritee_int(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_int64(fio, item, n)          gmx_fio_nwritee_int64(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_uchar(fio, item, n)          gmx_fio_nwritee_uchar(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_ushort(fio, item, n)         gmx_fio_nwritee_ushort(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_rvec(fio, item, n)           gmx_fio_nwritee_rvec(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_ivec(fio, item, n)           gmx_fio_nwritee_ivec(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_nwrite_string(fio, item, n)         gmx_fio_nwritee_string(fio, item, n, (#item), __FILE__, __LINE__)
-
-#define gmx_fio_ndo_real(fio, item, n)              gmx_fio_ndoe_real(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_float(fio, item, n)             gmx_fio_ndoe_float(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_double(fio, item, n)            gmx_fio_ndoe_double(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_gmx_bool(fio, item, n)          gmx_fio_ndoe_gmx_bool(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_int(fio, item, n)               gmx_fio_ndoe_int(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_int64(fio, item, n)             gmx_fio_ndoe_int64(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_uchar(fio, item, n)             gmx_fio_ndoe_uchar(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_ushort(fio, item, n)            gmx_fio_ndoe_ushort(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_rvec(fio, item, n)              gmx_fio_ndoe_rvec(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_ivec(fio, item, n)              gmx_fio_ndoe_ivec(fio, item, n, (#item), __FILE__, __LINE__)
-#define gmx_fio_ndo_string(fio, item, n)            gmx_fio_ndoe_string(fio, item, n, (#item), __FILE__, __LINE__)
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gromacs/fileio/gmxfio_asc.c b/src/gromacs/fileio/gmxfio_asc.c
deleted file mode 100644 (file)
index a451b0c..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include "config.h"
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
-#include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/gmxfio_int.h"
-#include "gromacs/fileio/md5.h"
-#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/utility/cstringutil.h"
-#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/futil.h"
-#include "gromacs/utility/smalloc.h"
-
-
-/* This is the part that reads dummy and ascii files.  */
-
-
-
-
-/* file type functions */
-static gmx_bool do_ascread(t_fileio *fio, void *item, int nitem, int eio,
-                           const char *desc, const char *srcfile, int line);
-static gmx_bool do_ascwrite(t_fileio *fio, const void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line);
-static gmx_bool do_dummyread(t_fileio *fio, void *item, int nitem, int eio,
-                             const char *desc, const char *srcfile, int line);
-static gmx_bool do_dummywrite(t_fileio *fio, const void *item, int nitem, int eio,
-                              const char *desc, const char *srcfile, int line);
-
-
-const t_iotype asc_iotype = {do_ascread, do_ascwrite};
-const t_iotype dummy_iotype = {do_dummyread, do_dummywrite};
-
-
-
-
-
-
-static gmx_bool do_dummyread(t_fileio gmx_unused *fio, void gmx_unused *item, int gmx_unused nitem, int gmx_unused eio,
-                             const char gmx_unused *desc, const char gmx_unused *srcfile, int gmx_unused line)
-{
-    gmx_fatal(FARGS, "File type not set!");
-    return FALSE;
-}
-
-static gmx_bool do_dummywrite(t_fileio gmx_unused *fio, const void gmx_unused *item, int gmx_unused nitem, int gmx_unused eio,
-                              const char gmx_unused *desc, const char gmx_unused *srcfile, int gmx_unused line)
-{
-    gmx_fatal(FARGS, "File type not set!");
-    return FALSE;
-}
-
-
-
-static void encode_string(int maxlen, char dst[], const char src[])
-{
-    int i;
-
-    for (i = 0; (i < maxlen - 1) && (src[i] != '\0'); i++)
-    {
-        if ((src[i] == ' ') || (src[i] == '\t'))
-        {
-            dst[i] = '_';
-        }
-        else
-        {
-            dst[i] = src[i];
-        }
-    }
-    dst[i] = '\0';
-
-    if (i == maxlen)
-    {
-        fprintf(stderr, "String '%s' truncated to '%s'\n", src, dst);
-    }
-}
-
-static void decode_string(int maxlen, char dst[], const char src[])
-{
-    int i;
-
-    for (i = 0; (i < maxlen - 1) && (src[i] != '\0'); i++)
-    {
-        if (src[i] == '_')
-        {
-            dst[i] = ' ';
-        }
-        else
-        {
-            dst[i] = src[i];
-        }
-    }
-    dst[i] = '\0';
-
-    if (i == maxlen)
-    {
-        fprintf(stderr, "String '%s' truncated to '%s'\n", src, dst);
-    }
-}
-
-static gmx_bool do_ascwrite(t_fileio *fio, const void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line)
-{
-    int            i;
-    int            res = 0, *iptr;
-    real          *ptr;
-    char           strbuf[256];
-    char           buf[GMX_FIO_BUFLEN];
-    unsigned char *ucptr;
-    FILE          *fp = fio->fp;
-
-    gmx_fio_check_nitem(eio, nitem, srcfile, line);
-    switch (eio)
-    {
-        case eioREAL:
-        case eioFLOAT:
-        case eioDOUBLE:
-            res = fprintf(fp, "%18.10e%s\n", *((real *) item),
-                          gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioINT:
-            res = fprintf(fp, "%18d%s\n", *((int *) item), gmx_fio_dbgstr(fio,
-                                                                          desc,
-                                                                          buf));
-            break;
-        case eioINT64:
-            sprintf(strbuf, "%s%s%s", "%", GMX_PRId64, "\n");
-            res = fprintf(fp, strbuf, *((gmx_int64_t *) item),
-                          gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioUCHAR:
-            res = fprintf(fp, "%4d%s\n", *((unsigned char *) item),
-                          gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioNUCHAR:
-            ucptr = (unsigned char *) item;
-            for (i = 0; (i < nitem); i++)
-            {
-                res = fprintf(fp, "%4d", (int) ucptr[i]);
-            }
-            fprintf(fio->fp, "%s\n", gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioUSHORT:
-            res = fprintf(fp, "%18d%s\n", *((unsigned short *) item),
-                          gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioRVEC:
-            ptr = (real *) item;
-            res = fprintf(fp, "%18.10e%18.10e%18.10e%s\n", ptr[XX],
-                          ptr[YY], ptr[ZZ], gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioNRVEC:
-            for (i = 0; (i < nitem); i++)
-            {
-                ptr = ((rvec *) item)[i];
-                res = fprintf(fp, "%18.10e%18.10e%18.10e%s\n", ptr[XX],
-                              ptr[YY], ptr[ZZ], gmx_fio_dbgstr(fio, desc, buf));
-            }
-            break;
-        case eioIVEC:
-            iptr = (int *) item;
-            res  = fprintf(fp, "%18d%18d%18d%s\n", iptr[XX], iptr[YY],
-                           iptr[ZZ], gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        case eioSTRING:
-            encode_string(256, strbuf, (char *) item);
-            res = fprintf(fp, "%-18s%s\n", strbuf, gmx_fio_dbgstr(fio, desc, buf));
-            break;
-        default:
-            gmx_fio_fe(fio, eio, desc, srcfile, line);
-    }
-    if ((res <= 0) && fio->bDebug)
-    {
-        fprintf(stderr,
-                "Error writing %s %s to file %s (source %s, line %d)\n",
-                eioNames[eio], desc, fio->fn, srcfile, line);
-    }
-
-    return (res > 0);
-}
-
-
-static char *next_item(FILE *fp, char *buf, int buflen)
-{
-    int      rd;
-    gmx_bool in_comment = FALSE;
-    gmx_bool in_token   = FALSE;
-    int      i          = 0;
-    /* This routine reads strings from the file fp, strips comment
-     * and buffers. For thread-safety reasons, It reads through getc()  */
-
-    rd = getc(fp);
-    if (rd == EOF)
-    {
-        gmx_file("End of file");
-    }
-    do
-    {
-        if (in_comment)
-        {
-            if (rd == '\n')
-            {
-                in_comment = FALSE;
-            }
-        }
-        else if (in_token)
-        {
-            if (isspace(rd) || rd == ';')
-            {
-                break;
-            }
-            buf[i++] = (char) rd;
-        }
-        else
-        {
-            if (!isspace(rd))
-            {
-                if (rd == ';')
-                {
-                    in_comment = TRUE;
-                }
-                else
-                {
-                    in_token = TRUE;
-                    buf[i++] = (char) (rd);
-                }
-            }
-        }
-        if (i >= buflen - 2)
-        {
-            break;
-        }
-    }
-    while ((rd = getc(fp)) != EOF);
-
-    fprintf(stderr, "WARNING, ftpASC file type not tested!\n");
-
-    buf[i] = 0;
-
-    return buf;
-}
-
-static gmx_bool do_ascread(t_fileio *fio, void *item, int nitem, int eio,
-                           const char *desc, const char *srcfile, int line)
-{
-    FILE           *fp = fio->fp;
-    int             i, m, res = 0, *iptr, ix;
-    gmx_int64_t     s;
-    double          d, x;
-    char            c;
-    real           *ptr;
-    unsigned char  *ucptr;
-    char           *cptr;
-#define NEXT_ITEM_BUF_LEN 128
-    char            ni_buf[NEXT_ITEM_BUF_LEN];
-
-    gmx_fio_check_nitem(eio, nitem, srcfile, line);
-    switch (eio)
-    {
-        case eioREAL:
-        case eioFLOAT:
-        case eioDOUBLE:
-            res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%lf", &d);
-            if (item)
-            {
-                *((real *) item) = d;
-            }
-            break;
-        case eioINT:
-            res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%d", &i);
-            if (item)
-            {
-                *((int *) item) = i;
-            }
-            break;
-        case eioINT64:
-            res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN),
-                         "%"GMX_SCNd64, &s);
-            if (item)
-            {
-                *((gmx_int64_t *) item) = s;
-            }
-            break;
-        case eioUCHAR:
-            res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%c", &c);
-            if (item)
-            {
-                *((unsigned char *) item) = (unsigned char)c;
-            }
-            break;
-        case eioNUCHAR:
-            ucptr = (unsigned char *) item;
-            for (i = 0; (i < nitem); i++)
-            {
-                res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%d", &ix);
-                if (item)
-                {
-                    ucptr[i] = ix;
-                }
-            }
-            break;
-        case eioUSHORT:
-            res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%d", &i);
-            if (item)
-            {
-                *((unsigned short *) item) = i;
-            }
-            break;
-        case eioRVEC:
-            ptr = (real *) item;
-            for (m = 0; (m < DIM); m++)
-            {
-                res    = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%lf\n", &x);
-                ptr[m] = x;
-            }
-            break;
-        case eioNRVEC:
-            assert(item);
-            for (i = 0; (i < nitem); i++)
-            {
-                ptr = ((rvec *) item)[i];
-                for (m = 0; (m < DIM); m++)
-                {
-                    res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%lf\n",
-                                 &x);
-                    ptr[m] = x;
-                }
-            }
-            break;
-        case eioIVEC:
-            iptr = (int *) item;
-            for (m = 0; (m < DIM); m++)
-            {
-                res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%d\n", &ix);
-                if (item)
-                {
-                    iptr[m] = ix;
-                }
-            }
-            break;
-        case eioSTRING:
-            cptr = next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN);
-            if (item)
-            {
-                decode_string(strlen(cptr) + 1, (char *) item, cptr);
-                /* res = sscanf(cptr,"%s",(char *)item);*/
-                res = 1;
-            }
-            break;
-        default:
-            gmx_fio_fe(fio, eio, desc, srcfile, line);
-    }
-
-    if ((res <= 0) && fio->bDebug)
-    {
-        fprintf(stderr,
-                "Error reading %s %s from file %s (source %s, line %d)\n",
-                eioNames[eio], desc, fio->fn, srcfile, line);
-    }
-    return (res > 0);
-}
diff --git a/src/gromacs/fileio/gmxfio_bin.c b/src/gromacs/fileio/gmxfio_bin.c
deleted file mode 100644 (file)
index 9238af5..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include "config.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
-#include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/gmxfio_int.h"
-#include "gromacs/fileio/md5.h"
-#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/utility/futil.h"
-#include "gromacs/utility/smalloc.h"
-
-/* This is the part that reads dummy and ascii files.  */
-
-
-static gmx_bool do_binread(t_fileio *fio, void *item, int nitem, int eio,
-                           const char *desc, const char *srcfile, int line);
-static gmx_bool do_binwrite(t_fileio *fio, const void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line);
-
-
-const t_iotype bin_iotype = {do_binread, do_binwrite};
-
-
-static gmx_bool do_binwrite(t_fileio *fio, const void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line)
-{
-    size_t size = 0, wsize;
-    int    ssize;
-
-    gmx_fio_check_nitem(eio, nitem, srcfile, line);
-    switch (eio)
-    {
-        case eioREAL:
-            size = sizeof(real);
-            break;
-        case eioFLOAT:
-            size = sizeof(float);
-            break;
-        case eioDOUBLE:
-            size = sizeof(double);
-            break;
-        case eioINT:
-            size = sizeof(int);
-            break;
-        case eioINT64:
-            size = sizeof(gmx_int64_t);
-            break;
-        case eioUCHAR:
-            size = sizeof(unsigned char);
-            break;
-        case eioNUCHAR:
-            size = sizeof(unsigned char);
-            break;
-        case eioUSHORT:
-            size = sizeof(unsigned short);
-            break;
-        case eioRVEC:
-            size = sizeof(rvec);
-            break;
-        case eioNRVEC:
-            size = sizeof(rvec);
-            break;
-        case eioIVEC:
-            size = sizeof(ivec);
-            break;
-        case eioSTRING:
-            size = ssize = strlen((char *) item) + 1;
-            do_binwrite(fio, &ssize, 1, eioINT, desc, srcfile, line);
-            break;
-        default:
-            gmx_fio_fe(fio, eio, desc, srcfile, line);
-    }
-
-    wsize = fwrite(item, size, nitem, fio->fp);
-
-    if ((wsize != nitem) && fio->bDebug)
-    {
-        fprintf(stderr,
-                "Error writing %s %s to file %s (source %s, line %d)\n",
-                eioNames[eio], desc, fio->fn, srcfile, line);
-        fprintf(stderr, "written size %u bytes, source size %u bytes\n",
-                (unsigned int) wsize, (unsigned int) size);
-    }
-    return (wsize == nitem);
-}
-
-static gmx_bool do_binread(t_fileio *fio, void *item, int nitem, int eio,
-                           const char *desc, const char *srcfile, int line)
-{
-    size_t size = 0, rsize;
-    int    ssize;
-
-    gmx_fio_check_nitem(eio, nitem, srcfile, line);
-    switch (eio)
-    {
-        case eioREAL:
-            if (fio->bDouble)
-            {
-                size = sizeof(double);
-            }
-            else
-            {
-                size = sizeof(float);
-            }
-            break;
-        case eioFLOAT:
-            size = sizeof(float);
-            break;
-        case eioDOUBLE:
-            size = sizeof(double);
-            break;
-        case eioINT:
-            size = sizeof(int);
-            break;
-        case eioINT64:
-            size = sizeof(gmx_int64_t);
-            break;
-        case eioUCHAR:
-            size = sizeof(unsigned char);
-            break;
-        case eioNUCHAR:
-            size = sizeof(unsigned char);
-            break;
-        case eioUSHORT:
-            size = sizeof(unsigned short);
-            break;
-        case eioRVEC:
-        case eioNRVEC:
-            if (fio->bDouble)
-            {
-                size = sizeof(double) * DIM;
-            }
-            else
-            {
-                size = sizeof(float) * DIM;
-            }
-            break;
-        case eioIVEC:
-            size = sizeof(ivec);
-            break;
-        case eioSTRING:
-            do_binread(fio, &ssize, 1, eioINT, desc, srcfile, line);
-            size = ssize;
-            break;
-        default:
-            gmx_fio_fe(fio, eio, desc, srcfile, line);
-    }
-    if (item)
-    {
-        rsize = fread(item, size, nitem, fio->fp);
-    }
-    else
-    {
-        /* Skip over it if we have a NULL pointer here */
-        gmx_fseek(fio->fp, (gmx_off_t)(size*nitem), SEEK_CUR);
-        rsize = nitem;
-    }
-    if ((rsize != nitem) && (fio->bDebug))
-    {
-        fprintf(stderr,
-                "Error reading %s %s from file %s (source %s, line %d)\n",
-                eioNames[eio], desc, fio->fn, srcfile, line);
-    }
-
-    return (rsize == nitem);
-}
diff --git a/src/gromacs/fileio/gmxfio_rw.c b/src/gromacs/fileio/gmxfio_rw.c
deleted file mode 100644 (file)
index bdfa1ec..0000000
+++ /dev/null
@@ -1,1027 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include "config.h"
-
-#include <errno.h>
-#include <stdio.h>
-
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
-#include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/gmxfio_int.h"
-#include "gromacs/fileio/md5.h"
-#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/utility/futil.h"
-#include "gromacs/utility/smalloc.h"
-
-
-/*******************************************************************
- *
- * READ/WRITE FUNCTIONS
- *
- *******************************************************************/
-
-gmx_bool gmx_fio_reade_real(t_fileio *fio, real *item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioREAL, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_float(t_fileio *fio, float *item,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioFLOAT, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_reade_double(t_fileio *fio, double *item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioDOUBLE, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_int(t_fileio *fio, int *item,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioINT, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_int64(t_fileio *fio, gmx_int64_t *item,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioINT64, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_uchar(t_fileio *fio, unsigned char *item,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioUCHAR, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_reade_ushort(t_fileio *fio, unsigned short *item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioUSHORT, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_rvec(t_fileio *fio, rvec *item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioRVEC, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_ivec(t_fileio *fio, ivec *item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioIVEC, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_reade_string(t_fileio *fio, char *item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, 1, eioSTRING, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-/* Write */
-
-gmx_bool gmx_fio_writee_real(t_fileio *fio, real item,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioREAL, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_float(t_fileio *fio, float item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioFLOAT, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_double(t_fileio *fio, double item,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioDOUBLE, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_writee_int(t_fileio *fio, int item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioINT, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_int64(t_fileio *fio, gmx_int64_t item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioINT64, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_uchar(t_fileio *fio, unsigned char item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioUCHAR, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_ushort(t_fileio *fio, unsigned short item,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, &item, 1, eioUSHORT, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_rvec(t_fileio *fio, rvec *item,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, item, 1, eioRVEC, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_ivec(t_fileio *fio, ivec *item,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, item, 1, eioIVEC, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_writee_string(t_fileio *fio, const char *item,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, item, 1, eioSTRING, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-/* Read/write functions */
-
-gmx_bool gmx_fio_doe_real(t_fileio *fio, real *item,
-                          const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioREAL, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioREAL, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-
-}
-
-gmx_bool gmx_fio_doe_float(t_fileio *fio, float *item,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioFLOAT, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioFLOAT, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_double(t_fileio *fio, double *item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioDOUBLE, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioDOUBLE, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_doe_gmx_bool(t_fileio *fio, gmx_bool *item,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    int      itmp;
-
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret   = fio->iotp->nread(fio, &itmp, 1, eioINT, desc, srcfile, line);
-        *item = itmp;
-    }
-    else
-    {
-        itmp = *item;
-        ret  = fio->iotp->nwrite(fio, &itmp, 1, eioINT, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_int(t_fileio *fio, int *item,
-                         const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioINT, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioINT, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_int64(t_fileio *fio, gmx_int64_t *item,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioINT64, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioINT64, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_uchar(t_fileio *fio, unsigned char *item,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioUCHAR, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioUCHAR, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_ushort(t_fileio *fio, unsigned short *item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioUSHORT, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioUSHORT, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_rvec(t_fileio *fio, rvec *item,
-                          const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioRVEC, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioRVEC, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_ivec(t_fileio *fio, ivec *item,
-                          const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioIVEC, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioIVEC, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_doe_string(t_fileio *fio, char *item,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = fio->iotp->nread(fio, item, 1, eioSTRING, desc, srcfile, line);
-    }
-    else
-    {
-        ret = fio->iotp->nwrite(fio, item, 1, eioSTRING, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-
-
-
-
-/* Array reading & writing */
-
-gmx_bool gmx_fio_nreade_real(t_fileio *fio, real *item, int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioREAL, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_float(t_fileio *fio, float *item, int n,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioFLOAT, desc,
-                                      srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_nreade_double(t_fileio *fio, double *item, int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioDOUBLE, desc,
-                                      srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_int(t_fileio *fio, int *item, int n,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioINT, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_int64(t_fileio *fio, gmx_int64_t *item, int n,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioINT64, desc,
-                                      srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_nreade_uchar(t_fileio *fio, unsigned char *item, int n,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, n, eioNUCHAR, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_ushort(t_fileio *fio, unsigned short *item, int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioUSHORT, desc,
-                                      srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_rvec(t_fileio *fio, rvec *item, int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nread(fio, item, n, eioNRVEC, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_ivec(t_fileio *fio, ivec *item, int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, item[i], 1, eioIVEC, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nreade_string(t_fileio *fio, char *item[], int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nread(fio, item[i], 1, eioSTRING, desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-
-/* Array writing */
-
-gmx_bool gmx_fio_nwritee_real(t_fileio *fio, const real *item, int n,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioREAL, desc,
-                                       srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_float(t_fileio *fio, const float *item, int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioFLOAT, desc,
-                                       srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_double(t_fileio *fio, const double *item, int n,
-                                const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioDOUBLE, desc,
-                                       srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_int(t_fileio *fio, const int *item, int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioINT, desc, srcfile,
-                                       line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_int64(t_fileio *fio,
-                               const gmx_int64_t *item, int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioINT64,
-                                       desc, srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_uchar(t_fileio *fio, const unsigned char *item, int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, item, n, eioNUCHAR, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_ushort(t_fileio *fio, const unsigned short *item, int n,
-                                const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioUSHORT, desc,
-                                       srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_nwritee_rvec(t_fileio *fio, const rvec *item, int n,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret;
-    gmx_fio_lock(fio);
-    ret = fio->iotp->nwrite(fio, item, n, eioNRVEC, desc, srcfile, line);
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_nwritee_ivec(t_fileio *fio, const ivec *item, int n,
-                              const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioIVEC, desc,
-                                       srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-gmx_bool gmx_fio_nwritee_string(t_fileio *fio, const char *item[], int n,
-                                const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioSTRING, desc, srcfile,
-                                       line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-/* array read/write functions */
-
-gmx_bool gmx_fio_ndoe_real(t_fileio *fio, real *item, int n,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioREAL, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioREAL, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_float(t_fileio *fio, float *item, int n,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioFLOAT, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioFLOAT, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_double(t_fileio *fio, double *item, int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioDOUBLE, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioDOUBLE, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_gmx_bool(t_fileio *fio, gmx_bool *item, int n,
-                               const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i, itmp;
-
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &itmp, 1, eioINT, desc,
-                                          srcfile, line);
-            item[i] = itmp;
-        }
-        else
-        {
-            itmp = item[i];
-            ret  = ret && fio->iotp->nwrite(fio, &itmp, 1, eioINT, desc,
-                                            srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-gmx_bool gmx_fio_ndoe_int(t_fileio *fio, int *item, int n,
-                          const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioINT, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioINT, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_int64(t_fileio *fio, gmx_int64_t *item, int n,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioINT64, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioINT64, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_uchar(t_fileio *fio, unsigned char *item, int n,
-                            const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = ret && fio->iotp->nread(fio, item, n, eioNUCHAR, desc,
-                                      srcfile, line);
-    }
-    else
-    {
-        ret = ret && fio->iotp->nwrite(fio, item, n, eioNUCHAR, desc,
-                                       srcfile, line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_ushort(t_fileio *fio, unsigned short *item, int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioUSHORT, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioUSHORT, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_rvec(t_fileio *fio, rvec *item, int n,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    gmx_fio_lock(fio);
-    if (fio->bRead)
-    {
-        ret = ret && fio->iotp->nread(fio, item, n, eioNRVEC, desc, srcfile, line);
-    }
-    else
-    {
-        ret = ret && fio->iotp->nwrite(fio, item, n, eioNRVEC, desc, srcfile,
-                                       line);
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_ivec(t_fileio *fio, ivec *item, int n,
-                           const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioIVEC, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioIVEC, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
-
-
-
-gmx_bool gmx_fio_ndoe_string(t_fileio *fio, char *item[], int n,
-                             const char *desc, const char *srcfile, int line)
-{
-    gmx_bool ret = TRUE;
-    int      i;
-    gmx_fio_lock(fio);
-    for (i = 0; i < n; i++)
-    {
-        if (fio->bRead)
-        {
-            ret = ret && fio->iotp->nread(fio, &(item[i]), 1, eioSTRING, desc,
-                                          srcfile, line);
-        }
-        else
-        {
-            ret = ret && fio->iotp->nwrite(fio, &(item[i]), 1, eioSTRING, desc,
-                                           srcfile, line);
-        }
-    }
-    gmx_fio_unlock(fio);
-    return ret;
-}
diff --git a/src/gromacs/fileio/gmxfio_xdr.c b/src/gromacs/fileio/gmxfio_xdr.c
deleted file mode 100644 (file)
index ca1b70d..0000000
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include "config.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
-#include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/gmxfio_int.h"
-#include "gromacs/fileio/md5.h"
-#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/futil.h"
-#include "gromacs/utility/smalloc.h"
-
-/* This is the part that reads xdr files.  */
-
-
-/* file type functions */
-static gmx_bool do_xdrread(t_fileio *fio, void *item, int nitem, int eio,
-                           const char *desc, const char *srcfile, int line);
-static gmx_bool do_xdrwrite(t_fileio *fio, const void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line);
-
-
-const t_iotype xdr_iotype = {do_xdrread, do_xdrwrite};
-
-
-#ifdef USE_XDR
-
-static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio,
-                       const char *desc, const char *srcfile, int line)
-{
-    unsigned char   ucdum, *ucptr;
-    bool_t          res = 0;
-    float           fvec[DIM];
-    double          dvec[DIM];
-    int             j, m, *iptr, idum;
-    gmx_int64_t     sdum;
-    real           *ptr;
-    unsigned short  us;
-    double          d = 0;
-    float           f = 0;
-
-    gmx_fio_check_nitem(eio, nitem, srcfile, line);
-    switch (eio)
-    {
-        case eioREAL:
-            if (fio->bDouble)
-            {
-                if (item && !fio->bRead)
-                {
-                    d = *((real *) item);
-                }
-                res = xdr_double(fio->xdr, &d);
-                if (item)
-                {
-                    *((real *) item) = d;
-                }
-            }
-            else
-            {
-                if (item && !fio->bRead)
-                {
-                    f = *((real *) item);
-                }
-                res = xdr_float(fio->xdr, &f);
-                if (item)
-                {
-                    *((real *) item) = f;
-                }
-            }
-            break;
-        case eioFLOAT:
-            if (item && !fio->bRead)
-            {
-                f = *((float *) item);
-            }
-            res = xdr_float(fio->xdr, &f);
-            if (item)
-            {
-                *((float *) item) = f;
-            }
-            break;
-        case eioDOUBLE:
-            if (item && !fio->bRead)
-            {
-                d = *((double *) item);
-            }
-            res = xdr_double(fio->xdr, &d);
-            if (item)
-            {
-                *((double *) item) = d;
-            }
-            break;
-        case eioINT:
-            if (item && !fio->bRead)
-            {
-                idum = *(int *) item;
-            }
-            res = xdr_int(fio->xdr, &idum);
-            if (item)
-            {
-                *(int *) item = idum;
-            }
-            break;
-        case eioINT64:
-            if (item && !fio->bRead)
-            {
-                sdum = *(gmx_int64_t *) item;
-            }
-            res = xdr_int64(fio->xdr, &sdum);
-            if (item)
-            {
-                *(gmx_int64_t *) item = sdum;
-            }
-            break;
-        case eioUCHAR:
-            if (item && !fio->bRead)
-            {
-                ucdum = *(unsigned char *) item;
-            }
-            res = xdr_u_char(fio->xdr, &ucdum);
-            if (item)
-            {
-                *(unsigned char *) item = ucdum;
-            }
-            break;
-        case eioNUCHAR:
-            ucptr = (unsigned char *) item;
-            res   = 1;
-            for (j = 0; (j < nitem) && res; j++)
-            {
-                res = xdr_u_char(fio->xdr, &(ucptr[j]));
-            }
-            break;
-        case eioUSHORT:
-            if (item && !fio->bRead)
-            {
-                us = *(unsigned short *) item;
-            }
-            res = xdr_u_short(fio->xdr, (unsigned short *) &us);
-            if (item)
-            {
-                *(unsigned short *) item = us;
-            }
-            break;
-        case eioRVEC:
-            if (fio->bDouble)
-            {
-                if (item && !fio->bRead)
-                {
-                    for (m = 0; (m < DIM); m++)
-                    {
-                        dvec[m] = ((real *) item)[m];
-                    }
-                }
-                res = xdr_vector(fio->xdr, (char *) dvec, DIM,
-                                 (unsigned int) sizeof(double),
-                                 (xdrproc_t) xdr_double);
-                if (item)
-                {
-                    for (m = 0; (m < DIM); m++)
-                    {
-                        ((real *) item)[m] = dvec[m];
-                    }
-                }
-            }
-            else
-            {
-                if (item && !fio->bRead)
-                {
-                    for (m = 0; (m < DIM); m++)
-                    {
-                        fvec[m] = ((real *) item)[m];
-                    }
-                }
-                res = xdr_vector(fio->xdr, (char *) fvec, DIM,
-                                 (unsigned int) sizeof(float),
-                                 (xdrproc_t) xdr_float);
-                if (item)
-                {
-                    for (m = 0; (m < DIM); m++)
-                    {
-                        ((real *) item)[m] = fvec[m];
-                    }
-                }
-            }
-            break;
-        case eioNRVEC:
-            ptr = NULL;
-            res = 1;
-            for (j = 0; (j < nitem) && res; j++)
-            {
-                if (item)
-                {
-                    ptr = ((rvec *) item)[j];
-                }
-                res = do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line);
-            }
-            break;
-        case eioIVEC:
-            iptr = (int *) item;
-            res  = 1;
-            for (m = 0; (m < DIM) && res; m++)
-            {
-                if (item && !fio->bRead)
-                {
-                    idum = iptr[m];
-                }
-                res = xdr_int(fio->xdr, &idum);
-                if (item)
-                {
-                    iptr[m] = idum;
-                }
-            }
-            break;
-        case eioSTRING:
-        {
-            char *cptr;
-            int   slen;
-
-            if (item)
-            {
-                if (!fio->bRead)
-                {
-                    slen = strlen((char *) item) + 1;
-                }
-                else
-                {
-                    slen = 0;
-                }
-            }
-            else
-            {
-                slen = 0;
-            }
-
-            if (xdr_int(fio->xdr, &slen) <= 0)
-            {
-                gmx_fatal(FARGS, "wrong string length %d for string %s"
-                          " (source %s, line %d)", slen, desc, srcfile, line);
-            }
-            if (!item && fio->bRead)
-            {
-                snew(cptr, slen);
-            }
-            else
-            {
-                cptr = (char *)item;
-            }
-            if (cptr)
-            {
-                res = xdr_string(fio->xdr, &cptr, slen);
-            }
-            else
-            {
-                res = 1;
-            }
-            if (!item && fio->bRead)
-            {
-                sfree(cptr);
-            }
-            break;
-        }
-        default:
-            gmx_fio_fe(fio, eio, desc, srcfile, line);
-    }
-    if ((res == 0) && (fio->bDebug))
-    {
-        fprintf(stderr, "Error in xdr I/O %s %s to file %s (source %s, line %d)\n",
-                eioNames[eio], desc, fio->fn, srcfile, line);
-    }
-
-    return (res != 0);
-}
-
-
-static gmx_bool do_xdrread(t_fileio *fio, void *item, int nitem, int eio,
-                           const char *desc, const char *srcfile, int line)
-{
-    return do_xdr(fio, item, nitem, eio, desc, srcfile, line);
-}
-
-
-static gmx_bool do_xdrwrite(t_fileio *fio, const void *item, int nitem, int eio,
-                            const char *desc, const char *srcfile, int line)
-{
-    void *it = (void*)item; /* ugh.. */
-    return do_xdr(fio, it, nitem, eio, desc, srcfile, line);
-}
-
-#endif
diff --git a/src/gromacs/fileio/groio.cpp b/src/gromacs/fileio/groio.cpp
new file mode 100644 (file)
index 0000000..47e65dd
--- /dev/null
@@ -0,0 +1,591 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gmxpre.h"
+
+#include "groio.h"
+
+#include <cstdio>
+#include <cstring>
+
+#include <algorithm>
+
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/trx.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/mtop_util.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/smalloc.h"
+
+static void get_coordnum_fp(FILE *in, char *title, int *natoms)
+{
+    char line[STRLEN+1];
+
+    fgets2(title, STRLEN, in);
+    fgets2(line, STRLEN, in);
+    if (sscanf(line, "%d", natoms) != 1)
+    {
+        gmx_fatal(FARGS, "gro file does not have the number of atoms on the second line");
+    }
+}
+
+void get_coordnum(const char *infile, int *natoms)
+{
+    FILE *in;
+    char  title[STRLEN];
+
+    in = gmx_fio_fopen(infile, "r");
+    get_coordnum_fp(in, title, natoms);
+    gmx_fio_fclose(in);
+}
+
+static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
+                           t_symtab *symtab, t_atoms *atoms, int *ndec,
+                           rvec x[], rvec *v, matrix box)
+{
+    char       name[6];
+    char       resname[6], oldresname[6];
+    char       line[STRLEN+1], *ptr;
+    char       buf[256];
+    double     x1, y1, z1, x2, y2, z2;
+    rvec       xmin, xmax;
+    int        natoms, i, m, resnr, newres, oldres, ddist, c;
+    gmx_bool   bFirst, bVel;
+    char      *p1, *p2, *p3;
+
+    newres  = -1;
+    oldres  = -12345; /* Unlikely number for the first residue! */
+    ddist   = 0;
+
+    /* Read the title and number of atoms */
+    get_coordnum_fp(in, title, &natoms);
+
+    if (natoms > atoms->nr)
+    {
+        gmx_fatal(FARGS, "gro file contains more atoms (%d) than expected (%d)",
+                  natoms, atoms->nr);
+    }
+    else if (natoms <  atoms->nr)
+    {
+        fprintf(stderr, "Warning: gro file contains less atoms (%d) than expected"
+                " (%d)\n", natoms, atoms->nr);
+    }
+
+    bFirst = TRUE;
+
+    bVel = FALSE;
+
+    resname[0]     = '\0';
+    oldresname[0]  = '\0';
+
+    /* just pray the arrays are big enough */
+    for (i = 0; (i < natoms); i++)
+    {
+        if ((fgets2(line, STRLEN, in)) == NULL)
+        {
+            gmx_fatal(FARGS, "Unexpected end of file in file %s at line %d",
+                      infile, i+2);
+        }
+        if (strlen(line) < 39)
+        {
+            gmx_fatal(FARGS, "Invalid line in %s for atom %d:\n%s", infile, i+1, line);
+        }
+
+        /* determine read precision from distance between periods
+           (decimal points) */
+        if (bFirst)
+        {
+            bFirst = FALSE;
+            p1     = strchr(line, '.');
+            if (p1 == NULL)
+            {
+                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
+            }
+            p2 = strchr(&p1[1], '.');
+            if (p2 == NULL)
+            {
+                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
+            }
+            ddist = p2 - p1;
+            *ndec = ddist - 5;
+
+            p3 = strchr(&p2[1], '.');
+            if (p3 == NULL)
+            {
+                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
+            }
+
+            if (p3 - p2 != ddist)
+            {
+                gmx_fatal(FARGS, "The spacing of the decimal points in file %s is not consistent for x, y and z", infile);
+            }
+        }
+
+        /* residue number*/
+        memcpy(name, line, 5);
+        name[5] = '\0';
+        sscanf(name, "%d", &resnr);
+        sscanf(line+5, "%5s", resname);
+
+        if (resnr != oldres || strncmp(resname, oldresname, sizeof(resname)))
+        {
+            oldres = resnr;
+            newres++;
+            if (newres >= natoms)
+            {
+                gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
+                          infile, natoms);
+            }
+            atoms->atom[i].resind = newres;
+            t_atoms_set_resinfo(atoms, i, symtab, resname, resnr, ' ', 0, ' ');
+        }
+        else
+        {
+            atoms->atom[i].resind = newres;
+        }
+
+        /* atomname */
+        std::memcpy(name, line+10, 5);
+        atoms->atomname[i] = put_symtab(symtab, name);
+
+        /* Copy resname to oldresname after we are done with the sanity check above */
+        std::strncpy(oldresname, resname, sizeof(oldresname));
+
+        /* eventueel controle atomnumber met i+1 */
+
+        /* coordinates (start after residue data) */
+        ptr = line + 20;
+        /* Read fixed format */
+        for (m = 0; m < DIM; m++)
+        {
+            for (c = 0; (c < ddist && ptr[0]); c++)
+            {
+                buf[c] = ptr[0];
+                ptr++;
+            }
+            buf[c] = '\0';
+            if (sscanf(buf, "%lf %lf", &x1, &x2) != 1)
+            {
+                gmx_fatal(FARGS, "Something is wrong in the coordinate formatting of file %s. Note that gro is fixed format (see the manual)", infile);
+            }
+            else
+            {
+                x[i][m] = x1;
+            }
+        }
+
+        /* velocities (start after residues and coordinates) */
+        if (v)
+        {
+            /* Read fixed format */
+            for (m = 0; m < DIM; m++)
+            {
+                for (c = 0; (c < ddist && ptr[0]); c++)
+                {
+                    buf[c] = ptr[0];
+                    ptr++;
+                }
+                buf[c] = '\0';
+                if (sscanf(buf, "%lf", &x1) != 1)
+                {
+                    v[i][m] = 0;
+                }
+                else
+                {
+                    v[i][m] = x1;
+                    bVel    = TRUE;
+                }
+            }
+        }
+    }
+    atoms->nres = newres + 1;
+
+    /* box */
+    fgets2(line, STRLEN, in);
+    if (sscanf(line, "%lf%lf%lf", &x1, &y1, &z1) != 3)
+    {
+        gmx_warning("Bad box in file %s", infile);
+
+        /* Generate a cubic box */
+        for (m = 0; (m < DIM); m++)
+        {
+            xmin[m] = xmax[m] = x[0][m];
+        }
+        for (i = 1; (i < atoms->nr); i++)
+        {
+            for (m = 0; (m < DIM); m++)
+            {
+                xmin[m] = std::min(xmin[m], x[i][m]);
+                xmax[m] = std::max(xmax[m], x[i][m]);
+            }
+        }
+        for (i = 0; i < DIM; i++)
+        {
+            for (m = 0; m < DIM; m++)
+            {
+                box[i][m] = 0.0;
+            }
+        }
+        for (m = 0; (m < DIM); m++)
+        {
+            box[m][m] = (xmax[m]-xmin[m]);
+        }
+        fprintf(stderr, "Generated a cubic box %8.3f x %8.3f x %8.3f\n",
+                box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
+    }
+    else
+    {
+        /* We found the first three values, the diagonal elements */
+        box[XX][XX] = x1;
+        box[YY][YY] = y1;
+        box[ZZ][ZZ] = z1;
+        if (sscanf (line, "%*f%*f%*f%lf%lf%lf%lf%lf%lf",
+                    &x1, &y1, &z1, &x2, &y2, &z2) != 6)
+        {
+            x1 = y1 = z1 = x2 = y2 = z2 = 0.0;
+        }
+        box[XX][YY] = x1;
+        box[XX][ZZ] = y1;
+        box[YY][XX] = z1;
+        box[YY][ZZ] = x2;
+        box[ZZ][XX] = y2;
+        box[ZZ][YY] = z2;
+    }
+
+    return bVel;
+}
+
+void read_whole_conf(const char *infile, char *title,
+                     t_atoms *atoms, rvec x[], rvec *v, matrix box)
+{
+    FILE    *in;
+    int      ndec;
+    t_symtab symtab;
+
+    /* open file */
+    in = gmx_fio_fopen(infile, "r");
+
+    open_symtab(&symtab);
+    get_w_conf(in, infile, title, &symtab, atoms, &ndec, x, v, box);
+    /* We can't free the symbols, as they are still used in atoms, so
+     * the only choice is to leak them. */
+    free_symtab(&symtab);
+
+    gmx_fio_fclose(in);
+}
+
+static gmx_bool gmx_one_before_eof(FILE *fp)
+{
+    char     data[4];
+    gmx_bool beof;
+
+    if ((beof = fread(data, 1, 1, fp)) == 1)
+    {
+        gmx_fseek(fp, -1, SEEK_CUR);
+    }
+    return !beof;
+}
+
+gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr)
+{
+    t_atoms  atoms;
+    t_symtab symtab;
+    char     title[STRLEN], *p;
+    double   tt;
+    int      ndec = 0, i;
+
+    if (gmx_one_before_eof(status))
+    {
+        return FALSE;
+    }
+
+    open_symtab(&symtab);
+    atoms.nr = fr->natoms;
+    snew(atoms.atom, fr->natoms);
+    atoms.nres = fr->natoms;
+    snew(atoms.resinfo, fr->natoms);
+    snew(atoms.atomname, fr->natoms);
+
+    fr->bV    = get_w_conf(status, title, title, &symtab, &atoms, &ndec, fr->x, fr->v, fr->box);
+    fr->bPrec = TRUE;
+    fr->prec  = 1;
+    /* prec = 10^ndec: */
+    for (i = 0; i < ndec; i++)
+    {
+        fr->prec *= 10;
+    }
+    fr->title  = title;
+    fr->bTitle = TRUE;
+    fr->bX     = TRUE;
+    fr->bBox   = TRUE;
+
+    sfree(atoms.atom);
+    sfree(atoms.resinfo);
+    sfree(atoms.atomname);
+    done_symtab(&symtab);
+
+    if ((p = strstr(title, "t=")) != NULL)
+    {
+        p += 2;
+        if (sscanf(p, "%lf", &tt) == 1)
+        {
+            fr->time  = tt;
+            fr->bTime = TRUE;
+        }
+        else
+        {
+            fr->time  = 0;
+            fr->bTime = FALSE;
+        }
+    }
+
+    if (atoms.nr != fr->natoms)
+    {
+        gmx_fatal(FARGS, "Number of atoms in gro frame (%d) doesn't match the number in the previous frame (%d)", atoms.nr, fr->natoms);
+    }
+
+    return TRUE;
+}
+
+int gro_first_x_or_v(FILE *status, t_trxframe *fr)
+{
+    char title[STRLEN];
+
+    frewind(status);
+    fprintf(stderr, "Reading frames from gro file");
+    get_coordnum_fp(status, title, &fr->natoms);
+    frewind(status);
+    fprintf(stderr, " '%s', %d atoms.\n", title, fr->natoms);
+    fr->bTitle = TRUE;
+    fr->title  = title;
+    if (fr->natoms == 0)
+    {
+        gmx_file("No coordinates in gro file");
+    }
+
+    snew(fr->x, fr->natoms);
+    snew(fr->v, fr->natoms);
+    gro_next_x_or_v(status, fr);
+
+    return fr->natoms;
+}
+
+static void make_hconf_format(int pr, gmx_bool bVel, char format[])
+{
+    int l, vpr;
+
+    /* build format string for printing,
+       something like "%8.3f" for x and "%8.4f" for v */
+    if (pr < 0)
+    {
+        pr = 0;
+    }
+    if (pr > 30)
+    {
+        pr = 30;
+    }
+    l   = pr+5;
+    vpr = pr+1;
+    if (bVel)
+    {
+        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df\n",
+                l, pr, l, pr, l, pr, l, vpr, l, vpr, l, vpr);
+    }
+    else
+    {
+        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df\n", l, pr, l, pr, l, pr);
+    }
+
+}
+
+static void write_hconf_box(FILE *out, int pr, matrix box)
+{
+    char format[100];
+    int  l;
+
+    if (pr < 5)
+    {
+        pr = 5;
+    }
+    l = pr+5;
+
+    if (box[XX][YY] || box[XX][ZZ] || box[YY][XX] || box[YY][ZZ] ||
+        box[ZZ][XX] || box[ZZ][YY])
+    {
+        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df"
+                "%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df\n",
+                l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr);
+        fprintf(out, format,
+                box[XX][XX], box[YY][YY], box[ZZ][ZZ],
+                box[XX][YY], box[XX][ZZ], box[YY][XX],
+                box[YY][ZZ], box[ZZ][XX], box[ZZ][YY]);
+    }
+    else
+    {
+        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df\n", l, pr, l, pr, l, pr);
+        fprintf(out, format,
+                box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
+    }
+}
+
+void write_hconf_indexed_p(FILE *out, const char *title, t_atoms *atoms,
+                           int nx, const atom_id index[], int pr,
+                           rvec *x, rvec *v, matrix box)
+{
+    char resnm[6], nm[6], format[100];
+    int  ai, i, resind, resnr;
+
+    bromacs(format, 99);
+    fprintf(out, "%s\n", (title && title[0]) ? title : format);
+    fprintf(out, "%5d\n", nx);
+
+    make_hconf_format(pr, v != NULL, format);
+
+    for (i = 0; (i < nx); i++)
+    {
+        ai = index[i];
+
+        resind = atoms->atom[ai].resind;
+        std::strncpy(resnm, " ??? ", sizeof(resnm)-1);
+        if (resind < atoms->nres)
+        {
+            std::strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
+            resnr = atoms->resinfo[resind].nr;
+        }
+        else
+        {
+            std::strncpy(resnm, " ??? ", sizeof(resnm)-1);
+            resnr = resind + 1;
+        }
+
+        if (atoms->atom)
+        {
+            std::strncpy(nm, *atoms->atomname[ai], sizeof(nm)-1);
+        }
+        else
+        {
+            std::strncpy(nm, " ??? ", sizeof(nm)-1);
+        }
+
+        fprintf(out, "%5d%-5.5s%5.5s%5d", resnr%100000, resnm, nm, (ai+1)%100000);
+        /* next fprintf uses built format string */
+        if (v)
+        {
+            fprintf(out, format,
+                    x[ai][XX], x[ai][YY], x[ai][ZZ], v[ai][XX], v[ai][YY], v[ai][ZZ]);
+        }
+        else
+        {
+            fprintf(out, format,
+                    x[ai][XX], x[ai][YY], x[ai][ZZ]);
+        }
+    }
+
+    write_hconf_box(out, pr, box);
+
+    fflush(out);
+}
+
+void write_hconf_mtop(FILE *out, const char *title, gmx_mtop_t *mtop, int pr,
+                      rvec *x, rvec *v, matrix box)
+{
+    char                    format[100];
+    int                     i, resnr;
+    gmx_mtop_atomloop_all_t aloop;
+    t_atom                 *atom;
+    char                   *atomname, *resname;
+
+    bromacs(format, 99);
+    fprintf(out, "%s\n", (title && title[0]) ? title : format);
+    fprintf(out, "%5d\n", mtop->natoms);
+
+    make_hconf_format(pr, v != NULL, format);
+
+    aloop = gmx_mtop_atomloop_all_init(mtop);
+    while (gmx_mtop_atomloop_all_next(aloop, &i, &atom))
+    {
+        gmx_mtop_atomloop_all_names(aloop, &atomname, &resnr, &resname);
+
+        fprintf(out, "%5d%-5.5s%5.5s%5d",
+                resnr%100000, resname, atomname, (i+1)%100000);
+        /* next fprintf uses built format string */
+        if (v)
+        {
+            fprintf(out, format,
+                    x[i][XX], x[i][YY], x[i][ZZ], v[i][XX], v[i][YY], v[i][ZZ]);
+        }
+        else
+        {
+            fprintf(out, format,
+                    x[i][XX], x[i][YY], x[i][ZZ]);
+        }
+    }
+
+    write_hconf_box(out, pr, box);
+
+    fflush(out);
+}
+
+void write_hconf_p(FILE *out, const char *title, t_atoms *atoms, int pr,
+                   rvec *x, rvec *v, matrix box)
+{
+    atom_id *aa;
+    int      i;
+
+    snew(aa, atoms->nr);
+    for (i = 0; (i < atoms->nr); i++)
+    {
+        aa[i] = i;
+    }
+    write_hconf_indexed_p(out, title, atoms, atoms->nr, aa, pr, x, v, box);
+    sfree(aa);
+}
+
+void write_conf_p(const char *outfile, const char *title,
+                  t_atoms *atoms, int pr,
+                  rvec *x, rvec *v, matrix box)
+{
+    FILE *out;
+
+    out = gmx_fio_fopen(outfile, "w");
+    write_hconf_p(out, title, atoms, pr, x, v, box);
+    gmx_fio_fclose(out);
+}
diff --git a/src/gromacs/fileio/groio.h b/src/gromacs/fileio/groio.h
new file mode 100644 (file)
index 0000000..b89c8ee
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_FILEIO_GROIO_H
+#define GMX_FILEIO_GROIO_H
+
+#include <stdio.h>
+
+#include "gromacs/legacyheaders/types/simple.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct gmx_mtop_t;
+struct t_atoms;
+struct t_topology;
+struct t_trxframe;
+
+void get_coordnum(const char *infile, int *natoms);
+void read_whole_conf(const char *infile, char *title,
+                     struct t_atoms *atoms, rvec x[], rvec *v, matrix box);
+
+gmx_bool gro_next_x_or_v(FILE *status, struct t_trxframe *fr);
+int gro_first_x_or_v(FILE *status, struct t_trxframe *fr);
+/* read first/next x and/or v frame from gro file */
+
+void write_hconf_indexed_p(FILE *out, const char *title, struct t_atoms *atoms,
+                           int nx, const atom_id index[], int ndec,
+                           rvec *x, rvec *v, matrix box);
+
+void write_hconf_mtop(FILE *out, const char *title, struct gmx_mtop_t *mtop, int pr,
+                      rvec *x, rvec *v, matrix box);
+
+void write_hconf_p(FILE *out, const char *title, struct t_atoms *atoms, int ndec,
+                   rvec *x, rvec *v, matrix box);
+/* Write a Gromos file with precision ndec: number of decimal places in x,
+ * v has one place more. */
+
+void write_conf_p(const char *outfile, const char *title,
+                  struct t_atoms *atoms, int pr,
+                  rvec *x, rvec *v, matrix box);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
similarity index 93%
rename from src/gromacs/fileio/libxdrf.c
rename to src/gromacs/fileio/libxdrf.cpp
index 401cfa8883691e9731e56380661d4c906068ed56..8f6aecf9b89301392b8dccbdedc0bc21b1e43c48 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  */
 #include "gmxpre.h"
 
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <climits>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/fileio/xdr_datatype.h"
 #include "gromacs/fileio/xdrf.h"
@@ -69,12 +71,6 @@ const char *xdr_datatype_names[] =
  */
 #define MAXABS INT_MAX-2
 
-#ifndef MIN
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#endif
-#ifndef MAX
-#define MAX(x, y) ((x) > (y) ? (x) : (y))
-#endif
 #ifndef SQR
 #define SQR(x) ((x)*(x))
 #endif
@@ -91,7 +87,7 @@ static const int magicints[] = {
 
 #define FIRSTIDX 9
 /* note that magicints[FIRSTIDX-1] == 0 */
-#define LASTIDX (sizeof(magicints) / sizeof(*magicints))
+#define LASTIDX static_cast<int>((sizeof(magicints) / sizeof(*magicints)))
 
 
 /*____________________________________________________________________________
@@ -112,10 +108,10 @@ static void sendbits(int buf[], int num_of_bits, int num)
     int             lastbits;
     unsigned char * cbuf;
 
-    cbuf     = ((unsigned char *)buf) + 3 * sizeof(*buf);
-    cnt      = (unsigned int) buf[0];
+    cbuf     = (reinterpret_cast<unsigned char *>(buf)) + 3 * sizeof(*buf);
+    cnt      = static_cast<unsigned int>(buf[0]);
     lastbits = buf[1];
-    lastbyte = (unsigned int) buf[2];
+    lastbyte = static_cast<unsigned int>(buf[2]);
     while (num_of_bits >= 8)
     {
         lastbyte     = (lastbyte << 8) | ((num >> (num_of_bits -8)) /* & 0xff*/);
@@ -299,10 +295,10 @@ static int receivebits(int buf[], int num_of_bits)
     unsigned char * cbuf;
     int             mask = (1 << num_of_bits) -1;
 
-    cbuf     = ((unsigned char *)buf) + 3 * sizeof(*buf);
+    cbuf     = reinterpret_cast<unsigned char *>(buf) + 3 * sizeof(*buf);
     cnt      = buf[0];
-    lastbits = (unsigned int) buf[1];
-    lastbyte = (unsigned int) buf[2];
+    lastbits = static_cast<unsigned int>(buf[1]);
+    lastbyte = static_cast<unsigned int>(buf[2]);
 
     num = 0;
     while (num_of_bits >= 8)
@@ -420,7 +416,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
     int          tmp, *thiscoord,  prevcoord[3];
     unsigned int tmpcoord[30];
 
-    int          bufsize, xdrid, lsize;
+    int          bufsize, lsize;
     unsigned int bitsize;
     float        inv_precision;
     int          errval = 1;
@@ -430,6 +426,14 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
     bitsizeint[0] = bitsizeint[1] = bitsizeint[2] = 0;
     prevcoord[0]  = prevcoord[1]  = prevcoord[2]  = 0;
 
+    // The static analyzer warns about garbage values for thiscoord[] further
+    // down. It might be thrown off by all the reinterpret_casts, but we might
+    // as well make sure the small preallocated buffer is zero-initialized.
+    for (i = 0; i < static_cast<int>(prealloc_size); i++)
+    {
+        prealloc_ip[i] = 0;
+    }
+
     if (!bRead)
     {
         /* xdrs is open for writing */
@@ -444,8 +448,8 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
          */
         if (*size <= 9)
         {
-            return (xdr_vector(xdrs, (char *) fp, (unsigned int)size3,
-                               (unsigned int)sizeof(*fp), (xdrproc_t)xdr_float));
+            return (xdr_vector(xdrs, reinterpret_cast<char *>(fp), static_cast<unsigned int>(size3),
+                               static_cast<unsigned int>(sizeof(*fp)), (xdrproc_t)xdr_float));
         }
 
         if (xdr_float(xdrs, precision) == 0)
@@ -461,9 +465,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         else
         {
             we_should_free = 1;
-            bufsize        = size3 * 1.2;
-            ip             = (int *)malloc((size_t)(size3 * sizeof(*ip)));
-            buf            = (int *)malloc((size_t)(bufsize * sizeof(*buf)));
+            bufsize        = static_cast<int>(size3 * 1.2);
+            ip             = reinterpret_cast<int *>(malloc(size3 * sizeof(*ip)));
+            buf            = reinterpret_cast<int *>(malloc(bufsize * sizeof(*buf)));
             if (ip == NULL || buf == NULL)
             {
                 fprintf(stderr, "malloc failed\n");
@@ -495,7 +499,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
                 /* scaling would cause overflow */
                 errval = 0;
             }
-            lint1 = lf;
+            lint1 = static_cast<int>(lf);
             if (lint1 < minint[0])
             {
                 minint[0] = lint1;
@@ -519,7 +523,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
                 /* scaling would cause overflow */
                 errval = 0;
             }
-            lint2 = lf;
+            lint2 = static_cast<int>(lf);
             if (lint2 < minint[1])
             {
                 minint[1] = lint2;
@@ -538,12 +542,12 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
             {
                 lf = *lfp * *precision - 0.5;
             }
-            if (fabs(lf) > MAXABS)
+            if (std::abs(lf) > MAXABS)
             {
                 /* scaling would cause overflow */
                 errval = 0;
             }
-            lint3 = lf;
+            lint3 = static_cast<int>(lf);
             if (lint3 < minint[2])
             {
                 minint[2] = lint3;
@@ -554,7 +558,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
             }
             *lip++ = lint3;
             lfp++;
-            diff = abs(oldlint1-lint1)+abs(oldlint2-lint2)+abs(oldlint3-lint3);
+            diff = std::abs(oldlint1-lint1)+std::abs(oldlint2-lint2)+std::abs(oldlint3-lint3);
             if (diff < mindiff && lfp > fp + 3)
             {
                 mindiff = diff;
@@ -603,8 +607,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         {
             bitsize = sizeofints(3, sizeint);
         }
-        lip      = ip;
-        luip     = (unsigned int *) ip;
+        luip     = reinterpret_cast<unsigned int *>(ip);
         smallidx = FIRSTIDX;
         while (smallidx < LASTIDX && magicints[smallidx] < mindiff)
         {
@@ -620,9 +623,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
             return 0;
         }
 
-        maxidx       = MIN(LASTIDX, smallidx + 8);
+        maxidx       = std::min(LASTIDX, smallidx + 8);
         minidx       = maxidx - 8; /* often this equal smallidx */
-        smaller      = magicints[MAX(FIRSTIDX, smallidx-1)] / 2;
+        smaller      = magicints[std::max(FIRSTIDX, smallidx-1)] / 2;
         smallnum     = magicints[smallidx] / 2;
         sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
         larger       = magicints[maxidx] / 2;
@@ -630,11 +633,11 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         while (i < *size)
         {
             is_small  = 0;
-            thiscoord = (int *)(luip) + i * 3;
+            thiscoord = reinterpret_cast<int *>(luip) + i * 3;
             if (smallidx < maxidx && i >= 1 &&
-                abs(thiscoord[0] - prevcoord[0]) < larger &&
-                abs(thiscoord[1] - prevcoord[1]) < larger &&
-                abs(thiscoord[2] - prevcoord[2]) < larger)
+                std::abs(thiscoord[0] - prevcoord[0]) < larger &&
+                std::abs(thiscoord[1] - prevcoord[1]) < larger &&
+                std::abs(thiscoord[2] - prevcoord[2]) < larger)
             {
                 is_smaller = 1;
             }
@@ -648,9 +651,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
             }
             if (i + 1 < *size)
             {
-                if (abs(thiscoord[0] - thiscoord[3]) < smallnum &&
-                    abs(thiscoord[1] - thiscoord[4]) < smallnum &&
-                    abs(thiscoord[2] - thiscoord[5]) < smallnum)
+                if (std::abs(thiscoord[0] - thiscoord[3]) < smallnum &&
+                    std::abs(thiscoord[1] - thiscoord[4]) < smallnum &&
+                    std::abs(thiscoord[2] - thiscoord[5]) < smallnum)
                 {
                     /* interchange first with second atom for better
                      * compression of water molecules
@@ -764,7 +767,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         }
 
 
-        rc = errval * (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0]));
+        rc = errval * (xdr_opaque(xdrs, reinterpret_cast<char *>(&(buf[3])), static_cast<unsigned int>(buf[0])));
         if (we_should_free)
         {
             free(ip);
@@ -792,8 +795,8 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         if (*size <= 9)
         {
             *precision = -1;
-            return (xdr_vector(xdrs, (char *) fp, (unsigned int)size3,
-                               (unsigned int)sizeof(*fp), (xdrproc_t)xdr_float));
+            return (xdr_vector(xdrs, reinterpret_cast<char *>(fp), static_cast<unsigned int>(size3),
+                               static_cast<unsigned int>(sizeof(*fp)), (xdrproc_t)xdr_float));
         }
         if (xdr_float(xdrs, precision) == 0)
         {
@@ -808,9 +811,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         else
         {
             we_should_free = 1;
-            bufsize        = size3 * 1.2;
-            ip             = (int *)malloc((size_t)(size3 * sizeof(*ip)));
-            buf            = (int *)malloc((size_t)(bufsize * sizeof(*buf)));
+            bufsize        = static_cast<int>(size3 * 1.2);
+            ip             = reinterpret_cast<int *>(malloc(size3 * sizeof(*ip)));
+            buf            = reinterpret_cast<int *>(malloc(bufsize * sizeof(*buf)));
             if (ip == NULL || buf == NULL)
             {
                 fprintf(stderr, "malloc failed\n");
@@ -862,12 +865,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
             return 0;
         }
 
-        maxidx       = MIN(LASTIDX, smallidx + 8);
-        minidx       = maxidx - 8; /* often this equal smallidx */
-        smaller      = magicints[MAX(FIRSTIDX, smallidx-1)] / 2;
+        smaller      = magicints[std::max(FIRSTIDX, smallidx-1)] / 2;
         smallnum     = magicints[smallidx] / 2;
         sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
-        larger       = magicints[maxidx];
 
         /* buf[0] holds the length in bytes */
 
@@ -882,7 +882,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         }
 
 
-        if (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0]) == 0)
+        if (xdr_opaque(xdrs, reinterpret_cast<char *>(&(buf[3])), static_cast<unsigned int>(buf[0])) == 0)
         {
             if (we_should_free)
             {
@@ -903,7 +903,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
         lip           = ip;
         while (i < lsize)
         {
-            thiscoord = (int *)(lip) + i * 3;
+            thiscoord = reinterpret_cast<int *>(lip) + i * 3;
 
             if (bitsize == 0)
             {
@@ -1272,7 +1272,6 @@ xtc_get_current_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
 
 static gmx_off_t xtc_get_next_frame_start(FILE *fp, XDR *xdrs, int natoms)
 {
-    int       inp;
     gmx_off_t res;
     int       ret;
     int       step;
@@ -1431,7 +1430,6 @@ int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms, gmx_bool bSeek
     gmx_bool  bOK = FALSE;
     gmx_off_t low = 0;
     gmx_off_t high, offset, pos;
-    int       res;
     int       dt_sign = 0;
 
     if (bSeekForwardOnly)
@@ -1592,7 +1590,6 @@ xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
 {
     float      time;
     gmx_off_t  off;
-    int        res;
     *bOK = 1;
     off  = gmx_ftell(fp);
     if (off < 0)
@@ -1601,7 +1598,7 @@ xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
         return -1;
     }
 
-    if ( (res = gmx_fseek(fp, -3*XDR_INT_SIZE, SEEK_END)) != 0)
+    if (gmx_fseek(fp, -3*XDR_INT_SIZE, SEEK_END) != 0)
     {
         *bOK = 0;
         return -1;
@@ -1613,7 +1610,7 @@ xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
         return -1;
     }
 
-    if ( (res = gmx_fseek(fp, off, SEEK_SET)) != 0)
+    if (gmx_fseek(fp, off, SEEK_SET) != 0)
     {
         *bOK = 0;
         return -1;
@@ -1627,7 +1624,6 @@ xdr_xtc_get_last_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
 {
     int        frame;
     gmx_off_t  off;
-    int        res;
     *bOK = 1;
 
     if ((off = gmx_ftell(fp)) < 0)
index 6d464f8c91b1b8574ad8d64da302cfd3b839181b..8b1e7a976a1ce6e37246be813e5c2055fbae4254 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,8 +38,9 @@
 
 #include "matio.h"
 
-#include <ctype.h>
-#include <stdio.h>
+#include <cctype>
+#include <cstdio>
+#include <cstring>
 
 #include <algorithm>
 
@@ -294,7 +295,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
     llmax = STRLEN;
 
     while ((NULL != fgetline(&line_buf, llmax, &llalloc, in)) &&
-           (strncmp(line_buf, "static", 6) != 0))
+           (std::strncmp(line_buf, "static", 6) != 0))
     {
         line = line_buf;
         parsestring(line, "title", (mm->title));
@@ -361,7 +362,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
     m = 0;
     while ((m < mm->nmap) && (NULL != fgetline(&line_buf, llmax, &llalloc, in)))
     {
-        line = strchr(line_buf, '\"');
+        line = std::strchr(line_buf, '\"');
         if  (line)
         {
             line++;
@@ -376,12 +377,12 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
                 map[m].code.c2 = line[1];
             }
             line += nch;
-            str   = strchr(line, '#');
+            str   = std::strchr(line, '#');
             if (str)
             {
                 str++;
                 col_len = 0;
-                while (isxdigit(str[col_len]))
+                while (std::isxdigit(str[col_len]))
                 {
                     col_len++;
                 }
@@ -406,7 +407,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
             }
             else
             {
-                str = strchr(line, 'c');
+                str = std::strchr(line, 'c');
                 if (str)
                 {
                     str += 2;
@@ -420,7 +421,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
                 map[m].rgb.g = 1;
                 map[m].rgb.b = 1;
             }
-            line = strchr(line, '\"');
+            line = std::strchr(line, '\"');
             line++;
             line2string(&line);
             map[m].desc = gmx_strdup(line);
@@ -446,7 +447,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
         bSetLine = TRUE;
         if (strstr(line, "x-axis"))
         {
-            line = strstr(line, "x-axis");
+            line = std::strstr(line, "x-axis");
             skipstr(line);
             if (mm->axis_x == NULL)
             {
@@ -467,9 +468,9 @@ static void read_xpm_entry(FILE *in, t_matrix *mm)
                 skipstr(line);
             }
         }
-        else if (strstr(line, "y-axis"))
+        else if (std::strstr(line, "y-axis"))
         {
-            line = strstr(line, "y-axis");
+            line = std::strstr(line, "y-axis");
             skipstr(line);
             if (mm->axis_y == NULL)
             {
@@ -560,7 +561,7 @@ int read_xpm_matrix(const char *fnm, t_matrix **mat)
     nmat = 0;
     while (NULL != fgetline(&line, STRLEN, &llalloc, in))
     {
-        if (strstr(line, "/* XPM */"))
+        if (std::strstr(line, "/* XPM */"))
         {
             srenew(*mat, nmat+1);
             read_xpm_entry(in, &(*mat)[nmat]);
@@ -705,9 +706,9 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
                 mapper[i % NMAP],
                 (*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
-                (unsigned int)round(255*r),
-                (unsigned int)round(255*g),
-                (unsigned int)round(255*b),
+                static_cast<unsigned int>(round(255*r)),
+                static_cast<unsigned int>(round(255*g)),
+                static_cast<unsigned int>(round(255*b)),
                 ((nmid - i)*lo + i*mid)/clev_lo);
     }
     for (i = 0; (i < (*nlevels-nmid)); i++)
@@ -718,9 +719,9 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
                 mapper[(i+nmid) % NMAP],
                 (*nlevels <= NMAP) ? ' ' : mapper[(i+nmid)/NMAP],
-                (unsigned int)round(255*r),
-                (unsigned int)round(255*g),
-                (unsigned int)round(255*b),
+                static_cast<unsigned int>(round(255*r)),
+                static_cast<unsigned int>(round(255*g)),
+                static_cast<unsigned int>(round(255*b)),
                 ((*nlevels - 1 - nmid - i)*mid + i*hi)/clev_hi);
     }
 }
@@ -740,9 +741,9 @@ static void pr_simple_cmap(FILE *out, real lo, real hi, int nlevel, t_rgb rlo,
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
                 mapper[(i+i0) % NMAP],
                 (nlevel <= NMAP) ? ' ' : mapper[(i+i0)/NMAP],
-                (unsigned int)round(255*r),
-                (unsigned int)round(255*g),
-                (unsigned int)round(255*b),
+                static_cast<unsigned int>(round(255*r)),
+                static_cast<unsigned int>(round(255*g)),
+                static_cast<unsigned int>(round(255*b)),
                 lo+fac*(hi-lo));
     }
 }
@@ -777,9 +778,9 @@ static void pr_discrete_cmap(FILE *out, int *nlevel, int i0)
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%3d\" */,\n",
                 mapper[(i+i0) % NMAP],
                 (n <= NMAP) ? ' ' : mapper[(i+i0)/NMAP],
-                (unsigned int)round(255*rgbd[i].r),
-                (unsigned int)round(255*rgbd[i].g),
-                (unsigned int)round(255*rgbd[i].b),
+                static_cast<unsigned int>(round(255*rgbd[i].r)),
+                static_cast<unsigned int>(round(255*rgbd[i].g)),
+                static_cast<unsigned int>(round(255*rgbd[i].b)),
                 i);
     }
 }
@@ -848,9 +849,9 @@ static void write_xpm_map(FILE *out, int n_x, int n_y, int *nlevels,
         b   = (nlo*rlo.b+i*rhi.b)*invlevel;
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
                 mapper[i % NMAP], (*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
-                (unsigned int)round(255*r),
-                (unsigned int)round(255*g),
-                (unsigned int)round(255*b),
+                static_cast<unsigned int>(round(255*r)),
+                static_cast<unsigned int>(round(255*g)),
+                static_cast<unsigned int>(round(255*b)),
                 (nlo*lo+i*hi)*invlevel);
     }
 }
@@ -1054,9 +1055,9 @@ void write_xpm_m(FILE *out, t_matrix m)
         fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%s\" */,\n",
                 m.map[i].code.c1,
                 bOneChar ? ' ' : m.map[i].code.c2,
-                (unsigned int)round(m.map[i].rgb.r*255),
-                (unsigned int)round(m.map[i].rgb.g*255),
-                (unsigned int)round(m.map[i].rgb.b*255), m.map[i].desc);
+                static_cast<unsigned int>(round(m.map[i].rgb.r*255)),
+                static_cast<unsigned int>(round(m.map[i].rgb.g*255)),
+                static_cast<unsigned int>(round(m.map[i].rgb.b*255)), m.map[i].desc);
     }
     write_xpm_axis(out, "x", m.flags & MAT_SPATIAL_X, m.nx, m.axis_x);
     write_xpm_axis(out, "y", m.flags & MAT_SPATIAL_Y, m.ny, m.axis_y);
similarity index 96%
rename from src/gromacs/fileio/md5.c
rename to src/gromacs/fileio/md5.cpp
index ff74cc68d073b5a4b4c5b73926a7c8424b48e48c..bacff2887dcc4170dea63a168d0a5b48f62d4492 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,7 +40,9 @@
 
 #include "config.h"
 
-#ifdef GMX_INTEGER_BIG_ENDIAN
+#include <cstring>
+
+#if GMX_INTEGER_BIG_ENDIAN
 #define ARCH_IS_BIG_ENDIAN 1
 #else
 #define ARCH_IS_BIG_ENDIAN 0
 
 #include "md5.h"
 
-#include <string.h>
-
 #undef BYTE_ORDER   /* 1 = big-endian, -1 = little-endian, 0 = unknown */
 #ifdef ARCH_IS_BIG_ENDIAN
 #  define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
@@ -201,15 +201,15 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
          */
         static const int w = 1;
 
-        if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+        if (*(reinterpret_cast<const md5_byte_t *>(&w))) /* dynamic little-endian */
 #endif
-#if BYTE_ORDER <= 0                    /* little-endian */
+#if BYTE_ORDER <= 0                                      /* little-endian */
         {
             /*
              * On little-endian machines, we can process properly aligned
              * data without copying it.
              */
-            if (!((data - (const md5_byte_t *)0) & 3))
+            if (!((data - reinterpret_cast<const md5_byte_t *>(0)) & 3))
             {
                 /* data are properly aligned */
                 X = (const md5_word_t *)data;
@@ -217,7 +217,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
             else
             {
                 /* not aligned */
-                memcpy(xbuf, data, 64);
+                std::memcpy(xbuf, data, 64);
                 X = xbuf;
             }
         }
@@ -398,7 +398,7 @@ gmx_md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
     {
         int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 
-        memcpy(pms->buf + offset, p, copy);
+        std::memcpy(pms->buf + offset, p, copy);
         if (offset + copy < 64)
         {
             return;
similarity index 94%
rename from src/gromacs/fileio/mdoutf.c
rename to src/gromacs/fileio/mdoutf.cpp
index bda0a7ac85d842308719eefc8e965be0711ee060..2f6f68ac37e7dfd6bbbc28080f82ab8acf18ed2c 100644 (file)
 #include "mdoutf.h"
 
 #include "gromacs/domdec/domdec.h"
+#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/tngio.h"
 #include "gromacs/fileio/trajectory_writing.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/checkpoint.h"
@@ -97,7 +98,7 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[],
     of->bExpanded               = ir->bExpanded;
     of->elamstats               = ir->expandedvals->elamstats;
     of->simulation_part         = ir->simulation_part;
-    of->x_compression_precision = ir->x_compression_precision;
+    of->x_compression_precision = static_cast<int>(ir->x_compression_precision);
     of->wcycle                  = wcycle;
 
     if (MASTER(cr))
@@ -124,7 +125,7 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[],
             {
                 case efTRR:
                 case efTRN:
-                    of->fp_trn = open_trn(filename, filemode);
+                    of->fp_trn = gmx_trr_open(filename, filemode);
                     break;
                 case efTNG:
                     gmx_tng_open(filename, filemode[0], &of->tng);
@@ -314,11 +315,11 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
         {
             if (of->fp_trn)
             {
-                fwrite_trn(of->fp_trn, step, t, state_local->lambda[efptFEP],
-                           state_local->box, top_global->natoms,
-                           (mdof_flags & MDOF_X) ? state_global->x : NULL,
-                           (mdof_flags & MDOF_V) ? global_v : NULL,
-                           (mdof_flags & MDOF_F) ? f_global : NULL);
+                gmx_trr_write_frame(of->fp_trn, step, t, state_local->lambda[efptFEP],
+                                    state_local->box, top_global->natoms,
+                                    (mdof_flags & MDOF_X) ? state_global->x : NULL,
+                                    (mdof_flags & MDOF_V) ? global_v : NULL,
+                                    (mdof_flags & MDOF_F) ? f_global : NULL);
                 if (gmx_fio_flush(of->fp_trn) != 0)
                 {
                     gmx_file("Cannot write trajectory; maybe you are out of disk space?");
@@ -326,11 +327,11 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
             }
 
             gmx_fwrite_tng(of->tng, FALSE, step, t, state_local->lambda[efptFEP],
-                           (const rvec *) state_local->box,
+                           state_local->box,
                            top_global->natoms,
-                           (mdof_flags & MDOF_X) ? (const rvec *) state_global->x : NULL,
-                           (mdof_flags & MDOF_V) ? (const rvec *) global_v : NULL,
-                           (mdof_flags & MDOF_F) ? (const rvec *) f_global : NULL);
+                           (mdof_flags & MDOF_X) ? state_global->x : NULL,
+                           (mdof_flags & MDOF_V) ? global_v : NULL,
+                           (mdof_flags & MDOF_F) ? f_global : NULL);
         }
         if (mdof_flags & MDOF_X_COMPRESSED)
         {
@@ -368,9 +369,9 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
                            step,
                            t,
                            state_local->lambda[efptFEP],
-                           (const rvec *) state_local->box,
+                           state_local->box,
                            of->natoms_x_compressed,
-                           (const rvec *) xxtc,
+                           xxtc,
                            NULL,
                            NULL);
             if (of->natoms_x_compressed != of->natoms_global)
@@ -404,7 +405,7 @@ void done_mdoutf(gmx_mdoutf_t of)
     }
     if (of->fp_trn)
     {
-        close_trn(of->fp_trn);
+        gmx_trr_close(of->fp_trn);
     }
     if (of->fp_dhdl != NULL)
     {
similarity index 92%
rename from src/gromacs/fileio/mtxio.c
rename to src/gromacs/fileio/mtxio.cpp
index c36f464815f1b99c2fa8ad16dbab21183f60c9cf..827452131cd9e14b19ed43d2f40b6e8fb3e89879 100644 (file)
@@ -44,7 +44,7 @@
  */
 
 #include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/xdrf.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
 #include "gromacs/linearalgebra/sparsematrix.h"
 #include "gromacs/utility/baseversion.h"
 #include "gromacs/utility/fatalerror.h"
@@ -86,10 +86,7 @@ void gmx_mtxio_write(const char *             filename,
                      gmx_sparsematrix_t *     sparse_matrix)
 {
     t_fileio   *fio;
-    XDR     *   xd;
     int         i, j, prec;
-    gmx_bool    bDum  = TRUE;
-    gmx_bool    bRead = FALSE;
     size_t      sz;
 
     if (full_matrix != NULL && sparse_matrix != NULL)
@@ -98,8 +95,6 @@ void gmx_mtxio_write(const char *             filename,
     }
 
     fio = gmx_fio_open(filename, "w");
-    gmx_fio_checktype(fio);
-    xd = gmx_fio_getxdr(fio);
 
     /* Write magic number */
     i = GMX_MTXIO_MAGIC_NUMBER;
@@ -128,7 +123,7 @@ void gmx_mtxio_write(const char *             filename,
         i = GMX_MTXIO_FULL_MATRIX;
         gmx_fio_do_int(fio, i);
         sz   = nrow*ncol;
-        bDum = gmx_fio_ndo_real(fio, full_matrix, sz);
+        gmx_fio_ndo_real(fio, full_matrix, sz);
     }
     else
     {
@@ -142,7 +137,7 @@ void gmx_mtxio_write(const char *             filename,
         {
             gmx_fatal(FARGS, "Internal inconsistency in sparse matrix.\n");
         }
-        bDum = gmx_fio_ndo_int(fio, sparse_matrix->ndata, sparse_matrix->nrow);
+        gmx_fio_ndo_int(fio, sparse_matrix->ndata, sparse_matrix->nrow);
         for (i = 0; i < sparse_matrix->nrow; i++)
         {
             for (j = 0; j < sparse_matrix->ndata[i]; j++)
@@ -164,16 +159,11 @@ gmx_mtxio_read (const char *            filename,
                 gmx_sparsematrix_t **   sparse_matrix)
 {
     t_fileio   *fio;
-    XDR     *   xd;
     int         i, j, prec;
-    gmx_bool    bDum  = TRUE;
-    gmx_bool    bRead = TRUE;
     char        gmxver[256];
     size_t      sz;
 
     fio = gmx_fio_open(filename, "r");
-    gmx_fio_checktype(fio);
-    xd = gmx_fio_getxdr(fio);
 
     /* Read and check magic number */
     i = GMX_MTXIO_MAGIC_NUMBER;
@@ -216,7 +206,7 @@ gmx_mtxio_read (const char *            filename,
 
         sz = (*nrow) * (*ncol);
         snew((*full_matrix), sz);
-        bDum = gmx_fio_ndo_real(fio, (*full_matrix), sz);
+        gmx_fio_ndo_real(fio, (*full_matrix), sz);
     }
     else if (NULL != sparse_matrix)
     {
@@ -233,8 +223,8 @@ gmx_mtxio_read (const char *            filename,
         snew((*sparse_matrix)->ndata, (*sparse_matrix)->nrow);
         snew((*sparse_matrix)->nalloc, (*sparse_matrix)->nrow);
         snew((*sparse_matrix)->data, (*sparse_matrix)->nrow);
-        bDum = gmx_fio_ndo_int(fio, (*sparse_matrix)->ndata,
-                               (*sparse_matrix)->nrow);
+        gmx_fio_ndo_int(fio, (*sparse_matrix)->ndata,
+                        (*sparse_matrix)->nrow);
 
         for (i = 0; i < (*sparse_matrix)->nrow; i++)
         {
similarity index 90%
rename from src/gromacs/fileio/pdbio.c
rename to src/gromacs/fileio/pdbio.cpp
index 20bd556dae66b0e680a567c5c0de966aa9c40076..572b3f94b59fd3511ea897cebc849273af0688f4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "pdbio.h"
 
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/copyrite.h"
@@ -82,8 +83,8 @@ static void xlate_atomname_pdb2gmx(char *name)
     int  i, length;
     char temp;
 
-    length = strlen(name);
-    if (length > 3 && isdigit(name[0]))
+    length = std::strlen(name);
+    if (length > 3 && std::isdigit(name[0]))
     {
         temp = name[0];
         for (i = 1; i < length; i++)
@@ -99,8 +100,8 @@ static void xlate_atomname_gmx2pdb(char *name)
     int  i, length;
     char temp;
 
-    length = strlen(name);
-    if (length > 3 && isdigit(name[length-1]))
+    length = std::strlen(name);
+    if (length > 3 && std::isdigit(name[length-1]))
     {
         temp = name[length-1];
         for (i = length-1; i > 0; --i)
@@ -128,7 +129,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box)
 
     if (norm2(box[YY])*norm2(box[ZZ]) != 0)
     {
-        alpha = RAD2DEG*acos(cos_angle_no_table(box[YY], box[ZZ]));
+        alpha = RAD2DEG*std::acos(cos_angle_no_table(box[YY], box[ZZ]));
     }
     else
     {
@@ -136,7 +137,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box)
     }
     if (norm2(box[XX])*norm2(box[ZZ]) != 0)
     {
-        beta  = RAD2DEG*acos(cos_angle_no_table(box[XX], box[ZZ]));
+        beta  = RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[ZZ]));
     }
     else
     {
@@ -144,7 +145,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box)
     }
     if (norm2(box[XX])*norm2(box[YY]) != 0)
     {
-        gamma = RAD2DEG*acos(cos_angle_no_table(box[XX], box[YY]));
+        gamma = RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[YY]));
     }
     else
     {
@@ -217,7 +218,7 @@ static void read_cryst1(char *line, int *ePBC, matrix box)
         {
             if (alpha != 90.0)
             {
-                cosa = cos(alpha*DEG2RAD);
+                cosa = std::cos(alpha*DEG2RAD);
             }
             else
             {
@@ -225,7 +226,7 @@ static void read_cryst1(char *line, int *ePBC, matrix box)
             }
             if (beta != 90.0)
             {
-                cosb = cos(beta*DEG2RAD);
+                cosb = std::cos(beta*DEG2RAD);
             }
             else
             {
@@ -233,8 +234,8 @@ static void read_cryst1(char *line, int *ePBC, matrix box)
             }
             if (gamma != 90.0)
             {
-                cosg = cos(gamma*DEG2RAD);
-                sing = sin(gamma*DEG2RAD);
+                cosg = std::cos(gamma*DEG2RAD);
+                sing = std::sin(gamma*DEG2RAD);
             }
             else
             {
@@ -245,8 +246,8 @@ static void read_cryst1(char *line, int *ePBC, matrix box)
             box[YY][YY] = fb*sing;
             box[ZZ][XX] = fc*cosb;
             box[ZZ][YY] = fc*(cosa - cosb*cosg)/sing;
-            box[ZZ][ZZ] = sqrt(fc*fc
-                               - box[ZZ][XX]*box[ZZ][XX] - box[ZZ][YY]*box[ZZ][YY]);
+            box[ZZ][ZZ] = std::sqrt(fc*fc
+                                    - box[ZZ][XX]*box[ZZ][XX] - box[ZZ][YY]*box[ZZ][YY]);
         }
         else
         {
@@ -271,9 +272,7 @@ void write_pdbfile_indexed(FILE *out, const char *title,
     char              altloc;
     real              occup, bfac;
     gmx_bool          bOccup;
-    int               nlongname = 0;
     int               chainnum, lastchainnum;
-    int               lastresind, lastchainresind;
     gmx_residuetype_t*rt;
     const char       *p_restype;
     const char       *p_lastrestype;
@@ -305,15 +304,12 @@ void write_pdbfile_indexed(FILE *out, const char *title,
 
     fprintf(out, "MODEL %8d\n", model_nr > 0 ? model_nr : 1);
 
-    lastchainresind   = -1;
     lastchainnum      = -1;
-    resind            = -1;
     p_restype         = NULL;
 
     for (ii = 0; ii < nindex; ii++)
     {
         i             = index[ii];
-        lastresind    = resind;
         resind        = atoms->atom[i].resind;
         chainnum      = atoms->resinfo[resind].chainnum;
         p_lastrestype = p_restype;
@@ -328,7 +324,6 @@ void write_pdbfile_indexed(FILE *out, const char *title,
                 fprintf(out, "TER\n");
             }
             lastchainnum    = chainnum;
-            lastchainresind = lastresind;
         }
 
         strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
@@ -359,7 +354,7 @@ void write_pdbfile_indexed(FILE *out, const char *title,
         }
         if (atoms->pdbinfo)
         {
-            type   = (enum PDB_record)(atoms->pdbinfo[i].type);
+            type   = static_cast<enum PDB_record>(atoms->pdbinfo[i].type);
             altloc = atoms->pdbinfo[i].altloc;
             if (!isalnum(altloc))
             {
@@ -444,7 +439,7 @@ int line2type(char *line)
 
     for (k = 0; (k < epdbNR); k++)
     {
-        if (strncmp(type, pdbtp[k], strlen(pdbtp[k])) == 0)
+        if (std::strncmp(type, pdbtp[k], strlen(pdbtp[k])) == 0)
         {
             break;
         }
@@ -478,10 +473,10 @@ static void read_anisou(char line[], int natom, t_atoms *atoms)
     trim(anm);
 
     /* Search backwards for number and name only */
-    atomnr = strtol(anr, NULL, 10);
+    atomnr = std::strtol(anr, NULL, 10);
     for (i = natom-1; (i >= 0); i--)
     {
-        if ((strcmp(anm, *(atoms->atomname[i])) == 0) &&
+        if ((std::strcmp(anm, *(atoms->atomname[i])) == 0) &&
             (atomnr == atoms->pdbinfo[i].atomnr))
         {
             break;
@@ -524,11 +519,11 @@ void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps)
     }
     for (i = 0; (i < atoms->nr); i++)
     {
-        strcpy(anm, atoms->pdbinfo[i].atomnm);
-        strcpy(anm_copy, atoms->pdbinfo[i].atomnm);
+        std::strcpy(anm, atoms->pdbinfo[i].atomnm);
+        std::strcpy(anm_copy, atoms->pdbinfo[i].atomnm);
         len        = strlen(anm);
         atomnumber = NOTSET;
-        if ((anm[0] != ' ') && ((len <= 2) || ((len > 2) && !isdigit(anm[2]))))
+        if ((anm[0] != ' ') && ((len <= 2) || ((len > 2) && !std::isdigit(anm[2]))))
         {
             anm_copy[2] = nc;
             if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
@@ -547,7 +542,7 @@ void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps)
         if (atomnumber == NOTSET)
         {
             k = 0;
-            while ((k < strlen(anm)) && (isspace(anm[k]) || isdigit(anm[k])))
+            while ((k < std::strlen(anm)) && (std::isspace(anm[k]) || std::isdigit(anm[k])))
             {
                 k++;
             }
@@ -560,7 +555,7 @@ void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps)
         }
         atoms->atom[i].atomnumber = atomnumber;
         ptr = gmx_atomprop_element(aps, atomnumber);
-        strncpy(atoms->atom[i].elem, ptr == NULL ? "" : ptr, 4);
+        std::strncpy(atoms->atom[i].elem, ptr == NULL ? "" : ptr, 4);
         if (debug)
         {
             fprintf(debug, "Atomnumber for atom '%s' is %d\n", anm, atomnumber);
@@ -601,7 +596,7 @@ static int read_atom(t_symtab *symtab,
         anm[k] = line[j];
     }
     anm[k] = nc;
-    strcpy(anm_copy, anm);
+    std::strcpy(anm_copy, anm);
     rtrim(anm_copy);
     atomnumber = NOTSET;
     trim(anm);
@@ -623,7 +618,7 @@ static int read_atom(t_symtab *symtab,
     }
     rnr[k] = nc;
     trim(rnr);
-    resnr = strtol(rnr, NULL, 10);
+    resnr = std::strtol(rnr, NULL, 10);
     resic = line[j];
     j    += 4;
 
@@ -723,14 +718,14 @@ gmx_bool is_hydrogen(const char *nm)
 {
     char buf[30];
 
-    strcpy(buf, nm);
+    std::strcpy(buf, nm);
     trim(buf);
 
     if (buf[0] == 'H')
     {
         return TRUE;
     }
-    else if ((isdigit(buf[0])) && (buf[1] == 'H'))
+    else if ((std::isdigit(buf[0])) && (buf[1] == 'H'))
     {
         return TRUE;
     }
@@ -741,10 +736,10 @@ gmx_bool is_dummymass(const char *nm)
 {
     char buf[30];
 
-    strcpy(buf, nm);
+    std::strcpy(buf, nm);
     trim(buf);
 
-    if ((buf[0] == 'M') && isdigit(buf[strlen(buf)-1]))
+    if ((buf[0] == 'M') && std::isdigit(buf[strlen(buf)-1]))
     {
         return TRUE;
     }
@@ -763,7 +758,7 @@ static void gmx_conect_addline(gmx_conect_t *con, char *line)
     {
         do
         {
-            strcat(form2, "%*s");
+            std::strcat(form2, "%*s");
             sprintf(format, "%s%%d", form2);
             n = sscanf(line, format, &aj);
             if (n == 1)
@@ -795,19 +790,19 @@ gmx_conect gmx_conect_init()
 
     snew(gc, 1);
 
-    return (gmx_conect) gc;
+    return gc;
 }
 
 void gmx_conect_done(gmx_conect conect)
 {
-    gmx_conect_t *gc = (gmx_conect_t *)conect;
+    gmx_conect_t *gc = conect;
 
     sfree(gc->conect);
 }
 
 gmx_bool gmx_conect_exist(gmx_conect conect, int ai, int aj)
 {
-    gmx_conect_t *gc = (gmx_conect_t *)conect;
+    gmx_conect_t *gc = conect;
     int           i;
 
     /* if (!gc->bSorted)
@@ -829,7 +824,6 @@ gmx_bool gmx_conect_exist(gmx_conect conect, int ai, int aj)
 void gmx_conect_add(gmx_conect conect, int ai, int aj)
 {
     gmx_conect_t *gc = (gmx_conect_t *)conect;
-    int           i;
 
     /* if (!gc->bSorted)
        sort_conect(gc);*/
@@ -846,15 +840,14 @@ int read_pdbfile(FILE *in, char *title, int *model_nr,
                  t_atoms *atoms, rvec x[], int *ePBC, matrix box, gmx_bool bChange,
                  gmx_conect conect)
 {
-    gmx_conect_t *gc = (gmx_conect_t *)conect;
+    gmx_conect_t *gc = conect;
     t_symtab      symtab;
     gmx_bool      bCOMPND;
     gmx_bool      bConnWarn = FALSE;
     char          line[STRLEN+1];
     int           line_type;
     char         *c, *d;
-    int           natom, chainnum, nres_ter_prev = 0;
-    char          chidmax = ' ';
+    int           natom, chainnum;
     gmx_bool      bStop   = FALSE;
 
     if (ePBC)
@@ -897,7 +890,7 @@ int read_pdbfile(FILE *in, char *title, int *model_nr,
 
             case epdbTITLE:
             case epdbHEADER:
-                if (strlen(line) > 6)
+                if (std::strlen(line) > 6)
                 {
                     c = line+6;
                     /* skip HEADER or TITLE and spaces */
@@ -910,22 +903,22 @@ int read_pdbfile(FILE *in, char *title, int *model_nr,
                         c++;
                     }
                     /* truncate after title */
-                    d = strstr(c, "      ");
+                    d = std::strstr(c, "      ");
                     if (d)
                     {
                         d[0] = '\0';
                     }
-                    if (strlen(c) > 0)
+                    if (std::strlen(c) > 0)
                     {
-                        strcpy(title, c);
+                        std::strcpy(title, c);
                     }
                 }
                 break;
 
             case epdbCOMPND:
-                if ((!strstr(line, ": ")) || (strstr(line+6, "MOLECULE:")))
+                if ((!std::strstr(line, ": ")) || (std::strstr(line+6, "MOLECULE:")))
                 {
-                    if (!(c = strstr(line+6, "MOLECULE:")) )
+                    if (!(c = std::strstr(line+6, "MOLECULE:")) )
                     {
                         c = line;
                     }
@@ -952,12 +945,12 @@ int read_pdbfile(FILE *in, char *title, int *model_nr,
                     {
                         if (bCOMPND)
                         {
-                            strcat(title, "; ");
-                            strcat(title, c);
+                            std::strcat(title, "; ");
+                            std::strcat(title, c);
                         }
                         else
                         {
-                            strcpy(title, c);
+                            std::strcpy(title, c);
                         }
                     }
                     bCOMPND = TRUE;
@@ -1006,11 +999,11 @@ void get_pdb_coordnum(FILE *in, int *natoms)
     *natoms = 0;
     while (fgets2(line, STRLEN, in))
     {
-        if (strncmp(line, "ENDMDL", 6) == 0)
+        if (std::strncmp(line, "ENDMDL", 6) == 0)
         {
             break;
         }
-        if ((strncmp(line, "ATOM  ", 6) == 0) || (strncmp(line, "HETATM", 6) == 0))
+        if ((std::strncmp(line, "ATOM  ", 6) == 0) || (std::strncmp(line, "HETATM", 6) == 0))
         {
             (*natoms)++;
         }
@@ -1082,16 +1075,16 @@ gmx_fprintf_pdb_atomline(FILE *            fp,
         /* If the atom name is an element name with two chars, it should start already in column 13.
          * Otherwise it should start in column 14, unless the name length is 4 chars.
          */
-        if ( (element != NULL) && (strlen(element) >= 2) && (gmx_strncasecmp(atom_name, element, 2) == 0) )
+        if ( (element != NULL) && (std::strlen(element) >= 2) && (gmx_strncasecmp(atom_name, element, 2) == 0) )
         {
             start_name_in_col13 = TRUE;
         }
         else
         {
-            start_name_in_col13 = (strlen(atom_name) >= 4);
+            start_name_in_col13 = (std::strlen(atom_name) >= 4);
         }
         sprintf(tmp_atomname, start_name_in_col13 ? "" : " ");
-        strncat(tmp_atomname, atom_name, 4);
+        std::strncat(tmp_atomname, atom_name, 4);
         tmp_atomname[5] = '\0';
     }
     else
@@ -1100,14 +1093,14 @@ gmx_fprintf_pdb_atomline(FILE *            fp,
     }
 
     /* Format residue name */
-    strncpy(tmp_resname, (res_name != NULL) ? res_name : "", 4);
+    std::strncpy(tmp_resname, (res_name != NULL) ? res_name : "", 4);
     /* Make sure the string is terminated if strlen was > 4 */
     tmp_resname[4] = '\0';
     /* String is properly terminated, so now we can use strcat. By adding a
      * space we can write it right-justified, and if the original name was
      * three characters or less there will be a space added on the right side.
      */
-    strcat(tmp_resname, " ");
+    std::strcat(tmp_resname, " ");
 
     /* Truncate integers so they fit */
     atom_seq_number = atom_seq_number % 100000;
similarity index 94%
rename from src/gromacs/fileio/strdb.c
rename to src/gromacs/fileio/strdb.cpp
index a0fc276d8fee579723e6856ce011ffc02fefc86d..937256031b263ff4bd8f2fb04cb4012dbccc6b4d 100644 (file)
@@ -38,9 +38,9 @@
 
 #include "strdb.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
@@ -61,12 +61,12 @@ gmx_bool get_a_line(FILE *fp, char line[], int n)
             sfree(line0);
             return FALSE;
         }
-        dum = strchr(line0, '\n');
+        dum = std::strchr(line0, '\n');
         if (dum)
         {
             dum[0] = '\0';
         }
-        else if (strlen(line0) == n)
+        else if (static_cast<int>(std::strlen(line0)) == n)
         {
             fprintf(stderr, "Warning: line length exceeds buffer length (%d), data might be corrupted\n", n);
             line0[n-1] = '\0';
@@ -76,12 +76,12 @@ gmx_bool get_a_line(FILE *fp, char line[], int n)
             fprintf(stderr, "Warning: file does not end with a newline, last line:\n%s\n",
                     line0);
         }
-        dum = strchr(line0, ';');
+        dum = std::strchr(line0, ';');
         if (dum)
         {
             dum[0] = '\0';
         }
-        strncpy(line, line0, n);
+        std::strncpy(line, line0, n);
         dum = line0;
         ltrim(dum);
     }
@@ -95,14 +95,14 @@ gmx_bool get_header(char line[], char *header)
 {
     char temp[STRLEN], *dum;
 
-    strcpy(temp, line);
-    dum = strchr(temp, '[');
+    std::strcpy(temp, line);
+    dum = std::strchr(temp, '[');
     if (dum == NULL)
     {
         return FALSE;
     }
     dum[0] = ' ';
-    dum    = strchr(temp, ']');
+    dum    = std::strchr(temp, ']');
     if (dum == NULL)
     {
         gmx_fatal(FARGS, "header is not terminated on line:\n'%s'\n", line);
index b0f62731b68418d10f8cf47e9d5f7b0bb073173a..8f83ed1cca72940202b559308d4b1eb2324ec14b 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2013,2014, by the GROMACS development team, led by
+# Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if(GMX_USE_TNG)
-    gmx_add_unit_test(FileIOTests fileio-test
-        tngio.cpp)
+set(test_sources
+    confio.cpp
+    )
+if (GMX_USE_TNG)
+    list(APPEND test_sources tngio.cpp)
 endif()
+gmx_add_unit_test(FileIOTests fileio-test ${test_sources})
diff --git a/src/gromacs/fileio/tests/confio.cpp b/src/gromacs/fileio/tests/confio.cpp
new file mode 100644 (file)
index 0000000..eb747f4
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Tests for reading/writing different structure file formats.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_fileio
+ */
+#include "gmxpre.h"
+
+#include "gromacs/fileio/confio.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "gromacs/fileio/filenm.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/math/vectypes.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/smalloc.h"
+
+#include "testutils/stringtest.h"
+#include "testutils/testfilemanager.h"
+
+// TODO: These should really appear somewhere centralized.
+/*! \brief
+ * Google Test formatter for GromacsFileType values.
+ */
+void PrintTo(const GromacsFileType &ftp, std::ostream *os)
+{
+    *os << "'" << ftp2ext(ftp) << "'";
+}
+
+namespace
+{
+
+class StructureIORoundtripTest : public gmx::test::StringTestBase,
+                                 public ::testing::WithParamInterface<GromacsFileType>
+{
+    public:
+        StructureIORoundtripTest()
+        {
+            generateReferenceTopology();
+            generateReferenceCoordinates();
+            testTop_ = NULL;
+            testX_   = NULL;
+            clear_mat(testBox_);
+            referenceFilename_ =
+                fileManager_.getTemporaryFilePath(getFileSuffix("ref"));
+            testFilename_ =
+                fileManager_.getTemporaryFilePath(getFileSuffix("test"));
+        }
+        ~StructureIORoundtripTest()
+        {
+            if (testTop_ != NULL)
+            {
+                free_t_atoms(&testTop_->atoms, TRUE);
+                done_top(testTop_);
+                sfree(testTop_);
+            }
+            sfree(testX_);
+            done_top(refTop_);
+            sfree(refTop_);
+        }
+
+        void writeReferenceFile()
+        {
+            write_sto_conf(referenceFilename_.c_str(), *refTop_->name,
+                           &refTop_->atoms, as_rvec_array(&refX_[0]), NULL, -1,
+                           refBox_);
+        }
+
+        void readReferenceFileStx()
+        {
+            int natoms = -1;
+            get_stx_coordnum(referenceFilename_.c_str(), &natoms);
+            ASSERT_EQ(refTop_->atoms.nr, natoms)
+            << "get_stx_coordnum() returned unexpected number of atoms";
+            char title[STRLEN];
+            snew(testTop_, 1);
+            init_t_atoms(&testTop_->atoms, natoms, GetParam() == efPDB);
+            snew(testX_, natoms);
+            read_stx_conf(referenceFilename_.c_str(), title, &testTop_->atoms,
+                          testX_, NULL, NULL, testBox_);
+            testTop_->name = put_symtab(&testTop_->symtab, title);
+        }
+
+        void readReferenceFileTps()
+        {
+            snew(testTop_, 1);
+            int  ePBC = -2;
+            char title[STRLEN];
+            read_tps_conf(referenceFilename_.c_str(), title, testTop_,
+                          &ePBC, &testX_, NULL, testBox_, FALSE);
+            testTop_->name = put_symtab(&testTop_->symtab, title);
+        }
+
+        void testTopologies()
+        {
+            // TODO: Compare the topologies.
+        }
+
+        void writeTestFileAndTest()
+        {
+            write_sto_conf(testFilename_.c_str(), *testTop_->name,
+                           &testTop_->atoms, testX_, NULL, -1, testBox_);
+            testFilesEqual(referenceFilename_, testFilename_);
+        }
+
+    private:
+        std::string getFileSuffix(const char *type)
+        {
+            return std::string(type) + "." + ftp2ext(GetParam());
+        }
+
+        void generateReferenceTopology()
+        {
+            snew(refTop_, 1);
+            open_symtab(&refTop_->symtab);
+            if (GetParam() == efESP)
+            {
+                // Titles cannot be read from an .esp file...
+                refTop_->name = put_symtab(&refTop_->symtab, "");
+            }
+            else
+            {
+                refTop_->name = put_symtab(&refTop_->symtab, "Test title");
+            }
+            const int atomCount = 10;
+            init_t_atoms(&refTop_->atoms, atomCount, FALSE);
+            for (int i = 0; i < atomCount; ++i)
+            {
+                char name[3];
+                name[0]                       = 'A';
+                name[1]                       = 'A' + i%3;
+                name[2]                       = '\0';
+                refTop_->atoms.atomname[i]    = put_symtab(&refTop_->symtab, name);
+                refTop_->atoms.atom[i].resind = i/3;
+                if (i%3 == 0)
+                {
+                    char resname[3];
+                    resname[0] = 'R';
+                    resname[1] = 'A' + i/3;
+                    resname[2] = '\0';
+                    t_atoms_set_resinfo(&refTop_->atoms, i, &refTop_->symtab,
+                                        resname, i/3 + 1, ' ', 0, ' ');
+                }
+            }
+            refTop_->atoms.nres = 4;
+            close_symtab(&refTop_->symtab);
+        }
+
+        void generateReferenceCoordinates()
+        {
+            clear_mat(refBox_);
+            refBox_[XX][XX] = 1;
+            refBox_[YY][YY] = 2;
+            refBox_[ZZ][ZZ] = 3;
+            const int atomCount = refTop_->atoms.nr;
+            refX_.reserve(atomCount);
+            for (int i = 0; i < atomCount; ++i)
+            {
+                refX_.push_back(gmx::RVec(i%4, i/4, (i/2)%3));
+            }
+        }
+
+        gmx::test::TestFileManager      fileManager_;
+        std::string                     referenceFilename_;
+        std::string                     testFilename_;
+        t_topology                     *refTop_;
+        std::vector<gmx::RVec>          refX_;
+        matrix                          refBox_;
+        t_topology                     *testTop_;
+        rvec                           *testX_;
+        matrix                          testBox_;
+};
+
+TEST_P(StructureIORoundtripTest, ReadWriteStxConf)
+{
+    writeReferenceFile();
+    readReferenceFileStx();
+    testTopologies();
+    writeTestFileAndTest();
+}
+
+TEST_P(StructureIORoundtripTest, ReadWriteTpsConf)
+{
+    writeReferenceFile();
+    readReferenceFileTps();
+    testTopologies();
+    writeTestFileAndTest();
+}
+
+INSTANTIATE_TEST_CASE_P(WithDifferentFormats,
+                        StructureIORoundtripTest,
+                            ::testing::Values(efGRO, efG96, efPDB, efESP));
+
+} // namespace
similarity index 97%
rename from src/gromacs/fileio/timecontrol.c
rename to src/gromacs/fileio/timecontrol.cpp
index 735d649423d480023d3a93757770078d8244b5f4..06c211e5da1fecb2da7a070a81ddd32c4945ab2d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index 417c246ca34101e15d794255fd61bd7feb2dd1d9..55d04721118a938d5869d18f31aa28a51bf12b29 100644 (file)
@@ -42,7 +42,6 @@
 #include "tng/tng_io.h"
 #endif
 
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/types/ifunc.h"
 #include "gromacs/math/units.h"
@@ -50,6 +49,7 @@
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/sysinfo.h"
index 15a92c1398d67a3ed4f0b5375082759a3a08e9fc..b006a042f19c756b24fc4e25ce613bdab67e129d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "config.h"
 
-#include <math.h>
+#include <cmath>
 
 #ifdef GMX_USE_TNG
 #include "tng/tng_io.h"
@@ -205,11 +205,11 @@ void gmx_write_tng_from_trxframe(tng_trajectory_t        output,
                    frame->step,
                    frame->time,
                    0,
-                   (const rvec *) frame->box,
+                   frame->box,
                    natoms,
-                   (const rvec *) frame->x,
-                   (const rvec *) frame->v,
-                   (const rvec *) frame->f);
+                   frame->x,
+                   frame->v,
+                   frame->f);
 #else
     GMX_UNUSED_VALUE(output);
     GMX_UNUSED_VALUE(frame);
@@ -243,7 +243,7 @@ convert_array_to_real_array(void       *from,
                     {
                         for (j = 0; j < nValues; j++)
                         {
-                            to[i*nValues+j] = (real)((float *)from)[i*nValues+j] * fact;
+                            to[i*nValues+j] = reinterpret_cast<float *>(from)[i*nValues+j] * fact;
                         }
                     }
                 }
@@ -254,7 +254,7 @@ convert_array_to_real_array(void       *from,
                 {
                     for (j = 0; j < nValues; j++)
                     {
-                        to[i*nValues+j] = (real)((float *)from)[i*nValues+j] * fact;
+                        to[i*nValues+j] = reinterpret_cast<float *>(from)[i*nValues+j] * fact;
                     }
                 }
             }
@@ -264,7 +264,7 @@ convert_array_to_real_array(void       *from,
             {
                 for (j = 0; j < nValues; j++)
                 {
-                    to[i*nValues+j] = (real)((gmx_int64_t *)from)[i*nValues+j] * fact;
+                    to[i*nValues+j] = reinterpret_cast<gmx_int64_t *>(from)[i*nValues+j] * fact;
                 }
             }
             break;
@@ -281,7 +281,7 @@ convert_array_to_real_array(void       *from,
                     {
                         for (j = 0; j < nValues; j++)
                         {
-                            to[i*nValues+j] = (real)((double *)from)[i*nValues+j] * fact;
+                            to[i*nValues+j] = reinterpret_cast<double *>(from)[i*nValues+j] * fact;
                         }
                     }
                 }
@@ -292,7 +292,7 @@ convert_array_to_real_array(void       *from,
                 {
                     for (j = 0; j < nValues; j++)
                     {
-                        to[i*nValues+j] = (real)((double *)from)[i*nValues+j] * fact;
+                        to[i*nValues+j] = reinterpret_cast<double *>(from)[i*nValues+j] * fact;
                     }
                 }
             }
@@ -541,8 +541,8 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
                 }
                 for (int i = 0; i < DIM; i++)
                 {
-                    convert_array_to_real_array((char *)(values) + size * i * DIM,
-                                                (real *) fr->box[i],
+                    convert_array_to_real_array(reinterpret_cast<char *>(values) + size * i * DIM,
+                                                reinterpret_cast<real *>(fr->box[i]),
                                                 getDistanceScaleFactor(input),
                                                 1,
                                                 DIM,
@@ -553,7 +553,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
             case TNG_TRAJ_POSITIONS:
                 srenew(fr->x, fr->natoms);
                 convert_array_to_real_array(values,
-                                            (real *) fr->x,
+                                            reinterpret_cast<real *>(fr->x),
                                             getDistanceScaleFactor(input),
                                             fr->natoms,
                                             DIM,
@@ -587,7 +587,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
             case TNG_TRAJ_FORCES:
                 srenew(fr->f, fr->natoms);
                 convert_array_to_real_array(values,
-                                            (real *) fr->f,
+                                            reinterpret_cast<real *>(fr->f),
                                             getDistanceScaleFactor(input),
                                             fr->natoms,
                                             DIM,
@@ -598,10 +598,10 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
                 switch (datatype)
                 {
                     case TNG_FLOAT_DATA:
-                        fr->lambda = (*(float *)values);
+                        fr->lambda = *(reinterpret_cast<float *>(values));
                         break;
                     case TNG_DOUBLE_DATA:
-                        fr->lambda = (*(double *)values);
+                        fr->lambda = *(reinterpret_cast<double *>(values));
                         break;
                     default:
                         gmx_incons("Illegal datatype lambda value!");
@@ -615,7 +615,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t            input,
          * be reallocated if it is not NULL. */
     }
 
-    fr->step  = (int) frameNumber;
+    fr->step  = static_cast<int>(frameNumber);
     fr->bStep = TRUE;
     // Convert the time to ps
     fr->time  = frameTime / PICO;
similarity index 94%
rename from src/gromacs/fileio/tpxio.c
rename to src/gromacs/fileio/tpxio.cpp
index 26aed407ee010b92645dc3e7d5cd4ca2e541692d..623c1d23fc8e816de78a1cdb1824bc65eff68fba 100644 (file)
 
 #include "tpxio.h"
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
 
-#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/math/vec.h"
-#include "gromacs/topology/atomprop.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/topology/symtab.h"
@@ -239,7 +240,6 @@ static void do_pullgrp_tpx_pre95(t_fileio     *fio,
                                  gmx_bool      bRead,
                                  int           file_version)
 {
-    int  i;
     rvec tmp;
 
     gmx_fio_do_int(fio, pgrp->nat);
@@ -273,8 +273,6 @@ static void do_pullgrp_tpx_pre95(t_fileio     *fio,
 
 static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
 {
-    int      i;
-
     gmx_fio_do_int(fio, pgrp->nat);
     if (bRead)
     {
@@ -293,8 +291,6 @@ static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
 static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version,
                           int ePullOld, int eGeomOld, ivec dimOld)
 {
-    int      i;
-
     gmx_fio_do_int(fio, pcrd->group[0]);
     gmx_fio_do_int(fio, pcrd->group[1]);
     if (file_version >= tpxv_PullCoordTypeGeom)
@@ -333,10 +329,6 @@ static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version,
 
 static void do_expandedvals(t_fileio *fio, t_expanded *expand, t_lambda *fepvals, gmx_bool bRead, int file_version)
 {
-    /* i is used in the ndo_double macro*/
-    int      i;
-    real     fv;
-    real     rdum;
     int      n_lambda = fepvals->n_lambda;
 
     /* reset the lambda calculation window */
@@ -411,8 +403,7 @@ static void do_imd(t_fileio *fio, t_IMD *imd, gmx_bool bRead)
 static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int file_version)
 {
     /* i is defined in the ndo_double macro; use g to iterate. */
-    int      i, g;
-    real     fv;
+    int      g;
     real     rdum;
 
     /* free energy values */
@@ -636,7 +627,7 @@ static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int fil
 static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead,
                     int file_version, int ePullOld)
 {
-    int  eGeomOld;
+    int  eGeomOld = -1;
     ivec dimOld;
     int  g;
 
@@ -699,7 +690,7 @@ static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead,
         for (g = 0; g < pull->ngroup; g++)
         {
             /* We read and ignore a pull coordinate for group 0 */
-            do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[max(g-1, 0)],
+            do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[std::max(g-1, 0)],
                                  bRead, file_version);
             if (g > 0)
             {
@@ -727,8 +718,6 @@ static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead,
 
 static void do_rotgrp(t_fileio *fio, t_rotgrp *rotg, gmx_bool bRead)
 {
-    int      i;
-
     gmx_fio_do_int(fio, rotg->eType);
     gmx_fio_do_int(fio, rotg->bMassW);
     gmx_fio_do_int(fio, rotg->nat);
@@ -774,8 +763,7 @@ static void do_rot(t_fileio *fio, t_rot *rot, gmx_bool bRead)
 
 static void do_swapcoords(t_fileio *fio, t_swapcoords *swap, gmx_bool bRead)
 {
-    int i, j;
-
+    int j;
 
     gmx_fio_do_int(fio, swap->nat);
     gmx_fio_do_int(fio, swap->nat_sol);
@@ -1840,10 +1828,6 @@ void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams,
     int      idum;
     real     rdum;
 
-    if (!bRead)
-    {
-        gmx_fio_set_comment(fio, interaction_function[ftype].name);
-    }
     switch (ftype)
     {
         case F_ANGLES:
@@ -2160,21 +2144,12 @@ void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams,
             gmx_fatal(FARGS, "unknown function type %d (%s) in %s line %d",
                       ftype, interaction_function[ftype].name, __FILE__, __LINE__);
     }
-    if (!bRead)
-    {
-        gmx_fio_unset_comment(fio);
-    }
 }
 
-static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version,
-                     int ftype)
+static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version)
 {
-    int      i, k, idum;
+    int      i, idum;
 
-    if (!bRead)
-    {
-        gmx_fio_set_comment(fio, interaction_function[ftype].name);
-    }
     if (file_version < 44)
     {
         for (i = 0; i < MAXNODES; i++)
@@ -2188,16 +2163,12 @@ static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_ver
         snew(ilist->iatoms, ilist->nr);
     }
     gmx_fio_ndo_int(fio, ilist->iatoms, ilist->nr);
-    if (!bRead)
-    {
-        gmx_fio_unset_comment(fio);
-    }
 }
 
 static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
                         gmx_bool bRead, int file_version)
 {
-    int          idum, i, j;
+    int          idum, i;
     unsigned int k;
 
     gmx_fio_do_int(fio, ffparams->atnr);
@@ -2292,7 +2263,7 @@ static void add_settle_atoms(t_ilist *ilist)
 static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
                       int file_version)
 {
-    int          i, j, renum[F_NRE];
+    int          j;
     gmx_bool     bClear;
     unsigned int k;
 
@@ -2316,7 +2287,7 @@ static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
         }
         else
         {
-            do_ilist(fio, &ilist[j], bRead, file_version, j);
+            do_ilist(fio, &ilist[j], bRead, file_version);
             if (file_version < 78 && j == F_SETTLE && ilist[j].nr > 0)
             {
                 add_settle_atoms(&ilist[j]);
@@ -2448,7 +2419,6 @@ static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
                     int file_version, gmx_groups_t *groups, int atnr)
 {
     int    i, myngrp;
-    char * p_elem;
 
     gmx_fio_do_real(fio, atom->m);
     gmx_fio_do_real(fio, atom->q);
@@ -2466,7 +2436,7 @@ static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
             /* Set element string from atomic number if present.
              * This routine returns an empty string if the name is not found.
              */
-            strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
+            std::strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
             /* avoid warnings about potentially unterminated string */
             atom->elem[3] = '\0';
         }
@@ -2507,7 +2477,7 @@ static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
 static void do_grps(t_fileio *fio, int ngrp, t_grps grps[], gmx_bool bRead,
                     int file_version)
 {
-    int      i, j, myngrp;
+    int      j, myngrp;
 
     if (file_version < 23)
     {
@@ -2651,7 +2621,7 @@ static void do_groups(t_fileio *fio, gmx_groups_t *groups,
                       gmx_bool bRead, t_symtab *symtab,
                       int file_version)
 {
-    int      g, n, i;
+    int      g;
 
     do_grps(fio, egcNR, groups->grps, bRead, file_version);
     gmx_fio_do_int(fio, groups->ngrpname);
@@ -2684,7 +2654,7 @@ static void do_groups(t_fileio *fio, gmx_groups_t *groups,
 static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes, gmx_bool bRead,
                          int file_version)
 {
-    int      i, j;
+    int      j;
 
     if (file_version > 25)
     {
@@ -2800,56 +2770,10 @@ static void do_cmap(t_fileio *fio, gmx_cmap_t *cmap_grid, gmx_bool bRead)
 }
 
 
-void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
-{
-    int  m, a, a0, a1, r;
-    char c, chainid;
-    int  chainnum;
-
-    /* We always assign a new chain number, but save the chain id characters
-     * for larger molecules.
-     */
-#define CHAIN_MIN_ATOMS 15
-
-    chainnum = 0;
-    chainid  = 'A';
-    for (m = 0; m < mols->nr; m++)
-    {
-        a0 = mols->index[m];
-        a1 = mols->index[m+1];
-        if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
-        {
-            c = chainid;
-            chainid++;
-        }
-        else
-        {
-            c = ' ';
-        }
-        for (a = a0; a < a1; a++)
-        {
-            atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
-            atoms->resinfo[atoms->atom[a].resind].chainid  = c;
-        }
-        chainnum++;
-    }
-
-    /* Blank out the chain id if there was only one chain */
-    if (chainid == 'B')
-    {
-        for (r = 0; r < atoms->nres; r++)
-        {
-            atoms->resinfo[r].chainid = ' ';
-        }
-    }
-}
-
 static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead,
                        t_symtab *symtab, int file_version,
                        gmx_groups_t *groups)
 {
-    int i;
-
     if (file_version >= 57)
     {
         do_symstr(fio, &(molt->name), bRead, symtab);
@@ -2879,8 +2803,6 @@ static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead,
 
 static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
 {
-    int i;
-
     gmx_fio_do_int(fio, molb->type);
     gmx_fio_do_int(fio, molb->nmol);
     gmx_fio_do_int(fio, molb->natoms_mol);
@@ -2957,7 +2879,7 @@ static void add_posres_molblock(gmx_mtop_t *mtop)
     for (i = 0; i < il->nr; i += 2)
     {
         ip = &mtop->ffparams.iparams[il->iatoms[i]];
-        am = max(am, il->iatoms[i+1]);
+        am = std::max(am, il->iatoms[i+1]);
         if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
             ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
             ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ])
@@ -2972,8 +2894,7 @@ static void add_posres_molblock(gmx_mtop_t *mtop)
     {
         for (i = 0; i < ilfb->nr; i += 2)
         {
-            ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
-            am = max(am, ilfb->iatoms[i+1]);
+            am = std::max(am, ilfb->iatoms[i+1]);
         }
     }
     /* Make the posres coordinate block end at a molecule end */
@@ -3058,7 +2979,7 @@ static void set_disres_npair(gmx_mtop_t *mtop)
 static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop, gmx_bool bRead,
                     int file_version)
 {
-    int            mt, mb, i;
+    int            mt, mb;
     t_blocka       dumb;
 
     if (bRead)
@@ -3238,15 +3159,12 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
     int       idum = 0;
     real      rdum = 0;
 
-    gmx_fio_checktype(fio);
-    gmx_fio_setdebug(fio, bDebugMode());
-
     /* XDR binary topology file */
     precision = sizeof(real);
     if (bRead)
     {
         gmx_fio_do_string(fio, buf);
-        if (strncmp(buf, "VERSION", 7))
+        if (std::strncmp(buf, "VERSION", 7))
         {
             gmx_fatal(FARGS, "Can not read file %s,\n"
                       "             this file is from a GROMACS version which is older than 2.0\n"
@@ -3310,7 +3228,7 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
             sprintf(file_tag, "%s", TPX_TAG_RELEASE);
         }
 
-        if (strcmp(file_tag, tpx_tag) != 0)
+        if (std::strcmp(file_tag, tpx_tag) != 0)
         {
             fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n",
                     file_tag, tpx_tag);
@@ -3318,7 +3236,7 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
             /* We only support reading tpx files with the same tag as the code
              * or tpx files with the release tag and with lower version number.
              */
-            if (strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
+            if (std::strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
             {
                 gmx_fatal(FARGS, "tpx tag/version mismatch: reading tpx file (%s) version %d, tag '%s' with program for tpx version %d, tag '%s'",
                           gmx_fio_getname(fio), fver, file_tag,
@@ -3393,7 +3311,6 @@ static int do_tpx(t_fileio *fio, gmx_bool bRead,
     gmx_mtop_t      dum_top;
     gmx_bool        TopOnlyOK;
     int             file_version, file_generation;
-    int             i;
     rvec           *xptr, *vptr;
     int             ePBC;
     gmx_bool        bPeriodicMols;
@@ -3657,22 +3574,22 @@ static int do_tpx(t_fileio *fio, gmx_bool bRead,
     return ePBC;
 }
 
-/************************************************************
- *
- *  The following routines are the exported ones
- *
- ************************************************************/
-
-t_fileio *open_tpx(const char *fn, const char *mode)
+static t_fileio *open_tpx(const char *fn, const char *mode)
 {
     return gmx_fio_open(fn, mode);
 }
 
-void close_tpx(t_fileio *fio)
+static void close_tpx(t_fileio *fio)
 {
     gmx_fio_close(fio);
 }
 
+/************************************************************
+ *
+ *  The following routines are the exported ones
+ *
+ ************************************************************/
+
 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
                     int *file_version, int *file_generation)
 {
@@ -3733,7 +3650,6 @@ int read_tpx_top(const char *fn,
                  rvec *x, rvec *v, rvec *f, t_topology *top)
 {
     gmx_mtop_t  mtop;
-    t_topology *ltop;
     int         ePBC;
 
     ePBC = read_tpx(fn, ir, box, natoms, x, v, f, &mtop);
@@ -3747,104 +3663,3 @@ gmx_bool fn2bTPX(const char *file)
 {
     return (efTPR == fn2ftp(file));
 }
-
-static void done_gmx_groups_t(gmx_groups_t *g)
-{
-    int i;
-
-    for (i = 0; (i < egcNR); i++)
-    {
-        if (NULL != g->grps[i].nm_ind)
-        {
-            sfree(g->grps[i].nm_ind);
-            g->grps[i].nm_ind = NULL;
-        }
-        if (NULL != g->grpnr[i])
-        {
-            sfree(g->grpnr[i]);
-            g->grpnr[i] = NULL;
-        }
-    }
-    /* The contents of this array is in symtab, don't free it here */
-    sfree(g->grpname);
-}
-
-gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *ePBC,
-                       rvec **x, rvec **v, matrix box, gmx_bool bMass)
-{
-    t_tpxheader      header;
-    int              natoms, i, version, generation;
-    gmx_bool         bTop, bXNULL = FALSE;
-    gmx_mtop_t      *mtop;
-    t_topology      *topconv;
-    gmx_atomprop_t   aps;
-
-    bTop  = fn2bTPX(infile);
-    *ePBC = -1;
-    if (bTop)
-    {
-        read_tpxheader(infile, &header, TRUE, &version, &generation);
-        if (x)
-        {
-            snew(*x, header.natoms);
-        }
-        if (v)
-        {
-            snew(*v, header.natoms);
-        }
-        snew(mtop, 1);
-        *ePBC = read_tpx(infile, NULL, box, &natoms,
-                         (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
-        *top = gmx_mtop_t_to_t_topology(mtop);
-        /* In this case we need to throw away the group data too */
-        done_gmx_groups_t(&mtop->groups);
-        sfree(mtop);
-        strcpy(title, *top->name);
-        tpx_make_chain_identifiers(&top->atoms, &top->mols);
-    }
-    else
-    {
-        get_stx_coordnum(infile, &natoms);
-        init_t_atoms(&top->atoms, natoms, (fn2ftp(infile) == efPDB));
-        if (x == NULL)
-        {
-            snew(x, 1);
-            bXNULL = TRUE;
-        }
-        snew(*x, natoms);
-        if (v)
-        {
-            snew(*v, natoms);
-        }
-        read_stx_conf(infile, title, &top->atoms, *x, (v == NULL) ? NULL : *v, ePBC, box);
-        if (bXNULL)
-        {
-            sfree(*x);
-            sfree(x);
-        }
-        if (bMass)
-        {
-            aps = gmx_atomprop_init();
-            for (i = 0; (i < natoms); i++)
-            {
-                if (!gmx_atomprop_query(aps, epropMass,
-                                        *top->atoms.resinfo[top->atoms.atom[i].resind].name,
-                                        *top->atoms.atomname[i],
-                                        &(top->atoms.atom[i].m)))
-                {
-                    if (debug)
-                    {
-                        fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
-                                *top->atoms.resinfo[top->atoms.atom[i].resind].name,
-                                top->atoms.resinfo[top->atoms.atom[i].resind].nr,
-                                *top->atoms.atomname[i]);
-                    }
-                }
-            }
-            gmx_atomprop_destroy(aps);
-        }
-        top->idef.ntypes = -1;
-    }
-
-    return bTop;
-}
index 0b3ca43e312d08841fb44c7c0725ea8f92664363..cec32f10f22ad86fb7bcda2db2b1506caf8d6ce1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  *
  * The routines in the corresponding c-file tpxio.c
  * are based on the lower level routines in gmxfio.c
- * The integer file pointer returned from open_tpx
- * can also be used with the routines in gmxfio.h
  *
  **************************************************************/
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/types/inputrec.h"
 #include "gromacs/legacyheaders/types/state.h"
 
@@ -85,18 +82,11 @@ typedef struct
  * These routines handle reading and writing of preprocessed
  * topology files in any of the following formats:
  * TPR : topology in XDR format, portable accross platforms
- * TRR : trajectory in XDR format (non compressed)
  *
  * Files are written in the precision with which the source are compiled,
  * but double and single precision can be read by either.
  */
 
-t_fileio *open_tpx(const char *fn, const char *mode);
-/* Return an file pointer corresponding to the file you have just opened */
-
-void close_tpx(t_fileio *fio);
-/*  Close the file corresponding to fio */
-
 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
                     int *version, int *generation);
 /* Read the header from a tpx file and then close it again.
@@ -133,17 +123,6 @@ int read_tpx_top(const char *fn,
 gmx_bool fn2bTPX(const char *file);
 /* return if *file is one of the TPX file types */
 
-gmx_bool read_tps_conf(const char *infile, char *title, struct t_topology *top,
-                       int *ePBC, rvec **x, rvec **v, matrix box, gmx_bool bMass);
-/* Read title, top.atoms, x, v (if not NULL) and box from an STX file,
- * memory for atoms, x and v will be allocated.
- * Return TRUE if a complete topology was read.
- * If infile is a TPX file read the whole top,
- * else if bMass=TRUE, read the masses into top.atoms from the mass database.
- */
-
-void tpx_make_chain_identifiers(struct t_atoms *atoms, struct t_block *mols);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gromacs/fileio/trnio.h b/src/gromacs/fileio/trnio.h
deleted file mode 100644 (file)
index 0dcc1e0..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-
-#ifndef GMX_FILEIO_TRNIO_H
-#define GMX_FILEIO_TRNIO_H
-
-/**************************************************************
- *
- * These routines handle trr (trajectory) I/O, they read and
- * write trr files. The routines should be able to read single
- * and double precision files without the user noting it.
- * The files are backward compatible, therefore the header holds
- * some unused variables.
- *
- * The routines in the corresponding c-file trnio.c
- * are based on the lower level routines in gmxfio.c
- * The integer file pointer returned from open_trn
- * can also be used with the routines in gmxfio.h
- *
- **************************************************************/
-
-#include "gromacs/fileio/gmxfio.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct           /* This struct describes the order and the    */
-                         /* sizes of the structs in a trjfile, sizes are given in bytes.       */
-{
-    gmx_bool  bDouble;   /* Double precision?                            */
-    int       ir_size;   /* Backward compatibility                     */
-    int       e_size;    /* Backward compatibility                     */
-    int       box_size;  /* Non zero if a box is present                       */
-    int       vir_size;  /* Backward compatibility                     */
-    int       pres_size; /* Backward compatibility                     */
-    int       top_size;  /* Backward compatibility                     */
-    int       sym_size;  /* Backward compatibility                     */
-    int       x_size;    /* Non zero if coordinates are present                */
-    int       v_size;    /* Non zero if velocities are present         */
-    int       f_size;    /* Non zero if forces are present             */
-
-    int       natoms;    /* The total number of atoms                  */
-    int       step;      /* Current step number                                */
-    int       nre;       /* Backward compatibility                     */
-    real      t;         /* Current time                                       */
-    real      lambda;    /* Current value of lambda                    */
-    int       fep_state; /* Current value of alchemical state */
-} t_trnheader;
-
-t_fileio *open_trn(const char *fn, const char *mode);
-/* Open a trr / trr file */
-
-void close_trn(t_fileio *fio);
-/* Close it */
-
-gmx_bool fread_trnheader(t_fileio *fio, t_trnheader *trn, gmx_bool *bOK);
-/* Read the header of a trn file. Return FALSE if there is no frame.
- * bOK will be FALSE when the header is incomplete.
- */
-
-void read_trnheader(const char *fn, t_trnheader *header);
-/* Read the header of a trn file from fn, and close the file afterwards.
- */
-
-void pr_trnheader(FILE *fp, int indent, char *title, t_trnheader *sh);
-/* Print the header of a trn file to fp */
-
-gmx_bool is_trn(FILE *fp);
-/* Return true when the file is a trn file. File will be rewound
- * afterwards.
- */
-
-void fwrite_trn(t_fileio *fio, int step, real t, real lambda,
-                rvec *box, int natoms, rvec *x, rvec *v, rvec *f);
-/* Write a trn frame to file fp, box, x, v, f may be NULL */
-
-gmx_bool fread_htrn(t_fileio *fio, t_trnheader *sh,
-                    rvec *box, rvec *x, rvec *v, rvec *f);
-/* Extern read a frame except the header (that should be pre-read,
- * using routine read_trnheader, see above) from a trn file.
- * Return FALSE on error
- */
-
-gmx_bool fread_trn(t_fileio *fio, int *step, real *t, real *lambda,
-                   rvec *box, int *natoms, rvec *x, rvec *v, rvec *f);
-/* Read a trn frame, including the header from fp. box, x, v, f may
- * be NULL, in which case the data will be skipped over.
- * return FALSE on error
- */
-
-void write_trn(const char *fn, int step, real t, real lambda,
-               rvec *box, int natoms, rvec *x, rvec *v, rvec *f);
-/* Write a single trn frame to file fn, which is closed afterwards */
-
-void read_trn(const char *fn, int *step, real *t, real *lambda,
-              rvec *box, int *natoms, rvec *x, rvec *v, rvec *f);
-/* Read a single trn frame from file fn, which is closed afterwards
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
similarity index 64%
rename from src/gromacs/fileio/trnio.c
rename to src/gromacs/fileio/trrio.cpp
index a1d6c8cbd7730ee617dbb51351c39ef689e3b425..f3e16b1f4d966d55ea90bf38d8b3a13a31cbd8b5 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  */
 #include "gmxpre.h"
 
-#include "trnio.h"
+#include "trrio.h"
 
-#include <string.h>
+#include <cstring>
 
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/utility/fatalerror.h"
@@ -50,7 +51,7 @@
 #define BUFSIZE     128
 #define GROMACS_MAGIC   1993
 
-static int nFloatSize(t_trnheader *sh)
+static int nFloatSize(gmx_trr_header_t *sh)
 {
     int nflsize = 0;
 
@@ -72,7 +73,7 @@ static int nFloatSize(t_trnheader *sh)
     }
     else
     {
-        gmx_file("Can not determine precision of trn file");
+        gmx_file("Can not determine precision of trr file");
     }
 
     if (((nflsize != sizeof(float)) && (nflsize != sizeof(double))))
@@ -83,7 +84,8 @@ static int nFloatSize(t_trnheader *sh)
     return nflsize;
 }
 
-static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx_bool *bOK)
+static gmx_bool
+do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *bOK)
 {
     int             magic  = GROMACS_MAGIC;
     static gmx_bool bFirst = TRUE;
@@ -91,8 +93,6 @@ static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx
 
     *bOK = TRUE;
 
-    gmx_fio_checktype(fio);
-
     if (!gmx_fio_do_int(fio, magic) || magic != GROMACS_MAGIC)
     {
         return FALSE;
@@ -103,7 +103,7 @@ static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx
         *bOK = *bOK && gmx_fio_do_string(fio, buf);
         if (bFirst)
         {
-            fprintf(stderr, "trn version: %s ", buf);
+            fprintf(stderr, "trr version: %s ", buf);
         }
     }
     else
@@ -144,33 +144,9 @@ static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx
     return *bOK;
 }
 
-void pr_trnheader(FILE *fp, int indent, char *title, t_trnheader *sh)
-{
-    if (sh)
-    {
-        indent = pr_title(fp, indent, title);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "box_size    = %d\n", sh->box_size);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "x_size      = %d\n", sh->x_size);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "v_size      = %d\n", sh->v_size);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "f_size      = %d\n", sh->f_size);
-
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "natoms      = %d\n", sh->natoms);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "step        = %d\n", sh->step);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "t           = %e\n", sh->t);
-        (void) pr_indent(fp, indent);
-        (void) fprintf(fp, "lambda      = %e\n", sh->lambda);
-    }
-}
-
-static gmx_bool do_htrn(t_fileio *fio, t_trnheader *sh,
-                        rvec *box, rvec *x, rvec *v, rvec *f)
+static gmx_bool
+do_trr_frame_data(t_fileio *fio, gmx_trr_header_t *sh,
+                  rvec *box, rvec *x, rvec *v, rvec *f)
 {
     matrix   pv;
     gmx_bool bOK;
@@ -204,11 +180,12 @@ static gmx_bool do_htrn(t_fileio *fio, t_trnheader *sh,
     return bOK;
 }
 
-static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real *lambda,
-                       rvec *box, int *natoms, rvec *x, rvec *v, rvec *f)
+static gmx_bool
+do_trr_frame(t_fileio *fio, bool bRead, int *step, real *t, real *lambda,
+             rvec *box, int *natoms, rvec *x, rvec *v, rvec *f)
 {
-    t_trnheader *sh;
-    gmx_bool     bOK;
+    gmx_trr_header_t *sh;
+    gmx_bool          bOK;
 
     snew(sh, 1);
     if (!bRead)
@@ -223,7 +200,7 @@ static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real *
         sh->t        = *t;
         sh->lambda   = *lambda;
     }
-    if (!do_trnheader(fio, bRead, sh, &bOK))
+    if (!do_trr_frame_header(fio, bRead, sh, &bOK))
     {
         return FALSE;
     }
@@ -235,22 +212,22 @@ static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real *
         *lambda = sh->lambda;
         if (sh->ir_size)
         {
-            gmx_file("inputrec in trn file");
+            gmx_file("inputrec in trr file");
         }
         if (sh->e_size)
         {
-            gmx_file("energies in trn file");
+            gmx_file("energies in trr file");
         }
         if (sh->top_size)
         {
-            gmx_file("topology in trn file");
+            gmx_file("topology in trr file");
         }
         if (sh->sym_size)
         {
-            gmx_file("symbol table in trn file");
+            gmx_file("symbol table in trr file");
         }
     }
-    bOK = do_htrn(fio, sh, box, x, v, f);
+    bOK = do_trr_frame_data(fio, sh, box, x, v, f);
 
     sfree(sh);
 
@@ -263,72 +240,66 @@ static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real *
  *
  ************************************************************/
 
-void read_trnheader(const char *fn, t_trnheader *trn)
+void gmx_trr_read_single_header(const char *fn, gmx_trr_header_t *header)
 {
-    t_fileio *fio;
+    t_fileio *fio = gmx_trr_open(fn, "r");
     gmx_bool  bOK;
-
-    fio = open_trn(fn, "r");
-    if (!do_trnheader(fio, TRUE, trn, &bOK))
+    if (!do_trr_frame_header(fio, true, header, &bOK))
     {
         gmx_fatal(FARGS, "Empty file %s", fn);
     }
-    close_trn(fio);
+    gmx_trr_close(fio);
 }
 
-gmx_bool fread_trnheader(t_fileio *fio, t_trnheader *trn, gmx_bool *bOK)
+gmx_bool gmx_trr_read_frame_header(t_fileio *fio, gmx_trr_header_t *header, gmx_bool *bOK)
 {
-    return do_trnheader(fio, TRUE, trn, bOK);
+    return do_trr_frame_header(fio, true, header, bOK);
 }
 
-void write_trn(const char *fn, int step, real t, real lambda,
-               rvec *box, int natoms, rvec *x, rvec *v, rvec *f)
+void gmx_trr_write_single_frame(const char *fn, int step, real t, real lambda,
+                                rvec *box, int natoms, rvec *x, rvec *v, rvec *f)
 {
-    t_fileio *fio;
-
-    fio = open_trn(fn, "w");
-    do_trn(fio, FALSE, &step, &t, &lambda, box, &natoms, x, v, f);
-    close_trn(fio);
+    t_fileio *fio = gmx_trr_open(fn, "w");
+    do_trr_frame(fio, false, &step, &t, &lambda, box, &natoms, x, v, f);
+    gmx_trr_close(fio);
 }
 
-void read_trn(const char *fn, int *step, real *t, real *lambda,
-              rvec *box, int *natoms, rvec *x, rvec *v, rvec *f)
+void gmx_trr_read_single_frame(const char *fn, int *step, real *t, real *lambda,
+                               rvec *box, int *natoms, rvec *x, rvec *v, rvec *f)
 {
-    t_fileio *fio;
-
-    fio = open_trn(fn, "r");
-    (void) do_trn(fio, TRUE, step, t, lambda, box, natoms, x, v, f);
-    close_trn(fio);
+    t_fileio *fio = gmx_trr_open(fn, "r");
+    do_trr_frame(fio, true, step, t, lambda, box, natoms, x, v, f);
+    gmx_trr_close(fio);
 }
 
-void fwrite_trn(t_fileio *fio, int step, real t, real lambda,
-                rvec *box, int natoms, rvec *x, rvec *v, rvec *f)
+void gmx_trr_write_frame(t_fileio *fio, int step, real t, real lambda,
+                         rvec *box, int natoms, rvec *x, rvec *v, rvec *f)
 {
-    if (do_trn(fio, FALSE, &step, &t, &lambda, box, &natoms, x, v, f) == FALSE)
+    if (!do_trr_frame(fio, false, &step, &t, &lambda, box, &natoms, x, v, f))
     {
         gmx_file("Cannot write trajectory frame; maybe you are out of disk space?");
     }
 }
 
 
-gmx_bool fread_trn(t_fileio *fio, int *step, real *t, real *lambda,
-                   rvec *box, int *natoms, rvec *x, rvec *v, rvec *f)
+gmx_bool gmx_trr_read_frame(t_fileio *fio, int *step, real *t, real *lambda,
+                            rvec *box, int *natoms, rvec *x, rvec *v, rvec *f)
 {
-    return do_trn(fio, TRUE, step, t, lambda, box, natoms, x, v, f);
+    return do_trr_frame(fio, true, step, t, lambda, box, natoms, x, v, f);
 }
 
-gmx_bool fread_htrn(t_fileio *fio, t_trnheader *trn, rvec *box, rvec *x, rvec *v,
-                    rvec *f)
+gmx_bool gmx_trr_read_frame_data(t_fileio *fio, gmx_trr_header_t *header,
+                                 rvec *box, rvec *x, rvec *v, rvec *f)
 {
-    return do_htrn(fio, trn, box, x, v, f);
+    return do_trr_frame_data(fio, header, box, x, v, f);
 }
 
-t_fileio *open_trn(const char *fn, const char *mode)
+t_fileio *gmx_trr_open(const char *fn, const char *mode)
 {
     return gmx_fio_open(fn, mode);
 }
 
-void close_trn(t_fileio *fio)
+void gmx_trr_close(t_fileio *fio)
 {
     gmx_fio_close(fio);
 }
diff --git a/src/gromacs/fileio/trrio.h b/src/gromacs/fileio/trrio.h
new file mode 100644 (file)
index 0000000..3f28057
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_FILEIO_TRRIO_H
+#define GMX_FILEIO_TRRIO_H
+
+#include "gromacs/math/vectypes.h"
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/real.h"
+
+/**************************************************************
+ *
+ * These routines handle trr (trajectory) I/O, they read and
+ * write trr files. The routines should be able to read single
+ * and double precision files without the user noting it.
+ * The files are backward compatible, therefore the header holds
+ * some unused variables.
+ *
+ * The routines in the corresponding c-file trrio.cpp
+ * are based on the lower level routines in gmxfio.cpp
+ * The file handle returned from gmx_trr_open()
+ * can also be used with the routines in gmxfio.h
+ *
+ **************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct t_fileio;
+
+/* This struct describes the order and the  */
+/* sizes of the structs in a trr file, sizes are given in bytes. */
+typedef struct gmx_trr_header_t
+{
+    gmx_bool  bDouble;   /* Double precision?                   */
+    int       ir_size;   /* Backward compatibility              */
+    int       e_size;    /* Backward compatibility              */
+    int       box_size;  /* Non zero if a box is present        */
+    int       vir_size;  /* Backward compatibility              */
+    int       pres_size; /* Backward compatibility              */
+    int       top_size;  /* Backward compatibility              */
+    int       sym_size;  /* Backward compatibility              */
+    int       x_size;    /* Non zero if coordinates are present */
+    int       v_size;    /* Non zero if velocities are present  */
+    int       f_size;    /* Non zero if forces are present      */
+
+    int       natoms;    /* The total number of atoms           */
+    int       step;      /* Current step number                 */
+    int       nre;       /* Backward compatibility              */
+    real      t;         /* Current time                        */
+    real      lambda;    /* Current value of lambda             */
+    int       fep_state; /* Current value of alchemical state   */
+} gmx_trr_header_t;
+
+struct t_fileio *gmx_trr_open(const char *fn, const char *mode);
+/* Open a trr file */
+
+void gmx_trr_close(struct t_fileio *fio);
+/* Close it */
+
+gmx_bool gmx_trr_read_frame_header(struct t_fileio *fio, gmx_trr_header_t *header, gmx_bool *bOK);
+/* Read the header of a trr file. Return FALSE if there is no frame.
+ * bOK will be FALSE when the header is incomplete.
+ */
+
+gmx_bool gmx_trr_read_frame_data(struct t_fileio *fio, gmx_trr_header_t *sh,
+                                 rvec *box, rvec *x, rvec *v, rvec *f);
+/* Extern read a frame except the header (that should be pre-read,
+ * using routine gmx_trr_read_frame_header(), see above) from a trr file.
+ * Return FALSE on error
+ */
+
+gmx_bool gmx_trr_read_frame(struct t_fileio *fio, int *step, real *t, real *lambda,
+                            rvec *box, int *natoms, rvec *x, rvec *v, rvec *f);
+/* Read a trr frame, including the header from fp. box, x, v, f may
+ * be NULL, in which case the data will be skipped over.
+ * return FALSE on error
+ */
+
+void gmx_trr_write_frame(struct t_fileio *fio, int step, real t, real lambda,
+                         rvec *box, int natoms, rvec *x, rvec *v, rvec *f);
+/* Write a trr frame to file fp, box, x, v, f may be NULL */
+
+void gmx_trr_read_single_header(const char *fn, gmx_trr_header_t *header);
+/* Read the header of a trr file from fn, and close the file afterwards.
+ */
+
+void gmx_trr_read_single_frame(const char *fn, int *step, real *t, real *lambda,
+                               rvec *box, int *natoms, rvec *x, rvec *v, rvec *f);
+/* Read a single trr frame from file fn, which is closed afterwards
+ */
+
+void gmx_trr_write_single_frame(const char *fn, int step, real t, real lambda,
+                                rvec *box, int natoms, rvec *x, rvec *v, rvec *f);
+/* Write a single trr frame to file fn, which is closed afterwards */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
similarity index 97%
rename from src/gromacs/fileio/trxio.c
rename to src/gromacs/fileio/trxio.cpp
index 084b9325c39bca352f479da88a805a0752e0f8f6..ab386090ebfc962c432e8afc8c1cee6af7bfe95c 100644 (file)
 
 #include "config.h"
 
-#include <assert.h>
-#include <math.h>
+#include <cassert>
+#include <cmath>
 
 #include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/g96io.h"
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
+#include "gromacs/fileio/groio.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/timecontrol.h"
 #include "gromacs/fileio/tngio.h"
 #include "gromacs/fileio/tngio_for_tools.h"
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/fileio/trx.h"
 #include "gromacs/fileio/xdrf.h"
 #include "gromacs/fileio/xtcio.h"
@@ -60,6 +63,7 @@
 #include "gromacs/topology/atoms.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #ifdef GMX_USE_PLUGINS
@@ -393,8 +397,8 @@ int write_trxframe_indexed(t_trxstatus *status, t_trxframe *fr, int nind,
             write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec);
             break;
         case efTRR:
-            fwrite_trn(status->fio, nframes_read(status),
-                       fr->time, fr->step, fr->box, nind, xout, vout, fout);
+            gmx_trr_write_frame(status->fio, nframes_read(status),
+                                fr->time, fr->step, fr->box, nind, xout, vout, fout);
             break;
         case efGRO:
         case efPDB:
@@ -545,8 +549,8 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
             write_xtc(status->fio, fr->natoms, fr->step, fr->time, fr->box, fr->x, prec);
             break;
         case efTRR:
-            fwrite_trn(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms,
-                       fr->bX ? fr->x : NULL, fr->bV ? fr->v : NULL, fr->bF ? fr->f : NULL);
+            gmx_trr_write_frame(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms,
+                                fr->bX ? fr->x : NULL, fr->bV ? fr->v : NULL, fr->bF ? fr->f : NULL);
             break;
         case efGRO:
         case efPDB:
@@ -632,12 +636,12 @@ t_trxstatus *open_trx(const char *outfile, const char *filemode)
 
 static gmx_bool gmx_next_frame(t_trxstatus *status, t_trxframe *fr)
 {
-    t_trnheader sh;
-    gmx_bool    bOK, bRet;
+    gmx_trr_header_t sh;
+    gmx_bool         bOK, bRet;
 
     bRet = FALSE;
 
-    if (fread_trnheader(status->fio, &sh, &bOK))
+    if (gmx_trr_read_frame_header(status->fio, &sh, &bOK))
     {
         fr->bDouble   = sh.bDouble;
         fr->natoms    = sh.natoms;
@@ -673,7 +677,7 @@ static gmx_bool gmx_next_frame(t_trxstatus *status, t_trxframe *fr)
             }
             fr->bF = sh.f_size > 0;
         }
-        if (fread_htrn(status->fio, &sh, fr->box, fr->x, fr->v, fr->f))
+        if (gmx_trr_read_frame_data(status->fio, &sh, fr->box, fr->x, fr->v, fr->f))
         {
             bRet = TRUE;
         }
@@ -783,7 +787,6 @@ gmx_bool read_next_frame(const output_env_t oenv, t_trxstatus *status, t_trxfram
     real     pt;
     int      ct;
     gmx_bool bOK, bRet, bMissingData = FALSE, bSkip = FALSE;
-    int      dummy = 0;
     int      ftp;
 
     bRet = FALSE;
@@ -913,9 +916,7 @@ int read_first_frame(const output_env_t oenv, t_trxstatus **status,
 {
     t_fileio      *fio;
     gmx_bool       bFirst, bOK;
-    int            dummy = 0;
     int            ftp   = fn2ftp(fn);
-    gmx_int64_t   *tng_ids;
 
     clear_trxframe(fr, TRUE);
     fr->flags = flags;
@@ -963,13 +964,13 @@ int read_first_frame(const output_env_t oenv, t_trxstatus **status,
             {
                 snew(fr->v, fr->natoms);
             }
-            fio = (*status)->fio = gmx_fio_open(fn, "r");
+            (*status)->fio = gmx_fio_open(fn, "r");
             break;
         case efXTC:
             if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x,
                                &fr->prec, &bOK) == 0)
             {
-                assert(!bOK);
+                GMX_RELEASE_ASSERT(!bOK, "Inconsistent results - OK status from read_first_xtc, but 0 atom coords read");
                 fr->not_ok = DATA_NOT_OK;
             }
             if (fr->not_ok)
index 0d32e364051a95bccbe9a4cecb6bae2050dc91e4..29a93693c9b70985c126b3c1c37b818632a1112b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -39,7 +39,6 @@
 #define GMX_FILEIO_TRXIO_H
 
 #include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/legacyheaders/oenv.h"
 #include "gromacs/legacyheaders/readinp.h"
@@ -53,6 +52,7 @@ extern "C" {
 
 struct gmx_mtop_t;
 struct t_atoms;
+struct t_fileio;
 struct t_topology;
 struct t_trxframe;
 
@@ -144,7 +144,7 @@ void close_trx(t_trxstatus *status);
 t_trxstatus *open_trx(const char *outfile, const char *filemode);
 /* Open a TRX file and return an allocated status pointer */
 
-t_fileio *trx_get_fileio(t_trxstatus *status);
+struct t_fileio *trx_get_fileio(t_trxstatus *status);
 /* get a fileio from a trxstatus */
 
 float trx_get_time_of_final_frame(t_trxstatus *status);
similarity index 98%
rename from src/gromacs/fileio/vmdio.c
rename to src/gromacs/fileio/vmdio.cpp
index 8533c243f6de985008918c5579ed5cb4be540e76..84e687871630719f72ea80d92faff6db85edf33b 100644 (file)
@@ -262,10 +262,9 @@ gmx_bool read_next_vmd_frame(t_trxframe *fr)
 
 static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin)
 {
-    char            pathname[GMX_PATH_MAX], filename[GMX_PATH_MAX];
+    char            pathname[GMX_PATH_MAX];
     const char     *pathenv;
     const char     *err;
-    int             i;
     int             ret = 0;
     char            pathenv_buffer[GMX_PATH_MAX];
 #ifndef GMX_NATIVE_WINDOWS
@@ -328,7 +327,7 @@ static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin)
                "The architecture (e.g. 32bit versus 64bit) of GROMACS and VMD has to match.\n");
         return 0;
     }
-    for (i = 0; i < globbuf.gl_pathc && vmdplugin->api == NULL; i++)
+    for (size_t i = 0; i < globbuf.gl_pathc && vmdplugin->api == NULL; i++)
     {
         /* FIXME: Undefined which plugin is chosen if more than one plugin
            can read a certain file ending. Requires some additional command
@@ -348,6 +347,7 @@ static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin)
     }
     do
     {
+        char filename[GMX_PATH_MAX];
         sprintf(filename, "%s\\%s", pathenv, ffd.cFileName);
         ret |= load_sharedlibrary_plugins(filename, vmdplugin);
     }
similarity index 99%
rename from src/gromacs/fileio/writeps.c
rename to src/gromacs/fileio/writeps.cpp
index a0ae4e15cb9719aa319be7a9eafbef634b198fdc..7f9f6229f51ceab82deb58cc3600f265553ba3cf 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "writeps.h"
 
-#include <stdio.h>
+#include <cstdio>
 
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/utility/fatalerror.h"
similarity index 89%
rename from src/gromacs/fileio/xdrd.c
rename to src/gromacs/fileio/xdrd.cpp
index 5af573e7b3b9ef1a698dcca7d95a397283c72397..5556316ae1160dadae07a3521f723f7e2d46b0e8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -88,7 +88,7 @@ int xdr3drcoord(XDR *xdrs, real *fp, int *size, real *precision)
     sfree(ffp);
     return ret;
 #else
-    return xdr3dfcoord(xdrs, (float *)fp, size, (float *)precision);
+    return xdr3dfcoord(xdrs, reinterpret_cast<float *>(fp), size, reinterpret_cast<float *>(precision));
 #endif
 }
 
@@ -104,12 +104,12 @@ int xdr_int64(XDR *xdrs, gmx_int64_t *i)
 
     imaj64 = ((*i)>>32) & two_p32_m1;
     imin64 = (*i) & two_p32_m1;
-    imaj   = (int)imaj64;
-    imin   = (int)imin64;
+    imaj   = static_cast<int>(imaj64);
+    imin   = static_cast<int>(imin64);
     ret    = xdr_int(xdrs, &imaj);
     ret   |= xdr_int(xdrs, &imin);
 
-    *i = (((gmx_int64_t)imaj << 32) | ((gmx_int64_t)imin & two_p32_m1));
+    *i = ((static_cast<gmx_int64_t>(imaj) << 32) | (static_cast<gmx_int64_t>(imin) & two_p32_m1));
 
     return ret;
 }
index dd2959e9863924c8b3f5e9ae6ebdffe0d0fcfba2..72a67afb669ea46ca7b3c87804b3641b63553c50 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -48,8 +48,8 @@
 
 #include "config.h"
 
-#ifdef GMX_INTERNAL_XDR
-#include "gromacs/fileio/gmx_system_xdr.h"
+#if GMX_INTERNAL_XDR
+#include "gromacs/fileio/gmx_internal_xdr.h"
 #else
 #include <rpc/rpc.h>
 #include <rpc/xdr.h>
@@ -59,8 +59,6 @@
 extern "C" {
 #endif
 
-struct t_fileio;
-
 /* Read or write reduced precision *float* coordinates */
 int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision);
 
@@ -92,16 +90,6 @@ float xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bO
 
 int xdr_xtc_get_last_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK);
 
-
-/* Defined in gmxfio.c.
- * TODO: It would be nice to decouple this header from t_fileio completely,
- * and not need the XDR struct in gmxfio.h, but that would require some
- * extra code that is not warranted for this single function.
- * Can be reconsidered if the file I/O gets refactored in the future.
- */
-XDR *gmx_fio_getxdr(struct t_fileio *fio);
-/* Return the file pointer itself */
-
 #ifdef __cplusplus
 }
 #endif
similarity index 94%
rename from src/gromacs/fileio/xtcio.c
rename to src/gromacs/fileio/xtcio.cpp
index 248146417a3c9b66342d7cf088c48563922c8f4c..cf4bfd45739a2b12856355f16216c46dbdeeab95 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "xtcio.h"
 
-#include <string.h>
+#include <cstring>
 
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
 #include "gromacs/fileio/xdrf.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/fatalerror.h"
@@ -92,7 +93,7 @@ static void check_xtc_magic(int magic)
     }
 }
 
-int xtc_check(const char *str, gmx_bool bResult, const char *file, int line)
+static int xtc_check(const char *str, gmx_bool bResult, const char *file, int line)
 {
     if (!bResult)
     {
@@ -106,14 +107,7 @@ int xtc_check(const char *str, gmx_bool bResult, const char *file, int line)
     return 1;
 }
 
-void xtc_check_fat_err(const char *str, gmx_bool bResult, const char *file, int line)
-{
-    if (!bResult)
-    {
-        gmx_fatal(FARGS, "XTC read/write of %s failed, "
-                  "source file %s, line %d\n", str, file, line);
-    }
-}
+#define XTC_CHECK(s, b) xtc_check(s, b, __FILE__, __LINE__)
 
 static int xtc_header(XDR *xd, int *magic, int *natoms, int *step, real *time,
                       gmx_bool bRead, gmx_bool *bOK)
index 2c50fb89f0bc5300b79069b29f7e84593636ea39..1d173f8ea5708d1f1afbebb2c908b526012c2eab 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,6 @@
 #ifndef GMX_FILEIO_XTCIO_H
 #define GMX_FILEIO_XTCIO_H
 
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 extern "C" {
 #endif
 
+struct t_fileio;
+
 /* All functions return 1 if successful, 0 otherwise
  * bOK tells if a frame is not corrupted
  */
 
-t_fileio *open_xtc(const char *filename, const char *mode);
+struct t_fileio *open_xtc(const char *filename, const char *mode);
 /* Open a file for xdr I/O */
 
-void close_xtc(t_fileio *fio);
+void close_xtc(struct t_fileio *fio);
 /* Close the file for xdr I/O */
 
-int read_first_xtc(t_fileio *fio,
+int read_first_xtc(struct t_fileio *fio,
                    int *natoms, int *step, real *time,
                    matrix box, rvec **x, real *prec, gmx_bool *bOK);
 /* Open xtc file, read xtc file first time, allocate memory for x */
 
-int read_next_xtc(t_fileio *fio,
+int read_next_xtc(struct t_fileio *fio,
                   int natoms, int *step, real *time,
                   matrix box, rvec *x, real *prec, gmx_bool *bOK);
 /* Read subsequent frames */
 
-int write_xtc(t_fileio *fio,
+int write_xtc(struct t_fileio *fio,
               int natoms, int step, real time,
               matrix box, rvec *x, real prec);
 /* Write a frame to xtc file */
 
-int xtc_check(const char *str, gmx_bool bResult, const char *file, int line);
-#define XTC_CHECK(s, b) xtc_check(s, b, __FILE__, __LINE__)
-
-void xtc_check_fat_err(const char *str, gmx_bool bResult, const char *file, int line);
-#define XTC_CHECK_FAT_ERR(s, b) xtc_check_fat_err(s, b, __FILE__, __LINE__)
-
 #ifdef __cplusplus
 }
 #endif
index f38f950b8c4bbf977d08ce59f0a6f825c2a1414c..1b5a47909aad4411d3e9d90d0a1b19bcb2fc6b80 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,8 +38,8 @@
 
 #include "xvgr.h"
 
-#include <ctype.h>
-#include <string.h>
+#include <cctype>
+#include <cstring>
 
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/copyrite.h"
@@ -166,23 +166,23 @@ static char *xvgrstr(const char *gmx, const output_env_t oenv,
                         break;
                 }
                 g++;
-                b = strlen(buf);
+                b = std::strlen(buf);
             }
             else
             {
                 /* Check for special symbol */
                 i = 0;
                 while (sym[i] != NULL &&
-                       gmx_strncasecmp(sym[i], gmx+g, strlen(sym[i])) != 0)
+                       gmx_strncasecmp(sym[i], gmx+g, std::strlen(sym[i])) != 0)
                 {
                     i++;
                 }
                 if (sym[i] != NULL)
                 {
                     c = symc[i];
-                    if (isupper(gmx[g]))
+                    if (std::isupper(gmx[g]))
                     {
-                        c = toupper(c);
+                        c = std::toupper(c);
                     }
                     switch (xvgf)
                     {
@@ -193,17 +193,17 @@ static char *xvgrstr(const char *gmx, const output_env_t oenv,
                             sprintf(buf+b, "%s%c%s", "\\8", c, "\\4");
                             break;
                         default:
-                            strncat(buf+b, gmx+g, strlen(sym[i]));
-                            b += strlen(sym[i]);
-                            if (gmx[g+strlen(sym[i])] != ' ')
+                            std::strncat(buf+b, gmx+g, std::strlen(sym[i]));
+                            b += std::strlen(sym[i]);
+                            if (gmx[g+std::strlen(sym[i])] != ' ')
                             {
                                 buf[b++] = ' ';
                             }
                             buf[b] = '\0';
                             break;
                     }
-                    g += strlen(sym[i]);
-                    b  = strlen(buf);
+                    g += std::strlen(sym[i]);
+                    b  = std::strlen(buf);
                 }
                 else
                 {
@@ -467,7 +467,7 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen)
         curp         += len_remaining-1; /* overwrite the nul char in next iteration */
         len_remaining = 1;
     }
-    while ((strchr(*ptr, '\n') == NULL) && (!feof(fp)));
+    while ((std::strchr(*ptr, '\n') == NULL) && (!feof(fp)));
 
     if (*len + STRLEN >= maxlen)
     {
@@ -481,7 +481,7 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen)
     }
     {
         /* now remove newline */
-        int slen = strlen(*ptr);
+        int slen = std::strlen(*ptr);
         if ((*ptr)[slen-1] == '\n')
         {
             (*ptr)[slen-1] = '\0';
@@ -501,7 +501,7 @@ static int wordcount(char *ptr)
     {
         for (i = 0; (ptr[i] != '\0'); i++)
         {
-            is[cur] = isspace(ptr[i]);
+            is[cur] = std::isspace(ptr[i]);
             if ((0 == i) && !is[cur])
             {
                 n++;
@@ -521,11 +521,11 @@ static char *read_xvgr_string(const char *line)
     const char *ptr0, *ptr1;
     char       *str;
 
-    ptr0 = strchr(line, '"');
+    ptr0 = std::strchr(line, '"');
     if (ptr0 != NULL)
     {
         ptr0++;
-        ptr1 = strchr(ptr0, '"');
+        ptr1 = std::strchr(ptr0, '"');
         if (ptr1 != NULL)
         {
             str            = gmx_strdup(ptr0);
@@ -584,7 +584,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
                 ptr++;
                 trim(ptr);
                 set = -1;
-                if (strncmp(ptr, "subtitle", 8) == 0)
+                if (std::strncmp(ptr, "subtitle", 8) == 0)
                 {
                     ptr += 8;
                     if (subtitle != NULL)
@@ -592,7 +592,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
                         *subtitle = read_xvgr_string(ptr);
                     }
                 }
-                else if (strncmp(ptr, "legend string", 13) == 0)
+                else if (std::strncmp(ptr, "legend string", 13) == 0)
                 {
                     ptr += 13;
                     sscanf(ptr, "%d%n", &set, &nchar);
@@ -604,7 +604,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
                     sscanf(ptr, "%d%n", &set, &nchar);
                     ptr += nchar;
                     trim(ptr);
-                    if (strncmp(ptr, "legend", 6) == 0)
+                    if (std::strncmp(ptr, "legend", 6) == 0)
                     {
                         ptr += 6;
                     }
@@ -654,8 +654,8 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
             /* fprintf(stderr,"ptr='%s'\n",ptr);*/
             for (k = 0; (k < nny); k++)
             {
-                strcpy(fmt, base);
-                strcat(fmt, "%lf");
+                std::strcpy(fmt, base);
+                std::strcat(fmt, "%lf");
                 rval = sscanf(ptr, fmt, &lf);
                 /* fprintf(stderr,"rval = %d\n",rval);*/
                 if ((rval == EOF) || (rval == 0))
@@ -665,7 +665,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny,
                 yy[k][nx] = lf;
                 srenew(fmt, 3*(nny+1)+1);
                 srenew(base, 3*nny+1);
-                strcat(base, "%*s");
+                std::strcat(base, "%*s");
             }
             if (k != nny)
             {
index 8d65ffbc59ab3123577f8604cf5b7af5a2a8f26e..97daf30f4b90b70743e2d7d94ba6cf727e88368a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -39,7 +39,7 @@
 #include "eigio.h"
 
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
@@ -50,21 +50,21 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit,
                        int *nvec, int **eignr,
                        rvec ***eigvec, real **eigval)
 {
-    t_trnheader head;
-    int         i, snew_size;
-    t_fileio   *status;
-    rvec       *x;
-    matrix      box;
-    gmx_bool    bOK;
+    gmx_trr_header_t   head;
+    int                i, snew_size;
+    struct t_fileio   *status;
+    rvec              *x;
+    matrix             box;
+    gmx_bool           bOK;
 
     *bDMR = FALSE;
 
     /* read (reference (t=-1) and) average (t=0) structure */
-    status = open_trn(file, "r");
-    fread_trnheader(status, &head, &bOK);
+    status = gmx_trr_open(file, "r");
+    gmx_trr_read_frame_header(status, &head, &bOK);
     *natoms = head.natoms;
     snew(*xav, *natoms);
-    fread_htrn(status, &head, box, *xav, NULL, NULL);
+    gmx_trr_read_frame_data(status, &head, box, *xav, NULL, NULL);
 
     if ((head.t >= -1.1) && (head.t <= -0.9))
     {
@@ -85,8 +85,8 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit,
             sfree(*xref);
             *xref = NULL;
         }
-        fread_trnheader(status, &head, &bOK);
-        fread_htrn(status, &head, box, *xav, NULL, NULL);
+        gmx_trr_read_frame_header(status, &head, &bOK);
+        gmx_trr_read_frame_data(status, &head, box, *xav, NULL, NULL);
     }
     else
     {
@@ -115,9 +115,9 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit,
     snew(*eigvec, snew_size);
 
     *nvec = 0;
-    while (fread_trnheader(status, &head, &bOK))
+    while (gmx_trr_read_frame_header(status, &head, &bOK))
     {
-        fread_htrn(status, &head, box, x, NULL, NULL);
+        gmx_trr_read_frame_data(status, &head, box, x, NULL, NULL);
         if (*nvec >= snew_size)
         {
             snew_size += 10;
@@ -136,19 +136,20 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit,
         (*nvec)++;
     }
     sfree(x);
+    gmx_trr_close(status);
     fprintf(stderr, "Read %d eigenvectors (for %d atoms)\n\n", *nvec, *natoms);
 }
 
 
-void write_eigenvectors(const char *trnname, int natoms, real mat[],
+void write_eigenvectors(const char *trrname, int natoms, real mat[],
                         gmx_bool bReverse, int begin, int end,
                         int WriteXref, rvec *xref, gmx_bool bDMR,
                         rvec xav[], gmx_bool bDMA, real eigval[])
 {
-    t_fileio *trnout;
-    int       ndim, i, j, d, vec;
-    matrix    zerobox;
-    rvec     *x;
+    struct t_fileio *trrout;
+    int              ndim, i, j, d, vec;
+    matrix           zerobox;
+    rvec            *x;
 
     ndim = natoms*DIM;
     clear_mat(zerobox);
@@ -157,22 +158,22 @@ void write_eigenvectors(const char *trnname, int natoms, real mat[],
     fprintf (stderr,
              "\nWriting %saverage structure & eigenvectors %d--%d to %s\n",
              (WriteXref == eWXR_YES) ? "reference, " : "",
-             begin, end, trnname);
+             begin, end, trrname);
 
-    trnout = open_tpx(trnname, "w");
+    trrout = gmx_trr_open(trrname, "w");
     if (WriteXref == eWXR_YES)
     {
         /* misuse lambda: 0/1 mass weighted fit no/yes */
-        fwrite_trn(trnout, -1, -1, bDMR ? 1.0 : 0.0, zerobox, natoms, xref, NULL, NULL);
+        gmx_trr_write_frame(trrout, -1, -1, bDMR ? 1.0 : 0.0, zerobox, natoms, xref, NULL, NULL);
     }
     else if (WriteXref == eWXR_NOFIT)
     {
         /* misuse lambda: -1 no fit */
-        fwrite_trn(trnout, -1, -1, -1.0, zerobox, natoms, x, NULL, NULL);
+        gmx_trr_write_frame(trrout, -1, -1, -1.0, zerobox, natoms, x, NULL, NULL);
     }
 
     /* misuse lambda: 0/1 mass weighted analysis no/yes */
-    fwrite_trn(trnout, 0, 0, bDMA ? 1.0 : 0.0, zerobox, natoms, xav, NULL, NULL);
+    gmx_trr_write_frame(trrout, 0, 0, bDMA ? 1.0 : 0.0, zerobox, natoms, xav, NULL, NULL);
 
     for (i = 0; i <= (end-begin); i++)
     {
@@ -195,9 +196,9 @@ void write_eigenvectors(const char *trnname, int natoms, real mat[],
         }
 
         /* Store the eigenvalue in the time field */
-        fwrite_trn(trnout, begin+i, eigval[vec], 0, zerobox, natoms, x, NULL, NULL);
+        gmx_trr_write_frame(trrout, begin+i, eigval[vec], 0, zerobox, natoms, x, NULL, NULL);
     }
-    close_trn(trnout);
+    gmx_trr_close(trrout);
 
     sfree(x);
 }
index b254923bb6812bc59b2cd037e8660d63166449bf..7b2638e16d3f99d7b6e3f4b1466128d57c6ba610 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -56,11 +56,11 @@ extern void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit,
 /* xav is the average/minimum structure is written (t=0).             */
 /* bDMA indicates mass weighted analysis/eigenvectors.                */
 
-extern void write_eigenvectors(const char *trnname, int natoms, real mat[],
+extern void write_eigenvectors(const char *trrname, int natoms, real mat[],
                                gmx_bool bReverse, int begin, int end,
                                int WriteXref, rvec *xref, gmx_bool bDMR,
                                rvec xav[], gmx_bool bDMA, real *eigval);
-/* Write eigenvectors in mat to a TRN file.                           */
+/* Write eigenvectors in mat to a TRR file.                           */
 /* The reference structure is written (t=-1) when WriteXref=eWXR_YES. */
 /* When WriteXref==eWXR_NOFIT a zero frame is written (t=-1),         */
 /* with lambda=-1.                                                    */
index 9f1ae46c1477189b0b37042259d419c287639b42..08441f75603d56c40d577ba27323d4bb782a83b9 100644 (file)
@@ -58,6 +58,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index abbe1f8820ac9b7402ce2afaa225a0f3ada17597..a12593a7b19b40b9b79eeca02d5c795342e6580a 100644 (file)
@@ -41,7 +41,7 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/gstat.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
-static void dump_dih_trn(int nframes, int nangles, real **dih, const char *fn,
+static void dump_dih_trr(int nframes, int nangles, real **dih, const char *fn,
                          real *time)
 {
-    int       i, j, k, l, m, na;
-    t_fileio *trn;
-    rvec     *x;
-    matrix    box = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
+    int              i, j, k, l, m, na;
+    struct t_fileio *fio;
+    rvec            *x;
+    matrix           box = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
 
     na = (nangles*2);
     if ((na % 3) != 0)
@@ -76,7 +76,7 @@ static void dump_dih_trn(int nframes, int nangles, real **dih, const char *fn,
     printf("There are %d dihedrals. Will fill %d atom positions with cos/sin\n",
            nangles, na);
     snew(x, na);
-    trn = open_trn(fn, "w");
+    fio = gmx_trr_open(fn, "w");
     for (i = 0; (i < nframes); i++)
     {
         k = l = 0;
@@ -93,9 +93,9 @@ static void dump_dih_trn(int nframes, int nangles, real **dih, const char *fn,
                 }
             }
         }
-        fwrite_trn(trn, i, time[i], 0, box, na, x, NULL, NULL);
+        gmx_trr_write_frame(fio, i, time[i], 0, box, na, x, NULL, NULL);
     }
-    close_trn(trn);
+    gmx_trr_close(fio);
     sfree(x);
 }
 
@@ -209,7 +209,7 @@ int gmx_g_angle(int argc, char *argv[])
     {
         if (mult != 4)
         {
-            gmx_fatal(FARGS, "Can not combine angles with trn dump");
+            gmx_fatal(FARGS, "Can not combine angles with trr dump");
         }
         else
         {
@@ -309,7 +309,7 @@ int gmx_g_angle(int argc, char *argv[])
     }
     if (opt2bSet("-or", NFILE, fnm))
     {
-        dump_dih_trn(nframes, nangles, dih, opt2fn("-or", NFILE, fnm), time);
+        dump_dih_trr(nframes, nangles, dih, opt2fn("-or", NFILE, fnm), time);
     }
 
     if (bFrac)
index 62b309d95c0f5357842d4071b06c589fe55f43e0..8daa582b6bcab93ca971c8dc94fc543addc07df3 100644 (file)
@@ -40,7 +40,7 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index f4156186fa3f8d0b233aac097bfc8bca981cdd6e..0b12224e2e98d91dd060b57cd2234bd4f4b744d1 100644 (file)
@@ -45,7 +45,6 @@
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/gstat.h"
@@ -57,6 +56,7 @@
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/residuetypes.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index f6da5c1243cbdc8223f5ebf77efeeabe611522b9..011fe580e29347bb9092f6b99c17b051ca5e0bcb 100644 (file)
@@ -41,9 +41,8 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/cmat.h"
index 89f899f0ac18f5a10aa010bd562ccdd64f30bed7..6aa02a2a954c7c72a62ad51966df3d4a5ae902d6 100644 (file)
@@ -53,6 +53,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/index.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 1bcbd5a60eef6be3e787f7c03bda6008e6a5c44d..26add192a6f9ad1c628a5b2578557dfa24160305 100644 (file)
@@ -42,8 +42,8 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/filenm.h"
+#include "gromacs/fileio/groio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/txtdump.h"
@@ -53,6 +53,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index bad3518ababad410abcb8c924d8ff9d719c8dfcd..779326f0b5a91ab8473a45f602a691da66ba2b33 100644 (file)
@@ -42,7 +42,6 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/eigio.h"
index 18bf3476474c90683535b240ebddfa94eaa26fb5..107d87223055f1bb335e96f62d8c06d7623d18bc 100644 (file)
@@ -38,7 +38,7 @@
 #include <stdlib.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -50,6 +50,7 @@
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/statistics/statistics.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 954e27cac8f4d2415fe2770f743b6345a1bd2e47..29bd719c4380249654e5134386405de7e8543bce 100644 (file)
@@ -42,7 +42,6 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index ab355db0e64216bf996cf8258932bda4bc4e8cf2..c88fa5da432006a76b5396a5530626e99b94a0bf 100644 (file)
@@ -40,8 +40,8 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/gstat.h"
@@ -52,6 +52,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 9f387ae8d32db64c2ef6d2c5c4aced15c003e932..a173e8291d9f833f5a40b56d5bf3b165b1bfad96 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/enxio.h"
 #include "gromacs/fileio/matio.h"
 #include "gromacs/fileio/trxio.h"
@@ -63,6 +64,7 @@
 #include "gromacs/random/random.h"
 #include "gromacs/statistics/statistics.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
index 7cc6e085e6c8260dbe810560bff6709a745da470..bfe6cfdbeb28c36be7436947984ccda4a47c2b15 100644 (file)
@@ -68,6 +68,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 typedef struct {
index 38c6de63d1251708db48b0797bdba44a80e575f1..cc33e1764130faae364939cabea2206a0680a2b5 100644 (file)
 #include <stdlib.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/strdb.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gstat.h"
@@ -54,6 +54,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/dir_separator.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 static int strip_dssp(char *dsspfile, int nres,
index 5ac2090141823f2d2a777fe6b98036675984139b..d4423adc47ca1e50d943d761b0b704f1f4d2d1c6 100644 (file)
@@ -44,6 +44,7 @@
 #include "gromacs/correlationfunctions/integrate.h"
 #include "gromacs/fft/fft.h"
 #include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index 0513f8f8a63f76033f60ebbe177b1378fed0ff83..2f985fa6e5469bbc262807293270a8d2dbadceca 100644 (file)
@@ -45,6 +45,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/index.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 int gmx_dyecoupl(int argc, char *argv[])
@@ -227,7 +228,7 @@ int gmx_dyecoupl(int argc, char *argv[])
 
             if (bDatout)
             {
-                datfp = fopen(out_datfile, "w");
+                datfp = gmx_ffopen(out_datfile, "w");
             }
 
             if (bRKout)
index 76945173633be528722f8e33264e675c70b41eac..6013b75f8e50020b3f860bea8449af440f4cb31e 100644 (file)
@@ -58,7 +58,9 @@
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/atomprop.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 typedef struct
index 87cf30d294fd835cab5392848d06b881834344a6..f04541ca90d32da08676ddacd812a2173d2f2456 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index acd82d595146d35a43bb1c48f5f89ef207f218d4..69da88fb2986491aa76f1bb8f5b3694dcc406997 100644 (file)
@@ -54,6 +54,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 
index d2595be547c6a100667c660b0c29255d488ef3be..fc2b29bbf882e5de776018d9b4364b41f0bb6438 100644 (file)
@@ -43,6 +43,7 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
 #include "gromacs/fileio/enxio.h"
+#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
index cb26f11be0dd05705b2c6955dc73fa5467b0b844..2f8e6c3b8e857dfd418395223c213e61e2332d51 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,7 +40,7 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/princ.h"
index 2790a4213f8243f70129ec48b79f60cd0d63b73d..c7d980eee99a68d5b8a266427d420ef520f95c5b 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/force.h"
 #include "gromacs/legacyheaders/macros.h"
index 7d02832330e89f3b5134636b74e31519318b313c..6b2b93762622f64c75b2aae47ae60f17472a45cf 100644 (file)
@@ -41,7 +41,7 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/correlationfunctions/autocorr.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index 37038b0af4cddef9acaec5e815272eeb6df09eab..98e33e5c9a3fdd3a63a4bb3afe5fc07f5beb89ed 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -39,8 +39,8 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/binsearch.h"
@@ -52,6 +52,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index aa95ade3eabf95d9178d445224e47620c1fce7f6..e33ddc7eead7e42dd8bd4a22a1b5e97462e1ddc5 100644 (file)
@@ -46,7 +46,6 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/eigio.h"
 #include "gromacs/legacyheaders/macros.h"
index d3a409ee28d6823409ca7449d7febf8935c8dc6a..8d2ac08527ab1a3d5367d54d667db66d3cfcfd83 100644 (file)
@@ -40,9 +40,9 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -52,6 +52,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 3c96ffb2c6a82b075ee849989d73701b512c78ee..214ba9ef4099c7dfc095bb48d21773c5dadc37f6 100644 (file)
@@ -41,7 +41,7 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -53,6 +53,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
index 04741c1c61b318a291f068ca32c81e0e6492afe9..048d7452fa013cf7a8737b9c4a8fde44ae882c4f 100644 (file)
@@ -42,6 +42,7 @@
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 12c4269589daa88511e37e17a34ddd0f80169641..f185477853954e7f90d42e959567d90fc21630b4 100644 (file)
@@ -46,6 +46,7 @@
 #include "gromacs/math/do_fit.h"
 #include "gromacs/topology/atoms.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 1e288eac27c18e53c3957d445c9c054f2a6dfd08..3a6361d8969d93c6a82784dfbd9462c91f6cda5d 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index 0d005fe5cd4088a62aa8771b52fd9b9b215106f8..4028f46b455d8e4995fb8c9a56c3cca099d8eeb3 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,8 +40,8 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxana/eigio.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -52,6 +52,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/random/random.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 008e3cc58e16693fd223788d2d5a9dfa18c13ce2..7e98f3de6d82b546f2774e30873d6caaf1f2ca62 100644 (file)
@@ -41,8 +41,8 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxana/eigio.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -51,6 +51,7 @@
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 81323175247e429135131a1f26ae4a2be9789639..c0dded8283de35e32d686594ece504779146a3eb 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/cmat.h"
@@ -54,6 +53,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 4f129e40cbf1739a489beebabf8530d080b2f0f0..d174119ac54301394b32234d7852457921f6a5ad 100644 (file)
@@ -51,6 +51,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
index 45adaa478390379a7790614709567b7c77062e74..68d10a239b6406adbe4b987f01e06689daa2d129 100644 (file)
@@ -40,7 +40,7 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -52,6 +52,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
index 4a35277dc526007b2cee6ea1f49aa6e869adbcac..3e32fa29e142e02a984e85440a548b00b222b100 100644 (file)
@@ -40,8 +40,8 @@
 #include <stdlib.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/cmat.h"
index ea2fff5a00d969f13a6fc6289498138c19552b2c..ad79bb2945c448fc1ca38076119adaaa44d01afb 100644 (file)
@@ -39,9 +39,9 @@
 #include <math.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
 #include "gromacs/fileio/strdb.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -52,6 +52,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
index afca0061548c0f4ff860f1c8959b880dd47e6de4..223a1d7d5995684f3ace3de3cb19a4dfedb0b48d 100644 (file)
@@ -41,7 +41,6 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -54,6 +53,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -224,7 +224,6 @@ int gmx_rmsf(int argc, char *argv[])
     int              step, nre, natoms, i, g, m, teller = 0;
     real             t, lambda, *w_rls, *w_rms;
 
-    t_tpxheader      header;
     t_inputrec       ir;
     t_topology       top;
     int              ePBC;
index c9f3dc16ee2dedb68ccd7db3d54dfaa786465e90..1c95da982faae63eb698031aee3a8ab67079aced 100644 (file)
@@ -38,7 +38,7 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index 11d7f1565ad5438d17e253a76f93cbe4d466d5ae..cc4417213daa0cc39ce816d0227a35ca93273b60 100644 (file)
@@ -48,6 +48,7 @@
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index fdff37b0ad33d8e99053e0e2eb56944ee6de0814..90d30a617a1718e45aa45c4102fc6725b21a2332 100644 (file)
@@ -38,7 +38,7 @@
 #include "config.h"
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -50,6 +50,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxomp.h"
index f426fe4e5135a2e6d29f6320744ba205b2900907..3866506b280c0e65b57091e7a9bada03eb1c743d 100644 (file)
@@ -40,9 +40,6 @@
 #include <stdio.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/pdbio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/names.h"
index 9b0f9e20a55881976b3d86ea1866d5af652b5426..ac01e53622643043d4b52931743c9c9ad6994fc9 100644 (file)
@@ -37,7 +37,7 @@
 #include "gmxpre.h"
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -48,6 +48,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index beeaf0d0e86b14fdcef437a7f9e86c48d52d8d13..a7f3d12720ba4f39634ae03d2cb1dc1bda3d2a4e 100644 (file)
@@ -38,7 +38,7 @@
 #include <stdlib.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -47,6 +47,8 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 static const double bohr = 0.529177249;  /* conversion factor to compensate for VMD plugin conversion... */
index 559aa2aa69af0657f68e0663e100510d68e483e1..8c6c25034026515bf520b741e5d36cbf7769e676 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 4846401597228ce87a4b08388a20c9925e706140..7560cec153d82974784b366b5e4c442401493380 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -54,6 +53,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index a651272a226dc4d5ff68fdc86fc150074797cb69..d6c2335650c06fa4d2aeee205abe5af5fc829234 100644 (file)
@@ -46,8 +46,6 @@
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/tngio.h"
 #include "gromacs/fileio/tngio_for_tools.h"
-#include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/fileio/xvgr.h"
index 26ba84944cdd64e9027bec5522a70f9284bff803..213eae951b78a56321bea554305c0c56c84f3303 100644 (file)
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/g96io.h"
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/groio.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/tngio_for_tools.h"
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/fileio/xvgr.h"
@@ -461,7 +463,7 @@ static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr,
     strcat(out_file, ext);
 }
 
-void check_trn(const char *fn)
+void check_trr(const char *fn)
 {
     if (fn2ftp(fn) != efTRR)
     {
@@ -474,7 +476,7 @@ void do_trunc(const char *fn, real t0)
     t_fileio        *in;
     FILE            *fp;
     gmx_bool         bStop, bOK;
-    t_trnheader      sh;
+    gmx_trr_header_t sh;
     gmx_off_t        fpos;
     char             yesno[256];
     int              j;
@@ -486,23 +488,23 @@ void do_trunc(const char *fn, real t0)
     }
 
     /* Check whether this is a .trr file */
-    check_trn(fn);
+    check_trr(fn);
 
-    in   = open_trn(fn, "r");
+    in   = gmx_trr_open(fn, "r");
     fp   = gmx_fio_getfp(in);
     if (fp == NULL)
     {
         fprintf(stderr, "Sorry, can not trunc %s, truncation of this filetype is not supported\n", fn);
-        close_trn(in);
+        gmx_trr_close(in);
     }
     else
     {
         j     = 0;
         fpos  = gmx_fio_ftell(in);
         bStop = FALSE;
-        while (!bStop && fread_trnheader(in, &sh, &bOK))
+        while (!bStop && gmx_trr_read_frame_header(in, &sh, &bOK))
         {
-            fread_htrn(in, &sh, NULL, NULL, NULL, NULL);
+            gmx_trr_read_frame_data(in, &sh, NULL, NULL, NULL, NULL);
             fpos = gmx_ftell(fp);
             t    = sh.t;
             if (t >= t0)
@@ -523,7 +525,7 @@ void do_trunc(const char *fn, real t0)
             if (strcmp(yesno, "YES") == 0)
             {
                 fprintf(stderr, "Once again, I'm gonna DO this...\n");
-                close_trn(in);
+                gmx_trr_close(in);
                 if (0 != gmx_truncate(fn, fpos))
                 {
                     gmx_fatal(FARGS, "Error truncating file %s", fn);
@@ -537,7 +539,7 @@ void do_trunc(const char *fn, real t0)
         else
         {
             fprintf(stderr, "Already at end of file (t=%g)...\n", t);
-            close_trn(in);
+            gmx_trr_close(in);
         }
     }
 }
index ea86375c9c989a439faa1f7d3eba3ea64e21c3f4..8b9e56ad9a7c0cf6721738911ed8338576216f13 100644 (file)
@@ -41,7 +41,7 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
index b293179c076f7ac79819bdeb8b1d4531dd6e2e4e..838b98e72b57d0c2c09e93493d483999df411c12 100644 (file)
@@ -61,6 +61,7 @@
 #include "gromacs/utility/baseversion.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 /* Enum for situations that can occur during log file parsing, the
index fa3567f02f62724442f08d8b0ec34c42d6fffad1..8d046f4b6afa12190776315795c3abc443b5018a 100644 (file)
@@ -42,8 +42,8 @@
 #include <string.h>
 
 #include "gromacs/commandline/pargs.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/matio.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxana/gmx_ana.h"
@@ -54,6 +54,7 @@
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
index bd8077af8a836d97a65ef112c9898273e8ce05a1..3b6c2c161593d16fb8072d80eb26ed59fdfad059 100644 (file)
@@ -64,6 +64,7 @@
 #include "gromacs/random/random.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxomp.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -1895,7 +1896,7 @@ FILE *open_pdo_pipe(const char *fn, t_UmbrellaOptions *opt, gmx_bool *bPipeOpen)
         {
             printf("Executing command '%s'\n", Buffer);
         }
-#ifdef HAVE_PIPES
+#if HAVE_PIPES
         if ((pipe = popen(Buffer, "r")) == NULL)
         {
             gmx_fatal(FARGS, "Unable to open pipe to `%s'\n", Buffer);
@@ -1917,7 +1918,7 @@ FILE *open_pdo_pipe(const char *fn, t_UmbrellaOptions *opt, gmx_bool *bPipeOpen)
 //! Close file or pipe
 void pdo_close_file(FILE *fp)
 {
-#ifdef HAVE_PIPES
+#if HAVE_PIPES
     pclose(fp);
 #else
     gmx_ffclose(fp);
index 8bf2b4d83a474022fbfded24d71859efcfd38328..83f5523ed7a4d93194ab5b028daad3cbb7944caf 100644 (file)
@@ -48,6 +48,7 @@
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/legacyheaders/viewit.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 5c40c6755958a681e8150f16ce0e92d62251655b..165fb75b230750ea630dc639f0789ceab7754515 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,6 +43,7 @@
 
 #include "gromacs/listed-forces/bonded.h"
 #include "gromacs/pbcutil/rmpbc.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index f5cf0eb7878e27e1e60371d08ce30f72ae49a36c..3fcb408faf15c8b9782a6fb0ba4a3d2e14266e96 100644 (file)
@@ -38,9 +38,8 @@
 
 #include "sfactor.h"
 
-#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/strdb.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -50,6 +49,7 @@
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 607f94974a2caa82ae7c2e59b4b7e990cda42c75..e38563f9c95446411ec6ea473492da16111252ca 100644 (file)
@@ -54,6 +54,7 @@
 #include "buildinfo.h"
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/gmxfio-xdr.h"
 #include "gromacs/fileio/xdr_datatype.h"
 #include "gromacs/fileio/xdrf.h"
 #include "gromacs/legacyheaders/copyrite.h"
@@ -1486,7 +1487,7 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
         npmenodes = 0;
     }
 
-#ifndef GMX_NO_RENAME
+#if !GMX_NO_RENAME
     /* make the new temporary filename */
     snew(fntemp, strlen(fn)+5+STEPSTRSIZE);
     strcpy(fntemp, fn);
@@ -1641,7 +1642,7 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
 
     /* we don't move the checkpoint if the user specified they didn't want it,
        or if the fsyncs failed */
-#ifndef GMX_NO_RENAME
+#if !GMX_NO_RENAME
     if (!bNumberAndKeep && !ret)
     {
         if (gmx_fexist(fn))
index 726edde72b4568bc45318d14b5cd54a24ac41485..abb0d80c4c054dc32b70268aae626248bc234302 100644 (file)
@@ -50,7 +50,7 @@
 #ifdef HAVE_LIBMKL
 #include <mkl.h>
 #endif
-#ifdef HAVE_EXTRAE
+#if HAVE_EXTRAE
 #include <extrae_user_events.h>
 #endif
 #include <boost/version.hpp>
@@ -78,7 +78,7 @@ static gmx_bool be_cool(void)
      * but we dont call this routine often, and it avoids using
      * a mutex for locking the variable...
      */
-#ifdef GMX_COOL_QUOTES
+#if GMX_COOL_QUOTES
     return (getenv("GMX_NO_QUOTES") == NULL);
 #else
     /*be uncool*/
@@ -738,7 +738,7 @@ static void gmx_print_version_info(FILE *fp)
 #else
     fprintf(fp, "RDTSCP usage:       disabled\n");
 #endif
-#ifdef GMX_CXX11
+#if GMX_CXX11
     fprintf(fp, "C++11 compilation:  enabled\n");
 #else
     fprintf(fp, "C++11 compilation:  disabled\n");
@@ -748,7 +748,7 @@ static void gmx_print_version_info(FILE *fp)
 #else
     fprintf(fp, "TNG support:        disabled\n");
 #endif
-#ifdef HAVE_EXTRAE
+#if HAVE_EXTRAE
     unsigned major, minor, revision;
     Extrae_get_version(&major, &minor, &revision);
     fprintf(fp, "Tracing support:    enabled. Using Extrae-%d.%d.%d\n", major, minor, revision);
@@ -817,14 +817,14 @@ BinaryInformationSettings::BinaryInformationSettings()
 {
 }
 
-void printBinaryInformation(FILE                          *fp,
-                            const ProgramContextInterface &programContext)
+void printBinaryInformation(FILE                  *fp,
+                            const IProgramContext &programContext)
 {
     printBinaryInformation(fp, programContext, BinaryInformationSettings());
 }
 
 void printBinaryInformation(FILE                            *fp,
-                            const ProgramContextInterface   &programContext,
+                            const IProgramContext           &programContext,
                             const BinaryInformationSettings &settings)
 {
     const char *prefix          = settings.prefix_;
index 89201b8064ae4e746c653177bcae8a4781eb436b..e835286bf7430e0d2d6c84baa83245158ffbdf30 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -44,7 +44,7 @@
 
 struct output_env
 {
-    explicit output_env(const gmx::ProgramContextInterface &context)
+    explicit output_env(const gmx::IProgramContext &context)
         : programContext(context)
     {
         time_unit   = time_ps;
@@ -53,7 +53,7 @@ struct output_env
         verbosity   = 0;
     }
 
-    const gmx::ProgramContextInterface  &programContext;
+    const gmx::IProgramContext  &programContext;
 
     /* the time unit, enum defined in oenv.h */
     time_unit_t                          time_unit;
@@ -91,7 +91,7 @@ static const char *time_units_xvgr[] = {
 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
 
 void output_env_init(output_env_t *oenvp,
-                     const gmx::ProgramContextInterface &context,
+                     const gmx::IProgramContext &context,
                      time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
                      int verbosity)
 {
@@ -207,7 +207,7 @@ const char *output_env_get_program_display_name(const output_env_t oenv)
     return displayName;
 }
 
-const gmx::ProgramContextInterface &
+const gmx::IProgramContext &
 output_env_get_program_context(const output_env_t oenv)
 {
     return oenv->programContext;
index 75ff86caba063cd5da802bd6b82451637c34a5eb..d22fe2159be12204fbf0d8944ec4e391c3b8c857 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -100,7 +100,7 @@ static void signal_handler(int n)
                 abort();
             }
             break;
-#ifdef HAVE_SIGUSR1
+#if HAVE_SIGUSR1
         case SIGUSR1:
             usr_condition = 1;
             break;
@@ -141,7 +141,7 @@ void signal_handler_install(void)
         }
         gmx_signal(SIGINT);
     }
-#ifdef HAVE_SIGUSR1
+#if HAVE_SIGUSR1
     if (getenv("GMX_NO_USR1") == NULL)
     {
         if (debug)
@@ -181,7 +181,7 @@ const char *gmx_get_signal_name(void)
 
 gmx_bool gmx_got_usr_signal(void)
 {
-#ifdef HAVE_SIGUSR1
+#if HAVE_SIGUSR1
     gmx_bool ret = (gmx_bool)usr_condition;
     usr_condition = 0;
     return ret;
index 606a8f4c071633e7f87afd24673067f5f40fd288..db4b587bbb4e8c791380b973f5c310e6cb2e9b68 100644 (file)
@@ -48,6 +48,7 @@
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 63a81b53fc1b9b8385f98e49f3d5e73799b0d67f..8dd9c8aad8791d0b71f09189b7b7cc34451748b4 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2011,2013,2014, by the GROMACS development team, led by
+# Copyright (c) 2011,2013,2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-file(GLOB GMXPREPROCESS_SOURCES *.c *.cpp)
+file(GLOB GMXPREPROCESS_SOURCES *.cpp)
 
 set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${GMXPREPROCESS_SOURCES} PARENT_SCOPE)
 
similarity index 96%
rename from src/gromacs/gmxpreprocess/add_par.c
rename to src/gromacs/gmxpreprocess/add_par.cpp
index cf471c4641e40693d73cef372453199e72c89640..9a916d05b8256f55ca900c44f82e93e00ce6bd99 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -39,6 +39,8 @@
 
 #include <string.h>
 
+#include <algorithm>
+
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/gmxpreprocess/hackblock.h"
 #include "gromacs/gmxpreprocess/toputil.h"
@@ -216,8 +218,9 @@ void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, int am)
 
 int search_jtype(t_restp *rtp, char *name, gmx_bool bNterm)
 {
-    int   niter, iter, j, k, kmax, jmax, minstrlen;
-    char *rtpname, searchname[12];
+    int    niter, iter, j, jmax;
+    size_t k, kmax, minstrlen;
+    char  *rtpname, searchname[12];
 
     strcpy(searchname, name);
 
@@ -253,7 +256,7 @@ int search_jtype(t_restp *rtp, char *name, gmx_bool bNterm)
             }
             if (iter == niter - 1)
             {
-                minstrlen = min(strlen(searchname), strlen(rtpname));
+                minstrlen = std::min(strlen(searchname), strlen(rtpname));
                 for (k = 0; k < minstrlen; k++)
                 {
                     if (searchname[k] != rtpname[k])
index 92a0d8be4d432853825564648e0fa42c5977864a..0ed13041fdc35474ccc3b0ff61ae215125cae34d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/pdb2top.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
 void add_param(t_params *ps, int ai, int aj, real *c, char *s);
 
 void add_imp_param(t_params *ps, int ai, int aj, int ak, int al,
@@ -72,8 +67,4 @@ void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al,
 
 int search_jtype(t_restp *rp, char *name, gmx_bool bFirstRes);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/gmxpreprocess/calch.c
rename to src/gromacs/gmxpreprocess/calch.cpp
index d171bbd34b85d99be060f2b883fb38626a834ca6..3011953d87deedd911d607a01b8cd13ddab81792 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,6 +38,8 @@
 
 #include "calch.h"
 
+#include <cmath>
+
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
@@ -81,7 +83,6 @@ static void gen_waterhydrogen(int nh, rvec xa[], rvec xh[], int *l)
 #undef BB
 #undef CC
     int        m;
-    rvec       kkk;
 
     /* This was copied from Gromos */
     for (m = 0; (m < DIM); m++)
@@ -119,7 +120,7 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l)
     real s6, rij, ra, rb, xd;
     int  d;
 
-    s6 = 0.5*sqrt(3.e0);
+    s6 = 0.5*std::sqrt(3.e0);
 
     /* common work for constructing one, two or three dihedral hydrogens */
     switch (nht)
@@ -137,7 +138,7 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l)
                 sb[d]  = xd-xAK[d];
                 rij   += sqr(sij[d]);
             }
-            rij    = sqrt(rij);
+            rij    = std::sqrt(rij);
             sa[XX] = sij[YY]*sb[ZZ]-sij[ZZ]*sb[YY];
             sa[YY] = sij[ZZ]*sb[XX]-sij[XX]*sb[ZZ];
             sa[ZZ] = sij[XX]*sb[YY]-sij[YY]*sb[XX];
@@ -147,7 +148,7 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l)
                 sij[d] = sij[d]/rij;
                 ra    += sqr(sa[d]);
             }
-            ra = sqrt(ra);
+            ra = std::sqrt(ra);
             for (d = 0; (d < DIM); d++)
             {
                 sa[d] = sa[d]/ra;
@@ -171,15 +172,15 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l)
                 rij   += sqr(sij[d]);
                 rb    += sqr(sb[d]);
             }
-            rij = sqrt(rij);
-            rb  = sqrt(rb);
+            rij = std::sqrt(rij);
+            rb  = std::sqrt(rb);
             ra  = 0.e0;
             for (d = 0; (d < DIM); d++)
             {
                 sa[d] = sij[d]/rij+sb[d]/rb;
                 ra   += sqr(sa[d]);
             }
-            ra = sqrt(ra);
+            ra = std::sqrt(ra);
             for (d = 0; (d < DIM); d++)
             {
                 xH1[d] = xAI[d]+distH*sa[d]/ra;
index ea6211f4dcd663a503542f2f73599544db4646c1..31cdeecd6e8833ecb34f711a07c1f998158a361f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l);
 /*
  *    w.f. van gunsteren, groningen, july 1981
@@ -64,8 +60,4 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l);
  *    l : dynamically changed index
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/convparm.c
rename to src/gromacs/gmxpreprocess/convparm.cpp
index 93f1603c8e9ea4c9253656b953d0c6485e94eb10..84fda2423458e715ce07e9e9c426f66f08c83fce 100644 (file)
 
 #include "convparm.h"
 
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
 #include "gromacs/gmxpreprocess/topio.h"
 #include "gromacs/gmxpreprocess/toputil.h"
@@ -81,21 +82,21 @@ static int round_check(real r, int limit, int ftype, const char *name)
     return i;
 }
 
-static void set_ljparams(int comb, double reppow, real v, real w,
+static void set_ljparams(int comb, double reppow, double v, double w,
                          real *c6, real *c12)
 {
     if (comb == eCOMB_ARITHMETIC || comb == eCOMB_GEOM_SIG_EPS)
     {
         if (v >= 0)
         {
-            *c6  = 4*w*pow(v, 6.0);
-            *c12 = 4*w*pow(v, reppow);
+            *c6  = 4*w*std::pow(v, 6.0);
+            *c12 = 4*w*std::pow(v, reppow);
         }
         else
         {
             /* Interpret negative sigma as c6=0 and c12 with -sigma */
             *c6  = 0;
-            *c12 = 4*w*pow(-v, reppow);
+            *c12 = 4*w*std::pow(-v, reppow);
         }
     }
     else
@@ -113,7 +114,6 @@ assign_param(t_functype ftype, t_iparams *newparam,
              real old[MAXFORCEPARAM], int comb, double reppow)
 {
     int      i, j;
-    real     tmp;
     gmx_bool all_param_zero = TRUE;
 
     /* Set to zero */
@@ -259,7 +259,7 @@ assign_param(t_functype ftype, t_iparams *newparam,
             newparam->thole.alpha2 = old[2];
             if ((old[1] > 0) && (old[2] > 0))
             {
-                newparam->thole.rfac = old[0]*pow(old[1]*old[2], -1.0/6.0);
+                newparam->thole.rfac = old[0]*std::pow(old[1]*old[2], static_cast<real>(-1.0/6.0));
             }
             else
             {
@@ -436,8 +436,8 @@ assign_param(t_functype ftype, t_iparams *newparam,
             newparam->vsiten.a = old[1];
             break;
         case F_CMAP:
-            newparam->cmap.cmapA = old[0];
-            newparam->cmap.cmapB = old[1];
+            newparam->cmap.cmapA = static_cast<int>(old[0]);
+            newparam->cmap.cmapB = static_cast<int>(old[1]);
             break;
         case F_GB12:
         case F_GB13:
@@ -571,7 +571,7 @@ void convert_params(int atnr, t_params nbtypes[],
                     int comb, double reppow, real fudgeQQ,
                     gmx_mtop_t *mtop)
 {
-    int             i, j, maxtypes, mt;
+    int             i, maxtypes, mt;
     unsigned long   flags;
     gmx_ffparams_t *ffp;
     gmx_moltype_t  *molt;
index 0505967510d630582b2e8104ba25c8c507d4bceb..23f233cdbac205dc4bd4f496154036ead1dc25e3 100644 (file)
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void convert_params(int atnr, t_params nbtypes[],
                     t_molinfo *mi,
                     t_molinfo *intermolecular_interactions,
                     int comb, double reppow, real fudgeQQ,
                     gmx_mtop_t *mtop);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index f986f5e545afac46530ad7042743a2ed528bbdbc..11e1f5ae8479677c603445a69a469efc61a77555 100644 (file)
@@ -47,7 +47,6 @@
 #include "gromacs/utility/directoryenumerator.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/path.h"
 #include "gromacs/utility/smalloc.h"
index 572235eee9b412c6b2d2ac92d2c816624fba4c55..1c0d6597c0d62a22e9ccc484683f218652126078 100644 (file)
 
 #include <stdio.h>
 
-#include "gromacs/utility/basedefinitions.h"
-
-#ifdef __cplusplus
 #include <vector>
 
+#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/datafilefinder.h"
 
 /*! \brief
@@ -50,9 +48,6 @@
  */
 std::vector<gmx::DataFileInfo> fflib_enumerate_forcefields();
 
-extern "C" {
-#endif
-
 const char *fflib_forcefield_dir_ext();
 /* Returns the name of the force field directory extension */
 
@@ -86,8 +81,4 @@ FILE *fflib_open(const char *file);
  * either absolute or relative to the current dir.
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 97%
rename from src/gromacs/gmxpreprocess/gen_ad.c
rename to src/gromacs/gmxpreprocess/gen_ad.cpp
index 1b7a0b9c5e3f68f57527db29decb909ac2973afd..201c17e1b0d3c307df2eac201f7d6ebfd785df09 100644 (file)
 #include "gen_ad.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/fileio/confio.h"
 #include "gromacs/gmxpreprocess/gpp_nextnb.h"
 #include "gromacs/gmxpreprocess/pgutil.h"
@@ -510,10 +513,8 @@ static void clean_dih(t_param *dih, int *ndih, t_param improper[], int nimproper
 static int get_impropers(t_atoms *atoms, t_hackblock hb[], t_param **improper,
                          gmx_bool bAllowMissing)
 {
-    char         *a0;
     t_rbondeds   *impropers;
-    t_rbonded    *hbimproper;
-    int           nimproper, i, j, k, r, start, ninc, nalloc;
+    int           nimproper, i, j, k, start, ninc, nalloc;
     atom_id       ai[MAXATOMLIST];
     gmx_bool      bStop;
 
@@ -686,7 +687,7 @@ static void remove_excl(t_excls *excls, int remove)
 
 void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[])
 {
-    int      i, j, j1, k, k1, l, l1, m, n, e;
+    int      i, j, j1, k, k1, l, l1, e;
     t_excls *excl;
 
     if (nrexcl >= 1)
@@ -750,10 +751,10 @@ void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[])
 
 void generate_excls(t_nextnb *nnb, int nrexcl, t_excls excls[])
 {
-    int      i, j, j1, k, k1, l, l1, m, n, e, N;
+    int      i, j, n, N;
     t_excls *excl;
 
-    for (N = 1; (N < min(nrexcl, nnb->nrex)); N++)
+    for (N = 1; (N < std::min(nrexcl, nnb->nrex)); N++)
     {
         /* extract all i-j-k-l neighbours from nnb struct */
         for (i = 0; (i < nnb->nr); i++)
@@ -861,8 +862,8 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[],
                             maxres = minres;
                             for (m = 1; m < 3; m++)
                             {
-                                minres = min(minres, atoms->atom[ang[nang].a[m]].resind);
-                                maxres = max(maxres, atoms->atom[ang[nang].a[m]].resind);
+                                minres = std::min(minres, atoms->atom[ang[nang].a[m]].resind);
+                                maxres = std::max(maxres, atoms->atom[ang[nang].a[m]].resind);
                             }
                             res = 2*minres-maxres;
                             do
@@ -925,8 +926,8 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[],
                                     maxres = minres;
                                     for (m = 1; m < 4; m++)
                                     {
-                                        minres = min(minres, atoms->atom[dih[ndih].a[m]].resind);
-                                        maxres = max(maxres, atoms->atom[dih[ndih].a[m]].resind);
+                                        minres = std::min(minres, atoms->atom[dih[ndih].a[m]].resind);
+                                        maxres = std::max(maxres, atoms->atom[dih[ndih].a[m]].resind);
                                     }
                                     res = 2*minres-maxres;
                                     do
@@ -1004,8 +1005,8 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[],
                                 }
                                 if (nbd == 3)
                                 {
-                                    i1    = min(i, l1);
-                                    i2    = max(i, l1);
+                                    i1    = std::min(i, l1);
+                                    i2    = std::max(i, l1);
                                     bExcl = FALSE;
                                     for (m = 0; m < excls[i1].nr; m++)
                                     {
index e8814a5cabe8491f960b7b543bafe0dfa9ad9712..af4c037288d149279d5181d4548c56f76d74bd61 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/toputil.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void generate_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]);
 void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]);
 
@@ -54,8 +50,4 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[],
              t_params plist[], t_excls excls[], t_hackblock hb[],
              gmx_bool bAllowMissing);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/gmxpreprocess/gen_maxwell_velocities.c
rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp
index 02522be85facfea72c534ecfbc500d2fcfff594e..3ba751f6b29ac1e9e3b800dd05c3ca6afb092506 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "gen_maxwell_velocities.h"
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/units.h"
@@ -65,7 +65,7 @@ static void low_mspeed(real tempi,
         mass = atom->m;
         if (mass > 0)
         {
-            sd = sqrt(boltz/mass);
+            sd = std::sqrt(boltz/mass);
             for (m = 0; (m < DIM); m++)
             {
                 v[i][m] = sd*gmx_rng_gaussian_real(rng);
@@ -77,7 +77,7 @@ static void low_mspeed(real tempi,
     temp = (2.0*ekin)/(nrdf*BOLTZ);
     if (temp > 0)
     {
-        scal = sqrt(tempi/temp);
+        scal = std::sqrt(tempi/temp);
         for (i = 0; (i < mtop->natoms); i++)
         {
             for (m = 0; (m < DIM); m++)
@@ -99,8 +99,6 @@ static void low_mspeed(real tempi,
 
 void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t *mtop, rvec v[])
 {
-    atom_id  *dummy;
-    int       i;
     gmx_rng_t rng;
 
     if (seed == 0)
index 2679948ceddcb28c7d200d3345baf1ea8ba87fd9..b4f65cd3c39460b4ee6572693932360accb4651c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*! \brief
  * Generate Maxwellian velocities.
  *
@@ -66,8 +62,4 @@ void maxwell_speed(real tempi, unsigned int seed,
  */
 void stop_cm(FILE *log, int natoms, real mass[], rvec x[], rvec v[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 97%
rename from src/gromacs/gmxpreprocess/gen_vsite.c
rename to src/gromacs/gmxpreprocess/gen_vsite.cpp
index 4d0e990044c17b47b9faf3c0d269383e98ceef72..5e21b9032c0f54ed0cead89483bc50177a0b5d46 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gen_vsite.h"
 
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
 #include "gromacs/gmxpreprocess/add_par.h"
 #include "gromacs/gmxpreprocess/fflibutil.h"
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
@@ -158,7 +159,7 @@ static void read_vsite_database(const char *ddbname,
     FILE        *ddb;
     char         dirstr[STRLEN];
     char         pline[STRLEN];
-    int          i, j, n, k, nvsite, ntop, curdir, prevdir;
+    int          i, n, k, nvsite, ntop, curdir;
     t_vsiteconf *vsiteconflist;
     t_vsitetop  *vsitetoplist;
     char        *ch;
@@ -582,7 +583,7 @@ static void add_vsites(t_params plist[], int vsite_type[],
                        int Heavy, int nrHatoms, int Hatoms[],
                        int nrheavies, int heavies[])
 {
-    int      i, j, ftype, other, moreheavy, bb;
+    int      i, j, ftype, other, moreheavy;
     gmx_bool bSwapParity;
 
     for (i = 0; i < nrHatoms; i++)
@@ -697,7 +698,7 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[],
 
     int  i, nvsite;
     real a, b, dCGCE, tmp1, tmp2, mtot, mG, mrest;
-    real xCG, yCG, xCE1, yCE1, xCE2, yCE2;
+    real xCG;
     /* CG, CE1 and CE2 stay and each get a part of the total mass,
      * so the c-o-m stays the same.
      */
@@ -711,7 +712,7 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[],
     }
 
     /* constraints between CG, CE1 and CE2: */
-    dCGCE = sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) );
+    dCGCE = std::sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) );
     my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atCE1], dCGCE);
     my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atCE2], dCGCE);
     my_add_param(&(plist[F_CONSTRNC]), ats[atCE1], ats[atCE2], dCGCE);
@@ -734,11 +735,6 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[],
      * the CE1-CE2 bond and y=0 at the line from CG to the middle of CE1-CE2 bond.
      */
     xCG  = -bond_cc+bond_cc*cos(ANGLE_6RING);
-    yCG  = 0;
-    xCE1 = 0;
-    yCE1 = bond_cc*sin(0.5*ANGLE_6RING);
-    xCE2 = 0;
-    yCE2 = -bond_cc*sin(0.5*ANGLE_6RING);
 
     mG                             = at->atom[ats[atCG]].m = at->atom[ats[atCG]].mB = xcom*mtot/xCG;
     mrest                          = mtot-mG;
@@ -792,7 +788,7 @@ static int gen_vsites_phe(t_atoms *at, int *vsite_type[], t_params plist[],
         atCG, atCD1, atHD1, atCD2, atHD2, atCE1, atHE1, atCE2, atHE2,
         atCZ, atHZ, atNR
     };
-    real x[atNR], y[atNR];
+    real x[atNR];
     /* Aromatic rings have 6-fold symmetry, so we only need one bond length.
      * (angle is always 120 degrees).
      */
@@ -800,27 +796,16 @@ static int gen_vsites_phe(t_atoms *at, int *vsite_type[], t_params plist[],
     bond_ch = get_ddb_bond(vsitetop, nvsitetop, "PHE", "CD1", "HD1");
 
     x[atCG]  = -bond_cc+bond_cc*cos(ANGLE_6RING);
-    y[atCG]  = 0;
     x[atCD1] = -bond_cc;
-    y[atCD1] = bond_cc*sin(0.5*ANGLE_6RING);
     x[atHD1] = x[atCD1]+bond_ch*cos(ANGLE_6RING);
-    y[atHD1] = y[atCD1]+bond_ch*sin(ANGLE_6RING);
     x[atCE1] = 0;
-    y[atCE1] = y[atCD1];
     x[atHE1] = x[atCE1]-bond_ch*cos(ANGLE_6RING);
-    y[atHE1] = y[atCE1]+bond_ch*sin(ANGLE_6RING);
     x[atCD2] = x[atCD1];
-    y[atCD2] = -y[atCD1];
     x[atHD2] = x[atHD1];
-    y[atHD2] = -y[atHD1];
     x[atCE2] = x[atCE1];
-    y[atCE2] = -y[atCE1];
     x[atHE2] = x[atHE1];
-    y[atHE2] = -y[atHE1];
     x[atCZ]  = bond_cc*cos(0.5*ANGLE_6RING);
-    y[atCZ]  = 0;
     x[atHZ]  = x[atCZ]+bond_ch;
-    y[atHZ]  = 0;
 
     xcom = mtot = 0;
     for (i = 0; i < atNR; i++)
@@ -840,14 +825,11 @@ static void calc_vsite3_param(real xd, real yd, real xi, real yi, real xj, real
      * virtual site coordinates here.
      */
     real dx_ij, dx_ik, dy_ij, dy_ik;
-    real b_ij, b_ik;
 
     dx_ij = xj-xi;
     dy_ij = yj-yi;
     dx_ik = xk-xi;
     dy_ik = yk-yi;
-    b_ij  = sqrt(dx_ij*dx_ij+dy_ij*dy_ij);
-    b_ik  = sqrt(dx_ik*dx_ik+dy_ik*dy_ik);
 
     *a = ( (xd-xi)*dy_ik - dx_ik*(yd-yi) ) / (dx_ij*dy_ik - dx_ik*dy_ij);
     *b = ( yd - yi - (*a)*dy_ij ) / dy_ik;
@@ -877,20 +859,18 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[],
     };
 
     real xi[atNR], yi[atNR];
-    real xcom[NMASS], ycom[NMASS], I, alpha;
-    real lineA, lineB, dist;
+    real xcom[NMASS], ycom[NMASS], alpha;
     real b_CD2_CE2, b_NE1_CE2, b_CG_CD2, b_CH2_HH2, b_CE2_CZ2;
     real b_NE1_HE1, b_CD2_CE3, b_CE3_CZ3, b_CB_CG;
     real b_CZ2_CH2, b_CZ2_HZ2, b_CD1_HD1, b_CE3_HE3;
     real b_CG_CD1, b_CZ3_HZ3;
     real a_NE1_CE2_CD2, a_CE2_CD2_CG, a_CB_CG_CD2, a_CE2_CD2_CE3;
-    real a_CB_CG_CD1, a_CD2_CG_CD1, a_CE2_CZ2_HZ2, a_CZ2_CH2_HH2;
+    real a_CD2_CG_CD1, a_CE2_CZ2_HZ2, a_CZ2_CH2_HH2;
     real a_CD2_CE2_CZ2, a_CD2_CE3_CZ3, a_CE3_CZ3_HZ3, a_CG_CD1_HD1;
     real a_CE2_CZ2_CH2, a_HE1_NE1_CE2, a_CD2_CE3_HE3;
-    real xM[NMASS];
     int  atM[NMASS], tpM, i, i0, j, nvsite;
-    real mwtot, mtot, mM[NMASS], dCBM1, dCBM2, dM1M2;
-    real a, b, c[MAXFORCEPARAM];
+    real mM[NMASS], dCBM1, dCBM2, dM1M2;
+    real a, b;
     rvec r_ij, r_ik, t1, t2;
     char name[10];
 
@@ -920,7 +900,7 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[],
     a_CE2_CD2_CG  = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CE2", "CD2", "CG");
     a_CB_CG_CD2   = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD2");
     a_CD2_CG_CD1  = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CD2", "CG", "CD1");
-    a_CB_CG_CD1   = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD1");
+    /*a_CB_CG_CD1   = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD1"); unused */
 
     a_CE2_CD2_CE3 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CE2", "CD2", "CE3");
     a_CD2_CE2_CZ2 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CD2", "CE2", "CZ2");
@@ -997,10 +977,6 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[],
     xi[atHH2] = xi[atCH2]+b_CH2_HH2*sin(alpha);
     yi[atHH2] = yi[atCH2]-b_CH2_HH2*cos(alpha);
 
-    /* Determine coeff. for the line CB-CG */
-    lineA = (yi[atCB]-yi[atCG])/(xi[atCB]-xi[atCG]);
-    lineB = yi[atCG]-lineA*xi[atCG];
-
     /* Calculate masses for each ring and put it on the dummy masses */
     for (j = 0; j < NMASS; j++)
     {
@@ -1097,9 +1073,9 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[],
 
     /* constraints between CB, M1 and M2 */
     /* 'add_shift' says which atoms won't be renumbered afterwards */
-    dCBM1 = sqrt( sqr(xcom[0]-xi[atCB]) + sqr(ycom[0]-yi[atCB]) );
-    dM1M2 = sqrt( sqr(xcom[0]-xcom[1]) + sqr(ycom[0]-ycom[1]) );
-    dCBM2 = sqrt( sqr(xcom[1]-xi[atCB]) + sqr(ycom[1]-yi[atCB]) );
+    dCBM1 = std::sqrt( sqr(xcom[0]-xi[atCB]) + sqr(ycom[0]-yi[atCB]) );
+    dM1M2 = std::sqrt( sqr(xcom[0]-xcom[1]) + sqr(ycom[0]-ycom[1]) );
+    dCBM2 = std::sqrt( sqr(xcom[1]-xi[atCB]) + sqr(ycom[1]-yi[atCB]) );
     my_add_param(&(plist[F_CONSTRNC]), ats[atCB],       add_shift+atM[0], dCBM1);
     my_add_param(&(plist[F_CONSTRNC]), ats[atCB],       add_shift+atM[1], dCBM2);
     my_add_param(&(plist[F_CONSTRNC]), add_shift+atM[0], add_shift+atM[1], dM1M2);
@@ -1144,7 +1120,7 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[],
     real dCGCE, dCEOH, dCGM, tmp1, a, b;
     real bond_cc, bond_ch, bond_co, bond_oh, angle_coh;
     real xcom, mtot;
-    real vmass, vdist, mM;
+    real vdist, mM;
     rvec r1;
     char name[10];
 
@@ -1153,7 +1129,7 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[],
         atCG, atCD1, atHD1, atCD2, atHD2, atCE1, atHE1, atCE2, atHE2,
         atCZ, atOH, atHH, atNR
     };
-    real xi[atNR], yi[atNR];
+    real xi[atNR];
     /* CG, CE1, CE2 (as in general 6-ring) and OH and HH stay,
        rest gets virtualized.
        Now we have two linked triangles with one improper keeping them flat */
@@ -1172,27 +1148,16 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[],
     angle_coh = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TYR", "CZ", "OH", "HH");
 
     xi[atCG]  = -bond_cc+bond_cc*cos(ANGLE_6RING);
-    yi[atCG]  = 0;
     xi[atCD1] = -bond_cc;
-    yi[atCD1] = bond_cc*sin(0.5*ANGLE_6RING);
     xi[atHD1] = xi[atCD1]+bond_ch*cos(ANGLE_6RING);
-    yi[atHD1] = yi[atCD1]+bond_ch*sin(ANGLE_6RING);
     xi[atCE1] = 0;
-    yi[atCE1] = yi[atCD1];
     xi[atHE1] = xi[atCE1]-bond_ch*cos(ANGLE_6RING);
-    yi[atHE1] = yi[atCE1]+bond_ch*sin(ANGLE_6RING);
     xi[atCD2] = xi[atCD1];
-    yi[atCD2] = -yi[atCD1];
     xi[atHD2] = xi[atHD1];
-    yi[atHD2] = -yi[atHD1];
     xi[atCE2] = xi[atCE1];
-    yi[atCE2] = -yi[atCE1];
     xi[atHE2] = xi[atHE1];
-    yi[atHE2] = -yi[atHE1];
     xi[atCZ]  = bond_cc*cos(0.5*ANGLE_6RING);
-    yi[atCZ]  = 0;
     xi[atOH]  = xi[atCZ]+bond_co;
-    yi[atOH]  = 0;
 
     xcom = mtot = 0;
     for (i = 0; i < atOH; i++)
@@ -1214,8 +1179,8 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[],
     at->atom[ats[atCZ]].m = at->atom[ats[atCZ]].mB = 0;
 
     /* constraints between CE1, CE2 and OH */
-    dCGCE = sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) );
-    dCEOH = sqrt( cosrule(bond_cc, bond_co, ANGLE_6RING) );
+    dCGCE = std::sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) );
+    dCEOH = std::sqrt( cosrule(bond_cc, bond_co, ANGLE_6RING) );
     my_add_param(&(plist[F_CONSTRNC]), ats[atCE1], ats[atOH], dCEOH);
     my_add_param(&(plist[F_CONSTRNC]), ats[atCE2], ats[atOH], dCEOH);
 
@@ -1282,7 +1247,7 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[],
     nvsite++;
     /* assume we also want the COH angle constrained: */
     tmp1 = bond_cc*cos(0.5*ANGLE_6RING) + dCGCE*sin(ANGLE_6RING*0.5) + bond_co;
-    dCGM = sqrt( cosrule(tmp1, vdist, angle_coh) );
+    dCGM = std::sqrt( cosrule(tmp1, vdist, angle_coh) );
     my_add_param(&(plist[F_CONSTRNC]), ats[atCG], add_shift+atM, dCGM);
     my_add_param(&(plist[F_CONSTRNC]), ats[atOH], add_shift+atM, vdist);
 
@@ -1375,8 +1340,8 @@ static int gen_vsites_his(t_atoms *at, int *vsite_type[], t_params plist[],
     }
 
     /* constraints between CG, CE1 and NE1 */
-    dCGCE1   = sqrt( cosrule(b_CG_ND1, b_ND1_CE1, a_CG_ND1_CE1) );
-    dCGNE2   = sqrt( cosrule(b_CG_CD2, b_CD2_NE2, a_CG_CD2_NE2) );
+    dCGCE1   = std::sqrt( cosrule(b_CG_ND1, b_ND1_CE1, a_CG_ND1_CE1) );
+    dCGNE2   = std::sqrt( cosrule(b_CG_CD2, b_CD2_NE2, a_CG_CD2_NE2) );
 
     my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atCE1], dCGCE1);
     my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atNE2], dCGNE2);
@@ -1394,7 +1359,7 @@ static int gen_vsites_his(t_atoms *at, int *vsite_type[], t_params plist[],
     y[atCE1] = cosalpha*dCGCE1;
     x[atNE2] = 0;
     y[atNE2] = y[atCE1]-b_CE1_NE2;
-    sinalpha = sqrt(1-cosalpha*cosalpha);
+    sinalpha = std::sqrt(1-cosalpha*cosalpha);
     x[atCG]  = -sinalpha*dCGCE1;
     y[atCG]  = 0;
     x[atHE1] = x[atHE2] = x[atHD1] = x[atHD2] = 0;
@@ -1553,7 +1518,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype,
     int               i, j, k, m, i0, ni0, whatres, resind, add_shift, ftype, nvsite, nadd;
     int               ai, aj, ak, al;
     int               nrfound = 0, needed, nrbonds, nrHatoms, Heavy, nrheavies, tpM, tpHeavy;
-    int               Hatoms[4], heavies[4], bb;
+    int               Hatoms[4], heavies[4];
     gmx_bool          bWARNING, bAddVsiteParam, bFirstWater;
     matrix            tmpmat;
     gmx_bool         *bResProcessed;
@@ -1959,7 +1924,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype,
                         mHtot *= mHmult;
                     }
                     fact2 = mHtot/mtot;
-                    fact  = sqrt(fact2);
+                    fact  = std::sqrt(fact2);
                     /* generate vectors parallel and perpendicular to rotational axis:
                      * rpar  = Heavy -> Hcom
                      * rperp = Hcom  -> H1   */
index 6a350ef7093b373f8e8eded985adee4b06f76078..4ece47f91e2bd418cb843c5eeba04cbcf29c6156 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/hackblock.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
 /* stuff for pdb2gmx */
 
 void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype,
@@ -59,8 +54,4 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype,
 void do_h_mass(t_params *psb, int vsite_type[], t_atoms *at, real mHmult,
                gmx_bool bDeuterate);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 99%
rename from src/gromacs/gmxpreprocess/genconf.c
rename to src/gromacs/gmxpreprocess/genconf.cpp
index 9f9a57ce8cda8b3f08e81d47b2aa7b9273ffca21..01c998a13871720ccfdd54ff5dc642cb40686123 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -50,6 +50,7 @@
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/random/random.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index fa067de2d7571b2d72d0852dafc49f00afc568f5..e10b6139a860b74799fc9b590736ae837cf4e8e7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_GMXPREPROCESS_GENCONF_H
 #define GMX_GMXPREPROCESS_GENCONF_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 int gmx_genconf(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 99%
rename from src/gromacs/gmxpreprocess/genhydro.c
rename to src/gromacs/gmxpreprocess/genhydro.cpp
index 3a85fa12094f8a8201a5647d3174d605c1619db1..5708d3ec5624dc451fdb581740018f4e2455d74d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -177,7 +177,7 @@ static t_hackblock *get_hackblocks(t_atoms *pdba, int nah, t_hackblock ah[],
 static void expand_hackblocks_one(t_hackblock *hbr, char *atomname,
                                   int *nabi, t_hack **abi, gmx_bool bN, gmx_bool bC)
 {
-    int      j, k, l, d;
+    int      j, k, l;
     gmx_bool bIgnore;
 
     /* we'll recursively add atoms to atoms */
@@ -320,7 +320,7 @@ static void expand_hackblocks(t_atoms *pdba, t_hackblock hb[],
 
 static int check_atoms_present(t_atoms *pdba, int nab[], t_hack *ab[])
 {
-    int i, j, k, d, rnr, nadd;
+    int i, j, k, rnr, nadd;
 
     nadd = 0;
     for (i = 0; i < pdba->nr; i++)
@@ -468,7 +468,7 @@ static int add_h_low(t_atoms **pdbaptr, rvec *xptr[],
 {
     t_atoms        *newpdba = NULL, *pdba = NULL;
     int             nadd;
-    int             i, newi, j, d, natoms, nalreadypresent;
+    int             i, newi, j, natoms, nalreadypresent;
     int            *nab = NULL;
     t_hack        **ab  = NULL;
     t_hackblock    *hb;
@@ -726,10 +726,6 @@ static int add_h_low(t_atoms **pdbaptr, rvec *xptr[],
         }
         *pdbaptr = newpdba;
     }
-    else
-    {
-        nadd = newi-natoms;
-    }
 
     sfree(*xptr);
     *xptr = xn;
index 9161a33324d63b8786358f7ed2b5ca285818a0d5..1fd797cff15a8934ad6f916769d856d3c0b6d053 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/gmxpreprocess/hackblock.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 int add_h(t_atoms **pdbaptr, rvec *xptr[],
           int nah, t_hackblock ah[],
           int nterpairs,
@@ -76,8 +72,4 @@ void deprotonate(t_atoms *atoms, rvec *x);
  * removed
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/gmxcpp.c
rename to src/gromacs/gmxpreprocess/gmxcpp.cpp
index 90ad4aabcfbb33a3cef904e6896f8effea707880..f538a72225f1bd479271a6b99e161babd2b31b7e 100644 (file)
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include <sys/types.h>
 
 #include "gromacs/legacyheaders/macros.h"
@@ -240,10 +243,9 @@ static void done_defines()
 int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts)
 {
     gmx_cpp_t    cpp;
-    char        *buf, *pdum;
+    char        *buf;
     char        *ptr, *ptr2;
     int          i;
-    unsigned int i1;
 
     /* First process options, they might be necessary for opening files
        (especially include statements). */
@@ -509,7 +511,6 @@ process_directive(gmx_cpp_t *handlep, const char *dname, const char *dval)
         /* Make a linked list of open files and move on to the include file */
         handle->child->parent = handle;
         *handlep              = handle->child;
-        handle                = *handlep;
         return eCPP_OK;
     }
 
@@ -670,7 +671,9 @@ int cpp_read_line(gmx_cpp_t *handlep, int n, char buf[])
             }
             if (nn > 0)
             {
-                len = strlen(buf) + nn*max(4, 4+strlen(defs[i].def)-strlen(defs[i].name));
+                size_t four = 4;
+
+                len = strlen(buf) + nn*std::max(four, four+strlen(defs[i].def)-strlen(defs[i].name));
                 snew(name, len);
                 ptr = buf;
                 while ((ptr2 = strstrw(ptr, defs[i].name)) != NULL)
@@ -702,7 +705,6 @@ int cpp_cur_linenr(const gmx_cpp_t *handlep)
 /* Close the file! Return integer status. */
 int cpp_close_file(gmx_cpp_t *handlep)
 {
-    int       i;
     gmx_cpp_t handle = (gmx_cpp_t)*handlep;
 
     if (!handle)
index 5488a220cf2c13cf285715fa173e4ac3b0ae800c..d0446f97533c965a0c05016851a0b25e47bee8ef 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -37,6 +37,7 @@
 
 #ifndef GMX_GMXPREPROCESS_GMXCPP_H
 #define GMX_GMXPREPROCESS_GMXCPP_H
+
 typedef struct gmx_cpp *gmx_cpp_t;
 
 /* The possible return codes for these functions */
@@ -93,4 +94,5 @@ void cpp_done();
    NOT THREAD SAFE
  */
 char *cpp_error(gmx_cpp_t *handlep, int status);
+
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/gpp_atomtype.c
rename to src/gromacs/gmxpreprocess/gpp_atomtype.cpp
index 4a9c932b0f93c8dd01f095bbc21acf0d006e4108..1387e21914c20b4c09678db505dd1be70861c09c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gpp_atomtype.h"
 
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
 #include "gromacs/gmxpreprocess/topdirs.h"
 #include "gromacs/gmxpreprocess/toputil.h"
 #include "gromacs/legacyheaders/txtdump.h"
@@ -295,7 +296,7 @@ int set_atomtype(int nt, gpp_atomtype_t ga, t_symtab *tab,
 int add_atomtype(gpp_atomtype_t ga, t_symtab *tab,
                  t_atom *a, const char *name, t_param *nb,
                  int bondatomtype,
-                 real radius, real vol, real surftens, real atomnumber,
+                 real radius, real vol, real surftens, int atomnumber,
                  real gb_radius, real S_hct)
 {
     int i;
index 9dd46548b3ae6fa8eece4e85583559e92ed09e62..19d345c650d80184509373e2b4b62ce3d83840c3 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 typedef struct gpp_atomtype *gpp_atomtype_t;
 
 int get_atomtype_type(const char *str, gpp_atomtype_t at);
@@ -99,7 +95,7 @@ set_atomtype_gbparam(gpp_atomtype_t at, int i,
 int add_atomtype(gpp_atomtype_t at, struct t_symtab *tab,
                  t_atom *a, const char *name, t_param *nb,
                  int bondatomtype,
-                 real radius, real vol, real surftens, real atomnumber,
+                 real radius, real vol, real surftens, int atomnumber,
                  real gb_radius, real S_hct);
 /* Add a complete new atom type to an existing atomtype structure. Returns
    the number of the atom type. */
@@ -114,8 +110,4 @@ void renum_atype(t_params plist[], gmx_mtop_t *mtop,
 void copy_atomtype_atomtypes(gpp_atomtype_t atype, t_atomtypes *atypes);
 /* Copy from one structure to another */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index c901d9b1f07484ab890e755a1ff22eb92cbb157c..6fc4635babec989e2836a7eabae2bc21be393ea6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 typedef struct gpp_bondatomtype *t_bond_atomtype;
 
 int get_bond_atomtype_type(char *str, t_bond_atomtype at);
@@ -65,8 +61,4 @@ void add_bond_atomtype(t_bond_atomtype at, struct t_symtab *tab,
                        char *name);
 /* Add a complete new atom type to an existing atomtype structure */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 99%
rename from src/gromacs/gmxpreprocess/gpp_nextnb.c
rename to src/gromacs/gmxpreprocess/gpp_nextnb.cpp
index ac779b14bdb2489eb34c261b3a3bc26a23597475..a7425263b6f235f8a4fdf33040e88e90aecc15d4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -406,8 +406,6 @@ sort_and_purge_nnb(t_nextnb *nnb)
 
 void generate_excl (int nrexcl, int nratoms, t_params plist[], t_nextnb *nnb, t_blocka *excl)
 {
-    int i, j, k;
-
     if (nrexcl < 0)
     {
         gmx_fatal(FARGS, "Can't have %d exclusions...", nrexcl);
index c5dde3865e4d3451ddf8a87fd2b98297d1ed38fc..93f35d634a230d7f7feb1371403ec46cbfeb60be 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 typedef struct {
     int nr;     /* nr atoms (0 <= i < nr) (atoms->nr)          */
     int nrex;   /* with nrex lists of neighbours               */
@@ -81,8 +77,4 @@ void generate_excl (int nrexcl, int nratoms,
  * plist.
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 20cafb0cd77ffc9b0113af0205484c336860c641..8e268457c7a20e064989c5179f74d3f3e8efcd2c 100644 (file)
 
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #define MAXSLEN 32
 
 typedef struct {
@@ -54,7 +50,6 @@ typedef struct {
  * non-bonded parameter combinations, which will be copied to t_params.
  */
 
-#ifndef __cplusplus
 /*
  * With the macros below you don't
  * have to use an index if you don't wan't to. You can eg. use
@@ -74,7 +69,6 @@ typedef struct {
 #define C0  c[0]
 #define C1  c[1]
 #define C2  c[2]
-#endif
 
 typedef struct {
     atom_id    a[MAXATOMLIST];   /* The atom list (eg. bonds: particle */
@@ -171,8 +165,4 @@ typedef enum {
     d_none
 } directive;
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 97%
rename from src/gromacs/gmxpreprocess/grompp.c
rename to src/gromacs/gmxpreprocess/grompp.cpp
index 2f976b8d2eef1c8667d524a3ac287ca999f9aef2..d8a6737091a6bc1bbee23613862035b37f925ce3 100644 (file)
 
 #include "grompp.h"
 
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include <sys/types.h>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/enxio.h"
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxpreprocess/add_par.h"
 #include "gromacs/gmxpreprocess/convparm.h"
@@ -84,6 +84,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/snprintf.h"
 
@@ -188,7 +189,7 @@ static void check_cg_sizes(const char *topfn, t_block *cgs, warninp_t wi)
     maxsize = 0;
     for (cg = 0; cg < cgs->nr; cg++)
     {
-        maxsize = max(maxsize, cgs->index[cg+1]-cgs->index[cg]);
+        maxsize = std::max(maxsize, cgs->index[cg+1]-cgs->index[cg]);
     }
 
     if (maxsize > MAX_CHARGEGROUP_SIZE)
@@ -290,7 +291,7 @@ static void check_bonds_timestep(gmx_mtop_t *mtop, double dt, warninp_t wi)
                 if (debug)
                 {
                     fprintf(debug, "fc %g m1 %g m2 %g period %g\n",
-                            fc, m1, m2, sqrt(period2));
+                            fc, m1, m2, std::sqrt(period2));
                 }
                 if (period2 < limit2)
                 {
@@ -335,7 +336,7 @@ static void check_bonds_timestep(gmx_mtop_t *mtop, double dt, warninp_t wi)
                 *w_moltype->name,
                 w_a1+1, *w_moltype->atoms.atomname[w_a1],
                 w_a2+1, *w_moltype->atoms.atomname[w_a2],
-                sqrt(w_period2), bWarn ? min_steps_warn : min_steps_note, dt,
+                std::sqrt(w_period2), bWarn ? min_steps_warn : min_steps_note, dt,
                 bWater ?
                 "Maybe you asked for fexible water." :
                 "Maybe you forgot to change the constraints mdp option.");
@@ -811,7 +812,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
                         rvec com,
                         warninp_t wi)
 {
-    gmx_bool        bFirst = TRUE, *hadAtom;
+    gmx_bool       *hadAtom;
     rvec           *x, *v, *xp;
     dvec            sum;
     double          totmass;
@@ -827,7 +828,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
     get_stx_coordnum(fn, &natoms);
     if (natoms != mtop->natoms)
     {
-        sprintf(warn_buf, "The number of atoms in %s (%d) does not match the number of atoms in the topology (%d). Will assume that the first %d atoms in the topology and %s match.", fn, natoms, mtop->natoms, min(mtop->natoms, natoms), fn);
+        sprintf(warn_buf, "The number of atoms in %s (%d) does not match the number of atoms in the topology (%d). Will assume that the first %d atoms in the topology and %s match.", fn, natoms, mtop->natoms, std::min(mtop->natoms, natoms), fn);
         warning(wi, warn_buf);
     }
     snew(x, natoms);
@@ -936,7 +937,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB,
 
     if (rc_scaling != erscNO)
     {
-        assert(npbcdim <= DIM);
+        GMX_ASSERT(npbcdim <= DIM, "Only DIM dimensions can have PBC");
 
         for (mb = 0; mb < mtop->nmolblock; mb++)
         {
@@ -994,8 +995,6 @@ static void gen_posres(gmx_mtop_t *mtop, t_molinfo *mi,
                        rvec com, rvec comB,
                        warninp_t wi)
 {
-    int i, j;
-
     read_posres  (mtop, mi, FALSE, fnA, rc_scaling, ePBC, com, wi);
     /* It is safer to simply read the b-state posres rather than trying
      * to be smart and copy the positions.
@@ -1092,7 +1091,7 @@ interpolate1d( double     xmin,
     int    ix;
     double a, b;
 
-    ix = (x-xmin)/dx;
+    ix = static_cast<int>((x-xmin)/dx);
 
     a = (xmin+(ix+1)*dx-x)/dx;
     b = (x-xmin-ix*dx)/dx;
@@ -1182,7 +1181,7 @@ setup_cmap (int              grid_spacing,
 
 void init_cmap_grid(gmx_cmap_t *cmap_grid, int ngrid, int grid_spacing)
 {
-    int i, k, nelem;
+    int i, nelem;
 
     cmap_grid->ngrid        = ngrid;
     cmap_grid->grid_spacing = grid_spacing;
@@ -1309,22 +1308,19 @@ static real calc_temp(const gmx_mtop_t *mtop,
                       const t_inputrec *ir,
                       rvec             *v)
 {
-    double                  sum_mv2;
     gmx_mtop_atomloop_all_t aloop;
     t_atom                 *atom;
     int                     a;
-    int                     nrdf, g;
-
-    sum_mv2 = 0;
 
+    double                  sum_mv2 = 0;
     aloop = gmx_mtop_atomloop_all_init(mtop);
     while (gmx_mtop_atomloop_all_next(aloop, &a, &atom))
     {
         sum_mv2 += atom->m*norm2(v[a]);
     }
 
-    nrdf = 0;
-    for (g = 0; g < ir->opts.ngtc; g++)
+    double nrdf = 0;
+    for (int g = 0; g < ir->opts.ngtc; g++)
     {
         nrdf += ir->opts.nrdf[g];
     }
@@ -1349,7 +1345,7 @@ static real get_max_reference_temp(const t_inputrec *ir,
         }
         else
         {
-            ref_t = max(ref_t, ir->opts.ref_t[i]);
+            ref_t = std::max(ref_t, ir->opts.ref_t[i]);
         }
     }
 
@@ -1371,7 +1367,6 @@ static void set_verlet_buffer(const gmx_mtop_t *mtop,
                               matrix            box,
                               warninp_t         wi)
 {
-    int                    i;
     verletbuf_list_setup_t ls;
     real                   rlist_1x1;
     int                    n_nonlin_vsite;
@@ -1397,18 +1392,18 @@ static void set_verlet_buffer(const gmx_mtop_t *mtop,
     }
 
     printf("Calculated rlist for %dx%d atom pair-list as %.3f nm, buffer size %.3f nm\n",
-           1, 1, rlist_1x1, rlist_1x1-max(ir->rvdw, ir->rcoulomb));
+           1, 1, rlist_1x1, rlist_1x1-std::max(ir->rvdw, ir->rcoulomb));
 
     ir->rlistlong = ir->rlist;
     printf("Set rlist, assuming %dx%d atom pair-list, to %.3f nm, buffer size %.3f nm\n",
            ls.cluster_size_i, ls.cluster_size_j,
-           ir->rlist, ir->rlist-max(ir->rvdw, ir->rcoulomb));
+           ir->rlist, ir->rlist-std::max(ir->rvdw, ir->rcoulomb));
 
     printf("Note that mdrun will redetermine rlist based on the actual pair-list setup\n");
 
     if (sqr(ir->rlistlong) >= max_cutoff2(ir->ePBC, box))
     {
-        gmx_fatal(FARGS, "The pair-list cut-off (%g nm) is longer than half the shortest box vector or longer than the smallest box diagonal element (%g nm). Increase the box size or decrease nstlist or increase verlet-buffer-tolerance.", ir->rlistlong, sqrt(max_cutoff2(ir->ePBC, box)));
+        gmx_fatal(FARGS, "The pair-list cut-off (%g nm) is longer than half the shortest box vector or longer than the smallest box diagonal element (%g nm). Increase the box size or decrease nstlist or increase verlet-buffer-tolerance.", ir->rlistlong, std::sqrt(max_cutoff2(ir->ePBC, box)));
     }
 }
 
@@ -1519,26 +1514,21 @@ int gmx_grompp(int argc, char *argv[])
     t_molinfo         *mi, *intermolecular_interactions;
     gpp_atomtype_t     atype;
     t_inputrec        *ir;
-    int                natoms, nvsite, comb, mt;
+    int                nvsite, comb, mt;
     t_params          *plist;
     t_state           *state;
     matrix             box;
-    real               max_spacing, fudgeQQ;
+    real               fudgeQQ;
     double             reppow;
     char               fn[STRLEN], fnB[STRLEN];
     const char        *mdparin;
     int                ntype;
     gmx_bool           bNeedVel, bGenVel;
     gmx_bool           have_atomnumber;
-    int                n12, n13, n14;
-    t_params          *gb_plist = NULL;
-    gmx_genborn_t     *born     = NULL;
     output_env_t       oenv;
     gmx_bool           bVerbose = FALSE;
     warninp_t          wi;
     char               warn_buf[STRLEN];
-    unsigned int       useed;
-    t_atoms            IMDatoms;   /* Atoms to be operated on interactively (IMD) */
 
     t_filenm           fnm[] = {
         { efMDP, NULL,  NULL,        ffREAD  },
@@ -1606,7 +1596,7 @@ int gmx_grompp(int argc, char *argv[])
     if (ir->ld_seed == -1)
     {
         ir->ld_seed = (gmx_int64_t)gmx_rng_make_seed();
-        fprintf(stderr, "Setting the LD random seed to %"GMX_PRId64 "\n", ir->ld_seed);
+        fprintf(stderr, "Setting the LD random seed to %" GMX_PRId64 "\n", ir->ld_seed);
     }
 
     if (ir->expandedvals->lmc_seed == -1)
@@ -1785,7 +1775,7 @@ int gmx_grompp(int argc, char *argv[])
     if (bRenum)
     {
         renum_atype(plist, sys, ir->wall_atomtype, atype, bVerbose);
-        ntype = get_atomtype_ntypes(atype);
+        get_atomtype_ntypes(atype);
     }
 
     if (ir->implicit_solvent != eisNO)
@@ -1865,7 +1855,6 @@ int gmx_grompp(int argc, char *argv[])
     }
     do_index(mdparin, ftp2fn_null(efNDX, NFILE, fnm),
              sys, bVerbose, ir,
-             bGenVel ? state->v : NULL,
              wi);
 
     if (ir->cutoff_scheme == ecutsVERLET && ir->verletbuf_tol > 0 &&
@@ -2012,8 +2001,8 @@ int gmx_grompp(int argc, char *argv[])
             set_warning_line(wi, mdparin, -1);
             warning_error(wi, "Some of the Fourier grid sizes are set, but all of them need to be set.");
         }
-        max_spacing = calc_grid(stdout, box, ir->fourier_spacing,
-                                &(ir->nkx), &(ir->nky), &(ir->nkz));
+        calc_grid(stdout, box, ir->fourier_spacing,
+                  &(ir->nkx), &(ir->nky), &(ir->nkz));
     }
 
     /* MRS: eventually figure out better logic for initializing the fep
index 9dc5254a80f66a4b461b96f2ffe29a3e22f3614f..9e6bcba68690f4299fb674f585d0d28041fc7cea 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_GMXPREPROCESS_GROMPP_H
 #define GMX_GMXPREPROCESS_GROMPP_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 int gmx_grompp(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/gmxpreprocess/h_db.c
rename to src/gromacs/gmxpreprocess/h_db.cpp
index f630ae787608c69c80730c6cd01c4e4ce7aee2e2..7504972d5dd2707e55fdfed77f0a601b317e8bc1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -42,7 +42,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/gmxpreprocess/fflibutil.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/utility/cstringutil.h"
@@ -192,8 +191,11 @@ static void read_h_db_file(const char *hfn, int *nahptr, t_hackblock **ah)
     }
     gmx_ffclose(in);
 
-    /* Sort the list (necessary to be able to use bsearch */
-    qsort(aah, nah, (size_t)sizeof(**ah), compaddh);
+    if (nah > 0)
+    {
+        /* Sort the list (necessary to be able to use bsearch */
+        qsort(aah, nah, (size_t)sizeof(**ah), compaddh);
+    }
 
     /*
        if (debug)
@@ -209,7 +211,6 @@ int read_h_db(const char *ffdir, t_hackblock **ah)
     int    nhdbf, f;
     char **hdbf;
     int    nah;
-    FILE  *fp;
 
     /* Read the hydrogen database file(s).
      * Do not generate an error when no files are found.
index 24f873b6c2e3fb913b269d925e7c479f024c92a7..c8e2df6f044bdfe21e3e2a31225b150c80dd072c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/gmxpreprocess/hackblock.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* functions for the h-database */
 
 void read_ab(char *line, const char *fn, t_hack *ab);
@@ -65,8 +61,4 @@ int compaddh(const void *a, const void *b);
 t_hackblock *search_h_db(int nh, t_hackblock ah[], char *key);
 /* Search for an entry in the database */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 294dcec86c486006856beeae573b874907c00fb9..bdeff0af49485179a0a4bd080570fa2bd6e41bd8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/topology/symtab.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* Used for reading .rtp/.tdb */
 /* ebtsBONDS must be the first, new types can be added to the end */
 /* these *MUST* correspond to the arrays in hackblock.c */
@@ -195,8 +191,4 @@ void dump_hb(FILE *out, int nres, t_hackblock hb[]);
 void init_t_protonate(t_protonate *protonate);
 /* initialize t_protein struct */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 97%
rename from src/gromacs/gmxpreprocess/hizzie.c
rename to src/gromacs/gmxpreprocess/hizzie.cpp
index 0aff84f7a41b04bac8fbf85c3ebeac82ef960f50..b2575850b3912fa1ec7f2a34cf118cbc960d2918 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,6 +40,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/gmxpreprocess/pdb2top.h"
 #include "gromacs/gmxpreprocess/toputil.h"
@@ -176,7 +178,7 @@ static gmx_bool chk_hbonds(int i, t_atoms *pdba, rvec x[],
                                 pdba->resinfo[pdba->atom[i].resind].nr, *pdba->atomname[i],
                                 *pdba->resinfo[pdba->atom[aj].resind].name,
                                 pdba->resinfo[pdba->atom[aj].resind].nr, *pdba->atomname[aj],
-                                sqrt(d2), a);
+                                std::sqrt(d2), a);
                     }
                     hbond[i] = TRUE;
                     bHB      = TRUE;
@@ -213,14 +215,13 @@ void set_histp(t_atoms *pdba, rvec *x, real angle, real dist)
 #define NPD asize(prot_don)
 
     gmx_bool *donor, *acceptor;
-    gmx_bool *hbond, bHaveH = FALSE;
+    gmx_bool *hbond;
     gmx_bool  bHDd, bHEd;
     rvec      xh1, xh2;
     int       natom;
-    int       i, j, nd, na, aj, hisind, his0, type = -1;
+    int       i, j, nd, na, hisind, type = -1;
     int       nd1, ne2, cg, cd2, ce1;
     t_blocka *hb;
-    real      d;
     char     *atomnm;
 
     natom = pdba->nr;
index 92c44f43b5d7fe954a59dc67a78b3cb8c4ae92b2..5bdcb8801c037e0941aedfac80383602b07da8d4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_GMXPREPROCESS_HIZZIE_H
 #define GMX_GMXPREPROCESS_HIZZIE_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void set_histp(t_atoms *pdba, rvec *x, real angle, real distance);
 /* calculate HIStidine protonation state */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 14b92616bcbc83518d77f14f399d1b96f44489fe..b4f77af2b32f1a6bee8332a1ab30182876ee1a6b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -303,7 +303,7 @@ namespace gmx
 namespace
 {
 
-class InsertMolecules : public CommandLineOptionsModuleInterface
+class InsertMolecules : public ICommandLineOptionsModule
 {
     public:
         InsertMolecules()
@@ -318,7 +318,8 @@ class InsertMolecules : public CommandLineOptionsModuleInterface
         {
         }
 
-        virtual void initOptions(Options *options);
+        virtual void initOptions(Options                           *options,
+                                 ICommandLineOptionsModuleSettings *settings);
         virtual void optionsFinished(Options *options);
 
         virtual int run();
@@ -339,7 +340,8 @@ class InsertMolecules : public CommandLineOptionsModuleInterface
         int         enumRot_;
 };
 
-void InsertMolecules::initOptions(Options *options)
+void InsertMolecules::initOptions(Options                           *options,
+                                  ICommandLineOptionsModuleSettings *settings)
 {
     const char *const desc[] = {
         "[THISMODULE] inserts [TT]-nmol[tt] copies of the system specified in",
@@ -376,7 +378,7 @@ void InsertMolecules::initOptions(Options *options)
         "[TT]-try[tt] and [TT]-rot[tt] work as in the default mode (see above)."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     // TODO: Replace use of legacyType.
     options->addOption(FileNameOption("f")
@@ -541,7 +543,7 @@ int InsertMolecules::run()
 const char InsertMoleculesInfo::name[]             = "insert-molecules";
 const char InsertMoleculesInfo::shortDescription[] =
     "Insert molecules into existing vacancies";
-CommandLineOptionsModuleInterface *InsertMoleculesInfo::create()
+ICommandLineOptionsModule *InsertMoleculesInfo::create()
 {
     return new InsertMolecules();
 }
index fd1552dfcd873786add9101520e40ea402428ef1..dafa07fae746f6697de6eef336d106a1f0cb9d4e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 namespace gmx
 {
 
-class CommandLineOptionsModuleInterface;
+class ICommandLineOptionsModule;
 
 class InsertMoleculesInfo
 {
     public:
         static const char name[];
         static const char shortDescription[];
-        static CommandLineOptionsModuleInterface *create();
+        static ICommandLineOptionsModule *create();
 };
 
 } // namespace gmx
similarity index 97%
rename from src/gromacs/gmxpreprocess/nm2type.c
rename to src/gromacs/gmxpreprocess/nm2type.cpp
index 41882302acdcf05967b850243e6ed6fdc053f8ad..dba4da9f9c9c47300b43aa86ad3a288f0956a4f6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -41,6 +41,8 @@
 
 #include <string.h>
 
+#include <algorithm>
+
 #include "gromacs/fileio/confio.h"
 #include "gromacs/gmxpreprocess/fflibutil.h"
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
@@ -55,6 +57,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 static void rd_nm2type_file(const char *fn, int *nnm, t_nm2type **nmp)
@@ -65,7 +68,7 @@ static void rd_nm2type_file(const char *fn, int *nnm, t_nm2type **nmp)
     char          format[128], f1[128];
     char          buf[1024], elem[16], type[16], nbbuf[16], **newbuf;
     int           i, nb, nnnm, line = 1;
-    double        qq, mm, *blen;
+    double        qq, mm;
     t_nm2type    *nm2t = NULL;
 
     fp = fflib_open(fn);
@@ -200,7 +203,7 @@ int nm2type(int nnm, t_nm2type nm2t[], struct t_symtab *tab, t_atoms *atoms,
     int      cur = 0;
 #define prev (1-cur)
     int      i, j, k, m, n, nresolved, nb, maxbond, ai, aj, best, im, nqual[2][ematchNR];
-    int     *bbb, *n_mask, *m_mask, **match, **quality;
+    int     *bbb, *n_mask, *m_mask, **match;
     char    *aname_i, *aname_m, *aname_n, *type;
     double   qq, mm;
     t_param *param;
@@ -209,7 +212,7 @@ int nm2type(int nnm, t_nm2type nm2t[], struct t_symtab *tab, t_atoms *atoms,
     maxbond = 0;
     for (i = 0; (i < atoms->nr); i++)
     {
-        maxbond = max(maxbond, nbonds[i]);
+        maxbond = std::max(maxbond, nbonds[i]);
     }
     if (debug)
     {
index 4f8505ed04bf7817835db8ab72f0a51da5bc164a..e86af8228d1382ea915687baf13d1be1f40a9479 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/topology/atoms.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 typedef struct {
     char    *elem, *type;
     double   q, m;
@@ -69,8 +65,4 @@ int nm2type(int nnm, t_nm2type nm2t[], struct t_symtab *tab, t_atoms *atoms,
  * with help of the bond list
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/pdb2gmx.c
rename to src/gromacs/gmxpreprocess/pdb2gmx.cpp
index 242aaf65e08ec587661d8acc684dcaaccd5348cb..f025990f80936e4d56f9c1cec60140126cfd0a16 100644 (file)
@@ -73,6 +73,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/dir_separator.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #define RTP_MAXCHAR 5
@@ -322,7 +323,7 @@ static void rename_resrtp(t_atoms *pdba, int nterpairs, int *r_start, int *r_end
                           int nrr, rtprename_t *rr, t_symtab *symtab,
                           gmx_bool bVerbose)
 {
-    int      r, i, j;
+    int      r, j;
     gmx_bool bStart, bEnd;
     char    *nn;
     gmx_bool bFFRTPTERRNM;
@@ -703,7 +704,6 @@ static void sort_pdbatoms(t_restp restp[],
     rvec       **xnew;
     int          i, j;
     t_restp     *rptr;
-    t_hackblock *hbr;
     t_pdbindex  *pdbi;
     atom_id     *a;
     char        *atomnm;
@@ -834,7 +834,10 @@ static int remove_duplicate_atoms(t_atoms *pdba, rvec x[], gmx_bool bVerbose)
             {
                 pdba->atom[j]     = pdba->atom[j+1];
                 pdba->atomname[j] = pdba->atomname[j+1];
-                pdba->pdbinfo[j]  = pdba->pdbinfo[j+1];
+                if (pdba->pdbinfo)
+                {
+                    pdba->pdbinfo[j]  = pdba->pdbinfo[j+1];
+                }
                 copy_rvec(x[j+1], x[j]);
             }
             srenew(pdba->atom,     pdba->nr);
@@ -921,42 +924,18 @@ void find_nc_ter(t_atoms *pdba, int r0, int r1, int *r_start, int *r_end,
 }
 
 
-static void
-modify_chain_numbers(t_atoms *       pdba,
-                     const char *    chainsep)
+enum SplittingType
 {
-    int           i;
-    char          old_prev_chainid;
-    char          old_this_chainid;
-    int           old_prev_chainnum;
-    int           old_this_chainnum;
-    t_resinfo    *ri;
-    char          select[STRLEN];
-    int           new_chainnum;
-    int           this_atomnum;
-    int           prev_atomnum;
-    const char *  prev_atomname;
-    const char *  this_atomname;
-    const char *  prev_resname;
-    const char *  this_resname;
-    int           prev_resnum;
-    int           this_resnum;
-    char          prev_chainid;
-    char          this_chainid;
-    int           prev_chainnumber;
-    int           this_chainnumber;
-
-    enum
-    {
-        SPLIT_ID_OR_TER,
-        SPLIT_ID_AND_TER,
-        SPLIT_ID_ONLY,
-        SPLIT_TER_ONLY,
-        SPLIT_INTERACTIVE
-    }
-    splitting;
-
-    splitting = SPLIT_TER_ONLY; /* keep compiler happy */
+    SPLIT_ID_OR_TER,
+    SPLIT_ID_AND_TER,
+    SPLIT_ID_ONLY,
+    SPLIT_TER_ONLY,
+    SPLIT_INTERACTIVE
+};
+
+static SplittingType getSplittingType(const char *chainsep)
+{
+    SplittingType splitting = SPLIT_TER_ONLY; /* keep compiler happy */
 
     /* Be a bit flexible to catch typos */
     if (!strncmp(chainsep, "id_o", 4))
@@ -990,6 +969,33 @@ modify_chain_numbers(t_atoms *       pdba,
     {
         gmx_fatal(FARGS, "Unidentified setting for chain separation: %s\n", chainsep);
     }
+    return splitting;
+}
+
+static void
+modify_chain_numbers(t_atoms *       pdba,
+                     const char *    chainsep)
+{
+    int           i;
+    char          old_prev_chainid;
+    char          old_this_chainid;
+    int           old_prev_chainnum;
+    int           old_this_chainnum;
+    t_resinfo    *ri;
+    char          select[STRLEN];
+    int           new_chainnum;
+    int           this_atomnum;
+    int           prev_atomnum;
+    const char *  prev_atomname;
+    const char *  this_atomname;
+    const char *  prev_resname;
+    const char *  this_resname;
+    int           prev_resnum;
+    int           this_resnum;
+    char          prev_chainid;
+    char          this_chainid;
+
+    SplittingType splitting = getSplittingType(chainsep);
 
     /* The default chain enumeration is based on TER records only, which is reflected in chainnum below */
 
@@ -1002,7 +1008,6 @@ modify_chain_numbers(t_atoms *       pdba,
     this_resname        = NULL;
     this_resnum         = -1;
     this_chainid        = '?';
-    this_chainnumber    = -1;
 
     for (i = 0; i < pdba->nres; i++)
     {
@@ -1015,14 +1020,12 @@ modify_chain_numbers(t_atoms *       pdba,
         prev_resname       = this_resname;
         prev_resnum        = this_resnum;
         prev_chainid       = this_chainid;
-        prev_chainnumber   = this_chainnumber;
 
         this_atomname      = *(pdba->atomname[i]);
         this_atomnum       = (pdba->pdbinfo != NULL) ? pdba->pdbinfo[i].atomnr : i+1;
         this_resname       = *ri->name;
         this_resnum        = ri->nr;
         this_chainid       = ri->chainid;
-        this_chainnumber   = ri->chainnum;
 
         switch (splitting)
         {
@@ -1257,17 +1260,16 @@ int gmx_pdb2gmx(int argc, char *argv[])
     const char       *watres;
     int               nrtpf;
     char            **rtpf;
-    char              rtp[STRLEN];
     int               nrrn;
     char            **rrn;
-    int               nrtprename, naa;
+    int               nrtprename;
     rtprename_t      *rtprename = NULL;
     int               nah, nNtdb, nCtdb, ntdblist;
     t_hackblock      *ntdb, *ctdb, **tdblist;
     int               nssbonds;
     t_ssbond         *ssbonds;
     rvec             *pdbx, *x;
-    gmx_bool          bVsites = FALSE, bWat, bPrevWat = FALSE, bITP, bVsiteAromatics = FALSE, bCheckMerge;
+    gmx_bool          bVsites = FALSE, bWat, bPrevWat = FALSE, bITP, bVsiteAromatics = FALSE;
     real              mHmult  = 0;
     t_hackblock      *hb_chain;
     t_restp          *restp_chain;
@@ -1441,6 +1443,9 @@ int gmx_pdb2gmx(int argc, char *argv[])
         mHmult = 1.0;
     }
 
+    /* parse_common_args ensures vsitestr has been selected, but
+       clang-static-analyzer needs clues to know that */
+    GMX_ASSERT(vsitestr[0], "-vsite default wasn't processed correctly");
     switch (vsitestr[0][0])
     {
         case 'n': /* none */
@@ -1481,7 +1486,6 @@ int gmx_pdb2gmx(int argc, char *argv[])
     sfree(rrn);
 
     /* Add all alternative names from the residue renaming database to the list of recognized amino/nucleic acids. */
-    naa = 0;
     for (i = 0; i < nrtprename; i++)
     {
         rc = gmx_residuetype_get_type(rt, rtprename[i].gmx, &p_restype);
@@ -1523,8 +1527,6 @@ int gmx_pdb2gmx(int argc, char *argv[])
     }
 
     printf("Analyzing pdb file\n");
-    nch         = 0;
-    maxch       = 0;
     nwaterchain = 0;
 
     modify_chain_numbers(&pdba_all, chainsep[0]);
@@ -1541,13 +1543,17 @@ int gmx_pdb2gmx(int argc, char *argv[])
     /* Keep the compiler happy */
     prev_chainstart     = 0;
 
-    pdb_ch = NULL;
+    nch   = 0;
+    maxch = 16;
+    snew(pdb_ch, maxch);
 
     bMerged = FALSE;
     for (i = 0; (i < natom); i++)
     {
         ri = &pdba_all.resinfo[pdba_all.atom[i].resind];
 
+        /* TODO this should live in a helper object, and consolidate
+           that with code in modify_chain_numbers */
         prev_atomname      = this_atomname;
         prev_atomnum       = this_atomnum;
         prev_resname       = this_resname;
@@ -1623,6 +1629,7 @@ int gmx_pdb2gmx(int argc, char *argv[])
                                ri->chainid);
                     }
                 }
+                // TODO This is too convoluted. Use a std::vector
                 if (nch == maxch)
                 {
                     maxch += 16;
@@ -1781,7 +1788,6 @@ int gmx_pdb2gmx(int argc, char *argv[])
     nmol  = 0;
     incls = NULL;
     mols  = NULL;
-    nres  = 0;
     for (chain = 0; (chain < nch); chain++)
     {
         cc = &(chains[chain]);
@@ -1954,7 +1960,7 @@ int gmx_pdb2gmx(int argc, char *argv[])
             block = new_blocka();
             snew(gnames, 1);
             sort_pdbatoms(restp_chain, natom, &pdba, &x, block, &gnames);
-            natom = remove_duplicate_atoms(pdba, x, bVerbose);
+            remove_duplicate_atoms(pdba, x, bVerbose);
             if (ftp2bSet(efNDX, NFILE, fnm))
             {
                 if (bRemoveH)
index d85c5bbae83c5d7bab54d8598dd8c24975678c15..b8da74c90b5bb2c69ab7cb1b04cf6def55e24e0e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_GMXPREPROCESS_PDB2GMX_H
 #define GMX_GMXPREPROCESS_PDB2GMX_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 int gmx_pdb2gmx(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 920c3a38f9db69948ce9a2ff4d7dc53ef8800c4a..00529571beae6650627eda67db453ba6a6b291bd 100644 (file)
 #include "pdb2top.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
 #include <algorithm>
 #include <string>
 #include <vector>
@@ -70,7 +71,6 @@
 #include "gromacs/utility/dir_separator.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/path.h"
 #include "gromacs/utility/programcontext.h"
@@ -801,12 +801,12 @@ static void at2bonds(t_params *psb, t_hackblock *hb,
 
                 {
                     fprintf(stderr, "Warning: Long Bond (%d-%d = %g nm)\n",
-                            ai+1, aj+1, sqrt(dist2));
+                            ai+1, aj+1, std::sqrt(dist2));
                 }
                 else if (dist2 < short_bond_dist2)
                 {
                     fprintf(stderr, "Warning: Short Bond (%d-%d = %g nm)\n",
-                            ai+1, aj+1, sqrt(dist2));
+                            ai+1, aj+1, std::sqrt(dist2));
                 }
                 add_param(psb, ai, aj, NULL, hb[resind].rb[ebtsBONDS].b[j].s);
             }
index cfbc800c879048746709698f1a4deac9228f09b8..a5e468106c0c97e3998bcf4f2c69f81343421ee9 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/toputil.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
 /* this *MUST* correspond to array in pdb2top.c */
 enum {
     ehisA, ehisB, ehisH, ehis1, ehisNR
@@ -127,8 +122,4 @@ void pdb2top(FILE *top_file, char *posre_fn, char *molname,
 
 void print_sums(t_atoms *atoms, gmx_bool bSystem);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index b9ebce727a120ee843584bee155085d0c1b28a07..1c5b46d2ca1e02d9b3a00eb811adeafe51a6c8f8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
 /* Search an atom in array of pointers to strings, starting from start
  * if type starts with '-' then searches backwards from start.
  * bondtype is only used for printing the error/warning string,
@@ -67,8 +62,4 @@ search_res_atom(const char *type, int resind,
 void set_at(t_atom *at, real m, real q, int type, int resind);
 
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 5ced52b98b35a37a60d735ca4ca578b153fff953..7c9f6a27fd1d6045deb8ec8a2c4f175ba1473d55 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/legacyheaders/types/simple.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 struct gmx_atomprop;
 struct t_atoms;
 
@@ -61,8 +57,4 @@ real *makeExclusionDistances(const struct t_atoms *a, struct gmx_atomprop *aps,
 char *readConformation(const char *confin, struct t_atoms *atoms, rvec **x, rvec **v,
                        int *ePBC, matrix box, const char *statusTitle);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/readadress.c
rename to src/gromacs/gmxpreprocess/readadress.cpp
index a95374cda85b3e7d873a8804f18ac396778b4570..16f75891ec2e18fb3695334753555e468f0be249 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2009 Christoph Junghans, Brad Lambeth.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
similarity index 98%
rename from src/gromacs/gmxpreprocess/readir.c
rename to src/gromacs/gmxpreprocess/readir.cpp
index 52f408f21d1a314edfeb62accce09a99b67a26ce..2bbed056ddded6898b6b3548f391014dbf5c4eda 100644 (file)
 #include <limits.h>
 #include <stdlib.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/gmxpreprocess/toputil.h"
 #include "gromacs/legacyheaders/chargegroup.h"
 #include "gromacs/legacyheaders/inputrec.h"
@@ -155,7 +159,7 @@ static void GetSimTemps(int ntemps, t_simtemp *simtemp, double *temperature_lamb
         }
         else if (simtemp->eSimTempScale == esimtempGEOMETRIC)  /* should give roughly equal acceptance for constant heat capacity . . . */
         {
-            simtemp->temperatures[i] = simtemp->simtemp_low * pow(simtemp->simtemp_high/simtemp->simtemp_low, (1.0*i)/(ntemps-1));
+            simtemp->temperatures[i] = simtemp->simtemp_low * std::pow(simtemp->simtemp_high/simtemp->simtemp_low, static_cast<real>((1.0*i)/(ntemps-1)));
         }
         else if (simtemp->eSimTempScale == esimtempEXPONENTIAL)
         {
@@ -172,7 +176,7 @@ static void GetSimTemps(int ntemps, t_simtemp *simtemp, double *temperature_lamb
 
 
 
-static void _low_check(gmx_bool b, char *s, warninp_t wi)
+static void _low_check(gmx_bool b, const char *s, warninp_t wi)
 {
     if (b)
     {
@@ -246,10 +250,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
 #define CHECK(b) _low_check(b, err_buf, wi)
     char        err_buf[256], warn_buf[STRLEN];
     int         i, j;
-    int         ns_type  = 0;
-    real        dt_coupl = 0;
     real        dt_pcoupl;
-    int         nstcmin;
     t_lambda   *fep    = ir->fepvals;
     t_expanded *expand = ir->expandedvals;
 
@@ -386,7 +387,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
             warning_note(wi, "With Verlet lists the optimal nstlist is >= 10, with GPUs >= 20. Note that with the Verlet scheme, nstlist has no effect on the accuracy of your simulation.");
         }
 
-        rc_max = max(ir->rvdw, ir->rcoulomb);
+        rc_max = std::max(ir->rvdw, ir->rcoulomb);
 
         if (ir->verletbuf_tol <= 0)
         {
@@ -739,7 +740,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
             sigma  = 0.34;
             /* Maximum estimate for A and B charges equal with lambda power 1 */
             lambda = 0.5;
-            r_sc   = pow(lambda*fep->sc_alpha*pow(sigma/ir->rcoulomb, fep->sc_r_power) + 1.0, 1.0/fep->sc_r_power);
+            r_sc   = std::pow(lambda*fep->sc_alpha*std::pow(sigma/ir->rcoulomb, fep->sc_r_power) + 1.0, 1.0/fep->sc_r_power);
             sprintf(warn_buf, "With PME there is a minor soft core effect present at the cut-off, proportional to (LJsigma/rcoulomb)^%g. This could have a minor effect on energy conservation, but usually other effects dominate. With a common sigma value of %g nm the fraction of the particle-particle potential at the cut-off at lambda=%g is around %.1e, while ewald-rtol is %.1e.",
                     fep->sc_r_power,
                     sigma, lambda, r_sc - 1.0, ir->ewald_rtol);
@@ -775,7 +776,6 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
     if ((ir->bSimTemp) || (ir->efep == efepEXPANDED))
     {
         fep    = ir->fepvals;
-        expand = ir->expandedvals;
 
         /* checking equilibration of weights inputs for validity */
 
@@ -848,9 +848,11 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
         sprintf(err_buf, "If there is no temperature control, and lmc-mcmove!= 'no',mc_temperature must be set to a positive number");
         if (expand->nstTij > 0)
         {
+            sprintf(err_buf, "nstlog must be non-zero");
+            CHECK(ir->nstlog != 0);
             sprintf(err_buf, "nst-transition-matrix (%d) must be an integer multiple of nstlog (%d)",
                     expand->nstTij, ir->nstlog);
-            CHECK((mod(expand->nstTij, ir->nstlog) != 0));
+            CHECK((expand->nstTij % ir->nstlog) != 0);
         }
     }
 
@@ -1651,7 +1653,6 @@ static void do_fep_params(t_inputrec *ir, char fep_lambda[][STRLEN], char weight
         }
     }
 
-    expand = ir->expandedvals;
     /* now read in the weights */
     parse_n_real(weights, &nweights, &(expand->init_lambda_weights));
     if (nweights == 0)
@@ -1758,7 +1759,7 @@ static void add_wall_energrps(gmx_groups_t *groups, int nwall, t_symtab *symtab)
 void read_expandedparams(int *ninp_p, t_inpfile **inp_p,
                          t_expanded *expand, warninp_t wi)
 {
-    int        ninp, nerror = 0;
+    int        ninp;
     t_inpfile *inp;
 
     ninp   = *ninp_p;
@@ -2485,9 +2486,9 @@ void get_ir(const char *mdparin, const char *mdparout,
     {
         dumdub[0][i] = 0;
     }
-    m = sscanf(is->deform, "%lf %lf %lf %lf %lf %lf",
-               &(dumdub[0][0]), &(dumdub[0][1]), &(dumdub[0][2]),
-               &(dumdub[0][3]), &(dumdub[0][4]), &(dumdub[0][5]));
+    sscanf(is->deform, "%lf %lf %lf %lf %lf %lf",
+           &(dumdub[0][0]), &(dumdub[0][1]), &(dumdub[0][2]),
+           &(dumdub[0][3]), &(dumdub[0][4]), &(dumdub[0][5]));
     for (i = 0; i < 3; i++)
     {
         ir->deform[i][i] = dumdub[0][i];
@@ -2843,8 +2844,8 @@ static void calc_nrdf(gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
                         {
                             imin = 2;
                         }
-                        imin       = min(imin, nrdf2[ai]);
-                        jmin       = min(jmin, nrdf2[aj]);
+                        imin       = std::min(imin, nrdf2[ai]);
+                        jmin       = std::min(jmin, nrdf2[aj]);
                         nrdf2[ai] -= imin;
                         nrdf2[aj] -= jmin;
                         nrdf_tc [ggrpnr(groups, egcTC, ai)]  -= 0.5*imin;
@@ -2863,7 +2864,7 @@ static void calc_nrdf(gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
                 for (j = 0; j < 3; j++)
                 {
                     ai         = as + ia[1+j];
-                    imin       = min(2, nrdf2[ai]);
+                    imin       = std::min(2, nrdf2[ai]);
                     nrdf2[ai] -= imin;
                     nrdf_tc [ggrpnr(groups, egcTC, ai)]  -= 0.5*imin;
                     nrdf_vcm[ggrpnr(groups, egcVCM, ai)] -= 0.5*imin;
@@ -2935,7 +2936,6 @@ static void calc_nrdf(gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
                 n_sub = 6;
                 break;
             default:
-                n_sub = 0;
                 gmx_incons("Checking comm_mode");
         }
 
@@ -3208,7 +3208,7 @@ void make_IMD_group(t_IMD *IMDgroup, char *IMDgname, t_blocka *grps, char **gnam
 void do_index(const char* mdparin, const char *ndx,
               gmx_mtop_t *mtop,
               gmx_bool bVerbose,
-              t_inputrec *ir, rvec *v,
+              t_inputrec *ir,
               warninp_t wi)
 {
     t_blocka     *grps;
@@ -3223,10 +3223,8 @@ void do_index(const char* mdparin, const char *ndx,
     int           nacg, nfreeze, nfrdim, nenergy, nvcm, nuser;
     char         *ptr1[MAXPTR], *ptr2[MAXPTR], *ptr3[MAXPTR];
     int           i, j, k, restnm;
-    real          SAtime;
     gmx_bool      bExcl, bTable, bSetTCpar, bAnneal, bRest;
-    int           nQMmethod, nQMbasis, nQMcharge, nQMmult, nbSH, nCASorb, nCASelec,
-                  nSAon, nSAoff, nSAsteps, nQMg, nbOPT, nbTS;
+    int           nQMmethod, nQMbasis, nQMg;
     char          warn_buf[STRLEN];
 
     if (bVerbose)
@@ -3312,7 +3310,7 @@ void do_index(const char* mdparin, const char *ndx,
 
             if (ir->opts.tau_t[i] >= 0)
             {
-                tau_min = min(tau_min, ir->opts.tau_t[i]);
+                tau_min = std::min(tau_min, ir->opts.tau_t[i]);
             }
         }
         if (ir->etc != etcNO && ir->nsttcouple == -1)
@@ -3330,7 +3328,7 @@ void do_index(const char* mdparin, const char *ndx,
             {
                 if (ir->nstpcouple != ir->nsttcouple)
                 {
-                    int mincouple = min(ir->nstpcouple, ir->nsttcouple);
+                    int mincouple = std::min(ir->nstpcouple, ir->nsttcouple);
                     ir->nstpcouple = ir->nsttcouple = mincouple;
                     sprintf(warn_buf, "for current Trotter decomposition methods with vv, nsttcouple and nstpcouple must be equal.  Both have been reset to min(nsttcouple,nstpcouple) = %d", mincouple);
                     warning_note(wi, warn_buf);
@@ -3623,30 +3621,6 @@ void do_index(const char* mdparin, const char *ndx,
     /* Now we have filled the freeze struct, so we can calculate NRDF */
     calc_nrdf(mtop, ir, gnames);
 
-    if (v && NULL)
-    {
-        real fac, ntot = 0;
-
-        /* Must check per group! */
-        for (i = 0; (i < ir->opts.ngtc); i++)
-        {
-            ntot += ir->opts.nrdf[i];
-        }
-        if (ntot != (DIM*natoms))
-        {
-            fac = sqrt(ntot/(DIM*natoms));
-            if (bVerbose)
-            {
-                fprintf(stderr, "Scaling velocities by a factor of %.3f to account for constraints\n"
-                        "and removal of center of mass motion\n", fac);
-            }
-            for (i = 0; (i < natoms); i++)
-            {
-                svmul(fac, v[i], v[i]);
-            }
-        }
-    }
-
     nuser = str_nelem(is->user1, MAXPTR, ptr1);
     do_numbering(natoms, groups, nuser, ptr1, grps, gnames, egcUser1,
                  restnm, egrptpALL_GENREST, bVerbose, wi);
@@ -3687,9 +3661,9 @@ void do_index(const char* mdparin, const char *ndx,
                                                eQMbasis_names);
 
     }
-    nQMmult   = str_nelem(is->QMmult, MAXPTR, ptr1);
-    nQMcharge = str_nelem(is->QMcharge, MAXPTR, ptr2);
-    nbSH      = str_nelem(is->bSH, MAXPTR, ptr3);
+    str_nelem(is->QMmult, MAXPTR, ptr1);
+    str_nelem(is->QMcharge, MAXPTR, ptr2);
+    str_nelem(is->bSH, MAXPTR, ptr3);
     snew(ir->opts.QMmult, nr);
     snew(ir->opts.QMcharge, nr);
     snew(ir->opts.bSH, nr);
@@ -3701,8 +3675,8 @@ void do_index(const char* mdparin, const char *ndx,
         ir->opts.bSH[i]      = (gmx_strncasecmp(ptr3[i], "Y", 1) == 0);
     }
 
-    nCASelec  = str_nelem(is->CASelectrons, MAXPTR, ptr1);
-    nCASorb   = str_nelem(is->CASorbitals, MAXPTR, ptr2);
+    str_nelem(is->CASelectrons, MAXPTR, ptr1);
+    str_nelem(is->CASorbitals, MAXPTR, ptr2);
     snew(ir->opts.CASelectrons, nr);
     snew(ir->opts.CASorbitals, nr);
     for (i = 0; i < nr; i++)
@@ -3712,8 +3686,8 @@ void do_index(const char* mdparin, const char *ndx,
     }
     /* special optimization options */
 
-    nbOPT = str_nelem(is->bOPT, MAXPTR, ptr1);
-    nbTS  = str_nelem(is->bTS, MAXPTR, ptr2);
+    str_nelem(is->bOPT, MAXPTR, ptr1);
+    str_nelem(is->bTS, MAXPTR, ptr2);
     snew(ir->opts.bOPT, nr);
     snew(ir->opts.bTS, nr);
     for (i = 0; i < nr; i++)
@@ -3721,9 +3695,9 @@ void do_index(const char* mdparin, const char *ndx,
         ir->opts.bOPT[i] = (gmx_strncasecmp(ptr1[i], "Y", 1) == 0);
         ir->opts.bTS[i]  = (gmx_strncasecmp(ptr2[i], "Y", 1) == 0);
     }
-    nSAon     = str_nelem(is->SAon, MAXPTR, ptr1);
-    nSAoff    = str_nelem(is->SAoff, MAXPTR, ptr2);
-    nSAsteps  = str_nelem(is->SAsteps, MAXPTR, ptr3);
+    str_nelem(is->SAon, MAXPTR, ptr1);
+    str_nelem(is->SAoff, MAXPTR, ptr2);
+    str_nelem(is->SAsteps, MAXPTR, ptr3);
     snew(ir->opts.SAon, nr);
     snew(ir->opts.SAoff, nr);
     snew(ir->opts.SAsteps, nr);
@@ -3929,10 +3903,9 @@ check_combination_rule_differences(const gmx_mtop_t *mtop, int state,
                                    gmx_bool *bC6ParametersWorkWithLBRules,
                                    gmx_bool *bLBRulesPossible)
 {
-    int           ntypes, tpi, tpj, thisLBdiff, thisgeomdiff;
+    int           ntypes, tpi, tpj;
     int          *typecount;
     real          tol;
-    double        geometricdiff, LBdiff;
     double        c6i, c6j, c12i, c12j;
     double        c6, c6_geometric, c6_LB;
     double        sigmai, sigmaj, epsi, epsj;
@@ -3955,11 +3928,9 @@ check_combination_rule_differences(const gmx_mtop_t *mtop, int state,
     *bC6ParametersWorkWithLBRules         = TRUE;
     *bC6ParametersWorkWithGeometricRules  = TRUE;
     bCanDoLBRules                         = TRUE;
-    bCanDoGeometricRules                  = TRUE;
     ntypes                                = mtop->ffparams.atnr;
     snew(typecount, ntypes);
     gmx_mtop_count_atomtypes(mtop, state, typecount);
-    geometricdiff           = LBdiff = 0.0;
     *bLBRulesPossible       = TRUE;
     for (tpi = 0; tpi < ntypes; ++tpi)
     {
@@ -3970,16 +3941,16 @@ check_combination_rule_differences(const gmx_mtop_t *mtop, int state,
             c6j          = mtop->ffparams.iparams[(ntypes + 1) * tpj].lj.c6;
             c12j         = mtop->ffparams.iparams[(ntypes + 1) * tpj].lj.c12;
             c6           = mtop->ffparams.iparams[ntypes * tpi + tpj].lj.c6;
-            c6_geometric = sqrt(c6i * c6j);
+            c6_geometric = std::sqrt(c6i * c6j);
             if (!gmx_numzero(c6_geometric))
             {
                 if (!gmx_numzero(c12i) && !gmx_numzero(c12j))
                 {
-                    sigmai   = pow(c12i / c6i, 1.0/6.0);
-                    sigmaj   = pow(c12j / c6j, 1.0/6.0);
+                    sigmai   = std::pow(c12i / c6i, 1.0/6.0);
+                    sigmaj   = std::pow(c12j / c6j, 1.0/6.0);
                     epsi     = c6i * c6i /(4.0 * c12i);
                     epsj     = c6j * c6j /(4.0 * c12j);
-                    c6_LB    = 4.0 * pow(epsi * epsj, 1.0/2.0) * pow(0.5 * (sigmai + sigmaj), 6);
+                    c6_LB    = 4.0 * std::pow(epsi * epsj, 1.0/2.0) * std::pow(0.5 * (sigmai + sigmaj), 6);
                 }
                 else
                 {
@@ -4009,7 +3980,6 @@ static void
 check_combination_rules(const t_inputrec *ir, const gmx_mtop_t *mtop,
                         warninp_t wi)
 {
-    char     err_buf[256];
     gmx_bool bLBRulesPossible, bC6ParametersWorkWithGeometricRules, bC6ParametersWorkWithLBRules;
 
     check_combination_rule_differences(mtop, 0,
@@ -4055,9 +4025,9 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
                   warninp_t wi)
 {
     char                      err_buf[STRLEN];
-    int                       i, m, c, nmol, npct;
+    int                       i, m, c, nmol;
     gmx_bool                  bCharge, bAcc;
-    real                      gdt_max, *mgrp, mt;
+    real                     *mgrp, mt;
     rvec                      acc;
     gmx_mtop_atomloop_block_t aloopb;
     gmx_mtop_atomloop_all_t   aloop;
@@ -4088,8 +4058,8 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
         tau = 0;
         for (i = 0; i < ir->opts.ngtc; i++)
         {
-            T   = max(T, ir->opts.ref_t[i]);
-            tau = max(tau, ir->opts.tau_t[i]);
+            T   = std::max(T, ir->opts.ref_t[i]);
+            tau = std::max(tau, ir->opts.tau_t[i]);
         }
         if (T > 0)
         {
@@ -4411,7 +4381,7 @@ void double_check(t_inputrec *ir, matrix box,
         }
         else
         {
-            min_size = min(box[XX][XX], min(box[YY][YY], box[ZZ][ZZ]));
+            min_size = std::min(box[XX][XX], std::min(box[YY][YY], box[ZZ][ZZ]));
             if (2*ir->rlistlong >= min_size)
             {
                 sprintf(warn_buf, "ERROR: One of the box lengths is smaller than twice the cut-off length. Increase the box size or decrease rlist.");
@@ -4453,7 +4423,7 @@ void check_chargegroup_radii(const gmx_mtop_t *mtop, const t_inputrec *ir,
             sprintf(warn_buf,
                     "The sum of the two largest charge group radii (%f) "
                     "is larger than rlist (%f)\n",
-                    max(rvdw1+rvdw2, rcoul1+rcoul2), ir->rlist);
+                    std::max(rvdw1+rvdw2, rcoul1+rcoul2), ir->rlist);
             warning(wi, warn_buf);
         }
         else
index ea76d63004759091f6689f6d17237759bceca28f..924681e895f8c3a94959ba6bbeb857577862a430 100644 (file)
 #include "gromacs/legacyheaders/readinp.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 enum {
     eshNONE, eshHBONDS, eshALLBONDS, eshHANGLES, eshALLANGLES, eshNR
 };
@@ -117,11 +113,8 @@ void do_index(const char* mdparin,
               gmx_mtop_t *mtop,
               gmx_bool    bVerbose,
               t_inputrec *ir,
-              rvec       *v,
               warninp_t   wi);
 /* Read the index file and assign grp numbers to atoms.
- * If v is not NULL, the velocities will be scaled to the correct number
- * of degrees of freedom.
  */
 
 /* Routines In readpull.c */
@@ -164,8 +157,4 @@ void make_rotation_groups(t_rot *rot, char **rotgnames,
 void set_reference_positions(t_rot *rot, rvec *x, matrix box,
                              const char *fn, gmx_bool bSet, warninp_t wi);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/readpull.c
rename to src/gromacs/gmxpreprocess/readpull.cpp
index f2fb2d220309a6e6e44b9fa8d471b588f773cf1b..665c93586b18a848f2d9f2b3a544f47ca2d25483 100644 (file)
@@ -68,7 +68,7 @@ static void init_pull_group(t_pull_group *pg,
                             const char   *wbuf)
 {
     double d;
-    int    n, m;
+    int    n;
 
     pg->nweight = 0;
     while (sscanf(wbuf, "%lf %n", &d, &n) == 1)
@@ -84,9 +84,8 @@ static void init_pull_group(t_pull_group *pg,
 
 static void process_pull_dim(char *dim_buf, ivec dim)
 {
-    int           ndim, d, nchar, c;
+    int           ndim, d, nchar;
     char         *ptr, pulldim1[STRLEN];
-    t_pull_coord *pcrd;
 
     ptr  = dim_buf;
     ndim = 0;
@@ -189,13 +188,11 @@ char **read_pullparams(int *ninp_p, t_inpfile **inp_p,
                        pull_params_t *pull,
                        warninp_t wi)
 {
-    int           ninp, i, nchar, nscan, m, idum;
+    int           ninp, i, nscan, idum;
     t_inpfile    *inp;
     const char   *tmp;
     char        **grpbuf;
-    char          dummy[STRLEN], buf[STRLEN], groups[STRLEN], dim_buf[STRLEN];
-    char          init[STRLEN];
-    const char   *init_def1 = "0.0", *init_def3 = "0.0 0.0 0.0";
+    char          buf[STRLEN], groups[STRLEN], dim_buf[STRLEN];
     char          wbuf[STRLEN], origin_buf[STRLEN], vec_buf[STRLEN];
 
     t_pull_group *pgrp;
similarity index 93%
rename from src/gromacs/gmxpreprocess/readrot.c
rename to src/gromacs/gmxpreprocess/readrot.cpp
index 5d9715f60deebf0169695e9aee0b0b177e874c9f..f663e953037c5ebb2fd3af115dfd852a2ad5e840 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  */
 #include "gmxpre.h"
 
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/gmxpreprocess/readir.h"
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
-static char *RotStr = {"Enforced rotation:"};
+static const char *RotStr = "Enforced rotation:";
 
 
 static char s_vec[STRLEN];
@@ -238,12 +239,12 @@ extern void set_reference_positions(
         t_rot *rot, rvec *x, matrix box,
         const char *fn, gmx_bool bSet, warninp_t wi)
 {
-    int         g, i, ii;
-    t_rotgrp   *rotg;
-    t_trnheader header;    /* Header information of reference file */
-    char        base[STRLEN], extension[STRLEN], reffile[STRLEN];
-    char       *extpos;
-    rvec        f_box[3];  /* Box from reference file */
+    int              g, i, ii;
+    t_rotgrp        *rotg;
+    gmx_trr_header_t header;    /* Header information of reference file */
+    char             base[STRLEN], extension[STRLEN], reffile[STRLEN];
+    char            *extpos;
+    rvec             f_box[3]; /* Box from reference file */
 
 
     /* Base name and extension of the reference file: */
@@ -275,13 +276,13 @@ extern void set_reference_positions(
         if (gmx_fexist(reffile))
         {
             fprintf(stderr, "  Reading them from %s.\n", reffile);
-            read_trnheader(reffile, &header);
+            gmx_trr_read_single_header(reffile, &header);
             if (rotg->nat != header.natoms)
             {
                 gmx_fatal(FARGS, "Number of atoms in file %s (%d) does not match the number of atoms in rotation group (%d)!\n",
                           reffile, header.natoms, rotg->nat);
             }
-            read_trn(reffile, &header.step, &header.t, &header.lambda, f_box, &header.natoms, rotg->x_ref, NULL, NULL);
+            gmx_trr_read_single_frame(reffile, &header.step, &header.t, &header.lambda, f_box, &header.natoms, rotg->x_ref, NULL, NULL);
 
             /* Check whether the box is unchanged and output a warning if not: */
             check_box_unchanged(f_box, box, reffile, wi);
@@ -294,7 +295,7 @@ extern void set_reference_positions(
                 ii = rotg->ind[i];
                 copy_rvec(x[ii], rotg->x_ref[i]);
             }
-            write_trn(reffile, g, 0.0, 0.0, box, rotg->nat, rotg->x_ref, NULL, NULL);
+            gmx_trr_write_single_frame(reffile, g, 0.0, 0.0, box, rotg->nat, rotg->x_ref, NULL, NULL);
         }
     }
 }
similarity index 98%
rename from src/gromacs/gmxpreprocess/resall.c
rename to src/gromacs/gmxpreprocess/resall.cpp
index fe75e0cc652e8f65294e2c8aab6a8aa960047d47..208faddf996e387e8fd089bf364f85f3e81ecd4e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -42,6 +42,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <algorithm>
+
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/gmxpreprocess/fflibutil.h"
 #include "gromacs/gmxpreprocess/pgutil.h"
@@ -88,7 +90,7 @@ gpp_atomtype_t read_atype(const char *ffdir, t_symtab *tab)
             if (sscanf(buf, "%s%lf", name, &m) == 2)
             {
                 a->m = m;
-                add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
+                add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0, 0.0, 0.0 );
                 fprintf(stderr, "\rAtomtype %d", ++nratt);
             }
             else
@@ -332,7 +334,7 @@ void read_resall(char *rrdb, int *nrtpptr, t_restp **rtp,
                  gmx_bool bAllowOverrideRTP)
 {
     FILE         *in;
-    char          filebase[STRLEN], *ptr, line[STRLEN], header[STRLEN];
+    char          filebase[STRLEN], line[STRLEN], header[STRLEN];
     int           i, nrtp, maxrtp, bt, nparam;
     int           dum1, dum2, dum3;
     t_restp      *rrtp, *header_settings;
@@ -574,7 +576,7 @@ static int neq_str_sign(const char *a1, const char *a2)
 
     l1 = (int)strlen(a1);
     l2 = (int)strlen(a2);
-    lm = min(l1, l2);
+    lm = std::min(l1, l2);
 
     if (lm >= 1 &&
         ((l1 == l2+1 && is_sign(a1[l1-1])) ||
index 487ed643e2a06febc6b4c69f5c069fffd7cd657f..463f982ef7e1114782bc824f100ad213a2d8a734 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/hackblock.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 char *search_rtp(const char *key, int nrtp, t_restp rtp[]);
 /* Search for an entry in the rtp database, returns the rtp residue name.
  * A mismatch of one character is allowed, if there is only one nearly
@@ -69,8 +65,5 @@ void read_resall(char *resdb, int *nrtp, t_restp **rtp,
 void print_resall(FILE *out, int nrtp, t_restp rtp[],
                   gpp_atomtype_t atype);
 /* write rtp database */
-#ifdef __cplusplus
-}
-#endif
 
 #endif
index 29552919bad4207ed6e2b8e5545bb39893a41a37..d7b17f6fbccdbfe3d7f016b8f7871cd3910be8a7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_GMXPREPROCESS_SOLVATE_H
 #define GMX_GMXPREPROCESS_SOLVATE_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 int gmx_solvate(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 99%
rename from src/gromacs/gmxpreprocess/sortwater.c
rename to src/gromacs/gmxpreprocess/sortwater.cpp
index 73c8b5472d8f7be3eb320460be9a0e554c8d7e96..1248f8d46a914d0c012bd69c65810a5c9adbad04 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index fc9e704712cadbd20af5733a776972c7cf48e1a2..ebef2dfa375b974168d5ed03c479d603b9cd3959 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/random/random.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void randwater(int astart, int nwater, int nwatom,
                rvec x[], rvec v[], gmx_rng_t rng);
 /* Randomize the order of nwater molecules of length nwatom, the
@@ -65,8 +61,4 @@ void mkcompact(int astart, int nwater, int nwatom, rvec x[], rvec v[],
 /* Make compact subboxes
  * IS NOT THREAD SAFE  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 97%
rename from src/gromacs/gmxpreprocess/specbond.c
rename to src/gromacs/gmxpreprocess/specbond.cpp
index 2d1bfcf261425105a6b0effc306a7b22c4201cbf..700e216d4218f2875cb1d88bf05964ec238579f0 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "specbond.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/gmxpreprocess/pdb2top.h"
@@ -274,7 +277,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
             for (j = 0; (j < nspec); j++)
             {
                 aj      = sgp[j];
-                d[i][j] = sqrt(distance2(x[ai], x[aj]));
+                d[i][j] = std::sqrt(distance2(x[ai], x[aj]));
             }
         }
         if (nspec > 1)
@@ -285,7 +288,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
             {
                 /* print resname/number column headings */
                 fprintf(stderr, "%8s%8s", "", "");
-                e = min(b+MAXCOL, nspec-1);
+                e = std::min(b+MAXCOL, nspec-1);
                 for (i = b; (i < e); i++)
                 {
                     sprintf(buf, "%s%d", *pdba->resinfo[pdba->atom[sgp[i]].resind].name,
@@ -295,7 +298,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
                 fprintf(stderr, "\n");
                 /* print atomname/number column headings */
                 fprintf(stderr, "%8s%8s", "", "");
-                e = min(b+MAXCOL, nspec-1);
+                e = std::min(b+MAXCOL, nspec-1);
                 for (i = b; (i < e); i++)
                 {
                     sprintf(buf, "%s%d", *pdba->atomname[sgp[i]], sgp[i]+1);
@@ -303,7 +306,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
                 }
                 fprintf(stderr, "\n");
                 /* print matrix */
-                e = min(b+MAXCOL, nspec);
+                e = std::min(b+MAXCOL, nspec);
                 for (i = b+1; (i < nspec); i++)
                 {
                     sprintf(buf, "%s%d", *pdba->resinfo[pdba->atom[sgp[i]].resind].name,
@@ -311,7 +314,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
                     fprintf(stderr, "%8s", buf);
                     sprintf(buf, "%s%d", *pdba->atomname[sgp[i]], sgp[i]+1);
                     fprintf(stderr, "%8s", buf);
-                    e2 = min(i, e);
+                    e2 = std::min(i, e);
                     for (j = b; (j < e2); j++)
                     {
                         fprintf(stderr, " %7.3f", d[i][j]);
index 4c8eedc307b62365d1fbb221b286426aad2afa02..bcdd7bd9aaf5824c77d0bb5f735a9830a6cf2c34 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/gmxpreprocess/pdb2top.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
                  t_ssbond **specbonds, gmx_bool bVerbose);
 
 gmx_bool yesno(void);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 91%
rename from src/gromacs/gmxpreprocess/ter_db.c
rename to src/gromacs/gmxpreprocess/ter_db.cpp
index df0722c368326e6cb534e58b01efc89cfc981dfb..eca3a323f077bbd84f61da58b2bdd6e6aa2930d5 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -90,7 +90,7 @@ static void read_atom(char *line, gmx_bool bAdd,
                       char **nname, t_atom *a, gpp_atomtype_t atype, int *cgnr)
 {
     int    nr, i;
-    char   buf[5][30], type[12];
+    char   buf[5][30];
     double m, q;
 
     /* This code is messy, because of support for different formats:
@@ -151,7 +151,7 @@ static void print_ter_db(const char *ff, char C, int nb, t_hackblock tb[],
 {
     FILE *out;
     int   i, j, k, bt, nrepl, nadd, ndel;
-    char  buf[STRLEN], nname[STRLEN];
+    char  buf[STRLEN];
 
     sprintf(buf, "%s-%c.tdb", ff, C);
     out = gmx_fio_fopen(buf, "w");
@@ -440,6 +440,7 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[],
                          const char *rtpname,
                          int *nret)
 {
+    // TODO Four years later, no force fields have ever used this, so decide status of this feature
     /* Since some force fields (e.g. OPLS) needs different
      * atomtypes for different residues there could be a lot
      * of entries in the databases for specific residues
@@ -462,9 +463,9 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[],
      */
 
     t_restp     *   restp;
-    int             i, j, n, len, none_idx;
+    int             i, j, n, none_idx;
     gmx_bool        found;
-    char           *rtpname_match, *s, *s2, *c;
+    char           *rtpname_match, *s;
     t_hackblock   **list;
 
     rtpname_match = search_rtp(rtpname, nrtp, rtp);
@@ -505,8 +506,8 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[],
         while (!found && s != NULL);
     }
 
-    /* All residue-specific termini have been added. See if there
-     * are some generic ones by searching for the occurence of
+    /* All residue-specific termini have been added. We might have to fall
+     * back on generic termini, which are characterized by not having
      * '-' in the name prior to the last position (which indicates charge).
      * The [ None ] alternative is special since we don't want that
      * to be the default, so we put it last in the list we return.
@@ -528,8 +529,22 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[],
             }
             else
             {
-                c = strchr(s, '-');
-                if (c == NULL || ((c-s+1) == strlen(s)))
+                /* Time to see if there's a generic terminus that matches.
+                   Is there a hyphen? */
+                char *c = strchr(s, '-');
+
+                /* A conjunction hyphen normally indicates a residue-specific
+                   terminus, which is named like "GLY-COOH". A generic terminus
+                   won't have a hyphen. */
+                bool bFoundAnyHyphen = (c != NULL);
+                /* '-' as the last character indicates charge, so if that's
+                   the only one found e.g. "COO-", then it was not a conjunction
+                   hyphen, so this is a generic terminus */
+                bool bOnlyFoundChargeHyphen = (bFoundAnyHyphen &&
+                                               *(c+1) == '\0');
+                /* Thus, "GLY-COO-" is not recognized as a generic terminus. */
+                bool bFoundGenericTerminus = !bFoundAnyHyphen || bOnlyFoundChargeHyphen;
+                if (bFoundGenericTerminus)
                 {
                     /* Check that we haven't already added a residue-specific version
                      * of this terminus.
@@ -567,12 +582,9 @@ t_hackblock *choose_ter(int nb, t_hackblock **tb, const char *title)
     printf("%s\n", title);
     for (i = 0; (i < nb); i++)
     {
-        char *advice_string = "";
-        if (0 == gmx_wcmatch("*ZWITTERION*", (*tb[i]).name))
-        {
-            advice_string = " (only use with zwitterions containing exactly one residue)";
-        }
-        printf("%2d: %s%s\n", i, (*tb[i]).name, advice_string);
+        bool bIsZwitterion = (0 == gmx_wcmatch("*ZWITTERION*", (*tb[i]).name));
+        printf("%2d: %s%s\n", i, (*tb[i]).name,
+               bIsZwitterion ? " (only use with zwitterions containing exactly one residue)" : "");
     }
     do
     {
index 45477d620705a65421430521529d7b2258db012d..b861e42d58ecdac70562055af3443be908647d7a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -41,9 +41,6 @@
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/gmxpreprocess/hackblock.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 int read_ter_db(const char *ffdir, char ter,
                 t_hackblock **tbptr, gpp_atomtype_t atype);
@@ -59,8 +56,4 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[],
 t_hackblock *choose_ter(int nb, t_hackblock **tb, const char *title);
 /* Interactively select one.. */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/tomorse.c
rename to src/gromacs/gmxpreprocess/tomorse.cpp
index cd9b793b5fb3b2bc75cd9c8b049cc73668da52cd..668c652cd895924168d734a5c8006fc6520a3c99 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "tomorse.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/gmxpreprocess/toputil.h"
@@ -250,7 +251,7 @@ void convert_harmonics(int nrmols, t_molinfo mols[], gpp_atomtype_t atype)
                         bRemoveHarm[j] = TRUE;
                         b0             = mols[i].plist[bb].param[j].c[0];
                         kb             = mols[i].plist[bb].param[j].c[1];
-                        beta           = sqrt(kb/(2*edis));
+                        beta           = std::sqrt(kb/(2*edis));
                         mols[i].plist[F_MORSE].param[nrmorse].a[0] = ni;
                         mols[i].plist[F_MORSE].param[nrmorse].a[1] = nj;
                         mols[i].plist[F_MORSE].param[nrmorse].c[0] = b0;
index 6a39ea6fd84200e000bbe34358be5c9bd477dcd8..cb098869de9d5f9c3384c83c2d20d7978ab50007 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void convert_harmonics(int nrmols, t_molinfo mols[], gpp_atomtype_t atype);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index fa62531eeb70025e794080eab2691cc009a00f9a..38a664a2d0f24f0b71fede126ada2c3238de7e19 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 typedef struct tagDirStack {
     directive           d;
     struct tagDirStack *prev;
@@ -65,8 +61,4 @@ int  DS_Search (DirStack *DS, directive d);
 
 int  DS_Check_Order (DirStack *DS, directive d);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 99%
rename from src/gromacs/gmxpreprocess/topio.c
rename to src/gromacs/gmxpreprocess/topio.cpp
index 3478619757bd2ebad0d0fff4b24e83ec76d3c44c..906823befc2f44b4b41976dd8760ba4f1aaad2f3 100644 (file)
 
 #include "topio.h"
 
-#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
 #include <sys/types.h>
 
 #include "gromacs/fileio/gmxfio.h"
@@ -72,6 +72,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #define OPENDIR     '[' /* starting sign for directive */
@@ -120,7 +121,8 @@ static void gen_pairs(t_params *nbs, t_params *pairs, real fudge, int comb)
     int     i, j, ntp, nrfp, nrfpA, nrfpB, nnn;
     real    scaling;
     ntp       = nbs->nr;
-    nnn       = sqrt(ntp);
+    nnn       = static_cast<int>(std::sqrt(static_cast<double>(ntp)));
+    GMX_ASSERT(nnn * nnn == ntp, "Number of pairs of generated non-bonded parameters should be a perfect square");
     nrfp      = NRFP(F_LJ);
     nrfpA     = interaction_function[F_LJ14].nrfpA;
     nrfpB     = interaction_function[F_LJ14].nrfpB;
@@ -415,7 +417,7 @@ find_gb_anglelength(t_params *plist, int ai, int ak, real *length)
                     if (status1 == 0 && status2 == 0)
                     {
                         /* cosine theorem to get r13 */
-                        *length = sqrt(r12*r12+r23*r23-(2*r12*r23*cos(a123/RAD2DEG)));
+                        *length = std::sqrt(r12*r12+r23*r23-(2*r12*r23*cos(a123/RAD2DEG)));
                         found   = 1;
                     }
                 }
@@ -430,8 +432,7 @@ find_gb_anglelength(t_params *plist, int ai, int ak, real *length)
 int
 generate_gb_exclusion_interactions(t_molinfo *mi, gpp_atomtype_t atype, t_nextnb *nnb)
 {
-    int          i, j, k, n, ai, aj, ti, tj;
-    int          n12, n13, n14;
+    int          j, n, ai, aj, ti, tj;
     int          ftype;
     t_param      param;
     t_params *   plist;
@@ -575,7 +576,7 @@ static char **read_topol(const char *infile, const char *outfile,
                          warninp_t   wi)
 {
     FILE           *out;
-    int             i, sl, nb_funct, comb;
+    int             i, sl, nb_funct;
     char           *pline = NULL, **title = NULL;
     char            line[STRLEN], errbuf[256], comb_str[256], nb_str[256];
     char            genpairs[32];
@@ -583,12 +584,10 @@ static char **read_topol(const char *infile, const char *outfile,
     int             nrcopies, nmol, nmolb = 0, nscan, ncombs, ncopy;
     double          fLJ, fQQ, fPOW;
     gmx_molblock_t *molb  = NULL;
-    t_topology     *block = NULL;
     t_molinfo      *mi0   = NULL;
     DirStack       *DS;
     directive       d, newd;
     t_nbparam     **nbparam, **pair;
-    gmx_bool        bIntermolecularInteractions;
     t_block2       *block2;
     real            fudgeLJ = -1;    /* Multiplication factor to generate 1-4 from LJ */
     gmx_bool        bReadDefaults, bReadMolType, bGenPairs, bWarn_copy_A_B;
@@ -965,7 +964,7 @@ static char **read_topol(const char *infile, const char *outfile,
                             push_vsitesn(d, mi0->plist, &(mi0->atoms), pline, wi);
                             break;
                         case d_exclusions:
-                            assert(block2);
+                            GMX_ASSERT(block2, "block2 must always be allocated so exclusions can be processed");
                             if (!block2[nmol-1].nr)
                             {
                                 init_block2(&(block2[nmol-1]), mi0->atoms.nr);
@@ -1260,7 +1259,6 @@ static void generate_qmexcl_moltype(gmx_moltype_t *molt, unsigned char *grpnr,
         j       = 0;
         while (j < molt->ilist[i].nr)
         {
-            bexcl = FALSE;
             switch (nratoms)
             {
                 case 2:
@@ -1299,6 +1297,7 @@ static void generate_qmexcl_moltype(gmx_moltype_t *molt, unsigned char *grpnr,
                     break;
                 default:
                     gmx_fatal(FARGS, "no such bonded interactions with %d atoms\n", nratoms);
+                    bexcl = FALSE;
             }
             if (bexcl)
             {
index 744f31202a342f7217c2e64c4bd34f8da7c5ead1..124503492ff4abb4c78728635b02bef3ca0bb7ac 100644 (file)
 #include "gromacs/gmxpreprocess/readir.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 double check_mol(gmx_mtop_t *mtop, warninp_t wi);
 /* Check mass and charge */
 
@@ -73,8 +69,4 @@ char **do_top(gmx_bool         bVerbose,
 /* This routine expects sys->molt[m].ilist to be of size F_NRE and ordered. */
 void generate_qmexcl(gmx_mtop_t *sys, t_inputrec *ir, warninp_t    wi);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 97%
rename from src/gromacs/gmxpreprocess/toppush.c
rename to src/gromacs/gmxpreprocess/toppush.cpp
index 832a2a12037fdd70864944b4f56605199393e290..6fb5e3577c60f18a60d028ccb45cd3a9552470b7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "toppush.h"
 
-#include <assert.h>
 #include <ctype.h>
-#include <math.h>
 #include <stdlib.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
 #include "gromacs/gmxpreprocess/gpp_bond_atomtype.h"
 #include "gromacs/gmxpreprocess/readir.h"
@@ -54,6 +56,7 @@
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atype,
@@ -86,7 +89,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp
                             {
                                 ci = get_atomtype_nbparam(i, nf, atype);
                                 cj = get_atomtype_nbparam(j, nf, atype);
-                                c  = sqrt(ci * cj);
+                                c  = std::sqrt(ci * cj);
                                 plist->param[k].c[nf]      = c;
                             }
                         }
@@ -111,7 +114,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp
                             {
                                 plist->param[k].c[0] *= -1;
                             }
-                            plist->param[k].c[1] = sqrt(ci1*cj1);
+                            plist->param[k].c[1] = std::sqrt(ci1*cj1);
                         }
                     }
 
@@ -126,7 +129,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp
                             cj0                  = get_atomtype_nbparam(j, 0, atype);
                             ci1                  = get_atomtype_nbparam(i, 1, atype);
                             cj1                  = get_atomtype_nbparam(j, 1, atype);
-                            plist->param[k].c[0] = sqrt(fabs(ci0*cj0));
+                            plist->param[k].c[0] = std::sqrt(fabs(ci0*cj0));
                             /* Negative sigma signals that c6 should be set to zero later,
                              * so we need to propagate that through the combination rules.
                              */
@@ -134,7 +137,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp
                             {
                                 plist->param[k].c[0] *= -1;
                             }
-                            plist->param[k].c[1] = sqrt(ci1*cj1);
+                            plist->param[k].c[1] = std::sqrt(ci1*cj1);
                         }
                     }
 
@@ -160,7 +163,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp
                     cj2                  = get_atomtype_nbparam(j, 2, atype);
                     bi                   = get_atomtype_nbparam(i, 1, atype);
                     bj                   = get_atomtype_nbparam(j, 1, atype);
-                    plist->param[k].c[0] = sqrt(ci0 * cj0);
+                    plist->param[k].c[0] = std::sqrt(ci0 * cj0);
                     if ((bi == 0) || (bj == 0))
                     {
                         plist->param[k].c[1] = 0;
@@ -169,7 +172,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp
                     {
                         plist->param[k].c[1] = 2.0/(1/bi+1/bj);
                     }
-                    plist->param[k].c[2] = sqrt(ci2 * cj2);
+                    plist->param[k].c[2] = std::sqrt(ci2 * cj2);
                 }
             }
 
@@ -516,9 +519,9 @@ void push_at (t_symtab *symtab, gpp_atomtype_t at, t_bond_atomtype bat,
             gmx_fatal(FARGS, "Replacing atomtype %s failed", type);
         }
     }
-    else if ((nr = add_atomtype(at, symtab, atom, type, param,
-                                batype_nr, radius, vol,
-                                surftens, atomnr, gb_radius, S_hct)) == NOTSET)
+    else if ((add_atomtype(at, symtab, atom, type, param,
+                           batype_nr, radius, vol,
+                           surftens, atomnr, gb_radius, S_hct)) == NOTSET)
     {
         gmx_fatal(FARGS, "Adding atomtype %s failed", type);
     }
@@ -674,7 +677,7 @@ void push_bt(directive d, t_params bt[], int nral,
         "%*s%*s%*s%*s%*s%*s%*s"
     };
     const char *formlf = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
-    int         i, ft, ftype, nn, nrfp, nrfpA, nrfpB;
+    int         i, ft, ftype, nn, nrfp, nrfpA;
     char        f1[STRLEN];
     char        alc[MAXATOMLIST+1][20];
     /* One force parameter more, so we can check if we read too many */
@@ -700,7 +703,6 @@ void push_bt(directive d, t_params bt[], int nral,
     ftype = ifunc_index(d, ft);
     nrfp  = NRFP(ftype);
     nrfpA = interaction_function[ftype].nrfpA;
-    nrfpB = interaction_function[ftype].nrfpB;
     strcpy(f1, formnl[nral]);
     strcat(f1, formlf);
     if ((nn = sscanf(line, f1, &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12]))
@@ -786,7 +788,7 @@ void push_dihedraltype(directive d, t_params bt[],
         "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
         "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
     };
-    int          i, ft, ftype, nn, nrfp, nrfpA, nrfpB, nral;
+    int          i, ft, ftype, nn, nrfp, nrfpA, nral;
     char         f1[STRLEN];
     char         alc[MAXATOMLIST+1][20];
     double       c[MAXFORCEPARAM];
@@ -860,7 +862,6 @@ void push_dihedraltype(directive d, t_params bt[],
     ftype = ifunc_index(d, ft);
     nrfp  = NRFP(ftype);
     nrfpA = interaction_function[ftype].nrfpA;
-    nrfpB = interaction_function[ftype].nrfpB;
 
     strcpy(f1, formnl[nral]);
     strcat(f1, formlf[nrfp-1]);
@@ -925,14 +926,13 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype,
               warninp_t wi)
 {
     /* swap the atoms */
-    const char *form2 = "%*s%*s%*s%lf%lf";
     const char *form3 = "%*s%*s%*s%lf%lf%lf";
     const char *form4 = "%*s%*s%*s%lf%lf%lf%lf";
     const char *form5 = "%*s%*s%*s%lf%lf%lf%lf%lf";
     char        a0[80], a1[80];
-    int         i, f, n, ftype, atnr, nrfp;
+    int         i, f, n, ftype, nrfp;
     double      c[4], dum;
-    real        cr[4], sig6;
+    real        cr[4];
     atom_id     ai, aj;
     t_nbparam  *nbp;
     gmx_bool    bId;
@@ -968,7 +968,7 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype,
         /* When the B topology parameters are not set,
          * copy them from topology A
          */
-        assert(nrfp <= 4);
+        GMX_ASSERT(nrfp <= 4, "LJ-14 cannot have more than 4 parameters");
         for (i = n; i < nrfp; i++)
         {
             c[i] = c[i-2];
@@ -1018,7 +1018,7 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype,
     {
         gmx_fatal(FARGS, "Atomtype %s not found", a1);
     }
-    nbp = &(nbt[max(ai, aj)][min(ai, aj)]);
+    nbp = &(nbt[std::max(ai, aj)][std::min(ai, aj)]);
 
     if (nbp->bSet)
     {
@@ -1050,13 +1050,12 @@ void
 push_gb_params (gpp_atomtype_t at, char *line,
                 warninp_t wi)
 {
-    int    nfield;
     int    atype;
     double radius, vol, surftens, gb_radius, S_hct;
     char   atypename[STRLEN];
     char   errbuf[STRLEN];
 
-    if ( (nfield = sscanf(line, "%s%lf%lf%lf%lf%lf", atypename, &radius, &vol, &surftens, &gb_radius, &S_hct)) != 6)
+    if ( (sscanf(line, "%s%lf%lf%lf%lf%lf", atypename, &radius, &vol, &surftens, &gb_radius, &S_hct)) != 6)
     {
         sprintf(errbuf, "Too few gb parameters for type %s\n", atypename);
         warning(wi, errbuf);
@@ -1081,12 +1080,11 @@ push_cmaptype(directive d, t_params bt[], int nral, gpp_atomtype_t at,
 {
     const char  *formal = "%s%s%s%s%s%s%s%s";
 
-    int          i, j, ft, ftype, nn, nrfp, nrfpA, nrfpB;
+    int          i, ft, ftype, nn, nrfp, nrfpA, nrfpB;
     int          start;
     int          nxcmap, nycmap, ncmap, read_cmap, sl, nct;
     char         s[20], alc[MAXATOMLIST+2][20];
     t_param      p;
-    gmx_bool     bAllowRepeat;
     char         errbuf[256];
 
     /* Keep the compiler happy */
@@ -1464,7 +1462,8 @@ static gmx_bool default_nb_params(int ftype, t_params bt[], t_atoms *at,
         /* First test the generated-pair position to save
          * time when we have 1000*1000 entries for e.g. OPLS...
          */
-        ntype = sqrt(nr);
+        ntype = static_cast<int>(std::sqrt(static_cast<double>(nr)));
+        GMX_ASSERT(ntype * ntype == nr, "Number of pairs of generated non-bonded parameters should be a perfect square");
         if (bB)
         {
             ti = at->atom[p->a[0]].typeB;
@@ -1541,7 +1540,7 @@ static gmx_bool default_cmap_params(t_params bondtype[],
                                     t_param *p, gmx_bool bB,
                                     int *cmap_type, int *nparam_def)
 {
-    int      i, j, nparam_found;
+    int      i, nparam_found;
     int      ct;
     gmx_bool bFound = FALSE;
 
@@ -1731,7 +1730,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[],
     /* One force parameter more, so we can check if we read too many */
     double       cc[MAXFORCEPARAM+1];
     int          aa[MAXATOMLIST+1];
-    t_param      param, paramB, *param_defA, *param_defB;
+    t_param      param, *param_defA, *param_defB;
     gmx_bool     bFoundA = FALSE, bFoundB = FALSE, bDef, bPert, bSwapParity = FALSE;
     int          nparam_defA, nparam_defB;
     char         errbuf[256];
@@ -1841,7 +1840,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[],
         if (bFoundA)
         {
             /* Copy the A-state and B-state default parameters. */
-            assert(NRFPA(ftype)+NRFPB(ftype) <= MAXFORCEPARAM);
+            GMX_ASSERT(NRFPA(ftype)+NRFPB(ftype) <= MAXFORCEPARAM, "Bonded interactions may have at most 12 parameters");
             for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++)
             {
                 param.c[j] = param_defA->c[j];
@@ -2113,16 +2112,15 @@ void push_cmap(directive d, t_params bondtype[], t_params bond[],
         "%d%d%d%d%d%d%d"
     };
 
-    int      i, j, nr, ftype, nral, nread, ncmap_params;
+    int      i, j, ftype, nral, nread, ncmap_params;
     int      cmap_type;
     int      aa[MAXATOMLIST+1];
     char     errbuf[256];
     gmx_bool bFound;
-    t_param  param, paramB, *param_defA, *param_defB;
+    t_param  param;
 
     ftype        = ifunc_index(d, 1);
     nral         = NRAL(ftype);
-    nr           = bondtype[ftype].nr;
     ncmap_params = 0;
 
     nread = sscanf(line, aaformat[nral-1],
@@ -2225,7 +2223,7 @@ void push_vsitesn(directive d, t_params bond[],
 
     param.a[0] = a - 1;
 
-    ret   = sscanf(ptr, "%d%n", &type, &n);
+    sscanf(ptr, "%d%n", &type, &n);
     ptr  += n;
     ftype = ifunc_index(d, type);
 
@@ -2606,7 +2604,8 @@ static void generate_LJCpairsNB(t_molinfo *mol, int nb_funct, t_params *nbp)
     n    = mol->atoms.nr;
     atom = mol->atoms.atom;
 
-    ntype = sqrt(nbp->nr);
+    ntype = static_cast<int>(std::sqrt(static_cast<double>(nbp->nr)));
+    GMX_ASSERT(ntype * ntype == nbp->nr, "Number of pairs of generated non-bonded parameters should be a perfect square");
 
     for (i = 0; i < MAXATOMLIST; i++)
     {
index 1e14c57bc72a8db85f7648838bb51aa85790be03..8ee48618dfd8a7b7e2df47c59ad92ff35c179ff5 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/legacyheaders/warninp.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 typedef struct {
     int       nr;   /* The number of entries in the list            */
     int       nra2; /* The total number of entries in a                        */
@@ -142,8 +138,4 @@ void convert_moltype_couple(t_molinfo *mol, int atomtype_decouple,
  * of the system, but full interaction with itself.
  */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/gmxpreprocess/topshake.c
rename to src/gromacs/gmxpreprocess/topshake.cpp
index bd2662df2ad09d93914160f2a698f7c199a1dec8..466bcc843dd39c80394d614c03d177115a0633b2 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,7 +40,8 @@
 #include "topshake.h"
 
 #include <ctype.h>
-#include <math.h>
+
+#include <cmath>
 
 #include "gromacs/gmxpreprocess/readir.h"
 #include "gromacs/gmxpreprocess/topdirs.h"
@@ -108,7 +109,7 @@ void make_shake (t_params plist[], t_atoms *atoms, int nshake)
     t_params        *bonds;
     t_param          p, *bond, *ang;
     real             b_ij, b_jk;
-    int              nb, b, i, j, ftype, ftype_a;
+    int              i, j, ftype, ftype_a;
     gmx_bool         bFound;
 
     if (nshake != eshNONE)
@@ -193,8 +194,8 @@ void make_shake (t_params plist[], t_atoms *atoms, int nshake)
                                     if (bFound)
                                     {
                                         /* apply law of cosines */
-                                        p.C0 = sqrt( b_ij*b_ij + b_jk*b_jk -
-                                                     2.0*b_ij*b_jk*cos(DEG2RAD*ang->C0) );
+                                        p.C0 = std::sqrt( b_ij*b_ij + b_jk*b_jk -
+                                                          2.0*b_ij*b_jk*cos(DEG2RAD*ang->C0) );
                                         p.C1 = p.C0;
 #ifdef DEBUG
                                         printf("p: %d, q: %d, dist: %12.5e\n", p.AI, p.AJ, p.C0);
index 15e09da6623937ebfd8ad444961a9ac9ab27c17f..f232d5620698eb7cfc526a19be37c029e69adbe4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/gmxpreprocess/topio.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 void make_shake (t_params plist[], t_atoms *atoms, int nshake);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/gmxpreprocess/toputil.c
rename to src/gromacs/gmxpreprocess/toputil.cpp
index 4cbcc05525a137e9b96b058295075b1861246ff2..133773bea069801a11178aff2a467ceb135d4af9 100644 (file)
 
 #include "toputil.h"
 
-#include <assert.h>
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
 #include "gromacs/gmxpreprocess/topdirs.h"
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 /* UTILITIES */
@@ -86,10 +89,10 @@ void pr_alloc (int extra, t_params *pr)
     {
         return;
     }
-    assert(!((pr->nr == 0) && (pr->param != NULL)));
+    GMX_ASSERT(pr->nr != 0 || pr->param == NULL, "Invalid t_params object");
     if (pr->nr+extra > pr->maxnr)
     {
-        pr->maxnr = max(1.2*pr->maxnr, pr->maxnr + extra);
+        pr->maxnr = std::max(static_cast<int>(1.2*pr->maxnr), pr->maxnr + extra);
         srenew(pr->param, pr->maxnr);
         for (i = pr->nr; (i < pr->maxnr); i++)
         {
@@ -477,6 +480,8 @@ void print_atoms(FILE *out, gpp_atomtype_t atype, t_atoms *at, int *cgnr,
                 gmx_fatal(FARGS, "tpA = %d, i= %d in print_atoms", tpA, i);
             }
 
+            /* This is true by construction, but static analysers don't know */
+            GMX_ASSERT(!bRTPresname || at->resinfo[at->atom[i].resind].rtp, "-rtpres did not have residue name available");
             fprintf(out, "%6d %10s %6d%c %5s %6s %6d %10g %10g",
                     i+1, tpnmA,
                     at->resinfo[ri].nr,
index d7d040effe46e3035391c61b73f57dfa608f48ed..f25b3f4bf0448ed0b979ed575ce045aa157cf56f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/gpp_atomtype.h"
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* UTILITIES */
 
 int name2index(char *str, char ***typenames, int ntypes);
@@ -79,8 +75,4 @@ void print_bondeds(FILE *out, int natoms, directive d,
 
 void print_excl(FILE *out, int natoms, t_excls excls[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/gmxpreprocess/vsite_parm.c
rename to src/gromacs/gmxpreprocess/vsite_parm.cpp
index 12357de2b44b0a2174e343c470c3063b1a250f35..34bbded82f44cbb5a9ba5e5d7f50a997bfe4815a 100644 (file)
 
 #include "vsite_parm.h"
 
-#include <assert.h>
-#include <math.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/gmxpreprocess/add_par.h"
 #include "gromacs/gmxpreprocess/resall.h"
 #include "gromacs/gmxpreprocess/toputil.h"
@@ -52,6 +54,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 typedef struct {
@@ -448,7 +451,7 @@ static gmx_bool calc_vsite3_param(gpp_atomtype_t atype,
         bError = bError || (bjk != bjl);
 
         /* the X atom (C or N) in the XH2/XH3 group is the first after the masses: */
-        aN = max(param->AK, param->AL)+1;
+        aN = std::max(param->AK, param->AL)+1;
 
         /* get common bonds */
         bMM    = get_bond_length(nrbond, bonds, param->AK, param->AL);
@@ -458,7 +461,7 @@ static gmx_bool calc_vsite3_param(gpp_atomtype_t atype,
 
         /* calculate common things */
         rM  = 0.5*bMM;
-        dM  = sqrt( sqr(bCM) - sqr(rM) );
+        dM  = std::sqrt( sqr(bCM) - sqr(rM) );
 
         /* are we dealing with the X atom? */
         if (param->AI == aN)
@@ -617,7 +620,7 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype,
         bError = bError || (bjk != bjl);
 
         /* the X atom (C or N) in the XH3 group is the first after the masses: */
-        aN = max(param->AK, param->AL)+1;
+        aN = std::max(param->AK, param->AL)+1;
 
         /* get all bondlengths and angles: */
         bMM    = get_bond_length(nrbond, bonds, param->AK, param->AL);
@@ -635,7 +638,7 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype,
         rHx = rH*cos(DEG2RAD*30);
         rHy = rH*sin(DEG2RAD*30);
         rM  = 0.5*bMM;
-        dM  = sqrt( sqr(bCM) - sqr(rM) );
+        dM  = std::sqrt( sqr(bCM) - sqr(rM) );
         a   = 0.5*( (dH/dM) - (rHy/rM) );
         b   = 0.5*( (dH/dM) + (rHy/rM) );
         c   = rHx / (2*dM*rM);
@@ -656,9 +659,9 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype,
         pijl = cos(aijl)*bij;
         a    = ( pijk + (pijk*cos(akjl)-pijl) * cos(akjl) / sqr(sin(akjl)) ) / bjk;
         b    = ( pijl + (pijl*cos(akjl)-pijk) * cos(akjl) / sqr(sin(akjl)) ) / bjl;
-        c    = -sqrt( sqr(bij) -
-                      ( sqr(pijk) - 2*pijk*pijl*cos(akjl) + sqr(pijl) )
-                      / sqr(sin(akjl)) )
+        c    = -std::sqrt( sqr(bij) -
+                           ( sqr(pijk) - 2*pijk*pijl*cos(akjl) + sqr(pijl) )
+                           / sqr(sin(akjl)) )
             / ( bjk*bjl*sin(akjl) );
     }
 
@@ -720,8 +723,8 @@ static gmx_bool calc_vsite4fd_param(t_param *param,
             gmx_fatal(FARGS, "invalid construction in calc_vsite4fd for atom %d: "
                       "cosakl=%f, cosakm=%f\n", param->AI+1, cosakl, cosakm);
         }
-        sinakl = sqrt(1-sqr(cosakl));
-        sinakm = sqrt(1-sqr(cosakm));
+        sinakl = std::sqrt(1-sqr(cosakl));
+        sinakm = std::sqrt(1-sqr(cosakm));
 
         /* note: there is a '+' because of the way the sines are calculated */
         cl = -pk / ( pl*cosakl - pk + pl*sinakl*(pm*cosakm-pk)/(pm*sinakm) );
@@ -817,7 +820,6 @@ int set_vsites(gmx_bool bVerbose, t_atoms *atoms, gpp_atomtype_t atype,
     t_mybonded     *idihs;
 
     bFirst = TRUE;
-    bERROR = TRUE;
     nvsite = 0;
     if (debug)
     {
@@ -915,6 +917,7 @@ int set_vsites(gmx_bool bVerbose, t_atoms *atoms, gpp_atomtype_t atype,
                                       "for %s atom %d",
                                       interaction_function[ftype].longname,
                                       plist[ftype].param[i].AI+1);
+                            bERROR = TRUE;
                     } /* switch */
                     if (bERROR)
                     {
@@ -1020,7 +1023,7 @@ static void check_vsite_constraints(t_params *plist,
 static void clean_vsite_bonds(t_params *plist, t_pindex pindex[],
                               int cftype, int vsite_type[])
 {
-    int          ftype, i, j, parnr, k, l, m, n, nvsite, nOut, kept_i, vsitetype;
+    int          ftype, i, j, k, m, n, nvsite, nOut, kept_i;
     int          nconverted, nremoved;
     atom_id      atom, oatom, at1, at2;
     gmx_bool     bKeep, bRemove, bUsed, bPresent, bThisFD, bThisOUT, bAllFD, bFirstTwo;
@@ -1104,8 +1107,8 @@ static void clean_vsite_bonds(t_params *plist, t_pindex pindex[],
                     }
                     else
                     {
-                        assert(vsnral != 0);
-                        assert(first_atoms != NULL);
+                        GMX_ASSERT(vsnral != 0, "nvsite > 1 must have vsnral != 0");
+                        GMX_ASSERT(first_atoms != NULL, "nvsite > 1 must have first_atoms != NULL");
                         /* if it is not the first then
                            check if this vsite is constructed from the same atoms */
                         if (vsnral == NRAL(pindex[atom].ftype)-1)
@@ -1175,7 +1178,7 @@ static void clean_vsite_bonds(t_params *plist, t_pindex pindex[],
                     bUsed = FALSE;
                     for (m = 0; (m < vsnral) && !bUsed; m++)
                     {
-                        assert(first_atoms != NULL);
+                        GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was");
 
                         if (atom == first_atoms[m])
                         {
@@ -1286,7 +1289,7 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[],
                                int cftype, int vsite_type[],
                                at2vsitecon_t *at2vc)
 {
-    int          i, j, parnr, k, l, m, n, nvsite, kept_i, vsitetype;
+    int          i, j, k, m, n, nvsite, kept_i;
     atom_id      atom, at1, at2;
     gmx_bool     bKeep, bUsed, bPresent, bAll3FAD, bFirstTwo;
     t_params    *ps;
@@ -1317,8 +1320,8 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[],
                 }
                 else
                 {
-                    assert(vsnral != 0);
-                    assert(first_atoms != NULL);
+                    GMX_ASSERT(vsnral != 0, "If we've seen a vsite before, we know how many constructing atoms it had");
+                    GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was");
                     /* check if this vsite is constructed from the same atoms */
                     if (vsnral == NRAL(pindex[atom].ftype)-1)
                     {
@@ -1366,7 +1369,7 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[],
                 bUsed = FALSE;
                 for (m = 0; (m < vsnral) && !bUsed; m++)
                 {
-                    assert(first_atoms != NULL);
+                    GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was");
 
                     if (atom == first_atoms[m])
                     {
@@ -1430,7 +1433,7 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[],
     kept_i = 0;
     for (i = 0; (i < ps->nr); i++) /* for all dihedrals in the plist */
     {
-        int            ftype, parnr, k, l, m, n, nvsite;
+        int            k, m, n, nvsite;
         int            vsnral      = 0;
         const atom_id *first_atoms = NULL;
         atom_id        atom;
@@ -1461,9 +1464,8 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[],
                 }
                 else
                 {
-                    assert(vsnral != 0);
-                    assert(first_atoms != NULL);
-
+                    GMX_ASSERT(vsnral != 0, "If we've seen a vsite before, we know how many constructing atoms it had");
+                    GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was");
                     /* check if this vsite is constructed from the same atoms */
                     if (vsnral == NRAL(pindex[atom].ftype)-1)
                     {
@@ -1504,9 +1506,8 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[],
            construction of virtual sites. If so, keep it, if not throw away: */
         for (k = 0; (k < 4) && !bKeep; k++) /* for all atoms in the dihedral */
         {
-            assert(vsnral != 0);
-            assert(first_atoms != NULL);
-
+            GMX_ASSERT(vsnral != 0, "If we've seen a vsite before, we know how many constructing atoms it had");
+            GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was");
             atom = ps->param[i].a[k];
             if (vsite_type[atom] == NOTSET && vsite_type[atom] != F_VSITEN)
             {
index 178ab9c0a4df8dd2809e33f3b78e8263400fd06c..2f87ef71afe07336f8d2c2a0f9b9587c971dd022 100644 (file)
 #include "gromacs/gmxpreprocess/grompp-impl.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 int set_vsites(gmx_bool bVerbose, t_atoms *atoms,  gpp_atomtype_t atype,
                t_params plist[]);
 /* set parameters for virtual sites, return number of virtual sites */
@@ -59,8 +55,4 @@ void set_vsites_ptype(gmx_bool bVerbose,  gmx_moltype_t *molt);
  * Throw away all constraints. */
 void clean_vsite_bondeds(t_params *ps, int natoms, gmx_bool bRmVSiteBds);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 98%
rename from src/gromacs/gmxpreprocess/x2top.c
rename to src/gromacs/gmxpreprocess/x2top.cpp
index 1c4e0bdce97c89a368ffa9169c44ee27f6346938..48f090e60f029a677920d1f2fd8ab88edf928df4 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "x2top.h"
 
-#include <assert.h>
+#include <cmath>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
@@ -62,6 +62,7 @@
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 char atp[7] = "HCNOSX";
@@ -156,11 +157,11 @@ void mk_bonds(int nnm, t_nm2type nmt[],
 
             dx2 = iprod(dx, dx);
             if (is_bond(nnm, nmt, *atoms->atomname[i], *atoms->atomname[j],
-                        sqrt(dx2)))
+                        std::sqrt(dx2)))
             {
                 b.AI = i;
                 b.AJ = j;
-                b.C0 = sqrt(dx2);
+                b.C0 = std::sqrt(dx2);
                 add_param_to_list (bond, &b);
                 nbond[i]++;
                 nbond[j]++;
@@ -179,7 +180,7 @@ int *set_cgnr(t_atoms *atoms, gmx_bool bUsePDBcharge, real *qtot, real *mtot)
 {
     int     i, n = 1;
     int    *cgnr;
-    double  qt = 0, mt = 0;
+    double  qt = 0;
 
     *qtot = *mtot = 0;
     snew(cgnr, atoms->nr);
@@ -263,7 +264,7 @@ void lo_set_force_const(t_params *plist, real c[], int nrfp, gmx_bool bRound,
                 c[0] += 180;
             }
         }
-        assert(nrfp <= MAXFORCEPARAM/2);
+        GMX_ASSERT(nrfp <= MAXFORCEPARAM/2, "Only 6 parameters may be used for an interaction");
         for (j = 0; (j < nrfp); j++)
         {
             plist->param[i].c[j]      = c[j];
@@ -276,7 +277,6 @@ void lo_set_force_const(t_params *plist, real c[], int nrfp, gmx_bool bRound,
 void set_force_const(t_params plist[], real kb, real kt, real kp, gmx_bool bRound,
                      gmx_bool bParam)
 {
-    int  i;
     real c[MAXFORCEPARAM];
 
     c[0] = 0;
@@ -451,12 +451,10 @@ int gmx_x2top(int argc, char *argv[])
     int                bts[] = { 1, 1, 1, 2 };
     matrix             box;    /* box length matrix */
     int                natoms; /* number of atoms in one molecule  */
-    int                nres;   /* number of molecules? */
-    int                i, j, k, l, m, ndih;
     int                epbc;
     gmx_bool           bRTP, bTOP, bOPLS;
     t_symtab           symtab;
-    real               cutoff, qtot, mtot;
+    real               qtot, mtot;
     char               n2t[STRLEN];
     output_env_t       oenv;
 
@@ -466,7 +464,7 @@ int gmx_x2top(int argc, char *argv[])
         { efRTP, "-r", "out",  ffOPTWR }
     };
 #define NFILE asize(fnm)
-    static real        scale = 1.1, kb = 4e5, kt = 400, kp = 5;
+    static real        kb = 4e5, kt = 400, kp = 5;
     static t_restp     rtp_header_settings;
     static gmx_bool    bRemoveDihedralIfWithImproper = FALSE;
     static gmx_bool    bGenerateHH14Interactions     = TRUE;
index 78de61acc7d978d32ae171693a1a9c1d94cc98db..99a5911dfc96a40be9f5544df442ec453e2ce1d7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_GMXPREPROCESS_X2TOP_H
 #define GMX_GMXPREPROCESS_X2TOP_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 int gmx_x2top(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 99%
rename from src/gromacs/gmxpreprocess/xlate.c
rename to src/gromacs/gmxpreprocess/xlate.cpp
index c4d2c7cfe23760334ded99be85c64094a3328b61..151eef2cbf41fb5aaf5d8b33b7663a35c3c1212a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index aa1c61006d4f2e50d1dc426f424e37c976fecbba..45c2a8fff358c0d866cd324307990f52492a8573 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/gmxpreprocess/hackblock.h"
 #include "gromacs/utility/basedefinitions.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 struct gmx_residuetype_t;
 struct t_atoms;
 struct t_symtab;
@@ -57,8 +53,4 @@ void rename_atoms(const char *xlfile, const char *ffdir,
                   gmx_bool bResname, struct gmx_residuetype_t *rt, gmx_bool bReorderNum,
                   gmx_bool bVerbose);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 36eed9785030d2fd6042eab96251796b4c002001..a21df8058428b0880ec43ab0e049247ab04764a7 100644 (file)
@@ -61,6 +61,7 @@
 #endif
 
 #include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/imd/imdsocket.h"
 #include "gromacs/legacyheaders/gmx_ga2la.h"
index c85a99fa2f3954303d804b8fc58892ffa340d3a7..dfe40adafdb4a9642b759cb91b07c9b864b7dfa0 100644 (file)
 #ifndef _checkpoint_h
 #define _checkpoint_h
 
-
 #include "gromacs/fileio/filenm.h"
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/typedefs.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gmx_file_position_t;
+struct t_fileio;
+
 /* the name of the environment variable to disable fsync failure checks with */
 #define GMX_IGNORE_FSYNC_FAILURE_ENV "GMX_IGNORE_FSYNC_FAILURE"
 
@@ -86,7 +87,7 @@ void read_checkpoint_state(const char *fn, int *simulation_part,
                            gmx_int64_t *step, double *t, t_state *state);
 
 /* Read everything that can be stored in t_trxframe from a checkpoint file */
-void read_checkpoint_trxframe(t_fileio *fp, t_trxframe *fr);
+void read_checkpoint_trxframe(struct t_fileio *fp, t_trxframe *fr);
 
 /* Print the complete contents of checkpoint file fn to out */
 void list_checkpoint(const char *fn, FILE *out);
@@ -115,10 +116,10 @@ void read_checkpoint_part_and_step(const char  *filename,
  * \param[out] outputfiles      Pointer to array of output file names from the previous run. Pointer is allocated in this function.
  */
 void
-read_checkpoint_simulation_part_and_filenames(t_fileio             *fp,
-                                              int                  *simulation_part,
-                                              int                  *nfiles,
-                                              gmx_file_position_t **outputfiles);
+read_checkpoint_simulation_part_and_filenames(struct t_fileio             *fp,
+                                              int                         *simulation_part,
+                                              int                         *nfiles,
+                                              struct gmx_file_position_t **outputfiles);
 
 #ifdef __cplusplus
 }
index 667dc9578d67766a21cd0738f899be763044ffb9..f3fb4d9359c07bad98aa5691b2947aa63dede565 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -77,7 +77,7 @@ please_cite(FILE *fp, const char *key);
 namespace gmx
 {
 
-class ProgramContextInterface;
+class IProgramContext;
 
 /*! \brief
  * Settings for printBinaryInformation().
@@ -129,7 +129,7 @@ class BinaryInformationSettings
 
         //! Needed to read the members without otherwise unnecessary accessors.
         friend void printBinaryInformation(
-            FILE *fp, const ProgramContextInterface &programContext,
+            FILE *fp, const IProgramContext &programContext,
             const BinaryInformationSettings &settings);
 };
 
@@ -140,7 +140,7 @@ class BinaryInformationSettings
  * \param[in] programContext Program information object to use.
  */
 void printBinaryInformation(FILE                          *fp,
-                            const ProgramContextInterface &programContext);
+                            const IProgramContext         &programContext);
 /*! \brief
  * Print basic information about the executable with custom settings.
  *
@@ -151,7 +151,7 @@ void printBinaryInformation(FILE                          *fp,
  * \see BinaryInformationSettings
  */
 void printBinaryInformation(FILE                            *fp,
-                            const ProgramContextInterface   &programContext,
+                            const IProgramContext           &programContext,
                             const BinaryInformationSettings &settings);
 
 } // namespace gmx;
index ade929e0815d51ed514701487a6ebe453b1248c0..f12bfed2767f2b35f6255e7b0901a799e59e10e8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -117,11 +117,11 @@ const char *output_env_get_program_display_name(const output_env_t oenv);
 
 namespace gmx
 {
-class ProgramContextInterface;
+class IProgramContext;
 } // namespace gmx
 
 void output_env_init(output_env_t *oenvp,
-                     const gmx::ProgramContextInterface &context,
+                     const gmx::IProgramContext &context,
                      time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
                      int verbosity);
 /* initialize an output_env structure, setting the command line,
@@ -130,9 +130,9 @@ void output_env_init(output_env_t *oenvp,
    the graph formatting type, the verbosity, and debug level */
 
 /*! \brief
- * Returns gmx::ProgramContextInterface from an output_env structure.
+ * Returns gmx::IProgramContext from an output_env structure.
  */
-const gmx::ProgramContextInterface &
+const gmx::IProgramContext &
 output_env_get_program_context(const output_env_t oenv);
 
 #endif
index 33c44a6442059f0aaf6e522bae9b8bdb2ee3a032..c0d8aa99192648668186357c03be75126fb60a33 100644 (file)
@@ -60,6 +60,7 @@ extern "C" {
 /* Abstract type for PME that is defined only in the routine that use them. */
 struct gmx_pme_t;
 struct nonbonded_verlet_t;
+struct bonded_threading_t;
 
 /* Structure describing the data in a single table */
 typedef struct
@@ -185,7 +186,7 @@ typedef struct {
 /* Forward declaration of type for managing Ewald tables */
 struct gmx_ewald_tab_t;
 
-typedef struct f_thread_t f_thread_t;
+typedef struct ewald_corr_thread_t ewald_corr_thread_t;
 
 typedef struct {
     interaction_const_t *ic;
@@ -468,18 +469,14 @@ typedef struct {
     real userreal3;
     real userreal4;
 
-    /* Thread local force and energy data */
-    /* FIXME move to bonded_thread_data_t */
-    int         nthreads;
-    int         red_ashift;
-    int         red_nblock;
-    f_thread_t *f_t;
+    /* Pointer to struct for managing threading of bonded force calculation */
+    struct bonded_threading_t *bonded_threading;
 
-    /* Maximum thread count for uniform distribution of bondeds over threads */
-    int   bonded_max_nthread_uniform;
-
-    /* Exclusion load distribution over the threads */
-    int  *excl_load;
+    /* Ewald correction thread local virial and energy data */
+    int                  nthread_ewc;
+    ewald_corr_thread_t *ewc_t;
+    /* Ewald charge correction load distribution over the threads */
+    int                 *excl_load;
 } t_forcerec;
 
 /* Important: Starting with Gromacs-4.6, the values of c6 and c12 in the nbfp array have
index 59a86026f0ec59730b6b4d1c8d0c11f023bfabf9..7804b0c5ec074b629cf7e80798cacd14e9829316 100644 (file)
@@ -59,8 +59,8 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/mshift.h"
-#include "gromacs/pbcutil/pbc-simd.h"
 #include "gromacs/pbcutil/pbc.h"
+#include "gromacs/pbcutil/pbc-simd.h"
 #include "gromacs/simd/simd.h"
 #include "gromacs/simd/simd_math.h"
 #include "gromacs/simd/vector_operations.h"
index 3f68624adddcea65c36c0ae5bb72e319f9182611..1fa6afccd2635c5f5a678dc3d9779f975f4b2b8b 100644 (file)
 #include "gromacs/listed-forces/bonded.h"
 #include "gromacs/listed-forces/position-restraints.h"
 #include "gromacs/math/vec.h"
-#include "gromacs/mdlib/forcerec-threading.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/simd/simd.h"
 #include "gromacs/timing/wallcycle.h"
 #include "gromacs/utility/smalloc.h"
 
+#include "listed-internal.h"
 #include "pairs.h"
 
 namespace
@@ -405,14 +405,18 @@ void calc_listed(const gmx_multisim_t *ms,
                  t_fcdata *fcd, int *global_atom_index,
                  int force_flags)
 {
-    gmx_bool      bCalcEnerVir;
-    int           i;
-    real          dvdl[efptNR]; /* The dummy array is to have a place to store the dhdl at other values
-                                                        of lambda, which will be thrown away in the end*/
-    const  t_pbc *pbc_null;
-    int           thread;
+    struct bonded_threading_t *bt;
+    gmx_bool                   bCalcEnerVir;
+    int                        i;
+    /* The dummy array is to have a place to store the dhdl at other values
+       of lambda, which will be thrown away in the end */
+    real                       dvdl[efptNR];
+    const  t_pbc              *pbc_null;
+    int                        thread;
+
+    bt = fr->bonded_threading;
 
-    assert(fr->nthreads == idef->nthreads);
+    assert(bt->nthreads == idef->nthreads);
 
     bCalcEnerVir = (force_flags & (GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY));
 
@@ -485,8 +489,8 @@ void calc_listed(const gmx_multisim_t *ms,
     }
 
     wallcycle_sub_start(wcycle, ewcsLISTED);
-#pragma omp parallel for num_threads(fr->nthreads) schedule(static)
-    for (thread = 0; thread < fr->nthreads; thread++)
+#pragma omp parallel for num_threads(bt->nthreads) schedule(static)
+    for (thread = 0; thread < bt->nthreads; thread++)
     {
         int                ftype;
         real              *epot, v;
@@ -505,14 +509,14 @@ void calc_listed(const gmx_multisim_t *ms,
         }
         else
         {
-            zero_thread_forces(&fr->f_t[thread], fr->natoms_force,
-                               fr->red_nblock, 1<<fr->red_ashift);
-
-            ft     = fr->f_t[thread].f;
-            fshift = fr->f_t[thread].fshift;
-            epot   = fr->f_t[thread].ener;
-            grpp   = &fr->f_t[thread].grpp;
-            dvdlt  = fr->f_t[thread].dvdl;
+            zero_thread_forces(&bt->f_t[thread], fr->natoms_force,
+                               bt->red_nblock, 1<<bt->red_ashift);
+
+            ft     = bt->f_t[thread].f;
+            fshift = bt->f_t[thread].fshift;
+            epot   = bt->f_t[thread].ener;
+            grpp   = &bt->f_t[thread].grpp;
+            dvdlt  = bt->f_t[thread].dvdl;
         }
         /* Loop over all bonded force types to calculate the bonded forces */
         for (ftype = 0; (ftype < F_NRE); ftype++)
@@ -530,13 +534,13 @@ void calc_listed(const gmx_multisim_t *ms,
     }
     wallcycle_sub_stop(wcycle, ewcsLISTED);
 
-    if (fr->nthreads > 1)
+    if (bt->nthreads > 1)
     {
         wallcycle_sub_start(wcycle, ewcsLISTED_BUF_OPS);
         reduce_thread_forces(fr->natoms_force, f, fr->fshift,
                              enerd->term, &enerd->grpp, dvdl,
-                             fr->nthreads, fr->f_t,
-                             fr->red_nblock, 1<<fr->red_ashift,
+                             bt->nthreads, bt->f_t,
+                             bt->red_nblock, 1<<bt->red_ashift,
                              bCalcEnerVir,
                              force_flags & GMX_FORCE_DHDL);
         wallcycle_sub_stop(wcycle, ewcsLISTED_BUF_OPS);
index 7e2982bc1dae7c000e412464b26c0f7bd80eee13..a6fa29c174f8f0e80160af86c960f6448d27c30a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_LISTED_FORCES_LISTED_INTERNAL_H
 #define GMX_LISTED_FORCES_LISTED_INTERNAL_H
 
+#include "gromacs/legacyheaders/types/forcerec.h"
+#include "gromacs/math/vectypes.h"
+#include "gromacs/topology/idef.h"
+#include "gromacs/utility/bitmask.h"
+
+/*! \internal \brief struct with output for bonded forces, used per thread */
+typedef struct
+{
+    rvec             *f;            /**< Force array */
+    int               f_nalloc;     /**< Allocation size of f */
+    gmx_bitmask_t     red_mask;     /**< Mask for marking which parts of f are filled */
+    rvec             *fshift;       /**< Shift force array, size SHIFTS */
+    real              ener[F_NRE];  /**< Energy array */
+    gmx_grppairener_t grpp;         /**< Group pair energy data for pairs */
+    real              dvdl[efptNR]; /**< Free-energy dV/dl output */
+}
+f_thread_t;
+
+/*! \internal \brief struct contain all data for bonded force threading */
+struct bonded_threading_t
+{
+    /* Thread local force and energy data */
+    int         nthreads;   /**< Number of threads to be used for bondeds */
+    int         red_ashift; /**< Size of force reduction blocks in bits */
+    int         red_nblock; /**< The number of force blocks to reduce */
+    f_thread_t *f_t;        /**< Force/enegry data per thread, size nthreads */
+
+    /* There are two different ways to distribute the bonded force calculation
+     * over the threads. We dedice which to use based on the number of threads.
+     */
+    int bonded_max_nthread_uniform; /**< Maximum thread count for uniform distribution of bondeds over threads */
+};
+
+
 /*! \brief Returns the global topology atom number belonging to local
  * atom index i.
  *
index b703d3d8ce0ff5162ac8f7c75d7991ff4cda3aee..183b819befd4c2db6552cc8b9389e8cfcd19a283 100644 (file)
 
 #include "gromacs/legacyheaders/gmx_omp_nthreads.h"
 #include "gromacs/listed-forces/listed-forces.h"
-#include "gromacs/mdlib/forcerec-threading.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
 
+#include "listed-internal.h"
+
 /*! \brief struct for passing all data required for a function type */
 typedef struct {
     int      ftype; /**< the function type index */
@@ -343,65 +344,68 @@ const int maxBlockBits = BITMASK_SIZE;
 
 void setup_bonded_threading(t_forcerec *fr, t_idef *idef)
 {
-    int t;
-    int ctot, c, b;
+    bonded_threading_t *bt;
+    int                 t;
+    int                 ctot, c, b;
+
+    bt = fr->bonded_threading;
 
-    assert(fr->nthreads >= 1);
+    assert(bt->nthreads >= 1);
 
     /* Divide the bonded interaction over the threads */
     divide_bondeds_over_threads(idef,
-                                fr->nthreads,
-                                fr->bonded_max_nthread_uniform);
+                                bt->nthreads,
+                                bt->bonded_max_nthread_uniform);
 
-    if (fr->nthreads == 1)
+    if (bt->nthreads == 1)
     {
-        fr->red_nblock = 0;
+        bt->red_nblock = 0;
 
         return;
     }
 
-    fr->red_ashift = 6;
-    while (fr->natoms_force > (int)(maxBlockBits*(1U<<fr->red_ashift)))
+    bt->red_ashift = 6;
+    while (fr->natoms_force > (int)(maxBlockBits*(1U<<bt->red_ashift)))
     {
-        fr->red_ashift++;
+        bt->red_ashift++;
     }
     if (debug)
     {
         fprintf(debug, "bonded force buffer block atom shift %d bits\n",
-                fr->red_ashift);
+                bt->red_ashift);
     }
 
     /* Determine to which blocks each thread's bonded force calculation
      * contributes. Store this is a mask for each thread.
      */
-#pragma omp parallel for num_threads(fr->nthreads) schedule(static)
-    for (t = 1; t < fr->nthreads; t++)
+#pragma omp parallel for num_threads(bt->nthreads) schedule(static)
+    for (t = 1; t < bt->nthreads; t++)
     {
-        calc_bonded_reduction_mask(&fr->f_t[t].red_mask,
-                                   idef, fr->red_ashift, t, fr->nthreads);
+        calc_bonded_reduction_mask(&bt->f_t[t].red_mask,
+                                   idef, bt->red_ashift, t, bt->nthreads);
     }
 
     /* Determine the maximum number of blocks we need to reduce over */
-    fr->red_nblock = 0;
+    bt->red_nblock = 0;
     ctot           = 0;
-    for (t = 0; t < fr->nthreads; t++)
+    for (t = 0; t < bt->nthreads; t++)
     {
         c = 0;
         for (b = 0; b < maxBlockBits; b++)
         {
-            if (bitmask_is_set(fr->f_t[t].red_mask, b))
+            if (bitmask_is_set(bt->f_t[t].red_mask, b))
             {
-                fr->red_nblock = std::max(fr->red_nblock, b+1);
+                bt->red_nblock = std::max(bt->red_nblock, b+1);
                 c++;
             }
         }
         if (debug)
         {
 #if BITMASK_SIZE <= 64 //move into bitmask when it is C++
-            std::string flags = gmx::formatString("%x", fr->f_t[t].red_mask);
+            std::string flags = gmx::formatString("%x", bt->f_t[t].red_mask);
 #else
-            std::string flags = gmx::formatAndJoin(fr->f_t[t].red_mask,
-                                                   fr->f_t[t].red_mask+BITMASK_ALEN,
+            std::string flags = gmx::formatAndJoin(bt->f_t[t].red_mask,
+                                                   bt->f_t[t].red_mask+BITMASK_ALEN,
                                                    "", gmx::StringFormatter("%x"));
 #endif
             fprintf(debug, "thread %d flags %s count %d\n",
@@ -412,38 +416,43 @@ void setup_bonded_threading(t_forcerec *fr, t_idef *idef)
     if (debug)
     {
         fprintf(debug, "Number of blocks to reduce: %d of size %d\n",
-                fr->red_nblock, 1<<fr->red_ashift);
+                bt->red_nblock, 1<<bt->red_ashift);
         fprintf(debug, "Reduction density %.2f density/#thread %.2f\n",
-                ctot*(1<<fr->red_ashift)/(double)fr->natoms_force,
-                ctot*(1<<fr->red_ashift)/(double)(fr->natoms_force*fr->nthreads));
+                ctot*(1<<bt->red_ashift)/(double)fr->natoms_force,
+                ctot*(1<<bt->red_ashift)/(double)(fr->natoms_force*bt->nthreads));
     }
 }
 
-void init_bonded_threading(FILE *fplog, t_forcerec *fr, int nenergrp)
+void init_bonded_threading(FILE *fplog, int nenergrp,
+                           struct bonded_threading_t **bt_ptr)
 {
+    bonded_threading_t *bt;
+
+    snew(bt, 1);
+
     /* These thread local data structures are used for bondeds only */
-    fr->nthreads = gmx_omp_nthreads_get(emntBonded);
+    bt->nthreads = gmx_omp_nthreads_get(emntBonded);
 
-    if (fr->nthreads > 1)
+    if (bt->nthreads > 1)
     {
         int t;
 
-        snew(fr->f_t, fr->nthreads);
-#pragma omp parallel for num_threads(fr->nthreads) schedule(static)
-        for (t = 0; t < fr->nthreads; t++)
+        snew(bt->f_t, bt->nthreads);
+#pragma omp parallel for num_threads(bt->nthreads) schedule(static)
+        for (t = 0; t < bt->nthreads; t++)
         {
             /* Thread 0 uses the global force and energy arrays */
             if (t > 0)
             {
                 int i;
 
-                fr->f_t[t].f        = NULL;
-                fr->f_t[t].f_nalloc = 0;
-                snew(fr->f_t[t].fshift, SHIFTS);
-                fr->f_t[t].grpp.nener = nenergrp*nenergrp;
+                bt->f_t[t].f        = NULL;
+                bt->f_t[t].f_nalloc = 0;
+                snew(bt->f_t[t].fshift, SHIFTS);
+                bt->f_t[t].grpp.nener = nenergrp*nenergrp;
                 for (i = 0; i < egNR; i++)
                 {
-                    snew(fr->f_t[t].grpp.ener[i], fr->f_t[t].grpp.nener);
+                    snew(bt->f_t[t].grpp.ener[i], bt->f_t[t].grpp.nener);
                 }
             }
         }
@@ -457,16 +466,18 @@ void init_bonded_threading(FILE *fplog, t_forcerec *fr, int nenergrp)
 
         if ((ptr = getenv("GMX_BONDED_NTHREAD_UNIFORM")) != NULL)
         {
-            sscanf(ptr, "%d", &fr->bonded_max_nthread_uniform);
+            sscanf(ptr, "%d", &bt->bonded_max_nthread_uniform);
             if (fplog != NULL)
             {
                 fprintf(fplog, "\nMax threads for uniform bonded distribution set to %d by env.var.\n",
-                        fr->bonded_max_nthread_uniform);
+                        bt->bonded_max_nthread_uniform);
             }
         }
         else
         {
-            fr->bonded_max_nthread_uniform = max_nthread_uniform;
+            bt->bonded_max_nthread_uniform = max_nthread_uniform;
         }
     }
+
+    *bt_ptr = bt;
 }
index 2096ec63ae1b719f7ebebb5011675cd079d5a28a..c8718da6eb5d71266a3a7e108fa16559ace548b6 100644 (file)
@@ -60,8 +60,13 @@ extern "C" {
  */
 void setup_bonded_threading(t_forcerec *fr, t_idef *idef);
 
-/*! \brief Initialize the bonded threading data structures */
-void init_bonded_threading(FILE *fplog, t_forcerec *fr, int nenergrp);
+/*! \brief Initialize the bonded threading data structures
+ *
+ * Allocates and initializes a bonded threading data structure.
+ * A pointer to this struct is returned as \p *bb_ptr.
+ */
+void init_bonded_threading(FILE *fplog, int nenergrp,
+                           struct bonded_threading_t **bt_ptr);
 
 #ifdef __cplusplus
 }
index 25f24b5beb913c33f738adad63857cdd8f30ff3b..646ecfe2e12ad735a2818c89cb3e5a6ddfaff747 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -177,7 +177,7 @@ static const double
 
 double gmx_erfd(double x)
 {
-#ifdef GMX_FLOAT_FORMAT_IEEE754
+#if GMX_FLOAT_FORMAT_IEEE754
     gmx_int32_t hx, ix, i;
     double      R, S, P, Q, s, y, z, r;
 
@@ -190,7 +190,7 @@ double gmx_erfd(double x)
 
     conv.d = x;
 
-#ifdef GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
+#if GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
     hx = conv.i[0];
 #else
     hx = conv.i[1];
@@ -266,7 +266,7 @@ double gmx_erfd(double x)
 
     conv.d = x;
 
-#ifdef GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
+#if GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
     conv.i[1] = 0;
 #else
     conv.i[0] = 0;
@@ -292,7 +292,7 @@ double gmx_erfd(double x)
 
 double gmx_erfcd(double x)
 {
-#ifdef GMX_FLOAT_FORMAT_IEEE754
+#if GMX_FLOAT_FORMAT_IEEE754
     gmx_int32_t hx, ix;
     double      R, S, P, Q, s, y, z, r;
 
@@ -305,7 +305,7 @@ double gmx_erfcd(double x)
 
     conv.d = x;
 
-#ifdef GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
+#if GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
     hx = conv.i[0];
 #else
     hx = conv.i[1];
@@ -383,7 +383,7 @@ double gmx_erfcd(double x)
 
         conv.d = x;
 
-#ifdef GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
+#if GMX_IEEE754_BIG_ENDIAN_WORD_ORDER
         conv.i[1] = 0;
 #else
         conv.i[0] = 0;
@@ -857,7 +857,7 @@ int gmx_greatest_common_divisor(int p, int q)
 
 int gmx_feenableexcept()
 {
-#ifdef HAVE_FEENABLEEXCEPT
+#if HAVE_FEENABLEEXCEPT
     return feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
 #elif (defined(__i386__) || defined(__x86_64__)) && defined(__APPLE__)
     /* Author:  David N. Williams
index d5ee22cbe1b3fead8a6a22449034d044fb1d47eb..17ef70662e5eb3ee4d100686e8e40d533fcd8161 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -841,7 +841,7 @@ static gmx_inline real _divide_err(real a, real b, const char *file, int line)
     return a/b;
 }
 
-static gmx_inline int _mod(int a, int b, char *file, int line)
+static gmx_inline int _mod(int a, int b, const char *file, int line)
 {
     if (b == 0)
     {
index aa36491198b78feefedd16c586fbec81076ddec6..8f1bf9150f323ad134bc9bdc5ccc44162570c472 100644 (file)
@@ -46,7 +46,6 @@
 #include <algorithm>
 
 #include "gromacs/domdec/domdec.h"
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/constr.h"
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/gmx_omp_nthreads.h"
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
-#include "gromacs/pbcutil/pbc-simd.h"
 #include "gromacs/pbcutil/pbc.h"
+#include "gromacs/pbcutil/pbc-simd.h"
 #include "gromacs/simd/simd.h"
 #include "gromacs/simd/simd_math.h"
 #include "gromacs/simd/vector_operations.h"
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/utility/bitmask.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/gmxomp.h"
 #include "gromacs/utility/smalloc.h"
index d0169dcdc28d4af97d65db9e4a2e5d454520ac33..0a7d423ccf629ff5d1359c6da25030059f2749d9 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/random/random.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 8056f1f9bf252e0cec24df9997742506017fc105..0fa41a72f6f7716d173810a5d4aba0028f10fbc2 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -46,6 +46,7 @@
 #include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index f1a1bce5e8f7ddb1938771ae27f55a58514473ed..402662de4c31989a0eb6c13f3a657c3fe60cd7cd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,7 +40,6 @@
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/legacyheaders/calcmu.h"
 #include "gromacs/legacyheaders/chargegroup.h"
index d11bf98797cb09c62decffaa535145f606e9740d..e27e347587d05bdebe58eb1f7063116d067e9c8c 100644 (file)
@@ -67,6 +67,7 @@
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/timing/wallcycle.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -112,34 +113,22 @@ void ns(FILE              *fp,
     }
 }
 
-static void reduce_thread_forces(int n, rvec *f,
-                                 tensor vir_q, tensor vir_lj,
-                                 real *Vcorr_q, real *Vcorr_lj,
-                                 real *dvdl_q, real *dvdl_lj,
-                                 int nthreads, f_thread_t *f_t)
+static void reduce_thread_energies(tensor vir_q, tensor vir_lj,
+                                   real *Vcorr_q, real *Vcorr_lj,
+                                   real *dvdl_q, real *dvdl_lj,
+                                   int nthreads,
+                                   ewald_corr_thread_t *ewc_t)
 {
-    int t, i;
-    int nthreads_loop gmx_unused;
+    int t;
 
-    // cppcheck-suppress unreadVariable
-    nthreads_loop = gmx_omp_nthreads_get(emntBonded);
-    /* This reduction can run over any number of threads */
-#pragma omp parallel for num_threads(nthreads_loop) private(t) schedule(static)
-    for (i = 0; i < n; i++)
-    {
-        for (t = 1; t < nthreads; t++)
-        {
-            rvec_inc(f[i], f_t[t].f[i]);
-        }
-    }
     for (t = 1; t < nthreads; t++)
     {
-        *Vcorr_q  += f_t[t].Vcorr_q;
-        *Vcorr_lj += f_t[t].Vcorr_lj;
-        *dvdl_q   += f_t[t].dvdl[efptCOUL];
-        *dvdl_lj  += f_t[t].dvdl[efptVDW];
-        m_add(vir_q, f_t[t].vir_q, vir_q);
-        m_add(vir_lj, f_t[t].vir_lj, vir_lj);
+        *Vcorr_q  += ewc_t[t].Vcorr_q;
+        *Vcorr_lj += ewc_t[t].Vcorr_lj;
+        *dvdl_q   += ewc_t[t].dvdl[efptCOUL];
+        *dvdl_lj  += ewc_t[t].dvdl[efptVDW];
+        m_add(vir_q, ewc_t[t].vir_q, vir_q);
+        m_add(vir_lj, ewc_t[t].vir_lj, vir_lj);
     }
 }
 
@@ -439,17 +428,14 @@ void do_force_lowlevel(t_forcerec *fr,      t_inputrec *ir,
                     gmx_fatal(FARGS, "TPI with PME currently only works in a 3D geometry with tin-foil boundary conditions");
                 }
 
-                nthreads = gmx_omp_nthreads_get(emntBonded);
+                nthreads = fr->nthread_ewc;
 #pragma omp parallel for num_threads(nthreads) schedule(static)
                 for (t = 0; t < nthreads; t++)
                 {
-                    int     i;
-                    rvec   *fnv;
                     tensor *vir_q, *vir_lj;
                     real   *Vcorrt_q, *Vcorrt_lj, *dvdlt_q, *dvdlt_lj;
                     if (t == 0)
                     {
-                        fnv       = fr->f_novirsum;
                         vir_q     = &fr->vir_el_recip;
                         vir_lj    = &fr->vir_lj_recip;
                         Vcorrt_q  = &Vcorr_q;
@@ -459,23 +445,23 @@ void do_force_lowlevel(t_forcerec *fr,      t_inputrec *ir,
                     }
                     else
                     {
-                        fnv       = fr->f_t[t].f;
-                        vir_q     = &fr->f_t[t].vir_q;
-                        vir_lj    = &fr->f_t[t].vir_lj;
-                        Vcorrt_q  = &fr->f_t[t].Vcorr_q;
-                        Vcorrt_lj = &fr->f_t[t].Vcorr_lj;
-                        dvdlt_q   = &fr->f_t[t].dvdl[efptCOUL];
-                        dvdlt_lj  = &fr->f_t[t].dvdl[efptVDW];
-                        for (i = 0; i < fr->natoms_force; i++)
-                        {
-                            clear_rvec(fnv[i]);
-                        }
+                        vir_q     = &fr->ewc_t[t].vir_q;
+                        vir_lj    = &fr->ewc_t[t].vir_lj;
+                        Vcorrt_q  = &fr->ewc_t[t].Vcorr_q;
+                        Vcorrt_lj = &fr->ewc_t[t].Vcorr_lj;
+                        dvdlt_q   = &fr->ewc_t[t].dvdl[efptCOUL];
+                        dvdlt_lj  = &fr->ewc_t[t].dvdl[efptVDW];
                         clear_mat(*vir_q);
                         clear_mat(*vir_lj);
                     }
                     *dvdlt_q  = 0;
                     *dvdlt_lj = 0;
 
+                    /* Threading is only supported with the Verlet cut-off
+                     * scheme and then only single particle forces (no
+                     * exclusion forces) are calculated, so we can store
+                     * the forces in the normal, single fr->f_novirsum array.
+                     */
                     ewald_LRcorrection(fr->excl_load[t], fr->excl_load[t+1],
                                        cr, t, fr,
                                        md->chargeA, md->chargeB,
@@ -487,19 +473,18 @@ void do_force_lowlevel(t_forcerec *fr,      t_inputrec *ir,
                                        excl, x, bSB ? boxs : box, mu_tot,
                                        ir->ewald_geometry,
                                        ir->epsilon_surface,
-                                       fnv, *vir_q, *vir_lj,
+                                       fr->f_novirsum, *vir_q, *vir_lj,
                                        Vcorrt_q, Vcorrt_lj,
                                        lambda[efptCOUL], lambda[efptVDW],
                                        dvdlt_q, dvdlt_lj);
                 }
                 if (nthreads > 1)
                 {
-                    reduce_thread_forces(fr->natoms_force, fr->f_novirsum,
-                                         fr->vir_el_recip, fr->vir_lj_recip,
-                                         &Vcorr_q, &Vcorr_lj,
-                                         &dvdl_long_range_correction_q,
-                                         &dvdl_long_range_correction_lj,
-                                         nthreads, fr->f_t);
+                    reduce_thread_energies(fr->vir_el_recip, fr->vir_lj_recip,
+                                           &Vcorr_q, &Vcorr_lj,
+                                           &dvdl_long_range_correction_q,
+                                           &dvdl_long_range_correction_lj,
+                                           nthreads, fr->ewc_t);
                 }
                 wallcycle_sub_stop(wcycle, ewcsEWALD_CORRECTION);
             }
index b40a18ba32ff37607fd32f8fd21b1363286337cf..070b476ec56d5861ad2dd60e8368c9f9c4167884 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_MDLIB_FORCEREC_THREADING_H
 #define GMX_MDLIB_FORCEREC_THREADING_H
 
-#include "gromacs/utility/bitmask.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-struct f_thread_t {
-    rvec             *f;
-    int               f_nalloc;
-    gmx_bitmask_t     red_mask; /* Mask for marking which parts of f are filled */
-    rvec             *fshift;
-    real              ener[F_NRE];
-    gmx_grppairener_t grpp;
+struct ewald_corr_thread_t {
     real              Vcorr_q;
     real              Vcorr_lj;
     real              dvdl[efptNR];
index 91f5c5f0893e2bc917be75426565b569b69a5ee0..b04b09a16baed48e9a6ec1ebe9ffc45ea7ebb0e5 100644 (file)
@@ -80,6 +80,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/simd/simd.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -3211,9 +3212,12 @@ void init_forcerec(FILE              *fp,
     }
 
     /* Initialize the thread working data for bonded interactions */
-    init_bonded_threading(fp, fr, mtop->groups.grps[egcENER].nr);
+    init_bonded_threading(fp, mtop->groups.grps[egcENER].nr,
+                          &fr->bonded_threading);
 
-    snew(fr->excl_load, fr->nthreads+1);
+    fr->nthread_ewc = gmx_omp_nthreads_get(emntBonded);
+    snew(fr->ewc_t, fr->nthread_ewc);
+    snew(fr->excl_load, fr->nthread_ewc + 1);
 
     /* fr->ic is used both by verlet and group kernels (to some extent) now */
     init_interaction_const(fp, &fr->ic, fr);
@@ -3284,9 +3288,9 @@ void forcerec_set_excl_load(t_forcerec           *fr,
     fr->excl_load[0] = 0;
     n                = 0;
     i                = 0;
-    for (t = 1; t <= fr->nthreads; t++)
+    for (t = 1; t <= fr->nthread_ewc; t++)
     {
-        ntarget = (ntot*t)/fr->nthreads;
+        ntarget = (ntot*t)/fr->nthread_ewc;
         while (i < top->excls.nr && n < ntarget)
         {
             for (j = ind[i]; j < ind[i+1]; j++)
similarity index 86%
rename from src/gromacs/mdlib/genborn.c
rename to src/gromacs/mdlib/genborn.cpp
index a4f34b8ad597615babffb9cc025b5d36dd3ed812..ebcd9b327d81b9e5256a28c4ad7adb3dff944833 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/legacyheaders/genborn.h"
 
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/legacyheaders/names.h"
@@ -51,6 +54,7 @@
 #include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/mdlib/genborn_allvsall.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/gmxmpi.h"
 #include "gromacs/utility/smalloc.h"
 
-#ifdef GMX_SIMD_X86_SSE2_OR_HIGHER
-#  ifdef GMX_DOUBLE
-#    include "gromacs/mdlib/genborn_allvsall_sse2_double.h"
-#    include "gromacs/mdlib/genborn_sse2_double.h"
-#  else
-#    include "gromacs/mdlib/genborn_allvsall_sse2_single.h"
-#    include "gromacs/mdlib/genborn_sse2_single.h"
-#  endif /* GMX_DOUBLE */
-#endif   /* SSE or AVX present */
-
-#include "gromacs/mdlib/genborn_allvsall.h"
-
-/*#define DISABLE_SSE*/
 
 typedef struct {
     int  shift;
@@ -131,12 +122,8 @@ static int init_gb_still(const t_atomtypes *atype, t_idef *idef, t_atoms *atoms,
                          gmx_genborn_t *born, int natoms)
 {
 
-    int   i, j, i1, i2, k, m, nbond, nang, ia, ib, ic, id, nb, idx, idx2, at;
-    int   iam, ibm;
-    int   at0, at1;
-    real  length, angle;
-    real  r, ri, rj, ri2, ri3, rj2, r2, r3, r4, rk, ratio, term, h, doffset;
-    real  p1, p2, p3, factor, cosine, rab, rbc;
+    int   i, j, m, ia, ib;
+    real  r, ri, rj, ri2, rj2, r3, r4, ratio, term, h, doffset;
 
     real *vsol;
     real *gp;
@@ -145,9 +132,6 @@ static int init_gb_still(const t_atomtypes *atype, t_idef *idef, t_atoms *atoms,
     snew(gp, natoms);
     snew(born->gpol_still_work, natoms+3);
 
-    at0 = 0;
-    at1 = natoms;
-
     doffset = born->gb_doffset;
 
     for (i = 0; i < natoms; i++)
@@ -177,7 +161,6 @@ static int init_gb_still(const t_atomtypes *atype, t_idef *idef, t_atoms *atoms,
         rj   = atype->gb_radius[atoms->atom[ib].type];
 
         ri2  = ri*ri;
-        ri3  = ri2*ri;
         rj2  = rj*rj;
 
         ratio  = (rj2-ri2-r*r)/(2*ri*r);
@@ -249,8 +232,8 @@ int init_gb(gmx_genborn_t **p_born,
             t_forcerec *fr, const t_inputrec *ir,
             const gmx_mtop_t *mtop, int gb_algorithm)
 {
-    int             i, j, m, ai, aj, jj, natoms, nalloc;
-    real            rai, sk, p, doffset;
+    int             i, jj, natoms;
+    real            rai, sk, doffset;
 
     t_atoms         atoms;
     gmx_genborn_t  *born;
@@ -375,10 +358,10 @@ calc_gb_rad_still(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
                   rvec x[], t_nblist *nl,
                   gmx_genborn_t *born, t_mdatoms *md)
 {
-    int  i, k, n, nj0, nj1, ai, aj, type;
+    int  i, k, n, nj0, nj1, ai, aj;
     int  shift;
     real shX, shY, shZ;
-    real gpi, dr, dr2, dr4, idr4, rvdw, ratio, ccf, theta, term, rai, raj;
+    real gpi, dr2, idr4, rvdw, ratio, ccf, theta, term, rai, raj;
     real ix1, iy1, iz1, jx1, jy1, jz1, dx11, dy11, dz11;
     real rinv, idr2, idr6, vaj, dccf, cosq, sinq, prod, gpi2;
     real factor;
@@ -503,14 +486,14 @@ calc_gb_rad_hct(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
                 rvec x[], t_nblist *nl,
                 gmx_genborn_t *born, t_mdatoms *md)
 {
-    int   i, k, n, ai, aj, nj0, nj1, at0, at1;
+    int   i, k, n, ai, aj, nj0, nj1;
     int   shift;
     real  shX, shY, shZ;
-    real  rai, raj, gpi, dr2, dr, sk, sk_ai, sk2, sk2_ai, lij, uij, diff2, tmp, sum_ai;
+    real  rai, raj, dr2, dr, sk, sk_ai, sk2, sk2_ai, lij, uij, diff2, tmp, sum_ai;
     real  rad, min_rad, rinv, rai_inv;
     real  ix1, iy1, iz1, jx1, jy1, jz1, dx11, dy11, dz11;
     real  lij2, uij2, lij3, uij3, t1, t2, t3;
-    real  lij_inv, dlij, duij, sk2_rinv, prod, log_term;
+    real  lij_inv, dlij, sk2_rinv, prod, log_term;
     real  doffset, raj_inv, dadx_val;
     real *gb_radius;
 
@@ -524,7 +507,6 @@ calc_gb_rad_hct(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
 
     /* Keep the compiler happy */
     n    = 0;
-    prod = 0;
 
     for (i = 0; i < nl->nri; i++)
     {
@@ -597,7 +579,7 @@ calc_gb_rad_hct(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
                 sk2_rinv = sk2*rinv;
                 prod     = 0.25*sk2_rinv;
 
-                log_term = log(uij*lij_inv);
+                log_term = std::log(uij*lij_inv);
 
                 tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term +
                     prod*(-diff2);
@@ -653,7 +635,7 @@ calc_gb_rad_hct(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
 
                 /* log_term = table_log(uij*lij_inv,born->log_table,
                    LOG_TABLE_ACCURACY); */
-                log_term = log(uij*lij_inv);
+                log_term = std::log(uij*lij_inv);
 
                 tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term +
                     prod*(-diff2);
@@ -698,7 +680,7 @@ calc_gb_rad_hct(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
             min_rad = rai + doffset;
             rad     = 1.0/sum_ai;
 
-            born->bRad[i]   = rad > min_rad ? rad : min_rad;
+            born->bRad[i]   = std::max(rad, min_rad);
             fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
         }
     }
@@ -718,21 +700,19 @@ static int
 calc_gb_rad_obc(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
                 rvec x[], t_nblist *nl, gmx_genborn_t *born, t_mdatoms *md)
 {
-    int   i, k, ai, aj, nj0, nj1, n, at0, at1;
+    int   i, k, ai, aj, nj0, nj1, n;
     int   shift;
     real  shX, shY, shZ;
-    real  rai, raj, gpi, dr2, dr, sk, sk2, lij, uij, diff2, tmp, sum_ai;
-    real  rad, min_rad, sum_ai2, sum_ai3, tsum, tchain, rinv, rai_inv, lij_inv, rai_inv2;
+    real  rai, raj, dr2, dr, sk, sk2, lij, uij, diff2, tmp, sum_ai;
+    real  sum_ai2, sum_ai3, tsum, tchain, rinv, rai_inv, lij_inv, rai_inv2;
     real  log_term, prod, sk2_rinv, sk_ai, sk2_ai;
     real  ix1, iy1, iz1, jx1, jy1, jz1, dx11, dy11, dz11;
-    real  lij2, uij2, lij3, uij3, dlij, duij, t1, t2, t3;
+    real  lij2, uij2, lij3, uij3, dlij, t1, t2, t3;
     real  doffset, raj_inv, dadx_val;
     real *gb_radius;
 
     /* Keep the compiler happy */
     n    = 0;
-    prod = 0;
-    raj  = 0;
 
     doffset   = born->gb_doffset;
     gb_radius = born->gb_radius;
@@ -813,7 +793,7 @@ calc_gb_rad_obc(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
                 sk2_rinv = sk2*rinv;
                 prod     = 0.25*sk2_rinv;
 
-                log_term = log(uij*lij_inv);
+                log_term = std::log(uij*lij_inv);
 
                 tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term + prod*(-diff2);
 
@@ -865,7 +845,7 @@ calc_gb_rad_obc(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
                 prod     = 0.25 * sk2_rinv;
 
                 /* log_term = table_log(uij*lij_inv,born->log_table,LOG_TABLE_ACCURACY); */
-                log_term = log(uij*lij_inv);
+                log_term = std::log(uij*lij_inv);
 
                 tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term + prod*(-diff2);
 
@@ -940,7 +920,6 @@ calc_gb_rad_obc(t_commrec *cr, t_forcerec *fr, gmx_localtop_t *top,
 int calc_gb_rad(t_commrec *cr, t_forcerec *fr, t_inputrec *ir, gmx_localtop_t *top,
                 rvec x[], t_nblist *nl, gmx_genborn_t *born, t_mdatoms *md, t_nrnb     *nrnb)
 {
-    real *p;
     int   cnt;
     int   ndadx;
 
@@ -978,43 +957,13 @@ int calc_gb_rad(t_commrec *cr, t_forcerec *fr, t_inputrec *ir, gmx_localtop_t *t
 
         if (ir->gb_algorithm == egbSTILL)
         {
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-            if (fr->use_simd_kernels)
-            {
-#  ifdef GMX_DOUBLE
-                genborn_allvsall_calc_still_radii_sse2_double(fr, md, born, top, x[0], cr, &fr->AllvsAll_workgb);
-#  else
-                genborn_allvsall_calc_still_radii_sse2_single(fr, md, born, top, x[0], cr, &fr->AllvsAll_workgb);
-#  endif
-            }
-            else
-            {
-                genborn_allvsall_calc_still_radii(fr, md, born, top, x[0], cr, &fr->AllvsAll_workgb);
-            }
-#else
             genborn_allvsall_calc_still_radii(fr, md, born, top, x[0], &fr->AllvsAll_workgb);
-#endif
             /* 13 flops in outer loop, 47 flops in inner loop */
             inc_nrnb(nrnb, eNR_BORN_AVA_RADII_STILL, md->homenr*13+cnt*47);
         }
         else if (ir->gb_algorithm == egbHCT || ir->gb_algorithm == egbOBC)
         {
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-            if (fr->use_simd_kernels)
-            {
-#  ifdef GMX_DOUBLE
-                genborn_allvsall_calc_hct_obc_radii_sse2_double(fr, md, born, ir->gb_algorithm, top, x[0], cr, &fr->AllvsAll_workgb);
-#  else
-                genborn_allvsall_calc_hct_obc_radii_sse2_single(fr, md, born, ir->gb_algorithm, top, x[0], cr, &fr->AllvsAll_workgb);
-#  endif
-            }
-            else
-            {
-                genborn_allvsall_calc_hct_obc_radii(fr, md, born, ir->gb_algorithm, top, x[0], cr, &fr->AllvsAll_workgb);
-            }
-#else
             genborn_allvsall_calc_hct_obc_radii(fr, md, born, ir->gb_algorithm, top, x[0], &fr->AllvsAll_workgb);
-#endif
             /* 24 flops in outer loop, 183 in inner */
             inc_nrnb(nrnb, eNR_BORN_AVA_RADII_HCT_OBC, md->homenr*24+cnt*183);
         }
@@ -1028,45 +977,6 @@ int calc_gb_rad(t_commrec *cr, t_forcerec *fr, t_inputrec *ir, gmx_localtop_t *t
     /* Switch for determining which algorithm to use for Born radii calculation */
 #ifdef GMX_DOUBLE
 
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-    /* x86 or x86-64 with GCC inline assembly and/or SSE intrinsics */
-    switch (ir->gb_algorithm)
-    {
-        case egbSTILL:
-            if (fr->use_simd_kernels)
-            {
-                calc_gb_rad_still_sse2_double(cr, fr, born->nr, top, atype, x[0], nl, born);
-            }
-            else
-            {
-                calc_gb_rad_still(cr, fr, top, x, nl, born, md);
-            }
-            break;
-        case egbHCT:
-            if (fr->use_simd_kernels)
-            {
-                calc_gb_rad_hct_obc_sse2_double(cr, fr, born->nr, top, atype, x[0], nl, born, md, ir->gb_algorithm);
-            }
-            else
-            {
-                calc_gb_rad_hct(cr, fr, top, x, nl, born, md);
-            }
-            break;
-        case egbOBC:
-            if (fr->use_simd_kernels)
-            {
-                calc_gb_rad_hct_obc_sse2_double(cr, fr, born->nr, top, atype, x[0], nl, born, md, ir->gb_algorithm);
-            }
-            else
-            {
-                calc_gb_rad_obc(cr, fr, born->nr, top, x, nl, born, md);
-            }
-            break;
-
-        default:
-            gmx_fatal(FARGS, "Unknown double precision sse-enabled algorithm for Born radii calculation: %d", ir->gb_algorithm);
-    }
-#else
     switch (ir->gb_algorithm)
     {
         case egbSTILL:
@@ -1083,51 +993,8 @@ int calc_gb_rad(t_commrec *cr, t_forcerec *fr, t_inputrec *ir, gmx_localtop_t *t
             gmx_fatal(FARGS, "Unknown double precision algorithm for Born radii calculation: %d", ir->gb_algorithm);
     }
 
-#endif
-
 #else
 
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-    /* x86 or x86-64 with GCC inline assembly and/or SSE intrinsics */
-    switch (ir->gb_algorithm)
-    {
-        case egbSTILL:
-            if (fr->use_simd_kernels)
-            {
-                calc_gb_rad_still_sse2_single(cr, fr, born->nr, top, x[0], nl, born);
-            }
-            else
-            {
-                calc_gb_rad_still(cr, fr, top, x, nl, born, md);
-            }
-            break;
-        case egbHCT:
-            if (fr->use_simd_kernels)
-            {
-                calc_gb_rad_hct_obc_sse2_single(cr, fr, born->nr, top, x[0], nl, born, md, ir->gb_algorithm);
-            }
-            else
-            {
-                calc_gb_rad_hct(cr, fr, top, x, nl, born, md);
-            }
-            break;
-
-        case egbOBC:
-            if (fr->use_simd_kernels)
-            {
-                calc_gb_rad_hct_obc_sse2_single(cr, fr, born->nr, top, x[0], nl, born, md, ir->gb_algorithm);
-            }
-            else
-            {
-                calc_gb_rad_obc(cr, fr, born->nr, top, x, nl, born, md);
-            }
-            break;
-
-        default:
-            gmx_fatal(FARGS, "Unknown sse-enabled algorithm for Born radii calculation: %d", ir->gb_algorithm);
-    }
-
-#else
     switch (ir->gb_algorithm)
     {
         case egbSTILL:
@@ -1144,8 +1011,6 @@ int calc_gb_rad(t_commrec *cr, t_forcerec *fr, t_inputrec *ir, gmx_localtop_t *t
             gmx_fatal(FARGS, "Unknown algorithm for Born radii calculation: %d", ir->gb_algorithm);
     }
 
-#endif /* Single precision sse */
-
 #endif /* Double or single precision */
 
     if (fr->bAllvsAll == FALSE)
@@ -1176,14 +1041,14 @@ real gb_bonds_tab(rvec x[], rvec f[], rvec fshift[], real *charge, real *p_gbtab
                   real *invsqrta, real *dvda, real *GBtab, t_idef *idef, real epsilon_r,
                   real gb_epsilon_solvent, real facel, const t_pbc *pbc, const t_graph *graph)
 {
-    int      i, j, n0, m, nnn, type, ai, aj;
+    int      i, j, n0, m, nnn, ai, aj;
     int      ki;
 
     real     isai, isaj;
     real     r, rsq11;
     real     rinv11, iq;
     real     isaprod, qq, gbscale, gbtabscale, Y, F, Geps, Heps2, Fp, VV, FF, rt, eps, eps2;
-    real     vgb, fgb, vcoul, fijC, dvdatmp, fscal, dvdaj;
+    real     vgb, fgb, fijC, dvdatmp, fscal;
     real     vctot;
 
     rvec     dx;
@@ -1223,7 +1088,7 @@ real gb_bonds_tab(rvec x[], rvec f[], rvec fshift[], real *charge, real *p_gbtab
             gbscale       = isaprod*gbtabscale;
             r             = rsq11*rinv11;
             rt            = r*gbscale;
-            n0            = rt;
+            n0            = static_cast<int>(rt);
             eps           = rt-n0;
             eps2          = eps*eps;
             nnn           = 4*n0;
@@ -1312,12 +1177,9 @@ real calc_gb_nonpolar(t_commrec *cr, t_forcerec *fr, int natoms, gmx_genborn_t *
                       real *dvda, t_mdatoms *md)
 {
     int  ai, i, at0, at1;
-    real e, es, rai, rbi, term, probe, tmp, factor;
+    real e, es, rai, term, probe, tmp, factor;
     real rbi_inv, rbi_inv2;
 
-    /* To keep the compiler happy */
-    factor = 0;
-
     if (DOMAINDECOMP(cr))
     {
         at0 = 0;
@@ -1331,19 +1193,6 @@ real calc_gb_nonpolar(t_commrec *cr, t_forcerec *fr, int natoms, gmx_genborn_t *
 
     /* factor is the surface tension */
     factor = born->sa_surface_tension;
-    /*
-
-       // The surface tension factor is 0.0049 for Still model, 0.0054 for HCT/OBC
-       if(gb_algorithm==egbSTILL)
-       {
-          factor=0.0049*100*CAL2JOULE;
-       }
-       else
-       {
-          factor=0.0054*100*CAL2JOULE;
-       }
-     */
-    /* if(gb_algorithm==egbHCT || gb_algorithm==egbOBC) */
 
     es    = 0;
     probe = 0.14;
@@ -1377,11 +1226,10 @@ real calc_gb_chainrule(int natoms, t_nblist *nl, real *dadx, real *dvda, rvec x[
     int          i, k, n, ai, aj, nj0, nj1, n0, n1;
     int          shift;
     real         shX, shY, shZ;
-    real         fgb, fij, rb2, rbi, fix1, fiy1, fiz1;
-    real         ix1, iy1, iz1, jx1, jy1, jz1, dx11, dy11, dz11, rsq11;
-    real         rinv11, tx, ty, tz, rbai, rbaj, fgb_ai;
+    real         fgb, rbi, fix1, fiy1, fiz1;
+    real         ix1, iy1, iz1, jx1, jy1, jz1, dx11, dy11, dz11;
+    real         tx, ty, tz, rbai, rbaj, fgb_ai;
     real        *rb;
-    volatile int idx;
 
     n  = 0;
     rb = born->work;
@@ -1492,9 +1340,7 @@ calc_gb_forces(t_commrec *cr, t_mdatoms *md, gmx_genborn_t *born, gmx_localtop_t
                rvec x[], rvec f[], t_forcerec *fr, t_idef *idef, int gb_algorithm, int sa_algorithm, t_nrnb *nrnb,
                const t_pbc *pbc, const t_graph *graph, gmx_enerdata_t *enerd)
 {
-    real v = 0;
     int  cnt;
-    int  i;
 
     /* PBC or not? */
     const t_pbc *pbc_null;
@@ -1530,48 +1376,15 @@ calc_gb_forces(t_commrec *cr, t_mdatoms *md, gmx_genborn_t *born, gmx_localtop_t
 
     if (fr->bAllvsAll)
     {
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-        if (fr->use_simd_kernels)
-        {
-#  ifdef GMX_DOUBLE
-            genborn_allvsall_calc_chainrule_sse2_double(fr, md, born, x[0], f[0], gb_algorithm, fr->AllvsAll_workgb);
-#  else
-            genborn_allvsall_calc_chainrule_sse2_single(fr, md, born, x[0], f[0], gb_algorithm, fr->AllvsAll_workgb);
-#  endif
-        }
-        else
-        {
-            genborn_allvsall_calc_chainrule(fr, md, born, x[0], f[0], gb_algorithm, fr->AllvsAll_workgb);
-        }
-#else
         genborn_allvsall_calc_chainrule(fr, md, born, x[0], f[0], gb_algorithm, fr->AllvsAll_workgb);
-#endif
         cnt = md->homenr*(md->nr/2+1);
         /* 9 flops for outer loop, 15 for inner */
         inc_nrnb(nrnb, eNR_BORN_AVA_CHAINRULE, md->homenr*9+cnt*15);
         return;
     }
 
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-    if (fr->use_simd_kernels)
-    {
-#  ifdef GMX_DOUBLE
-        calc_gb_chainrule_sse2_double(fr->natoms_force, &(fr->gblist), fr->dadx, fr->dvda, x[0],
-                                      f[0], fr->fshift[0], fr->shift_vec[0], gb_algorithm, born, md);
-#  else
-        calc_gb_chainrule_sse2_single(fr->natoms_force, &(fr->gblist), fr->dadx, fr->dvda, x[0],
-                                      f[0], fr->fshift[0], fr->shift_vec[0], gb_algorithm, born, md);
-#  endif
-    }
-    else
-    {
-        calc_gb_chainrule(fr->natoms_force, &(fr->gblist), fr->dadx, fr->dvda,
-                          x, f, fr->fshift, fr->shift_vec, gb_algorithm, born, md);
-    }
-#else
     calc_gb_chainrule(fr->natoms_force, &(fr->gblist), fr->dadx, fr->dvda,
                       x, f, fr->fshift, fr->shift_vec, gb_algorithm, born);
-#endif
 
     if (!fr->bAllvsAll)
     {
@@ -1627,18 +1440,17 @@ static void add_bondeds_to_gblist(t_ilist *il,
                                   gmx_bool bMolPBC, t_pbc *pbc, t_graph *g, rvec *x,
                                   struct gbtmpnbls *nls)
 {
-    int         ind, j, ai, aj, shift, found;
+    int         ind, j, ai, aj, found;
     rvec        dx;
     ivec        dt;
     gbtmpnbl_t *list;
 
-    shift = CENTRAL;
     for (ind = 0; ind < il->nr; ind += 3)
     {
         ai = il->iatoms[ind+1];
         aj = il->iatoms[ind+2];
 
-        shift = CENTRAL;
+        int shift = CENTRAL;
         if (g != NULL)
         {
             rvec_sub(x[ai], x[aj], dx);
@@ -1690,8 +1502,7 @@ int make_gb_nblist(t_commrec *cr, int gb_algorithm,
                    rvec x[], matrix box,
                    t_forcerec *fr, t_idef *idef, t_graph *graph, gmx_genborn_t *born)
 {
-    int               i, l, ii, j, k, n, nj0, nj1, ai, aj, at0, at1, found, shift, s;
-    int               apa;
+    int               i, j, k, n, nj0, nj1, ai, shift, s;
     t_nblist         *nblist;
     t_pbc             pbc;
 
similarity index 97%
rename from src/gromacs/mdlib/genborn_allvsall.c
rename to src/gromacs/mdlib/genborn_allvsall.cpp
index a18f2e1ac5cbc267a47a4ec97a3bd0b1f1ff1a11..47b14467edf8cce4b91c4fbd27e2802d6c8ae229 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2009, The GROMACS Development Team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,9 @@
 
 #include "genborn_allvsall.h"
 
-#include <math.h>
+#include <cmath>
+
+#include <algorithm>
 
 #include "gromacs/legacyheaders/genborn.h"
 #include "gromacs/legacyheaders/network.h"
@@ -115,12 +117,10 @@ setup_gb_exclusions_and_indices(gmx_allvsallgb2_data_t     *   aadata,
                                 gmx_bool                       bInclude13,
                                 gmx_bool                       bInclude14)
 {
-    int i, j, k, tp;
+    int i, j, k;
     int a1, a2;
-    int nj0, nj1;
     int max_offset;
     int max_excl_offset;
-    int nj;
 
     /* This routine can appear to be a bit complex, but it is mostly book-keeping.
      * To enable the fast all-vs-all kernel we need to be able to stream through all coordinates
@@ -168,7 +168,7 @@ setup_gb_exclusions_and_indices(gmx_allvsallgb2_data_t     *   aadata,
                 }
                 if (k > 0 && k <= max_offset)
                 {
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
+                    max_excl_offset = std::max(k, max_excl_offset);
                 }
             }
         }
@@ -194,7 +194,7 @@ setup_gb_exclusions_and_indices(gmx_allvsallgb2_data_t     *   aadata,
                 }
                 if (k > 0 && k <= max_offset)
                 {
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
+                    max_excl_offset = std::max(k, max_excl_offset);
                 }
             }
         }
@@ -220,11 +220,11 @@ setup_gb_exclusions_and_indices(gmx_allvsallgb2_data_t     *   aadata,
                 }
                 if (k > 0 && k <= max_offset)
                 {
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
+                    max_excl_offset = std::max(k, max_excl_offset);
                 }
             }
         }
-        max_excl_offset = (max_offset < max_excl_offset) ? max_offset : max_excl_offset;
+        max_excl_offset = std::min(max_offset, max_excl_offset);
 
         aadata->jindex_gb[3*i+1] = i+1+max_excl_offset;
 
@@ -329,9 +329,7 @@ genborn_allvsall_setup(gmx_allvsallgb2_data_t     **  p_aadata,
                        gmx_bool                       bInclude13,
                        gmx_bool                       bInclude14)
 {
-    int                     i, j, idx;
     gmx_allvsallgb2_data_t *aadata;
-    real                   *p;
 
     snew(aadata, 1);
     *p_aadata = aadata;
@@ -584,8 +582,6 @@ genborn_allvsall_calc_hct_obc_radii(t_forcerec *           fr,
     ni1                 = mdatoms->homenr;
 
     n       = 0;
-    prod    = 0;
-    raj     = 0;
     doffset = born->gb_doffset;
 
     aadata = *((gmx_allvsallgb2_data_t **)work);
@@ -679,7 +675,7 @@ genborn_allvsall_calc_hct_obc_radii(t_forcerec *           fr,
                     sk2_rinv = sk2*rinv;
                     prod     = 0.25*sk2_rinv;
 
-                    log_term = log(uij*lij_inv);
+                    log_term = std::log(uij*lij_inv);
                     /* log_term = table_log(uij*lij_inv,born->log_table,LOG_TABLE_ACCURACY); */
                     tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term + prod*(-diff2);
 
@@ -730,7 +726,7 @@ genborn_allvsall_calc_hct_obc_radii(t_forcerec *           fr,
                     prod     = 0.25 * sk2_rinv;
 
                     /* log_term = table_log(uij*lij_inv,born->log_table,LOG_TABLE_ACCURACY); */
-                    log_term = log(uij*lij_inv);
+                    log_term = std::log(uij*lij_inv);
 
                     tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term + prod*(-diff2);
 
@@ -806,7 +802,7 @@ genborn_allvsall_calc_hct_obc_radii(t_forcerec *           fr,
                 sk2_rinv = sk2*rinv;
                 prod     = 0.25*sk2_rinv;
 
-                log_term = log(uij*lij_inv);
+                log_term = std::log(uij*lij_inv);
                 /* log_term = table_log(uij*lij_inv,born->log_table,LOG_TABLE_ACCURACY); */
                 tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term + prod*(-diff2);
 
@@ -857,7 +853,7 @@ genborn_allvsall_calc_hct_obc_radii(t_forcerec *           fr,
                 prod     = 0.25 * sk2_rinv;
 
                 /* log_term = table_log(uij*lij_inv,born->log_table,LOG_TABLE_ACCURACY); */
-                log_term = log(uij*lij_inv);
+                log_term = std::log(uij*lij_inv);
 
                 tmp      = lij-uij + 0.25*dr*diff2 + (0.5*rinv)*log_term + prod*(-diff2);
 
@@ -898,7 +894,7 @@ genborn_allvsall_calc_hct_obc_radii(t_forcerec *           fr,
                 min_rad = rai + born->gb_doffset;
                 rad     = 1.0/sum_ai;
 
-                born->bRad[i]   = rad > min_rad ? rad : min_rad;
+                born->bRad[i]   = std::max(rad, min_rad);
                 fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
             }
         }
diff --git a/src/gromacs/mdlib/genborn_allvsall_sse2_double.c b/src/gromacs/mdlib/genborn_allvsall_sse2_double.c
deleted file mode 100644 (file)
index 5847525..0000000
+++ /dev/null
@@ -1,2506 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS Development Team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include <math.h>
-
-#include "gromacs/legacyheaders/genborn.h"
-#include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/types/simple.h"
-#include "gromacs/math/units.h"
-#include "gromacs/math/vec.h"
-#include "gromacs/mdlib/genborn_allvsall.h"
-#include "gromacs/utility/smalloc.h"
-
-
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-
-#include <gmx_sse2_double.h>
-
-
-#define SIMD_WIDTH 2
-#define UNROLLI    2
-#define UNROLLJ    2
-
-
-
-
-
-
-
-
-
-typedef struct
-{
-    int   *      jindex_gb;
-    int   **     prologue_mask_gb;
-    int   **     epilogue_mask;
-    int   *      imask;
-    double *     gb_radius;
-    double *     workparam;
-    double *     work;
-    double *     x_align;
-    double *     y_align;
-    double *     z_align;
-    double *     fx_align;
-    double *     fy_align;
-    double *     fz_align;
-}
-gmx_allvsallgb2_data_t;
-
-
-static int
-calc_maxoffset(int i, int natoms)
-{
-    int maxoffset;
-
-    if ((natoms % 2) == 1)
-    {
-        /* Odd number of atoms, easy */
-        maxoffset = natoms/2;
-    }
-    else if ((natoms % 4) == 0)
-    {
-        /* Multiple of four is hard */
-        if (i < natoms/2)
-        {
-            if ((i % 2) == 0)
-            {
-                maxoffset = natoms/2;
-            }
-            else
-            {
-                maxoffset = natoms/2-1;
-            }
-        }
-        else
-        {
-            if ((i % 2) == 1)
-            {
-                maxoffset = natoms/2;
-            }
-            else
-            {
-                maxoffset = natoms/2-1;
-            }
-        }
-    }
-    else
-    {
-        /* natoms/2 = odd */
-        if ((i % 2) == 0)
-        {
-            maxoffset = natoms/2;
-        }
-        else
-        {
-            maxoffset = natoms/2-1;
-        }
-    }
-
-    return maxoffset;
-}
-
-static void
-setup_gb_exclusions_and_indices(gmx_allvsallgb2_data_t     *   aadata,
-                                t_ilist     *                  ilist,
-                                int                            start,
-                                int                            end,
-                                int                            natoms,
-                                gmx_bool                       bInclude12,
-                                gmx_bool                       bInclude13,
-                                gmx_bool                       bInclude14)
-{
-    int   i, j, k, tp;
-    int   a1, a2;
-    int   ni0, ni1, nj0, nj1, nj;
-    int   imin, imax, iexcl;
-    int   max_offset;
-    int   max_excl_offset;
-    int   firstinteraction;
-    int   ibase;
-    int  *pi;
-
-    /* This routine can appear to be a bit complex, but it is mostly book-keeping.
-     * To enable the fast all-vs-all kernel we need to be able to stream through all coordinates
-     * whether they should interact or not.
-     *
-     * To avoid looping over the exclusions, we create a simple mask that is 1 if the interaction
-     * should be present, otherwise 0. Since exclusions typically only occur when i & j are close,
-     * we create a jindex array with three elements per i atom: the starting point, the point to
-     * which we need to check exclusions, and the end point.
-     * This way we only have to allocate a short exclusion mask per i atom.
-     */
-
-    ni0 = (start/UNROLLI)*UNROLLI;
-    ni1 = ((end+UNROLLI-1)/UNROLLI)*UNROLLI;
-
-    /* Set the interaction mask to only enable the i atoms we want to include */
-    snew(pi, 2*(natoms+UNROLLI+2*SIMD_WIDTH));
-    aadata->imask = (int *) (((size_t) pi + 16) & (~((size_t) 15)));
-    for (i = 0; i < natoms+UNROLLI; i++)
-    {
-        aadata->imask[2*i]   = (i >= start && i < end) ? 0xFFFFFFFF : 0;
-        aadata->imask[2*i+1] = (i >= start && i < end) ? 0xFFFFFFFF : 0;
-    }
-
-    /* Allocate memory for our modified jindex array */
-    snew(aadata->jindex_gb, 4*(natoms+UNROLLI));
-    for (i = 0; i < 4*(natoms+UNROLLI); i++)
-    {
-        aadata->jindex_gb[i] = 0;
-    }
-
-    /* Create the exclusion masks for the prologue part */
-    snew(aadata->prologue_mask_gb, natoms+UNROLLI); /* list of pointers */
-
-    /* First zero everything to avoid uninitialized data */
-    for (i = 0; i < natoms+UNROLLI; i++)
-    {
-        aadata->prologue_mask_gb[i] = NULL;
-    }
-
-    /* Calculate the largest exclusion range we need for each UNROLLI-tuplet of i atoms. */
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        max_excl_offset = -1;
-
-        /* First find maxoffset for the next 4 atoms (or fewer if we are close to end) */
-        imax = ((ibase+UNROLLI) < end) ? (ibase+UNROLLI) : end;
-
-        /* Which atom is the first we (might) interact with? */
-        imin = natoms; /* Guaranteed to be overwritten by one of 'firstinteraction' */
-        for (i = ibase; i < imax; i++)
-        {
-            /* Before exclusions, which atom is the first we (might) interact with? */
-            firstinteraction = i+1;
-            max_offset       = calc_maxoffset(i, natoms);
-
-            if (!bInclude12)
-            {
-                for (j = 0; j < ilist[F_GB12].nr; j += 3)
-                {
-                    a1 = ilist[F_GB12].iatoms[j+1];
-                    a2 = ilist[F_GB12].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k == firstinteraction)
-                    {
-                        firstinteraction++;
-                    }
-                }
-            }
-            if (!bInclude13)
-            {
-                for (j = 0; j < ilist[F_GB13].nr; j += 3)
-                {
-                    a1 = ilist[F_GB13].iatoms[j+1];
-                    a2 = ilist[F_GB13].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k == firstinteraction)
-                    {
-                        firstinteraction++;
-                    }
-                }
-            }
-            if (!bInclude14)
-            {
-                for (j = 0; j < ilist[F_GB14].nr; j += 3)
-                {
-                    a1 = ilist[F_GB14].iatoms[j+1];
-                    a2 = ilist[F_GB14].iatoms[j+2];
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k == firstinteraction)
-                    {
-                        firstinteraction++;
-                    }
-                }
-            }
-            imin = (firstinteraction < imin) ? firstinteraction : imin;
-        }
-        /* round down to j unrolling factor */
-        imin = (imin/UNROLLJ)*UNROLLJ;
-
-        for (i = ibase; i < imax; i++)
-        {
-            max_offset = calc_maxoffset(i, natoms);
-
-            if (!bInclude12)
-            {
-                for (j = 0; j < ilist[F_GB12].nr; j += 3)
-                {
-                    a1 = ilist[F_GB12].iatoms[j+1];
-                    a2 = ilist[F_GB12].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k < imin)
-                    {
-                        k += natoms;
-                    }
-
-                    if (k > i+max_offset)
-                    {
-                        continue;
-                    }
-
-                    k = k - imin;
-
-                    if (k+natoms <= max_offset)
-                    {
-                        k += natoms;
-                    }
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
-                }
-            }
-            if (!bInclude13)
-            {
-                for (j = 0; j < ilist[F_GB13].nr; j += 3)
-                {
-                    a1 = ilist[F_GB13].iatoms[j+1];
-                    a2 = ilist[F_GB13].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k < imin)
-                    {
-                        k += natoms;
-                    }
-
-                    if (k > i+max_offset)
-                    {
-                        continue;
-                    }
-
-                    k = k - imin;
-
-                    if (k+natoms <= max_offset)
-                    {
-                        k += natoms;
-                    }
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
-                }
-            }
-            if (!bInclude14)
-            {
-                for (j = 0; j < ilist[F_GB14].nr; j += 3)
-                {
-                    a1 = ilist[F_GB14].iatoms[j+1];
-                    a2 = ilist[F_GB14].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k < imin)
-                    {
-                        k += natoms;
-                    }
-
-                    if (k > i+max_offset)
-                    {
-                        continue;
-                    }
-
-                    k = k - imin;
-
-                    if (k+natoms <= max_offset)
-                    {
-                        k += natoms;
-                    }
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
-                }
-            }
-        }
-
-        /* The offset specifies the last atom to be excluded, so add one unit to get an upper loop limit */
-        max_excl_offset++;
-        /* round up to j unrolling factor */
-        max_excl_offset = (max_excl_offset/UNROLLJ+1)*UNROLLJ;
-
-        /* Set all the prologue masks length to this value (even for i>end) */
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-            aadata->jindex_gb[4*i]   = imin;
-            aadata->jindex_gb[4*i+1] = imin+max_excl_offset;
-        }
-    }
-
-    /* Now the hard part, loop over it all again to calculate the actual contents of the prologue masks */
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-            nj   = aadata->jindex_gb[4*i+1] - aadata->jindex_gb[4*i];
-            imin = aadata->jindex_gb[4*i];
-
-            /* Allocate aligned memory */
-            snew(pi, 2*(nj+2*SIMD_WIDTH));
-            aadata->prologue_mask_gb[i] = (int *) (((size_t) pi + 16) & (~((size_t) 15)));
-
-            max_offset = calc_maxoffset(i, natoms);
-
-            /* Include interactions i+1 <= j < i+maxoffset */
-            for (k = 0; k < nj; k++)
-            {
-                j = imin + k;
-
-                if ( (j > i) && (j <= i+max_offset) )
-                {
-                    aadata->prologue_mask_gb[i][2*k]   = 0xFFFFFFFF;
-                    aadata->prologue_mask_gb[i][2*k+1] = 0xFFFFFFFF;
-                }
-                else
-                {
-                    aadata->prologue_mask_gb[i][2*k]   = 0;
-                    aadata->prologue_mask_gb[i][2*k+1] = 0;
-                }
-            }
-
-            /* Clear out the explicit exclusions */
-            if (i < end)
-            {
-                if (!bInclude12)
-                {
-                    for (j = 0; j < ilist[F_GB12].nr; j += 3)
-                    {
-                        a1 = ilist[F_GB12].iatoms[j+1];
-                        a2 = ilist[F_GB12].iatoms[j+2];
-
-                        if (a1 == i)
-                        {
-                            k = a2;
-                        }
-                        else if (a2 == i)
-                        {
-                            k = a1;
-                        }
-                        else
-                        {
-                            continue;
-                        }
-
-                        if (k > i+max_offset)
-                        {
-                            continue;
-                        }
-                        k = k-i;
-
-                        if (k+natoms <= max_offset)
-                        {
-                            k += natoms;
-                        }
-
-                        k = k+i-imin;
-                        if (k >= 0)
-                        {
-                            aadata->prologue_mask_gb[i][2*k]   = 0;
-                            aadata->prologue_mask_gb[i][2*k+1] = 0;
-                        }
-                    }
-                }
-                if (!bInclude13)
-                {
-                    for (j = 0; j < ilist[F_GB13].nr; j += 3)
-                    {
-                        a1 = ilist[F_GB13].iatoms[j+1];
-                        a2 = ilist[F_GB13].iatoms[j+2];
-
-                        if (a1 == i)
-                        {
-                            k = a2;
-                        }
-                        else if (a2 == i)
-                        {
-                            k = a1;
-                        }
-                        else
-                        {
-                            continue;
-                        }
-
-                        if (k > i+max_offset)
-                        {
-                            continue;
-                        }
-                        k = k-i;
-
-                        if (k+natoms <= max_offset)
-                        {
-                            k += natoms;
-                        }
-
-                        k = k+i-imin;
-                        if (k >= 0)
-                        {
-                            aadata->prologue_mask_gb[i][2*k]   = 0;
-                            aadata->prologue_mask_gb[i][2*k+1] = 0;
-                        }
-                    }
-                }
-                if (!bInclude14)
-                {
-                    for (j = 0; j < ilist[F_GB14].nr; j += 3)
-                    {
-                        a1 = ilist[F_GB14].iatoms[j+1];
-                        a2 = ilist[F_GB14].iatoms[j+2];
-
-                        if (a1 == i)
-                        {
-                            k = a2;
-                        }
-                        else if (a2 == i)
-                        {
-                            k = a1;
-                        }
-                        else
-                        {
-                            continue;
-                        }
-
-                        if (k > i+max_offset)
-                        {
-                            continue;
-                        }
-                        k = k-i;
-
-                        if (k+natoms <= max_offset)
-                        {
-                            k += natoms;
-                        }
-
-                        k = k+i-imin;
-                        if (k >= 0)
-                        {
-                            aadata->prologue_mask_gb[i][2*k]   = 0;
-                            aadata->prologue_mask_gb[i][2*k+1] = 0;
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /* Construct the epilogue mask - this just contains the check for maxoffset */
-    snew(aadata->epilogue_mask, natoms+UNROLLI);
-
-    /* First zero everything to avoid uninitialized data */
-    for (i = 0; i < natoms+UNROLLI; i++)
-    {
-        aadata->jindex_gb[4*i+2]    = aadata->jindex_gb[4*i+1];
-        aadata->jindex_gb[4*i+3]    = aadata->jindex_gb[4*i+1];
-        aadata->epilogue_mask[i]    = NULL;
-    }
-
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        /* Find the lowest index for which we need to use the epilogue */
-        imin       = ibase;
-        max_offset = calc_maxoffset(imin, natoms);
-
-        imin = imin + 1 + max_offset;
-
-        /* Find largest index for which we need to use the epilogue */
-        imax = ibase + UNROLLI-1;
-        imax = (imax < end) ? imax : end;
-
-        max_offset = calc_maxoffset(imax, natoms);
-        imax       = imax + 1 + max_offset + UNROLLJ - 1;
-
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-            /* Start of epilogue - round down to j tile limit */
-            aadata->jindex_gb[4*i+2] = (imin/UNROLLJ)*UNROLLJ;
-            /* Make sure we dont overlap - for small systems everything is done in the prologue */
-            aadata->jindex_gb[4*i+2] = (aadata->jindex_gb[4*i+1] > aadata->jindex_gb[4*i+2]) ? aadata->jindex_gb[4*i+1] : aadata->jindex_gb[4*i+2];
-            /* Round upwards to j tile limit */
-            aadata->jindex_gb[4*i+3] = (imax/UNROLLJ)*UNROLLJ;
-            /* Make sure we dont have a negative range for the epilogue */
-            aadata->jindex_gb[4*i+3] = (aadata->jindex_gb[4*i+2] > aadata->jindex_gb[4*i+3]) ? aadata->jindex_gb[4*i+2] : aadata->jindex_gb[4*i+3];
-        }
-    }
-
-    /* And fill it with data... */
-
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-
-            nj = aadata->jindex_gb[4*i+3] - aadata->jindex_gb[4*i+2];
-
-            /* Allocate aligned memory */
-            snew(pi, 2*(nj+2*SIMD_WIDTH));
-            aadata->epilogue_mask[i] = (int *) (((size_t) pi + 16) & (~((size_t) 15)));
-
-            max_offset = calc_maxoffset(i, natoms);
-
-            for (k = 0; k < nj; k++)
-            {
-                j = aadata->jindex_gb[4*i+2] + k;
-                aadata->epilogue_mask[i][2*k]   = (j <= i+max_offset) ? 0xFFFFFFFF : 0;
-                aadata->epilogue_mask[i][2*k+1] = (j <= i+max_offset) ? 0xFFFFFFFF : 0;
-            }
-        }
-    }
-}
-
-
-static void
-genborn_allvsall_setup(gmx_allvsallgb2_data_t     **  p_aadata,
-                       gmx_localtop_t     *           top,
-                       gmx_genborn_t     *            born,
-                       t_mdatoms     *                mdatoms,
-                       double                         radius_offset,
-                       int                            gb_algorithm,
-                       gmx_bool                       bInclude12,
-                       gmx_bool                       bInclude13,
-                       gmx_bool                       bInclude14)
-{
-    int                     i, j, idx;
-    int                     natoms;
-    gmx_allvsallgb2_data_t *aadata;
-    double                 *p;
-
-    natoms = mdatoms->nr;
-
-    snew(aadata, 1);
-    *p_aadata = aadata;
-
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->x_align = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->y_align = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->z_align = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->fx_align = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->fy_align = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->fz_align = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    snew(p, 2*natoms+UNROLLJ+SIMD_WIDTH);
-    aadata->gb_radius = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    snew(p, 2*natoms+UNROLLJ+SIMD_WIDTH);
-    aadata->workparam = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    snew(p, 2*natoms+UNROLLJ+SIMD_WIDTH);
-    aadata->work = (double *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    for (i = 0; i < mdatoms->nr; i++)
-    {
-        aadata->gb_radius[i] = top->atomtypes.gb_radius[mdatoms->typeA[i]] - radius_offset;
-        if (gb_algorithm == egbSTILL)
-        {
-            aadata->workparam[i] = born->vsolv[i];
-        }
-        else if (gb_algorithm == egbOBC)
-        {
-            aadata->workparam[i] = born->param[i];
-        }
-        aadata->work[i]      = 0.0;
-    }
-    for (i = 0; i < mdatoms->nr; i++)
-    {
-        aadata->gb_radius[natoms+i] = aadata->gb_radius[i];
-        aadata->workparam[natoms+i] = aadata->workparam[i];
-        aadata->work[natoms+i]      = aadata->work[i];
-    }
-
-    for (i = 0; i < 2*natoms+SIMD_WIDTH; i++)
-    {
-        aadata->x_align[i]  = 0.0;
-        aadata->y_align[i]  = 0.0;
-        aadata->z_align[i]  = 0.0;
-        aadata->fx_align[i] = 0.0;
-        aadata->fy_align[i] = 0.0;
-        aadata->fz_align[i] = 0.0;
-    }
-
-    setup_gb_exclusions_and_indices(aadata, top->idef.il, 0, mdatoms->homenr, mdatoms->nr,
-                                    bInclude12, bInclude13, bInclude14);
-}
-
-
-/*
- * This routine apparently hits a compiler bug visual studio has had 'forever'.
- * It is present both in VS2005 and VS2008, and the only way around it is to
- * decrease optimization. We do that with at pragma, and only for MSVC, so it
- * will not hurt any of the well-behaving and supported compilers out there.
- * MS: Fix your compiler, it sucks like a black hole!
- */
-#ifdef _MSC_VER
-#pragma optimize("t",off)
-#endif
-
-int
-genborn_allvsall_calc_still_radii_sse2_double(t_forcerec   *           fr,
-                                              t_mdatoms   *            mdatoms,
-                                              gmx_genborn_t   *        born,
-                                              gmx_localtop_t   *       top,
-                                              double *                 x,
-                                              t_commrec   *            cr,
-                                              void   *                 paadata)
-{
-    gmx_allvsallgb2_data_t *aadata;
-    int                     natoms;
-    int                     ni0, ni1;
-    int                     nj0, nj1, nj2, nj3;
-    int                     i, j, k, n;
-    int              *      mask;
-    int              *      pmask0;
-    int              *      pmask1;
-    int              *      emask0;
-    int              *      emask1;
-    double                  ix, iy, iz;
-    double                  jx, jy, jz;
-    double                  dx, dy, dz;
-    double                  rsq, rinv;
-    double                  gpi, rai, vai;
-    double                  prod_ai;
-    double                  irsq, idr4, idr6;
-    double                  raj, rvdw, ratio;
-    double                  vaj, ccf, dccf, theta, cosq;
-    double                  term, prod, icf4, icf6, gpi2, factor, sinq;
-    double            *     gb_radius;
-    double            *     vsolv;
-    double            *     work;
-    double                  tmpsum[2];
-    double            *     x_align;
-    double            *     y_align;
-    double            *     z_align;
-    int              *      jindex;
-    double            *     dadx;
-
-    __m128d                 ix_SSE0, iy_SSE0, iz_SSE0;
-    __m128d                 ix_SSE1, iy_SSE1, iz_SSE1;
-    __m128d                 gpi_SSE0, rai_SSE0, prod_ai_SSE0;
-    __m128d                 gpi_SSE1, rai_SSE1, prod_ai_SSE1;
-    __m128d                 imask_SSE0, jmask_SSE0;
-    __m128d                 imask_SSE1, jmask_SSE1;
-    __m128d                 jx_SSE, jy_SSE, jz_SSE;
-    __m128d                 dx_SSE0, dy_SSE0, dz_SSE0;
-    __m128d                 dx_SSE1, dy_SSE1, dz_SSE1;
-    __m128d                 rsq_SSE0, rinv_SSE0, irsq_SSE0, idr4_SSE0, idr6_SSE0;
-    __m128d                 rsq_SSE1, rinv_SSE1, irsq_SSE1, idr4_SSE1, idr6_SSE1;
-    __m128d                 raj_SSE, vaj_SSE, prod_SSE;
-    __m128d                 rvdw_SSE0, ratio_SSE0;
-    __m128d                 rvdw_SSE1, ratio_SSE1;
-    __m128d                 theta_SSE0, sinq_SSE0, cosq_SSE0, term_SSE0;
-    __m128d                 theta_SSE1, sinq_SSE1, cosq_SSE1, term_SSE1;
-    __m128d                 ccf_SSE0, dccf_SSE0;
-    __m128d                 ccf_SSE1, dccf_SSE1;
-    __m128d                 icf4_SSE0, icf6_SSE0;
-    __m128d                 icf4_SSE1, icf6_SSE1;
-    __m128d                 half_SSE, one_SSE, two_SSE, four_SSE;
-    __m128d                 still_p4_SSE, still_p5inv_SSE, still_pip5_SSE;
-
-    natoms              = mdatoms->nr;
-    ni0                 = 0;
-    ni1                 = mdatoms->homenr;
-
-    n = 0;
-
-    aadata = *((gmx_allvsallgb2_data_t **)paadata);
-
-
-    if (aadata == NULL)
-    {
-        genborn_allvsall_setup(&aadata, top, born, mdatoms, 0.0,
-                               egbSTILL, FALSE, FALSE, TRUE);
-        *((gmx_allvsallgb2_data_t **)paadata) = aadata;
-    }
-
-    x_align = aadata->x_align;
-    y_align = aadata->y_align;
-    z_align = aadata->z_align;
-
-    gb_radius = aadata->gb_radius;
-    vsolv     = aadata->workparam;
-    work      = aadata->work;
-    jindex    = aadata->jindex_gb;
-    dadx      = fr->dadx;
-
-    still_p4_SSE    = _mm_set1_pd(STILL_P4);
-    still_p5inv_SSE = _mm_set1_pd(STILL_P5INV);
-    still_pip5_SSE  = _mm_set1_pd(STILL_PIP5);
-    half_SSE        = _mm_set1_pd(0.5);
-    one_SSE         = _mm_set1_pd(1.0);
-    two_SSE         = _mm_set1_pd(2.0);
-    four_SSE        = _mm_set1_pd(4.0);
-
-    /* This will be summed, so it has to extend to natoms + buffer */
-    for (i = 0; i < natoms+1+natoms/2; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = ni0; i < ni1+1+natoms/2; i++)
-    {
-        k           = i%natoms;
-        x_align[i]  = x[3*k];
-        y_align[i]  = x[3*k+1];
-        z_align[i]  = x[3*k+2];
-        work[i]     = 0;
-    }
-
-    for (i = ni0; i < ni1; i += UNROLLI)
-    {
-        /* We assume shifts are NOT used for all-vs-all interactions */
-        /* Load i atom data */
-        ix_SSE0          = _mm_load1_pd(x_align+i);
-        iy_SSE0          = _mm_load1_pd(y_align+i);
-        iz_SSE0          = _mm_load1_pd(z_align+i);
-        ix_SSE1          = _mm_load1_pd(x_align+i+1);
-        iy_SSE1          = _mm_load1_pd(y_align+i+1);
-        iz_SSE1          = _mm_load1_pd(z_align+i+1);
-
-        gpi_SSE0         = _mm_setzero_pd();
-        gpi_SSE1         = _mm_setzero_pd();
-
-        rai_SSE0         = _mm_load1_pd(gb_radius+i);
-        rai_SSE1         = _mm_load1_pd(gb_radius+i+1);
-
-        prod_ai_SSE0     = _mm_set1_pd(STILL_P4*vsolv[i]);
-        prod_ai_SSE1     = _mm_set1_pd(STILL_P4*vsolv[i+1]);
-
-        /* Load limits for loop over neighbors */
-        nj0              = jindex[4*i];
-        nj1              = jindex[4*i+1];
-        nj2              = jindex[4*i+2];
-        nj3              = jindex[4*i+3];
-
-        pmask0           = aadata->prologue_mask_gb[i];
-        pmask1           = aadata->prologue_mask_gb[i+1];
-        emask0           = aadata->epilogue_mask[i];
-        emask1           = aadata->epilogue_mask[i+1];
-
-        imask_SSE0        = _mm_load1_pd((double *)(aadata->imask+2*i));
-        imask_SSE1        = _mm_load1_pd((double *)(aadata->imask+2*i+2));
-
-        /* Prologue part, including exclusion mask */
-        for (j = nj0; j < nj1; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_pd((double *)pmask0);
-            jmask_SSE1 = _mm_load_pd((double *)pmask1);
-            pmask0    += 2*UNROLLJ;
-            pmask1    += 2*UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_pd(x_align+j);
-            jy_SSE            = _mm_load_pd(y_align+j);
-            jz_SSE            = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_pd(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_pd(dx_SSE1, dy_SSE1, dz_SSE1);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_pd(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_pd(jmask_SSE1, imask_SSE1);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_pd(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_pd(rsq_SSE1);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_pd(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_pd(rinv_SSE1, jmask_SSE1);
-
-            irsq_SSE0          = _mm_mul_pd(rinv_SSE0, rinv_SSE0);
-            irsq_SSE1          = _mm_mul_pd(rinv_SSE1, rinv_SSE1);
-            idr4_SSE0          = _mm_mul_pd(irsq_SSE0, irsq_SSE0);
-            idr4_SSE1          = _mm_mul_pd(irsq_SSE1, irsq_SSE1);
-            idr6_SSE0          = _mm_mul_pd(idr4_SSE0, irsq_SSE0);
-            idr6_SSE1          = _mm_mul_pd(idr4_SSE1, irsq_SSE1);
-
-            raj_SSE            = _mm_load_pd(gb_radius+j);
-            vaj_SSE            = _mm_load_pd(vsolv+j);
-
-            rvdw_SSE0          = _mm_add_pd(rai_SSE0, raj_SSE);
-            rvdw_SSE1          = _mm_add_pd(rai_SSE1, raj_SSE);
-
-            ratio_SSE0         = _mm_mul_pd(rsq_SSE0, gmx_mm_inv_pd( _mm_mul_pd(rvdw_SSE0, rvdw_SSE0)));
-            ratio_SSE1         = _mm_mul_pd(rsq_SSE1, gmx_mm_inv_pd( _mm_mul_pd(rvdw_SSE1, rvdw_SSE1)));
-
-            ratio_SSE0         = _mm_min_pd(ratio_SSE0, still_p5inv_SSE);
-            ratio_SSE1         = _mm_min_pd(ratio_SSE1, still_p5inv_SSE);
-            theta_SSE0         = _mm_mul_pd(ratio_SSE0, still_pip5_SSE);
-            theta_SSE1         = _mm_mul_pd(ratio_SSE1, still_pip5_SSE);
-            gmx_mm_sincos_pd(theta_SSE0, &sinq_SSE0, &cosq_SSE0);
-            gmx_mm_sincos_pd(theta_SSE1, &sinq_SSE1, &cosq_SSE1);
-            term_SSE0          = _mm_mul_pd(half_SSE, _mm_sub_pd(one_SSE, cosq_SSE0));
-            term_SSE1          = _mm_mul_pd(half_SSE, _mm_sub_pd(one_SSE, cosq_SSE1));
-            ccf_SSE0           = _mm_mul_pd(term_SSE0, term_SSE0);
-            ccf_SSE1           = _mm_mul_pd(term_SSE1, term_SSE1);
-            dccf_SSE0          = _mm_mul_pd(_mm_mul_pd(two_SSE, term_SSE0),
-                                            _mm_mul_pd(sinq_SSE0, theta_SSE0));
-            dccf_SSE1          = _mm_mul_pd(_mm_mul_pd(two_SSE, term_SSE1),
-                                            _mm_mul_pd(sinq_SSE1, theta_SSE1));
-
-            prod_SSE           = _mm_mul_pd(still_p4_SSE, vaj_SSE);
-            icf4_SSE0          = _mm_mul_pd(ccf_SSE0, idr4_SSE0);
-            icf4_SSE1          = _mm_mul_pd(ccf_SSE1, idr4_SSE1);
-            icf6_SSE0          = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four_SSE, ccf_SSE0), dccf_SSE0), idr6_SSE0);
-            icf6_SSE1          = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four_SSE, ccf_SSE1), dccf_SSE1), idr6_SSE1);
-
-            _mm_store_pd(work+j, _mm_add_pd(_mm_load_pd(work+j),
-                                            _mm_add_pd(_mm_mul_pd(prod_ai_SSE0, icf4_SSE0),
-                                                       _mm_mul_pd(prod_ai_SSE1, icf4_SSE1))));
-
-
-            gpi_SSE0           = _mm_add_pd(gpi_SSE0, _mm_mul_pd(prod_SSE, icf4_SSE0));
-            gpi_SSE1           = _mm_add_pd(gpi_SSE1, _mm_mul_pd(prod_SSE, icf4_SSE1));
-
-            /* Save ai->aj and aj->ai chain rule terms */
-            _mm_store_pd(dadx, _mm_mul_pd(prod_SSE, icf6_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_SSE, icf6_SSE1));
-            dadx += 2;
-
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai_SSE0, icf6_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai_SSE1, icf6_SSE1));
-            dadx += 2;
-        }
-
-        /* Main part, no exclusions */
-        for (j = nj1; j < nj2; j += UNROLLJ)
-        {
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_pd(x_align+j);
-            jy_SSE            = _mm_load_pd(y_align+j);
-            jz_SSE            = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_pd(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_pd(dx_SSE1, dy_SSE1, dz_SSE1);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_pd(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_pd(rsq_SSE1);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_pd(rinv_SSE0, imask_SSE0);
-            rinv_SSE1          = _mm_and_pd(rinv_SSE1, imask_SSE1);
-
-            irsq_SSE0          = _mm_mul_pd(rinv_SSE0, rinv_SSE0);
-            irsq_SSE1          = _mm_mul_pd(rinv_SSE1, rinv_SSE1);
-            idr4_SSE0          = _mm_mul_pd(irsq_SSE0, irsq_SSE0);
-            idr4_SSE1          = _mm_mul_pd(irsq_SSE1, irsq_SSE1);
-            idr6_SSE0          = _mm_mul_pd(idr4_SSE0, irsq_SSE0);
-            idr6_SSE1          = _mm_mul_pd(idr4_SSE1, irsq_SSE1);
-
-            raj_SSE            = _mm_load_pd(gb_radius+j);
-
-            rvdw_SSE0          = _mm_add_pd(rai_SSE0, raj_SSE);
-            rvdw_SSE1          = _mm_add_pd(rai_SSE1, raj_SSE);
-            vaj_SSE            = _mm_load_pd(vsolv+j);
-
-            ratio_SSE0         = _mm_mul_pd(rsq_SSE0, gmx_mm_inv_pd( _mm_mul_pd(rvdw_SSE0, rvdw_SSE0)));
-            ratio_SSE1         = _mm_mul_pd(rsq_SSE1, gmx_mm_inv_pd( _mm_mul_pd(rvdw_SSE1, rvdw_SSE1)));
-
-            ratio_SSE0         = _mm_min_pd(ratio_SSE0, still_p5inv_SSE);
-            ratio_SSE1         = _mm_min_pd(ratio_SSE1, still_p5inv_SSE);
-            theta_SSE0         = _mm_mul_pd(ratio_SSE0, still_pip5_SSE);
-            theta_SSE1         = _mm_mul_pd(ratio_SSE1, still_pip5_SSE);
-            gmx_mm_sincos_pd(theta_SSE0, &sinq_SSE0, &cosq_SSE0);
-            gmx_mm_sincos_pd(theta_SSE1, &sinq_SSE1, &cosq_SSE1);
-            term_SSE0          = _mm_mul_pd(half_SSE, _mm_sub_pd(one_SSE, cosq_SSE0));
-            term_SSE1          = _mm_mul_pd(half_SSE, _mm_sub_pd(one_SSE, cosq_SSE1));
-            ccf_SSE0           = _mm_mul_pd(term_SSE0, term_SSE0);
-            ccf_SSE1           = _mm_mul_pd(term_SSE1, term_SSE1);
-            dccf_SSE0          = _mm_mul_pd(_mm_mul_pd(two_SSE, term_SSE0),
-                                            _mm_mul_pd(sinq_SSE0, theta_SSE0));
-            dccf_SSE1          = _mm_mul_pd(_mm_mul_pd(two_SSE, term_SSE1),
-                                            _mm_mul_pd(sinq_SSE1, theta_SSE1));
-
-            prod_SSE           = _mm_mul_pd(still_p4_SSE, vaj_SSE );
-            icf4_SSE0          = _mm_mul_pd(ccf_SSE0, idr4_SSE0);
-            icf4_SSE1          = _mm_mul_pd(ccf_SSE1, idr4_SSE1);
-            icf6_SSE0          = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four_SSE, ccf_SSE0), dccf_SSE0), idr6_SSE0);
-            icf6_SSE1          = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four_SSE, ccf_SSE1), dccf_SSE1), idr6_SSE1);
-
-            _mm_store_pd(work+j, _mm_add_pd(_mm_load_pd(work+j),
-                                            _mm_add_pd(_mm_mul_pd(prod_ai_SSE0, icf4_SSE0),
-                                                       _mm_mul_pd(prod_ai_SSE1, icf4_SSE1))));
-
-            gpi_SSE0           = _mm_add_pd(gpi_SSE0, _mm_mul_pd(prod_SSE, icf4_SSE0));
-            gpi_SSE1           = _mm_add_pd(gpi_SSE1, _mm_mul_pd(prod_SSE, icf4_SSE1));
-
-            /* Save ai->aj and aj->ai chain rule terms */
-            _mm_store_pd(dadx, _mm_mul_pd(prod_SSE, icf6_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_SSE, icf6_SSE1));
-            dadx += 2;
-
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai_SSE0, icf6_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai_SSE1, icf6_SSE1));
-            dadx += 2;
-        }
-        /* Epilogue part, including exclusion mask */
-        for (j = nj2; j < nj3; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_pd((double *)emask0);
-            jmask_SSE1 = _mm_load_pd((double *)emask1);
-            emask0    += 2*UNROLLJ;
-            emask1    += 2*UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_pd(x_align+j);
-            jy_SSE            = _mm_load_pd(y_align+j);
-            jz_SSE            = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_pd(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_pd(dx_SSE1, dy_SSE1, dz_SSE1);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_pd(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_pd(jmask_SSE1, imask_SSE1);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_pd(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_pd(rsq_SSE1);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_pd(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_pd(rinv_SSE1, jmask_SSE1);
-
-            irsq_SSE0          = _mm_mul_pd(rinv_SSE0, rinv_SSE0);
-            irsq_SSE1          = _mm_mul_pd(rinv_SSE1, rinv_SSE1);
-            idr4_SSE0          = _mm_mul_pd(irsq_SSE0, irsq_SSE0);
-            idr4_SSE1          = _mm_mul_pd(irsq_SSE1, irsq_SSE1);
-            idr6_SSE0          = _mm_mul_pd(idr4_SSE0, irsq_SSE0);
-            idr6_SSE1          = _mm_mul_pd(idr4_SSE1, irsq_SSE1);
-
-            raj_SSE            = _mm_load_pd(gb_radius+j);
-            vaj_SSE            = _mm_load_pd(vsolv+j);
-
-            rvdw_SSE0          = _mm_add_pd(rai_SSE0, raj_SSE);
-            rvdw_SSE1          = _mm_add_pd(rai_SSE1, raj_SSE);
-
-            ratio_SSE0         = _mm_mul_pd(rsq_SSE0, gmx_mm_inv_pd( _mm_mul_pd(rvdw_SSE0, rvdw_SSE0)));
-            ratio_SSE1         = _mm_mul_pd(rsq_SSE1, gmx_mm_inv_pd( _mm_mul_pd(rvdw_SSE1, rvdw_SSE1)));
-
-            ratio_SSE0         = _mm_min_pd(ratio_SSE0, still_p5inv_SSE);
-            ratio_SSE1         = _mm_min_pd(ratio_SSE1, still_p5inv_SSE);
-            theta_SSE0         = _mm_mul_pd(ratio_SSE0, still_pip5_SSE);
-            theta_SSE1         = _mm_mul_pd(ratio_SSE1, still_pip5_SSE);
-            gmx_mm_sincos_pd(theta_SSE0, &sinq_SSE0, &cosq_SSE0);
-            gmx_mm_sincos_pd(theta_SSE1, &sinq_SSE1, &cosq_SSE1);
-            term_SSE0          = _mm_mul_pd(half_SSE, _mm_sub_pd(one_SSE, cosq_SSE0));
-            term_SSE1          = _mm_mul_pd(half_SSE, _mm_sub_pd(one_SSE, cosq_SSE1));
-            ccf_SSE0           = _mm_mul_pd(term_SSE0, term_SSE0);
-            ccf_SSE1           = _mm_mul_pd(term_SSE1, term_SSE1);
-            dccf_SSE0          = _mm_mul_pd(_mm_mul_pd(two_SSE, term_SSE0),
-                                            _mm_mul_pd(sinq_SSE0, theta_SSE0));
-            dccf_SSE1          = _mm_mul_pd(_mm_mul_pd(two_SSE, term_SSE1),
-                                            _mm_mul_pd(sinq_SSE1, theta_SSE1));
-
-            prod_SSE           = _mm_mul_pd(still_p4_SSE, vaj_SSE);
-            icf4_SSE0          = _mm_mul_pd(ccf_SSE0, idr4_SSE0);
-            icf4_SSE1          = _mm_mul_pd(ccf_SSE1, idr4_SSE1);
-            icf6_SSE0          = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four_SSE, ccf_SSE0), dccf_SSE0), idr6_SSE0);
-            icf6_SSE1          = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four_SSE, ccf_SSE1), dccf_SSE1), idr6_SSE1);
-
-            _mm_store_pd(work+j, _mm_add_pd(_mm_load_pd(work+j),
-                                            _mm_add_pd(_mm_mul_pd(prod_ai_SSE0, icf4_SSE0),
-                                                       _mm_mul_pd(prod_ai_SSE1, icf4_SSE1))));
-
-            gpi_SSE0           = _mm_add_pd(gpi_SSE0, _mm_mul_pd(prod_SSE, icf4_SSE0));
-            gpi_SSE1           = _mm_add_pd(gpi_SSE1, _mm_mul_pd(prod_SSE, icf4_SSE1));
-
-            /* Save ai->aj and aj->ai chain rule terms */
-            _mm_store_pd(dadx, _mm_mul_pd(prod_SSE, icf6_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_SSE, icf6_SSE1));
-            dadx += 2;
-
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai_SSE0, icf6_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai_SSE1, icf6_SSE1));
-            dadx += 2;
-        }
-        GMX_MM_TRANSPOSE2_PD(gpi_SSE0, gpi_SSE1);
-        gpi_SSE0 = _mm_add_pd(gpi_SSE0, gpi_SSE1);
-        _mm_store_pd(work+i, _mm_add_pd(gpi_SSE0, _mm_load_pd(work+i)));
-    }
-
-    /* In case we have written anything beyond natoms, move it back.
-     * Never mind that we leave stuff above natoms; that will not
-     * be accessed later in the routine.
-     * In principle this should be a move rather than sum, but this
-     * way we dont have to worry about even/odd offsets...
-     */
-    for (i = natoms; i < ni1+1+natoms/2; i++)
-    {
-        work[i-natoms] += work[i];
-    }
-
-    /* Parallel summations would go here if ever implemented with DD */
-
-    factor  = 0.5 * ONE_4PI_EPS0;
-    /* Calculate the radii - should we do all atoms, or just our local ones? */
-    for (i = 0; i < natoms; i++)
-    {
-        if (born->use[i] != 0)
-        {
-            gpi             = born->gpol[i]+work[i];
-            gpi2            = gpi * gpi;
-            born->bRad[i]   = factor*gmx_invsqrt(gpi2);
-            fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-        }
-    }
-
-    return 0;
-}
-/* Reinstate MSVC optimization */
-#ifdef _MSC_VER
-#pragma optimize("",on)
-#endif
-
-
-int
-genborn_allvsall_calc_hct_obc_radii_sse2_double(t_forcerec   *           fr,
-                                                t_mdatoms   *            mdatoms,
-                                                gmx_genborn_t   *        born,
-                                                int                      gb_algorithm,
-                                                gmx_localtop_t   *       top,
-                                                double *                 x,
-                                                t_commrec   *            cr,
-                                                void   *                 paadata)
-{
-    gmx_allvsallgb2_data_t *aadata;
-    int                     natoms;
-    int                     ni0, ni1;
-    int                     nj0, nj1, nj2, nj3;
-    int                     i, j, k, n;
-    int              *      mask;
-    int              *      pmask0;
-    int              *      pmask1;
-    int              *      emask0;
-    int              *      emask1;
-    double            *     gb_radius;
-    double            *     vsolv;
-    double            *     work;
-    double                  tmpsum[2];
-    double            *     x_align;
-    double            *     y_align;
-    double            *     z_align;
-    int              *      jindex;
-    double            *     dadx;
-    double            *     obc_param;
-    double                  rad, min_rad;
-    double                  rai, rai_inv, rai_inv2, sum_ai, sum_ai2, sum_ai3, tsum, tchain;
-
-    __m128d                 ix_SSE0, iy_SSE0, iz_SSE0;
-    __m128d                 ix_SSE1, iy_SSE1, iz_SSE1;
-    __m128d                 gpi_SSE0, rai_SSE0, prod_ai_SSE0;
-    __m128d                 gpi_SSE1, rai_SSE1, prod_ai_SSE1;
-    __m128d                 imask_SSE0, jmask_SSE0;
-    __m128d                 imask_SSE1, jmask_SSE1;
-    __m128d                 jx_SSE, jy_SSE, jz_SSE;
-    __m128d                 dx_SSE0, dy_SSE0, dz_SSE0;
-    __m128d                 dx_SSE1, dy_SSE1, dz_SSE1;
-    __m128d                 rsq_SSE0, rinv_SSE0, irsq_SSE0, idr4_SSE0, idr6_SSE0;
-    __m128d                 rsq_SSE1, rinv_SSE1, irsq_SSE1, idr4_SSE1, idr6_SSE1;
-    __m128d                 raj_SSE, raj_inv_SSE, sk_aj_SSE, sk2_aj_SSE;
-    __m128d                 ccf_SSE0, dccf_SSE0, prod_SSE0;
-    __m128d                 ccf_SSE1, dccf_SSE1, prod_SSE1;
-    __m128d                 icf4_SSE0, icf6_SSE0;
-    __m128d                 icf4_SSE1, icf6_SSE1;
-    __m128d                 oneeighth_SSE, onefourth_SSE, half_SSE, one_SSE, two_SSE, four_SSE;
-    __m128d                 still_p4_SSE, still_p5inv_SSE, still_pip5_SSE;
-    __m128d                 rai_inv_SSE0;
-    __m128d                 rai_inv_SSE1;
-    __m128d                 sk_ai_SSE0, sk2_ai_SSE0, sum_ai_SSE0;
-    __m128d                 sk_ai_SSE1, sk2_ai_SSE1, sum_ai_SSE1;
-    __m128d                 lij_inv_SSE0, sk2_rinv_SSE0;
-    __m128d                 lij_inv_SSE1, sk2_rinv_SSE1;
-    __m128d                 dr_SSE0;
-    __m128d                 dr_SSE1;
-    __m128d                 t1_SSE0, t2_SSE0, t3_SSE0, t4_SSE0;
-    __m128d                 t1_SSE1, t2_SSE1, t3_SSE1, t4_SSE1;
-    __m128d                 obc_mask1_SSE0, obc_mask2_SSE0, obc_mask3_SSE0;
-    __m128d                 obc_mask1_SSE1, obc_mask2_SSE1, obc_mask3_SSE1;
-    __m128d                 uij_SSE0, uij2_SSE0, uij3_SSE0;
-    __m128d                 uij_SSE1, uij2_SSE1, uij3_SSE1;
-    __m128d                 lij_SSE0, lij2_SSE0, lij3_SSE0;
-    __m128d                 lij_SSE1, lij2_SSE1, lij3_SSE1;
-    __m128d                 dlij_SSE0, diff2_SSE0, logterm_SSE0;
-    __m128d                 dlij_SSE1, diff2_SSE1, logterm_SSE1;
-    __m128d                 doffset_SSE, tmpSSE;
-
-    natoms              = mdatoms->nr;
-    ni0                 = 0;
-    ni1                 = mdatoms->homenr;
-
-    n = 0;
-
-    aadata = *((gmx_allvsallgb2_data_t **)paadata);
-
-
-    if (aadata == NULL)
-    {
-        genborn_allvsall_setup(&aadata, top, born, mdatoms, born->gb_doffset,
-                               egbOBC, TRUE, TRUE, TRUE);
-        *((gmx_allvsallgb2_data_t **)paadata) = aadata;
-    }
-
-    x_align = aadata->x_align;
-    y_align = aadata->y_align;
-    z_align = aadata->z_align;
-
-    gb_radius = aadata->gb_radius;
-    work      = aadata->work;
-    jindex    = aadata->jindex_gb;
-    dadx      = fr->dadx;
-    obc_param = aadata->workparam;
-
-    oneeighth_SSE   = _mm_set1_pd(0.125);
-    onefourth_SSE   = _mm_set1_pd(0.25);
-    half_SSE        = _mm_set1_pd(0.5);
-    one_SSE         = _mm_set1_pd(1.0);
-    two_SSE         = _mm_set1_pd(2.0);
-    four_SSE        = _mm_set1_pd(4.0);
-    doffset_SSE     = _mm_set1_pd(born->gb_doffset);
-
-    for (i = 0; i < natoms; i++)
-    {
-        x_align[i]  = x[3*i];
-        y_align[i]  = x[3*i+1];
-        z_align[i]  = x[3*i+2];
-    }
-
-    /* Copy again */
-    for (i = 0; i < natoms/2+1; i++)
-    {
-        x_align[natoms+i]  = x_align[i];
-        y_align[natoms+i]  = y_align[i];
-        z_align[natoms+i]  = z_align[i];
-    }
-
-    for (i = 0; i < natoms+natoms/2+1; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = ni0; i < ni1; i += UNROLLI)
-    {
-        /* We assume shifts are NOT used for all-vs-all interactions */
-
-        /* Load i atom data */
-        ix_SSE0          = _mm_load1_pd(x_align+i);
-        iy_SSE0          = _mm_load1_pd(y_align+i);
-        iz_SSE0          = _mm_load1_pd(z_align+i);
-        ix_SSE1          = _mm_load1_pd(x_align+i+1);
-        iy_SSE1          = _mm_load1_pd(y_align+i+1);
-        iz_SSE1          = _mm_load1_pd(z_align+i+1);
-
-        rai_SSE0         = _mm_load1_pd(gb_radius+i);
-        rai_SSE1         = _mm_load1_pd(gb_radius+i+1);
-        rai_inv_SSE0     = gmx_mm_inv_pd(rai_SSE0);
-        rai_inv_SSE1     = gmx_mm_inv_pd(rai_SSE1);
-
-        sk_ai_SSE0       = _mm_load1_pd(obc_param+i);
-        sk_ai_SSE1       = _mm_load1_pd(obc_param+i+1);
-        sk2_ai_SSE0      = _mm_mul_pd(sk_ai_SSE0, sk_ai_SSE0);
-        sk2_ai_SSE1      = _mm_mul_pd(sk_ai_SSE1, sk_ai_SSE1);
-
-        sum_ai_SSE0      = _mm_setzero_pd();
-        sum_ai_SSE1      = _mm_setzero_pd();
-
-        /* Load limits for loop over neighbors */
-        nj0              = jindex[4*i];
-        nj1              = jindex[4*i+1];
-        nj2              = jindex[4*i+2];
-        nj3              = jindex[4*i+3];
-
-        pmask0           = aadata->prologue_mask_gb[i];
-        pmask1           = aadata->prologue_mask_gb[i+1];
-        emask0           = aadata->epilogue_mask[i];
-        emask1           = aadata->epilogue_mask[i+1];
-
-        imask_SSE0        = _mm_load1_pd((double *)(aadata->imask+2*i));
-        imask_SSE1        = _mm_load1_pd((double *)(aadata->imask+2*i+2));
-
-        /* Prologue part, including exclusion mask */
-        for (j = nj0; j < nj1; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_pd((double *)pmask0);
-            jmask_SSE1 = _mm_load_pd((double *)pmask1);
-            pmask0    += 2*UNROLLJ;
-            pmask1    += 2*UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_pd(x_align+j);
-            jy_SSE            = _mm_load_pd(y_align+j);
-            jz_SSE            = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_pd(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_pd(dx_SSE1, dy_SSE1, dz_SSE1);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_pd(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_pd(jmask_SSE1, imask_SSE1);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_pd(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_pd(rsq_SSE1);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_pd(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_pd(rinv_SSE1, jmask_SSE1);
-
-            dr_SSE0            = _mm_mul_pd(rsq_SSE0, rinv_SSE0);
-            dr_SSE1            = _mm_mul_pd(rsq_SSE1, rinv_SSE1);
-
-            sk_aj_SSE          = _mm_load_pd(obc_param+j);
-            raj_SSE            = _mm_load_pd(gb_radius+j);
-            raj_inv_SSE        = gmx_mm_inv_pd(raj_SSE);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1_SSE0            = _mm_add_pd(dr_SSE0, sk_aj_SSE);
-            t1_SSE1            = _mm_add_pd(dr_SSE1, sk_aj_SSE);
-            t2_SSE0            = _mm_sub_pd(dr_SSE0, sk_aj_SSE);
-            t2_SSE1            = _mm_sub_pd(dr_SSE1, sk_aj_SSE);
-            t3_SSE0            = _mm_sub_pd(sk_aj_SSE, dr_SSE0);
-            t3_SSE1            = _mm_sub_pd(sk_aj_SSE, dr_SSE1);
-
-            obc_mask1_SSE0     = _mm_cmplt_pd(rai_SSE0, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_pd(rai_SSE1, t1_SSE1);
-            obc_mask2_SSE0     = _mm_cmplt_pd(rai_SSE0, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_pd(rai_SSE1, t2_SSE1);
-            obc_mask3_SSE0     = _mm_cmplt_pd(rai_SSE0, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_pd(rai_SSE1, t3_SSE1);
-            obc_mask1_SSE0     = _mm_and_pd(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_pd(obc_mask1_SSE1, jmask_SSE1);
-
-            uij_SSE0           = gmx_mm_inv_pd(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_pd(t1_SSE1);
-            lij_SSE0           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE0, gmx_mm_inv_pd(t2_SSE0)),
-                                              _mm_andnot_pd(obc_mask2_SSE0, rai_inv_SSE0));
-            lij_SSE1           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE1, gmx_mm_inv_pd(t2_SSE1)),
-                                              _mm_andnot_pd(obc_mask2_SSE1, rai_inv_SSE1));
-            dlij_SSE0          = _mm_and_pd(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_pd(one_SSE, obc_mask2_SSE1);
-
-            uij2_SSE0          = _mm_mul_pd(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_pd(uij_SSE1, uij_SSE1);
-            uij3_SSE0          = _mm_mul_pd(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_pd(uij2_SSE1, uij_SSE1);
-            lij2_SSE0          = _mm_mul_pd(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_pd(lij_SSE1, lij_SSE1);
-            lij3_SSE0          = _mm_mul_pd(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_pd(lij2_SSE1, lij_SSE1);
-
-            diff2_SSE0         = _mm_sub_pd(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_pd(uij2_SSE1, lij2_SSE1);
-            lij_inv_SSE0       = gmx_mm_invsqrt_pd(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_pd(lij2_SSE1);
-            sk2_aj_SSE         = _mm_mul_pd(sk_aj_SSE, sk_aj_SSE);
-            sk2_rinv_SSE0      = _mm_mul_pd(sk2_aj_SSE, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_pd(sk2_aj_SSE, rinv_SSE1);
-            prod_SSE0          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE1);
-
-            logterm_SSE0       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE1, lij_inv_SSE1));
-
-            t1_SSE0            = _mm_sub_pd(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_pd(lij_SSE1, uij_SSE1);
-            t2_SSE0            = _mm_mul_pd(diff2_SSE0,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_pd(diff2_SSE1,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-
-            t3_SSE0            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE1, logterm_SSE1));
-            t1_SSE0            = _mm_add_pd(t1_SSE0, _mm_add_pd(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_pd(t1_SSE1, _mm_add_pd(t2_SSE1, t3_SSE1));
-            t4_SSE0            = _mm_mul_pd(two_SSE, _mm_sub_pd(rai_inv_SSE0, lij_SSE0));
-            t4_SSE1            = _mm_mul_pd(two_SSE, _mm_sub_pd(rai_inv_SSE1, lij_SSE1));
-            t4_SSE0            = _mm_and_pd(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_pd(t4_SSE1, obc_mask3_SSE1);
-            t1_SSE0            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE1, t4_SSE1));
-
-            sum_ai_SSE0        = _mm_add_pd(sum_ai_SSE0, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            sum_ai_SSE1        = _mm_add_pd(sum_ai_SSE1, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-
-            t1_SSE0            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE0),
-                                            _mm_mul_pd(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE1),
-                                            _mm_mul_pd(prod_SSE1, lij3_SSE1));
-            t1_SSE0            = _mm_sub_pd(t1_SSE0,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_pd(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_pd(t1_SSE1,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_pd(lij3_SSE1, dr_SSE1))));
-
-            t2_SSE0            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_pd(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_pd(uij3_SSE1, dr_SSE1)));
-            t2_SSE0            = _mm_sub_pd(t2_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE0),
-                                                       _mm_mul_pd(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_pd(t2_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE1),
-                                                       _mm_mul_pd(prod_SSE1, uij3_SSE1)));
-            t3_SSE0            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_pd(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_pd(rinv_SSE1, rinv_SSE1));
-            t3_SSE0            = _mm_sub_pd(t3_SSE0,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_pd(t3_SSE1,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE1, rinv_SSE1))));
-
-            t1_SSE0            = _mm_mul_pd(rinv_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_pd(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_pd(rinv_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_pd(t2_SSE1, t3_SSE1)));
-
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-            dadx += 2;
-
-            /* Evaluate influence of atom ai -> aj */
-            t1_SSE0            = _mm_add_pd(dr_SSE0, sk_ai_SSE0);
-            t1_SSE1            = _mm_add_pd(dr_SSE1, sk_ai_SSE1);
-            t2_SSE0            = _mm_sub_pd(dr_SSE0, sk_ai_SSE0);
-            t2_SSE1            = _mm_sub_pd(dr_SSE1, sk_ai_SSE1);
-            t3_SSE0            = _mm_sub_pd(sk_ai_SSE0, dr_SSE0);
-            t3_SSE1            = _mm_sub_pd(sk_ai_SSE1, dr_SSE1);
-
-            obc_mask1_SSE0     = _mm_cmplt_pd(raj_SSE, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_pd(raj_SSE, t1_SSE1);
-            obc_mask2_SSE0     = _mm_cmplt_pd(raj_SSE, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_pd(raj_SSE, t2_SSE1);
-            obc_mask3_SSE0     = _mm_cmplt_pd(raj_SSE, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_pd(raj_SSE, t3_SSE1);
-            obc_mask1_SSE0     = _mm_and_pd(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_pd(obc_mask1_SSE1, jmask_SSE1);
-
-            uij_SSE0           = gmx_mm_inv_pd(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_pd(t1_SSE1);
-            lij_SSE0           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE0, gmx_mm_inv_pd(t2_SSE0)),
-                                              _mm_andnot_pd(obc_mask2_SSE0, raj_inv_SSE));
-            lij_SSE1           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE1, gmx_mm_inv_pd(t2_SSE1)),
-                                              _mm_andnot_pd(obc_mask2_SSE1, raj_inv_SSE));
-            dlij_SSE0          = _mm_and_pd(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_pd(one_SSE, obc_mask2_SSE1);
-
-            uij2_SSE0          = _mm_mul_pd(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_pd(uij_SSE1, uij_SSE1);
-            uij3_SSE0          = _mm_mul_pd(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_pd(uij2_SSE1, uij_SSE1);
-            lij2_SSE0          = _mm_mul_pd(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_pd(lij_SSE1, lij_SSE1);
-            lij3_SSE0          = _mm_mul_pd(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_pd(lij2_SSE1, lij_SSE1);
-
-            diff2_SSE0         = _mm_sub_pd(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_pd(uij2_SSE1, lij2_SSE1);
-            lij_inv_SSE0       = gmx_mm_invsqrt_pd(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_pd(lij2_SSE1);
-            sk2_rinv_SSE0      = _mm_mul_pd(sk2_ai_SSE0, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_pd(sk2_ai_SSE1, rinv_SSE1);
-            prod_SSE0          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE1);
-
-            logterm_SSE0       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE1, lij_inv_SSE1));
-            t1_SSE0            = _mm_sub_pd(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_pd(lij_SSE1, uij_SSE1);
-            t2_SSE0            = _mm_mul_pd(diff2_SSE0,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_pd(diff2_SSE1,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t3_SSE0            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE1, logterm_SSE1));
-            t1_SSE0            = _mm_add_pd(t1_SSE0, _mm_add_pd(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_pd(t1_SSE1, _mm_add_pd(t2_SSE1, t3_SSE1));
-            t4_SSE0            = _mm_mul_pd(two_SSE, _mm_sub_pd(raj_inv_SSE, lij_SSE0));
-            t4_SSE1            = _mm_mul_pd(two_SSE, _mm_sub_pd(raj_inv_SSE, lij_SSE1));
-            t4_SSE0            = _mm_and_pd(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_pd(t4_SSE1, obc_mask3_SSE1);
-            t1_SSE0            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE1, t4_SSE1));
-
-            _mm_store_pd(work+j, _mm_add_pd(_mm_load_pd(work+j),
-                                            _mm_add_pd(_mm_and_pd(t1_SSE0, obc_mask1_SSE0),
-                                                       _mm_and_pd(t1_SSE1, obc_mask1_SSE1))));
-
-            t1_SSE0            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE0),
-                                            _mm_mul_pd(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE1),
-                                            _mm_mul_pd(prod_SSE1, lij3_SSE1));
-            t1_SSE0            = _mm_sub_pd(t1_SSE0,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_pd(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_pd(t1_SSE1,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_pd(lij3_SSE1, dr_SSE1))));
-            t2_SSE0            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_pd(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_pd(uij3_SSE1, dr_SSE1)));
-            t2_SSE0            = _mm_sub_pd(t2_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE0),
-                                                       _mm_mul_pd(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_pd(t2_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE1),
-                                                       _mm_mul_pd(prod_SSE1, uij3_SSE1)));
-
-            t3_SSE0            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_pd(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_pd(rinv_SSE1, rinv_SSE1));
-
-            t3_SSE0            = _mm_sub_pd(t3_SSE0,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_pd(t3_SSE1,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE1, rinv_SSE1))));
-
-
-            t1_SSE0            = _mm_mul_pd(rinv_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_pd(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_pd(rinv_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_pd(t2_SSE1, t3_SSE1)));
-
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-            dadx += 2;
-        }
-
-        /* Main part, no exclusions */
-        for (j = nj1; j < nj2; j += UNROLLJ)
-        {
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_pd(x_align+j);
-            jy_SSE            = _mm_load_pd(y_align+j);
-            jz_SSE            = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_pd(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_pd(dx_SSE1, dy_SSE1, dz_SSE1);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_pd(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_pd(rsq_SSE1);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_pd(rinv_SSE0, imask_SSE0);
-            rinv_SSE1          = _mm_and_pd(rinv_SSE1, imask_SSE1);
-
-            dr_SSE0            = _mm_mul_pd(rsq_SSE0, rinv_SSE0);
-            dr_SSE1            = _mm_mul_pd(rsq_SSE1, rinv_SSE1);
-
-            sk_aj_SSE          = _mm_load_pd(obc_param+j);
-            raj_SSE            = _mm_load_pd(gb_radius+j);
-
-            raj_inv_SSE        = gmx_mm_inv_pd(raj_SSE);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1_SSE0            = _mm_add_pd(dr_SSE0, sk_aj_SSE);
-            t1_SSE1            = _mm_add_pd(dr_SSE1, sk_aj_SSE);
-            t2_SSE0            = _mm_sub_pd(dr_SSE0, sk_aj_SSE);
-            t2_SSE1            = _mm_sub_pd(dr_SSE1, sk_aj_SSE);
-            t3_SSE0            = _mm_sub_pd(sk_aj_SSE, dr_SSE0);
-            t3_SSE1            = _mm_sub_pd(sk_aj_SSE, dr_SSE1);
-
-            obc_mask1_SSE0     = _mm_cmplt_pd(rai_SSE0, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_pd(rai_SSE1, t1_SSE1);
-            obc_mask2_SSE0     = _mm_cmplt_pd(rai_SSE0, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_pd(rai_SSE1, t2_SSE1);
-            obc_mask3_SSE0     = _mm_cmplt_pd(rai_SSE0, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_pd(rai_SSE1, t3_SSE1);
-            obc_mask1_SSE0     = _mm_and_pd(obc_mask1_SSE0, imask_SSE0);
-            obc_mask1_SSE1     = _mm_and_pd(obc_mask1_SSE1, imask_SSE1);
-
-            uij_SSE0           = gmx_mm_inv_pd(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_pd(t1_SSE1);
-            lij_SSE0           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE0, gmx_mm_inv_pd(t2_SSE0)),
-                                              _mm_andnot_pd(obc_mask2_SSE0, rai_inv_SSE0));
-            lij_SSE1           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE1, gmx_mm_inv_pd(t2_SSE1)),
-                                              _mm_andnot_pd(obc_mask2_SSE1, rai_inv_SSE1));
-            dlij_SSE0          = _mm_and_pd(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_pd(one_SSE, obc_mask2_SSE1);
-
-            uij2_SSE0          = _mm_mul_pd(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_pd(uij_SSE1, uij_SSE1);
-            uij3_SSE0          = _mm_mul_pd(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_pd(uij2_SSE1, uij_SSE1);
-            lij2_SSE0          = _mm_mul_pd(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_pd(lij_SSE1, lij_SSE1);
-            lij3_SSE0          = _mm_mul_pd(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_pd(lij2_SSE1, lij_SSE1);
-
-            diff2_SSE0         = _mm_sub_pd(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_pd(uij2_SSE1, lij2_SSE1);
-            lij_inv_SSE0       = gmx_mm_invsqrt_pd(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_pd(lij2_SSE1);
-            sk2_aj_SSE         = _mm_mul_pd(sk_aj_SSE, sk_aj_SSE);
-            sk2_rinv_SSE0      = _mm_mul_pd(sk2_aj_SSE, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_pd(sk2_aj_SSE, rinv_SSE1);
-            prod_SSE0          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE1);
-
-            logterm_SSE0       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE1, lij_inv_SSE1));
-
-            t1_SSE0            = _mm_sub_pd(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_pd(lij_SSE1, uij_SSE1);
-            t2_SSE0            = _mm_mul_pd(diff2_SSE0,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_pd(diff2_SSE1,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-
-            t3_SSE0            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE1, logterm_SSE1));
-            t1_SSE0            = _mm_add_pd(t1_SSE0, _mm_add_pd(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_pd(t1_SSE1, _mm_add_pd(t2_SSE1, t3_SSE1));
-            t4_SSE0            = _mm_mul_pd(two_SSE, _mm_sub_pd(rai_inv_SSE0, lij_SSE0));
-            t4_SSE1            = _mm_mul_pd(two_SSE, _mm_sub_pd(rai_inv_SSE1, lij_SSE1));
-            t4_SSE0            = _mm_and_pd(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_pd(t4_SSE1, obc_mask3_SSE1);
-            t1_SSE0            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE1, t4_SSE1));
-
-            sum_ai_SSE0        = _mm_add_pd(sum_ai_SSE0, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            sum_ai_SSE1        = _mm_add_pd(sum_ai_SSE1, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-
-            t1_SSE0            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE0),
-                                            _mm_mul_pd(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE1),
-                                            _mm_mul_pd(prod_SSE1, lij3_SSE1));
-
-            t1_SSE0            = _mm_sub_pd(t1_SSE0,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_pd(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_pd(t1_SSE1,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_pd(lij3_SSE1, dr_SSE1))));
-
-            t2_SSE0            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_pd(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_pd(uij3_SSE1, dr_SSE1)));
-            t2_SSE0            = _mm_sub_pd(t2_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE0),
-                                                       _mm_mul_pd(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_pd(t2_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE1),
-                                                       _mm_mul_pd(prod_SSE1, uij3_SSE1)));
-            t3_SSE0            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_pd(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_pd(rinv_SSE1, rinv_SSE1));
-            t3_SSE0            = _mm_sub_pd(t3_SSE0,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_pd(t3_SSE1,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE1, rinv_SSE1))));
-
-            t1_SSE0            = _mm_mul_pd(rinv_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_pd(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_pd(rinv_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_pd(t2_SSE1, t3_SSE1)));
-
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-            dadx += 2;
-
-            /* Evaluate influence of atom ai -> aj */
-            t1_SSE0            = _mm_add_pd(dr_SSE0, sk_ai_SSE0);
-            t1_SSE1            = _mm_add_pd(dr_SSE1, sk_ai_SSE1);
-            t2_SSE0            = _mm_sub_pd(dr_SSE0, sk_ai_SSE0);
-            t2_SSE1            = _mm_sub_pd(dr_SSE1, sk_ai_SSE1);
-            t3_SSE0            = _mm_sub_pd(sk_ai_SSE0, dr_SSE0);
-            t3_SSE1            = _mm_sub_pd(sk_ai_SSE1, dr_SSE1);
-
-            obc_mask1_SSE0     = _mm_cmplt_pd(raj_SSE, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_pd(raj_SSE, t1_SSE1);
-            obc_mask2_SSE0     = _mm_cmplt_pd(raj_SSE, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_pd(raj_SSE, t2_SSE1);
-            obc_mask3_SSE0     = _mm_cmplt_pd(raj_SSE, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_pd(raj_SSE, t3_SSE1);
-            obc_mask1_SSE0     = _mm_and_pd(obc_mask1_SSE0, imask_SSE0);
-            obc_mask1_SSE1     = _mm_and_pd(obc_mask1_SSE1, imask_SSE1);
-
-            uij_SSE0           = gmx_mm_inv_pd(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_pd(t1_SSE1);
-            lij_SSE0           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE0, gmx_mm_inv_pd(t2_SSE0)),
-                                              _mm_andnot_pd(obc_mask2_SSE0, raj_inv_SSE));
-            lij_SSE1           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE1, gmx_mm_inv_pd(t2_SSE1)),
-                                              _mm_andnot_pd(obc_mask2_SSE1, raj_inv_SSE));
-            dlij_SSE0          = _mm_and_pd(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_pd(one_SSE, obc_mask2_SSE1);
-
-            uij2_SSE0          = _mm_mul_pd(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_pd(uij_SSE1, uij_SSE1);
-            uij3_SSE0          = _mm_mul_pd(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_pd(uij2_SSE1, uij_SSE1);
-            lij2_SSE0          = _mm_mul_pd(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_pd(lij_SSE1, lij_SSE1);
-            lij3_SSE0          = _mm_mul_pd(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_pd(lij2_SSE1, lij_SSE1);
-
-            diff2_SSE0         = _mm_sub_pd(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_pd(uij2_SSE1, lij2_SSE1);
-            lij_inv_SSE0       = gmx_mm_invsqrt_pd(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_pd(lij2_SSE1);
-            sk2_rinv_SSE0      = _mm_mul_pd(sk2_ai_SSE0, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_pd(sk2_ai_SSE1, rinv_SSE1);
-            prod_SSE0          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE1);
-
-            logterm_SSE0       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE1, lij_inv_SSE1));
-            t1_SSE0            = _mm_sub_pd(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_pd(lij_SSE1, uij_SSE1);
-            t2_SSE0            = _mm_mul_pd(diff2_SSE0,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_pd(diff2_SSE1,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t3_SSE0            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE1, logterm_SSE1));
-            t1_SSE0            = _mm_add_pd(t1_SSE0, _mm_add_pd(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_pd(t1_SSE1, _mm_add_pd(t2_SSE1, t3_SSE1));
-            t4_SSE0            = _mm_mul_pd(two_SSE, _mm_sub_pd(raj_inv_SSE, lij_SSE0));
-            t4_SSE1            = _mm_mul_pd(two_SSE, _mm_sub_pd(raj_inv_SSE, lij_SSE1));
-            t4_SSE0            = _mm_and_pd(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_pd(t4_SSE1, obc_mask3_SSE1);
-            t1_SSE0            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE1, t4_SSE1));
-
-            _mm_store_pd(work+j, _mm_add_pd(_mm_load_pd(work+j),
-                                            _mm_add_pd(_mm_and_pd(t1_SSE0, obc_mask1_SSE0),
-                                                       _mm_and_pd(t1_SSE1, obc_mask1_SSE1))));
-
-            t1_SSE0            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE0),
-                                            _mm_mul_pd(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE1),
-                                            _mm_mul_pd(prod_SSE1, lij3_SSE1));
-            t1_SSE0            = _mm_sub_pd(t1_SSE0,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_pd(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_pd(t1_SSE1,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_pd(lij3_SSE1, dr_SSE1))));
-            t2_SSE0            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_pd(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_pd(uij3_SSE1, dr_SSE1)));
-            t2_SSE0            = _mm_sub_pd(t2_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE0),
-                                                       _mm_mul_pd(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_pd(t2_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE1),
-                                                       _mm_mul_pd(prod_SSE1, uij3_SSE1)));
-
-            t3_SSE0            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_pd(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_pd(rinv_SSE1, rinv_SSE1));
-
-            t3_SSE0            = _mm_sub_pd(t3_SSE0,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_pd(t3_SSE1,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE1, rinv_SSE1))));
-
-            t1_SSE0            = _mm_mul_pd(rinv_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_pd(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_pd(rinv_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_pd(t2_SSE1, t3_SSE1)));
-
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-            dadx += 2;
-        }
-
-        /* Epilogue part, including exclusion mask */
-        for (j = nj2; j < nj3; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_pd((double *)emask0);
-            jmask_SSE1 = _mm_load_pd((double *)emask1);
-            emask0    += 2*UNROLLJ;
-            emask1    += 2*UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_pd(x_align+j);
-            jy_SSE            = _mm_load_pd(y_align+j);
-            jz_SSE            = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_pd(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_pd(dx_SSE1, dy_SSE1, dz_SSE1);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_pd(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_pd(jmask_SSE1, imask_SSE1);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_pd(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_pd(rsq_SSE1);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_pd(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_pd(rinv_SSE1, jmask_SSE1);
-
-            dr_SSE0            = _mm_mul_pd(rsq_SSE0, rinv_SSE0);
-            dr_SSE1            = _mm_mul_pd(rsq_SSE1, rinv_SSE1);
-
-            sk_aj_SSE          = _mm_load_pd(obc_param+j);
-            raj_SSE            = _mm_load_pd(gb_radius+j);
-
-            raj_inv_SSE        = gmx_mm_inv_pd(raj_SSE);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1_SSE0            = _mm_add_pd(dr_SSE0, sk_aj_SSE);
-            t1_SSE1            = _mm_add_pd(dr_SSE1, sk_aj_SSE);
-            t2_SSE0            = _mm_sub_pd(dr_SSE0, sk_aj_SSE);
-            t2_SSE1            = _mm_sub_pd(dr_SSE1, sk_aj_SSE);
-            t3_SSE0            = _mm_sub_pd(sk_aj_SSE, dr_SSE0);
-            t3_SSE1            = _mm_sub_pd(sk_aj_SSE, dr_SSE1);
-
-            obc_mask1_SSE0     = _mm_cmplt_pd(rai_SSE0, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_pd(rai_SSE1, t1_SSE1);
-            obc_mask2_SSE0     = _mm_cmplt_pd(rai_SSE0, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_pd(rai_SSE1, t2_SSE1);
-            obc_mask3_SSE0     = _mm_cmplt_pd(rai_SSE0, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_pd(rai_SSE1, t3_SSE1);
-            obc_mask1_SSE0     = _mm_and_pd(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_pd(obc_mask1_SSE1, jmask_SSE1);
-
-            uij_SSE0           = gmx_mm_inv_pd(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_pd(t1_SSE1);
-            lij_SSE0           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE0, gmx_mm_inv_pd(t2_SSE0)),
-                                              _mm_andnot_pd(obc_mask2_SSE0, rai_inv_SSE0));
-            lij_SSE1           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE1, gmx_mm_inv_pd(t2_SSE1)),
-                                              _mm_andnot_pd(obc_mask2_SSE1, rai_inv_SSE1));
-
-            dlij_SSE0          = _mm_and_pd(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_pd(one_SSE, obc_mask2_SSE1);
-
-            uij2_SSE0          = _mm_mul_pd(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_pd(uij_SSE1, uij_SSE1);
-            uij3_SSE0          = _mm_mul_pd(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_pd(uij2_SSE1, uij_SSE1);
-            lij2_SSE0          = _mm_mul_pd(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_pd(lij_SSE1, lij_SSE1);
-            lij3_SSE0          = _mm_mul_pd(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_pd(lij2_SSE1, lij_SSE1);
-
-            diff2_SSE0         = _mm_sub_pd(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_pd(uij2_SSE1, lij2_SSE1);
-            lij_inv_SSE0       = gmx_mm_invsqrt_pd(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_pd(lij2_SSE1);
-            sk2_aj_SSE         = _mm_mul_pd(sk_aj_SSE, sk_aj_SSE);
-            sk2_rinv_SSE0      = _mm_mul_pd(sk2_aj_SSE, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_pd(sk2_aj_SSE, rinv_SSE1);
-            prod_SSE0          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE1);
-
-            logterm_SSE0       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE1, lij_inv_SSE1));
-
-            t1_SSE0            = _mm_sub_pd(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_pd(lij_SSE1, uij_SSE1);
-            t2_SSE0            = _mm_mul_pd(diff2_SSE0,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_pd(diff2_SSE1,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-
-            t3_SSE0            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE1, logterm_SSE1));
-            t1_SSE0            = _mm_add_pd(t1_SSE0, _mm_add_pd(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_pd(t1_SSE1, _mm_add_pd(t2_SSE1, t3_SSE1));
-            t4_SSE0            = _mm_mul_pd(two_SSE, _mm_sub_pd(rai_inv_SSE0, lij_SSE0));
-            t4_SSE1            = _mm_mul_pd(two_SSE, _mm_sub_pd(rai_inv_SSE1, lij_SSE1));
-            t4_SSE0            = _mm_and_pd(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_pd(t4_SSE1, obc_mask3_SSE1);
-            t1_SSE0            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE1, t4_SSE1));
-
-            sum_ai_SSE0        = _mm_add_pd(sum_ai_SSE0, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            sum_ai_SSE1        = _mm_add_pd(sum_ai_SSE1, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-
-            t1_SSE0            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE0),
-                                            _mm_mul_pd(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE1),
-                                            _mm_mul_pd(prod_SSE1, lij3_SSE1));
-            t1_SSE0            = _mm_sub_pd(t1_SSE0,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_pd(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_pd(t1_SSE1,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_pd(lij3_SSE1, dr_SSE1))));
-
-            t2_SSE0            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_pd(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_pd(uij3_SSE1, dr_SSE1)));
-            t2_SSE0            = _mm_sub_pd(t2_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE0),
-                                                       _mm_mul_pd(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_pd(t2_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE1),
-                                                       _mm_mul_pd(prod_SSE1, uij3_SSE1)));
-            t3_SSE0            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_pd(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_pd(rinv_SSE1, rinv_SSE1));
-            t3_SSE0            = _mm_sub_pd(t3_SSE0,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_pd(t3_SSE1,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE1, rinv_SSE1))));
-
-            t1_SSE0            = _mm_mul_pd(rinv_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_pd(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_pd(rinv_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_pd(t2_SSE1, t3_SSE1)));
-
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-            dadx += 2;
-
-            /* Evaluate influence of atom ai -> aj */
-            t1_SSE0            = _mm_add_pd(dr_SSE0, sk_ai_SSE0);
-            t1_SSE1            = _mm_add_pd(dr_SSE1, sk_ai_SSE1);
-            t2_SSE0            = _mm_sub_pd(dr_SSE0, sk_ai_SSE0);
-            t2_SSE1            = _mm_sub_pd(dr_SSE1, sk_ai_SSE1);
-            t3_SSE0            = _mm_sub_pd(sk_ai_SSE0, dr_SSE0);
-            t3_SSE1            = _mm_sub_pd(sk_ai_SSE1, dr_SSE1);
-
-            obc_mask1_SSE0     = _mm_cmplt_pd(raj_SSE, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_pd(raj_SSE, t1_SSE1);
-            obc_mask2_SSE0     = _mm_cmplt_pd(raj_SSE, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_pd(raj_SSE, t2_SSE1);
-            obc_mask3_SSE0     = _mm_cmplt_pd(raj_SSE, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_pd(raj_SSE, t3_SSE1);
-            obc_mask1_SSE0     = _mm_and_pd(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_pd(obc_mask1_SSE1, jmask_SSE1);
-
-            uij_SSE0           = gmx_mm_inv_pd(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_pd(t1_SSE1);
-            lij_SSE0           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE0, gmx_mm_inv_pd(t2_SSE0)),
-                                              _mm_andnot_pd(obc_mask2_SSE0, raj_inv_SSE));
-            lij_SSE1           = _mm_or_pd(   _mm_and_pd(obc_mask2_SSE1, gmx_mm_inv_pd(t2_SSE1)),
-                                              _mm_andnot_pd(obc_mask2_SSE1, raj_inv_SSE));
-
-            dlij_SSE0          = _mm_and_pd(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_pd(one_SSE, obc_mask2_SSE1);
-
-            uij2_SSE0          = _mm_mul_pd(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_pd(uij_SSE1, uij_SSE1);
-            uij3_SSE0          = _mm_mul_pd(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_pd(uij2_SSE1, uij_SSE1);
-            lij2_SSE0          = _mm_mul_pd(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_pd(lij_SSE1, lij_SSE1);
-            lij3_SSE0          = _mm_mul_pd(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_pd(lij2_SSE1, lij_SSE1);
-
-            diff2_SSE0         = _mm_sub_pd(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_pd(uij2_SSE1, lij2_SSE1);
-            lij_inv_SSE0       = gmx_mm_invsqrt_pd(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_pd(lij2_SSE1);
-            sk2_rinv_SSE0      = _mm_mul_pd(sk2_ai_SSE0, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_pd(sk2_ai_SSE1, rinv_SSE1);
-            prod_SSE0          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_pd(onefourth_SSE, sk2_rinv_SSE1);
-
-            logterm_SSE0       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_pd(_mm_mul_pd(uij_SSE1, lij_inv_SSE1));
-            t1_SSE0            = _mm_sub_pd(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_pd(lij_SSE1, uij_SSE1);
-            t2_SSE0            = _mm_mul_pd(diff2_SSE0,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_pd(diff2_SSE1,
-                                            _mm_sub_pd(_mm_mul_pd(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t3_SSE0            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_pd(half_SSE, _mm_mul_pd(rinv_SSE1, logterm_SSE1));
-            t1_SSE0            = _mm_add_pd(t1_SSE0, _mm_add_pd(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_pd(t1_SSE1, _mm_add_pd(t2_SSE1, t3_SSE1));
-            t4_SSE0            = _mm_mul_pd(two_SSE, _mm_sub_pd(raj_inv_SSE, lij_SSE0));
-            t4_SSE1            = _mm_mul_pd(two_SSE, _mm_sub_pd(raj_inv_SSE, lij_SSE1));
-            t4_SSE0            = _mm_and_pd(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_pd(t4_SSE1, obc_mask3_SSE1);
-            t1_SSE0            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_pd(half_SSE, _mm_add_pd(t1_SSE1, t4_SSE1));
-
-            _mm_store_pd(work+j, _mm_add_pd(_mm_load_pd(work+j),
-                                            _mm_add_pd(_mm_and_pd(t1_SSE0, obc_mask1_SSE0),
-                                                       _mm_and_pd(t1_SSE1, obc_mask1_SSE1))));
-
-            t1_SSE0            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE0),
-                                            _mm_mul_pd(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_pd(_mm_mul_pd(half_SSE, lij2_SSE1),
-                                            _mm_mul_pd(prod_SSE1, lij3_SSE1));
-
-            t1_SSE0            = _mm_sub_pd(t1_SSE0,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_pd(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_pd(t1_SSE1,
-                                            _mm_mul_pd(onefourth_SSE,
-                                                       _mm_add_pd(_mm_mul_pd(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_pd(lij3_SSE1, dr_SSE1))));
-            t2_SSE0            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_pd(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_pd(onefourth_SSE,
-                                            _mm_add_pd(_mm_mul_pd(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_pd(uij3_SSE1, dr_SSE1)));
-            t2_SSE0            = _mm_sub_pd(t2_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE0),
-                                                       _mm_mul_pd(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_pd(t2_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(half_SSE, uij2_SSE1),
-                                                       _mm_mul_pd(prod_SSE1, uij3_SSE1)));
-
-            t3_SSE0            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_pd(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_pd(_mm_mul_pd(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_pd(rinv_SSE1, rinv_SSE1));
-
-            t3_SSE0            = _mm_sub_pd(t3_SSE0,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_pd(t3_SSE1,
-                                            _mm_mul_pd(_mm_mul_pd(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_pd(one_SSE,
-                                                                  _mm_mul_pd(sk2_rinv_SSE1, rinv_SSE1))));
-
-            t1_SSE0            = _mm_mul_pd(rinv_SSE0,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_pd(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_pd(rinv_SSE1,
-                                            _mm_add_pd(_mm_mul_pd(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_pd(t2_SSE1, t3_SSE1)));
-
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE0, obc_mask1_SSE0));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_and_pd(t1_SSE1, obc_mask1_SSE1));
-            dadx += 2;
-        }
-        GMX_MM_TRANSPOSE2_PD(sum_ai_SSE0, sum_ai_SSE1);
-        sum_ai_SSE0 = _mm_add_pd(sum_ai_SSE0, sum_ai_SSE1);
-        _mm_store_pd(work+i, _mm_add_pd(sum_ai_SSE0, _mm_load_pd(work+i)));
-    }
-
-
-    for (i = 0; i < natoms/2+1; i++)
-    {
-        work[i] += work[natoms+i];
-    }
-
-    /* Parallel summations would go here if ever implemented in DD */
-
-    if (gb_algorithm == egbHCT)
-    {
-        /* HCT */
-        for (i = 0; i < natoms; i++)
-        {
-            if (born->use[i] != 0)
-            {
-                rai     = top->atomtypes.gb_radius[mdatoms->typeA[i]]-born->gb_doffset;
-                sum_ai  = 1.0/rai - work[i];
-                min_rad = rai + born->gb_doffset;
-                rad     = 1.0/sum_ai;
-
-                born->bRad[i]   = rad > min_rad ? rad : min_rad;
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-            }
-        }
-
-    }
-    else
-    {
-        /* OBC */
-
-        /* Calculate the radii */
-        for (i = 0; i < natoms; i++)
-        {
-
-            if (born->use[i] != 0)
-            {
-                rai        = top->atomtypes.gb_radius[mdatoms->typeA[i]];
-                rai_inv2   = 1.0/rai;
-                rai        = rai-born->gb_doffset;
-                rai_inv    = 1.0/rai;
-                sum_ai     = rai * work[i];
-                sum_ai2    = sum_ai  * sum_ai;
-                sum_ai3    = sum_ai2 * sum_ai;
-
-                tsum          = tanh(born->obc_alpha*sum_ai-born->obc_beta*sum_ai2+born->obc_gamma*sum_ai3);
-                born->bRad[i] = rai_inv - tsum*rai_inv2;
-                born->bRad[i] = 1.0 / born->bRad[i];
-
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-
-                tchain         = rai * (born->obc_alpha-2*born->obc_beta*sum_ai+3*born->obc_gamma*sum_ai2);
-                born->drobc[i] = (1.0-tsum*tsum)*tchain*rai_inv2;
-            }
-        }
-    }
-
-    return 0;
-}
-
-
-
-
-
-
-
-
-int
-genborn_allvsall_calc_chainrule_sse2_double(t_forcerec   *           fr,
-                                            t_mdatoms   *            mdatoms,
-                                            gmx_genborn_t   *        born,
-                                            double *                 x,
-                                            double *                 f,
-                                            int                      gb_algorithm,
-                                            void   *                 paadata)
-{
-    gmx_allvsallgb2_data_t *aadata;
-    int                     natoms;
-    int                     ni0, ni1;
-    int                     nj0, nj1, nj2, nj3;
-    int                     i, j, k, n;
-    int                     idx;
-    int              *      mask;
-    int              *      pmask0;
-    int              *      emask0;
-    int              *      jindex;
-
-    double                  ix, iy, iz;
-    double                  fix, fiy, fiz;
-    double                  jx, jy, jz;
-    double                  dx, dy, dz;
-    double                  tx, ty, tz;
-    double                  rbai, rbaj, fgb, fgb_ai, rbi;
-    double            *     rb;
-    double            *     dadx;
-    double            *     x_align;
-    double            *     y_align;
-    double            *     z_align;
-    double            *     fx_align;
-    double            *     fy_align;
-    double            *     fz_align;
-    double                  tmpsum[2];
-
-    __m128d                 jmask_SSE0, jmask_SSE1;
-    __m128d                 ix_SSE0, iy_SSE0, iz_SSE0;
-    __m128d                 ix_SSE1, iy_SSE1, iz_SSE1;
-    __m128d                 fix_SSE0, fiy_SSE0, fiz_SSE0;
-    __m128d                 fix_SSE1, fiy_SSE1, fiz_SSE1;
-    __m128d                 rbai_SSE0, rbai_SSE1;
-    __m128d                 imask_SSE0, imask_SSE1;
-    __m128d                 jx_SSE, jy_SSE, jz_SSE, rbaj_SSE;
-    __m128d                 dx_SSE0, dy_SSE0, dz_SSE0;
-    __m128d                 dx_SSE1, dy_SSE1, dz_SSE1;
-    __m128d                 fgb_SSE0, fgb_ai_SSE0;
-    __m128d                 fgb_SSE1, fgb_ai_SSE1;
-    __m128d                 tx_SSE0, ty_SSE0, tz_SSE0;
-    __m128d                 tx_SSE1, ty_SSE1, tz_SSE1;
-    __m128d                 t1, t2, tmpSSE;
-
-    natoms              = mdatoms->nr;
-    ni0                 = 0;
-    ni1                 = mdatoms->homenr;
-
-    aadata = (gmx_allvsallgb2_data_t *)paadata;
-
-    x_align  = aadata->x_align;
-    y_align  = aadata->y_align;
-    z_align  = aadata->z_align;
-    fx_align = aadata->fx_align;
-    fy_align = aadata->fy_align;
-    fz_align = aadata->fz_align;
-
-    jindex    = aadata->jindex_gb;
-    dadx      = fr->dadx;
-
-    n  = 0;
-    rb = aadata->work;
-
-    /* Loop to get the proper form for the Born radius term */
-    if (gb_algorithm == egbSTILL)
-    {
-        for (i = 0; i < natoms; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = (2 * rbi * rbi * fr->dvda[i])/ONE_4PI_EPS0;
-        }
-    }
-    else if (gb_algorithm == egbHCT)
-    {
-        for (i = 0; i < natoms; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = rbi * rbi * fr->dvda[i];
-        }
-    }
-    else if (gb_algorithm == egbOBC)
-    {
-        for (idx = 0; idx < natoms; idx++)
-        {
-            rbi     = born->bRad[idx];
-            rb[idx] = rbi * rbi * born->drobc[idx] * fr->dvda[idx];
-        }
-    }
-
-    for (i = 0; i < 2*natoms; i++)
-    {
-        fx_align[i]       = 0;
-        fy_align[i]       = 0;
-        fz_align[i]       = 0;
-    }
-
-
-    for (i = 0; i < natoms; i++)
-    {
-        rb[i+natoms] = rb[i];
-    }
-
-    for (i = ni0; i < ni1; i += UNROLLI)
-    {
-        /* We assume shifts are NOT used for all-vs-all interactions */
-
-        /* Load i atom data */
-        ix_SSE0          = _mm_load1_pd(x_align+i);
-        iy_SSE0          = _mm_load1_pd(y_align+i);
-        iz_SSE0          = _mm_load1_pd(z_align+i);
-        ix_SSE1          = _mm_load1_pd(x_align+i+1);
-        iy_SSE1          = _mm_load1_pd(y_align+i+1);
-        iz_SSE1          = _mm_load1_pd(z_align+i+1);
-
-        fix_SSE0         = _mm_setzero_pd();
-        fiy_SSE0         = _mm_setzero_pd();
-        fiz_SSE0         = _mm_setzero_pd();
-        fix_SSE1         = _mm_setzero_pd();
-        fiy_SSE1         = _mm_setzero_pd();
-        fiz_SSE1         = _mm_setzero_pd();
-
-        rbai_SSE0        = _mm_load1_pd(rb+i);
-        rbai_SSE1        = _mm_load1_pd(rb+i+1);
-
-        /* Load limits for loop over neighbors */
-        nj0              = jindex[4*i];
-        nj3              = jindex[4*i+3];
-
-        /* No masks necessary, since the stored chain rule derivatives will be zero in those cases! */
-        for (j = nj0; j < nj3; j += UNROLLJ)
-        {
-            /* load j atom coordinates */
-            jx_SSE           = _mm_load_pd(x_align+j);
-            jy_SSE           = _mm_load_pd(y_align+j);
-            jz_SSE           = _mm_load_pd(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0          = _mm_sub_pd(ix_SSE0, jx_SSE);
-            dy_SSE0          = _mm_sub_pd(iy_SSE0, jy_SSE);
-            dz_SSE0          = _mm_sub_pd(iz_SSE0, jz_SSE);
-            dx_SSE1          = _mm_sub_pd(ix_SSE1, jx_SSE);
-            dy_SSE1          = _mm_sub_pd(iy_SSE1, jy_SSE);
-            dz_SSE1          = _mm_sub_pd(iz_SSE1, jz_SSE);
-
-            rbaj_SSE         = _mm_load_pd(rb+j);
-
-            fgb_SSE0         = _mm_mul_pd(rbai_SSE0, _mm_load_pd(dadx));
-            dadx            += 2;
-            fgb_SSE1         = _mm_mul_pd(rbai_SSE1, _mm_load_pd(dadx));
-            dadx            += 2;
-
-            fgb_ai_SSE0      = _mm_mul_pd(rbaj_SSE, _mm_load_pd(dadx));
-            dadx            += 2;
-            fgb_ai_SSE1      = _mm_mul_pd(rbaj_SSE, _mm_load_pd(dadx));
-            dadx            += 2;
-
-            /* Total force between ai and aj is the sum of ai->aj and aj->ai */
-            fgb_SSE0         = _mm_add_pd(fgb_SSE0, fgb_ai_SSE0);
-            fgb_SSE1         = _mm_add_pd(fgb_SSE1, fgb_ai_SSE1);
-
-            /* Calculate temporary vectorial force */
-            tx_SSE0            = _mm_mul_pd(fgb_SSE0, dx_SSE0);
-            ty_SSE0            = _mm_mul_pd(fgb_SSE0, dy_SSE0);
-            tz_SSE0            = _mm_mul_pd(fgb_SSE0, dz_SSE0);
-            tx_SSE1            = _mm_mul_pd(fgb_SSE1, dx_SSE1);
-            ty_SSE1            = _mm_mul_pd(fgb_SSE1, dy_SSE1);
-            tz_SSE1            = _mm_mul_pd(fgb_SSE1, dz_SSE1);
-
-            /* Increment i atom force */
-            fix_SSE0          = _mm_add_pd(fix_SSE0, tx_SSE0);
-            fiy_SSE0          = _mm_add_pd(fiy_SSE0, ty_SSE0);
-            fiz_SSE0          = _mm_add_pd(fiz_SSE0, tz_SSE0);
-            fix_SSE1          = _mm_add_pd(fix_SSE1, tx_SSE1);
-            fiy_SSE1          = _mm_add_pd(fiy_SSE1, ty_SSE1);
-            fiz_SSE1          = _mm_add_pd(fiz_SSE1, tz_SSE1);
-
-            /* Decrement j atom force */
-            _mm_store_pd(fx_align+j,
-                         _mm_sub_pd( _mm_load_pd(fx_align+j), _mm_add_pd(tx_SSE0, tx_SSE1) ));
-            _mm_store_pd(fy_align+j,
-                         _mm_sub_pd( _mm_load_pd(fy_align+j), _mm_add_pd(ty_SSE0, ty_SSE1) ));
-            _mm_store_pd(fz_align+j,
-                         _mm_sub_pd( _mm_load_pd(fz_align+j), _mm_add_pd(tz_SSE0, tz_SSE1) ));
-        }
-
-        /* Add i forces to mem */
-        GMX_MM_TRANSPOSE2_PD(fix_SSE0, fix_SSE1);
-        fix_SSE0 = _mm_add_pd(fix_SSE0, fix_SSE1);
-        _mm_store_pd(fx_align+i, _mm_add_pd(fix_SSE0, _mm_load_pd(fx_align+i)));
-
-        GMX_MM_TRANSPOSE2_PD(fiy_SSE0, fiy_SSE1);
-        fiy_SSE0 = _mm_add_pd(fiy_SSE0, fiy_SSE1);
-        _mm_store_pd(fy_align+i, _mm_add_pd(fiy_SSE0, _mm_load_pd(fy_align+i)));
-
-        GMX_MM_TRANSPOSE2_PD(fiz_SSE0, fiz_SSE1);
-        fiz_SSE0 = _mm_add_pd(fiz_SSE0, fiz_SSE1);
-        _mm_store_pd(fz_align+i, _mm_add_pd(fiz_SSE0, _mm_load_pd(fz_align+i)));
-    }
-
-    for (i = 0; i < natoms; i++)
-    {
-        f[3*i]       += fx_align[i] + fx_align[natoms+i];
-        f[3*i+1]     += fy_align[i] + fy_align[natoms+i];
-        f[3*i+2]     += fz_align[i] + fz_align[natoms+i];
-    }
-
-    return 0;
-}
-
-#else
-/* dummy variable when not using SSE */
-int genborn_allvsall_sse2_double_dummy;
-
-
-#endif
diff --git a/src/gromacs/mdlib/genborn_allvsall_sse2_double.h b/src/gromacs/mdlib/genborn_allvsall_sse2_double.h
deleted file mode 100644 (file)
index 3629475..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS Development Team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#ifndef _GENBORN_ALLVSALL_SSE2_DOUBLE_H
-#define _GENBORN_ALLVSALL_SSE2_DOUBLE_H
-
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/legacyheaders/types/simple.h"
-
-int
-genborn_allvsall_calc_still_radii_sse2_double(t_forcerec *           fr,
-                                              t_mdatoms *            mdatoms,
-                                              gmx_genborn_t *        born,
-                                              gmx_localtop_t *       top,
-                                              double *               x,
-                                              t_commrec *            cr,
-                                              void *                 work);
-
-int
-genborn_allvsall_calc_hct_obc_radii_sse2_double(t_forcerec *           fr,
-                                                t_mdatoms *            mdatoms,
-                                                gmx_genborn_t *        born,
-                                                int                    gb_algorithm,
-                                                gmx_localtop_t *       top,
-                                                double *               x,
-                                                t_commrec *            cr,
-                                                void *                 work);
-
-int
-genborn_allvsall_calc_chainrule_sse2_double(t_forcerec *           fr,
-                                            t_mdatoms *            mdatoms,
-                                            gmx_genborn_t *        born,
-                                            double *               x,
-                                            double *               f,
-                                            int                    gb_algorithm,
-                                            void *                 work);
-
-#endif
diff --git a/src/gromacs/mdlib/genborn_allvsall_sse2_single.c b/src/gromacs/mdlib/genborn_allvsall_sse2_single.c
deleted file mode 100644 (file)
index 8c3ce47..0000000
+++ /dev/null
@@ -1,3500 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS Development Team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include <math.h>
-
-#include "gromacs/legacyheaders/genborn.h"
-#include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/types/simple.h"
-#include "gromacs/math/units.h"
-#include "gromacs/math/vec.h"
-#include "gromacs/mdlib/genborn_allvsall.h"
-#include "gromacs/utility/smalloc.h"
-
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-
-#include <gmx_sse2_single.h>
-
-
-#define SIMD_WIDTH 4
-#define UNROLLI    4
-#define UNROLLJ    4
-
-
-
-
-
-
-
-
-
-typedef struct
-{
-    int *      jindex_gb;
-    int **     prologue_mask_gb;
-    int **     epilogue_mask;
-    int *      imask;
-    real *     gb_radius;
-    real *     workparam;
-    real *     work;
-    real *     x_align;
-    real *     y_align;
-    real *     z_align;
-    real *     fx_align;
-    real *     fy_align;
-    real *     fz_align;
-}
-gmx_allvsallgb2_data_t;
-
-
-static int
-calc_maxoffset(int i, int natoms)
-{
-    int maxoffset;
-
-    if ((natoms % 2) == 1)
-    {
-        /* Odd number of atoms, easy */
-        maxoffset = natoms/2;
-    }
-    else if ((natoms % 4) == 0)
-    {
-        /* Multiple of four is hard */
-        if (i < natoms/2)
-        {
-            if ((i % 2) == 0)
-            {
-                maxoffset = natoms/2;
-            }
-            else
-            {
-                maxoffset = natoms/2-1;
-            }
-        }
-        else
-        {
-            if ((i % 2) == 1)
-            {
-                maxoffset = natoms/2;
-            }
-            else
-            {
-                maxoffset = natoms/2-1;
-            }
-        }
-    }
-    else
-    {
-        /* natoms/2 = odd */
-        if ((i % 2) == 0)
-        {
-            maxoffset = natoms/2;
-        }
-        else
-        {
-            maxoffset = natoms/2-1;
-        }
-    }
-
-    return maxoffset;
-}
-
-static void
-setup_gb_exclusions_and_indices(gmx_allvsallgb2_data_t     *   aadata,
-                                t_ilist     *                  ilist,
-                                int                            start,
-                                int                            end,
-                                int                            natoms,
-                                gmx_bool                       bInclude12,
-                                gmx_bool                       bInclude13,
-                                gmx_bool                       bInclude14)
-{
-    int   i, j, k, tp;
-    int   a1, a2;
-    int   ni0, ni1, nj0, nj1, nj;
-    int   imin, imax, iexcl;
-    int   max_offset;
-    int   max_excl_offset;
-    int   firstinteraction;
-    int   ibase;
-    int  *pi;
-
-    /* This routine can appear to be a bit complex, but it is mostly book-keeping.
-     * To enable the fast all-vs-all kernel we need to be able to stream through all coordinates
-     * whether they should interact or not.
-     *
-     * To avoid looping over the exclusions, we create a simple mask that is 1 if the interaction
-     * should be present, otherwise 0. Since exclusions typically only occur when i & j are close,
-     * we create a jindex array with three elements per i atom: the starting point, the point to
-     * which we need to check exclusions, and the end point.
-     * This way we only have to allocate a short exclusion mask per i atom.
-     */
-
-    ni0 = (start/UNROLLI)*UNROLLI;
-    ni1 = ((end+UNROLLI-1)/UNROLLI)*UNROLLI;
-
-    /* Set the interaction mask to only enable the i atoms we want to include */
-    snew(pi, natoms+UNROLLI+2*SIMD_WIDTH);
-    aadata->imask = (int *) (((size_t) pi + 16) & (~((size_t) 15)));
-    for (i = 0; i < natoms+UNROLLI; i++)
-    {
-        aadata->imask[i] = (i >= start && i < end) ? 0xFFFFFFFF : 0;
-    }
-
-    /* Allocate memory for our modified jindex array */
-    snew(aadata->jindex_gb, 4*(natoms+UNROLLI));
-    for (i = 0; i < 4*(natoms+UNROLLI); i++)
-    {
-        aadata->jindex_gb[i] = 0;
-    }
-
-    /* Create the exclusion masks for the prologue part */
-    snew(aadata->prologue_mask_gb, natoms+UNROLLI); /* list of pointers */
-
-    /* First zero everything to avoid uninitialized data */
-    for (i = 0; i < natoms+UNROLLI; i++)
-    {
-        aadata->prologue_mask_gb[i] = NULL;
-    }
-
-    /* Calculate the largest exclusion range we need for each UNROLLI-tuplet of i atoms. */
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        max_excl_offset = -1;
-
-        /* First find maxoffset for the next 4 atoms (or fewer if we are close to end) */
-        imax = ((ibase+UNROLLI) < end) ? (ibase+UNROLLI) : end;
-
-        /* Which atom is the first we (might) interact with? */
-        imin = natoms; /* Guaranteed to be overwritten by one of 'firstinteraction' */
-        for (i = ibase; i < imax; i++)
-        {
-            /* Before exclusions, which atom is the first we (might) interact with? */
-            firstinteraction = i+1;
-            max_offset       = calc_maxoffset(i, natoms);
-
-            if (!bInclude12)
-            {
-                for (j = 0; j < ilist[F_GB12].nr; j += 3)
-                {
-                    a1 = ilist[F_GB12].iatoms[j+1];
-                    a2 = ilist[F_GB12].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k == firstinteraction)
-                    {
-                        firstinteraction++;
-                    }
-                }
-            }
-            if (!bInclude13)
-            {
-                for (j = 0; j < ilist[F_GB13].nr; j += 3)
-                {
-                    a1 = ilist[F_GB13].iatoms[j+1];
-                    a2 = ilist[F_GB13].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k == firstinteraction)
-                    {
-                        firstinteraction++;
-                    }
-                }
-            }
-            if (!bInclude14)
-            {
-                for (j = 0; j < ilist[F_GB14].nr; j += 3)
-                {
-                    a1 = ilist[F_GB14].iatoms[j+1];
-                    a2 = ilist[F_GB14].iatoms[j+2];
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k == firstinteraction)
-                    {
-                        firstinteraction++;
-                    }
-                }
-            }
-            imin = (firstinteraction < imin) ? firstinteraction : imin;
-        }
-        /* round down to j unrolling factor */
-        imin = (imin/UNROLLJ)*UNROLLJ;
-
-        for (i = ibase; i < imax; i++)
-        {
-            max_offset = calc_maxoffset(i, natoms);
-
-            if (!bInclude12)
-            {
-                for (j = 0; j < ilist[F_GB12].nr; j += 3)
-                {
-                    a1 = ilist[F_GB12].iatoms[j+1];
-                    a2 = ilist[F_GB12].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k < imin)
-                    {
-                        k += natoms;
-                    }
-
-                    if (k > i+max_offset)
-                    {
-                        continue;
-                    }
-
-                    k = k - imin;
-
-                    if (k+natoms <= max_offset)
-                    {
-                        k += natoms;
-                    }
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
-                }
-            }
-            if (!bInclude13)
-            {
-                for (j = 0; j < ilist[F_GB13].nr; j += 3)
-                {
-                    a1 = ilist[F_GB13].iatoms[j+1];
-                    a2 = ilist[F_GB13].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k < imin)
-                    {
-                        k += natoms;
-                    }
-
-                    if (k > i+max_offset)
-                    {
-                        continue;
-                    }
-
-                    k = k - imin;
-
-                    if (k+natoms <= max_offset)
-                    {
-                        k += natoms;
-                    }
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
-                }
-            }
-            if (!bInclude14)
-            {
-                for (j = 0; j < ilist[F_GB14].nr; j += 3)
-                {
-                    a1 = ilist[F_GB14].iatoms[j+1];
-                    a2 = ilist[F_GB14].iatoms[j+2];
-
-                    if (a1 == i)
-                    {
-                        k = a2;
-                    }
-                    else if (a2 == i)
-                    {
-                        k = a1;
-                    }
-                    else
-                    {
-                        continue;
-                    }
-
-                    if (k < imin)
-                    {
-                        k += natoms;
-                    }
-
-                    if (k > i+max_offset)
-                    {
-                        continue;
-                    }
-
-                    k = k - imin;
-
-                    if (k+natoms <= max_offset)
-                    {
-                        k += natoms;
-                    }
-                    max_excl_offset = (k > max_excl_offset) ? k : max_excl_offset;
-                }
-            }
-        }
-
-        /* The offset specifies the last atom to be excluded, so add one unit to get an upper loop limit */
-        max_excl_offset++;
-        /* round up to j unrolling factor */
-        max_excl_offset = (max_excl_offset/UNROLLJ+1)*UNROLLJ;
-
-        /* Set all the prologue masks length to this value (even for i>end) */
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-            aadata->jindex_gb[4*i]   = imin;
-            aadata->jindex_gb[4*i+1] = imin+max_excl_offset;
-        }
-    }
-
-    /* Now the hard part, loop over it all again to calculate the actual contents of the prologue masks */
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-            nj   = aadata->jindex_gb[4*i+1] - aadata->jindex_gb[4*i];
-            imin = aadata->jindex_gb[4*i];
-
-            /* Allocate aligned memory */
-            snew(pi, nj+2*SIMD_WIDTH);
-            aadata->prologue_mask_gb[i] = (int *) (((size_t) pi + 16) & (~((size_t) 15)));
-
-            max_offset = calc_maxoffset(i, natoms);
-
-            /* Include interactions i+1 <= j < i+maxoffset */
-            for (k = 0; k < nj; k++)
-            {
-                j = imin + k;
-
-                if ( (j > i) && (j <= i+max_offset) )
-                {
-                    aadata->prologue_mask_gb[i][k] = 0xFFFFFFFF;
-                }
-                else
-                {
-                    aadata->prologue_mask_gb[i][k] = 0;
-                }
-            }
-
-            /* Clear out the explicit exclusions */
-            if (i < end)
-            {
-                if (!bInclude12)
-                {
-                    for (j = 0; j < ilist[F_GB12].nr; j += 3)
-                    {
-                        a1 = ilist[F_GB12].iatoms[j+1];
-                        a2 = ilist[F_GB12].iatoms[j+2];
-
-                        if (a1 == i)
-                        {
-                            k = a2;
-                        }
-                        else if (a2 == i)
-                        {
-                            k = a1;
-                        }
-                        else
-                        {
-                            continue;
-                        }
-
-                        if (k > i+max_offset)
-                        {
-                            continue;
-                        }
-                        k = k-i;
-
-                        if (k+natoms <= max_offset)
-                        {
-                            k += natoms;
-                        }
-
-                        k = k+i-imin;
-                        if (k >= 0)
-                        {
-                            aadata->prologue_mask_gb[i][k] = 0;
-                        }
-                    }
-                }
-                if (!bInclude13)
-                {
-                    for (j = 0; j < ilist[F_GB13].nr; j += 3)
-                    {
-                        a1 = ilist[F_GB13].iatoms[j+1];
-                        a2 = ilist[F_GB13].iatoms[j+2];
-
-                        if (a1 == i)
-                        {
-                            k = a2;
-                        }
-                        else if (a2 == i)
-                        {
-                            k = a1;
-                        }
-                        else
-                        {
-                            continue;
-                        }
-
-                        if (k > i+max_offset)
-                        {
-                            continue;
-                        }
-                        k = k-i;
-
-                        if (k+natoms <= max_offset)
-                        {
-                            k += natoms;
-                        }
-
-                        k = k+i-imin;
-                        if (k >= 0)
-                        {
-                            aadata->prologue_mask_gb[i][k] = 0;
-                        }
-                    }
-                }
-                if (!bInclude14)
-                {
-                    for (j = 0; j < ilist[F_GB14].nr; j += 3)
-                    {
-                        a1 = ilist[F_GB14].iatoms[j+1];
-                        a2 = ilist[F_GB14].iatoms[j+2];
-
-                        if (a1 == i)
-                        {
-                            k = a2;
-                        }
-                        else if (a2 == i)
-                        {
-                            k = a1;
-                        }
-                        else
-                        {
-                            continue;
-                        }
-
-                        if (k > i+max_offset)
-                        {
-                            continue;
-                        }
-                        k = k-i;
-
-                        if (k+natoms <= max_offset)
-                        {
-                            k += natoms;
-                        }
-
-                        k = k+i-imin;
-                        if (k >= 0)
-                        {
-                            aadata->prologue_mask_gb[i][k] = 0;
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /* Construct the epilogue mask - this just contains the check for maxoffset */
-    snew(aadata->epilogue_mask, natoms+UNROLLI);
-
-    /* First zero everything to avoid uninitialized data */
-    for (i = 0; i < natoms+UNROLLI; i++)
-    {
-        aadata->jindex_gb[4*i+2]    = aadata->jindex_gb[4*i+1];
-        aadata->jindex_gb[4*i+3]    = aadata->jindex_gb[4*i+1];
-        aadata->epilogue_mask[i]    = NULL;
-    }
-
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        /* Find the lowest index for which we need to use the epilogue */
-        imin       = ibase;
-        max_offset = calc_maxoffset(imin, natoms);
-
-        imin = imin + 1 + max_offset;
-
-        /* Find largest index for which we need to use the epilogue */
-        imax = ibase + UNROLLI-1;
-        imax = (imax < end) ? imax : end;
-
-        max_offset = calc_maxoffset(imax, natoms);
-        imax       = imax + 1 + max_offset + UNROLLJ - 1;
-
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-            /* Start of epilogue - round down to j tile limit */
-            aadata->jindex_gb[4*i+2] = (imin/UNROLLJ)*UNROLLJ;
-            /* Make sure we dont overlap - for small systems everything is done in the prologue */
-            aadata->jindex_gb[4*i+2] = (aadata->jindex_gb[4*i+1] > aadata->jindex_gb[4*i+2]) ? aadata->jindex_gb[4*i+1] : aadata->jindex_gb[4*i+2];
-            /* Round upwards to j tile limit */
-            aadata->jindex_gb[4*i+3] = (imax/UNROLLJ)*UNROLLJ;
-            /* Make sure we dont have a negative range for the epilogue */
-            aadata->jindex_gb[4*i+3] = (aadata->jindex_gb[4*i+2] > aadata->jindex_gb[4*i+3]) ? aadata->jindex_gb[4*i+2] : aadata->jindex_gb[4*i+3];
-        }
-    }
-
-    /* And fill it with data... */
-
-    for (ibase = ni0; ibase < ni1; ibase += UNROLLI)
-    {
-        for (i = ibase; i < ibase+UNROLLI; i++)
-        {
-
-            nj = aadata->jindex_gb[4*i+3] - aadata->jindex_gb[4*i+2];
-
-            /* Allocate aligned memory */
-            snew(pi, nj+2*SIMD_WIDTH);
-            aadata->epilogue_mask[i] = (int *) (((size_t) pi + 16) & (~((size_t) 15)));
-
-            max_offset = calc_maxoffset(i, natoms);
-
-            for (k = 0; k < nj; k++)
-            {
-                j = aadata->jindex_gb[4*i+2] + k;
-                aadata->epilogue_mask[i][k] = (j <= i+max_offset) ? 0xFFFFFFFF : 0;
-            }
-        }
-    }
-}
-
-
-static void
-genborn_allvsall_setup(gmx_allvsallgb2_data_t     **  p_aadata,
-                       gmx_localtop_t     *           top,
-                       gmx_genborn_t     *            born,
-                       t_mdatoms     *                mdatoms,
-                       real                           radius_offset,
-                       int                            gb_algorithm,
-                       gmx_bool                       bInclude12,
-                       gmx_bool                       bInclude13,
-                       gmx_bool                       bInclude14)
-{
-    int                     i, j, idx;
-    int                     natoms;
-    gmx_allvsallgb2_data_t *aadata;
-    real                   *p;
-
-    natoms = mdatoms->nr;
-
-    snew(aadata, 1);
-    *p_aadata = aadata;
-
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->x_align = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->y_align = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->z_align = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->fx_align = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->fy_align = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-    snew(p, 2*natoms+2*SIMD_WIDTH);
-    aadata->fz_align = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    snew(p, 2*natoms+UNROLLJ+SIMD_WIDTH);
-    aadata->gb_radius = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    snew(p, 2*natoms+UNROLLJ+SIMD_WIDTH);
-    aadata->workparam = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    snew(p, 2*natoms+UNROLLJ+SIMD_WIDTH);
-    aadata->work = (real *) (((size_t) p + 16) & (~((size_t) 15)));
-
-    for (i = 0; i < mdatoms->nr; i++)
-    {
-        aadata->gb_radius[i] = top->atomtypes.gb_radius[mdatoms->typeA[i]] - radius_offset;
-        if (gb_algorithm == egbSTILL)
-        {
-            aadata->workparam[i] = born->vsolv[i];
-        }
-        else if (gb_algorithm == egbOBC)
-        {
-            aadata->workparam[i] = born->param[i];
-        }
-        aadata->work[i]      = 0.0;
-    }
-    for (i = 0; i < mdatoms->nr; i++)
-    {
-        aadata->gb_radius[natoms+i] = aadata->gb_radius[i];
-        aadata->workparam[natoms+i] = aadata->workparam[i];
-        aadata->work[natoms+i]      = aadata->work[i];
-    }
-
-    for (i = 0; i < 2*natoms+SIMD_WIDTH; i++)
-    {
-        aadata->x_align[i]  = 0.0;
-        aadata->y_align[i]  = 0.0;
-        aadata->z_align[i]  = 0.0;
-        aadata->fx_align[i] = 0.0;
-        aadata->fy_align[i] = 0.0;
-        aadata->fz_align[i] = 0.0;
-    }
-
-    setup_gb_exclusions_and_indices(aadata, top->idef.il, 0, mdatoms->homenr, mdatoms->nr,
-                                    bInclude12, bInclude13, bInclude14);
-}
-
-
-int
-genborn_allvsall_calc_still_radii_sse2_single(t_forcerec *           fr,
-                                              t_mdatoms *            mdatoms,
-                                              gmx_genborn_t *        born,
-                                              gmx_localtop_t *       top,
-                                              real *                 x,
-                                              t_commrec *            cr,
-                                              void *                 paadata)
-{
-    gmx_allvsallgb2_data_t *aadata;
-    int                     natoms;
-    int                     ni0, ni1;
-    int                     nj0, nj1, nj2, nj3;
-    int                     i, j, k, n;
-    int              *      mask;
-    int              *      pmask0;
-    int              *      pmask1;
-    int              *      pmask2;
-    int              *      pmask3;
-    int              *      emask0;
-    int              *      emask1;
-    int              *      emask2;
-    int              *      emask3;
-    real                    ix, iy, iz;
-    real                    jx, jy, jz;
-    real                    dx, dy, dz;
-    real                    rsq, rinv;
-    real                    gpi, rai, vai;
-    real                    prod_ai;
-    real                    irsq, idr4, idr6;
-    real                    raj, rvdw, ratio;
-    real                    vaj, ccf, dccf, theta, cosq;
-    real                    term, prod, icf4, icf6, gpi2, factor, sinq;
-    real              *     gb_radius;
-    real              *     vsolv;
-    real              *     work;
-    real                    tmpsum[4];
-    real              *     x_align;
-    real              *     y_align;
-    real              *     z_align;
-    int              *      jindex;
-    real              *     dadx;
-
-    __m128                  ix_SSE0, iy_SSE0, iz_SSE0;
-    __m128                  ix_SSE1, iy_SSE1, iz_SSE1;
-    __m128                  ix_SSE2, iy_SSE2, iz_SSE2;
-    __m128                  ix_SSE3, iy_SSE3, iz_SSE3;
-    __m128                  gpi_SSE0, rai_SSE0, prod_ai_SSE0;
-    __m128                  gpi_SSE1, rai_SSE1, prod_ai_SSE1;
-    __m128                  gpi_SSE2, rai_SSE2, prod_ai_SSE2;
-    __m128                  gpi_SSE3, rai_SSE3, prod_ai_SSE3;
-    __m128                  imask_SSE0, jmask_SSE0;
-    __m128                  imask_SSE1, jmask_SSE1;
-    __m128                  imask_SSE2, jmask_SSE2;
-    __m128                  imask_SSE3, jmask_SSE3;
-    __m128                  jx_SSE, jy_SSE, jz_SSE;
-    __m128                  dx_SSE0, dy_SSE0, dz_SSE0;
-    __m128                  dx_SSE1, dy_SSE1, dz_SSE1;
-    __m128                  dx_SSE2, dy_SSE2, dz_SSE2;
-    __m128                  dx_SSE3, dy_SSE3, dz_SSE3;
-    __m128                  rsq_SSE0, rinv_SSE0, irsq_SSE0, idr4_SSE0, idr6_SSE0;
-    __m128                  rsq_SSE1, rinv_SSE1, irsq_SSE1, idr4_SSE1, idr6_SSE1;
-    __m128                  rsq_SSE2, rinv_SSE2, irsq_SSE2, idr4_SSE2, idr6_SSE2;
-    __m128                  rsq_SSE3, rinv_SSE3, irsq_SSE3, idr4_SSE3, idr6_SSE3;
-    __m128                  raj_SSE, vaj_SSE, prod_SSE;
-    __m128                  rvdw_SSE0, ratio_SSE0;
-    __m128                  rvdw_SSE1, ratio_SSE1;
-    __m128                  rvdw_SSE2, ratio_SSE2;
-    __m128                  rvdw_SSE3, ratio_SSE3;
-    __m128                  theta_SSE0, sinq_SSE0, cosq_SSE0, term_SSE0;
-    __m128                  theta_SSE1, sinq_SSE1, cosq_SSE1, term_SSE1;
-    __m128                  theta_SSE2, sinq_SSE2, cosq_SSE2, term_SSE2;
-    __m128                  theta_SSE3, sinq_SSE3, cosq_SSE3, term_SSE3;
-    __m128                  ccf_SSE0, dccf_SSE0;
-    __m128                  ccf_SSE1, dccf_SSE1;
-    __m128                  ccf_SSE2, dccf_SSE2;
-    __m128                  ccf_SSE3, dccf_SSE3;
-    __m128                  icf4_SSE0, icf6_SSE0;
-    __m128                  icf4_SSE1, icf6_SSE1;
-    __m128                  icf4_SSE2, icf6_SSE2;
-    __m128                  icf4_SSE3, icf6_SSE3;
-    __m128                  half_SSE, one_SSE, two_SSE, four_SSE;
-    __m128                  still_p4_SSE, still_p5inv_SSE, still_pip5_SSE;
-
-    natoms              = mdatoms->nr;
-    ni0                 = 0;
-    ni1                 = mdatoms->homenr;
-
-    n = 0;
-
-    aadata = *((gmx_allvsallgb2_data_t **)paadata);
-
-
-    if (aadata == NULL)
-    {
-        genborn_allvsall_setup(&aadata, top, born, mdatoms, 0.0,
-                               egbSTILL, FALSE, FALSE, TRUE);
-        *((gmx_allvsallgb2_data_t **)paadata) = aadata;
-    }
-
-    x_align = aadata->x_align;
-    y_align = aadata->y_align;
-    z_align = aadata->z_align;
-
-    gb_radius = aadata->gb_radius;
-    vsolv     = aadata->workparam;
-    work      = aadata->work;
-    jindex    = aadata->jindex_gb;
-    dadx      = fr->dadx;
-
-    still_p4_SSE    = _mm_set1_ps(STILL_P4);
-    still_p5inv_SSE = _mm_set1_ps(STILL_P5INV);
-    still_pip5_SSE  = _mm_set1_ps(STILL_PIP5);
-    half_SSE        = _mm_set1_ps(0.5);
-    one_SSE         = _mm_set1_ps(1.0);
-    two_SSE         = _mm_set1_ps(2.0);
-    four_SSE        = _mm_set1_ps(4.0);
-
-    /* This will be summed, so it has to extend to natoms + buffer */
-    for (i = 0; i < natoms+1+natoms/2; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = ni0; i < ni1+1+natoms/2; i++)
-    {
-        k           = i%natoms;
-        x_align[i]  = x[3*k];
-        y_align[i]  = x[3*k+1];
-        z_align[i]  = x[3*k+2];
-        work[i]     = 0;
-    }
-
-
-    for (i = ni0; i < ni1; i += UNROLLI)
-    {
-        /* We assume shifts are NOT used for all-vs-all interactions */
-
-        /* Load i atom data */
-        ix_SSE0          = _mm_load1_ps(x_align+i);
-        iy_SSE0          = _mm_load1_ps(y_align+i);
-        iz_SSE0          = _mm_load1_ps(z_align+i);
-        ix_SSE1          = _mm_load1_ps(x_align+i+1);
-        iy_SSE1          = _mm_load1_ps(y_align+i+1);
-        iz_SSE1          = _mm_load1_ps(z_align+i+1);
-        ix_SSE2          = _mm_load1_ps(x_align+i+2);
-        iy_SSE2          = _mm_load1_ps(y_align+i+2);
-        iz_SSE2          = _mm_load1_ps(z_align+i+2);
-        ix_SSE3          = _mm_load1_ps(x_align+i+3);
-        iy_SSE3          = _mm_load1_ps(y_align+i+3);
-        iz_SSE3          = _mm_load1_ps(z_align+i+3);
-
-        gpi_SSE0         = _mm_setzero_ps();
-        gpi_SSE1         = _mm_setzero_ps();
-        gpi_SSE2         = _mm_setzero_ps();
-        gpi_SSE3         = _mm_setzero_ps();
-
-        rai_SSE0         = _mm_load1_ps(gb_radius+i);
-        rai_SSE1         = _mm_load1_ps(gb_radius+i+1);
-        rai_SSE2         = _mm_load1_ps(gb_radius+i+2);
-        rai_SSE3         = _mm_load1_ps(gb_radius+i+3);
-
-        prod_ai_SSE0     = _mm_set1_ps(STILL_P4*vsolv[i]);
-        prod_ai_SSE1     = _mm_set1_ps(STILL_P4*vsolv[i+1]);
-        prod_ai_SSE2     = _mm_set1_ps(STILL_P4*vsolv[i+2]);
-        prod_ai_SSE3     = _mm_set1_ps(STILL_P4*vsolv[i+3]);
-
-        /* Load limits for loop over neighbors */
-        nj0              = jindex[4*i];
-        nj1              = jindex[4*i+1];
-        nj2              = jindex[4*i+2];
-        nj3              = jindex[4*i+3];
-
-        pmask0           = aadata->prologue_mask_gb[i];
-        pmask1           = aadata->prologue_mask_gb[i+1];
-        pmask2           = aadata->prologue_mask_gb[i+2];
-        pmask3           = aadata->prologue_mask_gb[i+3];
-        emask0           = aadata->epilogue_mask[i];
-        emask1           = aadata->epilogue_mask[i+1];
-        emask2           = aadata->epilogue_mask[i+2];
-        emask3           = aadata->epilogue_mask[i+3];
-
-        imask_SSE0        = _mm_load1_ps((real *)(aadata->imask+i));
-        imask_SSE1        = _mm_load1_ps((real *)(aadata->imask+i+1));
-        imask_SSE2        = _mm_load1_ps((real *)(aadata->imask+i+2));
-        imask_SSE3        = _mm_load1_ps((real *)(aadata->imask+i+3));
-
-        /* Prologue part, including exclusion mask */
-        for (j = nj0; j < nj1; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_ps((real *)pmask0);
-            jmask_SSE1 = _mm_load_ps((real *)pmask1);
-            jmask_SSE2 = _mm_load_ps((real *)pmask2);
-            jmask_SSE3 = _mm_load_ps((real *)pmask3);
-            pmask0    += UNROLLJ;
-            pmask1    += UNROLLJ;
-            pmask2    += UNROLLJ;
-            pmask3    += UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_ps(x_align+j);
-            jy_SSE            = _mm_load_ps(y_align+j);
-            jz_SSE            = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2            = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2            = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2            = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3            = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3            = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3            = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_ps(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_ps(dx_SSE1, dy_SSE1, dz_SSE1);
-            rsq_SSE2           = gmx_mm_calc_rsq_ps(dx_SSE2, dy_SSE2, dz_SSE2);
-            rsq_SSE3           = gmx_mm_calc_rsq_ps(dx_SSE3, dy_SSE3, dz_SSE3);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_ps(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_ps(jmask_SSE1, imask_SSE1);
-            jmask_SSE2         = _mm_and_ps(jmask_SSE2, imask_SSE2);
-            jmask_SSE3         = _mm_and_ps(jmask_SSE3, imask_SSE3);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_ps(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_ps(rsq_SSE1);
-            rinv_SSE2          = gmx_mm_invsqrt_ps(rsq_SSE2);
-            rinv_SSE3          = gmx_mm_invsqrt_ps(rsq_SSE3);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_ps(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_ps(rinv_SSE1, jmask_SSE1);
-            rinv_SSE2          = _mm_and_ps(rinv_SSE2, jmask_SSE2);
-            rinv_SSE3          = _mm_and_ps(rinv_SSE3, jmask_SSE3);
-
-            irsq_SSE0          = _mm_mul_ps(rinv_SSE0, rinv_SSE0);
-            irsq_SSE1          = _mm_mul_ps(rinv_SSE1, rinv_SSE1);
-            irsq_SSE2          = _mm_mul_ps(rinv_SSE2, rinv_SSE2);
-            irsq_SSE3          = _mm_mul_ps(rinv_SSE3, rinv_SSE3);
-            idr4_SSE0          = _mm_mul_ps(irsq_SSE0, irsq_SSE0);
-            idr4_SSE1          = _mm_mul_ps(irsq_SSE1, irsq_SSE1);
-            idr4_SSE2          = _mm_mul_ps(irsq_SSE2, irsq_SSE2);
-            idr4_SSE3          = _mm_mul_ps(irsq_SSE3, irsq_SSE3);
-            idr6_SSE0          = _mm_mul_ps(idr4_SSE0, irsq_SSE0);
-            idr6_SSE1          = _mm_mul_ps(idr4_SSE1, irsq_SSE1);
-            idr6_SSE2          = _mm_mul_ps(idr4_SSE2, irsq_SSE2);
-            idr6_SSE3          = _mm_mul_ps(idr4_SSE3, irsq_SSE3);
-
-            raj_SSE            = _mm_load_ps(gb_radius+j);
-            vaj_SSE            = _mm_load_ps(vsolv+j);
-
-            rvdw_SSE0          = _mm_add_ps(rai_SSE0, raj_SSE);
-            rvdw_SSE1          = _mm_add_ps(rai_SSE1, raj_SSE);
-            rvdw_SSE2          = _mm_add_ps(rai_SSE2, raj_SSE);
-            rvdw_SSE3          = _mm_add_ps(rai_SSE3, raj_SSE);
-
-            ratio_SSE0         = _mm_mul_ps(rsq_SSE0, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE0, rvdw_SSE0)));
-            ratio_SSE1         = _mm_mul_ps(rsq_SSE1, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE1, rvdw_SSE1)));
-            ratio_SSE2         = _mm_mul_ps(rsq_SSE2, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE2, rvdw_SSE2)));
-            ratio_SSE3         = _mm_mul_ps(rsq_SSE3, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE3, rvdw_SSE3)));
-
-            ratio_SSE0         = _mm_min_ps(ratio_SSE0, still_p5inv_SSE);
-            ratio_SSE1         = _mm_min_ps(ratio_SSE1, still_p5inv_SSE);
-            ratio_SSE2         = _mm_min_ps(ratio_SSE2, still_p5inv_SSE);
-            ratio_SSE3         = _mm_min_ps(ratio_SSE3, still_p5inv_SSE);
-            theta_SSE0         = _mm_mul_ps(ratio_SSE0, still_pip5_SSE);
-            theta_SSE1         = _mm_mul_ps(ratio_SSE1, still_pip5_SSE);
-            theta_SSE2         = _mm_mul_ps(ratio_SSE2, still_pip5_SSE);
-            theta_SSE3         = _mm_mul_ps(ratio_SSE3, still_pip5_SSE);
-            gmx_mm_sincos_ps(theta_SSE0, &sinq_SSE0, &cosq_SSE0);
-            gmx_mm_sincos_ps(theta_SSE1, &sinq_SSE1, &cosq_SSE1);
-            gmx_mm_sincos_ps(theta_SSE2, &sinq_SSE2, &cosq_SSE2);
-            gmx_mm_sincos_ps(theta_SSE3, &sinq_SSE3, &cosq_SSE3);
-            term_SSE0          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE0));
-            term_SSE1          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE1));
-            term_SSE2          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE2));
-            term_SSE3          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE3));
-            ccf_SSE0           = _mm_mul_ps(term_SSE0, term_SSE0);
-            ccf_SSE1           = _mm_mul_ps(term_SSE1, term_SSE1);
-            ccf_SSE2           = _mm_mul_ps(term_SSE2, term_SSE2);
-            ccf_SSE3           = _mm_mul_ps(term_SSE3, term_SSE3);
-            dccf_SSE0          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE0),
-                                            _mm_mul_ps(sinq_SSE0, theta_SSE0));
-            dccf_SSE1          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE1),
-                                            _mm_mul_ps(sinq_SSE1, theta_SSE1));
-            dccf_SSE2          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE2),
-                                            _mm_mul_ps(sinq_SSE2, theta_SSE2));
-            dccf_SSE3          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE3),
-                                            _mm_mul_ps(sinq_SSE3, theta_SSE3));
-
-            prod_SSE           = _mm_mul_ps(still_p4_SSE, vaj_SSE);
-            icf4_SSE0          = _mm_mul_ps(ccf_SSE0, idr4_SSE0);
-            icf4_SSE1          = _mm_mul_ps(ccf_SSE1, idr4_SSE1);
-            icf4_SSE2          = _mm_mul_ps(ccf_SSE2, idr4_SSE2);
-            icf4_SSE3          = _mm_mul_ps(ccf_SSE3, idr4_SSE3);
-            icf6_SSE0          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE0), dccf_SSE0), idr6_SSE0);
-            icf6_SSE1          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE1), dccf_SSE1), idr6_SSE1);
-            icf6_SSE2          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE2), dccf_SSE2), idr6_SSE2);
-            icf6_SSE3          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE3), dccf_SSE3), idr6_SSE3);
-
-            _mm_store_ps(work+j, _mm_add_ps(_mm_load_ps(work+j),
-                                            gmx_mm_sum4_ps(_mm_mul_ps(prod_ai_SSE0, icf4_SSE0),
-                                                           _mm_mul_ps(prod_ai_SSE1, icf4_SSE1),
-                                                           _mm_mul_ps(prod_ai_SSE2, icf4_SSE2),
-                                                           _mm_mul_ps(prod_ai_SSE3, icf4_SSE3))));
-
-            gpi_SSE0           = _mm_add_ps(gpi_SSE0, _mm_mul_ps(prod_SSE, icf4_SSE0));
-            gpi_SSE1           = _mm_add_ps(gpi_SSE1, _mm_mul_ps(prod_SSE, icf4_SSE1));
-            gpi_SSE2           = _mm_add_ps(gpi_SSE2, _mm_mul_ps(prod_SSE, icf4_SSE2));
-            gpi_SSE3           = _mm_add_ps(gpi_SSE3, _mm_mul_ps(prod_SSE, icf4_SSE3));
-
-            /* Save ai->aj and aj->ai chain rule terms */
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE3));
-            dadx += 4;
-
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE0, icf6_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE1, icf6_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE2, icf6_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE3, icf6_SSE3));
-            dadx += 4;
-        }
-
-        /* Main part, no exclusions */
-        for (j = nj1; j < nj2; j += UNROLLJ)
-        {
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_ps(x_align+j);
-            jy_SSE            = _mm_load_ps(y_align+j);
-            jz_SSE            = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2            = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2            = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2            = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3            = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3            = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3            = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_ps(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_ps(dx_SSE1, dy_SSE1, dz_SSE1);
-            rsq_SSE2           = gmx_mm_calc_rsq_ps(dx_SSE2, dy_SSE2, dz_SSE2);
-            rsq_SSE3           = gmx_mm_calc_rsq_ps(dx_SSE3, dy_SSE3, dz_SSE3);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_ps(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_ps(rsq_SSE1);
-            rinv_SSE2          = gmx_mm_invsqrt_ps(rsq_SSE2);
-            rinv_SSE3          = gmx_mm_invsqrt_ps(rsq_SSE3);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_ps(rinv_SSE0, imask_SSE0);
-            rinv_SSE1          = _mm_and_ps(rinv_SSE1, imask_SSE1);
-            rinv_SSE2          = _mm_and_ps(rinv_SSE2, imask_SSE2);
-            rinv_SSE3          = _mm_and_ps(rinv_SSE3, imask_SSE3);
-
-            irsq_SSE0          = _mm_mul_ps(rinv_SSE0, rinv_SSE0);
-            irsq_SSE1          = _mm_mul_ps(rinv_SSE1, rinv_SSE1);
-            irsq_SSE2          = _mm_mul_ps(rinv_SSE2, rinv_SSE2);
-            irsq_SSE3          = _mm_mul_ps(rinv_SSE3, rinv_SSE3);
-            idr4_SSE0          = _mm_mul_ps(irsq_SSE0, irsq_SSE0);
-            idr4_SSE1          = _mm_mul_ps(irsq_SSE1, irsq_SSE1);
-            idr4_SSE2          = _mm_mul_ps(irsq_SSE2, irsq_SSE2);
-            idr4_SSE3          = _mm_mul_ps(irsq_SSE3, irsq_SSE3);
-            idr6_SSE0          = _mm_mul_ps(idr4_SSE0, irsq_SSE0);
-            idr6_SSE1          = _mm_mul_ps(idr4_SSE1, irsq_SSE1);
-            idr6_SSE2          = _mm_mul_ps(idr4_SSE2, irsq_SSE2);
-            idr6_SSE3          = _mm_mul_ps(idr4_SSE3, irsq_SSE3);
-
-            raj_SSE            = _mm_load_ps(gb_radius+j);
-
-            rvdw_SSE0          = _mm_add_ps(rai_SSE0, raj_SSE);
-            rvdw_SSE1          = _mm_add_ps(rai_SSE1, raj_SSE);
-            rvdw_SSE2          = _mm_add_ps(rai_SSE2, raj_SSE);
-            rvdw_SSE3          = _mm_add_ps(rai_SSE3, raj_SSE);
-            vaj_SSE            = _mm_load_ps(vsolv+j);
-
-            ratio_SSE0         = _mm_mul_ps(rsq_SSE0, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE0, rvdw_SSE0)));
-            ratio_SSE1         = _mm_mul_ps(rsq_SSE1, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE1, rvdw_SSE1)));
-            ratio_SSE2         = _mm_mul_ps(rsq_SSE2, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE2, rvdw_SSE2)));
-            ratio_SSE3         = _mm_mul_ps(rsq_SSE3, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE3, rvdw_SSE3)));
-
-            ratio_SSE0         = _mm_min_ps(ratio_SSE0, still_p5inv_SSE);
-            ratio_SSE1         = _mm_min_ps(ratio_SSE1, still_p5inv_SSE);
-            ratio_SSE2         = _mm_min_ps(ratio_SSE2, still_p5inv_SSE);
-            ratio_SSE3         = _mm_min_ps(ratio_SSE3, still_p5inv_SSE);
-            theta_SSE0         = _mm_mul_ps(ratio_SSE0, still_pip5_SSE);
-            theta_SSE1         = _mm_mul_ps(ratio_SSE1, still_pip5_SSE);
-            theta_SSE2         = _mm_mul_ps(ratio_SSE2, still_pip5_SSE);
-            theta_SSE3         = _mm_mul_ps(ratio_SSE3, still_pip5_SSE);
-            gmx_mm_sincos_ps(theta_SSE0, &sinq_SSE0, &cosq_SSE0);
-            gmx_mm_sincos_ps(theta_SSE1, &sinq_SSE1, &cosq_SSE1);
-            gmx_mm_sincos_ps(theta_SSE2, &sinq_SSE2, &cosq_SSE2);
-            gmx_mm_sincos_ps(theta_SSE3, &sinq_SSE3, &cosq_SSE3);
-            term_SSE0          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE0));
-            term_SSE1          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE1));
-            term_SSE2          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE2));
-            term_SSE3          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE3));
-            ccf_SSE0           = _mm_mul_ps(term_SSE0, term_SSE0);
-            ccf_SSE1           = _mm_mul_ps(term_SSE1, term_SSE1);
-            ccf_SSE2           = _mm_mul_ps(term_SSE2, term_SSE2);
-            ccf_SSE3           = _mm_mul_ps(term_SSE3, term_SSE3);
-            dccf_SSE0          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE0),
-                                            _mm_mul_ps(sinq_SSE0, theta_SSE0));
-            dccf_SSE1          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE1),
-                                            _mm_mul_ps(sinq_SSE1, theta_SSE1));
-            dccf_SSE2          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE2),
-                                            _mm_mul_ps(sinq_SSE2, theta_SSE2));
-            dccf_SSE3          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE3),
-                                            _mm_mul_ps(sinq_SSE3, theta_SSE3));
-
-            prod_SSE           = _mm_mul_ps(still_p4_SSE, vaj_SSE );
-            icf4_SSE0          = _mm_mul_ps(ccf_SSE0, idr4_SSE0);
-            icf4_SSE1          = _mm_mul_ps(ccf_SSE1, idr4_SSE1);
-            icf4_SSE2          = _mm_mul_ps(ccf_SSE2, idr4_SSE2);
-            icf4_SSE3          = _mm_mul_ps(ccf_SSE3, idr4_SSE3);
-            icf6_SSE0          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE0), dccf_SSE0), idr6_SSE0);
-            icf6_SSE1          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE1), dccf_SSE1), idr6_SSE1);
-            icf6_SSE2          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE2), dccf_SSE2), idr6_SSE2);
-            icf6_SSE3          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE3), dccf_SSE3), idr6_SSE3);
-
-            _mm_store_ps(work+j, _mm_add_ps(_mm_load_ps(work+j),
-                                            gmx_mm_sum4_ps(_mm_mul_ps(prod_ai_SSE0, icf4_SSE0),
-                                                           _mm_mul_ps(prod_ai_SSE1, icf4_SSE1),
-                                                           _mm_mul_ps(prod_ai_SSE2, icf4_SSE2),
-                                                           _mm_mul_ps(prod_ai_SSE3, icf4_SSE3))));
-
-            gpi_SSE0           = _mm_add_ps(gpi_SSE0, _mm_mul_ps(prod_SSE, icf4_SSE0));
-            gpi_SSE1           = _mm_add_ps(gpi_SSE1, _mm_mul_ps(prod_SSE, icf4_SSE1));
-            gpi_SSE2           = _mm_add_ps(gpi_SSE2, _mm_mul_ps(prod_SSE, icf4_SSE2));
-            gpi_SSE3           = _mm_add_ps(gpi_SSE3, _mm_mul_ps(prod_SSE, icf4_SSE3));
-
-            /* Save ai->aj and aj->ai chain rule terms */
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE3));
-            dadx += 4;
-
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE0, icf6_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE1, icf6_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE2, icf6_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE3, icf6_SSE3));
-            dadx += 4;
-        }
-        /* Epilogue part, including exclusion mask */
-        for (j = nj2; j < nj3; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_ps((real *)emask0);
-            jmask_SSE1 = _mm_load_ps((real *)emask1);
-            jmask_SSE2 = _mm_load_ps((real *)emask2);
-            jmask_SSE3 = _mm_load_ps((real *)emask3);
-            emask0    += UNROLLJ;
-            emask1    += UNROLLJ;
-            emask2    += UNROLLJ;
-            emask3    += UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_ps(x_align+j);
-            jy_SSE            = _mm_load_ps(y_align+j);
-            jz_SSE            = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2            = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2            = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2            = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3            = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3            = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3            = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_ps(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_ps(dx_SSE1, dy_SSE1, dz_SSE1);
-            rsq_SSE2           = gmx_mm_calc_rsq_ps(dx_SSE2, dy_SSE2, dz_SSE2);
-            rsq_SSE3           = gmx_mm_calc_rsq_ps(dx_SSE3, dy_SSE3, dz_SSE3);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_ps(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_ps(jmask_SSE1, imask_SSE1);
-            jmask_SSE2         = _mm_and_ps(jmask_SSE2, imask_SSE2);
-            jmask_SSE3         = _mm_and_ps(jmask_SSE3, imask_SSE3);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_ps(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_ps(rsq_SSE1);
-            rinv_SSE2          = gmx_mm_invsqrt_ps(rsq_SSE2);
-            rinv_SSE3          = gmx_mm_invsqrt_ps(rsq_SSE3);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_ps(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_ps(rinv_SSE1, jmask_SSE1);
-            rinv_SSE2          = _mm_and_ps(rinv_SSE2, jmask_SSE2);
-            rinv_SSE3          = _mm_and_ps(rinv_SSE3, jmask_SSE3);
-
-            irsq_SSE0          = _mm_mul_ps(rinv_SSE0, rinv_SSE0);
-            irsq_SSE1          = _mm_mul_ps(rinv_SSE1, rinv_SSE1);
-            irsq_SSE2          = _mm_mul_ps(rinv_SSE2, rinv_SSE2);
-            irsq_SSE3          = _mm_mul_ps(rinv_SSE3, rinv_SSE3);
-            idr4_SSE0          = _mm_mul_ps(irsq_SSE0, irsq_SSE0);
-            idr4_SSE1          = _mm_mul_ps(irsq_SSE1, irsq_SSE1);
-            idr4_SSE2          = _mm_mul_ps(irsq_SSE2, irsq_SSE2);
-            idr4_SSE3          = _mm_mul_ps(irsq_SSE3, irsq_SSE3);
-            idr6_SSE0          = _mm_mul_ps(idr4_SSE0, irsq_SSE0);
-            idr6_SSE1          = _mm_mul_ps(idr4_SSE1, irsq_SSE1);
-            idr6_SSE2          = _mm_mul_ps(idr4_SSE2, irsq_SSE2);
-            idr6_SSE3          = _mm_mul_ps(idr4_SSE3, irsq_SSE3);
-
-            raj_SSE            = _mm_load_ps(gb_radius+j);
-            vaj_SSE            = _mm_load_ps(vsolv+j);
-
-            rvdw_SSE0          = _mm_add_ps(rai_SSE0, raj_SSE);
-            rvdw_SSE1          = _mm_add_ps(rai_SSE1, raj_SSE);
-            rvdw_SSE2          = _mm_add_ps(rai_SSE2, raj_SSE);
-            rvdw_SSE3          = _mm_add_ps(rai_SSE3, raj_SSE);
-
-            ratio_SSE0         = _mm_mul_ps(rsq_SSE0, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE0, rvdw_SSE0)));
-            ratio_SSE1         = _mm_mul_ps(rsq_SSE1, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE1, rvdw_SSE1)));
-            ratio_SSE2         = _mm_mul_ps(rsq_SSE2, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE2, rvdw_SSE2)));
-            ratio_SSE3         = _mm_mul_ps(rsq_SSE3, gmx_mm_inv_ps( _mm_mul_ps(rvdw_SSE3, rvdw_SSE3)));
-
-            ratio_SSE0         = _mm_min_ps(ratio_SSE0, still_p5inv_SSE);
-            ratio_SSE1         = _mm_min_ps(ratio_SSE1, still_p5inv_SSE);
-            ratio_SSE2         = _mm_min_ps(ratio_SSE2, still_p5inv_SSE);
-            ratio_SSE3         = _mm_min_ps(ratio_SSE3, still_p5inv_SSE);
-            theta_SSE0         = _mm_mul_ps(ratio_SSE0, still_pip5_SSE);
-            theta_SSE1         = _mm_mul_ps(ratio_SSE1, still_pip5_SSE);
-            theta_SSE2         = _mm_mul_ps(ratio_SSE2, still_pip5_SSE);
-            theta_SSE3         = _mm_mul_ps(ratio_SSE3, still_pip5_SSE);
-            gmx_mm_sincos_ps(theta_SSE0, &sinq_SSE0, &cosq_SSE0);
-            gmx_mm_sincos_ps(theta_SSE1, &sinq_SSE1, &cosq_SSE1);
-            gmx_mm_sincos_ps(theta_SSE2, &sinq_SSE2, &cosq_SSE2);
-            gmx_mm_sincos_ps(theta_SSE3, &sinq_SSE3, &cosq_SSE3);
-            term_SSE0          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE0));
-            term_SSE1          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE1));
-            term_SSE2          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE2));
-            term_SSE3          = _mm_mul_ps(half_SSE, _mm_sub_ps(one_SSE, cosq_SSE3));
-            ccf_SSE0           = _mm_mul_ps(term_SSE0, term_SSE0);
-            ccf_SSE1           = _mm_mul_ps(term_SSE1, term_SSE1);
-            ccf_SSE2           = _mm_mul_ps(term_SSE2, term_SSE2);
-            ccf_SSE3           = _mm_mul_ps(term_SSE3, term_SSE3);
-            dccf_SSE0          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE0),
-                                            _mm_mul_ps(sinq_SSE0, theta_SSE0));
-            dccf_SSE1          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE1),
-                                            _mm_mul_ps(sinq_SSE1, theta_SSE1));
-            dccf_SSE2          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE2),
-                                            _mm_mul_ps(sinq_SSE2, theta_SSE2));
-            dccf_SSE3          = _mm_mul_ps(_mm_mul_ps(two_SSE, term_SSE3),
-                                            _mm_mul_ps(sinq_SSE3, theta_SSE3));
-
-            prod_SSE           = _mm_mul_ps(still_p4_SSE, vaj_SSE);
-            icf4_SSE0          = _mm_mul_ps(ccf_SSE0, idr4_SSE0);
-            icf4_SSE1          = _mm_mul_ps(ccf_SSE1, idr4_SSE1);
-            icf4_SSE2          = _mm_mul_ps(ccf_SSE2, idr4_SSE2);
-            icf4_SSE3          = _mm_mul_ps(ccf_SSE3, idr4_SSE3);
-            icf6_SSE0          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE0), dccf_SSE0), idr6_SSE0);
-            icf6_SSE1          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE1), dccf_SSE1), idr6_SSE1);
-            icf6_SSE2          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE2), dccf_SSE2), idr6_SSE2);
-            icf6_SSE3          = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four_SSE, ccf_SSE3), dccf_SSE3), idr6_SSE3);
-
-            _mm_store_ps(work+j, _mm_add_ps(_mm_load_ps(work+j),
-                                            gmx_mm_sum4_ps(_mm_mul_ps(prod_ai_SSE0, icf4_SSE0),
-                                                           _mm_mul_ps(prod_ai_SSE1, icf4_SSE1),
-                                                           _mm_mul_ps(prod_ai_SSE2, icf4_SSE2),
-                                                           _mm_mul_ps(prod_ai_SSE3, icf4_SSE3))));
-
-            gpi_SSE0           = _mm_add_ps(gpi_SSE0, _mm_mul_ps(prod_SSE, icf4_SSE0));
-            gpi_SSE1           = _mm_add_ps(gpi_SSE1, _mm_mul_ps(prod_SSE, icf4_SSE1));
-            gpi_SSE2           = _mm_add_ps(gpi_SSE2, _mm_mul_ps(prod_SSE, icf4_SSE2));
-            gpi_SSE3           = _mm_add_ps(gpi_SSE3, _mm_mul_ps(prod_SSE, icf4_SSE3));
-
-            /* Save ai->aj and aj->ai chain rule terms */
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_SSE, icf6_SSE3));
-            dadx += 4;
-
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE0, icf6_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE1, icf6_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE2, icf6_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai_SSE3, icf6_SSE3));
-            dadx += 4;
-        }
-        _MM_TRANSPOSE4_PS(gpi_SSE0, gpi_SSE1, gpi_SSE2, gpi_SSE3);
-        gpi_SSE0 = _mm_add_ps(gpi_SSE0, gpi_SSE1);
-        gpi_SSE2 = _mm_add_ps(gpi_SSE2, gpi_SSE3);
-        gpi_SSE0 = _mm_add_ps(gpi_SSE0, gpi_SSE2);
-        _mm_store_ps(work+i, _mm_add_ps(gpi_SSE0, _mm_load_ps(work+i)));
-    }
-
-    /* In case we have written anything beyond natoms, move it back.
-     * Never mind that we leave stuff above natoms; that will not
-     * be accessed later in the routine.
-     * In principle this should be a move rather than sum, but this
-     * way we dont have to worry about even/odd offsets...
-     */
-    for (i = natoms; i < ni1+1+natoms/2; i++)
-    {
-        work[i-natoms] += work[i];
-    }
-
-    /* Parallel summations would go here if ever implemented with DD */
-
-    factor  = 0.5 * ONE_4PI_EPS0;
-    /* Calculate the radii - should we do all atoms, or just our local ones? */
-    for (i = 0; i < natoms; i++)
-    {
-        if (born->use[i] != 0)
-        {
-            gpi             = born->gpol[i]+work[i];
-            gpi2            = gpi * gpi;
-            born->bRad[i]   = factor*gmx_invsqrt(gpi2);
-            fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-        }
-    }
-
-    return 0;
-}
-
-
-
-int
-genborn_allvsall_calc_hct_obc_radii_sse2_single(t_forcerec *           fr,
-                                                t_mdatoms *            mdatoms,
-                                                gmx_genborn_t *        born,
-                                                int                    gb_algorithm,
-                                                gmx_localtop_t *       top,
-                                                real *                 x,
-                                                t_commrec *            cr,
-                                                void *                 paadata)
-{
-    gmx_allvsallgb2_data_t *aadata;
-    int                     natoms;
-    int                     ni0, ni1;
-    int                     nj0, nj1, nj2, nj3;
-    int                     i, j, k, n;
-    int              *      mask;
-    int              *      pmask0;
-    int              *      pmask1;
-    int              *      pmask2;
-    int              *      pmask3;
-    int              *      emask0;
-    int              *      emask1;
-    int              *      emask2;
-    int              *      emask3;
-    real              *     gb_radius;
-    real              *     vsolv;
-    real              *     work;
-    real                    tmpsum[4];
-    real              *     x_align;
-    real              *     y_align;
-    real              *     z_align;
-    int              *      jindex;
-    real              *     dadx;
-    real              *     obc_param;
-    real                    rad, min_rad;
-    real                    rai, rai_inv, rai_inv2, sum_ai, sum_ai2, sum_ai3, tsum, tchain;
-
-    __m128                  ix_SSE0, iy_SSE0, iz_SSE0;
-    __m128                  ix_SSE1, iy_SSE1, iz_SSE1;
-    __m128                  ix_SSE2, iy_SSE2, iz_SSE2;
-    __m128                  ix_SSE3, iy_SSE3, iz_SSE3;
-    __m128                  gpi_SSE0, rai_SSE0, prod_ai_SSE0;
-    __m128                  gpi_SSE1, rai_SSE1, prod_ai_SSE1;
-    __m128                  gpi_SSE2, rai_SSE2, prod_ai_SSE2;
-    __m128                  gpi_SSE3, rai_SSE3, prod_ai_SSE3;
-    __m128                  imask_SSE0, jmask_SSE0;
-    __m128                  imask_SSE1, jmask_SSE1;
-    __m128                  imask_SSE2, jmask_SSE2;
-    __m128                  imask_SSE3, jmask_SSE3;
-    __m128                  jx_SSE, jy_SSE, jz_SSE;
-    __m128                  dx_SSE0, dy_SSE0, dz_SSE0;
-    __m128                  dx_SSE1, dy_SSE1, dz_SSE1;
-    __m128                  dx_SSE2, dy_SSE2, dz_SSE2;
-    __m128                  dx_SSE3, dy_SSE3, dz_SSE3;
-    __m128                  rsq_SSE0, rinv_SSE0, irsq_SSE0, idr4_SSE0, idr6_SSE0;
-    __m128                  rsq_SSE1, rinv_SSE1, irsq_SSE1, idr4_SSE1, idr6_SSE1;
-    __m128                  rsq_SSE2, rinv_SSE2, irsq_SSE2, idr4_SSE2, idr6_SSE2;
-    __m128                  rsq_SSE3, rinv_SSE3, irsq_SSE3, idr4_SSE3, idr6_SSE3;
-    __m128                  raj_SSE, raj_inv_SSE, sk_aj_SSE, sk2_aj_SSE;
-    __m128                  ccf_SSE0, dccf_SSE0, prod_SSE0;
-    __m128                  ccf_SSE1, dccf_SSE1, prod_SSE1;
-    __m128                  ccf_SSE2, dccf_SSE2, prod_SSE2;
-    __m128                  ccf_SSE3, dccf_SSE3, prod_SSE3;
-    __m128                  icf4_SSE0, icf6_SSE0;
-    __m128                  icf4_SSE1, icf6_SSE1;
-    __m128                  icf4_SSE2, icf6_SSE2;
-    __m128                  icf4_SSE3, icf6_SSE3;
-    __m128                  oneeighth_SSE, onefourth_SSE, half_SSE, one_SSE, two_SSE, four_SSE;
-    __m128                  still_p4_SSE, still_p5inv_SSE, still_pip5_SSE;
-    __m128                  rai_inv_SSE0;
-    __m128                  rai_inv_SSE1;
-    __m128                  rai_inv_SSE2;
-    __m128                  rai_inv_SSE3;
-    __m128                  sk_ai_SSE0, sk2_ai_SSE0, sum_ai_SSE0;
-    __m128                  sk_ai_SSE1, sk2_ai_SSE1, sum_ai_SSE1;
-    __m128                  sk_ai_SSE2, sk2_ai_SSE2, sum_ai_SSE2;
-    __m128                  sk_ai_SSE3, sk2_ai_SSE3, sum_ai_SSE3;
-    __m128                  lij_inv_SSE0, sk2_rinv_SSE0;
-    __m128                  lij_inv_SSE1, sk2_rinv_SSE1;
-    __m128                  lij_inv_SSE2, sk2_rinv_SSE2;
-    __m128                  lij_inv_SSE3, sk2_rinv_SSE3;
-    __m128                  dr_SSE0;
-    __m128                  dr_SSE1;
-    __m128                  dr_SSE2;
-    __m128                  dr_SSE3;
-    __m128                  t1_SSE0, t2_SSE0, t3_SSE0, t4_SSE0;
-    __m128                  t1_SSE1, t2_SSE1, t3_SSE1, t4_SSE1;
-    __m128                  t1_SSE2, t2_SSE2, t3_SSE2, t4_SSE2;
-    __m128                  t1_SSE3, t2_SSE3, t3_SSE3, t4_SSE3;
-    __m128                  obc_mask1_SSE0, obc_mask2_SSE0, obc_mask3_SSE0;
-    __m128                  obc_mask1_SSE1, obc_mask2_SSE1, obc_mask3_SSE1;
-    __m128                  obc_mask1_SSE2, obc_mask2_SSE2, obc_mask3_SSE2;
-    __m128                  obc_mask1_SSE3, obc_mask2_SSE3, obc_mask3_SSE3;
-    __m128                  uij_SSE0, uij2_SSE0, uij3_SSE0;
-    __m128                  uij_SSE1, uij2_SSE1, uij3_SSE1;
-    __m128                  uij_SSE2, uij2_SSE2, uij3_SSE2;
-    __m128                  uij_SSE3, uij2_SSE3, uij3_SSE3;
-    __m128                  lij_SSE0, lij2_SSE0, lij3_SSE0;
-    __m128                  lij_SSE1, lij2_SSE1, lij3_SSE1;
-    __m128                  lij_SSE2, lij2_SSE2, lij3_SSE2;
-    __m128                  lij_SSE3, lij2_SSE3, lij3_SSE3;
-    __m128                  dlij_SSE0, diff2_SSE0, logterm_SSE0;
-    __m128                  dlij_SSE1, diff2_SSE1, logterm_SSE1;
-    __m128                  dlij_SSE2, diff2_SSE2, logterm_SSE2;
-    __m128                  dlij_SSE3, diff2_SSE3, logterm_SSE3;
-    __m128                  doffset_SSE;
-
-    natoms              = mdatoms->nr;
-    ni0                 = 0;
-    ni1                 = mdatoms->homenr;
-
-    n = 0;
-
-    aadata = *((gmx_allvsallgb2_data_t **)paadata);
-
-
-    if (aadata == NULL)
-    {
-        genborn_allvsall_setup(&aadata, top, born, mdatoms, born->gb_doffset,
-                               egbOBC, TRUE, TRUE, TRUE);
-        *((gmx_allvsallgb2_data_t **)paadata) = aadata;
-    }
-
-    x_align = aadata->x_align;
-    y_align = aadata->y_align;
-    z_align = aadata->z_align;
-
-    gb_radius = aadata->gb_radius;
-    work      = aadata->work;
-    jindex    = aadata->jindex_gb;
-    dadx      = fr->dadx;
-    obc_param = aadata->workparam;
-
-    oneeighth_SSE   = _mm_set1_ps(0.125);
-    onefourth_SSE   = _mm_set1_ps(0.25);
-    half_SSE        = _mm_set1_ps(0.5);
-    one_SSE         = _mm_set1_ps(1.0);
-    two_SSE         = _mm_set1_ps(2.0);
-    four_SSE        = _mm_set1_ps(4.0);
-    doffset_SSE     = _mm_set1_ps(born->gb_doffset);
-
-    for (i = 0; i < natoms; i++)
-    {
-        x_align[i]  = x[3*i];
-        y_align[i]  = x[3*i+1];
-        z_align[i]  = x[3*i+2];
-    }
-
-    /* Copy again */
-    for (i = 0; i < natoms/2+1; i++)
-    {
-        x_align[natoms+i]  = x_align[i];
-        y_align[natoms+i]  = y_align[i];
-        z_align[natoms+i]  = z_align[i];
-    }
-
-    for (i = 0; i < natoms+natoms/2+1; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = ni0; i < ni1; i += UNROLLI)
-    {
-        /* We assume shifts are NOT used for all-vs-all interactions */
-
-        /* Load i atom data */
-        ix_SSE0          = _mm_load1_ps(x_align+i);
-        iy_SSE0          = _mm_load1_ps(y_align+i);
-        iz_SSE0          = _mm_load1_ps(z_align+i);
-        ix_SSE1          = _mm_load1_ps(x_align+i+1);
-        iy_SSE1          = _mm_load1_ps(y_align+i+1);
-        iz_SSE1          = _mm_load1_ps(z_align+i+1);
-        ix_SSE2          = _mm_load1_ps(x_align+i+2);
-        iy_SSE2          = _mm_load1_ps(y_align+i+2);
-        iz_SSE2          = _mm_load1_ps(z_align+i+2);
-        ix_SSE3          = _mm_load1_ps(x_align+i+3);
-        iy_SSE3          = _mm_load1_ps(y_align+i+3);
-        iz_SSE3          = _mm_load1_ps(z_align+i+3);
-
-        rai_SSE0         = _mm_load1_ps(gb_radius+i);
-        rai_SSE1         = _mm_load1_ps(gb_radius+i+1);
-        rai_SSE2         = _mm_load1_ps(gb_radius+i+2);
-        rai_SSE3         = _mm_load1_ps(gb_radius+i+3);
-        rai_inv_SSE0     = gmx_mm_inv_ps(rai_SSE0);
-        rai_inv_SSE1     = gmx_mm_inv_ps(rai_SSE1);
-        rai_inv_SSE2     = gmx_mm_inv_ps(rai_SSE2);
-        rai_inv_SSE3     = gmx_mm_inv_ps(rai_SSE3);
-
-        sk_ai_SSE0       = _mm_load1_ps(obc_param+i);
-        sk_ai_SSE1       = _mm_load1_ps(obc_param+i+1);
-        sk_ai_SSE2       = _mm_load1_ps(obc_param+i+2);
-        sk_ai_SSE3       = _mm_load1_ps(obc_param+i+3);
-        sk2_ai_SSE0      = _mm_mul_ps(sk_ai_SSE0, sk_ai_SSE0);
-        sk2_ai_SSE1      = _mm_mul_ps(sk_ai_SSE1, sk_ai_SSE1);
-        sk2_ai_SSE2      = _mm_mul_ps(sk_ai_SSE2, sk_ai_SSE2);
-        sk2_ai_SSE3      = _mm_mul_ps(sk_ai_SSE3, sk_ai_SSE3);
-
-        sum_ai_SSE0      = _mm_setzero_ps();
-        sum_ai_SSE1      = _mm_setzero_ps();
-        sum_ai_SSE2      = _mm_setzero_ps();
-        sum_ai_SSE3      = _mm_setzero_ps();
-
-        /* Load limits for loop over neighbors */
-        nj0              = jindex[4*i];
-        nj1              = jindex[4*i+1];
-        nj2              = jindex[4*i+2];
-        nj3              = jindex[4*i+3];
-
-        pmask0           = aadata->prologue_mask_gb[i];
-        pmask1           = aadata->prologue_mask_gb[i+1];
-        pmask2           = aadata->prologue_mask_gb[i+2];
-        pmask3           = aadata->prologue_mask_gb[i+3];
-        emask0           = aadata->epilogue_mask[i];
-        emask1           = aadata->epilogue_mask[i+1];
-        emask2           = aadata->epilogue_mask[i+2];
-        emask3           = aadata->epilogue_mask[i+3];
-
-        imask_SSE0        = _mm_load1_ps((real *)(aadata->imask+i));
-        imask_SSE1        = _mm_load1_ps((real *)(aadata->imask+i+1));
-        imask_SSE2        = _mm_load1_ps((real *)(aadata->imask+i+2));
-        imask_SSE3        = _mm_load1_ps((real *)(aadata->imask+i+3));
-
-        /* Prologue part, including exclusion mask */
-        for (j = nj0; j < nj1; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_ps((real *)pmask0);
-            jmask_SSE1 = _mm_load_ps((real *)pmask1);
-            jmask_SSE2 = _mm_load_ps((real *)pmask2);
-            jmask_SSE3 = _mm_load_ps((real *)pmask3);
-            pmask0    += UNROLLJ;
-            pmask1    += UNROLLJ;
-            pmask2    += UNROLLJ;
-            pmask3    += UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_ps(x_align+j);
-            jy_SSE            = _mm_load_ps(y_align+j);
-            jz_SSE            = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2            = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2            = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2            = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3            = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3            = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3            = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_ps(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_ps(dx_SSE1, dy_SSE1, dz_SSE1);
-            rsq_SSE2           = gmx_mm_calc_rsq_ps(dx_SSE2, dy_SSE2, dz_SSE2);
-            rsq_SSE3           = gmx_mm_calc_rsq_ps(dx_SSE3, dy_SSE3, dz_SSE3);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_ps(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_ps(jmask_SSE1, imask_SSE1);
-            jmask_SSE2         = _mm_and_ps(jmask_SSE2, imask_SSE2);
-            jmask_SSE3         = _mm_and_ps(jmask_SSE3, imask_SSE3);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_ps(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_ps(rsq_SSE1);
-            rinv_SSE2          = gmx_mm_invsqrt_ps(rsq_SSE2);
-            rinv_SSE3          = gmx_mm_invsqrt_ps(rsq_SSE3);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_ps(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_ps(rinv_SSE1, jmask_SSE1);
-            rinv_SSE2          = _mm_and_ps(rinv_SSE2, jmask_SSE2);
-            rinv_SSE3          = _mm_and_ps(rinv_SSE3, jmask_SSE3);
-
-            dr_SSE0            = _mm_mul_ps(rsq_SSE0, rinv_SSE0);
-            dr_SSE1            = _mm_mul_ps(rsq_SSE1, rinv_SSE1);
-            dr_SSE2            = _mm_mul_ps(rsq_SSE2, rinv_SSE2);
-            dr_SSE3            = _mm_mul_ps(rsq_SSE3, rinv_SSE3);
-
-            sk_aj_SSE          = _mm_load_ps(obc_param+j);
-            raj_SSE            = _mm_load_ps(gb_radius+j);
-            raj_inv_SSE        = gmx_mm_inv_ps(raj_SSE);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1_SSE0            = _mm_add_ps(dr_SSE0, sk_aj_SSE);
-            t1_SSE1            = _mm_add_ps(dr_SSE1, sk_aj_SSE);
-            t1_SSE2            = _mm_add_ps(dr_SSE2, sk_aj_SSE);
-            t1_SSE3            = _mm_add_ps(dr_SSE3, sk_aj_SSE);
-            t2_SSE0            = _mm_sub_ps(dr_SSE0, sk_aj_SSE);
-            t2_SSE1            = _mm_sub_ps(dr_SSE1, sk_aj_SSE);
-            t2_SSE2            = _mm_sub_ps(dr_SSE2, sk_aj_SSE);
-            t2_SSE3            = _mm_sub_ps(dr_SSE3, sk_aj_SSE);
-            t3_SSE0            = _mm_sub_ps(sk_aj_SSE, dr_SSE0);
-            t3_SSE1            = _mm_sub_ps(sk_aj_SSE, dr_SSE1);
-            t3_SSE2            = _mm_sub_ps(sk_aj_SSE, dr_SSE2);
-            t3_SSE3            = _mm_sub_ps(sk_aj_SSE, dr_SSE3);
-
-            obc_mask1_SSE0     = _mm_cmplt_ps(rai_SSE0, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_ps(rai_SSE1, t1_SSE1);
-            obc_mask1_SSE2     = _mm_cmplt_ps(rai_SSE2, t1_SSE2);
-            obc_mask1_SSE3     = _mm_cmplt_ps(rai_SSE3, t1_SSE3);
-            obc_mask2_SSE0     = _mm_cmplt_ps(rai_SSE0, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_ps(rai_SSE1, t2_SSE1);
-            obc_mask2_SSE2     = _mm_cmplt_ps(rai_SSE2, t2_SSE2);
-            obc_mask2_SSE3     = _mm_cmplt_ps(rai_SSE3, t2_SSE3);
-            obc_mask3_SSE0     = _mm_cmplt_ps(rai_SSE0, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_ps(rai_SSE1, t3_SSE1);
-            obc_mask3_SSE2     = _mm_cmplt_ps(rai_SSE2, t3_SSE2);
-            obc_mask3_SSE3     = _mm_cmplt_ps(rai_SSE3, t3_SSE3);
-            obc_mask1_SSE0     = _mm_and_ps(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_ps(obc_mask1_SSE1, jmask_SSE1);
-            obc_mask1_SSE2     = _mm_and_ps(obc_mask1_SSE2, jmask_SSE2);
-            obc_mask1_SSE3     = _mm_and_ps(obc_mask1_SSE3, jmask_SSE3);
-
-            uij_SSE0           = gmx_mm_inv_ps(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_ps(t1_SSE1);
-            uij_SSE2           = gmx_mm_inv_ps(t1_SSE2);
-            uij_SSE3           = gmx_mm_inv_ps(t1_SSE3);
-            lij_SSE0           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE0, gmx_mm_inv_ps(t2_SSE0)),
-                                              _mm_andnot_ps(obc_mask2_SSE0, rai_inv_SSE0));
-            lij_SSE1           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE1, gmx_mm_inv_ps(t2_SSE1)),
-                                              _mm_andnot_ps(obc_mask2_SSE1, rai_inv_SSE1));
-            lij_SSE2           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE2, gmx_mm_inv_ps(t2_SSE2)),
-                                              _mm_andnot_ps(obc_mask2_SSE2, rai_inv_SSE2));
-            lij_SSE3           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE3, gmx_mm_inv_ps(t2_SSE3)),
-                                              _mm_andnot_ps(obc_mask2_SSE3, rai_inv_SSE3));
-            dlij_SSE0          = _mm_and_ps(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_ps(one_SSE, obc_mask2_SSE1);
-            dlij_SSE2          = _mm_and_ps(one_SSE, obc_mask2_SSE2);
-            dlij_SSE3          = _mm_and_ps(one_SSE, obc_mask2_SSE3);
-
-            uij2_SSE0          = _mm_mul_ps(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_ps(uij_SSE1, uij_SSE1);
-            uij2_SSE2          = _mm_mul_ps(uij_SSE2, uij_SSE2);
-            uij2_SSE3          = _mm_mul_ps(uij_SSE3, uij_SSE3);
-            uij3_SSE0          = _mm_mul_ps(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_ps(uij2_SSE1, uij_SSE1);
-            uij3_SSE2          = _mm_mul_ps(uij2_SSE2, uij_SSE2);
-            uij3_SSE3          = _mm_mul_ps(uij2_SSE3, uij_SSE3);
-            lij2_SSE0          = _mm_mul_ps(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_ps(lij_SSE1, lij_SSE1);
-            lij2_SSE2          = _mm_mul_ps(lij_SSE2, lij_SSE2);
-            lij2_SSE3          = _mm_mul_ps(lij_SSE3, lij_SSE3);
-            lij3_SSE0          = _mm_mul_ps(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_ps(lij2_SSE1, lij_SSE1);
-            lij3_SSE2          = _mm_mul_ps(lij2_SSE2, lij_SSE2);
-            lij3_SSE3          = _mm_mul_ps(lij2_SSE3, lij_SSE3);
-
-            diff2_SSE0         = _mm_sub_ps(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_ps(uij2_SSE1, lij2_SSE1);
-            diff2_SSE2         = _mm_sub_ps(uij2_SSE2, lij2_SSE2);
-            diff2_SSE3         = _mm_sub_ps(uij2_SSE3, lij2_SSE3);
-            lij_inv_SSE0       = gmx_mm_invsqrt_ps(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_ps(lij2_SSE1);
-            lij_inv_SSE2       = gmx_mm_invsqrt_ps(lij2_SSE2);
-            lij_inv_SSE3       = gmx_mm_invsqrt_ps(lij2_SSE3);
-            sk2_aj_SSE         = _mm_mul_ps(sk_aj_SSE, sk_aj_SSE);
-            sk2_rinv_SSE0      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE1);
-            sk2_rinv_SSE2      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE2);
-            sk2_rinv_SSE3      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE3);
-            prod_SSE0          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE1);
-            prod_SSE2          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE2);
-            prod_SSE3          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE3);
-
-            logterm_SSE0       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE1, lij_inv_SSE1));
-            logterm_SSE2       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE2, lij_inv_SSE2));
-            logterm_SSE3       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE3, lij_inv_SSE3));
-
-            t1_SSE0            = _mm_sub_ps(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_ps(lij_SSE1, uij_SSE1);
-            t1_SSE2            = _mm_sub_ps(lij_SSE2, uij_SSE2);
-            t1_SSE3            = _mm_sub_ps(lij_SSE3, uij_SSE3);
-            t2_SSE0            = _mm_mul_ps(diff2_SSE0,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_ps(diff2_SSE1,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t2_SSE2            = _mm_mul_ps(diff2_SSE2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE2),
-                                                       prod_SSE2));
-            t2_SSE3            = _mm_mul_ps(diff2_SSE3,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE3),
-                                                       prod_SSE3));
-
-            t3_SSE0            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE1, logterm_SSE1));
-            t3_SSE2            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE2, logterm_SSE2));
-            t3_SSE3            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE3, logterm_SSE3));
-            t1_SSE0            = _mm_add_ps(t1_SSE0, _mm_add_ps(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_ps(t1_SSE1, _mm_add_ps(t2_SSE1, t3_SSE1));
-            t1_SSE2            = _mm_add_ps(t1_SSE2, _mm_add_ps(t2_SSE2, t3_SSE2));
-            t1_SSE3            = _mm_add_ps(t1_SSE3, _mm_add_ps(t2_SSE3, t3_SSE3));
-            t4_SSE0            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE0, lij_SSE0));
-            t4_SSE1            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE1, lij_SSE1));
-            t4_SSE2            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE2, lij_SSE2));
-            t4_SSE3            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE3, lij_SSE3));
-            t4_SSE0            = _mm_and_ps(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_ps(t4_SSE1, obc_mask3_SSE1);
-            t4_SSE2            = _mm_and_ps(t4_SSE2, obc_mask3_SSE2);
-            t4_SSE3            = _mm_and_ps(t4_SSE3, obc_mask3_SSE3);
-            t1_SSE0            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE1, t4_SSE1));
-            t1_SSE2            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE2, t4_SSE2));
-            t1_SSE3            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE3, t4_SSE3));
-
-            sum_ai_SSE0        = _mm_add_ps(sum_ai_SSE0, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            sum_ai_SSE1        = _mm_add_ps(sum_ai_SSE1, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            sum_ai_SSE2        = _mm_add_ps(sum_ai_SSE2, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            sum_ai_SSE3        = _mm_add_ps(sum_ai_SSE3, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-
-            t1_SSE0            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE0),
-                                            _mm_mul_ps(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE1),
-                                            _mm_mul_ps(prod_SSE1, lij3_SSE1));
-            t1_SSE2            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE2),
-                                            _mm_mul_ps(prod_SSE2, lij3_SSE2));
-            t1_SSE3            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE3),
-                                            _mm_mul_ps(prod_SSE3, lij3_SSE3));
-            t1_SSE0            = _mm_sub_ps(t1_SSE0,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_ps(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_ps(t1_SSE1,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_ps(lij3_SSE1, dr_SSE1))));
-            t1_SSE2            = _mm_sub_ps(t1_SSE2,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE2, rinv_SSE2),
-                                                                  _mm_mul_ps(lij3_SSE2, dr_SSE2))));
-            t1_SSE3            = _mm_sub_ps(t1_SSE3,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE3, rinv_SSE3),
-                                                                  _mm_mul_ps(lij3_SSE3, dr_SSE3))));
-
-            t2_SSE0            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_ps(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_ps(uij3_SSE1, dr_SSE1)));
-            t2_SSE2            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE2, rinv_SSE2),
-                                                       _mm_mul_ps(uij3_SSE2, dr_SSE2)));
-            t2_SSE3            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE3, rinv_SSE3),
-                                                       _mm_mul_ps(uij3_SSE3, dr_SSE3)));
-            t2_SSE0            = _mm_sub_ps(t2_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE0),
-                                                       _mm_mul_ps(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_ps(t2_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE1),
-                                                       _mm_mul_ps(prod_SSE1, uij3_SSE1)));
-            t2_SSE2            = _mm_sub_ps(t2_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE2),
-                                                       _mm_mul_ps(prod_SSE2, uij3_SSE2)));
-            t2_SSE3            = _mm_sub_ps(t2_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE3),
-                                                       _mm_mul_ps(prod_SSE3, uij3_SSE3)));
-            t3_SSE0            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_ps(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_ps(rinv_SSE1, rinv_SSE1));
-            t3_SSE2            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE2),
-                                            _mm_mul_ps(rinv_SSE2, rinv_SSE2));
-            t3_SSE3            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE3),
-                                            _mm_mul_ps(rinv_SSE3, rinv_SSE3));
-            t3_SSE0            = _mm_sub_ps(t3_SSE0,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_ps(t3_SSE1,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE1, rinv_SSE1))));
-            t3_SSE2            = _mm_sub_ps(t3_SSE2,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE2, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE2, rinv_SSE2))));
-            t3_SSE3            = _mm_sub_ps(t3_SSE3,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE3, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE3, rinv_SSE3))));
-
-            t1_SSE0            = _mm_mul_ps(rinv_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_ps(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_ps(rinv_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_ps(t2_SSE1, t3_SSE1)));
-            t1_SSE2            = _mm_mul_ps(rinv_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE2, t1_SSE2),
-                                                       _mm_add_ps(t2_SSE2, t3_SSE2)));
-            t1_SSE3            = _mm_mul_ps(rinv_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE3, t1_SSE3),
-                                                       _mm_add_ps(t2_SSE3, t3_SSE3)));
-
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-            dadx += 4;
-
-            /* Evaluate influence of atom ai -> aj */
-            t1_SSE0            = _mm_add_ps(dr_SSE0, sk_ai_SSE0);
-            t1_SSE1            = _mm_add_ps(dr_SSE1, sk_ai_SSE1);
-            t1_SSE2            = _mm_add_ps(dr_SSE2, sk_ai_SSE2);
-            t1_SSE3            = _mm_add_ps(dr_SSE3, sk_ai_SSE3);
-            t2_SSE0            = _mm_sub_ps(dr_SSE0, sk_ai_SSE0);
-            t2_SSE1            = _mm_sub_ps(dr_SSE1, sk_ai_SSE1);
-            t2_SSE2            = _mm_sub_ps(dr_SSE2, sk_ai_SSE2);
-            t2_SSE3            = _mm_sub_ps(dr_SSE3, sk_ai_SSE3);
-            t3_SSE0            = _mm_sub_ps(sk_ai_SSE0, dr_SSE0);
-            t3_SSE1            = _mm_sub_ps(sk_ai_SSE1, dr_SSE1);
-            t3_SSE2            = _mm_sub_ps(sk_ai_SSE2, dr_SSE2);
-            t3_SSE3            = _mm_sub_ps(sk_ai_SSE3, dr_SSE3);
-
-            obc_mask1_SSE0     = _mm_cmplt_ps(raj_SSE, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_ps(raj_SSE, t1_SSE1);
-            obc_mask1_SSE2     = _mm_cmplt_ps(raj_SSE, t1_SSE2);
-            obc_mask1_SSE3     = _mm_cmplt_ps(raj_SSE, t1_SSE3);
-            obc_mask2_SSE0     = _mm_cmplt_ps(raj_SSE, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_ps(raj_SSE, t2_SSE1);
-            obc_mask2_SSE2     = _mm_cmplt_ps(raj_SSE, t2_SSE2);
-            obc_mask2_SSE3     = _mm_cmplt_ps(raj_SSE, t2_SSE3);
-            obc_mask3_SSE0     = _mm_cmplt_ps(raj_SSE, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_ps(raj_SSE, t3_SSE1);
-            obc_mask3_SSE2     = _mm_cmplt_ps(raj_SSE, t3_SSE2);
-            obc_mask3_SSE3     = _mm_cmplt_ps(raj_SSE, t3_SSE3);
-            obc_mask1_SSE0     = _mm_and_ps(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_ps(obc_mask1_SSE1, jmask_SSE1);
-            obc_mask1_SSE2     = _mm_and_ps(obc_mask1_SSE2, jmask_SSE2);
-            obc_mask1_SSE3     = _mm_and_ps(obc_mask1_SSE3, jmask_SSE3);
-
-            uij_SSE0           = gmx_mm_inv_ps(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_ps(t1_SSE1);
-            uij_SSE2           = gmx_mm_inv_ps(t1_SSE2);
-            uij_SSE3           = gmx_mm_inv_ps(t1_SSE3);
-            lij_SSE0           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE0, gmx_mm_inv_ps(t2_SSE0)),
-                                              _mm_andnot_ps(obc_mask2_SSE0, raj_inv_SSE));
-            lij_SSE1           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE1, gmx_mm_inv_ps(t2_SSE1)),
-                                              _mm_andnot_ps(obc_mask2_SSE1, raj_inv_SSE));
-            lij_SSE2           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE2, gmx_mm_inv_ps(t2_SSE2)),
-                                              _mm_andnot_ps(obc_mask2_SSE2, raj_inv_SSE));
-            lij_SSE3           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE3, gmx_mm_inv_ps(t2_SSE3)),
-                                              _mm_andnot_ps(obc_mask2_SSE3, raj_inv_SSE));
-            dlij_SSE0          = _mm_and_ps(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_ps(one_SSE, obc_mask2_SSE1);
-            dlij_SSE2          = _mm_and_ps(one_SSE, obc_mask2_SSE2);
-            dlij_SSE3          = _mm_and_ps(one_SSE, obc_mask2_SSE3);
-
-            uij2_SSE0          = _mm_mul_ps(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_ps(uij_SSE1, uij_SSE1);
-            uij2_SSE2          = _mm_mul_ps(uij_SSE2, uij_SSE2);
-            uij2_SSE3          = _mm_mul_ps(uij_SSE3, uij_SSE3);
-            uij3_SSE0          = _mm_mul_ps(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_ps(uij2_SSE1, uij_SSE1);
-            uij3_SSE2          = _mm_mul_ps(uij2_SSE2, uij_SSE2);
-            uij3_SSE3          = _mm_mul_ps(uij2_SSE3, uij_SSE3);
-            lij2_SSE0          = _mm_mul_ps(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_ps(lij_SSE1, lij_SSE1);
-            lij2_SSE2          = _mm_mul_ps(lij_SSE2, lij_SSE2);
-            lij2_SSE3          = _mm_mul_ps(lij_SSE3, lij_SSE3);
-            lij3_SSE0          = _mm_mul_ps(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_ps(lij2_SSE1, lij_SSE1);
-            lij3_SSE2          = _mm_mul_ps(lij2_SSE2, lij_SSE2);
-            lij3_SSE3          = _mm_mul_ps(lij2_SSE3, lij_SSE3);
-
-            diff2_SSE0         = _mm_sub_ps(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_ps(uij2_SSE1, lij2_SSE1);
-            diff2_SSE2         = _mm_sub_ps(uij2_SSE2, lij2_SSE2);
-            diff2_SSE3         = _mm_sub_ps(uij2_SSE3, lij2_SSE3);
-            lij_inv_SSE0       = gmx_mm_invsqrt_ps(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_ps(lij2_SSE1);
-            lij_inv_SSE2       = gmx_mm_invsqrt_ps(lij2_SSE2);
-            lij_inv_SSE3       = gmx_mm_invsqrt_ps(lij2_SSE3);
-            sk2_rinv_SSE0      = _mm_mul_ps(sk2_ai_SSE0, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_ps(sk2_ai_SSE1, rinv_SSE1);
-            sk2_rinv_SSE2      = _mm_mul_ps(sk2_ai_SSE2, rinv_SSE2);
-            sk2_rinv_SSE3      = _mm_mul_ps(sk2_ai_SSE3, rinv_SSE3);
-            prod_SSE0          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE1);
-            prod_SSE2          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE2);
-            prod_SSE3          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE3);
-
-            logterm_SSE0       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE1, lij_inv_SSE1));
-            logterm_SSE2       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE2, lij_inv_SSE2));
-            logterm_SSE3       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE3, lij_inv_SSE3));
-            t1_SSE0            = _mm_sub_ps(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_ps(lij_SSE1, uij_SSE1);
-            t1_SSE2            = _mm_sub_ps(lij_SSE2, uij_SSE2);
-            t1_SSE3            = _mm_sub_ps(lij_SSE3, uij_SSE3);
-            t2_SSE0            = _mm_mul_ps(diff2_SSE0,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_ps(diff2_SSE1,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t2_SSE2            = _mm_mul_ps(diff2_SSE2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE2),
-                                                       prod_SSE2));
-            t2_SSE3            = _mm_mul_ps(diff2_SSE3,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE3),
-                                                       prod_SSE3));
-            t3_SSE0            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE1, logterm_SSE1));
-            t3_SSE2            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE2, logterm_SSE2));
-            t3_SSE3            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE3, logterm_SSE3));
-            t1_SSE0            = _mm_add_ps(t1_SSE0, _mm_add_ps(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_ps(t1_SSE1, _mm_add_ps(t2_SSE1, t3_SSE1));
-            t1_SSE2            = _mm_add_ps(t1_SSE2, _mm_add_ps(t2_SSE2, t3_SSE2));
-            t1_SSE3            = _mm_add_ps(t1_SSE3, _mm_add_ps(t2_SSE3, t3_SSE3));
-            t4_SSE0            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE0));
-            t4_SSE1            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE1));
-            t4_SSE2            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE2));
-            t4_SSE3            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE3));
-            t4_SSE0            = _mm_and_ps(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_ps(t4_SSE1, obc_mask3_SSE1);
-            t4_SSE2            = _mm_and_ps(t4_SSE2, obc_mask3_SSE2);
-            t4_SSE3            = _mm_and_ps(t4_SSE3, obc_mask3_SSE3);
-            t1_SSE0            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE1, t4_SSE1));
-            t1_SSE2            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE2, t4_SSE2));
-            t1_SSE3            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE3, t4_SSE3));
-
-            _mm_store_ps(work+j, _mm_add_ps(_mm_load_ps(work+j),
-                                            gmx_mm_sum4_ps(_mm_and_ps(t1_SSE0, obc_mask1_SSE0),
-                                                           _mm_and_ps(t1_SSE1, obc_mask1_SSE1),
-                                                           _mm_and_ps(t1_SSE2, obc_mask1_SSE2),
-                                                           _mm_and_ps(t1_SSE3, obc_mask1_SSE3))));
-
-            t1_SSE0            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE0),
-                                            _mm_mul_ps(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE1),
-                                            _mm_mul_ps(prod_SSE1, lij3_SSE1));
-            t1_SSE2            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE2),
-                                            _mm_mul_ps(prod_SSE2, lij3_SSE2));
-            t1_SSE3            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE3),
-                                            _mm_mul_ps(prod_SSE3, lij3_SSE3));
-            t1_SSE0            = _mm_sub_ps(t1_SSE0,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_ps(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_ps(t1_SSE1,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_ps(lij3_SSE1, dr_SSE1))));
-            t1_SSE2            = _mm_sub_ps(t1_SSE2,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE2, rinv_SSE2),
-                                                                  _mm_mul_ps(lij3_SSE2, dr_SSE2))));
-            t1_SSE3            = _mm_sub_ps(t1_SSE3,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE3, rinv_SSE3),
-                                                                  _mm_mul_ps(lij3_SSE3, dr_SSE3))));
-            t2_SSE0            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_ps(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_ps(uij3_SSE1, dr_SSE1)));
-            t2_SSE2            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE2, rinv_SSE2),
-                                                       _mm_mul_ps(uij3_SSE2, dr_SSE2)));
-            t2_SSE3            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE3, rinv_SSE3),
-                                                       _mm_mul_ps(uij3_SSE3, dr_SSE3)));
-            t2_SSE0            = _mm_sub_ps(t2_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE0),
-                                                       _mm_mul_ps(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_ps(t2_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE1),
-                                                       _mm_mul_ps(prod_SSE1, uij3_SSE1)));
-            t2_SSE2            = _mm_sub_ps(t2_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE2),
-                                                       _mm_mul_ps(prod_SSE2, uij3_SSE2)));
-            t2_SSE3            = _mm_sub_ps(t2_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE3),
-                                                       _mm_mul_ps(prod_SSE3, uij3_SSE3)));
-
-            t3_SSE0            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_ps(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_ps(rinv_SSE1, rinv_SSE1));
-            t3_SSE2            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE2),
-                                            _mm_mul_ps(rinv_SSE2, rinv_SSE2));
-            t3_SSE3            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE3),
-                                            _mm_mul_ps(rinv_SSE3, rinv_SSE3));
-
-            t3_SSE0            = _mm_sub_ps(t3_SSE0,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_ps(t3_SSE1,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE1, rinv_SSE1))));
-            t3_SSE2            = _mm_sub_ps(t3_SSE2,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE2, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE2, rinv_SSE2))));
-            t3_SSE3            = _mm_sub_ps(t3_SSE3,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE3, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE3, rinv_SSE3))));
-
-
-            t1_SSE0            = _mm_mul_ps(rinv_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_ps(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_ps(rinv_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_ps(t2_SSE1, t3_SSE1)));
-            t1_SSE2            = _mm_mul_ps(rinv_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE2, t1_SSE2),
-                                                       _mm_add_ps(t2_SSE2, t3_SSE2)));
-            t1_SSE3            = _mm_mul_ps(rinv_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE3, t1_SSE3),
-                                                       _mm_add_ps(t2_SSE3, t3_SSE3)));
-
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-            dadx += 4;
-
-        }
-
-        /* Main part, no exclusions */
-        for (j = nj1; j < nj2; j += UNROLLJ)
-        {
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_ps(x_align+j);
-            jy_SSE            = _mm_load_ps(y_align+j);
-            jz_SSE            = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2            = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2            = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2            = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3            = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3            = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3            = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_ps(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_ps(dx_SSE1, dy_SSE1, dz_SSE1);
-            rsq_SSE2           = gmx_mm_calc_rsq_ps(dx_SSE2, dy_SSE2, dz_SSE2);
-            rsq_SSE3           = gmx_mm_calc_rsq_ps(dx_SSE3, dy_SSE3, dz_SSE3);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_ps(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_ps(rsq_SSE1);
-            rinv_SSE2          = gmx_mm_invsqrt_ps(rsq_SSE2);
-            rinv_SSE3          = gmx_mm_invsqrt_ps(rsq_SSE3);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_ps(rinv_SSE0, imask_SSE0);
-            rinv_SSE1          = _mm_and_ps(rinv_SSE1, imask_SSE1);
-            rinv_SSE2          = _mm_and_ps(rinv_SSE2, imask_SSE2);
-            rinv_SSE3          = _mm_and_ps(rinv_SSE3, imask_SSE3);
-
-            dr_SSE0            = _mm_mul_ps(rsq_SSE0, rinv_SSE0);
-            dr_SSE1            = _mm_mul_ps(rsq_SSE1, rinv_SSE1);
-            dr_SSE2            = _mm_mul_ps(rsq_SSE2, rinv_SSE2);
-            dr_SSE3            = _mm_mul_ps(rsq_SSE3, rinv_SSE3);
-
-            sk_aj_SSE          = _mm_load_ps(obc_param+j);
-            raj_SSE            = _mm_load_ps(gb_radius+j);
-
-            raj_inv_SSE        = gmx_mm_inv_ps(raj_SSE);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1_SSE0            = _mm_add_ps(dr_SSE0, sk_aj_SSE);
-            t1_SSE1            = _mm_add_ps(dr_SSE1, sk_aj_SSE);
-            t1_SSE2            = _mm_add_ps(dr_SSE2, sk_aj_SSE);
-            t1_SSE3            = _mm_add_ps(dr_SSE3, sk_aj_SSE);
-            t2_SSE0            = _mm_sub_ps(dr_SSE0, sk_aj_SSE);
-            t2_SSE1            = _mm_sub_ps(dr_SSE1, sk_aj_SSE);
-            t2_SSE2            = _mm_sub_ps(dr_SSE2, sk_aj_SSE);
-            t2_SSE3            = _mm_sub_ps(dr_SSE3, sk_aj_SSE);
-            t3_SSE0            = _mm_sub_ps(sk_aj_SSE, dr_SSE0);
-            t3_SSE1            = _mm_sub_ps(sk_aj_SSE, dr_SSE1);
-            t3_SSE2            = _mm_sub_ps(sk_aj_SSE, dr_SSE2);
-            t3_SSE3            = _mm_sub_ps(sk_aj_SSE, dr_SSE3);
-
-            obc_mask1_SSE0     = _mm_cmplt_ps(rai_SSE0, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_ps(rai_SSE1, t1_SSE1);
-            obc_mask1_SSE2     = _mm_cmplt_ps(rai_SSE2, t1_SSE2);
-            obc_mask1_SSE3     = _mm_cmplt_ps(rai_SSE3, t1_SSE3);
-            obc_mask2_SSE0     = _mm_cmplt_ps(rai_SSE0, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_ps(rai_SSE1, t2_SSE1);
-            obc_mask2_SSE2     = _mm_cmplt_ps(rai_SSE2, t2_SSE2);
-            obc_mask2_SSE3     = _mm_cmplt_ps(rai_SSE3, t2_SSE3);
-            obc_mask3_SSE0     = _mm_cmplt_ps(rai_SSE0, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_ps(rai_SSE1, t3_SSE1);
-            obc_mask3_SSE2     = _mm_cmplt_ps(rai_SSE2, t3_SSE2);
-            obc_mask3_SSE3     = _mm_cmplt_ps(rai_SSE3, t3_SSE3);
-            obc_mask1_SSE0     = _mm_and_ps(obc_mask1_SSE0, imask_SSE0);
-            obc_mask1_SSE1     = _mm_and_ps(obc_mask1_SSE1, imask_SSE1);
-            obc_mask1_SSE2     = _mm_and_ps(obc_mask1_SSE2, imask_SSE2);
-            obc_mask1_SSE3     = _mm_and_ps(obc_mask1_SSE3, imask_SSE3);
-
-            uij_SSE0           = gmx_mm_inv_ps(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_ps(t1_SSE1);
-            uij_SSE2           = gmx_mm_inv_ps(t1_SSE2);
-            uij_SSE3           = gmx_mm_inv_ps(t1_SSE3);
-            lij_SSE0           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE0, gmx_mm_inv_ps(t2_SSE0)),
-                                              _mm_andnot_ps(obc_mask2_SSE0, rai_inv_SSE0));
-            lij_SSE1           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE1, gmx_mm_inv_ps(t2_SSE1)),
-                                              _mm_andnot_ps(obc_mask2_SSE1, rai_inv_SSE1));
-            lij_SSE2           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE2, gmx_mm_inv_ps(t2_SSE2)),
-                                              _mm_andnot_ps(obc_mask2_SSE2, rai_inv_SSE2));
-            lij_SSE3           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE3, gmx_mm_inv_ps(t2_SSE3)),
-                                              _mm_andnot_ps(obc_mask2_SSE3, rai_inv_SSE3));
-            dlij_SSE0          = _mm_and_ps(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_ps(one_SSE, obc_mask2_SSE1);
-            dlij_SSE2          = _mm_and_ps(one_SSE, obc_mask2_SSE2);
-            dlij_SSE3          = _mm_and_ps(one_SSE, obc_mask2_SSE3);
-
-            uij2_SSE0          = _mm_mul_ps(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_ps(uij_SSE1, uij_SSE1);
-            uij2_SSE2          = _mm_mul_ps(uij_SSE2, uij_SSE2);
-            uij2_SSE3          = _mm_mul_ps(uij_SSE3, uij_SSE3);
-            uij3_SSE0          = _mm_mul_ps(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_ps(uij2_SSE1, uij_SSE1);
-            uij3_SSE2          = _mm_mul_ps(uij2_SSE2, uij_SSE2);
-            uij3_SSE3          = _mm_mul_ps(uij2_SSE3, uij_SSE3);
-            lij2_SSE0          = _mm_mul_ps(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_ps(lij_SSE1, lij_SSE1);
-            lij2_SSE2          = _mm_mul_ps(lij_SSE2, lij_SSE2);
-            lij2_SSE3          = _mm_mul_ps(lij_SSE3, lij_SSE3);
-            lij3_SSE0          = _mm_mul_ps(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_ps(lij2_SSE1, lij_SSE1);
-            lij3_SSE2          = _mm_mul_ps(lij2_SSE2, lij_SSE2);
-            lij3_SSE3          = _mm_mul_ps(lij2_SSE3, lij_SSE3);
-
-            diff2_SSE0         = _mm_sub_ps(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_ps(uij2_SSE1, lij2_SSE1);
-            diff2_SSE2         = _mm_sub_ps(uij2_SSE2, lij2_SSE2);
-            diff2_SSE3         = _mm_sub_ps(uij2_SSE3, lij2_SSE3);
-            lij_inv_SSE0       = gmx_mm_invsqrt_ps(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_ps(lij2_SSE1);
-            lij_inv_SSE2       = gmx_mm_invsqrt_ps(lij2_SSE2);
-            lij_inv_SSE3       = gmx_mm_invsqrt_ps(lij2_SSE3);
-            sk2_aj_SSE         = _mm_mul_ps(sk_aj_SSE, sk_aj_SSE);
-            sk2_rinv_SSE0      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE1);
-            sk2_rinv_SSE2      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE2);
-            sk2_rinv_SSE3      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE3);
-            prod_SSE0          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE1);
-            prod_SSE2          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE2);
-            prod_SSE3          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE3);
-
-            logterm_SSE0       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE1, lij_inv_SSE1));
-            logterm_SSE2       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE2, lij_inv_SSE2));
-            logterm_SSE3       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE3, lij_inv_SSE3));
-
-            t1_SSE0            = _mm_sub_ps(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_ps(lij_SSE1, uij_SSE1);
-            t1_SSE2            = _mm_sub_ps(lij_SSE2, uij_SSE2);
-            t1_SSE3            = _mm_sub_ps(lij_SSE3, uij_SSE3);
-            t2_SSE0            = _mm_mul_ps(diff2_SSE0,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_ps(diff2_SSE1,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t2_SSE2            = _mm_mul_ps(diff2_SSE2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE2),
-                                                       prod_SSE2));
-            t2_SSE3            = _mm_mul_ps(diff2_SSE3,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE3),
-                                                       prod_SSE3));
-
-            t3_SSE0            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE1, logterm_SSE1));
-            t3_SSE2            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE2, logterm_SSE2));
-            t3_SSE3            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE3, logterm_SSE3));
-            t1_SSE0            = _mm_add_ps(t1_SSE0, _mm_add_ps(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_ps(t1_SSE1, _mm_add_ps(t2_SSE1, t3_SSE1));
-            t1_SSE2            = _mm_add_ps(t1_SSE2, _mm_add_ps(t2_SSE2, t3_SSE2));
-            t1_SSE3            = _mm_add_ps(t1_SSE3, _mm_add_ps(t2_SSE3, t3_SSE3));
-            t4_SSE0            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE0, lij_SSE0));
-            t4_SSE1            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE1, lij_SSE1));
-            t4_SSE2            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE2, lij_SSE2));
-            t4_SSE3            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE3, lij_SSE3));
-            t4_SSE0            = _mm_and_ps(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_ps(t4_SSE1, obc_mask3_SSE1);
-            t4_SSE2            = _mm_and_ps(t4_SSE2, obc_mask3_SSE2);
-            t4_SSE3            = _mm_and_ps(t4_SSE3, obc_mask3_SSE3);
-            t1_SSE0            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE1, t4_SSE1));
-            t1_SSE2            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE2, t4_SSE2));
-            t1_SSE3            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE3, t4_SSE3));
-
-            sum_ai_SSE0        = _mm_add_ps(sum_ai_SSE0, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            sum_ai_SSE1        = _mm_add_ps(sum_ai_SSE1, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            sum_ai_SSE2        = _mm_add_ps(sum_ai_SSE2, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            sum_ai_SSE3        = _mm_add_ps(sum_ai_SSE3, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-
-            t1_SSE0            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE0),
-                                            _mm_mul_ps(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE1),
-                                            _mm_mul_ps(prod_SSE1, lij3_SSE1));
-            t1_SSE2            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE2),
-                                            _mm_mul_ps(prod_SSE2, lij3_SSE2));
-            t1_SSE3            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE3),
-                                            _mm_mul_ps(prod_SSE3, lij3_SSE3));
-            t1_SSE0            = _mm_sub_ps(t1_SSE0,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_ps(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_ps(t1_SSE1,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_ps(lij3_SSE1, dr_SSE1))));
-            t1_SSE2            = _mm_sub_ps(t1_SSE2,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE2, rinv_SSE2),
-                                                                  _mm_mul_ps(lij3_SSE2, dr_SSE2))));
-            t1_SSE3            = _mm_sub_ps(t1_SSE3,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE3, rinv_SSE3),
-                                                                  _mm_mul_ps(lij3_SSE3, dr_SSE3))));
-
-            t2_SSE0            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_ps(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_ps(uij3_SSE1, dr_SSE1)));
-            t2_SSE2            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE2, rinv_SSE2),
-                                                       _mm_mul_ps(uij3_SSE2, dr_SSE2)));
-            t2_SSE3            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE3, rinv_SSE3),
-                                                       _mm_mul_ps(uij3_SSE3, dr_SSE3)));
-            t2_SSE0            = _mm_sub_ps(t2_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE0),
-                                                       _mm_mul_ps(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_ps(t2_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE1),
-                                                       _mm_mul_ps(prod_SSE1, uij3_SSE1)));
-            t2_SSE2            = _mm_sub_ps(t2_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE2),
-                                                       _mm_mul_ps(prod_SSE2, uij3_SSE2)));
-            t2_SSE3            = _mm_sub_ps(t2_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE3),
-                                                       _mm_mul_ps(prod_SSE3, uij3_SSE3)));
-            t3_SSE0            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_ps(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_ps(rinv_SSE1, rinv_SSE1));
-            t3_SSE2            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE2),
-                                            _mm_mul_ps(rinv_SSE2, rinv_SSE2));
-            t3_SSE3            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE3),
-                                            _mm_mul_ps(rinv_SSE3, rinv_SSE3));
-            t3_SSE0            = _mm_sub_ps(t3_SSE0,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_ps(t3_SSE1,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE1, rinv_SSE1))));
-            t3_SSE2            = _mm_sub_ps(t3_SSE2,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE2, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE2, rinv_SSE2))));
-            t3_SSE3            = _mm_sub_ps(t3_SSE3,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE3, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE3, rinv_SSE3))));
-
-            t1_SSE0            = _mm_mul_ps(rinv_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_ps(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_ps(rinv_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_ps(t2_SSE1, t3_SSE1)));
-            t1_SSE2            = _mm_mul_ps(rinv_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE2, t1_SSE2),
-                                                       _mm_add_ps(t2_SSE2, t3_SSE2)));
-            t1_SSE3            = _mm_mul_ps(rinv_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE3, t1_SSE3),
-                                                       _mm_add_ps(t2_SSE3, t3_SSE3)));
-
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-            dadx += 4;
-
-            /* Evaluate influence of atom ai -> aj */
-            t1_SSE0            = _mm_add_ps(dr_SSE0, sk_ai_SSE0);
-            t1_SSE1            = _mm_add_ps(dr_SSE1, sk_ai_SSE1);
-            t1_SSE2            = _mm_add_ps(dr_SSE2, sk_ai_SSE2);
-            t1_SSE3            = _mm_add_ps(dr_SSE3, sk_ai_SSE3);
-            t2_SSE0            = _mm_sub_ps(dr_SSE0, sk_ai_SSE0);
-            t2_SSE1            = _mm_sub_ps(dr_SSE1, sk_ai_SSE1);
-            t2_SSE2            = _mm_sub_ps(dr_SSE2, sk_ai_SSE2);
-            t2_SSE3            = _mm_sub_ps(dr_SSE3, sk_ai_SSE3);
-            t3_SSE0            = _mm_sub_ps(sk_ai_SSE0, dr_SSE0);
-            t3_SSE1            = _mm_sub_ps(sk_ai_SSE1, dr_SSE1);
-            t3_SSE2            = _mm_sub_ps(sk_ai_SSE2, dr_SSE2);
-            t3_SSE3            = _mm_sub_ps(sk_ai_SSE3, dr_SSE3);
-
-            obc_mask1_SSE0     = _mm_cmplt_ps(raj_SSE, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_ps(raj_SSE, t1_SSE1);
-            obc_mask1_SSE2     = _mm_cmplt_ps(raj_SSE, t1_SSE2);
-            obc_mask1_SSE3     = _mm_cmplt_ps(raj_SSE, t1_SSE3);
-            obc_mask2_SSE0     = _mm_cmplt_ps(raj_SSE, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_ps(raj_SSE, t2_SSE1);
-            obc_mask2_SSE2     = _mm_cmplt_ps(raj_SSE, t2_SSE2);
-            obc_mask2_SSE3     = _mm_cmplt_ps(raj_SSE, t2_SSE3);
-            obc_mask3_SSE0     = _mm_cmplt_ps(raj_SSE, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_ps(raj_SSE, t3_SSE1);
-            obc_mask3_SSE2     = _mm_cmplt_ps(raj_SSE, t3_SSE2);
-            obc_mask3_SSE3     = _mm_cmplt_ps(raj_SSE, t3_SSE3);
-            obc_mask1_SSE0     = _mm_and_ps(obc_mask1_SSE0, imask_SSE0);
-            obc_mask1_SSE1     = _mm_and_ps(obc_mask1_SSE1, imask_SSE1);
-            obc_mask1_SSE2     = _mm_and_ps(obc_mask1_SSE2, imask_SSE2);
-            obc_mask1_SSE3     = _mm_and_ps(obc_mask1_SSE3, imask_SSE3);
-
-            uij_SSE0           = gmx_mm_inv_ps(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_ps(t1_SSE1);
-            uij_SSE2           = gmx_mm_inv_ps(t1_SSE2);
-            uij_SSE3           = gmx_mm_inv_ps(t1_SSE3);
-            lij_SSE0           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE0, gmx_mm_inv_ps(t2_SSE0)),
-                                              _mm_andnot_ps(obc_mask2_SSE0, raj_inv_SSE));
-            lij_SSE1           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE1, gmx_mm_inv_ps(t2_SSE1)),
-                                              _mm_andnot_ps(obc_mask2_SSE1, raj_inv_SSE));
-            lij_SSE2           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE2, gmx_mm_inv_ps(t2_SSE2)),
-                                              _mm_andnot_ps(obc_mask2_SSE2, raj_inv_SSE));
-            lij_SSE3           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE3, gmx_mm_inv_ps(t2_SSE3)),
-                                              _mm_andnot_ps(obc_mask2_SSE3, raj_inv_SSE));
-            dlij_SSE0          = _mm_and_ps(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_ps(one_SSE, obc_mask2_SSE1);
-            dlij_SSE2          = _mm_and_ps(one_SSE, obc_mask2_SSE2);
-            dlij_SSE3          = _mm_and_ps(one_SSE, obc_mask2_SSE3);
-
-            uij2_SSE0          = _mm_mul_ps(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_ps(uij_SSE1, uij_SSE1);
-            uij2_SSE2          = _mm_mul_ps(uij_SSE2, uij_SSE2);
-            uij2_SSE3          = _mm_mul_ps(uij_SSE3, uij_SSE3);
-            uij3_SSE0          = _mm_mul_ps(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_ps(uij2_SSE1, uij_SSE1);
-            uij3_SSE2          = _mm_mul_ps(uij2_SSE2, uij_SSE2);
-            uij3_SSE3          = _mm_mul_ps(uij2_SSE3, uij_SSE3);
-            lij2_SSE0          = _mm_mul_ps(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_ps(lij_SSE1, lij_SSE1);
-            lij2_SSE2          = _mm_mul_ps(lij_SSE2, lij_SSE2);
-            lij2_SSE3          = _mm_mul_ps(lij_SSE3, lij_SSE3);
-            lij3_SSE0          = _mm_mul_ps(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_ps(lij2_SSE1, lij_SSE1);
-            lij3_SSE2          = _mm_mul_ps(lij2_SSE2, lij_SSE2);
-            lij3_SSE3          = _mm_mul_ps(lij2_SSE3, lij_SSE3);
-
-            diff2_SSE0         = _mm_sub_ps(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_ps(uij2_SSE1, lij2_SSE1);
-            diff2_SSE2         = _mm_sub_ps(uij2_SSE2, lij2_SSE2);
-            diff2_SSE3         = _mm_sub_ps(uij2_SSE3, lij2_SSE3);
-            lij_inv_SSE0       = gmx_mm_invsqrt_ps(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_ps(lij2_SSE1);
-            lij_inv_SSE2       = gmx_mm_invsqrt_ps(lij2_SSE2);
-            lij_inv_SSE3       = gmx_mm_invsqrt_ps(lij2_SSE3);
-            sk2_rinv_SSE0      = _mm_mul_ps(sk2_ai_SSE0, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_ps(sk2_ai_SSE1, rinv_SSE1);
-            sk2_rinv_SSE2      = _mm_mul_ps(sk2_ai_SSE2, rinv_SSE2);
-            sk2_rinv_SSE3      = _mm_mul_ps(sk2_ai_SSE3, rinv_SSE3);
-            prod_SSE0          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE1);
-            prod_SSE2          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE2);
-            prod_SSE3          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE3);
-
-            logterm_SSE0       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE1, lij_inv_SSE1));
-            logterm_SSE2       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE2, lij_inv_SSE2));
-            logterm_SSE3       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE3, lij_inv_SSE3));
-            t1_SSE0            = _mm_sub_ps(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_ps(lij_SSE1, uij_SSE1);
-            t1_SSE2            = _mm_sub_ps(lij_SSE2, uij_SSE2);
-            t1_SSE3            = _mm_sub_ps(lij_SSE3, uij_SSE3);
-            t2_SSE0            = _mm_mul_ps(diff2_SSE0,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_ps(diff2_SSE1,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t2_SSE2            = _mm_mul_ps(diff2_SSE2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE2),
-                                                       prod_SSE2));
-            t2_SSE3            = _mm_mul_ps(diff2_SSE3,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE3),
-                                                       prod_SSE3));
-            t3_SSE0            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE1, logterm_SSE1));
-            t3_SSE2            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE2, logterm_SSE2));
-            t3_SSE3            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE3, logterm_SSE3));
-            t1_SSE0            = _mm_add_ps(t1_SSE0, _mm_add_ps(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_ps(t1_SSE1, _mm_add_ps(t2_SSE1, t3_SSE1));
-            t1_SSE2            = _mm_add_ps(t1_SSE2, _mm_add_ps(t2_SSE2, t3_SSE2));
-            t1_SSE3            = _mm_add_ps(t1_SSE3, _mm_add_ps(t2_SSE3, t3_SSE3));
-            t4_SSE0            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE0));
-            t4_SSE1            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE1));
-            t4_SSE2            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE2));
-            t4_SSE3            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE3));
-            t4_SSE0            = _mm_and_ps(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_ps(t4_SSE1, obc_mask3_SSE1);
-            t4_SSE2            = _mm_and_ps(t4_SSE2, obc_mask3_SSE2);
-            t4_SSE3            = _mm_and_ps(t4_SSE3, obc_mask3_SSE3);
-            t1_SSE0            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE1, t4_SSE1));
-            t1_SSE2            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE2, t4_SSE2));
-            t1_SSE3            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE3, t4_SSE3));
-
-            _mm_store_ps(work+j, _mm_add_ps(_mm_load_ps(work+j),
-                                            gmx_mm_sum4_ps(_mm_and_ps(t1_SSE0, obc_mask1_SSE0),
-                                                           _mm_and_ps(t1_SSE1, obc_mask1_SSE1),
-                                                           _mm_and_ps(t1_SSE2, obc_mask1_SSE2),
-                                                           _mm_and_ps(t1_SSE3, obc_mask1_SSE3))));
-
-            t1_SSE0            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE0),
-                                            _mm_mul_ps(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE1),
-                                            _mm_mul_ps(prod_SSE1, lij3_SSE1));
-            t1_SSE2            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE2),
-                                            _mm_mul_ps(prod_SSE2, lij3_SSE2));
-            t1_SSE3            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE3),
-                                            _mm_mul_ps(prod_SSE3, lij3_SSE3));
-            t1_SSE0            = _mm_sub_ps(t1_SSE0,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_ps(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_ps(t1_SSE1,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_ps(lij3_SSE1, dr_SSE1))));
-            t1_SSE2            = _mm_sub_ps(t1_SSE2,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE2, rinv_SSE2),
-                                                                  _mm_mul_ps(lij3_SSE2, dr_SSE2))));
-            t1_SSE3            = _mm_sub_ps(t1_SSE3,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE3, rinv_SSE3),
-                                                                  _mm_mul_ps(lij3_SSE3, dr_SSE3))));
-            t2_SSE0            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_ps(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_ps(uij3_SSE1, dr_SSE1)));
-            t2_SSE2            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE2, rinv_SSE2),
-                                                       _mm_mul_ps(uij3_SSE2, dr_SSE2)));
-            t2_SSE3            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE3, rinv_SSE3),
-                                                       _mm_mul_ps(uij3_SSE3, dr_SSE3)));
-            t2_SSE0            = _mm_sub_ps(t2_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE0),
-                                                       _mm_mul_ps(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_ps(t2_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE1),
-                                                       _mm_mul_ps(prod_SSE1, uij3_SSE1)));
-            t2_SSE2            = _mm_sub_ps(t2_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE2),
-                                                       _mm_mul_ps(prod_SSE2, uij3_SSE2)));
-            t2_SSE3            = _mm_sub_ps(t2_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE3),
-                                                       _mm_mul_ps(prod_SSE3, uij3_SSE3)));
-
-            t3_SSE0            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_ps(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_ps(rinv_SSE1, rinv_SSE1));
-            t3_SSE2            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE2),
-                                            _mm_mul_ps(rinv_SSE2, rinv_SSE2));
-            t3_SSE3            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE3),
-                                            _mm_mul_ps(rinv_SSE3, rinv_SSE3));
-
-            t3_SSE0            = _mm_sub_ps(t3_SSE0,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_ps(t3_SSE1,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE1, rinv_SSE1))));
-            t3_SSE2            = _mm_sub_ps(t3_SSE2,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE2, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE2, rinv_SSE2))));
-            t3_SSE3            = _mm_sub_ps(t3_SSE3,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE3, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE3, rinv_SSE3))));
-
-            t1_SSE0            = _mm_mul_ps(rinv_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_ps(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_ps(rinv_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_ps(t2_SSE1, t3_SSE1)));
-            t1_SSE2            = _mm_mul_ps(rinv_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE2, t1_SSE2),
-                                                       _mm_add_ps(t2_SSE2, t3_SSE2)));
-            t1_SSE3            = _mm_mul_ps(rinv_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE3, t1_SSE3),
-                                                       _mm_add_ps(t2_SSE3, t3_SSE3)));
-
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-            dadx += 4;
-        }
-
-        /* Epilogue part, including exclusion mask */
-        for (j = nj2; j < nj3; j += UNROLLJ)
-        {
-            jmask_SSE0 = _mm_load_ps((real *)emask0);
-            jmask_SSE1 = _mm_load_ps((real *)emask1);
-            jmask_SSE2 = _mm_load_ps((real *)emask2);
-            jmask_SSE3 = _mm_load_ps((real *)emask3);
-            emask0    += UNROLLJ;
-            emask1    += UNROLLJ;
-            emask2    += UNROLLJ;
-            emask3    += UNROLLJ;
-
-            /* load j atom coordinates */
-            jx_SSE            = _mm_load_ps(x_align+j);
-            jy_SSE            = _mm_load_ps(y_align+j);
-            jz_SSE            = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0            = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0            = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0            = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1            = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1            = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1            = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2            = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2            = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2            = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3            = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3            = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3            = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            /* rsq = dx*dx+dy*dy+dz*dz */
-            rsq_SSE0           = gmx_mm_calc_rsq_ps(dx_SSE0, dy_SSE0, dz_SSE0);
-            rsq_SSE1           = gmx_mm_calc_rsq_ps(dx_SSE1, dy_SSE1, dz_SSE1);
-            rsq_SSE2           = gmx_mm_calc_rsq_ps(dx_SSE2, dy_SSE2, dz_SSE2);
-            rsq_SSE3           = gmx_mm_calc_rsq_ps(dx_SSE3, dy_SSE3, dz_SSE3);
-
-            /* Combine masks */
-            jmask_SSE0         = _mm_and_ps(jmask_SSE0, imask_SSE0);
-            jmask_SSE1         = _mm_and_ps(jmask_SSE1, imask_SSE1);
-            jmask_SSE2         = _mm_and_ps(jmask_SSE2, imask_SSE2);
-            jmask_SSE3         = _mm_and_ps(jmask_SSE3, imask_SSE3);
-
-            /* Calculate 1/r and 1/r2 */
-            rinv_SSE0          = gmx_mm_invsqrt_ps(rsq_SSE0);
-            rinv_SSE1          = gmx_mm_invsqrt_ps(rsq_SSE1);
-            rinv_SSE2          = gmx_mm_invsqrt_ps(rsq_SSE2);
-            rinv_SSE3          = gmx_mm_invsqrt_ps(rsq_SSE3);
-
-            /* Apply mask */
-            rinv_SSE0          = _mm_and_ps(rinv_SSE0, jmask_SSE0);
-            rinv_SSE1          = _mm_and_ps(rinv_SSE1, jmask_SSE1);
-            rinv_SSE2          = _mm_and_ps(rinv_SSE2, jmask_SSE2);
-            rinv_SSE3          = _mm_and_ps(rinv_SSE3, jmask_SSE3);
-
-            dr_SSE0            = _mm_mul_ps(rsq_SSE0, rinv_SSE0);
-            dr_SSE1            = _mm_mul_ps(rsq_SSE1, rinv_SSE1);
-            dr_SSE2            = _mm_mul_ps(rsq_SSE2, rinv_SSE2);
-            dr_SSE3            = _mm_mul_ps(rsq_SSE3, rinv_SSE3);
-
-            sk_aj_SSE          = _mm_load_ps(obc_param+j);
-            raj_SSE            = _mm_load_ps(gb_radius+j);
-
-            raj_inv_SSE        = gmx_mm_inv_ps(raj_SSE);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1_SSE0            = _mm_add_ps(dr_SSE0, sk_aj_SSE);
-            t1_SSE1            = _mm_add_ps(dr_SSE1, sk_aj_SSE);
-            t1_SSE2            = _mm_add_ps(dr_SSE2, sk_aj_SSE);
-            t1_SSE3            = _mm_add_ps(dr_SSE3, sk_aj_SSE);
-            t2_SSE0            = _mm_sub_ps(dr_SSE0, sk_aj_SSE);
-            t2_SSE1            = _mm_sub_ps(dr_SSE1, sk_aj_SSE);
-            t2_SSE2            = _mm_sub_ps(dr_SSE2, sk_aj_SSE);
-            t2_SSE3            = _mm_sub_ps(dr_SSE3, sk_aj_SSE);
-            t3_SSE0            = _mm_sub_ps(sk_aj_SSE, dr_SSE0);
-            t3_SSE1            = _mm_sub_ps(sk_aj_SSE, dr_SSE1);
-            t3_SSE2            = _mm_sub_ps(sk_aj_SSE, dr_SSE2);
-            t3_SSE3            = _mm_sub_ps(sk_aj_SSE, dr_SSE3);
-
-            obc_mask1_SSE0     = _mm_cmplt_ps(rai_SSE0, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_ps(rai_SSE1, t1_SSE1);
-            obc_mask1_SSE2     = _mm_cmplt_ps(rai_SSE2, t1_SSE2);
-            obc_mask1_SSE3     = _mm_cmplt_ps(rai_SSE3, t1_SSE3);
-            obc_mask2_SSE0     = _mm_cmplt_ps(rai_SSE0, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_ps(rai_SSE1, t2_SSE1);
-            obc_mask2_SSE2     = _mm_cmplt_ps(rai_SSE2, t2_SSE2);
-            obc_mask2_SSE3     = _mm_cmplt_ps(rai_SSE3, t2_SSE3);
-            obc_mask3_SSE0     = _mm_cmplt_ps(rai_SSE0, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_ps(rai_SSE1, t3_SSE1);
-            obc_mask3_SSE2     = _mm_cmplt_ps(rai_SSE2, t3_SSE2);
-            obc_mask3_SSE3     = _mm_cmplt_ps(rai_SSE3, t3_SSE3);
-            obc_mask1_SSE0     = _mm_and_ps(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_ps(obc_mask1_SSE1, jmask_SSE1);
-            obc_mask1_SSE2     = _mm_and_ps(obc_mask1_SSE2, jmask_SSE2);
-            obc_mask1_SSE3     = _mm_and_ps(obc_mask1_SSE3, jmask_SSE3);
-
-            uij_SSE0           = gmx_mm_inv_ps(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_ps(t1_SSE1);
-            uij_SSE2           = gmx_mm_inv_ps(t1_SSE2);
-            uij_SSE3           = gmx_mm_inv_ps(t1_SSE3);
-            lij_SSE0           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE0, gmx_mm_inv_ps(t2_SSE0)),
-                                              _mm_andnot_ps(obc_mask2_SSE0, rai_inv_SSE0));
-            lij_SSE1           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE1, gmx_mm_inv_ps(t2_SSE1)),
-                                              _mm_andnot_ps(obc_mask2_SSE1, rai_inv_SSE1));
-            lij_SSE2           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE2, gmx_mm_inv_ps(t2_SSE2)),
-                                              _mm_andnot_ps(obc_mask2_SSE2, rai_inv_SSE2));
-            lij_SSE3           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE3, gmx_mm_inv_ps(t2_SSE3)),
-                                              _mm_andnot_ps(obc_mask2_SSE3, rai_inv_SSE3));
-            dlij_SSE0          = _mm_and_ps(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_ps(one_SSE, obc_mask2_SSE1);
-            dlij_SSE2          = _mm_and_ps(one_SSE, obc_mask2_SSE2);
-            dlij_SSE3          = _mm_and_ps(one_SSE, obc_mask2_SSE3);
-
-            uij2_SSE0          = _mm_mul_ps(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_ps(uij_SSE1, uij_SSE1);
-            uij2_SSE2          = _mm_mul_ps(uij_SSE2, uij_SSE2);
-            uij2_SSE3          = _mm_mul_ps(uij_SSE3, uij_SSE3);
-            uij3_SSE0          = _mm_mul_ps(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_ps(uij2_SSE1, uij_SSE1);
-            uij3_SSE2          = _mm_mul_ps(uij2_SSE2, uij_SSE2);
-            uij3_SSE3          = _mm_mul_ps(uij2_SSE3, uij_SSE3);
-            lij2_SSE0          = _mm_mul_ps(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_ps(lij_SSE1, lij_SSE1);
-            lij2_SSE2          = _mm_mul_ps(lij_SSE2, lij_SSE2);
-            lij2_SSE3          = _mm_mul_ps(lij_SSE3, lij_SSE3);
-            lij3_SSE0          = _mm_mul_ps(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_ps(lij2_SSE1, lij_SSE1);
-            lij3_SSE2          = _mm_mul_ps(lij2_SSE2, lij_SSE2);
-            lij3_SSE3          = _mm_mul_ps(lij2_SSE3, lij_SSE3);
-
-            diff2_SSE0         = _mm_sub_ps(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_ps(uij2_SSE1, lij2_SSE1);
-            diff2_SSE2         = _mm_sub_ps(uij2_SSE2, lij2_SSE2);
-            diff2_SSE3         = _mm_sub_ps(uij2_SSE3, lij2_SSE3);
-            lij_inv_SSE0       = gmx_mm_invsqrt_ps(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_ps(lij2_SSE1);
-            lij_inv_SSE2       = gmx_mm_invsqrt_ps(lij2_SSE2);
-            lij_inv_SSE3       = gmx_mm_invsqrt_ps(lij2_SSE3);
-            sk2_aj_SSE         = _mm_mul_ps(sk_aj_SSE, sk_aj_SSE);
-            sk2_rinv_SSE0      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE1);
-            sk2_rinv_SSE2      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE2);
-            sk2_rinv_SSE3      = _mm_mul_ps(sk2_aj_SSE, rinv_SSE3);
-            prod_SSE0          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE1);
-            prod_SSE2          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE2);
-            prod_SSE3          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE3);
-
-            logterm_SSE0       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE1, lij_inv_SSE1));
-            logterm_SSE2       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE2, lij_inv_SSE2));
-            logterm_SSE3       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE3, lij_inv_SSE3));
-
-            t1_SSE0            = _mm_sub_ps(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_ps(lij_SSE1, uij_SSE1);
-            t1_SSE2            = _mm_sub_ps(lij_SSE2, uij_SSE2);
-            t1_SSE3            = _mm_sub_ps(lij_SSE3, uij_SSE3);
-            t2_SSE0            = _mm_mul_ps(diff2_SSE0,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_ps(diff2_SSE1,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t2_SSE2            = _mm_mul_ps(diff2_SSE2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE2),
-                                                       prod_SSE2));
-            t2_SSE3            = _mm_mul_ps(diff2_SSE3,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE3),
-                                                       prod_SSE3));
-
-            t3_SSE0            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE1, logterm_SSE1));
-            t3_SSE2            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE2, logterm_SSE2));
-            t3_SSE3            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE3, logterm_SSE3));
-            t1_SSE0            = _mm_add_ps(t1_SSE0, _mm_add_ps(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_ps(t1_SSE1, _mm_add_ps(t2_SSE1, t3_SSE1));
-            t1_SSE2            = _mm_add_ps(t1_SSE2, _mm_add_ps(t2_SSE2, t3_SSE2));
-            t1_SSE3            = _mm_add_ps(t1_SSE3, _mm_add_ps(t2_SSE3, t3_SSE3));
-            t4_SSE0            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE0, lij_SSE0));
-            t4_SSE1            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE1, lij_SSE1));
-            t4_SSE2            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE2, lij_SSE2));
-            t4_SSE3            = _mm_mul_ps(two_SSE, _mm_sub_ps(rai_inv_SSE3, lij_SSE3));
-            t4_SSE0            = _mm_and_ps(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_ps(t4_SSE1, obc_mask3_SSE1);
-            t4_SSE2            = _mm_and_ps(t4_SSE2, obc_mask3_SSE2);
-            t4_SSE3            = _mm_and_ps(t4_SSE3, obc_mask3_SSE3);
-            t1_SSE0            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE1, t4_SSE1));
-            t1_SSE2            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE2, t4_SSE2));
-            t1_SSE3            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE3, t4_SSE3));
-
-            sum_ai_SSE0        = _mm_add_ps(sum_ai_SSE0, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            sum_ai_SSE1        = _mm_add_ps(sum_ai_SSE1, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            sum_ai_SSE2        = _mm_add_ps(sum_ai_SSE2, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            sum_ai_SSE3        = _mm_add_ps(sum_ai_SSE3, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-
-            t1_SSE0            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE0),
-                                            _mm_mul_ps(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE1),
-                                            _mm_mul_ps(prod_SSE1, lij3_SSE1));
-            t1_SSE2            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE2),
-                                            _mm_mul_ps(prod_SSE2, lij3_SSE2));
-            t1_SSE3            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE3),
-                                            _mm_mul_ps(prod_SSE3, lij3_SSE3));
-            t1_SSE0            = _mm_sub_ps(t1_SSE0,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_ps(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_ps(t1_SSE1,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_ps(lij3_SSE1, dr_SSE1))));
-            t1_SSE2            = _mm_sub_ps(t1_SSE2,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE2, rinv_SSE2),
-                                                                  _mm_mul_ps(lij3_SSE2, dr_SSE2))));
-            t1_SSE3            = _mm_sub_ps(t1_SSE3,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE3, rinv_SSE3),
-                                                                  _mm_mul_ps(lij3_SSE3, dr_SSE3))));
-
-            t2_SSE0            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_ps(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_ps(uij3_SSE1, dr_SSE1)));
-            t2_SSE2            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE2, rinv_SSE2),
-                                                       _mm_mul_ps(uij3_SSE2, dr_SSE2)));
-            t2_SSE3            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE3, rinv_SSE3),
-                                                       _mm_mul_ps(uij3_SSE3, dr_SSE3)));
-            t2_SSE0            = _mm_sub_ps(t2_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE0),
-                                                       _mm_mul_ps(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_ps(t2_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE1),
-                                                       _mm_mul_ps(prod_SSE1, uij3_SSE1)));
-            t2_SSE2            = _mm_sub_ps(t2_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE2),
-                                                       _mm_mul_ps(prod_SSE2, uij3_SSE2)));
-            t2_SSE3            = _mm_sub_ps(t2_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE3),
-                                                       _mm_mul_ps(prod_SSE3, uij3_SSE3)));
-            t3_SSE0            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_ps(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_ps(rinv_SSE1, rinv_SSE1));
-            t3_SSE2            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE2),
-                                            _mm_mul_ps(rinv_SSE2, rinv_SSE2));
-            t3_SSE3            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE3),
-                                            _mm_mul_ps(rinv_SSE3, rinv_SSE3));
-            t3_SSE0            = _mm_sub_ps(t3_SSE0,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_ps(t3_SSE1,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE1, rinv_SSE1))));
-            t3_SSE2            = _mm_sub_ps(t3_SSE2,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE2, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE2, rinv_SSE2))));
-            t3_SSE3            = _mm_sub_ps(t3_SSE3,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE3, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE3, rinv_SSE3))));
-
-            t1_SSE0            = _mm_mul_ps(rinv_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_ps(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_ps(rinv_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_ps(t2_SSE1, t3_SSE1)));
-            t1_SSE2            = _mm_mul_ps(rinv_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE2, t1_SSE2),
-                                                       _mm_add_ps(t2_SSE2, t3_SSE2)));
-            t1_SSE3            = _mm_mul_ps(rinv_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE3, t1_SSE3),
-                                                       _mm_add_ps(t2_SSE3, t3_SSE3)));
-
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-            dadx += 4;
-
-            /* Evaluate influence of atom ai -> aj */
-            t1_SSE0            = _mm_add_ps(dr_SSE0, sk_ai_SSE0);
-            t1_SSE1            = _mm_add_ps(dr_SSE1, sk_ai_SSE1);
-            t1_SSE2            = _mm_add_ps(dr_SSE2, sk_ai_SSE2);
-            t1_SSE3            = _mm_add_ps(dr_SSE3, sk_ai_SSE3);
-            t2_SSE0            = _mm_sub_ps(dr_SSE0, sk_ai_SSE0);
-            t2_SSE1            = _mm_sub_ps(dr_SSE1, sk_ai_SSE1);
-            t2_SSE2            = _mm_sub_ps(dr_SSE2, sk_ai_SSE2);
-            t2_SSE3            = _mm_sub_ps(dr_SSE3, sk_ai_SSE3);
-            t3_SSE0            = _mm_sub_ps(sk_ai_SSE0, dr_SSE0);
-            t3_SSE1            = _mm_sub_ps(sk_ai_SSE1, dr_SSE1);
-            t3_SSE2            = _mm_sub_ps(sk_ai_SSE2, dr_SSE2);
-            t3_SSE3            = _mm_sub_ps(sk_ai_SSE3, dr_SSE3);
-
-            obc_mask1_SSE0     = _mm_cmplt_ps(raj_SSE, t1_SSE0);
-            obc_mask1_SSE1     = _mm_cmplt_ps(raj_SSE, t1_SSE1);
-            obc_mask1_SSE2     = _mm_cmplt_ps(raj_SSE, t1_SSE2);
-            obc_mask1_SSE3     = _mm_cmplt_ps(raj_SSE, t1_SSE3);
-            obc_mask2_SSE0     = _mm_cmplt_ps(raj_SSE, t2_SSE0);
-            obc_mask2_SSE1     = _mm_cmplt_ps(raj_SSE, t2_SSE1);
-            obc_mask2_SSE2     = _mm_cmplt_ps(raj_SSE, t2_SSE2);
-            obc_mask2_SSE3     = _mm_cmplt_ps(raj_SSE, t2_SSE3);
-            obc_mask3_SSE0     = _mm_cmplt_ps(raj_SSE, t3_SSE0);
-            obc_mask3_SSE1     = _mm_cmplt_ps(raj_SSE, t3_SSE1);
-            obc_mask3_SSE2     = _mm_cmplt_ps(raj_SSE, t3_SSE2);
-            obc_mask3_SSE3     = _mm_cmplt_ps(raj_SSE, t3_SSE3);
-            obc_mask1_SSE0     = _mm_and_ps(obc_mask1_SSE0, jmask_SSE0);
-            obc_mask1_SSE1     = _mm_and_ps(obc_mask1_SSE1, jmask_SSE1);
-            obc_mask1_SSE2     = _mm_and_ps(obc_mask1_SSE2, jmask_SSE2);
-            obc_mask1_SSE3     = _mm_and_ps(obc_mask1_SSE3, jmask_SSE3);
-
-            uij_SSE0           = gmx_mm_inv_ps(t1_SSE0);
-            uij_SSE1           = gmx_mm_inv_ps(t1_SSE1);
-            uij_SSE2           = gmx_mm_inv_ps(t1_SSE2);
-            uij_SSE3           = gmx_mm_inv_ps(t1_SSE3);
-            lij_SSE0           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE0, gmx_mm_inv_ps(t2_SSE0)),
-                                              _mm_andnot_ps(obc_mask2_SSE0, raj_inv_SSE));
-            lij_SSE1           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE1, gmx_mm_inv_ps(t2_SSE1)),
-                                              _mm_andnot_ps(obc_mask2_SSE1, raj_inv_SSE));
-            lij_SSE2           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE2, gmx_mm_inv_ps(t2_SSE2)),
-                                              _mm_andnot_ps(obc_mask2_SSE2, raj_inv_SSE));
-            lij_SSE3           = _mm_or_ps(   _mm_and_ps(obc_mask2_SSE3, gmx_mm_inv_ps(t2_SSE3)),
-                                              _mm_andnot_ps(obc_mask2_SSE3, raj_inv_SSE));
-            dlij_SSE0          = _mm_and_ps(one_SSE, obc_mask2_SSE0);
-            dlij_SSE1          = _mm_and_ps(one_SSE, obc_mask2_SSE1);
-            dlij_SSE2          = _mm_and_ps(one_SSE, obc_mask2_SSE2);
-            dlij_SSE3          = _mm_and_ps(one_SSE, obc_mask2_SSE3);
-
-            uij2_SSE0          = _mm_mul_ps(uij_SSE0, uij_SSE0);
-            uij2_SSE1          = _mm_mul_ps(uij_SSE1, uij_SSE1);
-            uij2_SSE2          = _mm_mul_ps(uij_SSE2, uij_SSE2);
-            uij2_SSE3          = _mm_mul_ps(uij_SSE3, uij_SSE3);
-            uij3_SSE0          = _mm_mul_ps(uij2_SSE0, uij_SSE0);
-            uij3_SSE1          = _mm_mul_ps(uij2_SSE1, uij_SSE1);
-            uij3_SSE2          = _mm_mul_ps(uij2_SSE2, uij_SSE2);
-            uij3_SSE3          = _mm_mul_ps(uij2_SSE3, uij_SSE3);
-            lij2_SSE0          = _mm_mul_ps(lij_SSE0, lij_SSE0);
-            lij2_SSE1          = _mm_mul_ps(lij_SSE1, lij_SSE1);
-            lij2_SSE2          = _mm_mul_ps(lij_SSE2, lij_SSE2);
-            lij2_SSE3          = _mm_mul_ps(lij_SSE3, lij_SSE3);
-            lij3_SSE0          = _mm_mul_ps(lij2_SSE0, lij_SSE0);
-            lij3_SSE1          = _mm_mul_ps(lij2_SSE1, lij_SSE1);
-            lij3_SSE2          = _mm_mul_ps(lij2_SSE2, lij_SSE2);
-            lij3_SSE3          = _mm_mul_ps(lij2_SSE3, lij_SSE3);
-
-            diff2_SSE0         = _mm_sub_ps(uij2_SSE0, lij2_SSE0);
-            diff2_SSE1         = _mm_sub_ps(uij2_SSE1, lij2_SSE1);
-            diff2_SSE2         = _mm_sub_ps(uij2_SSE2, lij2_SSE2);
-            diff2_SSE3         = _mm_sub_ps(uij2_SSE3, lij2_SSE3);
-            lij_inv_SSE0       = gmx_mm_invsqrt_ps(lij2_SSE0);
-            lij_inv_SSE1       = gmx_mm_invsqrt_ps(lij2_SSE1);
-            lij_inv_SSE2       = gmx_mm_invsqrt_ps(lij2_SSE2);
-            lij_inv_SSE3       = gmx_mm_invsqrt_ps(lij2_SSE3);
-            sk2_rinv_SSE0      = _mm_mul_ps(sk2_ai_SSE0, rinv_SSE0);
-            sk2_rinv_SSE1      = _mm_mul_ps(sk2_ai_SSE1, rinv_SSE1);
-            sk2_rinv_SSE2      = _mm_mul_ps(sk2_ai_SSE2, rinv_SSE2);
-            sk2_rinv_SSE3      = _mm_mul_ps(sk2_ai_SSE3, rinv_SSE3);
-            prod_SSE0          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE0);
-            prod_SSE1          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE1);
-            prod_SSE2          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE2);
-            prod_SSE3          = _mm_mul_ps(onefourth_SSE, sk2_rinv_SSE3);
-
-            logterm_SSE0       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE0, lij_inv_SSE0));
-            logterm_SSE1       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE1, lij_inv_SSE1));
-            logterm_SSE2       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE2, lij_inv_SSE2));
-            logterm_SSE3       = gmx_mm_log_ps(_mm_mul_ps(uij_SSE3, lij_inv_SSE3));
-            t1_SSE0            = _mm_sub_ps(lij_SSE0, uij_SSE0);
-            t1_SSE1            = _mm_sub_ps(lij_SSE1, uij_SSE1);
-            t1_SSE2            = _mm_sub_ps(lij_SSE2, uij_SSE2);
-            t1_SSE3            = _mm_sub_ps(lij_SSE3, uij_SSE3);
-            t2_SSE0            = _mm_mul_ps(diff2_SSE0,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE0),
-                                                       prod_SSE0));
-            t2_SSE1            = _mm_mul_ps(diff2_SSE1,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE1),
-                                                       prod_SSE1));
-            t2_SSE2            = _mm_mul_ps(diff2_SSE2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE2),
-                                                       prod_SSE2));
-            t2_SSE3            = _mm_mul_ps(diff2_SSE3,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth_SSE, dr_SSE3),
-                                                       prod_SSE3));
-            t3_SSE0            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE0, logterm_SSE0));
-            t3_SSE1            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE1, logterm_SSE1));
-            t3_SSE2            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE2, logterm_SSE2));
-            t3_SSE3            = _mm_mul_ps(half_SSE, _mm_mul_ps(rinv_SSE3, logterm_SSE3));
-            t1_SSE0            = _mm_add_ps(t1_SSE0, _mm_add_ps(t2_SSE0, t3_SSE0));
-            t1_SSE1            = _mm_add_ps(t1_SSE1, _mm_add_ps(t2_SSE1, t3_SSE1));
-            t1_SSE2            = _mm_add_ps(t1_SSE2, _mm_add_ps(t2_SSE2, t3_SSE2));
-            t1_SSE3            = _mm_add_ps(t1_SSE3, _mm_add_ps(t2_SSE3, t3_SSE3));
-            t4_SSE0            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE0));
-            t4_SSE1            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE1));
-            t4_SSE2            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE2));
-            t4_SSE3            = _mm_mul_ps(two_SSE, _mm_sub_ps(raj_inv_SSE, lij_SSE3));
-            t4_SSE0            = _mm_and_ps(t4_SSE0, obc_mask3_SSE0);
-            t4_SSE1            = _mm_and_ps(t4_SSE1, obc_mask3_SSE1);
-            t4_SSE2            = _mm_and_ps(t4_SSE2, obc_mask3_SSE2);
-            t4_SSE3            = _mm_and_ps(t4_SSE3, obc_mask3_SSE3);
-            t1_SSE0            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE0, t4_SSE0));
-            t1_SSE1            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE1, t4_SSE1));
-            t1_SSE2            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE2, t4_SSE2));
-            t1_SSE3            = _mm_mul_ps(half_SSE, _mm_add_ps(t1_SSE3, t4_SSE3));
-
-            _mm_store_ps(work+j, _mm_add_ps(_mm_load_ps(work+j),
-                                            gmx_mm_sum4_ps(_mm_and_ps(t1_SSE0, obc_mask1_SSE0),
-                                                           _mm_and_ps(t1_SSE1, obc_mask1_SSE1),
-                                                           _mm_and_ps(t1_SSE2, obc_mask1_SSE2),
-                                                           _mm_and_ps(t1_SSE3, obc_mask1_SSE3))));
-
-            t1_SSE0            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE0),
-                                            _mm_mul_ps(prod_SSE0, lij3_SSE0));
-            t1_SSE1            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE1),
-                                            _mm_mul_ps(prod_SSE1, lij3_SSE1));
-            t1_SSE2            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE2),
-                                            _mm_mul_ps(prod_SSE2, lij3_SSE2));
-            t1_SSE3            = _mm_add_ps(_mm_mul_ps(half_SSE, lij2_SSE3),
-                                            _mm_mul_ps(prod_SSE3, lij3_SSE3));
-            t1_SSE0            = _mm_sub_ps(t1_SSE0,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE0, rinv_SSE0),
-                                                                  _mm_mul_ps(lij3_SSE0, dr_SSE0))));
-            t1_SSE1            = _mm_sub_ps(t1_SSE1,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE1, rinv_SSE1),
-                                                                  _mm_mul_ps(lij3_SSE1, dr_SSE1))));
-            t1_SSE2            = _mm_sub_ps(t1_SSE2,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE2, rinv_SSE2),
-                                                                  _mm_mul_ps(lij3_SSE2, dr_SSE2))));
-            t1_SSE3            = _mm_sub_ps(t1_SSE3,
-                                            _mm_mul_ps(onefourth_SSE,
-                                                       _mm_add_ps(_mm_mul_ps(lij_SSE3, rinv_SSE3),
-                                                                  _mm_mul_ps(lij3_SSE3, dr_SSE3))));
-            t2_SSE0            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE0, rinv_SSE0),
-                                                       _mm_mul_ps(uij3_SSE0, dr_SSE0)));
-            t2_SSE1            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE1, rinv_SSE1),
-                                                       _mm_mul_ps(uij3_SSE1, dr_SSE1)));
-            t2_SSE2            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE2, rinv_SSE2),
-                                                       _mm_mul_ps(uij3_SSE2, dr_SSE2)));
-            t2_SSE3            = _mm_mul_ps(onefourth_SSE,
-                                            _mm_add_ps(_mm_mul_ps(uij_SSE3, rinv_SSE3),
-                                                       _mm_mul_ps(uij3_SSE3, dr_SSE3)));
-            t2_SSE0            = _mm_sub_ps(t2_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE0),
-                                                       _mm_mul_ps(prod_SSE0, uij3_SSE0)));
-            t2_SSE1            = _mm_sub_ps(t2_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE1),
-                                                       _mm_mul_ps(prod_SSE1, uij3_SSE1)));
-            t2_SSE2            = _mm_sub_ps(t2_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE2),
-                                                       _mm_mul_ps(prod_SSE2, uij3_SSE2)));
-            t2_SSE3            = _mm_sub_ps(t2_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(half_SSE, uij2_SSE3),
-                                                       _mm_mul_ps(prod_SSE3, uij3_SSE3)));
-
-            t3_SSE0            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE0),
-                                            _mm_mul_ps(rinv_SSE0, rinv_SSE0));
-            t3_SSE1            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE1),
-                                            _mm_mul_ps(rinv_SSE1, rinv_SSE1));
-            t3_SSE2            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE2),
-                                            _mm_mul_ps(rinv_SSE2, rinv_SSE2));
-            t3_SSE3            = _mm_mul_ps(_mm_mul_ps(onefourth_SSE, logterm_SSE3),
-                                            _mm_mul_ps(rinv_SSE3, rinv_SSE3));
-
-            t3_SSE0            = _mm_sub_ps(t3_SSE0,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE0, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE0, rinv_SSE0))));
-            t3_SSE1            = _mm_sub_ps(t3_SSE1,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE1, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE1, rinv_SSE1))));
-            t3_SSE2            = _mm_sub_ps(t3_SSE2,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE2, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE2, rinv_SSE2))));
-            t3_SSE3            = _mm_sub_ps(t3_SSE3,
-                                            _mm_mul_ps(_mm_mul_ps(diff2_SSE3, oneeighth_SSE),
-                                                       _mm_add_ps(one_SSE,
-                                                                  _mm_mul_ps(sk2_rinv_SSE3, rinv_SSE3))));
-
-
-            t1_SSE0            = _mm_mul_ps(rinv_SSE0,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE0, t1_SSE0),
-                                                       _mm_add_ps(t2_SSE0, t3_SSE0)));
-            t1_SSE1            = _mm_mul_ps(rinv_SSE1,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE1, t1_SSE1),
-                                                       _mm_add_ps(t2_SSE1, t3_SSE1)));
-            t1_SSE2            = _mm_mul_ps(rinv_SSE2,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE2, t1_SSE2),
-                                                       _mm_add_ps(t2_SSE2, t3_SSE2)));
-            t1_SSE3            = _mm_mul_ps(rinv_SSE3,
-                                            _mm_add_ps(_mm_mul_ps(dlij_SSE3, t1_SSE3),
-                                                       _mm_add_ps(t2_SSE3, t3_SSE3)));
-
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE0, obc_mask1_SSE0));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE1, obc_mask1_SSE1));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE2, obc_mask1_SSE2));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_and_ps(t1_SSE3, obc_mask1_SSE3));
-            dadx += 4;
-        }
-        _MM_TRANSPOSE4_PS(sum_ai_SSE0, sum_ai_SSE1, sum_ai_SSE2, sum_ai_SSE3);
-        sum_ai_SSE0 = _mm_add_ps(sum_ai_SSE0, sum_ai_SSE1);
-        sum_ai_SSE2 = _mm_add_ps(sum_ai_SSE2, sum_ai_SSE3);
-        sum_ai_SSE0 = _mm_add_ps(sum_ai_SSE0, sum_ai_SSE2);
-        _mm_store_ps(work+i, _mm_add_ps(sum_ai_SSE0, _mm_load_ps(work+i)));
-    }
-
-
-    for (i = 0; i < natoms/2+1; i++)
-    {
-        work[i] += work[natoms+i];
-    }
-
-    /* Parallel summations would go here if ever implemented with DD */
-
-    if (gb_algorithm == egbHCT)
-    {
-        /* HCT */
-        for (i = 0; i < natoms; i++)
-        {
-            if (born->use[i] != 0)
-            {
-                rai     = top->atomtypes.gb_radius[mdatoms->typeA[i]]-born->gb_doffset;
-                sum_ai  = 1.0/rai - work[i];
-                min_rad = rai + born->gb_doffset;
-                rad     = 1.0/sum_ai;
-
-                born->bRad[i]   = rad > min_rad ? rad : min_rad;
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-            }
-        }
-
-    }
-    else
-    {
-        /* OBC */
-
-        /* Calculate the radii */
-        for (i = 0; i < natoms; i++)
-        {
-
-            if (born->use[i] != 0)
-            {
-                rai        = top->atomtypes.gb_radius[mdatoms->typeA[i]];
-                rai_inv2   = 1.0/rai;
-                rai        = rai-born->gb_doffset;
-                rai_inv    = 1.0/rai;
-                sum_ai     = rai * work[i];
-                sum_ai2    = sum_ai  * sum_ai;
-                sum_ai3    = sum_ai2 * sum_ai;
-
-                tsum          = tanh(born->obc_alpha*sum_ai-born->obc_beta*sum_ai2+born->obc_gamma*sum_ai3);
-                born->bRad[i] = rai_inv - tsum*rai_inv2;
-                born->bRad[i] = 1.0 / born->bRad[i];
-
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-
-                tchain         = rai * (born->obc_alpha-2*born->obc_beta*sum_ai+3*born->obc_gamma*sum_ai2);
-                born->drobc[i] = (1.0-tsum*tsum)*tchain*rai_inv2;
-            }
-        }
-    }
-
-    return 0;
-}
-
-
-
-
-
-
-
-
-int
-genborn_allvsall_calc_chainrule_sse2_single(t_forcerec *           fr,
-                                            t_mdatoms *            mdatoms,
-                                            gmx_genborn_t *        born,
-                                            real *                 x,
-                                            real *                 f,
-                                            int                    gb_algorithm,
-                                            void *                 paadata)
-{
-    gmx_allvsallgb2_data_t *aadata;
-    int                     natoms;
-    int                     ni0, ni1;
-    int                     nj0, nj1, nj2, nj3;
-    int                     i, j, k, n;
-    int                     idx;
-    int              *      mask;
-    int              *      pmask0;
-    int              *      emask0;
-    int              *      jindex;
-
-    real                    ix, iy, iz;
-    real                    fix, fiy, fiz;
-    real                    jx, jy, jz;
-    real                    dx, dy, dz;
-    real                    tx, ty, tz;
-    real                    rbai, rbaj, fgb, fgb_ai, rbi;
-    real              *     rb;
-    real              *     dadx;
-    real              *     x_align;
-    real              *     y_align;
-    real              *     z_align;
-    real              *     fx_align;
-    real              *     fy_align;
-    real              *     fz_align;
-    real                    tmpsum[4];
-
-    __m128                  jmask_SSE0, jmask_SSE1, jmask_SSE2, jmask_SSE3;
-    __m128                  ix_SSE0, iy_SSE0, iz_SSE0;
-    __m128                  ix_SSE1, iy_SSE1, iz_SSE1;
-    __m128                  ix_SSE2, iy_SSE2, iz_SSE2;
-    __m128                  ix_SSE3, iy_SSE3, iz_SSE3;
-    __m128                  fix_SSE0, fiy_SSE0, fiz_SSE0;
-    __m128                  fix_SSE1, fiy_SSE1, fiz_SSE1;
-    __m128                  fix_SSE2, fiy_SSE2, fiz_SSE2;
-    __m128                  fix_SSE3, fiy_SSE3, fiz_SSE3;
-    __m128                  rbai_SSE0, rbai_SSE1, rbai_SSE2, rbai_SSE3;
-    __m128                  imask_SSE0, imask_SSE1, imask_SSE2, imask_SSE3;
-    __m128                  jx_SSE, jy_SSE, jz_SSE, rbaj_SSE;
-    __m128                  dx_SSE0, dy_SSE0, dz_SSE0;
-    __m128                  dx_SSE1, dy_SSE1, dz_SSE1;
-    __m128                  dx_SSE2, dy_SSE2, dz_SSE2;
-    __m128                  dx_SSE3, dy_SSE3, dz_SSE3;
-    __m128                  fgb_SSE0, fgb_ai_SSE0;
-    __m128                  fgb_SSE1, fgb_ai_SSE1;
-    __m128                  fgb_SSE2, fgb_ai_SSE2;
-    __m128                  fgb_SSE3, fgb_ai_SSE3;
-    __m128                  tx_SSE0, ty_SSE0, tz_SSE0;
-    __m128                  tx_SSE1, ty_SSE1, tz_SSE1;
-    __m128                  tx_SSE2, ty_SSE2, tz_SSE2;
-    __m128                  tx_SSE3, ty_SSE3, tz_SSE3;
-    __m128                  t1, t2;
-
-    natoms              = mdatoms->nr;
-    ni0                 = 0;
-    ni1                 = mdatoms->homenr;
-    dadx                = fr->dadx;
-
-    aadata = (gmx_allvsallgb2_data_t *)paadata;
-
-    x_align  = aadata->x_align;
-    y_align  = aadata->y_align;
-    z_align  = aadata->z_align;
-    fx_align = aadata->fx_align;
-    fy_align = aadata->fy_align;
-    fz_align = aadata->fz_align;
-
-    jindex    = aadata->jindex_gb;
-    dadx      = fr->dadx;
-
-    n  = 0;
-    rb = aadata->work;
-
-    /* Loop to get the proper form for the Born radius term */
-    if (gb_algorithm == egbSTILL)
-    {
-        for (i = 0; i < natoms; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = (2 * rbi * rbi * fr->dvda[i])/ONE_4PI_EPS0;
-        }
-    }
-    else if (gb_algorithm == egbHCT)
-    {
-        for (i = 0; i < natoms; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = rbi * rbi * fr->dvda[i];
-        }
-    }
-    else if (gb_algorithm == egbOBC)
-    {
-        for (idx = 0; idx < natoms; idx++)
-        {
-            rbi     = born->bRad[idx];
-            rb[idx] = rbi * rbi * born->drobc[idx] * fr->dvda[idx];
-        }
-    }
-
-    for (i = 0; i < 2*natoms; i++)
-    {
-        fx_align[i]       = 0;
-        fy_align[i]       = 0;
-        fz_align[i]       = 0;
-    }
-
-
-    for (i = 0; i < natoms; i++)
-    {
-        rb[i+natoms] = rb[i];
-    }
-
-    for (i = ni0; i < ni1; i += UNROLLI)
-    {
-        /* We assume shifts are NOT used for all-vs-all interactions */
-
-        /* Load i atom data */
-        ix_SSE0          = _mm_load1_ps(x_align+i);
-        iy_SSE0          = _mm_load1_ps(y_align+i);
-        iz_SSE0          = _mm_load1_ps(z_align+i);
-        ix_SSE1          = _mm_load1_ps(x_align+i+1);
-        iy_SSE1          = _mm_load1_ps(y_align+i+1);
-        iz_SSE1          = _mm_load1_ps(z_align+i+1);
-        ix_SSE2          = _mm_load1_ps(x_align+i+2);
-        iy_SSE2          = _mm_load1_ps(y_align+i+2);
-        iz_SSE2          = _mm_load1_ps(z_align+i+2);
-        ix_SSE3          = _mm_load1_ps(x_align+i+3);
-        iy_SSE3          = _mm_load1_ps(y_align+i+3);
-        iz_SSE3          = _mm_load1_ps(z_align+i+3);
-
-        fix_SSE0         = _mm_setzero_ps();
-        fiy_SSE0         = _mm_setzero_ps();
-        fiz_SSE0         = _mm_setzero_ps();
-        fix_SSE1         = _mm_setzero_ps();
-        fiy_SSE1         = _mm_setzero_ps();
-        fiz_SSE1         = _mm_setzero_ps();
-        fix_SSE2         = _mm_setzero_ps();
-        fiy_SSE2         = _mm_setzero_ps();
-        fiz_SSE2         = _mm_setzero_ps();
-        fix_SSE3         = _mm_setzero_ps();
-        fiy_SSE3         = _mm_setzero_ps();
-        fiz_SSE3         = _mm_setzero_ps();
-
-        rbai_SSE0        = _mm_load1_ps(rb+i);
-        rbai_SSE1        = _mm_load1_ps(rb+i+1);
-        rbai_SSE2        = _mm_load1_ps(rb+i+2);
-        rbai_SSE3        = _mm_load1_ps(rb+i+3);
-
-        /* Load limits for loop over neighbors */
-        nj0              = jindex[4*i];
-        nj3              = jindex[4*i+3];
-
-        /* No masks necessary, since the stored chain rule derivatives will be zero in those cases! */
-        for (j = nj0; j < nj3; j += UNROLLJ)
-        {
-            /* load j atom coordinates */
-            jx_SSE           = _mm_load_ps(x_align+j);
-            jy_SSE           = _mm_load_ps(y_align+j);
-            jz_SSE           = _mm_load_ps(z_align+j);
-
-            /* Calculate distance */
-            dx_SSE0          = _mm_sub_ps(ix_SSE0, jx_SSE);
-            dy_SSE0          = _mm_sub_ps(iy_SSE0, jy_SSE);
-            dz_SSE0          = _mm_sub_ps(iz_SSE0, jz_SSE);
-            dx_SSE1          = _mm_sub_ps(ix_SSE1, jx_SSE);
-            dy_SSE1          = _mm_sub_ps(iy_SSE1, jy_SSE);
-            dz_SSE1          = _mm_sub_ps(iz_SSE1, jz_SSE);
-            dx_SSE2          = _mm_sub_ps(ix_SSE2, jx_SSE);
-            dy_SSE2          = _mm_sub_ps(iy_SSE2, jy_SSE);
-            dz_SSE2          = _mm_sub_ps(iz_SSE2, jz_SSE);
-            dx_SSE3          = _mm_sub_ps(ix_SSE3, jx_SSE);
-            dy_SSE3          = _mm_sub_ps(iy_SSE3, jy_SSE);
-            dz_SSE3          = _mm_sub_ps(iz_SSE3, jz_SSE);
-
-            rbaj_SSE         = _mm_load_ps(rb+j);
-
-            fgb_SSE0         = _mm_mul_ps(rbai_SSE0, _mm_load_ps(dadx));
-            dadx            += 4;
-            fgb_SSE1         = _mm_mul_ps(rbai_SSE1, _mm_load_ps(dadx));
-            dadx            += 4;
-            fgb_SSE2         = _mm_mul_ps(rbai_SSE2, _mm_load_ps(dadx));
-            dadx            += 4;
-            fgb_SSE3         = _mm_mul_ps(rbai_SSE3, _mm_load_ps(dadx));
-            dadx            += 4;
-
-            fgb_ai_SSE0      = _mm_mul_ps(rbaj_SSE, _mm_load_ps(dadx));
-            dadx            += 4;
-            fgb_ai_SSE1      = _mm_mul_ps(rbaj_SSE, _mm_load_ps(dadx));
-            dadx            += 4;
-            fgb_ai_SSE2      = _mm_mul_ps(rbaj_SSE, _mm_load_ps(dadx));
-            dadx            += 4;
-            fgb_ai_SSE3      = _mm_mul_ps(rbaj_SSE, _mm_load_ps(dadx));
-            dadx            += 4;
-
-            /* Total force between ai and aj is the sum of ai->aj and aj->ai */
-            fgb_SSE0         = _mm_add_ps(fgb_SSE0, fgb_ai_SSE0);
-            fgb_SSE1         = _mm_add_ps(fgb_SSE1, fgb_ai_SSE1);
-            fgb_SSE2         = _mm_add_ps(fgb_SSE2, fgb_ai_SSE2);
-            fgb_SSE3         = _mm_add_ps(fgb_SSE3, fgb_ai_SSE3);
-
-            /* Calculate temporary vectorial force */
-            tx_SSE0            = _mm_mul_ps(fgb_SSE0, dx_SSE0);
-            ty_SSE0            = _mm_mul_ps(fgb_SSE0, dy_SSE0);
-            tz_SSE0            = _mm_mul_ps(fgb_SSE0, dz_SSE0);
-            tx_SSE1            = _mm_mul_ps(fgb_SSE1, dx_SSE1);
-            ty_SSE1            = _mm_mul_ps(fgb_SSE1, dy_SSE1);
-            tz_SSE1            = _mm_mul_ps(fgb_SSE1, dz_SSE1);
-            tx_SSE2            = _mm_mul_ps(fgb_SSE2, dx_SSE2);
-            ty_SSE2            = _mm_mul_ps(fgb_SSE2, dy_SSE2);
-            tz_SSE2            = _mm_mul_ps(fgb_SSE2, dz_SSE2);
-            tx_SSE3            = _mm_mul_ps(fgb_SSE3, dx_SSE3);
-            ty_SSE3            = _mm_mul_ps(fgb_SSE3, dy_SSE3);
-            tz_SSE3            = _mm_mul_ps(fgb_SSE3, dz_SSE3);
-
-            /* Increment i atom force */
-            fix_SSE0          = _mm_add_ps(fix_SSE0, tx_SSE0);
-            fiy_SSE0          = _mm_add_ps(fiy_SSE0, ty_SSE0);
-            fiz_SSE0          = _mm_add_ps(fiz_SSE0, tz_SSE0);
-            fix_SSE1          = _mm_add_ps(fix_SSE1, tx_SSE1);
-            fiy_SSE1          = _mm_add_ps(fiy_SSE1, ty_SSE1);
-            fiz_SSE1          = _mm_add_ps(fiz_SSE1, tz_SSE1);
-            fix_SSE2          = _mm_add_ps(fix_SSE2, tx_SSE2);
-            fiy_SSE2          = _mm_add_ps(fiy_SSE2, ty_SSE2);
-            fiz_SSE2          = _mm_add_ps(fiz_SSE2, tz_SSE2);
-            fix_SSE3          = _mm_add_ps(fix_SSE3, tx_SSE3);
-            fiy_SSE3          = _mm_add_ps(fiy_SSE3, ty_SSE3);
-            fiz_SSE3          = _mm_add_ps(fiz_SSE3, tz_SSE3);
-
-            /* Decrement j atom force */
-            _mm_store_ps(fx_align+j,
-                         _mm_sub_ps( _mm_load_ps(fx_align+j), gmx_mm_sum4_ps(tx_SSE0, tx_SSE1, tx_SSE2, tx_SSE3) ));
-            _mm_store_ps(fy_align+j,
-                         _mm_sub_ps( _mm_load_ps(fy_align+j), gmx_mm_sum4_ps(ty_SSE0, ty_SSE1, ty_SSE2, ty_SSE3) ));
-            _mm_store_ps(fz_align+j,
-                         _mm_sub_ps( _mm_load_ps(fz_align+j), gmx_mm_sum4_ps(tz_SSE0, tz_SSE1, tz_SSE2, tz_SSE3) ));
-        }
-        /* Add i forces to mem and shifted force list */
-        _MM_TRANSPOSE4_PS(fix_SSE0, fix_SSE1, fix_SSE2, fix_SSE3);
-        fix_SSE0 = _mm_add_ps(fix_SSE0, fix_SSE1);
-        fix_SSE2 = _mm_add_ps(fix_SSE2, fix_SSE3);
-        fix_SSE0 = _mm_add_ps(fix_SSE0, fix_SSE2);
-        _mm_store_ps(fx_align+i, _mm_add_ps(fix_SSE0, _mm_load_ps(fx_align+i)));
-
-        _MM_TRANSPOSE4_PS(fiy_SSE0, fiy_SSE1, fiy_SSE2, fiy_SSE3);
-        fiy_SSE0 = _mm_add_ps(fiy_SSE0, fiy_SSE1);
-        fiy_SSE2 = _mm_add_ps(fiy_SSE2, fiy_SSE3);
-        fiy_SSE0 = _mm_add_ps(fiy_SSE0, fiy_SSE2);
-        _mm_store_ps(fy_align+i, _mm_add_ps(fiy_SSE0, _mm_load_ps(fy_align+i)));
-
-        _MM_TRANSPOSE4_PS(fiz_SSE0, fiz_SSE1, fiz_SSE2, fiz_SSE3);
-        fiz_SSE0 = _mm_add_ps(fiz_SSE0, fiz_SSE1);
-        fiz_SSE2 = _mm_add_ps(fiz_SSE2, fiz_SSE3);
-        fiz_SSE0 = _mm_add_ps(fiz_SSE0, fiz_SSE2);
-        _mm_store_ps(fz_align+i, _mm_add_ps(fiz_SSE0, _mm_load_ps(fz_align+i)));
-    }
-
-    for (i = 0; i < natoms; i++)
-    {
-        f[3*i]       += fx_align[i] + fx_align[natoms+i];
-        f[3*i+1]     += fy_align[i] + fy_align[natoms+i];
-        f[3*i+2]     += fz_align[i] + fz_align[natoms+i];
-    }
-
-    return 0;
-}
-
-#else
-/* dummy variable when not using SSE */
-int genborn_allvsall_sse2_single_dummy;
-
-
-#endif
diff --git a/src/gromacs/mdlib/genborn_allvsall_sse2_single.h b/src/gromacs/mdlib/genborn_allvsall_sse2_single.h
deleted file mode 100644 (file)
index d1e908a..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS Development Team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#ifndef _GENBORN_ALLVSALL_SSE2_SINGLE_H
-#define _GENBORN_ALLVSALL_SSE2_SINGLE_H
-
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/legacyheaders/types/simple.h"
-
-int
-genborn_allvsall_calc_still_radii_sse2_single(t_forcerec *           fr,
-                                              t_mdatoms *            mdatoms,
-                                              gmx_genborn_t *        born,
-                                              gmx_localtop_t *       top,
-                                              real *                 x,
-                                              t_commrec *            cr,
-                                              void *                 work);
-
-int
-genborn_allvsall_calc_hct_obc_radii_sse2_single(t_forcerec *           fr,
-                                                t_mdatoms *            mdatoms,
-                                                gmx_genborn_t *        born,
-                                                int                    gb_algorithm,
-                                                gmx_localtop_t *       top,
-                                                real *                 x,
-                                                t_commrec *            cr,
-                                                void *                 work);
-
-int
-genborn_allvsall_calc_chainrule_sse2_single(t_forcerec *           fr,
-                                            t_mdatoms *            mdatoms,
-                                            gmx_genborn_t *        born,
-                                            real *                 x,
-                                            real *                 f,
-                                            int                    gb_algorithm,
-                                            void *                 work);
-
-#endif
diff --git a/src/gromacs/mdlib/genborn_sse2_double.c b/src/gromacs/mdlib/genborn_sse2_double.c
deleted file mode 100644 (file)
index 62cab4b..0000000
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include <math.h>
-#include <string.h>
-
-#include "gromacs/domdec/domdec.h"
-#include "gromacs/fileio/pdbio.h"
-#include "gromacs/legacyheaders/genborn.h"
-#include "gromacs/legacyheaders/names.h"
-#include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/math/units.h"
-#include "gromacs/math/vec.h"
-#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/gmxmpi.h"
-#include "gromacs/utility/smalloc.h"
-
-/* Only compile this file if SSE2 intrinsics are available */
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-#include "genborn_sse2_double.h"
-
-#include <emmintrin.h>
-#include <gmx_sse2_double.h>
-
-int
-calc_gb_rad_still_sse2_double(t_commrec *cr, t_forcerec *fr,
-                              int natoms, gmx_localtop_t *top,
-                              double *x, t_nblist *nl,
-                              gmx_genborn_t *born)
-{
-    int           i, k, n, ii, is3, ii3, nj0, nj1, offset;
-    int           jnrA, jnrB, j3A, j3B;
-    int          *mdtype;
-    double        shX, shY, shZ;
-    int          *jjnr;
-    double       *shiftvec;
-
-    double        gpi_ai, gpi2;
-    double        factor;
-    double       *gb_radius;
-    double       *vsolv;
-    double       *work;
-    double       *dadx;
-
-    __m128d       ix, iy, iz;
-    __m128d       jx, jy, jz;
-    __m128d       dx, dy, dz;
-    __m128d       tx, ty, tz;
-    __m128d       rsq, rinv, rinv2, rinv4, rinv6;
-    __m128d       ratio, gpi, rai, raj, vai, vaj, rvdw;
-    __m128d       ccf, dccf, theta, cosq, term, sinq, res, prod, prod_ai, tmp;
-    __m128d       mask, icf4, icf6, mask_cmp;
-
-    const __m128d half   = _mm_set1_pd(0.5);
-    const __m128d three  = _mm_set1_pd(3.0);
-    const __m128d one    = _mm_set1_pd(1.0);
-    const __m128d two    = _mm_set1_pd(2.0);
-    const __m128d zero   = _mm_set1_pd(0.0);
-    const __m128d four   = _mm_set1_pd(4.0);
-
-    const __m128d still_p5inv  = _mm_set1_pd(STILL_P5INV);
-    const __m128d still_pip5   = _mm_set1_pd(STILL_PIP5);
-    const __m128d still_p4     = _mm_set1_pd(STILL_P4);
-
-    factor  = 0.5 * ONE_4PI_EPS0;
-
-    gb_radius = born->gb_radius;
-    vsolv     = born->vsolv;
-    work      = born->gpol_still_work;
-    jjnr      = nl->jjnr;
-    shiftvec  = fr->shift_vec[0];
-    dadx      = fr->dadx;
-
-    jnrA = jnrB = 0;
-    jx   = _mm_setzero_pd();
-    jy   = _mm_setzero_pd();
-    jz   = _mm_setzero_pd();
-
-    n = 0;
-
-    for (i = 0; i < natoms; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = 0; i < nl->nri; i++)
-    {
-        ii     = nl->iinr[i];
-        ii3    = ii*3;
-        is3    = 3*nl->shift[i];
-        shX    = shiftvec[is3];
-        shY    = shiftvec[is3+1];
-        shZ    = shiftvec[is3+2];
-        nj0    = nl->jindex[i];
-        nj1    = nl->jindex[i+1];
-
-        ix     = _mm_set1_pd(shX+x[ii3+0]);
-        iy     = _mm_set1_pd(shY+x[ii3+1]);
-        iz     = _mm_set1_pd(shZ+x[ii3+2]);
-
-
-        /* Polarization energy for atom ai */
-        gpi    = _mm_setzero_pd();
-
-        rai     = _mm_load1_pd(gb_radius+ii);
-        prod_ai = _mm_set1_pd(STILL_P4*vsolv[ii]);
-
-        for (k = nj0; k < nj1-1; k += 2)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-
-            GMX_MM_LOAD_1RVEC_2POINTERS_PD(x+j3A, x+j3B, jx, jy, jz);
-
-            GMX_MM_LOAD_2VALUES_PD(gb_radius+jnrA, gb_radius+jnrB, raj);
-            GMX_MM_LOAD_2VALUES_PD(vsolv+jnrA, vsolv+jnrB, vaj);
-
-            dx          = _mm_sub_pd(ix, jx);
-            dy          = _mm_sub_pd(iy, jy);
-            dz          = _mm_sub_pd(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_pd(dx, dy, dz);
-            rinv        = gmx_mm_invsqrt_pd(rsq);
-            rinv2       = _mm_mul_pd(rinv, rinv);
-            rinv4       = _mm_mul_pd(rinv2, rinv2);
-            rinv6       = _mm_mul_pd(rinv4, rinv2);
-
-            rvdw        = _mm_add_pd(rai, raj);
-            ratio       = _mm_mul_pd(rsq, gmx_mm_inv_pd( _mm_mul_pd(rvdw, rvdw)));
-
-            mask_cmp    = _mm_cmple_pd(ratio, still_p5inv);
-
-            /* gmx_mm_sincos_pd() is quite expensive, so avoid calculating it if we can! */
-            if (0 == _mm_movemask_pd(mask_cmp) )
-            {
-                /* if ratio>still_p5inv for ALL elements */
-                ccf         = one;
-                dccf        = _mm_setzero_pd();
-            }
-            else
-            {
-                ratio       = _mm_min_pd(ratio, still_p5inv);
-                theta       = _mm_mul_pd(ratio, still_pip5);
-                gmx_mm_sincos_pd(theta, &sinq, &cosq);
-                term        = _mm_mul_pd(half, _mm_sub_pd(one, cosq));
-                ccf         = _mm_mul_pd(term, term);
-                dccf        = _mm_mul_pd(_mm_mul_pd(two, term),
-                                         _mm_mul_pd(sinq, theta));
-            }
-
-            prod        = _mm_mul_pd(still_p4, vaj);
-            icf4        = _mm_mul_pd(ccf, rinv4);
-            icf6        = _mm_mul_pd( _mm_sub_pd( _mm_mul_pd(four, ccf), dccf), rinv6);
-
-            GMX_MM_INCREMENT_2VALUES_PD(work+jnrA, work+jnrB, _mm_mul_pd(prod_ai, icf4));
-
-            gpi           = _mm_add_pd(gpi, _mm_mul_pd(prod, icf4) );
-
-            _mm_store_pd(dadx, _mm_mul_pd(prod, icf6));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai, icf6));
-            dadx += 2;
-        }
-
-        if (k < nj1)
-        {
-            jnrA        = jjnr[k];
-
-            j3A         = 3*jnrA;
-
-            GMX_MM_LOAD_1RVEC_1POINTER_PD(x+j3A, jx, jy, jz);
-
-            GMX_MM_LOAD_1VALUE_PD(gb_radius+jnrA, raj);
-            GMX_MM_LOAD_1VALUE_PD(vsolv+jnrA, vaj);
-
-            dx          = _mm_sub_sd(ix, jx);
-            dy          = _mm_sub_sd(iy, jy);
-            dz          = _mm_sub_sd(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_pd(dx, dy, dz);
-            rinv        = gmx_mm_invsqrt_pd(rsq);
-            rinv2       = _mm_mul_sd(rinv, rinv);
-            rinv4       = _mm_mul_sd(rinv2, rinv2);
-            rinv6       = _mm_mul_sd(rinv4, rinv2);
-
-            rvdw        = _mm_add_sd(rai, raj);
-            ratio       = _mm_mul_sd(rsq, gmx_mm_inv_pd( _mm_mul_pd(rvdw, rvdw)));
-
-            mask_cmp    = _mm_cmple_sd(ratio, still_p5inv);
-
-            /* gmx_mm_sincos_pd() is quite expensive, so avoid calculating it if we can! */
-            if (0 == _mm_movemask_pd(mask_cmp) )
-            {
-                /* if ratio>still_p5inv for ALL elements */
-                ccf         = one;
-                dccf        = _mm_setzero_pd();
-            }
-            else
-            {
-                ratio       = _mm_min_sd(ratio, still_p5inv);
-                theta       = _mm_mul_sd(ratio, still_pip5);
-                gmx_mm_sincos_pd(theta, &sinq, &cosq);
-                term        = _mm_mul_sd(half, _mm_sub_sd(one, cosq));
-                ccf         = _mm_mul_sd(term, term);
-                dccf        = _mm_mul_sd(_mm_mul_sd(two, term),
-                                         _mm_mul_sd(sinq, theta));
-            }
-
-            prod        = _mm_mul_sd(still_p4, vaj);
-            icf4        = _mm_mul_sd(ccf, rinv4);
-            icf6        = _mm_mul_sd( _mm_sub_sd( _mm_mul_sd(four, ccf), dccf), rinv6);
-
-            GMX_MM_INCREMENT_1VALUE_PD(work+jnrA, _mm_mul_sd(prod_ai, icf4));
-
-            gpi           = _mm_add_sd(gpi, _mm_mul_sd(prod, icf4) );
-
-            _mm_store_pd(dadx, _mm_mul_pd(prod, icf6));
-            dadx += 2;
-            _mm_store_pd(dadx, _mm_mul_pd(prod_ai, icf6));
-            dadx += 2;
-        }
-        gmx_mm_update_1pot_pd(gpi, work+ii);
-    }
-
-    /* Sum up the polarization energy from other nodes */
-    if (DOMAINDECOMP(cr))
-    {
-        dd_atom_sum_real(cr->dd, work);
-    }
-
-    /* Compute the radii */
-    for (i = 0; i < fr->natoms_force; i++) /* PELA born->nr */
-    {
-        if (born->use[i] != 0)
-        {
-            gpi_ai           = born->gpol[i] + work[i]; /* add gpi to the initial pol energy gpi_ai*/
-            gpi2             = gpi_ai * gpi_ai;
-            born->bRad[i]    = factor*gmx_invsqrt(gpi2);
-            fr->invsqrta[i]  = gmx_invsqrt(born->bRad[i]);
-        }
-    }
-
-    /* Extra (local) communication required for DD */
-    if (DOMAINDECOMP(cr))
-    {
-        dd_atom_spread_real(cr->dd, born->bRad);
-        dd_atom_spread_real(cr->dd, fr->invsqrta);
-    }
-
-    return 0;
-}
-
-
-int
-calc_gb_rad_hct_obc_sse2_double(t_commrec *cr, t_forcerec * fr, int natoms, gmx_localtop_t *top,
-                                double *x, t_nblist *nl, gmx_genborn_t *born, t_mdatoms *md, int gb_algorithm)
-{
-    int           i, ai, k, n, ii, ii3, is3, nj0, nj1, at0, at1, offset;
-    int           jnrA, jnrB;
-    int           j3A, j3B;
-    double        shX, shY, shZ;
-    double        rr, rr_inv, rr_inv2, sum_tmp, sum, sum2, sum3, gbr;
-    double        sum_ai2, sum_ai3, tsum, tchain, doffset;
-    double       *obc_param;
-    double       *gb_radius;
-    double       *work;
-    int        *  jjnr;
-    double       *dadx;
-    double       *shiftvec;
-    double        min_rad, rad;
-
-    __m128d       ix, iy, iz, jx, jy, jz;
-    __m128d       dx, dy, dz, t1, t2, t3, t4;
-    __m128d       rsq, rinv, r;
-    __m128d       rai, rai_inv, raj, raj_inv, rai_inv2, sk, sk2, lij, dlij, duij;
-    __m128d       uij, lij2, uij2, lij3, uij3, diff2;
-    __m128d       lij_inv, sk2_inv, prod, log_term, tmp, tmp_sum;
-    __m128d       sum_ai, tmp_ai, sk_ai, sk_aj, sk2_ai, sk2_aj, sk2_rinv;
-    __m128d       dadx1, dadx2;
-    __m128d       logterm;
-    __m128d       mask;
-    __m128d       obc_mask1, obc_mask2, obc_mask3;
-
-    __m128d       oneeighth   = _mm_set1_pd(0.125);
-    __m128d       onefourth   = _mm_set1_pd(0.25);
-
-    const __m128d half  = _mm_set1_pd(0.5);
-    const __m128d three = _mm_set1_pd(3.0);
-    const __m128d one   = _mm_set1_pd(1.0);
-    const __m128d two   = _mm_set1_pd(2.0);
-    const __m128d zero  = _mm_set1_pd(0.0);
-    const __m128d neg   = _mm_set1_pd(-1.0);
-
-    /* Set the dielectric offset */
-    doffset   = born->gb_doffset;
-    gb_radius = born->gb_radius;
-    obc_param = born->param;
-    work      = born->gpol_hct_work;
-    jjnr      = nl->jjnr;
-    dadx      = fr->dadx;
-    shiftvec  = fr->shift_vec[0];
-
-    jx        = _mm_setzero_pd();
-    jy        = _mm_setzero_pd();
-    jz        = _mm_setzero_pd();
-
-    jnrA = jnrB = 0;
-
-    for (i = 0; i < born->nr; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = 0; i < nl->nri; i++)
-    {
-        ii     = nl->iinr[i];
-        ii3    = ii*3;
-        is3    = 3*nl->shift[i];
-        shX    = shiftvec[is3];
-        shY    = shiftvec[is3+1];
-        shZ    = shiftvec[is3+2];
-        nj0    = nl->jindex[i];
-        nj1    = nl->jindex[i+1];
-
-        ix     = _mm_set1_pd(shX+x[ii3+0]);
-        iy     = _mm_set1_pd(shY+x[ii3+1]);
-        iz     = _mm_set1_pd(shZ+x[ii3+2]);
-
-        rai     = _mm_load1_pd(gb_radius+ii);
-        rai_inv = gmx_mm_inv_pd(rai);
-
-        sum_ai = _mm_setzero_pd();
-
-        sk_ai  = _mm_load1_pd(born->param+ii);
-        sk2_ai = _mm_mul_pd(sk_ai, sk_ai);
-
-        for (k = nj0; k < nj1-1; k += 2)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-
-            GMX_MM_LOAD_1RVEC_2POINTERS_PD(x+j3A, x+j3B, jx, jy, jz);
-            GMX_MM_LOAD_2VALUES_PD(gb_radius+jnrA, gb_radius+jnrB, raj);
-            GMX_MM_LOAD_2VALUES_PD(obc_param+jnrA, obc_param+jnrB, sk_aj);
-
-            dx    = _mm_sub_pd(ix, jx);
-            dy    = _mm_sub_pd(iy, jy);
-            dz    = _mm_sub_pd(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_pd(dx, dy, dz);
-
-            rinv        = gmx_mm_invsqrt_pd(rsq);
-            r           = _mm_mul_pd(rsq, rinv);
-
-            /* Compute raj_inv aj1-4 */
-            raj_inv     = gmx_mm_inv_pd(raj);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1            = _mm_add_pd(r, sk_aj);
-            t2            = _mm_sub_pd(r, sk_aj);
-            t3            = _mm_sub_pd(sk_aj, r);
-            obc_mask1     = _mm_cmplt_pd(rai, t1);
-            obc_mask2     = _mm_cmplt_pd(rai, t2);
-            obc_mask3     = _mm_cmplt_pd(rai, t3);
-
-            uij           = gmx_mm_inv_pd(t1);
-            lij           = _mm_or_pd(   _mm_and_pd(obc_mask2, gmx_mm_inv_pd(t2)),
-                                         _mm_andnot_pd(obc_mask2, rai_inv));
-            dlij          = _mm_and_pd(one, obc_mask2);
-            uij2          = _mm_mul_pd(uij, uij);
-            uij3          = _mm_mul_pd(uij2, uij);
-            lij2          = _mm_mul_pd(lij, lij);
-            lij3          = _mm_mul_pd(lij2, lij);
-
-            diff2         = _mm_sub_pd(uij2, lij2);
-            lij_inv       = gmx_mm_invsqrt_pd(lij2);
-            sk2_aj        = _mm_mul_pd(sk_aj, sk_aj);
-            sk2_rinv      = _mm_mul_pd(sk2_aj, rinv);
-            prod          = _mm_mul_pd(onefourth, sk2_rinv);
-
-            logterm       = gmx_mm_log_pd(_mm_mul_pd(uij, lij_inv));
-
-            t1            = _mm_sub_pd(lij, uij);
-            t2            = _mm_mul_pd(diff2,
-                                       _mm_sub_pd(_mm_mul_pd(onefourth, r),
-                                                  prod));
-            t3            = _mm_mul_pd(half, _mm_mul_pd(rinv, logterm));
-            t1            = _mm_add_pd(t1, _mm_add_pd(t2, t3));
-            t4            = _mm_mul_pd(two, _mm_sub_pd(rai_inv, lij));
-            t4            = _mm_and_pd(t4, obc_mask3);
-            t1            = _mm_mul_pd(half, _mm_add_pd(t1, t4));
-
-            sum_ai        = _mm_add_pd(sum_ai, _mm_and_pd(t1, obc_mask1) );
-
-            t1            = _mm_add_pd(_mm_mul_pd(half, lij2),
-                                       _mm_mul_pd(prod, lij3));
-            t1            = _mm_sub_pd(t1,
-                                       _mm_mul_pd(onefourth,
-                                                  _mm_add_pd(_mm_mul_pd(lij, rinv),
-                                                             _mm_mul_pd(lij3, r))));
-            t2            = _mm_mul_pd(onefourth,
-                                       _mm_add_pd(_mm_mul_pd(uij, rinv),
-                                                  _mm_mul_pd(uij3, r)));
-            t2            = _mm_sub_pd(t2,
-                                       _mm_add_pd(_mm_mul_pd(half, uij2),
-                                                  _mm_mul_pd(prod, uij3)));
-            t3            = _mm_mul_pd(_mm_mul_pd(onefourth, logterm),
-                                       _mm_mul_pd(rinv, rinv));
-            t3            = _mm_sub_pd(t3,
-                                       _mm_mul_pd(_mm_mul_pd(diff2, oneeighth),
-                                                  _mm_add_pd(one,
-                                                             _mm_mul_pd(sk2_rinv, rinv))));
-            t1            = _mm_mul_pd(rinv,
-                                       _mm_add_pd(_mm_mul_pd(dlij, t1),
-                                                  _mm_add_pd(t2, t3)));
-
-            dadx1         = _mm_and_pd(t1, obc_mask1);
-
-            /* Evaluate influence of atom ai -> aj */
-            t1            = _mm_add_pd(r, sk_ai);
-            t2            = _mm_sub_pd(r, sk_ai);
-            t3            = _mm_sub_pd(sk_ai, r);
-            obc_mask1     = _mm_cmplt_pd(raj, t1);
-            obc_mask2     = _mm_cmplt_pd(raj, t2);
-            obc_mask3     = _mm_cmplt_pd(raj, t3);
-
-            uij           = gmx_mm_inv_pd(t1);
-            lij           = _mm_or_pd(   _mm_and_pd(obc_mask2, gmx_mm_inv_pd(t2)),
-                                         _mm_andnot_pd(obc_mask2, raj_inv));
-            dlij          = _mm_and_pd(one, obc_mask2);
-            uij2          = _mm_mul_pd(uij, uij);
-            uij3          = _mm_mul_pd(uij2, uij);
-            lij2          = _mm_mul_pd(lij, lij);
-            lij3          = _mm_mul_pd(lij2, lij);
-
-            diff2         = _mm_sub_pd(uij2, lij2);
-            lij_inv       = gmx_mm_invsqrt_pd(lij2);
-            sk2_rinv      = _mm_mul_pd(sk2_ai, rinv);
-            prod          = _mm_mul_pd(onefourth, sk2_rinv);
-
-            logterm       = gmx_mm_log_pd(_mm_mul_pd(uij, lij_inv));
-
-            t1            = _mm_sub_pd(lij, uij);
-            t2            = _mm_mul_pd(diff2,
-                                       _mm_sub_pd(_mm_mul_pd(onefourth, r),
-                                                  prod));
-            t3            = _mm_mul_pd(half, _mm_mul_pd(rinv, logterm));
-            t1            = _mm_add_pd(t1, _mm_add_pd(t2, t3));
-            t4            = _mm_mul_pd(two, _mm_sub_pd(raj_inv, lij));
-            t4            = _mm_and_pd(t4, obc_mask3);
-            t1            = _mm_mul_pd(half, _mm_add_pd(t1, t4));
-
-            GMX_MM_INCREMENT_2VALUES_PD(work+jnrA, work+jnrB, _mm_and_pd(t1, obc_mask1));
-
-            t1            = _mm_add_pd(_mm_mul_pd(half, lij2),
-                                       _mm_mul_pd(prod, lij3));
-            t1            = _mm_sub_pd(t1,
-                                       _mm_mul_pd(onefourth,
-                                                  _mm_add_pd(_mm_mul_pd(lij, rinv),
-                                                             _mm_mul_pd(lij3, r))));
-            t2            = _mm_mul_pd(onefourth,
-                                       _mm_add_pd(_mm_mul_pd(uij, rinv),
-                                                  _mm_mul_pd(uij3, r)));
-            t2            = _mm_sub_pd(t2,
-                                       _mm_add_pd(_mm_mul_pd(half, uij2),
-                                                  _mm_mul_pd(prod, uij3)));
-            t3            = _mm_mul_pd(_mm_mul_pd(onefourth, logterm),
-                                       _mm_mul_pd(rinv, rinv));
-            t3            = _mm_sub_pd(t3,
-                                       _mm_mul_pd(_mm_mul_pd(diff2, oneeighth),
-                                                  _mm_add_pd(one,
-                                                             _mm_mul_pd(sk2_rinv, rinv))));
-            t1            = _mm_mul_pd(rinv,
-                                       _mm_add_pd(_mm_mul_pd(dlij, t1),
-                                                  _mm_add_pd(t2, t3)));
-
-            dadx2         = _mm_and_pd(t1, obc_mask1);
-
-            _mm_store_pd(dadx, dadx1);
-            dadx += 2;
-            _mm_store_pd(dadx, dadx2);
-            dadx += 2;
-        } /* end normal inner loop */
-
-        if (k < nj1)
-        {
-            jnrA        = jjnr[k];
-
-            j3A         = 3*jnrA;
-
-            GMX_MM_LOAD_1RVEC_1POINTER_PD(x+j3A, jx, jy, jz);
-            GMX_MM_LOAD_1VALUE_PD(gb_radius+jnrA, raj);
-            GMX_MM_LOAD_1VALUE_PD(obc_param+jnrA, sk_aj);
-
-            dx    = _mm_sub_sd(ix, jx);
-            dy    = _mm_sub_sd(iy, jy);
-            dz    = _mm_sub_sd(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_pd(dx, dy, dz);
-
-            rinv        = gmx_mm_invsqrt_pd(rsq);
-            r           = _mm_mul_sd(rsq, rinv);
-
-            /* Compute raj_inv aj1-4 */
-            raj_inv     = gmx_mm_inv_pd(raj);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1            = _mm_add_sd(r, sk_aj);
-            t2            = _mm_sub_sd(r, sk_aj);
-            t3            = _mm_sub_sd(sk_aj, r);
-            obc_mask1     = _mm_cmplt_sd(rai, t1);
-            obc_mask2     = _mm_cmplt_sd(rai, t2);
-            obc_mask3     = _mm_cmplt_sd(rai, t3);
-
-            uij           = gmx_mm_inv_pd(t1);
-            lij           = _mm_or_pd(_mm_and_pd(obc_mask2, gmx_mm_inv_pd(t2)),
-                                      _mm_andnot_pd(obc_mask2, rai_inv));
-            dlij          = _mm_and_pd(one, obc_mask2);
-            uij2          = _mm_mul_sd(uij, uij);
-            uij3          = _mm_mul_sd(uij2, uij);
-            lij2          = _mm_mul_sd(lij, lij);
-            lij3          = _mm_mul_sd(lij2, lij);
-
-            diff2         = _mm_sub_sd(uij2, lij2);
-            lij_inv       = gmx_mm_invsqrt_pd(lij2);
-            sk2_aj        = _mm_mul_sd(sk_aj, sk_aj);
-            sk2_rinv      = _mm_mul_sd(sk2_aj, rinv);
-            prod          = _mm_mul_sd(onefourth, sk2_rinv);
-
-            logterm       = gmx_mm_log_pd(_mm_mul_sd(uij, lij_inv));
-
-            t1            = _mm_sub_sd(lij, uij);
-            t2            = _mm_mul_sd(diff2,
-                                       _mm_sub_sd(_mm_mul_pd(onefourth, r),
-                                                  prod));
-            t3            = _mm_mul_sd(half, _mm_mul_sd(rinv, logterm));
-            t1            = _mm_add_sd(t1, _mm_add_sd(t2, t3));
-            t4            = _mm_mul_sd(two, _mm_sub_sd(rai_inv, lij));
-            t4            = _mm_and_pd(t4, obc_mask3);
-            t1            = _mm_mul_sd(half, _mm_add_sd(t1, t4));
-
-            sum_ai        = _mm_add_sd(sum_ai, _mm_and_pd(t1, obc_mask1) );
-
-            t1            = _mm_add_sd(_mm_mul_sd(half, lij2),
-                                       _mm_mul_sd(prod, lij3));
-            t1            = _mm_sub_sd(t1,
-                                       _mm_mul_sd(onefourth,
-                                                  _mm_add_sd(_mm_mul_sd(lij, rinv),
-                                                             _mm_mul_sd(lij3, r))));
-            t2            = _mm_mul_sd(onefourth,
-                                       _mm_add_sd(_mm_mul_sd(uij, rinv),
-                                                  _mm_mul_sd(uij3, r)));
-            t2            = _mm_sub_sd(t2,
-                                       _mm_add_sd(_mm_mul_sd(half, uij2),
-                                                  _mm_mul_sd(prod, uij3)));
-            t3            = _mm_mul_sd(_mm_mul_sd(onefourth, logterm),
-                                       _mm_mul_sd(rinv, rinv));
-            t3            = _mm_sub_sd(t3,
-                                       _mm_mul_sd(_mm_mul_sd(diff2, oneeighth),
-                                                  _mm_add_sd(one,
-                                                             _mm_mul_sd(sk2_rinv, rinv))));
-            t1            = _mm_mul_sd(rinv,
-                                       _mm_add_sd(_mm_mul_sd(dlij, t1),
-                                                  _mm_add_pd(t2, t3)));
-
-            dadx1         = _mm_and_pd(t1, obc_mask1);
-
-            /* Evaluate influence of atom ai -> aj */
-            t1            = _mm_add_sd(r, sk_ai);
-            t2            = _mm_sub_sd(r, sk_ai);
-            t3            = _mm_sub_sd(sk_ai, r);
-            obc_mask1     = _mm_cmplt_sd(raj, t1);
-            obc_mask2     = _mm_cmplt_sd(raj, t2);
-            obc_mask3     = _mm_cmplt_sd(raj, t3);
-
-            uij           = gmx_mm_inv_pd(t1);
-            lij           = _mm_or_pd(   _mm_and_pd(obc_mask2, gmx_mm_inv_pd(t2)),
-                                         _mm_andnot_pd(obc_mask2, raj_inv));
-            dlij          = _mm_and_pd(one, obc_mask2);
-            uij2          = _mm_mul_sd(uij, uij);
-            uij3          = _mm_mul_sd(uij2, uij);
-            lij2          = _mm_mul_sd(lij, lij);
-            lij3          = _mm_mul_sd(lij2, lij);
-
-            diff2         = _mm_sub_sd(uij2, lij2);
-            lij_inv       = gmx_mm_invsqrt_pd(lij2);
-            sk2_rinv      = _mm_mul_sd(sk2_ai, rinv);
-            prod          = _mm_mul_sd(onefourth, sk2_rinv);
-
-            logterm       = gmx_mm_log_pd(_mm_mul_sd(uij, lij_inv));
-
-            t1            = _mm_sub_sd(lij, uij);
-            t2            = _mm_mul_sd(diff2,
-                                       _mm_sub_sd(_mm_mul_sd(onefourth, r),
-                                                  prod));
-            t3            = _mm_mul_sd(half, _mm_mul_sd(rinv, logterm));
-            t1            = _mm_add_sd(t1, _mm_add_sd(t2, t3));
-            t4            = _mm_mul_sd(two, _mm_sub_sd(raj_inv, lij));
-            t4            = _mm_and_pd(t4, obc_mask3);
-            t1            = _mm_mul_sd(half, _mm_add_sd(t1, t4));
-
-            GMX_MM_INCREMENT_1VALUE_PD(work+jnrA, _mm_and_pd(t1, obc_mask1));
-
-            t1            = _mm_add_sd(_mm_mul_sd(half, lij2),
-                                       _mm_mul_sd(prod, lij3));
-            t1            = _mm_sub_sd(t1,
-                                       _mm_mul_sd(onefourth,
-                                                  _mm_add_sd(_mm_mul_sd(lij, rinv),
-                                                             _mm_mul_sd(lij3, r))));
-            t2            = _mm_mul_sd(onefourth,
-                                       _mm_add_sd(_mm_mul_sd(uij, rinv),
-                                                  _mm_mul_sd(uij3, r)));
-            t2            = _mm_sub_sd(t2,
-                                       _mm_add_sd(_mm_mul_sd(half, uij2),
-                                                  _mm_mul_sd(prod, uij3)));
-            t3            = _mm_mul_sd(_mm_mul_sd(onefourth, logterm),
-                                       _mm_mul_sd(rinv, rinv));
-            t3            = _mm_sub_sd(t3,
-                                       _mm_mul_sd(_mm_mul_sd(diff2, oneeighth),
-                                                  _mm_add_sd(one,
-                                                             _mm_mul_sd(sk2_rinv, rinv))));
-            t1            = _mm_mul_sd(rinv,
-                                       _mm_add_sd(_mm_mul_sd(dlij, t1),
-                                                  _mm_add_sd(t2, t3)));
-
-            dadx2         = _mm_and_pd(t1, obc_mask1);
-
-            _mm_store_pd(dadx, dadx1);
-            dadx += 2;
-            _mm_store_pd(dadx, dadx2);
-            dadx += 2;
-        }
-        gmx_mm_update_1pot_pd(sum_ai, work+ii);
-
-    }
-
-    /* Parallel summations */
-    if (DOMAINDECOMP(cr))
-    {
-        dd_atom_sum_real(cr->dd, work);
-    }
-
-    if (gb_algorithm == egbHCT)
-    {
-        /* HCT */
-        for (i = 0; i < fr->natoms_force; i++) /* PELA born->nr */
-        {
-            if (born->use[i] != 0)
-            {
-                rr      = top->atomtypes.gb_radius[md->typeA[i]]-doffset;
-                sum     = 1.0/rr - work[i];
-                min_rad = rr + doffset;
-                rad     = 1.0/sum;
-
-                born->bRad[i]   = rad > min_rad ? rad : min_rad;
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-            }
-        }
-
-        /* Extra communication required for DD */
-        if (DOMAINDECOMP(cr))
-        {
-            dd_atom_spread_real(cr->dd, born->bRad);
-            dd_atom_spread_real(cr->dd, fr->invsqrta);
-        }
-    }
-    else
-    {
-        /* OBC */
-        for (i = 0; i < fr->natoms_force; i++) /* PELA born->nr */
-        {
-            if (born->use[i] != 0)
-            {
-                rr      = top->atomtypes.gb_radius[md->typeA[i]];
-                rr_inv2 = 1.0/rr;
-                rr      = rr-doffset;
-                rr_inv  = 1.0/rr;
-                sum     = rr * work[i];
-                sum2    = sum  * sum;
-                sum3    = sum2 * sum;
-
-                tsum          = tanh(born->obc_alpha*sum-born->obc_beta*sum2+born->obc_gamma*sum3);
-                born->bRad[i] = rr_inv - tsum*rr_inv2;
-                born->bRad[i] = 1.0 / born->bRad[i];
-
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-
-                tchain         = rr * (born->obc_alpha-2*born->obc_beta*sum+3*born->obc_gamma*sum2);
-                born->drobc[i] = (1.0-tsum*tsum)*tchain*rr_inv2;
-            }
-        }
-        /* Extra (local) communication required for DD */
-        if (DOMAINDECOMP(cr))
-        {
-            dd_atom_spread_real(cr->dd, born->bRad);
-            dd_atom_spread_real(cr->dd, fr->invsqrta);
-            dd_atom_spread_real(cr->dd, born->drobc);
-        }
-    }
-
-
-
-    return 0;
-}
-
-
-int
-calc_gb_chainrule_sse2_double(int natoms, t_nblist *nl, double *dadx, double *dvda,
-                              double *x, double *f, double *fshift, double *shiftvec,
-                              int gb_algorithm, gmx_genborn_t *born, t_mdatoms *md)
-{
-    int           i, k, n, ii, jnr, ii3, is3, nj0, nj1, n0, n1;
-    int           jnrA, jnrB;
-    int           j3A, j3B;
-    int        *  jjnr;
-
-    double        rbi, shX, shY, shZ;
-    double       *rb;
-
-    __m128d       ix, iy, iz;
-    __m128d       jx, jy, jz;
-    __m128d       fix, fiy, fiz;
-    __m128d       dx, dy, dz;
-    __m128d       tx, ty, tz;
-
-    __m128d       rbai, rbaj, f_gb, f_gb_ai;
-    __m128d       xmm1, xmm2, xmm3;
-
-    const __m128d two = _mm_set1_pd(2.0);
-
-    rb     = born->work;
-
-    jjnr   = nl->jjnr;
-
-    /* Loop to get the proper form for the Born radius term, sse style */
-    n0 = 0;
-    n1 = natoms;
-
-    if (gb_algorithm == egbSTILL)
-    {
-        for (i = n0; i < n1; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = (2 * rbi * rbi * dvda[i])/ONE_4PI_EPS0;
-        }
-    }
-    else if (gb_algorithm == egbHCT)
-    {
-        for (i = n0; i < n1; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = rbi * rbi * dvda[i];
-        }
-    }
-    else if (gb_algorithm == egbOBC)
-    {
-        for (i = n0; i < n1; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = rbi * rbi * born->drobc[i] * dvda[i];
-        }
-    }
-
-    jz = _mm_setzero_pd();
-
-    n = j3A = j3B = 0;
-
-    for (i = 0; i < nl->nri; i++)
-    {
-        ii     = nl->iinr[i];
-        ii3    = ii*3;
-        is3    = 3*nl->shift[i];
-        shX    = shiftvec[is3];
-        shY    = shiftvec[is3+1];
-        shZ    = shiftvec[is3+2];
-        nj0    = nl->jindex[i];
-        nj1    = nl->jindex[i+1];
-
-        ix     = _mm_set1_pd(shX+x[ii3+0]);
-        iy     = _mm_set1_pd(shY+x[ii3+1]);
-        iz     = _mm_set1_pd(shZ+x[ii3+2]);
-
-        rbai   = _mm_load1_pd(rb+ii);
-        fix    = _mm_setzero_pd();
-        fiy    = _mm_setzero_pd();
-        fiz    = _mm_setzero_pd();
-
-
-        for (k = nj0; k < nj1-1; k += 2)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-
-            GMX_MM_LOAD_1RVEC_2POINTERS_PD(x+j3A, x+j3B, jx, jy, jz);
-
-            dx          = _mm_sub_pd(ix, jx);
-            dy          = _mm_sub_pd(iy, jy);
-            dz          = _mm_sub_pd(iz, jz);
-
-            GMX_MM_LOAD_2VALUES_PD(rb+jnrA, rb+jnrB, rbaj);
-
-            /* load chain rule terms for j1-4 */
-            f_gb        = _mm_load_pd(dadx);
-            dadx       += 2;
-            f_gb_ai     = _mm_load_pd(dadx);
-            dadx       += 2;
-
-            /* calculate scalar force */
-            f_gb    = _mm_mul_pd(f_gb, rbai);
-            f_gb_ai = _mm_mul_pd(f_gb_ai, rbaj);
-            f_gb    = _mm_add_pd(f_gb, f_gb_ai);
-
-            tx     = _mm_mul_pd(f_gb, dx);
-            ty     = _mm_mul_pd(f_gb, dy);
-            tz     = _mm_mul_pd(f_gb, dz);
-
-            fix    = _mm_add_pd(fix, tx);
-            fiy    = _mm_add_pd(fiy, ty);
-            fiz    = _mm_add_pd(fiz, tz);
-
-            GMX_MM_DECREMENT_1RVEC_2POINTERS_PD(f+j3A, f+j3B, tx, ty, tz);
-        }
-
-        /*deal with odd elements */
-        if (k < nj1)
-        {
-            jnrA        = jjnr[k];
-            j3A         = 3*jnrA;
-
-            GMX_MM_LOAD_1RVEC_1POINTER_PD(x+j3A, jx, jy, jz);
-
-            dx          = _mm_sub_sd(ix, jx);
-            dy          = _mm_sub_sd(iy, jy);
-            dz          = _mm_sub_sd(iz, jz);
-
-            GMX_MM_LOAD_1VALUE_PD(rb+jnrA, rbaj);
-
-            /* load chain rule terms */
-            f_gb        = _mm_load_pd(dadx);
-            dadx       += 2;
-            f_gb_ai     = _mm_load_pd(dadx);
-            dadx       += 2;
-
-            /* calculate scalar force */
-            f_gb    = _mm_mul_sd(f_gb, rbai);
-            f_gb_ai = _mm_mul_sd(f_gb_ai, rbaj);
-            f_gb    = _mm_add_sd(f_gb, f_gb_ai);
-
-            tx     = _mm_mul_sd(f_gb, dx);
-            ty     = _mm_mul_sd(f_gb, dy);
-            tz     = _mm_mul_sd(f_gb, dz);
-
-            fix    = _mm_add_sd(fix, tx);
-            fiy    = _mm_add_sd(fiy, ty);
-            fiz    = _mm_add_sd(fiz, tz);
-
-            GMX_MM_DECREMENT_1RVEC_1POINTER_PD(f+j3A, tx, ty, tz);
-        }
-
-        /* fix/fiy/fiz now contain four partial force terms, that all should be
-         * added to the i particle forces and shift forces.
-         */
-        gmx_mm_update_iforce_1atom_pd(&fix, &fiy, &fiz, f+ii3, fshift+is3);
-    }
-
-    return 0;
-}
-
-#else
-/* keep compiler happy */
-int genborn_sse2_dummy;
-
-#endif /* SSE2 intrinsics available */
diff --git a/src/gromacs/mdlib/genborn_sse2_single.c b/src/gromacs/mdlib/genborn_sse2_single.c
deleted file mode 100644 (file)
index accbb6e..0000000
+++ /dev/null
@@ -1,1510 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include <math.h>
-#include <string.h>
-
-#include "gromacs/domdec/domdec.h"
-#include "gromacs/fileio/pdbio.h"
-#include "gromacs/legacyheaders/genborn.h"
-#include "gromacs/legacyheaders/names.h"
-#include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/math/units.h"
-#include "gromacs/math/vec.h"
-#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/gmxmpi.h"
-#include "gromacs/utility/smalloc.h"
-
-
-/* Only compile this file if SSE intrinsics are available */
-#if 0 && defined (GMX_SIMD_X86_SSE2_OR_HIGHER)
-
-#include "genborn_sse2_single.h"
-
-#include <emmintrin.h>
-#include <gmx_sse2_single.h>
-
-
-int
-calc_gb_rad_still_sse2_single(t_commrec *cr, t_forcerec *fr,
-                              int natoms, gmx_localtop_t *top,
-                              float *x, t_nblist *nl,
-                              gmx_genborn_t *born)
-{
-    int          i, k, n, ii, is3, ii3, nj0, nj1, offset;
-    int          jnrA, jnrB, jnrC, jnrD, j3A, j3B, j3C, j3D;
-    int          jnrE, jnrF, jnrG, jnrH, j3E, j3F, j3G, j3H;
-    int          shift;
-    int         *mdtype;
-    real         shX, shY, shZ;
-    int         *jjnr;
-    real        *shiftvec;
-
-    float        gpi_ai, gpi2;
-    float        factor;
-    float       *gb_radius;
-    float       *vsolv;
-    float       *work;
-    float       *dadx;
-
-    __m128       ix, iy, iz;
-    __m128       jx, jy, jz;
-    __m128       dx, dy, dz;
-    __m128       tx, ty, tz;
-    __m128       jxB, jyB, jzB;
-    __m128       dxB, dyB, dzB;
-    __m128       txB, tyB, tzB;
-    __m128       rsq, rinv, rinv2, rinv4, rinv6;
-    __m128       rsqB, rinvB, rinv2B, rinv4B, rinv6B;
-    __m128       ratio, gpi, rai, raj, vai, vaj, rvdw;
-    __m128       ratioB, rajB, vajB, rvdwB;
-    __m128       ccf, dccf, theta, cosq, term, sinq, res, prod, prod_ai, tmp;
-    __m128       ccfB, dccfB, thetaB, cosqB, termB, sinqB, resB, prodB;
-    __m128       mask, icf4, icf6, mask_cmp;
-    __m128       icf4B, icf6B, mask_cmpB;
-
-    __m128       mask1 = gmx_mm_castsi128_ps( _mm_set_epi32(0, 0, 0, 0xffffffff) );
-    __m128       mask2 = gmx_mm_castsi128_ps( _mm_set_epi32(0, 0, 0xffffffff, 0xffffffff) );
-    __m128       mask3 = gmx_mm_castsi128_ps( _mm_set_epi32(0, 0xffffffff, 0xffffffff, 0xffffffff) );
-
-    const __m128 half   = _mm_set1_ps(0.5f);
-    const __m128 three  = _mm_set1_ps(3.0f);
-    const __m128 one    = _mm_set1_ps(1.0f);
-    const __m128 two    = _mm_set1_ps(2.0f);
-    const __m128 zero   = _mm_set1_ps(0.0f);
-    const __m128 four   = _mm_set1_ps(4.0f);
-
-    const __m128 still_p5inv  = _mm_set1_ps(STILL_P5INV);
-    const __m128 still_pip5   = _mm_set1_ps(STILL_PIP5);
-    const __m128 still_p4     = _mm_set1_ps(STILL_P4);
-
-    factor  = 0.5 * ONE_4PI_EPS0;
-
-    gb_radius = born->gb_radius;
-    vsolv     = born->vsolv;
-    work      = born->gpol_still_work;
-    jjnr      = nl->jjnr;
-    shiftvec  = fr->shift_vec[0];
-    dadx      = fr->dadx;
-
-    jnrA = jnrB = jnrC = jnrD = 0;
-    jx   = _mm_setzero_ps();
-    jy   = _mm_setzero_ps();
-    jz   = _mm_setzero_ps();
-
-    n = 0;
-
-    for (i = 0; i < natoms; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = 0; i < nl->nri; i++)
-    {
-        ii     = nl->iinr[i];
-        ii3    = ii*3;
-        is3    = 3*nl->shift[i];
-        shX    = shiftvec[is3];
-        shY    = shiftvec[is3+1];
-        shZ    = shiftvec[is3+2];
-        nj0    = nl->jindex[i];
-        nj1    = nl->jindex[i+1];
-
-        ix     = _mm_set1_ps(shX+x[ii3+0]);
-        iy     = _mm_set1_ps(shY+x[ii3+1]);
-        iz     = _mm_set1_ps(shZ+x[ii3+2]);
-
-        offset = (nj1-nj0)%4;
-
-        /* Polarization energy for atom ai */
-        gpi    = _mm_setzero_ps();
-
-        rai     = _mm_load1_ps(gb_radius+ii);
-        prod_ai = _mm_set1_ps(STILL_P4*vsolv[ii]);
-
-        for (k = nj0; k < nj1-4-offset; k += 8)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-            jnrC        = jjnr[k+2];
-            jnrD        = jjnr[k+3];
-            jnrE        = jjnr[k+4];
-            jnrF        = jjnr[k+5];
-            jnrG        = jjnr[k+6];
-            jnrH        = jjnr[k+7];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-            j3C         = 3*jnrC;
-            j3D         = 3*jnrD;
-            j3E         = 3*jnrE;
-            j3F         = 3*jnrF;
-            j3G         = 3*jnrG;
-            j3H         = 3*jnrH;
-
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3A, x+j3B, x+j3C, x+j3D, jx, jy, jz);
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3E, x+j3F, x+j3G, x+j3H, jxB, jyB, jzB);
-
-            GMX_MM_LOAD_4VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, gb_radius+jnrC, gb_radius+jnrD, raj);
-            GMX_MM_LOAD_4VALUES_PS(gb_radius+jnrE, gb_radius+jnrF, gb_radius+jnrG, gb_radius+jnrH, rajB);
-            GMX_MM_LOAD_4VALUES_PS(vsolv+jnrA, vsolv+jnrB, vsolv+jnrC, vsolv+jnrD, vaj);
-            GMX_MM_LOAD_4VALUES_PS(vsolv+jnrE, vsolv+jnrF, vsolv+jnrG, vsolv+jnrH, vajB);
-
-            dx          = _mm_sub_ps(ix, jx);
-            dy          = _mm_sub_ps(iy, jy);
-            dz          = _mm_sub_ps(iz, jz);
-            dxB         = _mm_sub_ps(ix, jxB);
-            dyB         = _mm_sub_ps(iy, jyB);
-            dzB         = _mm_sub_ps(iz, jzB);
-
-            rsq         = gmx_mm_calc_rsq_ps(dx, dy, dz);
-            rsqB        = gmx_mm_calc_rsq_ps(dxB, dyB, dzB);
-            rinv        = gmx_mm_invsqrt_ps(rsq);
-            rinvB       = gmx_mm_invsqrt_ps(rsqB);
-            rinv2       = _mm_mul_ps(rinv, rinv);
-            rinv2B      = _mm_mul_ps(rinvB, rinvB);
-            rinv4       = _mm_mul_ps(rinv2, rinv2);
-            rinv4B      = _mm_mul_ps(rinv2B, rinv2B);
-            rinv6       = _mm_mul_ps(rinv4, rinv2);
-            rinv6B      = _mm_mul_ps(rinv4B, rinv2B);
-
-            rvdw        = _mm_add_ps(rai, raj);
-            rvdwB       = _mm_add_ps(rai, rajB);
-            ratio       = _mm_mul_ps(rsq, gmx_mm_inv_ps( _mm_mul_ps(rvdw, rvdw)));
-            ratioB      = _mm_mul_ps(rsqB, gmx_mm_inv_ps( _mm_mul_ps(rvdwB, rvdwB)));
-
-            mask_cmp    = _mm_cmple_ps(ratio, still_p5inv);
-            mask_cmpB   = _mm_cmple_ps(ratioB, still_p5inv);
-
-            /* gmx_mm_sincos_ps() is quite expensive, so avoid calculating it if we can! */
-            if (0 == _mm_movemask_ps(mask_cmp) )
-            {
-                /* if ratio>still_p5inv for ALL elements */
-                ccf         = one;
-                dccf        = _mm_setzero_ps();
-            }
-            else
-            {
-                ratio       = _mm_min_ps(ratio, still_p5inv);
-                theta       = _mm_mul_ps(ratio, still_pip5);
-                gmx_mm_sincos_ps(theta, &sinq, &cosq);
-                term        = _mm_mul_ps(half, _mm_sub_ps(one, cosq));
-                ccf         = _mm_mul_ps(term, term);
-                dccf        = _mm_mul_ps(_mm_mul_ps(two, term),
-                                         _mm_mul_ps(sinq, theta));
-            }
-            if (0 == _mm_movemask_ps(mask_cmpB) )
-            {
-                /* if ratio>still_p5inv for ALL elements */
-                ccfB        = one;
-                dccfB       = _mm_setzero_ps();
-            }
-            else
-            {
-                ratioB      = _mm_min_ps(ratioB, still_p5inv);
-                thetaB      = _mm_mul_ps(ratioB, still_pip5);
-                gmx_mm_sincos_ps(thetaB, &sinqB, &cosqB);
-                termB       = _mm_mul_ps(half, _mm_sub_ps(one, cosqB));
-                ccfB        = _mm_mul_ps(termB, termB);
-                dccfB       = _mm_mul_ps(_mm_mul_ps(two, termB),
-                                         _mm_mul_ps(sinqB, thetaB));
-            }
-
-            prod        = _mm_mul_ps(still_p4, vaj);
-            prodB       = _mm_mul_ps(still_p4, vajB);
-            icf4        = _mm_mul_ps(ccf, rinv4);
-            icf4B       = _mm_mul_ps(ccfB, rinv4B);
-            icf6        = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four, ccf), dccf), rinv6);
-            icf6B       = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four, ccfB), dccfB), rinv6B);
-
-            GMX_MM_INCREMENT_4VALUES_PS(work+jnrA, work+jnrB, work+jnrC, work+jnrD, _mm_mul_ps(prod_ai, icf4));
-            GMX_MM_INCREMENT_4VALUES_PS(work+jnrE, work+jnrF, work+jnrG, work+jnrH, _mm_mul_ps(prod_ai, icf4B));
-
-            gpi           = _mm_add_ps(gpi, _mm_add_ps( _mm_mul_ps(prod, icf4), _mm_mul_ps(prodB, icf4B) ) );
-
-            _mm_store_ps(dadx, _mm_mul_ps(prod, icf6));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai, icf6));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prodB, icf6B));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai, icf6B));
-            dadx += 4;
-        }
-
-        for (; k < nj1-offset; k += 4)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-            jnrC        = jjnr[k+2];
-            jnrD        = jjnr[k+3];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-            j3C         = 3*jnrC;
-            j3D         = 3*jnrD;
-
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3A, x+j3B, x+j3C, x+j3D, jx, jy, jz);
-
-            GMX_MM_LOAD_4VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, gb_radius+jnrC, gb_radius+jnrD, raj);
-            GMX_MM_LOAD_4VALUES_PS(vsolv+jnrA, vsolv+jnrB, vsolv+jnrC, vsolv+jnrD, vaj);
-
-            dx          = _mm_sub_ps(ix, jx);
-            dy          = _mm_sub_ps(iy, jy);
-            dz          = _mm_sub_ps(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_ps(dx, dy, dz);
-            rinv        = gmx_mm_invsqrt_ps(rsq);
-            rinv2       = _mm_mul_ps(rinv, rinv);
-            rinv4       = _mm_mul_ps(rinv2, rinv2);
-            rinv6       = _mm_mul_ps(rinv4, rinv2);
-
-            rvdw        = _mm_add_ps(rai, raj);
-            ratio       = _mm_mul_ps(rsq, gmx_mm_inv_ps( _mm_mul_ps(rvdw, rvdw)));
-
-            mask_cmp    = _mm_cmple_ps(ratio, still_p5inv);
-
-            /* gmx_mm_sincos_ps() is quite expensive, so avoid calculating it if we can! */
-            if (0 == _mm_movemask_ps(mask_cmp))
-            {
-                /* if ratio>still_p5inv for ALL elements */
-                ccf         = one;
-                dccf        = _mm_setzero_ps();
-            }
-            else
-            {
-                ratio       = _mm_min_ps(ratio, still_p5inv);
-                theta       = _mm_mul_ps(ratio, still_pip5);
-                gmx_mm_sincos_ps(theta, &sinq, &cosq);
-                term        = _mm_mul_ps(half, _mm_sub_ps(one, cosq));
-                ccf         = _mm_mul_ps(term, term);
-                dccf        = _mm_mul_ps(_mm_mul_ps(two, term),
-                                         _mm_mul_ps(sinq, theta));
-            }
-
-            prod        = _mm_mul_ps(still_p4, vaj);
-            icf4        = _mm_mul_ps(ccf, rinv4);
-            icf6        = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four, ccf), dccf), rinv6);
-
-            GMX_MM_INCREMENT_4VALUES_PS(work+jnrA, work+jnrB, work+jnrC, work+jnrD, _mm_mul_ps(prod_ai, icf4));
-
-            gpi           = _mm_add_ps(gpi, _mm_mul_ps(prod, icf4));
-
-            _mm_store_ps(dadx, _mm_mul_ps(prod, icf6));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai, icf6));
-            dadx += 4;
-        }
-
-        if (offset != 0)
-        {
-            if (offset == 1)
-            {
-                jnrA        = jjnr[k];
-                j3A         = 3*jnrA;
-                GMX_MM_LOAD_1RVEC_1POINTER_PS(x+j3A, jx, jy, jz);
-                GMX_MM_LOAD_1VALUE_PS(gb_radius+jnrA, raj);
-                GMX_MM_LOAD_1VALUE_PS(vsolv+jnrA, vaj);
-                mask        = mask1;
-            }
-            else if (offset == 2)
-            {
-                jnrA        = jjnr[k];
-                jnrB        = jjnr[k+1];
-                j3A         = 3*jnrA;
-                j3B         = 3*jnrB;
-                GMX_MM_LOAD_1RVEC_2POINTERS_PS(x+j3A, x+j3B, jx, jy, jz);
-                GMX_MM_LOAD_2VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, raj);
-                GMX_MM_LOAD_2VALUES_PS(vsolv+jnrA, vsolv+jnrB, vaj);
-                mask        = mask2;
-            }
-            else
-            {
-                /* offset must be 3 */
-                jnrA        = jjnr[k];
-                jnrB        = jjnr[k+1];
-                jnrC        = jjnr[k+2];
-                j3A         = 3*jnrA;
-                j3B         = 3*jnrB;
-                j3C         = 3*jnrC;
-                GMX_MM_LOAD_1RVEC_3POINTERS_PS(x+j3A, x+j3B, x+j3C, jx, jy, jz);
-                GMX_MM_LOAD_3VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, gb_radius+jnrC, raj);
-                GMX_MM_LOAD_3VALUES_PS(vsolv+jnrA, vsolv+jnrB, vsolv+jnrC, vaj);
-                mask        = mask3;
-            }
-
-            dx          = _mm_sub_ps(ix, jx);
-            dy          = _mm_sub_ps(iy, jy);
-            dz          = _mm_sub_ps(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_ps(dx, dy, dz);
-            rinv        = gmx_mm_invsqrt_ps(rsq);
-            rinv2       = _mm_mul_ps(rinv, rinv);
-            rinv4       = _mm_mul_ps(rinv2, rinv2);
-            rinv6       = _mm_mul_ps(rinv4, rinv2);
-
-            rvdw        = _mm_add_ps(rai, raj);
-            ratio       = _mm_mul_ps(rsq, gmx_mm_inv_ps( _mm_mul_ps(rvdw, rvdw)));
-
-            mask_cmp    = _mm_cmple_ps(ratio, still_p5inv);
-
-            if (0 == _mm_movemask_ps(mask_cmp))
-            {
-                /* if ratio>still_p5inv for ALL elements */
-                ccf         = one;
-                dccf        = _mm_setzero_ps();
-            }
-            else
-            {
-                ratio       = _mm_min_ps(ratio, still_p5inv);
-                theta       = _mm_mul_ps(ratio, still_pip5);
-                gmx_mm_sincos_ps(theta, &sinq, &cosq);
-                term        = _mm_mul_ps(half, _mm_sub_ps(one, cosq));
-                ccf         = _mm_mul_ps(term, term);
-                dccf        = _mm_mul_ps(_mm_mul_ps(two, term),
-                                         _mm_mul_ps(sinq, theta));
-            }
-
-            prod        = _mm_mul_ps(still_p4, vaj);
-            icf4        = _mm_mul_ps(ccf, rinv4);
-            icf6        = _mm_mul_ps( _mm_sub_ps( _mm_mul_ps(four, ccf), dccf), rinv6);
-
-            gpi           = _mm_add_ps(gpi, _mm_mul_ps(prod, icf4));
-
-            _mm_store_ps(dadx, _mm_mul_ps(prod, icf6));
-            dadx += 4;
-            _mm_store_ps(dadx, _mm_mul_ps(prod_ai, icf6));
-            dadx += 4;
-
-            tmp = _mm_mul_ps(prod_ai, icf4);
-
-            if (offset == 1)
-            {
-                GMX_MM_INCREMENT_1VALUE_PS(work+jnrA, tmp);
-            }
-            else if (offset == 2)
-            {
-                GMX_MM_INCREMENT_2VALUES_PS(work+jnrA, work+jnrB, tmp);
-            }
-            else
-            {
-                /* offset must be 3 */
-                GMX_MM_INCREMENT_3VALUES_PS(work+jnrA, work+jnrB, work+jnrC, tmp);
-            }
-        }
-        GMX_MM_UPDATE_1POT_PS(gpi, work+ii);
-    }
-
-    /* Sum up the polarization energy from other nodes */
-    if (DOMAINDECOMP(cr))
-    {
-        dd_atom_sum_real(cr->dd, work);
-    }
-
-    /* Compute the radii */
-    for (i = 0; i < fr->natoms_force; i++) /* PELA born->nr */
-    {
-        if (born->use[i] != 0)
-        {
-            gpi_ai           = born->gpol[i] + work[i]; /* add gpi to the initial pol energy gpi_ai*/
-            gpi2             = gpi_ai * gpi_ai;
-            born->bRad[i]    = factor*gmx_invsqrt(gpi2);
-            fr->invsqrta[i]  = gmx_invsqrt(born->bRad[i]);
-        }
-    }
-
-    /* Extra (local) communication required for DD */
-    if (DOMAINDECOMP(cr))
-    {
-        dd_atom_spread_real(cr->dd, born->bRad);
-        dd_atom_spread_real(cr->dd, fr->invsqrta);
-    }
-
-    return 0;
-}
-
-
-int
-calc_gb_rad_hct_obc_sse2_single(t_commrec *cr, t_forcerec * fr, int natoms, gmx_localtop_t *top,
-                                float *x, t_nblist *nl, gmx_genborn_t *born, t_mdatoms *md, int gb_algorithm)
-{
-    int          i, ai, k, n, ii, ii3, is3, nj0, nj1, at0, at1, offset;
-    int          jnrA, jnrB, jnrC, jnrD;
-    int          j3A, j3B, j3C, j3D;
-    int          jnrE, jnrF, jnrG, jnrH;
-    int          j3E, j3F, j3G, j3H;
-    float        shX, shY, shZ;
-    float        rr, rr_inv, rr_inv2, sum_tmp, sum, sum2, sum3, gbr;
-    float        sum_ai2, sum_ai3, tsum, tchain, doffset;
-    float       *obc_param;
-    float       *gb_radius;
-    float       *work;
-    int       *  jjnr;
-    float       *dadx;
-    float       *shiftvec;
-    float        min_rad, rad;
-
-    __m128       ix, iy, iz, jx, jy, jz;
-    __m128       dx, dy, dz, t1, t2, t3, t4;
-    __m128       rsq, rinv, r;
-    __m128       rai, rai_inv, raj, raj_inv, rai_inv2, sk, sk2, lij, dlij, duij;
-    __m128       uij, lij2, uij2, lij3, uij3, diff2;
-    __m128       lij_inv, sk2_inv, prod, log_term, tmp, tmp_sum;
-    __m128       sum_ai, tmp_ai, sk_ai, sk_aj, sk2_ai, sk2_aj, sk2_rinv;
-    __m128       dadx1, dadx2;
-    __m128       logterm;
-    __m128       mask;
-    __m128       obc_mask1, obc_mask2, obc_mask3;
-    __m128       jxB, jyB, jzB, t1B, t2B, t3B, t4B;
-    __m128       dxB, dyB, dzB, rsqB, rinvB, rB;
-    __m128       rajB, raj_invB, rai_inv2B, sk2B, lijB, dlijB, duijB;
-    __m128       uijB, lij2B, uij2B, lij3B, uij3B, diff2B;
-    __m128       lij_invB, sk2_invB, prodB;
-    __m128       sk_ajB, sk2_ajB, sk2_rinvB;
-    __m128       dadx1B, dadx2B;
-    __m128       logtermB;
-    __m128       obc_mask1B, obc_mask2B, obc_mask3B;
-
-    __m128       mask1 = gmx_mm_castsi128_ps( _mm_set_epi32(0, 0, 0, 0xffffffff) );
-    __m128       mask2 = gmx_mm_castsi128_ps( _mm_set_epi32(0, 0, 0xffffffff, 0xffffffff) );
-    __m128       mask3 = gmx_mm_castsi128_ps( _mm_set_epi32(0, 0xffffffff, 0xffffffff, 0xffffffff) );
-
-    __m128       oneeighth   = _mm_set1_ps(0.125);
-    __m128       onefourth   = _mm_set1_ps(0.25);
-
-    const __m128 half  = _mm_set1_ps(0.5f);
-    const __m128 three = _mm_set1_ps(3.0f);
-    const __m128 one   = _mm_set1_ps(1.0f);
-    const __m128 two   = _mm_set1_ps(2.0f);
-    const __m128 zero  = _mm_set1_ps(0.0f);
-    const __m128 neg   = _mm_set1_ps(-1.0f);
-
-    /* Set the dielectric offset */
-    doffset   = born->gb_doffset;
-    gb_radius = born->gb_radius;
-    obc_param = born->param;
-    work      = born->gpol_hct_work;
-    jjnr      = nl->jjnr;
-    dadx      = fr->dadx;
-    shiftvec  = fr->shift_vec[0];
-
-    jx        = _mm_setzero_ps();
-    jy        = _mm_setzero_ps();
-    jz        = _mm_setzero_ps();
-
-    jnrA = jnrB = jnrC = jnrD = 0;
-
-    for (i = 0; i < born->nr; i++)
-    {
-        work[i] = 0;
-    }
-
-    for (i = 0; i < nl->nri; i++)
-    {
-        ii     = nl->iinr[i];
-        ii3    = ii*3;
-        is3    = 3*nl->shift[i];
-        shX    = shiftvec[is3];
-        shY    = shiftvec[is3+1];
-        shZ    = shiftvec[is3+2];
-        nj0    = nl->jindex[i];
-        nj1    = nl->jindex[i+1];
-
-        ix     = _mm_set1_ps(shX+x[ii3+0]);
-        iy     = _mm_set1_ps(shY+x[ii3+1]);
-        iz     = _mm_set1_ps(shZ+x[ii3+2]);
-
-        offset = (nj1-nj0)%4;
-
-        rai     = _mm_load1_ps(gb_radius+ii);
-        rai_inv = gmx_mm_inv_ps(rai);
-
-        sum_ai = _mm_setzero_ps();
-
-        sk_ai  = _mm_load1_ps(born->param+ii);
-        sk2_ai = _mm_mul_ps(sk_ai, sk_ai);
-
-        for (k = nj0; k < nj1-4-offset; k += 8)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-            jnrC        = jjnr[k+2];
-            jnrD        = jjnr[k+3];
-            jnrE        = jjnr[k+4];
-            jnrF        = jjnr[k+5];
-            jnrG        = jjnr[k+6];
-            jnrH        = jjnr[k+7];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-            j3C         = 3*jnrC;
-            j3D         = 3*jnrD;
-            j3E         = 3*jnrE;
-            j3F         = 3*jnrF;
-            j3G         = 3*jnrG;
-            j3H         = 3*jnrH;
-
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3A, x+j3B, x+j3C, x+j3D, jx, jy, jz);
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3E, x+j3F, x+j3G, x+j3H, jxB, jyB, jzB);
-            GMX_MM_LOAD_4VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, gb_radius+jnrC, gb_radius+jnrD, raj);
-            GMX_MM_LOAD_4VALUES_PS(gb_radius+jnrE, gb_radius+jnrF, gb_radius+jnrG, gb_radius+jnrH, rajB);
-            GMX_MM_LOAD_4VALUES_PS(obc_param+jnrA, obc_param+jnrB, obc_param+jnrC, obc_param+jnrD, sk_aj);
-            GMX_MM_LOAD_4VALUES_PS(obc_param+jnrE, obc_param+jnrF, obc_param+jnrG, obc_param+jnrH, sk_ajB);
-
-            dx    = _mm_sub_ps(ix, jx);
-            dy    = _mm_sub_ps(iy, jy);
-            dz    = _mm_sub_ps(iz, jz);
-            dxB   = _mm_sub_ps(ix, jxB);
-            dyB   = _mm_sub_ps(iy, jyB);
-            dzB   = _mm_sub_ps(iz, jzB);
-
-            rsq         = gmx_mm_calc_rsq_ps(dx, dy, dz);
-            rsqB        = gmx_mm_calc_rsq_ps(dxB, dyB, dzB);
-
-            rinv        = gmx_mm_invsqrt_ps(rsq);
-            r           = _mm_mul_ps(rsq, rinv);
-            rinvB       = gmx_mm_invsqrt_ps(rsqB);
-            rB          = _mm_mul_ps(rsqB, rinvB);
-
-            /* Compute raj_inv aj1-4 */
-            raj_inv     = gmx_mm_inv_ps(raj);
-            raj_invB    = gmx_mm_inv_ps(rajB);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1            = _mm_add_ps(r, sk_aj);
-            t2            = _mm_sub_ps(r, sk_aj);
-            t3            = _mm_sub_ps(sk_aj, r);
-            t1B           = _mm_add_ps(rB, sk_ajB);
-            t2B           = _mm_sub_ps(rB, sk_ajB);
-            t3B           = _mm_sub_ps(sk_ajB, rB);
-            obc_mask1     = _mm_cmplt_ps(rai, t1);
-            obc_mask2     = _mm_cmplt_ps(rai, t2);
-            obc_mask3     = _mm_cmplt_ps(rai, t3);
-            obc_mask1B    = _mm_cmplt_ps(rai, t1B);
-            obc_mask2B    = _mm_cmplt_ps(rai, t2B);
-            obc_mask3B    = _mm_cmplt_ps(rai, t3B);
-
-            uij           = gmx_mm_inv_ps(t1);
-            lij           = _mm_or_ps(   _mm_and_ps(obc_mask2, gmx_mm_inv_ps(t2)),
-                                         _mm_andnot_ps(obc_mask2, rai_inv));
-            dlij          = _mm_and_ps(one, obc_mask2);
-            uij2          = _mm_mul_ps(uij, uij);
-            uij3          = _mm_mul_ps(uij2, uij);
-            lij2          = _mm_mul_ps(lij, lij);
-            lij3          = _mm_mul_ps(lij2, lij);
-
-            uijB          = gmx_mm_inv_ps(t1B);
-            lijB          = _mm_or_ps(   _mm_and_ps(obc_mask2B, gmx_mm_inv_ps(t2B)),
-                                         _mm_andnot_ps(obc_mask2B, rai_inv));
-            dlijB         = _mm_and_ps(one, obc_mask2B);
-            uij2B         = _mm_mul_ps(uijB, uijB);
-            uij3B         = _mm_mul_ps(uij2B, uijB);
-            lij2B         = _mm_mul_ps(lijB, lijB);
-            lij3B         = _mm_mul_ps(lij2B, lijB);
-
-            diff2         = _mm_sub_ps(uij2, lij2);
-            lij_inv       = gmx_mm_invsqrt_ps(lij2);
-            sk2_aj        = _mm_mul_ps(sk_aj, sk_aj);
-            sk2_rinv      = _mm_mul_ps(sk2_aj, rinv);
-            prod          = _mm_mul_ps(onefourth, sk2_rinv);
-
-            diff2B        = _mm_sub_ps(uij2B, lij2B);
-            lij_invB      = gmx_mm_invsqrt_ps(lij2B);
-            sk2_ajB       = _mm_mul_ps(sk_ajB, sk_ajB);
-            sk2_rinvB     = _mm_mul_ps(sk2_ajB, rinvB);
-            prodB         = _mm_mul_ps(onefourth, sk2_rinvB);
-
-            logterm       = gmx_mm_log_ps(_mm_mul_ps(uij, lij_inv));
-            logtermB      = gmx_mm_log_ps(_mm_mul_ps(uijB, lij_invB));
-
-            t1            = _mm_sub_ps(lij, uij);
-            t2            = _mm_mul_ps(diff2,
-                                       _mm_sub_ps(_mm_mul_ps(onefourth, r),
-                                                  prod));
-            t3            = _mm_mul_ps(half, _mm_mul_ps(rinv, logterm));
-            t1            = _mm_add_ps(t1, _mm_add_ps(t2, t3));
-            t4            = _mm_mul_ps(two, _mm_sub_ps(rai_inv, lij));
-            t4            = _mm_and_ps(t4, obc_mask3);
-            t1            = _mm_mul_ps(half, _mm_add_ps(t1, t4));
-
-            t1B           = _mm_sub_ps(lijB, uijB);
-            t2B           = _mm_mul_ps(diff2B,
-                                       _mm_sub_ps(_mm_mul_ps(onefourth, rB),
-                                                  prodB));
-            t3B           = _mm_mul_ps(half, _mm_mul_ps(rinvB, logtermB));
-            t1B           = _mm_add_ps(t1B, _mm_add_ps(t2B, t3B));
-            t4B           = _mm_mul_ps(two, _mm_sub_ps(rai_inv, lijB));
-            t4B           = _mm_and_ps(t4B, obc_mask3B);
-            t1B           = _mm_mul_ps(half, _mm_add_ps(t1B, t4B));
-
-            sum_ai        = _mm_add_ps(sum_ai, _mm_add_ps( _mm_and_ps(t1, obc_mask1), _mm_and_ps(t1B, obc_mask1B) ));
-
-            t1            = _mm_add_ps(_mm_mul_ps(half, lij2),
-                                       _mm_mul_ps(prod, lij3));
-            t1            = _mm_sub_ps(t1,
-                                       _mm_mul_ps(onefourth,
-                                                  _mm_add_ps(_mm_mul_ps(lij, rinv),
-                                                             _mm_mul_ps(lij3, r))));
-            t2            = _mm_mul_ps(onefourth,
-                                       _mm_add_ps(_mm_mul_ps(uij, rinv),
-                                                  _mm_mul_ps(uij3, r)));
-            t2            = _mm_sub_ps(t2,
-                                       _mm_add_ps(_mm_mul_ps(half, uij2),
-                                                  _mm_mul_ps(prod, uij3)));
-            t3            = _mm_mul_ps(_mm_mul_ps(onefourth, logterm),
-                                       _mm_mul_ps(rinv, rinv));
-            t3            = _mm_sub_ps(t3,
-                                       _mm_mul_ps(_mm_mul_ps(diff2, oneeighth),
-                                                  _mm_add_ps(one,
-                                                             _mm_mul_ps(sk2_rinv, rinv))));
-            t1            = _mm_mul_ps(rinv,
-                                       _mm_add_ps(_mm_mul_ps(dlij, t1),
-                                                  _mm_add_ps(t2, t3)));
-
-
-
-            t1B           = _mm_add_ps(_mm_mul_ps(half, lij2B),
-                                       _mm_mul_ps(prodB, lij3B));
-            t1B           = _mm_sub_ps(t1B,
-                                       _mm_mul_ps(onefourth,
-                                                  _mm_add_ps(_mm_mul_ps(lijB, rinvB),
-                                                             _mm_mul_ps(lij3B, rB))));
-            t2B           = _mm_mul_ps(onefourth,
-                                       _mm_add_ps(_mm_mul_ps(uijB, rinvB),
-                                                  _mm_mul_ps(uij3B, rB)));
-            t2B           = _mm_sub_ps(t2B,
-                                       _mm_add_ps(_mm_mul_ps(half, uij2B),
-                                                  _mm_mul_ps(prodB, uij3B)));
-            t3B           = _mm_mul_ps(_mm_mul_ps(onefourth, logtermB),
-                                       _mm_mul_ps(rinvB, rinvB));
-            t3B           = _mm_sub_ps(t3B,
-                                       _mm_mul_ps(_mm_mul_ps(diff2B, oneeighth),
-                                                  _mm_add_ps(one,
-                                                             _mm_mul_ps(sk2_rinvB, rinvB))));
-            t1B           = _mm_mul_ps(rinvB,
-                                       _mm_add_ps(_mm_mul_ps(dlijB, t1B),
-                                                  _mm_add_ps(t2B, t3B)));
-
-            dadx1         = _mm_and_ps(t1, obc_mask1);
-            dadx1B        = _mm_and_ps(t1B, obc_mask1B);
-
-
-            /* Evaluate influence of atom ai -> aj */
-            t1            = _mm_add_ps(r, sk_ai);
-            t2            = _mm_sub_ps(r, sk_ai);
-            t3            = _mm_sub_ps(sk_ai, r);
-            t1B           = _mm_add_ps(rB, sk_ai);
-            t2B           = _mm_sub_ps(rB, sk_ai);
-            t3B           = _mm_sub_ps(sk_ai, rB);
-            obc_mask1     = _mm_cmplt_ps(raj, t1);
-            obc_mask2     = _mm_cmplt_ps(raj, t2);
-            obc_mask3     = _mm_cmplt_ps(raj, t3);
-            obc_mask1B    = _mm_cmplt_ps(rajB, t1B);
-            obc_mask2B    = _mm_cmplt_ps(rajB, t2B);
-            obc_mask3B    = _mm_cmplt_ps(rajB, t3B);
-
-            uij           = gmx_mm_inv_ps(t1);
-            lij           = _mm_or_ps(   _mm_and_ps(obc_mask2, gmx_mm_inv_ps(t2)),
-                                         _mm_andnot_ps(obc_mask2, raj_inv));
-            dlij          = _mm_and_ps(one, obc_mask2);
-            uij2          = _mm_mul_ps(uij, uij);
-            uij3          = _mm_mul_ps(uij2, uij);
-            lij2          = _mm_mul_ps(lij, lij);
-            lij3          = _mm_mul_ps(lij2, lij);
-
-            uijB          = gmx_mm_inv_ps(t1B);
-            lijB          = _mm_or_ps(   _mm_and_ps(obc_mask2B, gmx_mm_inv_ps(t2B)),
-                                         _mm_andnot_ps(obc_mask2B, raj_invB));
-            dlijB         = _mm_and_ps(one, obc_mask2B);
-            uij2B         = _mm_mul_ps(uijB, uijB);
-            uij3B         = _mm_mul_ps(uij2B, uijB);
-            lij2B         = _mm_mul_ps(lijB, lijB);
-            lij3B         = _mm_mul_ps(lij2B, lijB);
-
-            diff2         = _mm_sub_ps(uij2, lij2);
-            lij_inv       = gmx_mm_invsqrt_ps(lij2);
-            sk2_rinv      = _mm_mul_ps(sk2_ai, rinv);
-            prod          = _mm_mul_ps(onefourth, sk2_rinv);
-
-            diff2B        = _mm_sub_ps(uij2B, lij2B);
-            lij_invB      = gmx_mm_invsqrt_ps(lij2B);
-            sk2_rinvB     = _mm_mul_ps(sk2_ai, rinvB);
-            prodB         = _mm_mul_ps(onefourth, sk2_rinvB);
-
-            logterm       = gmx_mm_log_ps(_mm_mul_ps(uij, lij_inv));
-            logtermB      = gmx_mm_log_ps(_mm_mul_ps(uijB, lij_invB));
-
-            t1            = _mm_sub_ps(lij, uij);
-            t2            = _mm_mul_ps(diff2,
-                                       _mm_sub_ps(_mm_mul_ps(onefourth, r),
-                                                  prod));
-            t3            = _mm_mul_ps(half, _mm_mul_ps(rinv, logterm));
-            t1            = _mm_add_ps(t1, _mm_add_ps(t2, t3));
-            t4            = _mm_mul_ps(two, _mm_sub_ps(raj_inv, lij));
-            t4            = _mm_and_ps(t4, obc_mask3);
-            t1            = _mm_mul_ps(half, _mm_add_ps(t1, t4));
-
-            t1B           = _mm_sub_ps(lijB, uijB);
-            t2B           = _mm_mul_ps(diff2B,
-                                       _mm_sub_ps(_mm_mul_ps(onefourth, rB),
-                                                  prodB));
-            t3B           = _mm_mul_ps(half, _mm_mul_ps(rinvB, logtermB));
-            t1B           = _mm_add_ps(t1B, _mm_add_ps(t2B, t3B));
-            t4B           = _mm_mul_ps(two, _mm_sub_ps(raj_invB, lijB));
-            t4B           = _mm_and_ps(t4B, obc_mask3B);
-            t1B           = _mm_mul_ps(half, _mm_add_ps(t1B, t4B));
-
-            GMX_MM_INCREMENT_4VALUES_PS(work+jnrA, work+jnrB, work+jnrC, work+jnrD, _mm_and_ps(t1, obc_mask1));
-            GMX_MM_INCREMENT_4VALUES_PS(work+jnrE, work+jnrF, work+jnrG, work+jnrH, _mm_and_ps(t1B, obc_mask1B));
-
-            t1            = _mm_add_ps(_mm_mul_ps(half, lij2),
-                                       _mm_mul_ps(prod, lij3));
-            t1            = _mm_sub_ps(t1,
-                                       _mm_mul_ps(onefourth,
-                                                  _mm_add_ps(_mm_mul_ps(lij, rinv),
-                                                             _mm_mul_ps(lij3, r))));
-            t2            = _mm_mul_ps(onefourth,
-                                       _mm_add_ps(_mm_mul_ps(uij, rinv),
-                                                  _mm_mul_ps(uij3, r)));
-            t2            = _mm_sub_ps(t2,
-                                       _mm_add_ps(_mm_mul_ps(half, uij2),
-                                                  _mm_mul_ps(prod, uij3)));
-            t3            = _mm_mul_ps(_mm_mul_ps(onefourth, logterm),
-                                       _mm_mul_ps(rinv, rinv));
-            t3            = _mm_sub_ps(t3,
-                                       _mm_mul_ps(_mm_mul_ps(diff2, oneeighth),
-                                                  _mm_add_ps(one,
-                                                             _mm_mul_ps(sk2_rinv, rinv))));
-            t1            = _mm_mul_ps(rinv,
-                                       _mm_add_ps(_mm_mul_ps(dlij, t1),
-                                                  _mm_add_ps(t2, t3)));
-
-
-            t1B           = _mm_add_ps(_mm_mul_ps(half, lij2B),
-                                       _mm_mul_ps(prodB, lij3B));
-            t1B           = _mm_sub_ps(t1B,
-                                       _mm_mul_ps(onefourth,
-                                                  _mm_add_ps(_mm_mul_ps(lijB, rinvB),
-                                                             _mm_mul_ps(lij3B, rB))));
-            t2B           = _mm_mul_ps(onefourth,
-                                       _mm_add_ps(_mm_mul_ps(uijB, rinvB),
-                                                  _mm_mul_ps(uij3B, rB)));
-            t2B           = _mm_sub_ps(t2B,
-                                       _mm_add_ps(_mm_mul_ps(half, uij2B),
-                                                  _mm_mul_ps(prodB, uij3B)));
-            t3B           = _mm_mul_ps(_mm_mul_ps(onefourth, logtermB),
-                                       _mm_mul_ps(rinvB, rinvB));
-            t3B           = _mm_sub_ps(t3B,
-                                       _mm_mul_ps(_mm_mul_ps(diff2B, oneeighth),
-                                                  _mm_add_ps(one,
-                                                             _mm_mul_ps(sk2_rinvB, rinvB))));
-            t1B           = _mm_mul_ps(rinvB,
-                                       _mm_add_ps(_mm_mul_ps(dlijB, t1B),
-                                                  _mm_add_ps(t2B, t3B)));
-
-
-            dadx2         = _mm_and_ps(t1, obc_mask1);
-            dadx2B        = _mm_and_ps(t1B, obc_mask1B);
-
-            _mm_store_ps(dadx, dadx1);
-            dadx += 4;
-            _mm_store_ps(dadx, dadx2);
-            dadx += 4;
-            _mm_store_ps(dadx, dadx1B);
-            dadx += 4;
-            _mm_store_ps(dadx, dadx2B);
-            dadx += 4;
-
-        } /* end normal inner loop */
-
-        for (; k < nj1-offset; k += 4)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-            jnrC        = jjnr[k+2];
-            jnrD        = jjnr[k+3];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-            j3C         = 3*jnrC;
-            j3D         = 3*jnrD;
-
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3A, x+j3B, x+j3C, x+j3D, jx, jy, jz);
-            GMX_MM_LOAD_4VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, gb_radius+jnrC, gb_radius+jnrD, raj);
-            GMX_MM_LOAD_4VALUES_PS(obc_param+jnrA, obc_param+jnrB, obc_param+jnrC, obc_param+jnrD, sk_aj);
-
-            dx    = _mm_sub_ps(ix, jx);
-            dy    = _mm_sub_ps(iy, jy);
-            dz    = _mm_sub_ps(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_ps(dx, dy, dz);
-
-            rinv        = gmx_mm_invsqrt_ps(rsq);
-            r           = _mm_mul_ps(rsq, rinv);
-
-            /* Compute raj_inv aj1-4 */
-            raj_inv     = gmx_mm_inv_ps(raj);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1            = _mm_add_ps(r, sk_aj);
-            obc_mask1     = _mm_cmplt_ps(rai, t1);
-
-            if (_mm_movemask_ps(obc_mask1))
-            {
-                /* If any of the elements has rai<dr+sk, this is executed */
-                t2            = _mm_sub_ps(r, sk_aj);
-                t3            = _mm_sub_ps(sk_aj, r);
-
-                obc_mask2     = _mm_cmplt_ps(rai, t2);
-                obc_mask3     = _mm_cmplt_ps(rai, t3);
-
-                uij           = gmx_mm_inv_ps(t1);
-                lij           = _mm_or_ps(   _mm_and_ps(obc_mask2, gmx_mm_inv_ps(t2)),
-                                             _mm_andnot_ps(obc_mask2, rai_inv));
-                dlij          = _mm_and_ps(one, obc_mask2);
-                uij2          = _mm_mul_ps(uij, uij);
-                uij3          = _mm_mul_ps(uij2, uij);
-                lij2          = _mm_mul_ps(lij, lij);
-                lij3          = _mm_mul_ps(lij2, lij);
-                diff2         = _mm_sub_ps(uij2, lij2);
-                lij_inv       = gmx_mm_invsqrt_ps(lij2);
-                sk2_aj        = _mm_mul_ps(sk_aj, sk_aj);
-                sk2_rinv      = _mm_mul_ps(sk2_aj, rinv);
-                prod          = _mm_mul_ps(onefourth, sk2_rinv);
-                logterm       = gmx_mm_log_ps(_mm_mul_ps(uij, lij_inv));
-                t1            = _mm_sub_ps(lij, uij);
-                t2            = _mm_mul_ps(diff2,
-                                           _mm_sub_ps(_mm_mul_ps(onefourth, r),
-                                                      prod));
-                t3            = _mm_mul_ps(half, _mm_mul_ps(rinv, logterm));
-                t1            = _mm_add_ps(t1, _mm_add_ps(t2, t3));
-                t4            = _mm_mul_ps(two, _mm_sub_ps(rai_inv, lij));
-                t4            = _mm_and_ps(t4, obc_mask3);
-                t1            = _mm_mul_ps(half, _mm_add_ps(t1, t4));
-                sum_ai        = _mm_add_ps(sum_ai, _mm_and_ps(t1, obc_mask1));
-                t1            = _mm_add_ps(_mm_mul_ps(half, lij2),
-                                           _mm_mul_ps(prod, lij3));
-                t1            = _mm_sub_ps(t1,
-                                           _mm_mul_ps(onefourth,
-                                                      _mm_add_ps(_mm_mul_ps(lij, rinv),
-                                                                 _mm_mul_ps(lij3, r))));
-                t2            = _mm_mul_ps(onefourth,
-                                           _mm_add_ps(_mm_mul_ps(uij, rinv),
-                                                      _mm_mul_ps(uij3, r)));
-                t2            = _mm_sub_ps(t2,
-                                           _mm_add_ps(_mm_mul_ps(half, uij2),
-                                                      _mm_mul_ps(prod, uij3)));
-                t3            = _mm_mul_ps(_mm_mul_ps(onefourth, logterm),
-                                           _mm_mul_ps(rinv, rinv));
-                t3            = _mm_sub_ps(t3,
-                                           _mm_mul_ps(_mm_mul_ps(diff2, oneeighth),
-                                                      _mm_add_ps(one,
-                                                                 _mm_mul_ps(sk2_rinv, rinv))));
-                t1            = _mm_mul_ps(rinv,
-                                           _mm_add_ps(_mm_mul_ps(dlij, t1),
-                                                      _mm_add_ps(t2, t3)));
-
-                dadx1         = _mm_and_ps(t1, obc_mask1);
-            }
-            else
-            {
-                dadx1         = _mm_setzero_ps();
-            }
-
-            /* Evaluate influence of atom ai -> aj */
-            t1            = _mm_add_ps(r, sk_ai);
-            obc_mask1     = _mm_cmplt_ps(raj, t1);
-
-            if (_mm_movemask_ps(obc_mask1))
-            {
-                t2            = _mm_sub_ps(r, sk_ai);
-                t3            = _mm_sub_ps(sk_ai, r);
-                obc_mask2     = _mm_cmplt_ps(raj, t2);
-                obc_mask3     = _mm_cmplt_ps(raj, t3);
-
-                uij           = gmx_mm_inv_ps(t1);
-                lij           = _mm_or_ps(   _mm_and_ps(obc_mask2, gmx_mm_inv_ps(t2)),
-                                             _mm_andnot_ps(obc_mask2, raj_inv));
-                dlij          = _mm_and_ps(one, obc_mask2);
-                uij2          = _mm_mul_ps(uij, uij);
-                uij3          = _mm_mul_ps(uij2, uij);
-                lij2          = _mm_mul_ps(lij, lij);
-                lij3          = _mm_mul_ps(lij2, lij);
-                diff2         = _mm_sub_ps(uij2, lij2);
-                lij_inv       = gmx_mm_invsqrt_ps(lij2);
-                sk2_rinv      = _mm_mul_ps(sk2_ai, rinv);
-                prod          = _mm_mul_ps(onefourth, sk2_rinv);
-                logterm       = gmx_mm_log_ps(_mm_mul_ps(uij, lij_inv));
-                t1            = _mm_sub_ps(lij, uij);
-                t2            = _mm_mul_ps(diff2,
-                                           _mm_sub_ps(_mm_mul_ps(onefourth, r),
-                                                      prod));
-                t3            = _mm_mul_ps(half, _mm_mul_ps(rinv, logterm));
-                t1            = _mm_add_ps(t1, _mm_add_ps(t2, t3));
-                t4            = _mm_mul_ps(two, _mm_sub_ps(raj_inv, lij));
-                t4            = _mm_and_ps(t4, obc_mask3);
-                t1            = _mm_mul_ps(half, _mm_add_ps(t1, t4));
-
-                GMX_MM_INCREMENT_4VALUES_PS(work+jnrA, work+jnrB, work+jnrC, work+jnrD, _mm_and_ps(t1, obc_mask1));
-
-                t1            = _mm_add_ps(_mm_mul_ps(half, lij2),
-                                           _mm_mul_ps(prod, lij3));
-                t1            = _mm_sub_ps(t1,
-                                           _mm_mul_ps(onefourth,
-                                                      _mm_add_ps(_mm_mul_ps(lij, rinv),
-                                                                 _mm_mul_ps(lij3, r))));
-                t2            = _mm_mul_ps(onefourth,
-                                           _mm_add_ps(_mm_mul_ps(uij, rinv),
-                                                      _mm_mul_ps(uij3, r)));
-                t2            = _mm_sub_ps(t2,
-                                           _mm_add_ps(_mm_mul_ps(half, uij2),
-                                                      _mm_mul_ps(prod, uij3)));
-                t3            = _mm_mul_ps(_mm_mul_ps(onefourth, logterm),
-                                           _mm_mul_ps(rinv, rinv));
-                t3            = _mm_sub_ps(t3,
-                                           _mm_mul_ps(_mm_mul_ps(diff2, oneeighth),
-                                                      _mm_add_ps(one,
-                                                                 _mm_mul_ps(sk2_rinv, rinv))));
-                t1            = _mm_mul_ps(rinv,
-                                           _mm_add_ps(_mm_mul_ps(dlij, t1),
-                                                      _mm_add_ps(t2, t3)));
-                dadx2         = _mm_and_ps(t1, obc_mask1);
-            }
-            else
-            {
-                dadx2         = _mm_setzero_ps();
-            }
-
-            _mm_store_ps(dadx, dadx1);
-            dadx += 4;
-            _mm_store_ps(dadx, dadx2);
-            dadx += 4;
-        } /* end normal inner loop */
-
-        if (offset != 0)
-        {
-            if (offset == 1)
-            {
-                jnrA        = jjnr[k];
-                j3A         = 3*jnrA;
-                GMX_MM_LOAD_1RVEC_1POINTER_PS(x+j3A, jx, jy, jz);
-                GMX_MM_LOAD_1VALUE_PS(gb_radius+jnrA, raj);
-                GMX_MM_LOAD_1VALUE_PS(obc_param+jnrA, sk_aj);
-                mask        = mask1;
-            }
-            else if (offset == 2)
-            {
-                jnrA        = jjnr[k];
-                jnrB        = jjnr[k+1];
-                j3A         = 3*jnrA;
-                j3B         = 3*jnrB;
-                GMX_MM_LOAD_1RVEC_2POINTERS_PS(x+j3A, x+j3B, jx, jy, jz);
-                GMX_MM_LOAD_2VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, raj);
-                GMX_MM_LOAD_2VALUES_PS(obc_param+jnrA, obc_param+jnrB, sk_aj);
-                mask        = mask2;
-            }
-            else
-            {
-                /* offset must be 3 */
-                jnrA        = jjnr[k];
-                jnrB        = jjnr[k+1];
-                jnrC        = jjnr[k+2];
-                j3A         = 3*jnrA;
-                j3B         = 3*jnrB;
-                j3C         = 3*jnrC;
-                GMX_MM_LOAD_1RVEC_3POINTERS_PS(x+j3A, x+j3B, x+j3C, jx, jy, jz);
-                GMX_MM_LOAD_3VALUES_PS(gb_radius+jnrA, gb_radius+jnrB, gb_radius+jnrC, raj);
-                GMX_MM_LOAD_3VALUES_PS(obc_param+jnrA, obc_param+jnrB, obc_param+jnrC, sk_aj);
-                mask        = mask3;
-            }
-
-            dx    = _mm_sub_ps(ix, jx);
-            dy    = _mm_sub_ps(iy, jy);
-            dz    = _mm_sub_ps(iz, jz);
-
-            rsq         = gmx_mm_calc_rsq_ps(dx, dy, dz);
-
-            rinv        = gmx_mm_invsqrt_ps(rsq);
-            r           = _mm_mul_ps(rsq, rinv);
-
-            /* Compute raj_inv aj1-4 */
-            raj_inv     = gmx_mm_inv_ps(raj);
-
-            /* Evaluate influence of atom aj -> ai */
-            t1            = _mm_add_ps(r, sk_aj);
-            obc_mask1     = _mm_cmplt_ps(rai, t1);
-            obc_mask1     = _mm_and_ps(obc_mask1, mask);
-
-            if (_mm_movemask_ps(obc_mask1))
-            {
-                t2            = _mm_sub_ps(r, sk_aj);
-                t3            = _mm_sub_ps(sk_aj, r);
-                obc_mask2     = _mm_cmplt_ps(rai, t2);
-                obc_mask3     = _mm_cmplt_ps(rai, t3);
-
-                uij           = gmx_mm_inv_ps(t1);
-                lij           = _mm_or_ps(   _mm_and_ps(obc_mask2, gmx_mm_inv_ps(t2)),
-                                             _mm_andnot_ps(obc_mask2, rai_inv));
-                dlij           = _mm_and_ps(one, obc_mask2);
-                uij2           = _mm_mul_ps(uij, uij);
-                uij3           = _mm_mul_ps(uij2, uij);
-                lij2           = _mm_mul_ps(lij, lij);
-                lij3           = _mm_mul_ps(lij2, lij);
-                diff2          = _mm_sub_ps(uij2, lij2);
-                lij_inv        = gmx_mm_invsqrt_ps(lij2);
-                sk2_aj         = _mm_mul_ps(sk_aj, sk_aj);
-                sk2_rinv       = _mm_mul_ps(sk2_aj, rinv);
-                prod           = _mm_mul_ps(onefourth, sk2_rinv);
-                logterm        = gmx_mm_log_ps(_mm_mul_ps(uij, lij_inv));
-                t1             = _mm_sub_ps(lij, uij);
-                t2             = _mm_mul_ps(diff2,
-                                            _mm_sub_ps(_mm_mul_ps(onefourth, r),
-                                                       prod));
-                t3            = _mm_mul_ps(half, _mm_mul_ps(rinv, logterm));
-                t1            = _mm_add_ps(t1, _mm_add_ps(t2, t3));
-                t4            = _mm_mul_ps(two, _mm_sub_ps(rai_inv, lij));
-                t4            = _mm_and_ps(t4, obc_mask3);
-                t1            = _mm_mul_ps(half, _mm_add_ps(t1, t4));
-                sum_ai        = _mm_add_ps(sum_ai, _mm_and_ps(t1, obc_mask1));
-                t1            = _mm_add_ps(_mm_mul_ps(half, lij2),
-                                           _mm_mul_ps(prod, lij3));
-                t1            = _mm_sub_ps(t1,
-                                           _mm_mul_ps(onefourth,
-                                                      _mm_add_ps(_mm_mul_ps(lij, rinv),
-                                                                 _mm_mul_ps(lij3, r))));
-                t2            = _mm_mul_ps(onefourth,
-                                           _mm_add_ps(_mm_mul_ps(uij, rinv),
-                                                      _mm_mul_ps(uij3, r)));
-                t2            = _mm_sub_ps(t2,
-                                           _mm_add_ps(_mm_mul_ps(half, uij2),
-                                                      _mm_mul_ps(prod, uij3)));
-                t3            = _mm_mul_ps(_mm_mul_ps(onefourth, logterm),
-                                           _mm_mul_ps(rinv, rinv));
-                t3            = _mm_sub_ps(t3,
-                                           _mm_mul_ps(_mm_mul_ps(diff2, oneeighth),
-                                                      _mm_add_ps(one,
-                                                                 _mm_mul_ps(sk2_rinv, rinv))));
-                t1            = _mm_mul_ps(rinv,
-                                           _mm_add_ps(_mm_mul_ps(dlij, t1),
-                                                      _mm_add_ps(t2, t3)));
-                dadx1         = _mm_and_ps(t1, obc_mask1);
-            }
-            else
-            {
-                dadx1         = _mm_setzero_ps();
-            }
-
-            /* Evaluate influence of atom ai -> aj */
-            t1            = _mm_add_ps(r, sk_ai);
-            obc_mask1     = _mm_cmplt_ps(raj, t1);
-            obc_mask1     = _mm_and_ps(obc_mask1, mask);
-
-            if (_mm_movemask_ps(obc_mask1))
-            {
-                t2            = _mm_sub_ps(r, sk_ai);
-                t3            = _mm_sub_ps(sk_ai, r);
-                obc_mask2     = _mm_cmplt_ps(raj, t2);
-                obc_mask3     = _mm_cmplt_ps(raj, t3);
-
-                uij           = gmx_mm_inv_ps(t1);
-                lij           = _mm_or_ps(_mm_and_ps(obc_mask2, gmx_mm_inv_ps(t2)),
-                                          _mm_andnot_ps(obc_mask2, raj_inv));
-                dlij          = _mm_and_ps(one, obc_mask2);
-                uij2          = _mm_mul_ps(uij, uij);
-                uij3          = _mm_mul_ps(uij2, uij);
-                lij2          = _mm_mul_ps(lij, lij);
-                lij3          = _mm_mul_ps(lij2, lij);
-                diff2         = _mm_sub_ps(uij2, lij2);
-                lij_inv       = gmx_mm_invsqrt_ps(lij2);
-                sk2_rinv      = _mm_mul_ps(sk2_ai, rinv);
-                prod          = _mm_mul_ps(onefourth, sk2_rinv);
-                logterm       = gmx_mm_log_ps(_mm_mul_ps(uij, lij_inv));
-                t1            = _mm_sub_ps(lij, uij);
-                t2            = _mm_mul_ps(diff2,
-                                           _mm_sub_ps(_mm_mul_ps(onefourth, r),
-                                                      prod));
-                t3            = _mm_mul_ps(half, _mm_mul_ps(rinv, logterm));
-                t1            = _mm_add_ps(t1, _mm_add_ps(t2, t3));
-                t4            = _mm_mul_ps(two, _mm_sub_ps(raj_inv, lij));
-                t4            = _mm_and_ps(t4, obc_mask3);
-                t1            = _mm_mul_ps(half, _mm_add_ps(t1, t4));
-
-                tmp           = _mm_and_ps(t1, obc_mask1);
-
-                t1            = _mm_add_ps(_mm_mul_ps(half, lij2),
-                                           _mm_mul_ps(prod, lij3));
-                t1            = _mm_sub_ps(t1,
-                                           _mm_mul_ps(onefourth,
-                                                      _mm_add_ps(_mm_mul_ps(lij, rinv),
-                                                                 _mm_mul_ps(lij3, r))));
-                t2            = _mm_mul_ps(onefourth,
-                                           _mm_add_ps(_mm_mul_ps(uij, rinv),
-                                                      _mm_mul_ps(uij3, r)));
-                t2            = _mm_sub_ps(t2,
-                                           _mm_add_ps(_mm_mul_ps(half, uij2),
-                                                      _mm_mul_ps(prod, uij3)));
-                t3            = _mm_mul_ps(_mm_mul_ps(onefourth, logterm),
-                                           _mm_mul_ps(rinv, rinv));
-                t3            = _mm_sub_ps(t3,
-                                           _mm_mul_ps(_mm_mul_ps(diff2, oneeighth),
-                                                      _mm_add_ps(one,
-                                                                 _mm_mul_ps(sk2_rinv, rinv))));
-                t1            = _mm_mul_ps(rinv,
-                                           _mm_add_ps(_mm_mul_ps(dlij, t1),
-                                                      _mm_add_ps(t2, t3)));
-                dadx2         = _mm_and_ps(t1, obc_mask1);
-            }
-            else
-            {
-                dadx2         = _mm_setzero_ps();
-                tmp           = _mm_setzero_ps();
-            }
-
-            _mm_store_ps(dadx, dadx1);
-            dadx += 4;
-            _mm_store_ps(dadx, dadx2);
-            dadx += 4;
-
-            if (offset == 1)
-            {
-                GMX_MM_INCREMENT_1VALUE_PS(work+jnrA, tmp);
-            }
-            else if (offset == 2)
-            {
-                GMX_MM_INCREMENT_2VALUES_PS(work+jnrA, work+jnrB, tmp);
-            }
-            else
-            {
-                /* offset must be 3 */
-                GMX_MM_INCREMENT_3VALUES_PS(work+jnrA, work+jnrB, work+jnrC, tmp);
-            }
-
-        }
-        GMX_MM_UPDATE_1POT_PS(sum_ai, work+ii);
-
-    }
-
-    /* Parallel summations */
-    if (DOMAINDECOMP(cr))
-    {
-        dd_atom_sum_real(cr->dd, work);
-    }
-
-    if (gb_algorithm == egbHCT)
-    {
-        /* HCT */
-        for (i = 0; i < fr->natoms_force; i++) /* PELA born->nr */
-        {
-            if (born->use[i] != 0)
-            {
-                rr      = top->atomtypes.gb_radius[md->typeA[i]]-doffset;
-                sum     = 1.0/rr - work[i];
-                min_rad = rr + doffset;
-                rad     = 1.0/sum;
-
-                born->bRad[i]   = rad > min_rad ? rad : min_rad;
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-            }
-        }
-
-        /* Extra communication required for DD */
-        if (DOMAINDECOMP(cr))
-        {
-            dd_atom_spread_real(cr->dd, born->bRad);
-            dd_atom_spread_real(cr->dd, fr->invsqrta);
-        }
-    }
-    else
-    {
-        /* OBC */
-        for (i = 0; i < fr->natoms_force; i++) /* PELA born->nr */
-        {
-            if (born->use[i] != 0)
-            {
-                rr      = top->atomtypes.gb_radius[md->typeA[i]];
-                rr_inv2 = 1.0/rr;
-                rr      = rr-doffset;
-                rr_inv  = 1.0/rr;
-                sum     = rr * work[i];
-                sum2    = sum  * sum;
-                sum3    = sum2 * sum;
-
-                tsum          = tanh(born->obc_alpha*sum-born->obc_beta*sum2+born->obc_gamma*sum3);
-                born->bRad[i] = rr_inv - tsum*rr_inv2;
-                born->bRad[i] = 1.0 / born->bRad[i];
-
-                fr->invsqrta[i] = gmx_invsqrt(born->bRad[i]);
-
-                tchain         = rr * (born->obc_alpha-2*born->obc_beta*sum+3*born->obc_gamma*sum2);
-                born->drobc[i] = (1.0-tsum*tsum)*tchain*rr_inv2;
-            }
-        }
-        /* Extra (local) communication required for DD */
-        if (DOMAINDECOMP(cr))
-        {
-            dd_atom_spread_real(cr->dd, born->bRad);
-            dd_atom_spread_real(cr->dd, fr->invsqrta);
-            dd_atom_spread_real(cr->dd, born->drobc);
-        }
-    }
-
-
-
-    return 0;
-}
-
-
-
-float calc_gb_chainrule_sse2_single(int natoms, t_nblist *nl, float *dadx, float *dvda,
-                                    float *x, float *f, float *fshift, float *shiftvec,
-                                    int gb_algorithm, gmx_genborn_t *born, t_mdatoms *md)
-{
-    int          i, k, n, ii, jnr, ii3, is3, nj0, nj1, offset, n0, n1;
-    int          jnrA, jnrB, jnrC, jnrD;
-    int          j3A, j3B, j3C, j3D;
-    int          jnrE, jnrF, jnrG, jnrH;
-    int          j3E, j3F, j3G, j3H;
-    int       *  jjnr;
-
-    float        rbi, shX, shY, shZ;
-    float       *rb;
-
-    __m128       ix, iy, iz;
-    __m128       jx, jy, jz;
-    __m128       jxB, jyB, jzB;
-    __m128       fix, fiy, fiz;
-    __m128       dx, dy, dz;
-    __m128       tx, ty, tz;
-    __m128       dxB, dyB, dzB;
-    __m128       txB, tyB, tzB;
-
-    __m128       rbai, rbaj, rbajB, f_gb, f_gb_ai, f_gbB, f_gb_aiB;
-    __m128       xmm1, xmm2, xmm3;
-
-    const __m128 two = _mm_set1_ps(2.0f);
-
-    rb     = born->work;
-
-    jjnr   = nl->jjnr;
-
-    /* Loop to get the proper form for the Born radius term, sse style */
-    offset = natoms%4;
-
-    n0 = 0;
-    n1 = natoms;
-
-    if (gb_algorithm == egbSTILL)
-    {
-        for (i = n0; i < n1; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = (2 * rbi * rbi * dvda[i])/ONE_4PI_EPS0;
-        }
-    }
-    else if (gb_algorithm == egbHCT)
-    {
-        for (i = n0; i < n1; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = rbi * rbi * dvda[i];
-        }
-    }
-    else if (gb_algorithm == egbOBC)
-    {
-        for (i = n0; i < n1; i++)
-        {
-            rbi   = born->bRad[i];
-            rb[i] = rbi * rbi * born->drobc[i] * dvda[i];
-        }
-    }
-
-    jz = _mm_setzero_ps();
-
-    n = j3A = j3B = j3C = j3D = 0;
-
-    for (i = 0; i < nl->nri; i++)
-    {
-        ii     = nl->iinr[i];
-        ii3    = ii*3;
-        is3    = 3*nl->shift[i];
-        shX    = shiftvec[is3];
-        shY    = shiftvec[is3+1];
-        shZ    = shiftvec[is3+2];
-        nj0    = nl->jindex[i];
-        nj1    = nl->jindex[i+1];
-
-        ix     = _mm_set1_ps(shX+x[ii3+0]);
-        iy     = _mm_set1_ps(shY+x[ii3+1]);
-        iz     = _mm_set1_ps(shZ+x[ii3+2]);
-
-        offset = (nj1-nj0)%4;
-
-        rbai   = _mm_load1_ps(rb+ii);
-        fix    = _mm_setzero_ps();
-        fiy    = _mm_setzero_ps();
-        fiz    = _mm_setzero_ps();
-
-
-        for (k = nj0; k < nj1-offset; k += 4)
-        {
-            jnrA        = jjnr[k];
-            jnrB        = jjnr[k+1];
-            jnrC        = jjnr[k+2];
-            jnrD        = jjnr[k+3];
-
-            j3A         = 3*jnrA;
-            j3B         = 3*jnrB;
-            j3C         = 3*jnrC;
-            j3D         = 3*jnrD;
-
-            GMX_MM_LOAD_1RVEC_4POINTERS_PS(x+j3A, x+j3B, x+j3C, x+j3D, jx, jy, jz);
-
-            dx          = _mm_sub_ps(ix, jx);
-            dy          = _mm_sub_ps(iy, jy);
-            dz          = _mm_sub_ps(iz, jz);
-
-            GMX_MM_LOAD_4VALUES_PS(rb+jnrA, rb+jnrB, rb+jnrC, rb+jnrD, rbaj);
-
-            /* load chain rule terms for j1-4 */
-            f_gb        = _mm_load_ps(dadx);
-            dadx       += 4;
-            f_gb_ai     = _mm_load_ps(dadx);
-            dadx       += 4;
-
-            /* calculate scalar force */
-            f_gb    = _mm_mul_ps(f_gb, rbai);
-            f_gb_ai = _mm_mul_ps(f_gb_ai, rbaj);
-            f_gb    = _mm_add_ps(f_gb, f_gb_ai);
-
-            tx     = _mm_mul_ps(f_gb, dx);
-            ty     = _mm_mul_ps(f_gb, dy);
-            tz     = _mm_mul_ps(f_gb, dz);
-
-            fix    = _mm_add_ps(fix, tx);
-            fiy    = _mm_add_ps(fiy, ty);
-            fiz    = _mm_add_ps(fiz, tz);
-
-            GMX_MM_DECREMENT_1RVEC_4POINTERS_PS(f+j3A, f+j3B, f+j3C, f+j3D, tx, ty, tz);
-        }
-
-        /*deal with odd elements */
-        if (offset != 0)
-        {
-            if (offset == 1)
-            {
-                jnrA        = jjnr[k];
-                j3A         = 3*jnrA;
-                GMX_MM_LOAD_1RVEC_1POINTER_PS(x+j3A, jx, jy, jz);
-                GMX_MM_LOAD_1VALUE_PS(rb+jnrA, rbaj);
-            }
-            else if (offset == 2)
-            {
-                jnrA        = jjnr[k];
-                jnrB        = jjnr[k+1];
-                j3A         = 3*jnrA;
-                j3B         = 3*jnrB;
-                GMX_MM_LOAD_1RVEC_2POINTERS_PS(x+j3A, x+j3B, jx, jy, jz);
-                GMX_MM_LOAD_2VALUES_PS(rb+jnrA, rb+jnrB, rbaj);
-            }
-            else
-            {
-                /* offset must be 3 */
-                jnrA        = jjnr[k];
-                jnrB        = jjnr[k+1];
-                jnrC        = jjnr[k+2];
-                j3A         = 3*jnrA;
-                j3B         = 3*jnrB;
-                j3C         = 3*jnrC;
-                GMX_MM_LOAD_1RVEC_3POINTERS_PS(x+j3A, x+j3B, x+j3C, jx, jy, jz);
-                GMX_MM_LOAD_3VALUES_PS(rb+jnrA, rb+jnrB, rb+jnrC, rbaj);
-            }
-
-            dx          = _mm_sub_ps(ix, jx);
-            dy          = _mm_sub_ps(iy, jy);
-            dz          = _mm_sub_ps(iz, jz);
-
-            /* load chain rule terms for j1-4 */
-            f_gb        = _mm_load_ps(dadx);
-            dadx       += 4;
-            f_gb_ai     = _mm_load_ps(dadx);
-            dadx       += 4;
-
-            /* calculate scalar force */
-            f_gb    = _mm_mul_ps(f_gb, rbai);
-            f_gb_ai = _mm_mul_ps(f_gb_ai, rbaj);
-            f_gb    = _mm_add_ps(f_gb, f_gb_ai);
-
-            tx     = _mm_mul_ps(f_gb, dx);
-            ty     = _mm_mul_ps(f_gb, dy);
-            tz     = _mm_mul_ps(f_gb, dz);
-
-            fix    = _mm_add_ps(fix, tx);
-            fiy    = _mm_add_ps(fiy, ty);
-            fiz    = _mm_add_ps(fiz, tz);
-
-            if (offset == 1)
-            {
-                GMX_MM_DECREMENT_1RVEC_1POINTER_PS(f+j3A, tx, ty, tz);
-            }
-            else if (offset == 2)
-            {
-                GMX_MM_DECREMENT_1RVEC_2POINTERS_PS(f+j3A, f+j3B, tx, ty, tz);
-            }
-            else
-            {
-                /* offset must be 3 */
-                GMX_MM_DECREMENT_1RVEC_3POINTERS_PS(f+j3A, f+j3B, f+j3C, tx, ty, tz);
-            }
-        }
-
-        /* fix/fiy/fiz now contain four partial force terms, that all should be
-         * added to the i particle forces and shift forces.
-         */
-        gmx_mm_update_iforce_1atom_ps(&fix, &fiy, &fiz, f+ii3, fshift+is3);
-    }
-
-    return 0;
-}
-
-
-#else
-/* keep compiler happy */
-int genborn_sse_dummy;
-
-#endif /* SSE intrinsics available */
index e351275864fe06b0e57b0059d7084235b07b6086..c2a596d9b26d8ff5dafeee428a0d97b971d72f07 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,7 +43,6 @@
 #include <string.h>
 
 #include "gromacs/fileio/enxio.h"
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/mdebin.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/utility/fatalerror.h"
index b7740bfcaf0bfdb19cbdef72a32a2c7053e54310..06ba18d562736b4f509534127c72c161eeea4c86 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2013,2014, by the GROMACS development team, led by
+# Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -80,7 +80,7 @@ import collections # Requires Python 2.7
 sys.path.append('../../../../../admin')
 from copyright import create_copyright_header
 
-FileHeader = create_copyright_header('2012,2013,2014')
+FileHeader = create_copyright_header('2012,2013,2014,2015')
 FileHeader += """/*
  * Note: this file was generated by the Verlet kernel generator for
  * kernel type {0}.
index 2dbae1b8513305ad0786c17686cbd2cd75c9925e..63b73c70eebf4fea910e9bc82daaa289533b5151 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,6 +40,8 @@
  */
 #include "gmxpre.h"
 
+#include "gromacs/mdlib/nbnxn_simd.h"
+
 #define GMX_SIMD_J_UNROLL_SIZE {7}
 #include "{4}"
 
index 69872b938c20a1c7a492ba4a3a1dcb5dd54c9c8a..a43ac5cc34b1791b798e9c382ac6d39431573b33 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,6 +40,8 @@
  */
 #include "gmxpre.h"
 
+#include "gromacs/mdlib/nbnxn_simd.h"
+
 #define GMX_SIMD_J_UNROLL_SIZE {7}
 #include "{4}"
 
index 5e410cdecc4525f96fa7ab74c4a50c848b203861..2571a0534807813fdb1da1094e1a43d1f813a332 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -51,6 +51,7 @@
 #include "gromacs/legacyheaders/gmx_omp_nthreads.h"
 #include "gromacs/legacyheaders/types/force_flags.h"
 #include "gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_common.h"
+#include "gromacs/simd/simd.h"
 #include "gromacs/utility/fatalerror.h"
 
 /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels
index 22ada3b193bd4770efa13ada39efbffa3742c36e..a841aaa9e91a10c4e2c03fd90069390179681a98 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -34,7 +34,6 @@
  */
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/mdlib/nbnxn_pairlist.h"
-#include "gromacs/mdlib/nbnxn_simd.h"
 
 #ifdef __cplusplus
 extern "C" {{
similarity index 97%
rename from src/gromacs/mdlib/ns.c
rename to src/gromacs/mdlib/ns.cpp
index d6e9314fb16a70eeca45b33d9fb3774d8463a34c..e3f37fc45a6b089a0ae6715d3b82b81f0bc98023 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/legacyheaders/force.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -93,7 +97,7 @@ static gmx_bool NOTEXCL_(t_excl e[], atom_id i, atom_id j)
 static int
 round_up_to_simd_width(int length, int simd_width)
 {
-    int offset, newlength;
+    int offset;
 
     offset = (simd_width > 0) ? length % simd_width : 0;
 
@@ -132,7 +136,7 @@ static void init_nblist(FILE *log, t_nblist *nl_sr, t_nblist *nl_lr,
 {
     t_nblist *nl;
     int       homenr;
-    int       i, nn;
+    int       i;
 
     for (i = 0; (i < 2); i++)
     {
@@ -199,7 +203,6 @@ void init_neighbor_list(FILE *log, t_forcerec *fr, int homenr)
      */
     int        maxsr, maxsr_wat, maxlr, maxlr_wat;
     int        ielec, ivdw, ielecmod, ivdwmod, type;
-    int        solvent;
     int        igeometry_def, igeometry_w, igeometry_ww;
     int        i;
     gmx_bool   bElecAndVdwSwitchDiffers;
@@ -217,11 +220,11 @@ void init_neighbor_list(FILE *log, t_forcerec *fr, int homenr)
      * all the nlist arrays many times in a row.
      * The numbers seem very accurate, but they are uncritical.
      */
-    maxsr_wat = min(fr->nWatMol, (homenr+2)/3);
+    maxsr_wat = std::min(fr->nWatMol, (homenr+2)/3);
     if (fr->bTwinRange)
     {
         maxlr     = 50;
-        maxlr_wat = min(maxsr_wat, maxlr);
+        maxlr_wat = std::min(maxsr_wat, maxlr);
     }
     else
     {
@@ -363,9 +366,7 @@ static void reset_neighbor_lists(t_forcerec *fr, gmx_bool bResetSR, gmx_bool bRe
 
 static gmx_inline void new_i_nblist(t_nblist *nlist, atom_id i_atom, int shift, int gid)
 {
-    int    i, k, nri, nshift;
-
-    nri = nlist->nri;
+    int    nri = nlist->nri;
 
     /* Check whether we have to increase the i counter */
     if ((nri == -1) ||
@@ -594,14 +595,14 @@ put_in_list_at(gmx_bool              bHaveVdW[],
     t_nblist  *   vdwc_ww    = NULL;
     t_nblist  *   coul_ww    = NULL;
 
-    int           i, j, jcg, igid, gid, nbl_ind, ind_ij;
+    int           i, j, jcg, igid, gid, nbl_ind;
     atom_id       jj, jj0, jj1, i_atom;
-    int           i0, nicg, len;
+    int           i0, nicg;
 
     int          *cginfo;
     int          *type, *typeB;
     real         *charge, *chargeB;
-    real          qi, qiB, qq, rlj;
+    real          qi, qiB;
     gmx_bool      bFreeEnergy, bFree, bFreeJ, bNotEx, *bPert;
     gmx_bool      bDoVdW_i, bDoCoul_i, bDoCoul_i_sol;
     int           iwater, jwater;
@@ -1094,7 +1095,7 @@ put_in_list_adress(gmx_bool              bHaveVdW[],
                    gmx_bool              bLR,
                    gmx_bool              bDoVdW,
                    gmx_bool              bDoCoul,
-                   int                   solvent_opt)
+                   int       gmx_unused  solvent_opt)
 {
     /* The a[] index has been removed,
      * to put it back in i_atom should be a[i0] and jj should be a[jj].
@@ -1105,33 +1106,26 @@ put_in_list_adress(gmx_bool              bHaveVdW[],
     t_nblist  *   vdwc_adress  = NULL;
     t_nblist  *   vdw_adress   = NULL;
     t_nblist  *   coul_adress  = NULL;
-    t_nblist  *   vdwc_ww      = NULL;
-    t_nblist  *   coul_ww      = NULL;
 
     int           i, j, jcg, igid, gid, nbl_ind, nbl_ind_adress;
     atom_id       jj, jj0, jj1, i_atom;
-    int           i0, nicg, len;
+    int           i0, nicg;
 
     int          *cginfo;
-    int          *type, *typeB;
-    real         *charge, *chargeB;
+    int          *type;
+    real         *charge;
     real         *wf;
-    real          qi, qiB, qq, rlj;
-    gmx_bool      bFreeEnergy, bFree, bFreeJ, bNotEx, *bPert;
-    gmx_bool      bDoVdW_i, bDoCoul_i, bDoCoul_i_sol;
+    real          qi;
+    gmx_bool      bNotEx;
+    gmx_bool      bDoVdW_i, bDoCoul_i;
     gmx_bool      b_hybrid;
-    gmx_bool      j_all_atom;
-    int           iwater, jwater;
     t_nblist     *nlist, *nlist_adress;
     gmx_bool      bEnergyGroupCG;
 
     /* Copy some pointers */
     cginfo  = fr->cginfo;
     charge  = md->chargeA;
-    chargeB = md->chargeB;
     type    = md->typeA;
-    typeB   = md->typeB;
-    bPert   = md->bPerturbed;
     wf      = md->wf;
 
     /* Get atom range */
@@ -1141,8 +1135,6 @@ put_in_list_adress(gmx_bool              bHaveVdW[],
     /* Get the i charge group info */
     igid   = GET_CGINFO_GID(cginfo[icg]);
 
-    iwater = (solvent_opt != esolNO) ? GET_CGINFO_SOLOPT(cginfo[icg]) : esolNO;
-
     if (md->nPerturbed)
     {
         gmx_fatal(FARGS, "AdResS does not support free energy pertubation\n");
@@ -1585,18 +1577,18 @@ static real calc_image_tric(rvec xi, rvec xj, matrix box,
     /* Perform NINT operation, using trunc operation, therefore
      * we first add 2.5 then subtract 2 again
      */
-    tz  = dz*b_inv[ZZ] + h25;
+    tz  = static_cast<int>(dz*b_inv[ZZ] + h25);
     tz -= 2;
     dz -= tz*box[ZZ][ZZ];
     dy -= tz*box[ZZ][YY];
     dx -= tz*box[ZZ][XX];
 
-    ty  = dy*b_inv[YY] + h25;
+    ty  = static_cast<int>(dy*b_inv[YY] + h25);
     ty -= 2;
     dy -= ty*box[YY][YY];
     dx -= ty*box[YY][XX];
 
-    tx  = dx*b_inv[XX]+h25;
+    tx  = static_cast<int>(dx*b_inv[XX]+h25);
     tx -= 2;
     dx -= tx*box[XX][XX];
 
@@ -1625,9 +1617,9 @@ static real calc_image_rect(rvec xi, rvec xj, rvec box_size,
     /* Perform NINT operation, using trunc operation, therefore
      * we first add 1.5 then subtract 1 again
      */
-    tx = dx*b_inv[XX] + h15;
-    ty = dy*b_inv[YY] + h15;
-    tz = dz*b_inv[ZZ] + h15;
+    tx = static_cast<int>(dx*b_inv[XX] + h15);
+    ty = static_cast<int>(dy*b_inv[YY] + h15);
+    tz = static_cast<int>(dz*b_inv[ZZ] + h15);
     tx--;
     ty--;
     tz--;
@@ -1645,7 +1637,7 @@ static real calc_image_rect(rvec xi, rvec xj, rvec box_size,
     return r2;
 }
 
-static void add_simple(t_ns_buf *nsbuf, int nrj, atom_id cg_j,
+static void add_simple(t_ns_buf * nsbuf, int nrj, atom_id cg_j,
                        gmx_bool bHaveVdW[], int ngid, t_mdatoms *md,
                        int icg, int jgid, t_block *cgs, t_excl bexcl[],
                        int shift, t_forcerec *fr, put_in_list_t *put_in_list)
@@ -1673,7 +1665,6 @@ static void ns_inner_tric(rvec x[], int icg, int *i_egp_flags,
     int       j, nrj, jgid;
     int      *cginfo = fr->cginfo;
     atom_id   cg_j, *cgindex;
-    t_ns_buf *nsbuf;
 
     cgindex = cgs->index;
     shift   = CENTRAL;
@@ -1706,7 +1697,6 @@ static void ns_inner_rect(rvec x[], int icg, int *i_egp_flags,
     int       j, nrj, jgid;
     int      *cginfo = fr->cginfo;
     atom_id   cg_j, *cgindex;
-    t_ns_buf *nsbuf;
 
     cgindex = cgs->index;
     if (bBox)
@@ -1760,7 +1750,7 @@ static int ns_simple_core(t_forcerec *fr,
 {
     int          naaj, k;
     real         rlist2;
-    int          nsearch, icg, jcg, igid, i0, nri, nn;
+    int          nsearch, icg, igid, nn;
     int         *cginfo;
     t_ns_buf    *nsbuf;
     /* atom_id  *i_atoms; */
@@ -2044,8 +2034,8 @@ static void get_cutoff2(t_forcerec *fr, gmx_bool bDoLongRange,
         *rvdw2  = *rs2;
         *rcoul2 = *rs2;
     }
-    *rm2 = min(*rvdw2, *rcoul2);
-    *rl2 = max(*rvdw2, *rcoul2);
+    *rm2 = std::min(*rvdw2, *rcoul2);
+    *rl2 = std::max(*rvdw2, *rcoul2);
 }
 
 static void init_nsgrid_lists(t_forcerec *fr, int ngid, gmx_ns_t *ns)
@@ -2107,15 +2097,15 @@ static int nsgrid_core(t_commrec *cr, t_forcerec *fr,
 #endif
     int           dx0, dx1, dy0, dy1, dz0, dz1;
     int           Nx, Ny, Nz, shift = -1, j, nrj, nns, nn = -1;
-    real          gridx, gridy, gridz, grid_x, grid_y, grid_z;
+    real          gridx, gridy, gridz, grid_x, grid_y;
     real         *dcx2, *dcy2, *dcz2;
     int           zgi, ygi, xgi;
-    int           cg0, cg1, icg = -1, cgsnr, i0, igid, nri, naaj, max_jcg;
+    int           cg0, cg1, icg = -1, cgsnr, i0, igid, naaj, max_jcg;
     int           jcg0, jcg1, jjcg, cgj0, jgid;
     int          *grida, *gridnra, *gridind;
     gmx_bool      rvdw_lt_rcoul, rcoul_lt_rvdw;
-    rvec          xi, *cgcm, grid_offset;
-    real          r2, rs2, rvdw2, rcoul2, rm2, rl2, XI, YI, ZI, dcx, dcy, dcz, tmp1, tmp2;
+    rvec         *cgcm, grid_offset;
+    real          r2, rs2, rvdw2, rcoul2, rm2, rl2, XI, YI, ZI, tmp1, tmp2;
     int          *i_egp_flags;
     gmx_bool      bDomDec, bTriclinicX, bTriclinicY;
     ivec          ncpddc;
@@ -2167,7 +2157,6 @@ static int nsgrid_core(t_commrec *cr, t_forcerec *fr,
     gridz      = grid->cell_size[ZZ];
     grid_x     = 1/gridx;
     grid_y     = 1/gridy;
-    grid_z     = 1/gridz;
     copy_rvec(grid->cell_offset, grid_offset);
     copy_ivec(grid->ncpddc, ncpddc);
     dcx2       = grid->dcx2;
@@ -2213,7 +2202,7 @@ static int nsgrid_core(t_commrec *cr, t_forcerec *fr,
         else
         {
             if (d == XX &&
-                box[XX][XX] - fabs(box[YY][XX]) - fabs(box[ZZ][XX]) < sqrt(rl2))
+                box[XX][XX] - fabs(box[YY][XX]) - fabs(box[ZZ][XX]) < std::sqrt(rl2))
             {
                 shp[d] = 2;
             }
@@ -2512,7 +2501,6 @@ static int nsgrid_core(t_commrec *cr, t_forcerec *fr,
                 }
             }
         }
-        /* setexcl(nri,i_atoms,&top->atoms.excl,FALSE,bexcl); */
         setexcl(cgs->index[icg], cgs->index[icg+1], &top->excls, FALSE, bexcl);
     }
     /* No need to perform any left-over force calculations anymore (as we used to do here)
@@ -2548,7 +2536,6 @@ void init_ns(FILE *fplog, const t_commrec *cr,
 {
     int  mt, icg, nr_in_cg, maxcg, i, j, jcg, ngid, ncg;
     t_block *cgs;
-    char *ptr;
 
     /* Compute largest charge groups size (# atoms) */
     nr_in_cg = 1;
@@ -2557,7 +2544,7 @@ void init_ns(FILE *fplog, const t_commrec *cr,
         cgs = &mtop->moltype[mt].cgs;
         for (icg = 0; (icg < cgs->nr); icg++)
         {
-            nr_in_cg = max(nr_in_cg, (int)(cgs->index[icg+1]-cgs->index[icg]));
+            nr_in_cg = std::max(nr_in_cg, (int)(cgs->index[icg+1]-cgs->index[icg]));
         }
     }
 
@@ -2669,13 +2656,11 @@ int search_neighbours(FILE *log, t_forcerec *fr,
 {
     t_block  *cgs = &(top->cgs);
     rvec     box_size, grid_x0, grid_x1;
-    int      i, j, m, ngid;
+    int      m, ngid;
     real     min_size, grid_dens;
     int      nsearch;
     gmx_bool     bGrid;
-    char     *ptr;
-    gmx_bool     *i_egp_flags;
-    int      cg_start, cg_end, start, end;
+    int      start, end;
     gmx_ns_t *ns;
     t_grid   *grid;
     gmx_domdec_zones_t *dd_zones;
@@ -2700,7 +2685,7 @@ int search_neighbours(FILE *log, t_forcerec *fr,
         }
         if (!bGrid)
         {
-            min_size = min(box_size[XX], min(box_size[YY], box_size[ZZ]));
+            min_size = std::min(box_size[XX], std::min(box_size[YY], box_size[ZZ]));
             if (2*fr->rlistlong >= min_size)
             {
                 gmx_fatal(FARGS, "One of the box diagonal elements has become smaller than twice the cut-off length.");
similarity index 97%
rename from src/gromacs/mdlib/nsgrid.c
rename to src/gromacs/mdlib/nsgrid.cpp
index 5ce59e935920d4d76c69552d984931acdbb3dbe6..63649e3bee792e81ffb6af9f5954d14e7c5ef38e 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -90,7 +94,7 @@ static void calc_x_av_stddev(int n, rvec *x, rvec av, rvec stddev)
     for (d = 0; d < DIM; d++)
     {
         av[d]     = s1[d];
-        stddev[d] = sqrt(s2[d] - s1[d]*s1[d]);
+        stddev[d] = std::sqrt(s2[d] - s1[d]*s1[d]);
     }
 }
 
@@ -202,7 +206,6 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis
 {
     int      i, j;
     gmx_bool bDD, bDDRect;
-    rvec     av, stddev;
     rvec     izones_size;
     real     inv_r_ideal, size, add_tric, radd;
 
@@ -218,7 +221,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis
     }
 
     /* Use the ideal number of cg's per cell to set the ideal cell size */
-    inv_r_ideal = pow(grid_density/grid->ncg_ideal, 1.0/3.0);
+    inv_r_ideal = std::pow((real)(grid_density/grid->ncg_ideal), (real)(1.0/3.0));
     if (rlist > 0 && inv_r_ideal*rlist < 1)
     {
         inv_r_ideal = 1/rlist;
@@ -273,8 +276,11 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis
 
             /* Check if the cell boundary in this direction is
              * perpendicular to the Cartesian axis.
+             * Since grid->npbcdim isan integer that in principle can take
+             * any value, we help the compiler avoid warnings and potentially
+             * optimize by ensuring that j < DIM here.
              */
-            for (j = i+1; j < grid->npbcdim; j++)
+            for (j = i+1; j < grid->npbcdim && j < DIM; j++)
             {
                 if (box[j][i] != 0)
                 {
@@ -357,7 +363,6 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis
 
 t_grid *init_grid(FILE *fplog, t_forcerec *fr)
 {
-    int     d, m;
     char   *ptr;
     t_grid *grid;
 
@@ -475,7 +480,6 @@ void grid_first(FILE *fplog, t_grid *grid,
                 real rlistlong, real grid_density)
 {
     int    i, m;
-    ivec   cx;
 
     set_grid_sizes(box, izones_x0, izones_x1, rlistlong, dd, ddbox, grid, grid_density);
 
@@ -495,7 +499,7 @@ void grid_first(FILE *fplog, t_grid *grid,
         }
     }
 
-    m = max(grid->n[XX], max(grid->n[YY], grid->n[ZZ]));
+    m = std::max(grid->n[XX], std::max(grid->n[YY], grid->n[ZZ]));
     if (m > grid->dc_nalloc)
     {
         /* Allocate with double the initial size for box scaling */
@@ -642,7 +646,7 @@ void fill_grid(gmx_domdec_zones_t *dd_zones,
                int cg0, int cg1, rvec cg_cm[])
 {
     int       *cell_index;
-    int        nrx, nry, nrz;
+    int        nry, nrz;
     rvec       n_box, offset;
     int        zone, ccg0, ccg1, cg, d, not_used;
     ivec       shift0, useall, b0, b1, ind;
@@ -661,7 +665,6 @@ void fill_grid(gmx_domdec_zones_t *dd_zones,
     cell_index = grid->cell_index;
 
     /* Initiate cell borders */
-    nrx = grid->n[XX];
     nry = grid->n[YY];
     nrz = grid->n[ZZ];
     for (d = 0; d < DIM; d++)
@@ -689,7 +692,7 @@ void fill_grid(gmx_domdec_zones_t *dd_zones,
         {
             for (d = 0; d < DIM; d++)
             {
-                ind[d] = (cg_cm[cg][d] - offset[d])*n_box[d];
+                ind[d] = static_cast<int>((cg_cm[cg][d] - offset[d])*n_box[d]);
                 /* With pbc we should be done here.
                  * Without pbc cg's outside the grid
                  * should be assigned to the closest grid cell.
@@ -764,7 +767,7 @@ void fill_grid(gmx_domdec_zones_t *dd_zones,
                 bUse = TRUE;
                 for (d = 0; d < DIM; d++)
                 {
-                    ind[d] = (cg_cm[cg][d] - offset[d])*n_box[d];
+                    ind[d] = static_cast<int>((cg_cm[cg][d] - offset[d])*n_box[d]);
                     /* Here we have to correct for rounding problems,
                      * as this cg_cm to cell index operation is not necessarily
                      * binary identical to the operation for the DD zone assignment
similarity index 95%
rename from src/gromacs/mdlib/qm_gamess.c
rename to src/gromacs/mdlib/qm_gamess.cpp
index d913f7f48925abd33818aa8e90317dac5d590b2a..0921efd187df45913e5229f49a8733432e4f2cdb 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "config.h"
 
-#ifdef GMX_QMMM_GAMESS
+#if GMX_QMMM_GAMESS
 
 #include <math.h>
 #include <stdio.h>
@@ -55,6 +55,7 @@
 #include "gromacs/legacyheaders/qmmm.h"
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/fatalerror.h"
 
 
 void
-F77_FUNC(inigms, IMIGMS) (void);
+    F77_FUNC(inigms, IMIGMS) (void);
 
 void
-F77_FUNC(endgms, ENDGMS) (void);
+    F77_FUNC(endgms, ENDGMS) (void);
 
 void
-F77_FUNC(grads, GRADS) (int *nrqmat, real *qmcrd, int *nrmmat, real *mmchrg,
-                        real *mmcrd, real *qmgrad, real *mmgrad, real *energy);
+    F77_FUNC(grads, GRADS) (int *nrqmat, real *qmcrd, int *nrmmat, real *mmchrg,
+                            real *mmcrd, real *qmgrad, real *mmgrad, real *energy);
 
 
 
@@ -88,7 +89,7 @@ void init_gamess(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
      * dynamics simulations. 7-6-2002 (London)
      */
     int
-        i, j, rank;
+        i, j;
     FILE
        *out;
     char
@@ -228,7 +229,7 @@ void init_gamess(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
     }
 }
 
-real call_gamess(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
+real call_gamess(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
                  rvec f[], rvec fshift[])
 {
     /* do the actual QMMM calculation using GAMESS-UK. In this
@@ -237,7 +238,7 @@ real call_gamess(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
      * gradient routines linked directly
      */
     int
-        i, j, rank;
+        i, j;
     real
         QMener = 0.0, *qmgrad, *mmgrad, *mmcrd, *qmcrd, energy;
     t_QMMMrec
similarity index 97%
rename from src/gromacs/mdlib/qm_gaussian.c
rename to src/gromacs/mdlib/qm_gaussian.cpp
index d90232c7e86a55fae13a1b0ca5d9a31f4c1fb51f..ab7e7c4c18b1436d3c7cf28878ab64dcd437356d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "config.h"
 
-#ifdef GMX_QMMM_GAUSSIAN
+#if GMX_QMMM_GAUSSIAN
 
 #include <math.h>
 #include <stdio.h>
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
-
 /* TODO: this should be made thread-safe */
 
 /* Gaussian interface routines */
 
-void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
+void init_gaussian(t_QMrec *qm)
 {
-    FILE
-       *rffile = NULL, *out = NULL;
+    FILE *out = NULL;
     ivec
-        basissets[eQMbasisNR] = {{0, 3, 0},
+          basissets[eQMbasisNR] = {{0, 3, 0},
                                  {0, 3, 0}, /*added for double sto-3g entry in names.c*/
                                  {5, 0, 0},
                                  {5, 0, 1},
@@ -81,9 +80,9 @@ void init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
                                  {1, 6, 11},
                                  {4, 6, 0}};
     char
-       *buf = NULL;
+         *buf = NULL;
     int
-        i;
+          i;
 
     /* using the ivec above to convert the basis read form the mdp file
      * in a human readable format into some numbers for the gaussian
@@ -695,8 +694,7 @@ void write_gaussian_input(int step, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm)
 
 }  /* write_gaussian_input */
 
-real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], int step,
-                          t_QMrec *qm, t_MMrec *mm)
+real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], t_QMrec *qm, t_MMrec *mm)
 {
     int
         i, j, atnum;
@@ -801,8 +799,7 @@ real read_gaussian_output(rvec QMgrad[], rvec MMgrad[], int step,
     return(QMener);
 }
 
-real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step,
-                             gmx_bool swapped, t_QMrec *qm, t_MMrec *mm)
+real read_gaussian_SH_output(rvec QMgrad[], rvec MMgrad[], int step, t_QMrec *qm, t_MMrec *mm)
 {
     int
         i;
@@ -1023,8 +1020,7 @@ void do_gaussian(int step, char *exe)
     }
 }
 
-real call_gaussian(t_commrec *cr,  t_forcerec *fr,
-                   t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
+real call_gaussian(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
 {
     /* normal gaussian jobs */
     static int
@@ -1045,7 +1041,7 @@ real call_gaussian(t_commrec *cr,  t_forcerec *fr,
 
     write_gaussian_input(step, fr, qm, mm);
     do_gaussian(step, exe);
-    QMener = read_gaussian_output(QMgrad, MMgrad, step, qm, mm);
+    QMener = read_gaussian_output(QMgrad, MMgrad, qm, mm);
     /* put the QMMM forces in the force array and to the fshift
      */
     for (i = 0; i < qm->nrQMatoms; i++)
@@ -1071,8 +1067,7 @@ real call_gaussian(t_commrec *cr,  t_forcerec *fr,
 
 } /* call_gaussian */
 
-real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
-                      rvec f[], rvec fshift[])
+real call_gaussian_SH(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
 {
     /* a gaussian call routine intended for doing diabatic surface
      * "sliding". See the manual for the theoretical background of this
@@ -1128,7 +1123,7 @@ real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
     write_gaussian_SH_input(step, swapped, fr, qm, mm);
 
     do_gaussian(step, exe);
-    QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, swapped, qm, mm);
+    QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
 
     /* check for a surface hop. Only possible if we were already state
      * averaging.
@@ -1149,7 +1144,7 @@ real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
         {
             write_gaussian_SH_input(step, swapped, fr, qm, mm);
             do_gaussian(step, exe);
-            QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, swapped, qm, mm);
+            QMener = read_gaussian_SH_output(QMgrad, MMgrad, step, qm, mm);
         }
     }
     /* add the QMMM forces to the gmx force array and fshift
similarity index 91%
rename from src/gromacs/mdlib/qm_mopac.c
rename to src/gromacs/mdlib/qm_mopac.cpp
index 6eb689cd3ea5d5f4002da26408af314e9154625c..16b2d38f03c9f1f5c0b9f4ba7115046faf3f906a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "config.h"
 
-#ifdef GMX_QMMM_MOPAC
+#if GMX_QMMM_MOPAC
 
 #include <math.h>
 #include <stdio.h>
 
 /* mopac interface routines */
 void
-F77_FUNC(domldt, DOMLDT) (int *nrqmat, int labels[], char keywords[]);
+    F77_FUNC(domldt, DOMLDT) (int *nrqmat, int labels[], char keywords[]);
 
 void
-F77_FUNC(domop, DOMOP) (int *nrqmat, double qmcrd[], int *nrmmat,
-                        double mmchrg[], double mmcrd[], double qmgrad[],
-                        double mmgrad[], double *energy, double qmcharges[]);
+    F77_FUNC(domop, DOMOP) (int *nrqmat, double qmcrd[], int *nrmmat,
+                            double mmchrg[], double mmcrd[], double qmgrad[],
+                            double mmgrad[], double *energy, double qmcharges[]);
 
 
 
-void init_mopac(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
+void init_mopac(t_QMrec *qm)
 {
     /* initializes the mopac routines ans sets up the semiempirical
      * computation by calling moldat(). The inline mopac routines can
@@ -104,8 +104,7 @@ void init_mopac(t_commrec *cr, t_QMrec *qm, t_MMrec *mm)
 
 } /* init_mopac */
 
-real call_mopac(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
-                rvec f[], rvec fshift[])
+real call_mopac(t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
 {
     /* do the actual QMMM calculation using directly linked mopac subroutines
      */
@@ -167,8 +166,7 @@ real call_mopac(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
     return (QMener);
 }
 
-real call_mopac_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
-                   rvec f[], rvec fshift[])
+real call_mopac_SH(t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[])
 {
     /* do the actual SH QMMM calculation using directly linked mopac
        subroutines */
similarity index 98%
rename from src/gromacs/mdlib/qm_orca.c
rename to src/gromacs/mdlib/qm_orca.cpp
index 11ddfd325b901c82b2b25aa211aa228f59c9546b..2f121806fd3ef98fec128f7ad797d0208067ca73 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -284,7 +284,7 @@ real read_orca_output(rvec QMgrad[], rvec MMgrad[], t_forcerec *fr,
     int
         i, j, atnum;
     char
-        buf[300], tmp[300], orca_xyzFilename[300], orca_pcgradFilename[300], orca_engradFilename[300];
+        buf[300], orca_xyzFilename[300], orca_pcgradFilename[300], orca_engradFilename[300];
     real
         QMener;
     FILE
@@ -320,8 +320,8 @@ real read_orca_output(rvec QMgrad[], rvec MMgrad[], t_forcerec *fr,
                 gmx_fatal(FARGS, "Unexpected end of ORCA output");
             }
 #ifdef GMX_DOUBLE
-            sscanf(buf, "%s%lf%lf%lf\n",
-                   tmp,
+            sscanf(buf, "%d%lf%lf%lf\n",
+                   &atnum,
                    &qm->xQM[i][XX],
                    &qm->xQM[i][YY],
                    &qm->xQM[i][ZZ]);
similarity index 94%
rename from src/gromacs/mdlib/qmmm.c
rename to src/gromacs/mdlib/qmmm.cpp
index bb83405a5548e083d481bcf88616aed3c422a2b5..d2aabba8caf2300c70168ba11c77166ce6601f59 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include "gromacs/fileio/confio.h"
 #include "gromacs/legacyheaders/force.h"
 #include "gromacs/legacyheaders/macros.h"
 /* declarations of the interfaces to the QM packages. The _SH indicate
  * the QM interfaces can be used for Surface Hopping simulations
  */
-#ifdef GMX_QMMM_GAMESS
+#if GMX_QMMM_GAMESS
 /* GAMESS interface */
 
 void
 init_gamess(t_commrec *cr, t_QMrec *qm, t_MMrec *mm);
 
 real
-call_gamess(t_commrec *cr, t_forcerec *fr,
+call_gamess(t_forcerec *fr,
             t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[]);
 
-#elif defined GMX_QMMM_MOPAC
+#elif GMX_QMMM_MOPAC
 /* MOPAC interface */
 
 void
-init_mopac(t_commrec *cr, t_QMrec *qm, t_MMrec *mm);
+init_mopac(t_QMrec *qm);
 
 real
-call_mopac(t_commrec *cr, t_forcerec *fr, t_QMrec *qm,
-           t_MMrec *mm, rvec f[], rvec fshift[]);
+call_mopac(t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[]);
 
 real
-call_mopac_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm,
-              t_MMrec *mm, rvec f[], rvec fshift[]);
+call_mopac_SH(t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[]);
 
-#elif defined GMX_QMMM_GAUSSIAN
+#elif GMX_QMMM_GAUSSIAN
 /* GAUSSIAN interface */
 
 void
-init_gaussian(t_commrec *cr, t_QMrec *qm, t_MMrec *mm);
+init_gaussian(t_QMrec *qm);
 
 real
-call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm,
-                 t_MMrec *mm, rvec f[], rvec fshift[]);
+call_gaussian_SH(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[]);
 
 real
-call_gaussian(t_commrec *cr, t_forcerec *fr, t_QMrec *qm,
-              t_MMrec *mm, rvec f[], rvec fshift[]);
+call_gaussian(t_forcerec *fr, t_QMrec *qm, t_MMrec *mm, rvec f[], rvec fshift[]);
 
-#elif defined GMX_QMMM_ORCA
+#elif GMX_QMMM_ORCA
 /* ORCA interface */
 
 void
@@ -162,14 +162,14 @@ real call_QMroutine(t_commrec gmx_unused *cr, t_forcerec gmx_unused *fr, t_QMrec
 
     if (qm->QMmethod < eQMmethodRHF && !(mm->nrMMatoms))
     {
-#ifdef GMX_QMMM_MOPAC
+#if GMX_QMMM_MOPAC
         if (qm->bSH)
         {
-            QMener = call_mopac_SH(cr, fr, qm, mm, f, fshift);
+            QMener = call_mopac_SH(qm, mm, f, fshift);
         }
         else
         {
-            QMener = call_mopac(cr, fr, qm, mm, f, fshift);
+            QMener = call_mopac(qm, mm, f, fshift);
         }
 #else
         gmx_fatal(FARGS, "Semi-empirical QM only supported with Mopac.");
@@ -180,19 +180,19 @@ real call_QMroutine(t_commrec gmx_unused *cr, t_forcerec gmx_unused *fr, t_QMrec
         /* do an ab-initio calculation */
         if (qm->bSH && qm->QMmethod == eQMmethodCASSCF)
         {
-#ifdef GMX_QMMM_GAUSSIAN
-            QMener = call_gaussian_SH(cr, fr, qm, mm, f, fshift);
+#if GMX_QMMM_GAUSSIAN
+            QMener = call_gaussian_SH(fr, qm, mm, f, fshift);
 #else
             gmx_fatal(FARGS, "Ab-initio Surface-hopping only supported with Gaussian.");
 #endif
         }
         else
         {
-#ifdef GMX_QMMM_GAMESS
-            QMener = call_gamess(cr, fr, qm, mm, f, fshift);
-#elif defined GMX_QMMM_GAUSSIAN
-            QMener = call_gaussian(cr, fr, qm, mm, f, fshift);
-#elif defined GMX_QMMM_ORCA
+#if GMX_QMMM_GAMESS
+            QMener = call_gamess(fr, qm, mm, f, fshift);
+#elif GMX_QMMM_GAUSSIAN
+            QMener = call_gaussian(fr, qm, mm, f, fshift);
+#elif GMX_QMMM_ORCA
             QMener = call_orca(fr, qm, mm, f, fshift);
 #else
             gmx_fatal(FARGS, "Ab-initio calculation only supported with Gamess, Gaussian or ORCA.");
@@ -208,9 +208,9 @@ void init_QMroutine(t_commrec gmx_unused *cr, t_QMrec gmx_unused *qm, t_MMrec gm
      */
     if (qm->QMmethod < eQMmethodRHF)
     {
-#ifdef GMX_QMMM_MOPAC
+#if GMX_QMMM_MOPAC
         /* do a semi-empiprical calculation */
-        init_mopac(cr, qm, mm);
+        init_mopac(qm);
 #else
         gmx_fatal(FARGS, "Semi-empirical QM only supported with Mopac.");
 #endif
@@ -218,11 +218,11 @@ void init_QMroutine(t_commrec gmx_unused *cr, t_QMrec gmx_unused *qm, t_MMrec gm
     else
     {
         /* do an ab-initio calculation */
-#ifdef GMX_QMMM_GAMESS
+#if GMX_QMMM_GAMESS
         init_gamess(cr, qm, mm);
-#elif defined GMX_QMMM_GAUSSIAN
-        init_gaussian(cr, qm, mm);
-#elif defined GMX_QMMM_ORCA
+#elif GMX_QMMM_GAUSSIAN
+        init_gaussian(qm);
+#elif GMX_QMMM_ORCA
         init_orca(qm);
 #else
         gmx_fatal(FARGS, "Ab-initio calculation only supported with Gamess, Gaussian or ORCA.");
@@ -262,7 +262,7 @@ static void punch_QMMM_excl(t_QMrec *qm, t_MMrec *mm, t_blocka *excls)
     FILE
        *out = NULL;
     int
-        i, j, k, nrexcl = 0, *excluded = NULL, max = 0;
+        i, j, k, nrexcl = 0, *excluded = NULL, max_excl = 0;
 
 
     out = fopen("QMMMexcl.dat", "w");
@@ -280,10 +280,10 @@ static void punch_QMMM_excl(t_QMrec *qm, t_MMrec *mm, t_blocka *excls)
             {
                 if (mm->indexMM[k] == excls->a[j]) /* the excluded MM atom */
                 {
-                    if (nrexcl >= max)
+                    if (nrexcl >= max_excl)
                     {
-                        max += 1000;
-                        srenew(excluded, max);
+                        max_excl += 1000;
+                        srenew(excluded, max_excl);
                     }
                     excluded[nrexcl++] = k;
                     continue;
@@ -485,8 +485,8 @@ void init_QMMMrec(t_commrec  *cr,
     t_ilist                 *ilist_mol;
     gmx_mtop_atomlookup_t    alook;
 
-    c6au  = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM, 6));
-    c12au = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM, 12));
+    c6au  = (HARTREE2KJ*AVOGADRO*std::pow(BOHR2NM, 6));
+    c12au = (HARTREE2KJ*AVOGADRO*std::pow(BOHR2NM, 12));
     /* issue a fatal if the user wants to run with more than one node */
     if (PAR(cr))
     {
@@ -751,9 +751,9 @@ void init_QMMMrec(t_commrec  *cr,
          */
         if (qr->qm[0]->QMmethod < eQMmethodRHF)
         {
-#ifdef GMX_QMMM_MOPAC
+#if GMX_QMMM_MOPAC
             /* semi-empiprical 1-layer ONIOM calculation requested (mopac93) */
-            init_mopac(cr, qr->qm[0], qr->mm);
+            init_mopac(qr->qm[0]);
 #else
             gmx_fatal(FARGS, "Semi-empirical QM only supported with Mopac.");
 #endif
@@ -761,11 +761,11 @@ void init_QMMMrec(t_commrec  *cr,
         else
         {
             /* ab initio calculation requested (gamess/gaussian/ORCA) */
-#ifdef GMX_QMMM_GAMESS
+#if GMX_QMMM_GAMESS
             init_gamess(cr, qr->qm[0], qr->mm);
-#elif defined GMX_QMMM_GAUSSIAN
-            init_gaussian(cr, qr->qm[0], qr->mm);
-#elif defined GMX_QMMM_ORCA
+#elif GMX_QMMM_GAUSSIAN
+            init_gaussian(qr->qm[0]);
+#elif GMX_QMMM_ORCA
             init_orca(qr->qm[0]);
 #else
             gmx_fatal(FARGS, "Ab-initio calculation only supported with Gamess, Gaussian or ORCA.");
@@ -797,8 +797,6 @@ void update_QMMMrec(t_commrec      *cr,
         QMMMlist;
     rvec
         dx, crd;
-    int
-       *MMatoms;
     t_QMrec
        *qm;
     t_MMrec
@@ -810,8 +808,8 @@ void update_QMMMrec(t_commrec      *cr,
     real
         c12au, c6au;
 
-    c6au  = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM, 6));
-    c12au = (HARTREE2KJ*AVOGADRO*pow(BOHR2NM, 12));
+    c6au  = (HARTREE2KJ*AVOGADRO*std::pow(BOHR2NM, 6));
+    c12au = (HARTREE2KJ*AVOGADRO*std::pow(BOHR2NM, 12));
 
     /* every cpu has this array. On every processor we fill this array
      * with 1's and 0's. 1's indicate the atoms is a QM atom on the
@@ -873,7 +871,7 @@ void update_QMMMrec(t_commrec      *cr,
                 crd[0] = IS2X(QMMMlist.shift[i]) + IS2X(qm_i_particles[i].shift);
                 crd[1] = IS2Y(QMMMlist.shift[i]) + IS2Y(qm_i_particles[i].shift);
                 crd[2] = IS2Z(QMMMlist.shift[i]) + IS2Z(qm_i_particles[i].shift);
-                is     = XYZ2IS(crd[0], crd[1], crd[2]);
+                is     = static_cast<int>(XYZ2IS(crd[0], crd[1], crd[2]));
                 for (j = QMMMlist.jindex[i];
                      j < QMMMlist.jindex[i+1];
                      j++)
@@ -897,9 +895,13 @@ void update_QMMMrec(t_commrec      *cr,
             qsort(qm_i_particles, QMMMlist.nri,
                   (size_t)sizeof(qm_i_particles[0]),
                   struct_comp);
-            qsort(mm_j_particles, mm_nr,
-                  (size_t)sizeof(mm_j_particles[0]),
-                  struct_comp);
+            /* The mm_j_particles argument to qsort is not allowed to be NULL */
+            if (mm_nr > 0)
+            {
+                qsort(mm_j_particles, mm_nr,
+                      (size_t)sizeof(mm_j_particles[0]),
+                      struct_comp);
+            }
             /* remove multiples in the QM shift array, since in init_QMMM() we
              * went through the atom numbers from 0 to md.nr, the order sorted
              * here matches the one of QMindex already.
index 1d044cc92354f29763314e1c4213f9830a91dab2..b1ab19dbcb9c575a318d87e152f66a3f964b1163 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -61,6 +61,7 @@
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 6a30e1f0347e375ce88fb2bad2e7af6955574453..fc906209eb9d83335513753baa4f3768621c1346 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -40,8 +40,6 @@
 #include <string.h>
 
 #include "gromacs/domdec/domdec.h"
-#include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/legacyheaders/checkpoint.h"
 #include "gromacs/legacyheaders/constr.h"
index ad8e473cf7cfd90f1824d07de242f0471556dc5f..a6f3b202258c34933727e335b9a0528af29a2e12 100644 (file)
@@ -40,7 +40,6 @@
 
 #include <math.h>
 
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/force.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -50,6 +49,7 @@
 #include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
index 744efd51af0e059380d0ab0a151029c74749ed85..7ca2eeae92c7f530b0d76c365a11a851df505520 100644 (file)
@@ -46,7 +46,6 @@
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/ewald/pme.h"
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxlib/conformation-utilities.h"
@@ -73,6 +72,7 @@
 #include "gromacs/timing/wallcycle.h"
 #include "gromacs/timing/walltime_accounting.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index fd1e7a0c9f99675676af62f691b013833cf80d30..13acaaa2f9eb376a52dfb1caaca8b27c75c1de29 100644 (file)
@@ -48,7 +48,7 @@
  *    it can be rewrapped for console output.
  *  - helpformat.h provides some general text-processing classes, currently
  *    focused on producing aligned tables for console output.
- *  - helptopicinterface.h, helptopic.h, and helpmanager.h provide classes for
+ *  - ihelptopic.h, helptopic.h, and helpmanager.h provide classes for
  *    managing a hierarchy of help topics and printing out help from this
  *    hierarchy.
  *
index 99e16425b5639626944d081b034be8413d745ffb..bf99fdd7c4771a4435fa3aecdd4c1bdbb2705302 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -50,7 +50,6 @@
 namespace gmx
 {
 
-class File;
 class HelpWriterContext;
 
 /*! \libinternal \brief
index 89cb7cc811c0f916505b13fc7d0b089f497562a5..60a8b7f48ed1cbeb63bb45226d58678706ac9d58 100644 (file)
@@ -46,8 +46,8 @@
 #include <string>
 #include <vector>
 
-#include "gromacs/onlinehelp/helptopicinterface.h"
 #include "gromacs/onlinehelp/helpwritercontext.h"
+#include "gromacs/onlinehelp/ihelptopic.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/stringutil.h"
 
@@ -67,7 +67,7 @@ class HelpManager::Impl
 {
     public:
         //! Container type for keeping the stack of active topics.
-        typedef std::vector<const HelpTopicInterface *> TopicStack;
+        typedef std::vector<const IHelpTopic *> TopicStack;
 
         //! Initializes a new manager with the given context.
         explicit Impl(const HelpWriterContext &context)
@@ -78,7 +78,7 @@ class HelpManager::Impl
         //! Whether the active topic is the root topic.
         bool isAtRootTopic() const { return topicStack_.size() == 1; }
         //! Returns the active topic.
-        const HelpTopicInterface &currentTopic() const
+        const IHelpTopic &currentTopic() const
         {
             return *topicStack_.back();
         }
@@ -115,7 +115,7 @@ std::string HelpManager::Impl::currentTopicAsString() const
  * HelpManager
  */
 
-HelpManager::HelpManager(const HelpTopicInterface &rootTopic,
+HelpManager::HelpManager(const IHelpTopic         &rootTopic,
                          const HelpWriterContext  &context)
     : impl_(new Impl(context))
 {
@@ -128,14 +128,14 @@ HelpManager::~HelpManager()
 
 void HelpManager::enterTopic(const char *name)
 {
-    const HelpTopicInterface &topic = impl_->currentTopic();
+    const IHelpTopic &topic = impl_->currentTopic();
     if (!topic.hasSubTopics())
     {
         GMX_THROW(InvalidInputError(
                           formatString("Help topic '%s' has no subtopics",
                                        impl_->currentTopicAsString().c_str())));
     }
-    const HelpTopicInterface *newTopic = topic.findSubTopic(name);
+    const IHelpTopic *newTopic = topic.findSubTopic(name);
     if (newTopic == NULL)
     {
         if (impl_->isAtRootTopic())
@@ -160,7 +160,7 @@ void HelpManager::enterTopic(const std::string &name)
 
 void HelpManager::writeCurrentTopic() const
 {
-    const HelpTopicInterface &topic = impl_->currentTopic();
+    const IHelpTopic         &topic = impl_->currentTopic();
     const char               *title = topic.title();
     HelpWriterContext         context(impl_->rootContext_);
     context.enterSubSection(title != NULL ? title : "");
index 97f78e926d8c56a9ad6e34cbd47fc72a7b305cd5..b258f3cac81bf639d23465cb5f9de9a22dbf6e3e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -50,8 +50,8 @@
 namespace gmx
 {
 
-class HelpTopicInterface;
 class HelpWriterContext;
+class IHelpTopic;
 
 /*! \libinternal \brief
  * Helper for providing interactive online help.
@@ -73,7 +73,7 @@ class HelpManager
          * The provided topic and context objects must remain valid for the
          * lifetime of this manager object.
          */
-        HelpManager(const HelpTopicInterface &rootTopic,
+        HelpManager(const IHelpTopic         &rootTopic,
                     const HelpWriterContext  &context);
         ~HelpManager();
 
index 58be839ba3222b2400c08a6551fe92605a80cf9f..c1eafa9dace4ceaf586f8a8787e3bcba2e5f12de 100644 (file)
@@ -49,9 +49,9 @@
 #include "gromacs/onlinehelp/helpformat.h"
 #include "gromacs/onlinehelp/helpwritercontext.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 namespace gmx
 {
@@ -65,7 +65,7 @@ bool AbstractSimpleHelpTopic::hasSubTopics() const
     return false;
 }
 
-const HelpTopicInterface *
+const IHelpTopic *
 AbstractSimpleHelpTopic::findSubTopic(const char * /* name */) const
 {
     return NULL;
@@ -91,7 +91,7 @@ class AbstractCompositeHelpTopic::Impl
         //! Container for subtopics.
         typedef std::vector<HelpTopicPointer> SubTopicList;
         //! Container for mapping subtopic names to help topic objects.
-        typedef std::map<std::string, const HelpTopicInterface *> SubTopicMap;
+        typedef std::map<std::string, const IHelpTopic *> SubTopicMap;
 
         /*! \brief
          * Subtopics in the order they were added.
@@ -125,7 +125,7 @@ bool AbstractCompositeHelpTopic::hasSubTopics() const
     return !impl_->subTopics_.empty();
 }
 
-const HelpTopicInterface *
+const IHelpTopic *
 AbstractCompositeHelpTopic::findSubTopic(const char *name) const
 {
     Impl::SubTopicMap::const_iterator topic = impl_->subTopicMap_.find(name);
@@ -180,7 +180,7 @@ AbstractCompositeHelpTopic::writeSubTopicList(const HelpWriterContext &context,
     {
         return false;
     }
-    File              &file = context.outputFile();
+    TextWriter        &file = context.outputFile();
     TextTableFormatter formatter;
     formatter.addColumn(NULL, maxNameLength + 1, false);
     formatter.addColumn(NULL, 72 - maxNameLength, true);
@@ -205,7 +205,7 @@ void AbstractCompositeHelpTopic::addSubTopic(HelpTopicPointer topic)
 {
     GMX_ASSERT(impl_->subTopicMap_.find(topic->name()) == impl_->subTopicMap_.end(),
                "Attempted to register a duplicate help topic name");
-    const HelpTopicInterface *topicPtr = topic.get();
+    const IHelpTopic *topicPtr = topic.get();
     impl_->subTopics_.reserve(impl_->subTopics_.size() + 1);
     impl_->subTopicMap_.insert(std::make_pair(std::string(topicPtr->name()), topicPtr));
     impl_->subTopics_.push_back(move(topic));
index 3a49e39bd0dc0fd311680f283f272c35070e9ac2..d9027d6a57a561efd412139df36a2ae2addfb052 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \libinternal \file
  * \brief
- * Declares helper classes for implementing gmx::HelpTopicInterface.
+ * Declares helper classes for implementing gmx::IHelpTopic.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
@@ -43,7 +43,7 @@
 #ifndef GMX_ONLINEHELP_HELPTOPIC_H
 #define GMX_ONLINEHELP_HELPTOPIC_H
 
-#include "gromacs/onlinehelp/helptopicinterface.h"
+#include "gromacs/onlinehelp/ihelptopic.h"
 #include "gromacs/utility/classhelpers.h"
 #include "gromacs/utility/stringutil.h"
 #include "gromacs/utility/uniqueptr.h"
@@ -54,7 +54,7 @@ namespace gmx
 /*! \libinternal \brief
  * Abstract base class for help topics that have simple text and no subtopics.
  *
- * This class implements subtopic-related methods from HelpTopicInterface such
+ * This class implements subtopic-related methods from IHelpTopic such
  * that there are no subtopics.  writeHelp() is also implemented such that it
  * uses HelpTopicContext::writeTextBlock() to write out the text returned by a
  * new virtual method helpText().
@@ -64,14 +64,14 @@ namespace gmx
  * \inlibraryapi
  * \ingroup module_onlinehelp
  */
-class AbstractSimpleHelpTopic : public HelpTopicInterface
+class AbstractSimpleHelpTopic : public IHelpTopic
 {
     public:
         virtual const char *name() const  = 0;
         virtual const char *title() const = 0;
 
         virtual bool hasSubTopics() const;
-        virtual const HelpTopicInterface *findSubTopic(const char *name) const;
+        virtual const IHelpTopic *findSubTopic(const char *name) const;
 
         virtual void writeHelp(const HelpWriterContext &context) const;
 
@@ -90,8 +90,8 @@ class AbstractSimpleHelpTopic : public HelpTopicInterface
  * Abstract base class for help topics that have simple text and subtopics.
  *
  * This class implements an internal container for subtopics and provides
- * public methods for adding subtopics (as HelpTopicInterface objects).
- * Subtopic-related methods from HelpTopicInterface are implemented to access
+ * public methods for adding subtopics (as IHelpTopic objects).
+ * Subtopic-related methods from IHelpTopic are implemented to access
  * the internal container.  writeHelp() is also implemented such that it
  * uses HelpTopicContext::writeTextBlock() to write out the text returned by a
  * new virtual method helpText(), and a list of subtopics is written after the
@@ -102,7 +102,7 @@ class AbstractSimpleHelpTopic : public HelpTopicInterface
  * \inlibraryapi
  * \ingroup module_onlinehelp
  */
-class AbstractCompositeHelpTopic : public HelpTopicInterface
+class AbstractCompositeHelpTopic : public IHelpTopic
 {
     public:
         AbstractCompositeHelpTopic();
@@ -112,7 +112,7 @@ class AbstractCompositeHelpTopic : public HelpTopicInterface
         virtual const char *title() const = 0;
 
         virtual bool hasSubTopics() const;
-        virtual const HelpTopicInterface *findSubTopic(const char *name) const;
+        virtual const IHelpTopic *findSubTopic(const char *name) const;
 
         virtual void writeHelp(const HelpWriterContext &context) const;
 
@@ -134,7 +134,7 @@ class AbstractCompositeHelpTopic : public HelpTopicInterface
          * \throws  std::bad_alloc if out of memory.
          *
          * \p Topic must be default-constructible and implement
-         * HelpTopicInterface.
+         * IHelpTopic.
          *
          * This method is provided as a convenient alternative to addSubTopic()
          * for cases where each topic is implemented by a different type
index f4deb7918619be1e1dd3cb568a7312a1d80cdb4c..020d12fdfb8321db4658d7f41be586e89b5699bb 100644 (file)
 
 #include "gromacs/onlinehelp/helpformat.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "rstparser.h"
 
@@ -215,10 +215,10 @@ std::string repall(const std::string &s, const t_sandr (&sa)[nsr])
  * Provides an interface that is used to implement different types of output
  * from HelpWriterContext::Impl::processMarkup().
  */
-class WrapperInterface
+class IWrapper
 {
     public:
-        virtual ~WrapperInterface() {}
+        virtual ~IWrapper() {}
 
         /*! \brief
          * Provides the wrapping settings.
@@ -235,7 +235,7 @@ class WrapperInterface
 /*! \brief
  * Wraps markup output into a single string.
  */
-class WrapperToString : public WrapperInterface
+class WrapperToString : public IWrapper
 {
     public:
         //! Creates a wrapper with the given settings.
@@ -263,7 +263,7 @@ class WrapperToString : public WrapperInterface
 /*! \brief
  * Wraps markup output into a vector of string (one line per element).
  */
-class WrapperToVector : public WrapperInterface
+class WrapperToVector : public IWrapper
 {
     public:
         //! Creates a wrapper with the given settings.
@@ -438,9 +438,9 @@ class HelpWriterContext::Impl
         {
             public:
                 //! Initializes the state with the given parameters.
-                SharedState(File *file, HelpOutputFormat format,
+                SharedState(TextOutputStream *stream, HelpOutputFormat format,
                             const HelpLinks *links)
-                    : file_(*file), format_(format), links_(links)
+                    : file_(stream), format_(format), links_(links)
                 {
                 }
 
@@ -466,8 +466,8 @@ class HelpWriterContext::Impl
                     return *consoleOptionsFormatter_;
                 }
 
-                //! Output file to which the help is written.
-                File                   &file_;
+                //! Writer for writing the help.
+                TextWriter              file_;
                 //! Output format for the help output.
                 HelpOutputFormat        format_;
                 //! Links to use.
@@ -520,7 +520,7 @@ class HelpWriterContext::Impl
          * or providing an interface for the caller to retrieve the output.
          */
         void processMarkup(const std::string &text,
-                           WrapperInterface  *wrapper) const;
+                           IWrapper          *wrapper) const;
 
         //! Constant state shared by all child context objects.
         StatePointer            state_;
@@ -549,7 +549,7 @@ std::string HelpWriterContext::Impl::replaceLinks(const std::string &input) cons
 }
 
 void HelpWriterContext::Impl::processMarkup(const std::string &text,
-                                            WrapperInterface  *wrapper) const
+                                            IWrapper          *wrapper) const
 {
     std::string result(text);
     for (ReplaceList::const_iterator i = replacements_.begin();
@@ -598,14 +598,14 @@ void HelpWriterContext::Impl::processMarkup(const std::string &text,
  * HelpWriterContext
  */
 
-HelpWriterContext::HelpWriterContext(File *file, HelpOutputFormat format)
-    : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, NULL)), 0))
+HelpWriterContext::HelpWriterContext(TextOutputStream *stream, HelpOutputFormat format)
+    : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(stream, format, NULL)), 0))
 {
 }
 
-HelpWriterContext::HelpWriterContext(File *file, HelpOutputFormat format,
+HelpWriterContext::HelpWriterContext(TextOutputStream *stream, HelpOutputFormat format,
                                      const HelpLinks *links)
-    : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, links)), 0))
+    : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(stream, format, links)), 0))
 {
     if (links != NULL)
     {
@@ -639,9 +639,10 @@ HelpOutputFormat HelpWriterContext::outputFormat() const
     return impl_->state_->format_;
 }
 
-File &HelpWriterContext::outputFile() const
+TextWriter &HelpWriterContext::outputFile() const
 {
-    return impl_->state_->file_;
+    // TODO: Consider how to deal with the const/non-const difference better.
+    return const_cast<TextWriter &>(impl_->state_->file_);
 }
 
 void HelpWriterContext::enterSubSection(const std::string &title)
@@ -676,7 +677,7 @@ void HelpWriterContext::writeTitle(const std::string &title) const
     {
         return;
     }
-    File &file = outputFile();
+    TextWriter &file = outputFile();
     switch (outputFormat())
     {
         case eHelpOutputFormat_Console:
@@ -714,7 +715,7 @@ void HelpWriterContext::writeOptionItem(const std::string &name,
                                         const std::string &info,
                                         const std::string &description) const
 {
-    File &file = outputFile();
+    TextWriter &file = outputFile();
     switch (outputFormat())
     {
         case eHelpOutputFormat_Console:
index 1cbce8e6b5e5533eaeb4af8e7b8565f15bcc4d9d..95cac6d739a1d347ce540bad92b459c2c97b6faf 100644 (file)
@@ -51,8 +51,9 @@
 namespace gmx
 {
 
-class File;
 class TextLineWrapperSettings;
+class TextOutputStream;
+class TextWriter;
 
 /*! \cond libapi */
 //! \libinternal Output format for help writing.
@@ -132,13 +133,13 @@ class HelpWriterContext
 {
     public:
         /*! \brief
-         * Initializes a context with the given output file and format.
+         * Initializes a context with the given output stream and format.
          *
          * \throws std::bad_alloc if out of memory.
          */
-        HelpWriterContext(File *file, HelpOutputFormat format);
+        HelpWriterContext(TextOutputStream *stream, HelpOutputFormat format);
         /*! \brief
-         * Initializes a context with the given output file, format and links.
+         * Initializes a context with the given output stream, format and links.
          *
          * \throws std::bad_alloc if out of memory.
          *
@@ -146,7 +147,7 @@ class HelpWriterContext
          * is destructed.  The caller is responsible for ensuring that the
          * links object remains valid long enough.
          */
-        HelpWriterContext(File *file, HelpOutputFormat format,
+        HelpWriterContext(TextOutputStream *stream, HelpOutputFormat format,
                           const HelpLinks *links);
         //! Creates a copy of the context.
         HelpWriterContext(const HelpWriterContext &other);
@@ -174,15 +175,15 @@ class HelpWriterContext
          */
         HelpOutputFormat outputFormat() const;
         /*! \brief
-         * Returns the raw output file for writing the help.
+         * Returns the raw writer for writing the help.
          *
-         * Using this file directly should be avoided, as it requires one to
+         * Using this writer directly should be avoided, as it requires one to
          * have different code for each output format.
          * Using other methods in this class should be preferred.
          *
          * Does not throw.
          */
-        File &outputFile() const;
+        TextWriter &outputFile() const;
 
         /*! \brief
          * Creates a subsection in the output help.
similarity index 90%
rename from src/gromacs/onlinehelp/helptopicinterface.h
rename to src/gromacs/onlinehelp/ihelptopic.h
index 79dfbc390be04a666908103e9e3c6cb07079a2a0..edb9343d328ae251df40a49db753b7c2863785f4 100644 (file)
  */
 /*! \libinternal \file
  * \brief
- * Declares gmx::HelpTopicInterface.
+ * Declares gmx::IHelpTopic.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
  * \ingroup module_onlinehelp
  */
-#ifndef GMX_ONLINEHELP_HELPTOPICINTERFACE_H
-#define GMX_ONLINEHELP_HELPTOPICINTERFACE_H
+#ifndef GMX_ONLINEHELP_IHELPTOPIC_H
+#define GMX_ONLINEHELP_IHELPTOPIC_H
 
 #include "gromacs/utility/uniqueptr.h"
 
@@ -63,10 +63,10 @@ class HelpWriterContext;
  * \inlibraryapi
  * \ingroup module_onlinehelp
  */
-class HelpTopicInterface
+class IHelpTopic
 {
     public:
-        virtual ~HelpTopicInterface() {}
+        virtual ~IHelpTopic() {}
 
         /*! \brief
          * Returns the name of the topic.
@@ -93,7 +93,7 @@ class HelpTopicInterface
          * \returns   Pointer to the found subtopic, or NULL if matching topic
          *      is not found.
          */
-        virtual const HelpTopicInterface *findSubTopic(const char *name) const = 0;
+        virtual const IHelpTopic *findSubTopic(const char *name) const = 0;
 
         /*! \brief
          * Prints the help text for this topic.
@@ -105,8 +105,8 @@ class HelpTopicInterface
         virtual void writeHelp(const HelpWriterContext &context) const = 0;
 };
 
-//! Smart pointer type to manage a HelpTopicInterface object.
-typedef gmx_unique_ptr<HelpTopicInterface>::type HelpTopicPointer;
+//! Smart pointer type to manage a IHelpTopic object.
+typedef gmx_unique_ptr<IHelpTopic>::type HelpTopicPointer;
 
 } // namespace gmx
 
index f28b0f8e12cdca9a5bc176cd78eeaf1968c0522c..05dfb2438202bc87f0774dcc69adee9053572f83 100644 (file)
 #include "gromacs/onlinehelp/helptopic.h"
 #include "gromacs/onlinehelp/helpwritercontext.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/stringstream.h"
 
 #include "gromacs/onlinehelp/tests/mock_helptopic.h"
 #include "testutils/stringtest.h"
 #include "testutils/testasserts.h"
-#include "testutils/testfilemanager.h"
 
 namespace
 {
@@ -68,18 +67,14 @@ class HelpTestBase : public gmx::test::StringTestBase
     public:
         HelpTestBase();
 
-        gmx::test::TestFileManager tempFiles_;
         MockHelpTopic              rootTopic_;
-        std::string                filename_;
-        gmx::File                  helpFile_;
+        gmx::StringOutputStream    helpFile_;
         gmx::HelpWriterContext     context_;
         gmx::HelpManager           manager_;
 };
 
 HelpTestBase::HelpTestBase()
     : rootTopic_("", NULL, "Root topic text"),
-      filename_(tempFiles_.getTemporaryFilePath("helptext.txt")),
-      helpFile_(filename_, "w"),
       context_(&helpFile_, gmx::eHelpOutputFormat_Console),
       manager_(rootTopic_, context_)
 {
@@ -158,7 +153,7 @@ void HelpTopicFormattingTest::checkHelpFormatting()
     ASSERT_NO_THROW_GMX(manager_.writeCurrentTopic());
     helpFile_.close();
 
-    checkFileContents(filename_, "HelpText");
+    checkText(helpFile_.toString(), "HelpText");
 }
 
 TEST_F(HelpTopicFormattingTest, FormatsSimpleTopic)
index d1996e0b6fb4d68211d152e80bff361196a86eb6..e55f03eac596f28695127db3518a59832227eb10 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \libinternal \file
  * \brief
- * Declares mock implementation of gmx::HelpTopicInterface.
+ * Declares mock implementation of gmx::IHelpTopic.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
index e33443b8b1e54c4a1f65d8325cac3295f07fb5bf..1a627cd85c6d7f550f915cd71458928357855854 100644 (file)
@@ -81,7 +81,7 @@ const char *const c_compressedExtensions[] =
  */
 std::string findExistingExtension(const std::string                  &prefix,
                                   const FileNameOptionInfo           &option,
-                                  const FileInputRedirectorInterface *redirector)
+                                  const IFileInputRedirector         *redirector)
 {
     ConstArrayRef<int>                 types = option.fileTypes();
     ConstArrayRef<int>::const_iterator i;
@@ -117,7 +117,7 @@ class FileNameOptionManager::Impl
         }
 
         //! Redirector for file existence checks.
-        const FileInputRedirectorInterface *redirector_;
+        const IFileInputRedirector         *redirector_;
         //! Global default file name, if set.
         std::string                         defaultFileName_;
         //! Whether input option processing has been disabled.
@@ -138,7 +138,7 @@ FileNameOptionManager::~FileNameOptionManager()
 }
 
 void FileNameOptionManager::setInputRedirector(
-        const FileInputRedirectorInterface *redirector)
+        const IFileInputRedirector *redirector)
 {
     impl_->redirector_ = redirector;
 }
index 37f9f7c3bb880673bc18ee49e617deacc4da3ab8..fd2099a40b4b22e03e3c2e436102b0e292ed49d5 100644 (file)
@@ -51,8 +51,8 @@
 namespace gmx
 {
 
-class FileInputRedirectorInterface;
 class FileNameOptionInfo;
+class IFileInputRedirector;
 class Options;
 
 /*! \brief
@@ -79,7 +79,7 @@ class Options;
  * \inpublicapi
  * \ingroup module_selection
  */
-class FileNameOptionManager : public OptionManagerInterface
+class FileNameOptionManager : public IOptionManager
 {
     public:
         FileNameOptionManager();
@@ -101,7 +101,7 @@ class FileNameOptionManager : public OptionManagerInterface
          * For tests, there should only be need to call this a single time,
          * right after creating the manager.
          */
-        void setInputRedirector(const FileInputRedirectorInterface *redirector);
+        void setInputRedirector(const IFileInputRedirector *redirector);
 
         /*! \brief
          * Disables special input file option handling.
index 860b7a2aac4489bcb22acfda8d7180568b4720b5..cfecedaa58ab36e4b271e68e3001cf75617b90eb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -51,7 +51,7 @@
 namespace gmx
 {
 
-class OptionManagerInterface;
+class IOptionManager;
 
 /*! \libinternal
  * \brief
@@ -75,7 +75,7 @@ class OptionManagerContainer
         bool empty() const { return list_.empty(); }
 
         //! Adds a manager to the container.
-        void add(OptionManagerInterface *manager)
+        void add(IOptionManager *manager)
         {
             list_.push_back(manager);
         }
@@ -83,7 +83,7 @@ class OptionManagerContainer
          * Retrieves a manager of a certain type.
          *
          * \tparam  ManagerType  Type of manager to retrieve
-         *     (should derive from OptionManagerInterface).
+         *     (should derive from IOptionManager).
          * \returns The manager, or `NULL` if there is none.
          *
          * This method is used in AbstractOption::createStorage() to retrieve
@@ -112,7 +112,7 @@ class OptionManagerContainer
 
     private:
         //! Shorthand for the internal container type.
-        typedef std::vector<OptionManagerInterface *> ListType;
+        typedef std::vector<IOptionManager *> ListType;
 
         ListType  list_;
 
index 3fba6da02ad8efc80378ae11bceb42d12fa4fd30..a5294c04209ee8fa217cd93071da93a174f47dad 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -108,10 +108,6 @@ class Options::Impl
 
         //! Name for the Options object.
         std::string             name_;
-        //! Description title for the Options object.
-        std::string             title_;
-        //! Full description for the Options object.
-        std::string             description_;
         /*! \brief
          * Option managers set for this collection.
          *
index 3b587bef104e5c369d3468ac16eb838607bd4e09..c0cff702033c691e79be4913cb2c05356117446b 100644 (file)
@@ -56,10 +56,10 @@ namespace gmx
 {
 
 /********************************************************************
- * OptionManagerInterface
+ * IOptionManager
  */
 
-OptionManagerInterface::~OptionManagerInterface()
+IOptionManager::~IOptionManager()
 {
 }
 
@@ -67,8 +67,8 @@ OptionManagerInterface::~OptionManagerInterface()
  * Options::Impl
  */
 
-Options::Impl::Impl(const char *name, const char *title)
-    : name_(name != NULL ? name : ""), title_(title != NULL ? title : ""),
+Options::Impl::Impl(const char *name, const char * /*title*/)
+    : name_(name != NULL ? name : ""),
       parent_(NULL)
 {
 }
@@ -137,27 +137,8 @@ const std::string &Options::name() const
     return impl_->name_;
 }
 
-const std::string &Options::title() const
-{
-    return impl_->title_;
-}
-
-const std::string &Options::description() const
-{
-    return impl_->description_;
-}
-
-void Options::setDescription(const std::string &desc)
-{
-    impl_->description_ = desc;
-}
-
-void Options::setDescription(const ConstArrayRef<const char *> &descArray)
-{
-    impl_->description_ = joinStrings(descArray, "\n");
-}
 
-void Options::addManager(OptionManagerInterface *manager)
+void Options::addManager(IOptionManager *manager)
 {
     GMX_RELEASE_ASSERT(impl_->parent_ == NULL,
                        "Can only add a manager in a top-level Options object");
index 1605fb88ace51c51b4ac8b49881af55f303325d1..d62319b0a0626bea7b7c814dec5892f4bacab023 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -55,8 +55,6 @@
 namespace gmx
 {
 
-template <typename T> class ConstArrayRef;
-
 class AbstractOption;
 class OptionsAssigner;
 class OptionsIterator;
@@ -76,10 +74,10 @@ class OptionsIterator;
  * \inlibraryapi
  * \ingroup module_options
  */
-class OptionManagerInterface
+class IOptionManager
 {
     protected:
-        virtual ~OptionManagerInterface();
+        virtual ~IOptionManager();
 };
 
 /*! \brief
@@ -134,43 +132,6 @@ class Options
 
         //! Returns the short name of the option collection.
         const std::string &name() const;
-        //! Returns the title of the option collection.
-        const std::string &title() const;
-        //! Returns the full description of the option collection.
-        const std::string &description() const;
-
-        /*! \brief
-         * Sets the full description of the option collection.
-         *
-         * \param[in] desc  String to set as the description.
-         *
-         * This overload is mainly useful if the description is very short.
-         * Currently this is mostly the case in unit testing.
-         */
-        void setDescription(const std::string &desc);
-        /*! \brief
-         * Sets the full description of the option collection from string array.
-         *
-         * \param[in] descArray  String array to set as the description.
-         *
-         * All strings in `descArray` are concatenated to form the description.
-         * Spaces are inserted between strings if they are missing.
-         *
-         * Example usage:
-         * \code
-           const char *const desc[] = {
-               "This is the description",
-               "for the options"
-           };
-
-           gmx::Options options(NULL, NULL);
-           options.setDescription(desc);
-           \endcode
-         *
-         * To use this overload, you must also include
-         * `gromacs/utility/arrayref.h`.
-         */
-        void setDescription(const ConstArrayRef<const char *> &descArray);
 
         /*! \brief
          * Adds an option manager.
@@ -192,7 +153,7 @@ class Options
          *
          * This method cannot be called after adding options or subsections.
          */
-        void addManager(OptionManagerInterface *manager);
+        void addManager(IOptionManager *manager);
 
         /*! \brief
          * Adds an option collection as a subsection of this collection.
index 187fef017fe8490b57f09ff2f290630e7fff1b8c..a44e84a47775c7458ea11f481ce12081fdce3b13 100644 (file)
@@ -48,7 +48,6 @@
 
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/fileio/gmxfio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/gmx_ga2la.h"
index 2e85724ac4d8e43ee679f2e55269a643fb5c03eb..8aecd065e7ed9199bc4e74abb0a4d0d4e245aab9 100644 (file)
@@ -56,6 +56,8 @@
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 /********************************************************************
  * gmx_ana_indexgrps_t functions
@@ -261,18 +263,19 @@ gmx_ana_indexgrps_find(gmx_ana_index_t *dest, std::string *destName,
 }
 
 /*!
- * \param[in]  fp     Where to print the output.
+ * \param[in]  writer Writer to use for output.
  * \param[in]  g      Index groups to print.
  * \param[in]  maxn   Maximum number of indices to print
  *      (-1 = print all, 0 = print only names).
  */
 void
-gmx_ana_indexgrps_print(FILE *fp, gmx_ana_indexgrps_t *g, int maxn)
+gmx_ana_indexgrps_print(gmx::TextWriter *writer, gmx_ana_indexgrps_t *g, int maxn)
 {
     for (int i = 0; i < g->nr; ++i)
     {
-        fprintf(fp, " Group %2d \"%s\" ", i, g->names[i].c_str());
-        gmx_ana_index_dump(fp, &g->g[i], maxn);
+        writer->writeString(gmx::formatString(" Group %2d \"%s\" ",
+                                              i, g->names[i].c_str()));
+        gmx_ana_index_dump(writer, &g->g[i], maxn);
     }
 }
 
@@ -394,34 +397,32 @@ gmx_ana_index_copy(gmx_ana_index_t *dest, gmx_ana_index_t *src, bool bAlloc)
 }
 
 /*!
- * \param[in]  fp     Where to print the output.
+ * \param[in]  writer Writer to use for output.
  * \param[in]  g      Index group to print.
  * \param[in]  maxn   Maximum number of indices to print (-1 = print all).
  */
 void
-gmx_ana_index_dump(FILE *fp, gmx_ana_index_t *g, int maxn)
+gmx_ana_index_dump(gmx::TextWriter *writer, gmx_ana_index_t *g, int maxn)
 {
-    int  j, n;
-
-    fprintf(fp, "(%d atoms)", g->isize);
+    writer->writeString(gmx::formatString("(%d atoms)", g->isize));
     if (maxn != 0)
     {
-        fprintf(fp, ":");
-        n = g->isize;
+        writer->writeString(":");
+        int n = g->isize;
         if (maxn >= 0 && n > maxn)
         {
             n = maxn;
         }
-        for (j = 0; j < n; ++j)
+        for (int j = 0; j < n; ++j)
         {
-            fprintf(fp, " %d", g->index[j]+1);
+            writer->writeString(gmx::formatString(" %d", g->index[j]+1));
         }
         if (n < g->isize)
         {
-            fprintf(fp, " ...");
+            writer->writeString(" ...");
         }
     }
-    fprintf(fp, "\n");
+    writer->writeLine();
 }
 
 int
index 7ec5bd96916b0d2610fcedbe87cd9ab2868b4784..9ac9364008ba028178a82269af688450ca373f41 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/legacyheaders/types/simple.h"
 #include "gromacs/topology/block.h"
 
+namespace gmx
+{
+class TextWriter;
+}
+
 struct t_topology;
 
 /** Stores a set of index groups. */
@@ -205,7 +210,7 @@ gmx_ana_indexgrps_find(gmx_ana_index_t *dest, std::string *destName,
 
 /** Writes out a list of index groups. */
 void
-gmx_ana_indexgrps_print(FILE *fp, gmx_ana_indexgrps_t *g, int maxn);
+gmx_ana_indexgrps_print(gmx::TextWriter *writer, gmx_ana_indexgrps_t *g, int maxn);
 /*@}*/
 
 /*! \name Functions for handling gmx_ana_index_t
@@ -235,7 +240,7 @@ gmx_ana_index_copy(gmx_ana_index_t *dest, gmx_ana_index_t *src, bool bAlloc);
 
 /** Writes out the contents of a index group. */
 void
-gmx_ana_index_dump(FILE *fp, gmx_ana_index_t *g, int maxn);
+gmx_ana_index_dump(gmx::TextWriter *writer, gmx_ana_index_t *g, int maxn);
 
 /*! \brief
  * Returns maximum atom index that appears in an index group.
index 768be462d87beaa763113edb6043f3e43ebb38dc..86fdcbefaed185a097378354f35f05ef366567f3 100644 (file)
@@ -62,8 +62,6 @@
 #include <algorithm>
 #include <vector>
 
-#include "thread_mpi/mutex.h"
-
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
@@ -72,6 +70,7 @@
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/mutex.h"
 #include "gromacs/utility/stringutil.h"
 
 namespace gmx
@@ -309,7 +308,7 @@ class AnalysisNeighborhoodSearchImpl
         //! Data structure to hold the grid cell contents.
         CellList                cells_;
 
-        tMPI::mutex             createPairSearchMutex_;
+        Mutex                   createPairSearchMutex_;
         PairSearchList          pairSearchList_;
 
         friend class AnalysisNeighborhoodPairSearchImpl;
@@ -439,7 +438,7 @@ AnalysisNeighborhoodSearchImpl::~AnalysisNeighborhoodSearchImpl()
 AnalysisNeighborhoodSearchImpl::PairSearchImplPointer
 AnalysisNeighborhoodSearchImpl::getPairSearch()
 {
-    tMPI::lock_guard<tMPI::mutex> lock(createPairSearchMutex_);
+    lock_guard<Mutex> lock(createPairSearchMutex_);
     // TODO: Consider whether this needs to/can be faster, e.g., by keeping a
     // separate pool of unused search objects.
     PairSearchList::const_iterator i;
@@ -1252,7 +1251,7 @@ class AnalysisNeighborhood::Impl
 
         SearchImplPointer getSearch();
 
-        tMPI::mutex             createSearchMutex_;
+        Mutex                   createSearchMutex_;
         SearchList              searchList_;
         real                    cutoff_;
         const t_blocka         *excls_;
@@ -1263,7 +1262,7 @@ class AnalysisNeighborhood::Impl
 AnalysisNeighborhood::Impl::SearchImplPointer
 AnalysisNeighborhood::Impl::getSearch()
 {
-    tMPI::lock_guard<tMPI::mutex> lock(createSearchMutex_);
+    lock_guard<Mutex> lock(createSearchMutex_);
     // TODO: Consider whether this needs to/can be faster, e.g., by keeping a
     // separate pool of unused search objects.
     SearchList::const_iterator i;
index f00413346f22174394ca83a97e28b0645ac3aa38..379dc199387ff12c87b628cb49c6b327e0087cd0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -151,7 +151,7 @@ yyerror(YYLTYPE *location, yyscan_t scanner, char const *s)
     }
 //!\}
 
-#ifndef GMX_CXX11
+#if !GMX_CXX11
 //! No-op to enable use of same get()/set() implementation as with C++11.
 static gmx::SelectionParserValue &move(gmx::SelectionParserValue &src)
 {
@@ -170,7 +170,7 @@ static gmx::SelectionParserParameter &move(gmx::SelectionParserParameter &src)
  * \param[in] src  Semantic value to get the value from.
  * \returns   Retrieved value.
  * \throws    unspecified  Any exception thrown by the move constructor of
- *      ValueType (copy constructor if GMX_CXX11 is not set).
+ *      ValueType (copy constructor if GMX_CXX11 is 0).
  *
  * There should be no statements that may throw exceptions in actions before
  * this function has been called for all semantic values that have a C++ object
@@ -196,7 +196,7 @@ ValueType get(ValueType *src)
  * \param[in]  value Value to put into the semantic value.
  * \throws     std::bad_alloc if out of memory.
  * \throws     unspecified  Any exception thrown by the move constructor of
- *      ValueType (copy constructor if GMX_CXX11 is not set).
+ *      ValueType (copy constructor if GMX_CXX11 is 0).
  *
  * This should be the last statement before ::END_ACTION, except for a
  * possible ::CHECK_SEL.
index d3d9096f18211cda5374801599cbd1adb69b096d..d1eb39fcf3081e1f5e1769c12b36677cea8d2f9e 100644 (file)
@@ -66,8 +66,9 @@
  *    methods and initializes the children of the method element.
  *  - selectioncollection.h, selectioncollection.cpp:
  *    These files define the high-level public interface to the parser
- *    through SelectionCollection::parseFromStdin(),
- *    SelectionCollection::parseFromFile() and
+ *    through SelectionCollection::parseInteractive(),
+ *    SelectionCollection::parseFromStdin(),
+ *    SelectionCollection::parseFromFile(), and
  *    SelectionCollection::parseFromString().
  *
  * The basic control flow in the parser is as follows: when a parser function
 #include "gromacs/selection/selection.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "keywords.h"
 #include "poscalc.h"
@@ -310,9 +311,11 @@ _gmx_selparser_handle_error(yyscan_t scanner)
     catch (gmx::UserInputError &ex)
     {
         ex.prependContext(context);
-        if (_gmx_sel_is_lexer_interactive(scanner))
+        gmx::TextWriter *statusWriter
+            = _gmx_sel_lexer_get_status_writer(scanner);
+        if (statusWriter != NULL)
         {
-            gmx::formatExceptionMessageToFile(stderr, ex);
+            gmx::formatExceptionMessageToWriter(statusWriter, ex);
             return true;
         }
         throw;
@@ -1062,10 +1065,13 @@ _gmx_sel_init_selection(const char                             *name,
     root->fillNameIfMissing(_gmx_sel_lexer_pselstr(scanner));
 
     /* Print out some information if the parser is interactive */
-    if (_gmx_sel_is_lexer_interactive(scanner))
+    gmx::TextWriter *statusWriter = _gmx_sel_lexer_get_status_writer(scanner);
+    if (statusWriter != NULL)
     {
-        fprintf(stderr, "Selection '%s' parsed\n",
-                _gmx_sel_lexer_pselstr(scanner));
+        const std::string message
+            = gmx::formatString("Selection '%s' parsed",
+                                _gmx_sel_lexer_pselstr(scanner));
+        statusWriter->writeLine(message);
     }
 
     return root;
@@ -1129,9 +1135,12 @@ _gmx_sel_assign_variable(const char                             *name,
     srenew(sc->varstrs, sc->nvars + 1);
     sc->varstrs[sc->nvars] = gmx_strdup(pselstr);
     ++sc->nvars;
-    if (_gmx_sel_is_lexer_interactive(scanner))
+    gmx::TextWriter *statusWriter = _gmx_sel_lexer_get_status_writer(scanner);
+    if (statusWriter != NULL)
     {
-        fprintf(stderr, "Variable '%s' parsed\n", pselstr);
+        const std::string message
+            = gmx::formatString("Variable '%s' parsed", pselstr);
+        statusWriter->writeLine(message);
     }
     return root;
 }
index a37f3e8cf77fd65b7dd0ab6913d1c72cd78eeb24..3cdfb93e73b11554cb8984336cb319257c61e377 100644 (file)
@@ -495,7 +495,7 @@ static yyconst flex_int16_t yy_chk[151] =
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -932,7 +932,7 @@ case 6:
 YY_RULE_SETUP
 #line 137 "scanner.l"
 {
-                    if (yytext[0] == ';' || state->bInteractive)
+                    if (yytext[0] == ';' || state->statusWriter != NULL)
                     {
                         rtrim(state->pselstr);
                         state->bCmdStart = true;
index ad7fcf56ce3e33a90ec1e620803edb1bdc5bd388..b918ccc5fd375f9266eb75d7a7f3378505bbfef1 100644 (file)
 
 #include "parser.h"
 
+namespace gmx
+{
+class TextWriter;
+}
+
 struct gmx_ana_indexgrps_t;
 struct gmx_ana_selcollection_t;
 
@@ -62,7 +67,7 @@ typedef void *yyscan_t;
 /** Initializes the selection scanner. */
 void
 _gmx_sel_init_lexer(yyscan_t *scannerp, struct gmx_ana_selcollection_t *sc,
-                    bool bInteractive, int maxnr, bool bGroups,
+                    gmx::TextWriter *statusWriter, int maxnr, bool bGroups,
                     struct gmx_ana_indexgrps_t *grps);
 /** Frees memory allocated for the selection scanner. */
 void
@@ -77,9 +82,9 @@ _gmx_sel_lexer_set_exception(yyscan_t                    scanner,
 void
 _gmx_sel_lexer_rethrow_exception_if_occurred(yyscan_t scanner);
 
-/** Returns true if the scanner is interactive. */
-bool
-_gmx_sel_is_lexer_interactive(yyscan_t scanner);
+/** Returns writer for status output (if not NULL, the scanner is interactive). */
+gmx::TextWriter *
+_gmx_sel_lexer_get_status_writer(yyscan_t scanner);
 /** Returns the selection collection for the scanner. */
 struct gmx_ana_selcollection_t *
 _gmx_sel_lexer_selcollection(yyscan_t scanner);
index f41234b2de01ea6d47b9acfe7560e89d1990633c..d2d2fd97ecbd8bc7edcfd52df34ceeaf32a89d0d 100644 (file)
@@ -135,7 +135,7 @@ COMMENT    (#.*)
 
 \\\n            { _gmx_sel_lexer_add_token(yylloc, " ", 1, state); break; }
 ";"|\n          {
-                    if (yytext[0] == ';' || state->bInteractive)
+                    if (yytext[0] == ';' || state->statusWriter != NULL)
                     {
                         rtrim(state->pselstr);
                         state->bCmdStart = true;
index 1f3be505e5d192e406ce9824d30b916a1942ad54..d66d647b58dfb524cc635ae20429cea8ae68ccdc 100644 (file)
@@ -384,8 +384,8 @@ _gmx_sel_lexer_add_token(YYLTYPE *yylloc, const char *str, int len,
 
 void
 _gmx_sel_init_lexer(yyscan_t *scannerp, struct gmx_ana_selcollection_t *sc,
-                    bool bInteractive, int maxnr, bool bGroups,
-                    struct gmx_ana_indexgrps_t *grps)
+                    gmx::TextWriter *statusWriter, int maxnr,
+                    bool bGroups, struct gmx_ana_indexgrps_t *grps)
 {
     int rc = _gmx_sel_yylex_init(scannerp);
     if (rc != 0)
@@ -401,7 +401,7 @@ _gmx_sel_init_lexer(yyscan_t *scannerp, struct gmx_ana_selcollection_t *sc,
     state->grps      = grps;
     state->nexpsel   = (maxnr > 0 ? static_cast<int>(sc->sel.size()) + maxnr : -1);
 
-    state->bInteractive = bInteractive;
+    state->statusWriter = statusWriter;
 
     snew(state->pselstr, STRSTORE_ALLOCSTEP);
     state->pselstr[0]                 = 0;
@@ -461,11 +461,11 @@ _gmx_sel_lexer_rethrow_exception_if_occurred(yyscan_t scanner)
     }
 }
 
-bool
-_gmx_sel_is_lexer_interactive(yyscan_t scanner)
+gmx::TextWriter *
+_gmx_sel_lexer_get_status_writer(yyscan_t scanner)
 {
     gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);
-    return state->bInteractive;
+    return state->statusWriter;
 }
 
 struct gmx_ana_selcollection_t *
index 5bd8eb0e433718259cf383c4135cef7a1894af1b..7b01b81e27346ea116fa2a2d81c63e51ab1cb9ea 100644 (file)
@@ -48,6 +48,7 @@
 namespace gmx
 {
 class SelectionParserSymbol;
+class TextWriter;
 }
 
 /* These need to be defined before including scanner_flex.h, because it
@@ -81,8 +82,8 @@ typedef struct gmx_sel_lexer_t
     //! Number of selections at which the parser should stop.
     int                              nexpsel;
 
-    //! Whether the parser is interactive.
-    bool                             bInteractive;
+    //! Writer to use for status output (if not NULL, parser is interactive).
+    gmx::TextWriter                 *statusWriter;
 
     //! Pretty-printed version of the string parsed since last clear.
     char                            *pselstr;
index 7b77d5c5ac4845a31d286e680517d69395f48180..8c81ca51ac6feba05cfc00d6d9d67b2b14f6f969 100644 (file)
@@ -51,6 +51,7 @@
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "selelem.h"
 #include "selvalue.h"
@@ -320,7 +321,8 @@ Selection::printDebugInfo(FILE *fp, int nmaxind) const
     fprintf(fp, "    Group ");
     gmx_ana_index_t g;
     gmx_ana_index_set(&g, p.m.mapb.nra, p.m.mapb.a, 0);
-    gmx_ana_index_dump(fp, &g, nmaxind);
+    TextWriter      writer(fp);
+    gmx_ana_index_dump(&writer, &g, nmaxind);
 
     fprintf(fp, "    Block (size=%d):", p.m.mapb.nr);
     if (!p.m.mapb.index)
index abc938683067dc98fc8485b784db340a83292066..b92ecf4c62dd2f3acdccfd308ded30aa91e6dd85 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -50,7 +50,7 @@
 
 #include <boost/scoped_ptr.hpp>
 
-#include "gromacs/onlinehelp/helptopicinterface.h"
+#include "gromacs/onlinehelp/ihelptopic.h"
 #include "gromacs/selection/indexutil.h"
 #include "gromacs/selection/selection.h" // For gmx::SelectionList
 #include "gromacs/selection/selectioncollection.h"
index e18078814b489a5bfdfc32878001dd145bad0b7a..b7ee4d0b2d67b75835196179a9a6a4878c6f5727 100644 (file)
@@ -49,6 +49,7 @@
 #include <string>
 #include <vector>
 
+#include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 
 #include "gromacs/fileio/trx.h"
 #include "gromacs/selection/selhelp.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/filestream.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "compiler.h"
 #include "mempool.h"
@@ -129,43 +131,44 @@ namespace
 /*! \brief
  * Reads a single selection line from stdin.
  *
- * \param[in]  infile        File to read from (typically File::standardInput()).
- * \param[in]  bInteractive  Whether to print interactive prompts.
+ * \param[in]  inputStream   Stream to read from (typically the StandardInputStream).
+ * \param[in]  statusWriter  Stream to print prompts to (if NULL, no output is done).
  * \param[out] line          The read line in stored here.
  * \returns true if something was read, false if at end of input.
  *
  * Handles line continuation, reading also the continuing line(s) in one call.
  */
-bool promptLine(File *infile, bool bInteractive, std::string *line)
+bool promptLine(TextInputStream *inputStream, TextWriter *statusWriter,
+                std::string *line)
 {
-    if (bInteractive)
+    if (statusWriter != NULL)
     {
-        fprintf(stderr, "> ");
+        statusWriter->writeString("> ");
     }
-    if (!infile->readLineWithTrailingSpace(line))
+    if (!inputStream->readLine(line))
     {
         return false;
     }
     while (endsWith(*line, "\\\n"))
     {
         line->resize(line->length() - 2);
-        if (bInteractive)
+        if (statusWriter != NULL)
         {
-            fprintf(stderr, "... ");
+            statusWriter->writeString("... ");
         }
         std::string buffer;
         // Return value ignored, buffer remains empty and works correctly
         // if there is nothing to read.
-        infile->readLineWithTrailingSpace(&buffer);
+        inputStream->readLine(&buffer);
         line->append(buffer);
     }
     if (endsWith(*line, "\n"))
     {
         line->resize(line->length() - 1);
     }
-    else if (bInteractive)
+    else if (statusWriter != NULL)
     {
-        fprintf(stderr, "\n");
+        statusWriter->writeLine();
     }
     return true;
 }
@@ -185,26 +188,14 @@ int runParserLoop(yyscan_t scanner, _gmx_sel_yypstate *parserState,
                   bool bInteractive)
 {
     int status    = YYPUSH_MORE;
-    int prevToken = 0;
     do
     {
         YYSTYPE value;
         YYLTYPE location;
         int     token = _gmx_sel_yylex(&value, &location, scanner);
-        if (bInteractive)
+        if (bInteractive && token == 0)
         {
-            if (token == 0)
-            {
-                break;
-            }
-            // Empty commands cause the interactive parser to print out
-            // status information. This avoids producing those unnecessarily,
-            // e.g., from "resname RA;;".
-            if (prevToken == CMD_SEP && token == CMD_SEP)
-            {
-                continue;
-            }
-            prevToken = token;
+            break;
         }
         status = _gmx_sel_yypush_parse(parserState, token, &value, &location, scanner);
     }
@@ -216,6 +207,7 @@ int runParserLoop(yyscan_t scanner, _gmx_sel_yypstate *parserState,
 /*! \brief
  * Print current status in response to empty line in interactive input.
  *
+ * \param[in] writer         Writer to use for the output.
  * \param[in] sc             Selection collection data structure.
  * \param[in] grps           Available index groups.
  * \param[in] firstSelection Index of first selection from this interactive
@@ -227,52 +219,54 @@ int runParserLoop(yyscan_t scanner, _gmx_sel_yypstate *parserState,
  *
  * Prints the available index groups and currently provided selections.
  */
-void printCurrentStatus(gmx_ana_selcollection_t *sc, gmx_ana_indexgrps_t *grps,
-                        size_t firstSelection, int maxCount,
-                        const std::string &context, bool bFirst)
+void printCurrentStatus(TextWriter *writer, gmx_ana_selcollection_t *sc,
+                        gmx_ana_indexgrps_t *grps, size_t firstSelection,
+                        int maxCount, const std::string &context, bool bFirst)
 {
     if (grps != NULL)
     {
-        std::fprintf(stderr, "Available static index groups:\n");
-        gmx_ana_indexgrps_print(stderr, grps, 0);
+        writer->writeLine("Available static index groups:");
+        gmx_ana_indexgrps_print(writer, grps, 0);
     }
-    std::fprintf(stderr, "Specify ");
+    writer->writeString("Specify ");
     if (maxCount < 0)
     {
-        std::fprintf(stderr, "any number of selections");
+        writer->writeString("any number of selections");
     }
     else if (maxCount == 1)
     {
-        std::fprintf(stderr, "a selection");
+        writer->writeString("a selection");
     }
     else
     {
-        std::fprintf(stderr, "%d selections", maxCount);
+        writer->writeString(formatString("%d selections", maxCount));
     }
-    std::fprintf(stderr, "%s%s:\n",
-                 context.empty() ? "" : " ", context.c_str());
-    std::fprintf(stderr,
-                 "(one per line, <enter> for status/groups, 'help' for help%s)\n",
-                 maxCount < 0 ? ", Ctrl-D to end" : "");
+    writer->writeString(formatString("%s%s:\n",
+                                     context.empty() ? "" : " ", context.c_str()));
+    writer->writeString(formatString(
+                                "(one per line, <enter> for status/groups, 'help' for help%s)\n",
+                                maxCount < 0 ? ", Ctrl-D to end" : ""));
     if (!bFirst && (sc->nvars > 0 || sc->sel.size() > firstSelection))
     {
-        std::fprintf(stderr, "Currently provided selections:\n");
+        writer->writeLine("Currently provided selections:");
         for (int i = 0; i < sc->nvars; ++i)
         {
-            std::fprintf(stderr, "     %s\n", sc->varstrs[i]);
+            writer->writeString(formatString("     %s\n", sc->varstrs[i]));
         }
         for (size_t i = firstSelection; i < sc->sel.size(); ++i)
         {
-            std::fprintf(stderr, " %2d. %s\n",
-                         static_cast<int>(i - firstSelection + 1),
-                         sc->sel[i]->selectionText());
+            writer->writeString(formatString(
+                                        " %2d. %s\n",
+                                        static_cast<int>(i - firstSelection + 1),
+                                        sc->sel[i]->selectionText()));
         }
         if (maxCount > 0)
         {
             const int remaining
                 = maxCount - static_cast<int>(sc->sel.size() - firstSelection);
-            std::fprintf(stderr, "(%d more selection%s required)\n",
-                         remaining, remaining > 1 ? "s" : "");
+            writer->writeString(formatString(
+                                        "(%d more selection%s required)\n",
+                                        remaining, remaining > 1 ? "s" : ""));
         }
     }
 }
@@ -280,20 +274,21 @@ void printCurrentStatus(gmx_ana_selcollection_t *sc, gmx_ana_indexgrps_t *grps,
 /*! \brief
  * Prints selection help in interactive selection input.
  *
+ * \param[in] writer Writer to use for the output.
  * \param[in] sc    Selection collection data structure.
  * \param[in] line  Line of user input requesting help (starting with `help`).
  *
  * Initializes the selection help if not yet initialized, and finds the help
  * topic based on words on the input line.
  */
-void printHelp(gmx_ana_selcollection_t *sc, const std::string &line)
+void printHelp(TextWriter *writer, gmx_ana_selcollection_t *sc,
+               const std::string &line)
 {
     if (sc->rootHelp.get() == NULL)
     {
         sc->rootHelp = createSelectionHelpTopic();
     }
-    HelpWriterContext context(&File::standardError(),
-                              eHelpOutputFormat_Console);
+    HelpWriterContext context(&writer->stream(), eHelpOutputFormat_Console);
     HelpManager       manager(*sc->rootHelp, context);
     try
     {
@@ -307,7 +302,7 @@ void printHelp(gmx_ana_selcollection_t *sc, const std::string &line)
     }
     catch (const InvalidInputError &ex)
     {
-        fprintf(stderr, "%s\n", ex.what());
+        writer->writeLine(ex.what());
         return;
     }
     manager.writeCurrentTopic();
@@ -317,8 +312,10 @@ void printHelp(gmx_ana_selcollection_t *sc, const std::string &line)
  * Helper function that runs the parser once the tokenizer has been
  * initialized.
  *
- * \param[in,out] scanner Scanner data structure.
- * \param[in]     bStdIn  Whether to use a line-based reading
+ * \param[in,out] scanner       Scanner data structure.
+ * \param[in]     inputStream   Stream to use for input (currently only with
+ *      `bInteractive==true`).
+ * \param[in]     bInteractive  Whether to use a line-based reading
  *      algorithm designed for interactive input.
  * \param[in]     maxnr   Maximum number of selections to parse
  *      (if -1, parse as many as provided by the user).
@@ -327,11 +324,11 @@ void printHelp(gmx_ana_selcollection_t *sc, const std::string &line)
  * \throws        std::bad_alloc if out of memory.
  * \throws        InvalidInputError if there is a parsing error.
  *
- * Used internally to implement parseFromStdin(), parseFromFile() and
+ * Used internally to implement parseInteractive(), parseFromFile() and
  * parseFromString().
  */
-SelectionList runParser(yyscan_t scanner, bool bStdIn, int maxnr,
-                        const std::string &context)
+SelectionList runParser(yyscan_t scanner, TextInputStream *inputStream,
+                        bool bInteractive, int maxnr, const std::string &context)
 {
     boost::shared_ptr<void>  scannerGuard(scanner, &_gmx_sel_free_lexer);
     gmx_ana_selcollection_t *sc   = _gmx_sel_lexer_selcollection(scanner);
@@ -341,30 +338,29 @@ SelectionList runParser(yyscan_t scanner, bool bStdIn, int maxnr,
     {
         boost::shared_ptr<_gmx_sel_yypstate> parserState(
                 _gmx_sel_yypstate_new(), &_gmx_sel_yypstate_delete);
-        if (bStdIn)
+        if (bInteractive)
         {
-            File       &stdinFile(File::standardInput());
-            const bool  bInteractive = _gmx_sel_is_lexer_interactive(scanner);
-            if (bInteractive)
+            TextWriter *statusWriter = _gmx_sel_lexer_get_status_writer(scanner);
+            if (statusWriter != NULL)
             {
-                printCurrentStatus(sc, grps, oldCount, maxnr, context, true);
+                printCurrentStatus(statusWriter, sc, grps, oldCount, maxnr, context, true);
             }
             std::string line;
             int         status;
-            while (promptLine(&stdinFile, bInteractive, &line))
+            while (promptLine(inputStream, statusWriter, &line))
             {
-                if (bInteractive)
+                if (statusWriter != NULL)
                 {
                     line = stripString(line);
                     if (line.empty())
                     {
-                        printCurrentStatus(sc, grps, oldCount, maxnr, context, false);
+                        printCurrentStatus(statusWriter, sc, grps, oldCount, maxnr, context, false);
                         continue;
                     }
                     if (startsWith(line, "help")
                         && (line[4] == 0 || std::isspace(line[4])))
                     {
-                        printHelp(sc, line);
+                        printHelp(statusWriter, sc, line);
                         continue;
                     }
                 }
@@ -673,17 +669,32 @@ SelectionCollection::requiresTopology() const
     return false;
 }
 
-
 SelectionList
-SelectionCollection::parseFromStdin(int nr, bool bInteractive,
+SelectionCollection::parseFromStdin(int count, bool bInteractive,
                                     const std::string &context)
+{
+    return parseInteractive(count, &StandardInputStream::instance(),
+                            bInteractive ? &TextOutputFile::standardError() : NULL,
+                            context);
+}
+
+SelectionList
+SelectionCollection::parseInteractive(int                count,
+                                      TextInputStream   *inputStream,
+                                      TextOutputStream  *statusStream,
+                                      const std::string &context)
 {
     yyscan_t scanner;
 
-    _gmx_sel_init_lexer(&scanner, &impl_->sc_, bInteractive, nr,
-                        impl_->bExternalGroupsSet_,
-                        impl_->grps_);
-    return runParser(scanner, true, nr, context);
+    boost::scoped_ptr<TextWriter> statusWriter;
+    if (statusStream != NULL)
+    {
+        statusWriter.reset(new TextWriter(statusStream));
+        statusWriter->wrapperSettings().setLineLength(78);
+    }
+    _gmx_sel_init_lexer(&scanner, &impl_->sc_, statusWriter.get(),
+                        count, impl_->bExternalGroupsSet_, impl_->grps_);
+    return runParser(scanner, inputStream, true, count, context);
 }
 
 
@@ -693,14 +704,14 @@ SelectionCollection::parseFromFile(const std::string &filename)
 
     try
     {
-        yyscan_t scanner;
-        File     file(filename, "r");
+        yyscan_t      scanner;
+        TextInputFile file(filename);
         // TODO: Exception-safe way of using the lexer.
-        _gmx_sel_init_lexer(&scanner, &impl_->sc_, false, -1,
+        _gmx_sel_init_lexer(&scanner, &impl_->sc_, NULL, -1,
                             impl_->bExternalGroupsSet_,
                             impl_->grps_);
         _gmx_sel_set_lex_input_file(scanner, file.handle());
-        return runParser(scanner, false, -1, std::string());
+        return runParser(scanner, NULL, false, -1, std::string());
     }
     catch (GromacsException &ex)
     {
@@ -717,11 +728,11 @@ SelectionCollection::parseFromString(const std::string &str)
 {
     yyscan_t scanner;
 
-    _gmx_sel_init_lexer(&scanner, &impl_->sc_, false, -1,
+    _gmx_sel_init_lexer(&scanner, &impl_->sc_, NULL, -1,
                         impl_->bExternalGroupsSet_,
                         impl_->grps_);
     _gmx_sel_set_lex_input_str(scanner, str.c_str());
-    return runParser(scanner, false, -1, std::string());
+    return runParser(scanner, NULL, false, -1, std::string());
 }
 
 
index 8ec7ed1f230554acb65ed5cbbbbb094be6af8a80..826f20a04d1a85c3a8ddd23f6e2afda3995d8ec4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -63,6 +63,8 @@ namespace gmx
 class Options;
 class SelectionCompiler;
 class SelectionEvaluator;
+class TextInputStream;
+class TextOutputStream;
 
 /*! \brief
  * Collection of selections.
@@ -79,7 +81,7 @@ class SelectionEvaluator;
  * initialization options.
  *
  * After setting the default values, one or more selections can be parsed with
- * one or more calls to parseFromStdin(), parseFromFile(), and/or
+ * one or more calls to parseInteractive(), parseFromStdin(), parseFromFile(), and/or
  * parseFromString().  After all selections are parsed, the topology must be
  * set with setTopology() unless requiresTopology() returns false (the topology
  * can also be set earlier).
@@ -257,6 +259,31 @@ class SelectionCollection
          */
         SelectionList parseFromStdin(int count, bool bInteractive,
                                      const std::string &context);
+        /*! \brief
+         * Parses selection(s) interactively using provided streams.
+         *
+         * \param[in]  count    Number of selections to parse
+         *      (if -1, parse as many as provided by the user).
+         * \param[in]  inputStream  Stream to use for input.
+         * \param[in]  outputStream Stream to use for output
+         *      (if NULL, the parser runs non-interactively and does not
+         *      produce any status messages).
+         * \param[in]  context  Context to print for interactive input.
+         * \returns    Vector of parsed selections.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     InvalidInputError if there is a parsing error
+         *      (an interactive parser only throws this if too few selections
+         *      are provided and the user forced the end of input).
+         *
+         * Works the same as parseFromStdin(), except that the caller can
+         * provide streams to use instead of `stdin` and `stderr`.
+         *
+         * Mainly usable for unit testing interactive input.
+         */
+        SelectionList parseInteractive(int                count,
+                                       TextInputStream   *inputStream,
+                                       TextOutputStream  *outputStream,
+                                       const std::string &context);
         /*! \brief
          * Parses selection(s) from a file.
          *
index 7ddb8660872e80449c94a09eabb90f6633a8ff01..82e91749f405b32c8129d45f54060248ab7b224c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -79,7 +79,7 @@ class SelectionOptionStorage;
  * \inpublicapi
  * \ingroup module_selection
  */
-class SelectionOptionManager : public OptionManagerInterface
+class SelectionOptionManager : public IOptionManager
 {
     public:
         /*! \brief
index e96a955f716b7198179e1e9b130efd1b3918c217..0a29722728ae9fce6cf1803696842c0e80750bbd 100644 (file)
@@ -53,9 +53,9 @@
 #include "gromacs/onlinehelp/helptopic.h"
 #include "gromacs/onlinehelp/helpwritercontext.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "selmethod.h"
 #include "symrec.h"
@@ -708,7 +708,7 @@ void KeywordsHelpTopic::printKeywordList(const HelpWriterContext &context,
                                          e_selvalue_t             type,
                                          bool                     bModifiers) const
 {
-    File &file = context.outputFile();
+    TextWriter                &file = context.outputFile();
     MethodList::const_iterator iter;
     for (iter = methods_.begin(); iter != methods_.end(); ++iter)
     {
@@ -774,7 +774,7 @@ void KeywordsHelpTopic::writeKeywordSubTopics(const HelpWriterContext &context)
             }
         }
 
-        const HelpTopicInterface *subTopic = findSubTopic(iter->first.c_str());
+        const IHelpTopic         *subTopic = findSubTopic(iter->first.c_str());
         GMX_RELEASE_ASSERT(subTopic != NULL, "Keyword subtopic no longer exists");
         HelpWriterContext         subContext(context);
         subContext.enterSubSection(title);
index b29251d31aaf2f2cd1438117570388b8110dfc22..bfcea9ccfc8ea2b37084a93db16b1bc4136fabd0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,7 +43,7 @@
 #ifndef GMX_SELECTION_SELHELP_H
 #define GMX_SELECTION_SELHELP_H
 
-#include "gromacs/onlinehelp/helptopicinterface.h"
+#include "gromacs/onlinehelp/ihelptopic.h"
 
 namespace gmx
 {
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesBasicInput.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesBasicInput.xml
new file mode 100644 (file)
index 0000000..b6dab1a
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+foo = resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Variable 'foo = resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+resname RB
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection 'resname RB' parsed
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+"Name" resname RC
+]]></String>
+    <String Name="Output3"><![CDATA[
+Selection '"Name" resname RC' parsed
+> ]]></String>
+    <String Name="Input4"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesContinuation.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesContinuation.xml
new file mode 100644 (file)
index 0000000..55bba6e
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+resname RB and \
+]]></String>
+    <String Name="Output1"><![CDATA[
+... ]]></String>
+    <String Name="Input2"><![CDATA[
+resname RC
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection 'resname RB and resname RC' parsed
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesEmptySelections.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesEmptySelections.xml
new file mode 100644 (file)
index 0000000..3f50325
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+resname RA;
+]]></String>
+    <String Name="Output1"><![CDATA[
+Selection 'resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+; resname RB;;
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection 'resname RB' parsed
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+]]></String>
+    <String Name="Output3"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+Currently provided selections:
+  1. resname RA
+  2. resname RB
+> ]]></String>
+    <String Name="Input4"><![CDATA[
+;
+]]></String>
+    <String Name="Output4"><![CDATA[
+> ]]></String>
+    <String Name="Input5"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesMultiSelectionInputStatus.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesMultiSelectionInputStatus.xml
new file mode 100644 (file)
index 0000000..8a1d9bf
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+"Sel" resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Selection '"Sel" resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+"Sel2" resname RB
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection '"Sel2" resname RB' parsed
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+
+]]></String>
+    <String Name="Output3"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+Currently provided selections:
+  1. "Sel" resname RA
+  2. "Sel2" resname RB
+> ]]></String>
+    <String Name="Input4"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesMultipleSelectionsOnLine.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesMultipleSelectionsOnLine.xml
new file mode 100644 (file)
index 0000000..6f4135d
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify 2 selections for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+resname RA; resname RB and \
+]]></String>
+    <String Name="Output1"><![CDATA[
+... ]]></String>
+    <String Name="Input2"><![CDATA[
+resname RC
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection 'resname RA' parsed
+Selection 'resname RB and resname RC' parsed
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesNoFinalNewline.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesNoFinalNewline.xml
new file mode 100644 (file)
index 0000000..9555a9b
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+resname RA]]></String>
+    <String Name="Output1"><![CDATA[
+
+Selection 'resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesNoninteractiveInput.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesNoninteractiveInput.xml
new file mode 100644 (file)
index 0000000..515754e
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Input1"><![CDATA[
+foo = resname RA
+]]></String>
+    <String Name="Input2"><![CDATA[
+resname RB
+]]></String>
+    <String Name="Input3"><![CDATA[
+"Name" resname RC
+]]></String>
+    <String Name="Input4"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInput.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInput.xml
new file mode 100644 (file)
index 0000000..7e469d3
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify a selection for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+foo = resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Variable 'foo = resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+resname RA
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection 'resname RA' parsed
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInputNoninteractively.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInputNoninteractively.xml
new file mode 100644 (file)
index 0000000..32abef4
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Input1"><![CDATA[
+foo = resname RA
+]]></String>
+    <String Name="Input2"><![CDATA[
+resname RA
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInputStatus.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesSingleSelectionInputStatus.xml
new file mode 100644 (file)
index 0000000..1e83b16
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify a selection for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+foo = resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Variable 'foo = resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+
+]]></String>
+    <String Name="Output2"><![CDATA[
+Specify a selection for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+Currently provided selections:
+     foo = resname RA
+(1 more selection required)
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+resname RB
+]]></String>
+    <String Name="Output3"><![CDATA[
+Selection 'resname RB' parsed
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesStatusWithExistingSelections.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesStatusWithExistingSelections.xml
new file mode 100644 (file)
index 0000000..fc32bf7
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+
+]]></String>
+    <String Name="Output1"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+Currently provided selections:
+     foo = resname RA
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+bar = resname RC
+]]></String>
+    <String Name="Output2"><![CDATA[
+Variable 'bar = resname RC' parsed
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+resname RA
+]]></String>
+    <String Name="Output3"><![CDATA[
+Selection 'resname RA' parsed
+> ]]></String>
+    <String Name="Input4"><![CDATA[
+
+]]></String>
+    <String Name="Output4"><![CDATA[
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+Currently provided selections:
+     foo = resname RA
+     bar = resname RC
+  1. resname RA
+> ]]></String>
+    <String Name="Input5"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesStatusWithGroups.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesStatusWithGroups.xml
new file mode 100644 (file)
index 0000000..1bc4c4e
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Available static index groups:
+ Group  0 "GrpA" (5 atoms)
+ Group  1 "GrpB" (5 atoms)
+ Group  2 "GrpUnsorted" (8 atoms)
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Selection 'resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+
+]]></String>
+    <String Name="Output2"><![CDATA[
+Available static index groups:
+ Group  0 "GrpA" (5 atoms)
+ Group  1 "GrpB" (5 atoms)
+ Group  2 "GrpUnsorted" (8 atoms)
+Specify any number of selections for test context:
+(one per line, <enter> for status/groups, 'help' for help, Ctrl-D to end)
+Currently provided selections:
+  1. resname RA
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesTwoSelectionInput.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesTwoSelectionInput.xml
new file mode 100644 (file)
index 0000000..cef23d4
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify 2 selections for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Selection 'resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+resname RB
+]]></String>
+    <String Name="Output2"><![CDATA[
+Selection 'resname RB' parsed
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesTwoSelectionInputStatus.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionInteractiveTest_HandlesTwoSelectionInputStatus.xml
new file mode 100644 (file)
index 0000000..2f77680
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <InteractiveSession Name="Interactive">
+    <String Name="Output0"><![CDATA[
+Specify 2 selections for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+> ]]></String>
+    <String Name="Input1"><![CDATA[
+"Sel" resname RA
+]]></String>
+    <String Name="Output1"><![CDATA[
+Selection '"Sel" resname RA' parsed
+> ]]></String>
+    <String Name="Input2"><![CDATA[
+
+]]></String>
+    <String Name="Output2"><![CDATA[
+Specify 2 selections for test context:
+(one per line, <enter> for status/groups, 'help' for help)
+Currently provided selections:
+  1. "Sel" resname RA
+(1 more selection required)
+> ]]></String>
+    <String Name="Input3"><![CDATA[
+resname RB
+]]></String>
+    <String Name="Output3"><![CDATA[
+Selection 'resname RB' parsed
+]]></String>
+  </InteractiveSession>
+</ReferenceData>
index 1ae38d84525b8dfc62b0f5178ad9305cb3948268..b6e9bcfdb67f16b17e6b79715d4980024cf82b08 100644 (file)
@@ -68,4 +68,31 @@ and use the copy_xsl.sh script to copy it to relevant locations.
     <xsl:value-of select="."/>
 </xsl:template>
 
+<xsl:template match="InteractiveSession">
+    <pre>
+        <xsl:for-each select="*">
+            <xsl:choose>
+                <xsl:when test="starts-with(@Name, 'Output')">
+                    <xsl:value-of select="substring(.,2)"/>
+                </xsl:when>
+                <xsl:when test="string-length(.)=1">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:when>
+                <xsl:when test="contains(substring(.,2), '&#10;')">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="translate(substring(.,2), '&#10;', '&#x23ce;')"/>
+                    <xsl:text>&#10;</xsl:text>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="substring(.,2)"/>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:for-each>
+        <xsl:text>[EOF]</xsl:text>
+    </pre>
+</xsl:template>
+
 </xsl:stylesheet>
index d26d2e2b18ff1d13c151e92af80d45a3e50887e4..57048feab7ecfbd598cf2b7aa52d163c550c5929 100644 (file)
 
 <xsl:key name="SelectionName" match="ParsedSelections/ParsedSelection" use="@Name"/>
 
+<xsl:template match="InteractiveSession">
+    <h2>Interactive Session</h2>
+    <xsl:apply-imports />
+</xsl:template>
+
 <xsl:template match="ParsedSelections">
     <h2>Parsed Selections</h2>
     <table border="1">
index c04539a03fe54ac7c4631ef734fe1af79824c7e9..436abee87dafae069916d136e170ff7adefb6a08 100644 (file)
@@ -57,6 +57,7 @@
 #include "gromacs/utility/gmxregex.h"
 #include "gromacs/utility/stringutil.h"
 
+#include "testutils/interactivetest.h"
 #include "testutils/refdata.h"
 #include "testutils/testasserts.h"
 #include "testutils/testfilemanager.h"
@@ -152,6 +153,39 @@ SelectionCollectionTest::loadIndexGroups(const char *filename)
 }
 
 
+/********************************************************************
+ * Test fixture for interactive SelectionCollection tests
+ */
+
+class SelectionCollectionInteractiveTest : public SelectionCollectionTest
+{
+    public:
+        SelectionCollectionInteractiveTest()
+            : helper_(data_.rootChecker())
+        {
+        }
+
+        void runTest(int count, bool bInteractive,
+                     const gmx::ConstArrayRef<const char *> &input);
+
+        gmx::test::TestReferenceData      data_;
+        gmx::test::InteractiveTestHelper  helper_;
+};
+
+void SelectionCollectionInteractiveTest::runTest(
+        int count, bool bInteractive,
+        const gmx::ConstArrayRef<const char *> &inputLines)
+{
+    helper_.setInputLines(inputLines);
+    // TODO: Check something about the returned selections as well.
+    ASSERT_NO_THROW_GMX(sc_.parseInteractive(
+                                count, &helper_.inputStream(),
+                                bInteractive ? &helper_.outputStream() : NULL,
+                                "for test context"));
+    helper_.checkSession();
+}
+
+
 /********************************************************************
  * Test fixture for selection testing with reference data
  */
@@ -617,6 +651,150 @@ TEST_F(SelectionCollectionTest, HandlesFramesWithTooSmallAtomSubsets3)
 
 // TODO: Tests for more evaluation errors
 
+/********************************************************************
+ * Tests for interactive selection input
+ */
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesBasicInput)
+{
+    const char *const input[] = {
+        "foo = resname RA",
+        "resname RB",
+        "\"Name\" resname RC"
+    };
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesContinuation)
+{
+    const char *const input[] = {
+        "resname RB and \\",
+        "resname RC"
+    };
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesSingleSelectionInput)
+{
+    const char *const input[] = {
+        "foo = resname RA",
+        "resname RA"
+    };
+    runTest(1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesTwoSelectionInput)
+{
+    const char *const input[] = {
+        "resname RA",
+        "resname RB"
+    };
+    runTest(2, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesStatusWithGroups)
+{
+    const char *const input[] = {
+        "resname RA",
+        ""
+    };
+    loadIndexGroups("simple.ndx");
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesStatusWithExistingSelections)
+{
+    const char *const input[] = {
+        "",
+        "bar = resname RC",
+        "resname RA",
+        ""
+    };
+    ASSERT_NO_THROW_GMX(sc_.parseFromString("foo = resname RA"));
+    ASSERT_NO_THROW_GMX(sc_.parseFromString("resname RB"));
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesSingleSelectionInputStatus)
+{
+    const char *const input[] = {
+        "foo = resname RA",
+        "",
+        "resname RB"
+    };
+    runTest(1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesTwoSelectionInputStatus)
+{
+    const char *const input[] = {
+        "\"Sel\" resname RA",
+        "",
+        "resname RB"
+    };
+    runTest(2, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesMultiSelectionInputStatus)
+{
+    const char *const input[] = {
+        "\"Sel\" resname RA",
+        "\"Sel2\" resname RB",
+        ""
+    };
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesNoFinalNewline)
+{
+    // TODO: There is an extra prompt printed after the input is finished; it
+    // would be cleaner not to have it, but it's only a cosmetic issue.
+    const char *const input[] = {
+        "resname RA"
+    };
+    helper_.setLastNewline(false);
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesEmptySelections)
+{
+    const char *const input[] = {
+        "resname RA;",
+        "; resname RB;;",
+        " ",
+        ";"
+    };
+    runTest(-1, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesMultipleSelectionsOnLine)
+{
+    const char *const input[] = {
+        "resname RA; resname RB and \\",
+        "resname RC"
+    };
+    runTest(2, true, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesNoninteractiveInput)
+{
+    const char *const input[] = {
+        "foo = resname RA",
+        "resname RB",
+        "\"Name\" resname RC"
+    };
+    runTest(-1, false, input);
+}
+
+TEST_F(SelectionCollectionInteractiveTest, HandlesSingleSelectionInputNoninteractively)
+{
+    const char *const input[] = {
+        "foo = resname RA",
+        "resname RA"
+    };
+    runTest(1, false, input);
+}
+
 
 /********************************************************************
  * Tests for selection keywords
index eff1e0c3560af5c52fd69eac7fbb3c92742a0655..b98217255990bf1377a6a7a8a75cb9d28751019e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include <cstring>
 
-#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trx.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/atoms.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
index 2f7f9f9c654ebfcc2b60d03f00900900fe234439..1fce039188965e71e37c5495edc303c45718e378 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-file(GLOB STATISTICS_SOURCES statistics.c)
+file(GLOB STATISTICS_SOURCES *.cpp)
 
 set(LIBGROMACS_SOURCES
     ${LIBGROMACS_SOURCES} ${STATISTICS_SOURCES} PARENT_SCOPE)
similarity index 78%
rename from src/gromacs/statistics/statistics.c
rename to src/gromacs/statistics/statistics.cpp
index d77c231f611a09c3c6cdae657dc6f96c88d653b2..5815a45b38453d89a04d1fef059f0d2a15b4fba6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -38,7 +38,7 @@
 
 #include "statistics.h"
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/real.h"
@@ -46,7 +46,7 @@
 
 static int gmx_dnint(double x)
 {
-    return (int) (x+0.5);
+    return static_cast<int>(x+0.5);
 }
 
 typedef struct gmx_stats {
@@ -94,8 +94,7 @@ int gmx_stats_done(gmx_stats_t gstats)
 int gmx_stats_add_point(gmx_stats_t gstats, double x, double y,
                         double dx, double dy)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
-    int        i;
+    gmx_stats *stats = gstats;
 
     if (stats->np+1 >= stats->nalloc)
     {
@@ -111,7 +110,7 @@ int gmx_stats_add_point(gmx_stats_t gstats, double x, double y,
         srenew(stats->y, stats->nalloc);
         srenew(stats->dx, stats->nalloc);
         srenew(stats->dy, stats->nalloc);
-        for (i = stats->np; (i < stats->nalloc); i++)
+        for (int i = stats->np; (i < stats->nalloc); i++)
         {
             stats->x[i]  = 0;
             stats->y[i]  = 0;
@@ -132,7 +131,7 @@ int gmx_stats_add_point(gmx_stats_t gstats, double x, double y,
 int gmx_stats_get_point(gmx_stats_t gstats, real *x, real *y,
                         real *dx, real *dy, real level)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok, outlier;
     real       rmsd, r;
 
@@ -143,7 +142,7 @@ int gmx_stats_get_point(gmx_stats_t gstats, real *x, real *y,
     outlier = 0;
     while ((outlier == 0) && (stats->np_c < stats->np))
     {
-        r       = fabs(stats->x[stats->np_c] - stats->y[stats->np_c]);
+        r       = std::abs(stats->x[stats->np_c] - stats->y[stats->np_c]);
         outlier = (r > rmsd*level);
         if (outlier)
         {
@@ -180,10 +179,9 @@ int gmx_stats_get_point(gmx_stats_t gstats, real *x, real *y,
 int gmx_stats_add_points(gmx_stats_t gstats, int n, real *x, real *y,
                          real *dx, real *dy)
 {
-    int i, ok;
-
-    for (i = 0; (i < n); i++)
+    for (int i = 0; (i < n); i++)
     {
+        int ok;
         if ((ok = gmx_stats_add_point(gstats, x[i], y[i],
                                       (NULL != dx) ? dx[i] : 0,
                                       (NULL != dy) ? dy[i] : 0)) != estatsOK)
@@ -199,9 +197,9 @@ static int gmx_stats_compute(gmx_stats *stats, int weight)
     double yy, yx, xx, sx, sy, dy, chi2, chi2aa, d2;
     double ssxx, ssyy, ssxy;
     double w, wtot, yx_nw, sy_nw, sx_nw, yy_nw, xx_nw, dx2, dy2;
-    int    i, N;
 
-    N = stats->np;
+    int    N = stats->np;
+
     if (stats->computed == 0)
     {
         if (N < 1)
@@ -216,7 +214,7 @@ static int gmx_stats_compute(gmx_stats *stats, int weight)
         sy   = sy_nw = 0;
         wtot = 0;
         d2   = 0;
-        for (i = 0; (i < N); i++)
+        for (int i = 0; (i < N); i++)
         {
             d2 += dsqr(stats->x[i]-stats->y[i]);
             if ((stats->dy[i]) && (weight == elsqWEIGHT_Y))
@@ -248,11 +246,11 @@ static int gmx_stats_compute(gmx_stats *stats, int weight)
 
         /* Compute average, sigma and error */
         stats->aver       = sy_nw/N;
-        stats->sigma_aver = sqrt(yy_nw/N - dsqr(sy_nw/N));
-        stats->error      = stats->sigma_aver/sqrt(N);
+        stats->sigma_aver = std::sqrt(yy_nw/N - dsqr(sy_nw/N));
+        stats->error      = stats->sigma_aver/std::sqrt(static_cast<double>(N));
 
         /* Compute RMSD between x and y */
-        stats->rmsd = sqrt(d2/N);
+        stats->rmsd = std::sqrt(d2/N);
 
         /* Correlation coefficient for data */
         yx_nw       /= N;
@@ -263,7 +261,7 @@ static int gmx_stats_compute(gmx_stats *stats, int weight)
         ssxx         = N*(xx_nw - dsqr(sx_nw));
         ssyy         = N*(yy_nw - dsqr(sy_nw));
         ssxy         = N*(yx_nw - (sx_nw*sy_nw));
-        stats->Rdata = sqrt(dsqr(ssxy)/(ssxx*ssyy));
+        stats->Rdata = std::sqrt(dsqr(ssxy)/(ssxx*ssyy));
 
         /* Compute straight line through datapoints, either with intercept
            zero (result in aa) or with intercept variable (results in a
@@ -281,7 +279,7 @@ static int gmx_stats_compute(gmx_stats *stats, int weight)
            chi2aa which returns the deviation from a line y = ax. */
         chi2   = 0;
         chi2aa = 0;
-        for (i = 0; (i < N); i++)
+        for (int i = 0; (i < N); i++)
         {
             if (stats->dy[i] > 0)
             {
@@ -296,17 +294,16 @@ static int gmx_stats_compute(gmx_stats *stats, int weight)
         }
         if (N > 2)
         {
-            stats->chi2   = sqrt(chi2/(N-2));
-            stats->chi2aa = sqrt(chi2aa/(N-2));
+            stats->chi2   = std::sqrt(chi2/(N-2));
+            stats->chi2aa = std::sqrt(chi2aa/(N-2));
 
             /* Look up equations! */
             dx2            = (xx-sx*sx);
             dy2            = (yy-sy*sy);
-            stats->sigma_a = sqrt(stats->chi2/((N-2)*dx2));
-            stats->sigma_b = stats->sigma_a*sqrt(xx);
-            stats->Rfit    = fabs(ssxy)/sqrt(ssxx*ssyy);
-            /*stats->a*sqrt(dx2/dy2);*/
-            stats->Rfitaa  = stats->aa*sqrt(dx2/dy2);
+            stats->sigma_a = std::sqrt(stats->chi2/((N-2)*dx2));
+            stats->sigma_b = stats->sigma_a*std::sqrt(xx);
+            stats->Rfit    = std::abs(ssxy)/std::sqrt(ssxx*ssyy);
+            stats->Rfitaa  = stats->aa*std::sqrt(dx2/dy2);
         }
         else
         {
@@ -328,7 +325,7 @@ int gmx_stats_get_ab(gmx_stats_t gstats, int weight,
                      real *a, real *b, real *da, real *db,
                      real *chi2, real *Rfit)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, weight)) != estatsOK)
@@ -366,7 +363,7 @@ int gmx_stats_get_ab(gmx_stats_t gstats, int weight,
 int gmx_stats_get_a(gmx_stats_t gstats, int weight, real *a, real *da,
                     real *chi2, real *Rfit)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, weight)) != estatsOK)
@@ -395,7 +392,7 @@ int gmx_stats_get_a(gmx_stats_t gstats, int weight, real *a, real *da,
 
 int gmx_stats_get_average(gmx_stats_t gstats, real *aver)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, elsqWEIGHT_NONE)) != estatsOK)
@@ -410,7 +407,7 @@ int gmx_stats_get_average(gmx_stats_t gstats, real *aver)
 
 int gmx_stats_get_ase(gmx_stats_t gstats, real *aver, real *sigma, real *error)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, elsqWEIGHT_NONE)) != estatsOK)
@@ -436,7 +433,7 @@ int gmx_stats_get_ase(gmx_stats_t gstats, real *aver, real *sigma, real *error)
 
 int gmx_stats_get_sigma(gmx_stats_t gstats, real *sigma)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, elsqWEIGHT_NONE)) != estatsOK)
@@ -451,7 +448,7 @@ int gmx_stats_get_sigma(gmx_stats_t gstats, real *sigma)
 
 int gmx_stats_get_error(gmx_stats_t gstats, real *error)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, elsqWEIGHT_NONE)) != estatsOK)
@@ -466,7 +463,7 @@ int gmx_stats_get_error(gmx_stats_t gstats, real *error)
 
 int gmx_stats_get_corr_coeff(gmx_stats_t gstats, real *R)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, elsqWEIGHT_NONE)) != estatsOK)
@@ -481,7 +478,7 @@ int gmx_stats_get_corr_coeff(gmx_stats_t gstats, real *R)
 
 int gmx_stats_get_rmsd(gmx_stats_t gstats, real *rmsd)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
+    gmx_stats *stats = gstats;
     int        ok;
 
     if ((ok = gmx_stats_compute(stats, elsqWEIGHT_NONE)) != estatsOK)
@@ -496,10 +493,9 @@ int gmx_stats_get_rmsd(gmx_stats_t gstats, real *rmsd)
 
 int gmx_stats_dump_xy(gmx_stats_t gstats, FILE *fp)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
-    int        i, ok;
+    gmx_stats *stats = gstats;
 
-    for (i = 0; (i < stats->np); i++)
+    for (int i = 0; (i < stats->np); i++)
     {
         fprintf(fp, "%12g  %12g  %12g  %12g\n", stats->x[i], stats->y[i],
                 stats->dx[i], stats->dy[i]);
@@ -510,8 +506,8 @@ int gmx_stats_dump_xy(gmx_stats_t gstats, FILE *fp)
 
 int gmx_stats_remove_outliers(gmx_stats_t gstats, double level)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
-    int        i, iter = 1, done = 0, ok;
+    gmx_stats *stats = gstats;
+    int        iter  = 1, done = 0, ok;
     real       rmsd, r;
 
     while ((stats->np >= 10) && !done)
@@ -521,9 +517,9 @@ int gmx_stats_remove_outliers(gmx_stats_t gstats, double level)
             return ok;
         }
         done = 1;
-        for (i = 0; (i < stats->np); )
+        for (int i = 0; (i < stats->np); )
         {
-            r = fabs(stats->x[i]-stats->y[i]);
+            r = std::abs(stats->x[i]-stats->y[i]);
             if (r > level*rmsd)
             {
                 fprintf(stderr, "Removing outlier, iter = %d, rmsd = %g, x = %g, y = %g\n",
@@ -552,8 +548,8 @@ int gmx_stats_remove_outliers(gmx_stats_t gstats, double level)
 int gmx_stats_make_histogram(gmx_stats_t gstats, real binwidth, int *nb,
                              int ehisto, int normalized, real **x, real **y)
 {
-    gmx_stats *stats = (gmx_stats *) gstats;
-    int        i, ok, index = 0, nbins = *nb, *nindex;
+    gmx_stats *stats = gstats;
+    int        index = 0, nbins = *nb, *nindex;
     double     minx, maxx, maxy, miny, delta, dd, minh;
 
     if (((binwidth <= 0) && (nbins <= 0)) ||
@@ -567,7 +563,7 @@ int gmx_stats_make_histogram(gmx_stats_t gstats, real binwidth, int *nb,
     }
     minx = maxx = stats->x[0];
     miny = maxy = stats->y[0];
-    for (i = 1; (i < stats->np); i++)
+    for (int i = 1; (i < stats->np); i++)
     {
         miny = (stats->y[i] < miny) ? stats->y[i] : miny;
         maxy = (stats->y[i] > maxy) ? stats->y[i] : maxy;
@@ -599,7 +595,7 @@ int gmx_stats_make_histogram(gmx_stats_t gstats, real binwidth, int *nb,
     }
     snew(*x, nbins);
     snew(nindex, nbins);
-    for (i = 0; (i < nbins); i++)
+    for (int i = 0; (i < nbins); i++)
     {
         (*x)[i] = minh + binwidth*(i+0.5);
     }
@@ -613,15 +609,15 @@ int gmx_stats_make_histogram(gmx_stats_t gstats, real binwidth, int *nb,
     }
 
     snew(*y, nbins);
-    for (i = 0; (i < stats->np); i++)
+    for (int i = 0; (i < stats->np); i++)
     {
         if (ehisto == ehistoY)
         {
-            index = (stats->y[i]-miny)/binwidth;
+            index = static_cast<int>((stats->y[i]-miny)/binwidth);
         }
         else if (ehisto == ehistoX)
         {
-            index = (stats->x[i]-minx)/binwidth;
+            index = static_cast<int>((stats->x[i]-minx)/binwidth);
         }
         if (index < 0)
         {
@@ -638,7 +634,7 @@ int gmx_stats_make_histogram(gmx_stats_t gstats, real binwidth, int *nb,
     {
         *nb = nbins;
     }
-    for (i = 0; (i < nbins); i++)
+    for (int i = 0; (i < nbins); i++)
     {
         if (nindex[i] > 0)
         {
@@ -687,30 +683,33 @@ int lsq_y_ax(int n, real x[], real y[], real *a)
         return ok;
     }
 
-    /*  int    i;
-        double xx,yx;
-
-        yx=xx=0.0;
-        for (i=0; i<n; i++) {
-        yx+=y[i]*x[i];
-        xx+=x[i]*x[i];
-        }
-     * a=yx/xx;
-     */
     return estatsOK;
 }
 
 static int low_lsq_y_ax_b(int n, real *xr, double *xd, real yr[],
                           real *a, real *b, real *r, real *chi2)
 {
-    int         i, ok;
-    gmx_stats_t lsq;
+    gmx_stats_t lsq = gmx_stats_init();
+    int         ok;
 
-    lsq = gmx_stats_init();
-    for (i = 0; (i < n); i++)
+    for (int i = 0; (i < n); i++)
     {
-        if ((ok = gmx_stats_add_point(lsq, (NULL != xd) ? xd[i] : xr[i], yr[i], 0, 0))
-            != estatsOK)
+        double pt;
+
+        if (xd != NULL)
+        {
+            pt = xd[i];
+        }
+        else if (xr != NULL)
+        {
+            pt = xr[i];
+        }
+        else
+        {
+            gmx_incons("Either xd or xr has to be non-NULL in low_lsq_y_ax_b()");
+        }
+
+        if ((ok = gmx_stats_add_point(lsq, pt, yr[i], 0, 0)) != estatsOK)
         {
             return ok;
         }
@@ -721,42 +720,6 @@ static int low_lsq_y_ax_b(int n, real *xr, double *xd, real yr[],
     }
 
     return estatsOK;
-    /*
-       double x,y,yx,xx,yy,sx,sy,chi2;
-
-       yx=xx=yy=sx=sy=0.0;
-       for (i=0; i<n; i++) {
-       if (xd != NULL) {
-       x = xd[i];
-       } else {
-       x = xr[i];
-       }
-       y =   yr[i];
-
-       yx += y*x;
-       xx += x*x;
-       yy += y*y;
-       sx += x;
-       sy += y;
-       }
-     * a = (n*yx-sy*sx)/(n*xx-sx*sx);
-     * b = (sy-(*a)*sx)/n;
-     * r = sqrt((xx-sx*sx)/(yy-sy*sy));
-
-       chi2 = 0;
-       if (xd != NULL) {
-       for(i=0; i<n; i++)
-       chi2 += dsqr(yr[i] - ((*a)*xd[i] + (*b)));
-       } else {
-       for(i=0; i<n; i++)
-       chi2 += dsqr(yr[i] - ((*a)*xr[i] + (*b)));
-       }
-
-       if (n > 2)
-       return sqrt(chi2/(n-2));
-       else
-       return 0;
-     */
 }
 
 int lsq_y_ax_b(int n, real x[], real y[], real *a, real *b, real *r, real *chi2)
@@ -774,11 +737,10 @@ int lsq_y_ax_b_error(int n, real x[], real y[], real dy[],
                      real *a, real *b, real *da, real *db,
                      real *r, real *chi2)
 {
-    gmx_stats_t lsq;
-    int         i, ok;
+    gmx_stats_t lsq = gmx_stats_init();
+    int         ok;
 
-    lsq = gmx_stats_init();
-    for (i = 0; (i < n); i++)
+    for (int i = 0; (i < n); i++)
     {
         if ((ok = gmx_stats_add_point(lsq, x[i], y[i], 0, dy[i])) != estatsOK)
         {
@@ -796,52 +758,4 @@ int lsq_y_ax_b_error(int n, real x[], real y[], real dy[],
     sfree(lsq);
 
     return estatsOK;
-    /*
-       double sxy,sxx,syy,sx,sy,w,s_2,dx2,dy2,mins;
-
-       sxy=sxx=syy=sx=sy=w=0.0;
-       mins = dy[0];
-       for(i=1; (i<n); i++)
-       mins = min(mins,dy[i]);
-       if (mins <= 0)
-       gmx_fatal(FARGS,"Zero or negative weigths in linear regression analysis");
-
-       for (i=0; i<n; i++) {
-       s_2  = dsqr(1.0/dy[i]);
-       sxx += s_2*dsqr(x[i]);
-       sxy += s_2*y[i]*x[i];
-       syy += s_2*dsqr(y[i]);
-       sx  += s_2*x[i];
-       sy  += s_2*y[i];
-       w   += s_2;
-       }
-       sxx = sxx/w;
-       sxy = sxy/w;
-       syy = syy/w;
-       sx  = sx/w;
-       sy  = sy/w;
-       dx2 = (sxx-sx*sx);
-       dy2 = (syy-sy*sy);
-     * a=(sxy-sy*sx)/dx2;
-     * b=(sy-(*a)*sx);
-
-     * chi2=0;
-       for(i=0; i<n; i++)
-     * chi2+=dsqr((y[i]-((*a)*x[i]+(*b)))/dy[i]);
-     * chi2 = *chi2/w;
-
-     * da = sqrt(*chi2/((n-2)*dx2));
-     * db = *da*sqrt(sxx);
-     * r  = *a*sqrt(dx2/dy2);
-
-       if (debug)
-       fprintf(debug,"sx = %g, sy = %g, sxy = %g, sxx = %g, w = %g\n"
-       "chi2 = %g, dx2 = %g\n",
-       sx,sy,sxy,sxx,w,*chi2,dx2);
-
-       if (n > 2)
-     * chi2 = sqrt(*chi2/(n-2));
-       else
-     * chi2 = 0;
-     */
 }
diff --git a/src/gromacs/statistics/statistics_test.c b/src/gromacs/statistics/statistics_test.c
deleted file mode 100644 (file)
index 4b3dbf8..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2011,2014, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include <stdio.h>
-
-#include "gromacs/math/vec.h"
-#include "gromacs/random/random.h"
-#include "gromacs/statistics/statistics.h"
-#include "gromacs/utility/real.h"
-#include "gromacs/utility/smalloc.h"
-
-static void horizontal()
-{
-    gmx_rng_t   rng;
-    gmx_stats_t straight;
-    int         i, ok, n = 1000;
-    real        y, a, b, da, db, aver, sigma, error, chi2, R, *xh, *yh;
-    FILE       *fp;
-
-    rng      = gmx_rng_init(13);
-    straight = gmx_stats_init();
-    for (i = 0; (i < n); i++)
-    {
-        y = gmx_rng_uniform_real(rng);
-        if ((ok = gmx_stats_add_point(straight, i, y, 0, 0)) != estatsOK)
-        {
-            fprintf(stderr, "%s\n", gmx_stats_message(ok));
-        }
-    }
-    /* Horizontal test */
-    if ((ok = gmx_stats_get_ase(straight, &aver, &sigma, &error)) != estatsOK)
-    {
-        fprintf(stderr, "%s\n", gmx_stats_message(ok));
-    }
-    fp = fopen("straight.xvg", "w");
-    if ((ok = gmx_stats_dump_xy(straight, fp)) != estatsOK)
-    {
-        fprintf(stderr, "%s\n", gmx_stats_message(ok));
-    }
-    fclose(fp);
-    printf("Horizontal line: average %g, sigma %g, error %g\n", aver, sigma, error);
-    if ((ok = gmx_stats_done(straight)) != estatsOK)
-    {
-        fprintf(stderr, "%s\n", gmx_stats_message(ok));
-    }
-}
-
-static void line()
-{
-    gmx_rng_t   rng;
-    gmx_stats_t line;
-    int         i, dy, ok, n = 1000;
-    real        y, a, b, da, db, aver, sigma, error, chi2, R, rfit;
-    const real  a0 = 0.23, b0 = 2.7;
-    FILE       *fp;
-
-    for (dy = 0; (dy < 2); dy++)
-    {
-        rng      = gmx_rng_init(13);
-        line     = gmx_stats_init();
-        for (i = 0; (i < n); i++)
-        {
-            y = a0*i+b0+50*(gmx_rng_uniform_real(rng)-0.5);
-            if ((ok = gmx_stats_add_point(line, i, y, 0, dy*0.1)) != estatsOK)
-            {
-                fprintf(stderr, "%s\n", gmx_stats_message(ok));
-            }
-        }
-        /* Line with slope test */
-        if ((ok = gmx_stats_get_ab(line, elsqWEIGHT_NONE, &a, &b, &da, &db, &chi2, &rfit)) != estatsOK)
-        {
-            fprintf(stderr, "%s\n", gmx_stats_message(ok));
-        }
-        if ((ok = gmx_stats_get_corr_coeff(line, &R)) != estatsOK)
-        {
-            fprintf(stderr, "%s\n", gmx_stats_message(ok));
-        }
-        if (dy == 0)
-        {
-            fp = fopen("line0.xvg", "w");
-        }
-        else
-        {
-            fp = fopen("line1.xvg", "w");
-        }
-        if ((ok = gmx_stats_dump_xy(line, fp)) != estatsOK)
-        {
-            fprintf(stderr, "%s\n", gmx_stats_message(ok));
-        }
-        fclose(fp);
-        printf("Line with eqn. y = %gx + %g with noise%s\n", a0, b0,
-               (dy == 0) ? "" : " and uncertainties");
-        printf("Found: a = %g +/- %g, b = %g +/- %g\n", a, da, b, db);
-        if ((ok = gmx_stats_done(line)) != estatsOK)
-        {
-            fprintf(stderr, "%s\n", gmx_stats_message(ok));
-        }
-        gmx_rng_destroy(rng);
-    }
-}
-
-static void histogram()
-{
-    gmx_rng_t   rng;
-    gmx_stats_t camel;
-    int         i, ok, n = 1000, norm;
-    real        y, a, b, da, db, aver, sigma, error, chi2, R, *xh, *yh;
-    const real  a0 = 0.23, b0 = 2.7;
-    FILE       *fp;
-    char        fn[256];
-
-    for (norm = 0; (norm < 2); norm++)
-    {
-        rng      = gmx_rng_init(13);
-        camel    = gmx_stats_init();
-        for (i = 0; (i < n); i++)
-        {
-            y = sqr(gmx_rng_uniform_real(rng));
-            if ((ok = gmx_stats_add_point(camel, i, y+1, 0, 0)) != estatsOK)
-            {
-                fprintf(stderr, "%s\n", gmx_stats_message(ok));
-            }
-            y = sqr(gmx_rng_uniform_real(rng));
-            if ((ok = gmx_stats_add_point(camel, i+0.5, y+2, 0, 0)) != estatsOK)
-            {
-                fprintf(stderr, "%s\n", gmx_stats_message(ok));
-            }
-        }
-        /* Histogram test */
-        if ((ok = gmx_stats_make_histogram(camel, 0, 101, norm, &xh, &yh)) != estatsOK)
-        {
-            fprintf(stderr, "%s\n", gmx_stats_message(ok));
-        }
-        sprintf(fn, "histo%d-data.xvg", norm);
-        fp = fopen(fn, "w");
-        gmx_stats_dump_xy(camel, fp);
-        fclose(fp);
-        sprintf(fn, "histo%d.xvg", norm);
-        fp = fopen(fn, "w");
-        for (i = 0; (i < 101); i++)
-        {
-            fprintf(fp, "%12g  %12g\n", xh[i], yh[i]);
-        }
-        fclose(fp);
-        sfree(xh);
-        sfree(yh);
-    }
-}
-
-int main(int argc, char *argv[])
-{
-    line();
-    horizontal();
-    histogram();
-
-    return 0;
-}
index 6d1d944600274446a79f1b2130c3a924d94811a1..6314bbedf8f20e32b9d0f51c95073deb91bd36f9 100644 (file)
@@ -49,6 +49,7 @@
 #include <time.h>
 
 #include "gromacs/fileio/confio.h"
+#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/copyrite.h"
 #include "gromacs/legacyheaders/macros.h"
index ceec518fe6a0b676c3bdbaae0d708bbe3c511021..061fcf2168067e3762951214c67d1e13c90dc179 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-file(GLOB TOOLS_SOURCES *.cpp *.c)
+file(GLOB TOOLS_SOURCES *.cpp)
 set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${TOOLS_SOURCES} PARENT_SCOPE)
 
 if (BUILD_TESTING)
similarity index 97%
rename from src/gromacs/tools/check.c
rename to src/gromacs/tools/check.cpp
index d54b84ce1408df1de6d8933bd9a2eacfc6d598f6..0c34c66cb142f9d418ecef8106a38e07a2d86ab7 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/enxio.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -85,7 +84,7 @@ typedef struct {
 
 static void tpx2system(FILE *fp, gmx_mtop_t *mtop)
 {
-    int                       i, nmol, nvsite = 0;
+    int                       nmol, nvsite = 0;
     gmx_mtop_atomloop_block_t aloop;
     t_atom                   *atom;
 
@@ -144,7 +143,6 @@ static void tpx2params(FILE *fp, t_inputrec *ir)
 static void tpx2methods(const char *tpx, const char *tex)
 {
     FILE         *fp;
-    t_tpxheader   sh;
     t_inputrec    ir;
     t_state       state;
     gmx_mtop_t    mtop;
@@ -223,12 +221,11 @@ static void chk_forces(int frame, int natoms, rvec *f)
 
 static void chk_bonds(t_idef *idef, int ePBC, rvec *x, matrix box, real tol)
 {
-    int   ftype, i, k, ai, aj, type;
-    real  b0, blen, deviation, devtot;
+    int   ftype, k, ai, aj, type;
+    real  b0, blen, deviation;
     t_pbc pbc;
     rvec  dx;
 
-    devtot = 0;
     set_pbc(&pbc, ePBC, box);
     for (ftype = 0; (ftype < F_NRE); ftype++)
     {
@@ -246,7 +243,7 @@ static void chk_bonds(t_idef *idef, int ePBC, rvec *x, matrix box, real tol)
                         b0 = idef->iparams[type].harmonic.rA;
                         break;
                     case F_G96BONDS:
-                        b0 = sqrt(idef->iparams[type].harmonic.rA);
+                        b0 = std::sqrt(idef->iparams[type].harmonic.rA);
                         break;
                     case F_MORSE:
                         b0 = idef->iparams[type].morse.b0A;
@@ -265,7 +262,7 @@ static void chk_bonds(t_idef *idef, int ePBC, rvec *x, matrix box, real tol)
                     pbc_dx(&pbc, x[ai], x[aj], dx);
                     blen      = norm(dx);
                     deviation = sqr(blen-b0);
-                    if (sqrt(deviation/sqr(b0) > tol))
+                    if (std::sqrt(deviation/sqr(b0)) > tol)
                     {
                         fprintf(stderr, "Distance between atoms %d and %d is %.3f, should be %.3f\n", ai+1, aj+1, blen, b0);
                     }
@@ -281,8 +278,8 @@ void chk_trj(const output_env_t oenv, const char *fn, const char *tpr, real tol)
     t_count          count;
     t_fr_time        first, last;
     int              j = -1, new_natoms, natoms;
-    real             rdum, tt, old_t1, old_t2, prec;
-    gmx_bool         bShowTimestep = TRUE, bOK, newline = FALSE;
+    real             old_t1, old_t2;
+    gmx_bool         bShowTimestep = TRUE, newline = FALSE;
     t_trxstatus     *status;
     gmx_mtop_t       mtop;
     gmx_localtop_t  *top = NULL;
@@ -549,7 +546,7 @@ void chk_tps(const char *fn, real vdw_fac, real bon_lo, real bon_hi)
                             *(atoms->resinfo[atoms->atom[j].resind].name),
                             atoms->resinfo[atoms->atom[j].resind].nr,
                             atom_vdw[j],
-                            sqrt(r2) );
+                            std::sqrt(r2) );
                 }
             }
         }
@@ -616,7 +613,7 @@ void chk_ndx(const char *fn)
 {
     t_blocka *grps;
     char    **grpname;
-    int       i, j;
+    int       i;
 
     grps = init_index(fn, &grpname);
     if (debug)
@@ -646,7 +643,7 @@ void chk_ndx(const char *fn)
 
 void chk_enx(const char *fn)
 {
-    int            nre, fnr, ndr;
+    int            nre, fnr;
     ener_file_t    in;
     gmx_enxnm_t   *enm = NULL;
     t_enxframe    *fr;
index 3eb6acd56f68f3112be85e6e1a6269a7ac4a00d5..435cd0d88ad0cd918827208e96a2ad6efb88109f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_TOOLS_CHECK_H
 #define GMX_TOOLS_CHECK_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 /*! \brief Implements gmx check
  *
  * \param[in] argc  argc value passed to main().
@@ -49,8 +42,4 @@ extern "C" {
  */
 int gmx_check(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 96%
rename from src/gromacs/tools/compare.c
rename to src/gromacs/tools/compare.cpp
index 975b62f53697e3e5335b22f24e159683cef54754..bdbd351d3157bcb5d12b36c49ba5e89678386014 100644 (file)
  * the research papers on the package. Check out http://www.gromacs.org.
  */
 /* This file is completely threadsafe - keep it that way! */
+
 #include "gmxpre.h"
 
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+
+#include <algorithm>
 
 #include "gromacs/fileio/enxio.h"
 #include "gromacs/fileio/tpxio.h"
@@ -73,9 +76,9 @@ static void cmp_int64(FILE *fp, const char *s, gmx_int64_t i1, gmx_int64_t i2)
     if (i1 != i2)
     {
         fprintf(fp, "%s (", s);
-        fprintf(fp, "%"GMX_PRId64, i1);
+        fprintf(fp, "%" GMX_PRId64, i1);
         fprintf(fp, " - ");
-        fprintf(fp, "%"GMX_PRId64, i2);
+        fprintf(fp, "%" GMX_PRId64, i2);
         fprintf(fp, ")\n");
     }
 }
@@ -147,7 +150,7 @@ static gmx_bool cmp_bool(FILE *fp, const char *s, int index, gmx_bool b1, gmx_bo
 static void cmp_str(FILE *fp, const char *s, int index,
                     const char *s1, const char *s2)
 {
-    if (strcmp(s1, s2) != 0)
+    if (std::strcmp(s1, s2) != 0)
     {
         if (index != -1)
         {
@@ -347,7 +350,7 @@ static void cmp_idef(FILE *fp, t_idef *id1, t_idef *id2, real ftol, real abstol)
     {
         cmp_int(fp, "idef->ntypes", -1, id1->ntypes, id2->ntypes);
         cmp_int(fp, "idef->atnr",  -1, id1->atnr, id2->atnr);
-        for (i = 0; (i < min(id1->ntypes, id2->ntypes)); i++)
+        for (i = 0; (i < std::min(id1->ntypes, id2->ntypes)); i++)
         {
             sprintf(buf1, "idef->functype[%d]", i);
             sprintf(buf2, "idef->iparam[%d]", i);
@@ -372,7 +375,6 @@ static void cmp_idef(FILE *fp, t_idef *id1, t_idef *id2, real ftol, real abstol)
 
 static void cmp_block(FILE *fp, t_block *b1, t_block *b2, const char *s)
 {
-    int  i, j, k;
     char buf[32];
 
     fprintf(fp, "comparing block %s\n", s);
@@ -382,7 +384,6 @@ static void cmp_block(FILE *fp, t_block *b1, t_block *b2, const char *s)
 
 static void cmp_blocka(FILE *fp, t_blocka *b1, t_blocka *b2, const char *s)
 {
-    int  i, j, k;
     char buf[32];
 
     fprintf(fp, "comparing blocka %s\n", s);
@@ -394,9 +395,6 @@ static void cmp_blocka(FILE *fp, t_blocka *b1, t_blocka *b2, const char *s)
 
 static void cmp_atom(FILE *fp, int index, t_atom *a1, t_atom *a2, real ftol, real abstol)
 {
-    int  i;
-    char buf[256];
-
     if (a2)
     {
         cmp_us(fp, "atom.type", index, a1->type, a2->type);
@@ -442,8 +440,6 @@ static void cmp_atoms(FILE *fp, t_atoms *a1, t_atoms *a2, real ftol, real abstol
 
 static void cmp_top(FILE *fp, t_topology *t1, t_topology *t2, real ftol, real abstol)
 {
-    int i;
-
     fprintf(fp, "comparing top\n");
     if (t2)
     {
@@ -464,7 +460,7 @@ static void cmp_top(FILE *fp, t_topology *t1, t_topology *t2, real ftol, real ab
 static void cmp_groups(FILE *fp, gmx_groups_t *g0, gmx_groups_t *g1,
                        int natoms0, int natoms1)
 {
-    int  i, j, ndiff;
+    int  i, j;
     char buf[32];
 
     fprintf(fp, "comparing groups\n");
@@ -515,7 +511,7 @@ static void cmp_rvecs(FILE *fp, const char *title, int n, rvec x1[], rvec x2[],
                 ssd += d*d;
             }
         }
-        fprintf(fp, "%s RMSD %g\n", title, sqrt(ssd/n));
+        fprintf(fp, "%s RMSD %g\n", title, std::sqrt(ssd/n));
     }
     else
     {
@@ -562,7 +558,7 @@ static void cmp_rvecs_rmstol(FILE *fp, const char *title, int n, rvec x1[], rvec
             rms_x1 += d*d;
         }
     }
-    rms_x1 = sqrt(rms_x1/(DIM*n));
+    rms_x1 = std::sqrt(rms_x1/(DIM*n));
     /* And now do the actual comparision with a hopefully realistic abstol. */
     for (i = 0; (i < n); i++)
     {
@@ -579,7 +575,7 @@ static void cmp_grpopts(FILE *fp, t_grpopts *opt1, t_grpopts *opt2, real ftol, r
     cmp_int(fp, "inputrec->grpopts.ngacc", -1, opt1->ngacc, opt2->ngacc);
     cmp_int(fp, "inputrec->grpopts.ngfrz", -1, opt1->ngfrz, opt2->ngfrz);
     cmp_int(fp, "inputrec->grpopts.ngener", -1, opt1->ngener, opt2->ngener);
-    for (i = 0; (i < min(opt1->ngtc, opt2->ngtc)); i++)
+    for (i = 0; (i < std::min(opt1->ngtc, opt2->ngtc)); i++)
     {
         cmp_real(fp, "inputrec->grpopts.nrdf", i, opt1->nrdf[i], opt2->nrdf[i], ftol, abstol);
         cmp_real(fp, "inputrec->grpopts.ref_t", i, opt1->ref_t[i], opt2->ref_t[i], ftol, abstol);
@@ -611,11 +607,11 @@ static void cmp_grpopts(FILE *fp, t_grpopts *opt1, t_grpopts *opt2, real ftol, r
             }
         }
     }
-    for (i = 0; (i < min(opt1->ngacc, opt2->ngacc)); i++)
+    for (i = 0; (i < std::min(opt1->ngacc, opt2->ngacc)); i++)
     {
         cmp_rvec(fp, "inputrec->grpopts.acc", i, opt1->acc[i], opt2->acc[i], ftol, abstol);
     }
-    for (i = 0; (i < min(opt1->ngfrz, opt2->ngfrz)); i++)
+    for (i = 0; (i < std::min(opt1->ngfrz, opt2->ngfrz)); i++)
     {
         cmp_ivec(fp, "inputrec->grpopts.nFreeze", i, opt1->nFreeze[i], opt2->nFreeze[i]);
     }
@@ -630,7 +626,7 @@ static void cmp_cosines(FILE *fp, const char *s, t_cosines c1[DIM], t_cosines c2
     {
         sprintf(buf, "inputrec->%s[%d]", s, m);
         cmp_int(fp, buf, 0, c1->n, c2->n);
-        for (i = 0; (i < min(c1->n, c2->n)); i++)
+        for (i = 0; (i < std::min(c1->n, c2->n)); i++)
         {
             cmp_real(fp, buf, i, c1->a[i], c2->a[i], ftol, abstol);
             cmp_real(fp, buf, i, c1->phi[i], c2->phi[i], ftol, abstol);
@@ -712,7 +708,7 @@ static void cmp_fepvals(FILE *fp, t_lambda *fep1, t_lambda *fep2, real ftol, rea
     cmp_int(fp, "inputrec->fepvals->n_lambda", -1, fep1->n_lambda, fep2->n_lambda);
     for (i = 0; i < efptNR; i++)
     {
-        for (j = 0; j < min(fep1->n_lambda, fep2->n_lambda); j++)
+        for (j = 0; j < std::min(fep1->n_lambda, fep2->n_lambda); j++)
         {
             cmp_double(fp, "inputrec->fepvals->all_lambda", -1, fep1->all_lambda[i][j], fep2->all_lambda[i][j], ftol, abstol);
         }
@@ -822,12 +818,12 @@ static void cmp_inputrec(FILE *fp, t_inputrec *ir1, t_inputrec *ir2, real ftol,
     cmp_int(fp, "inputrec->bSimTemp", -1, ir1->bSimTemp, ir2->bSimTemp);
     if ((ir1->bSimTemp == ir2->bSimTemp) && (ir1->bSimTemp))
     {
-        cmp_simtempvals(fp, ir1->simtempvals, ir2->simtempvals, min(ir1->fepvals->n_lambda, ir2->fepvals->n_lambda), ftol, abstol);
+        cmp_simtempvals(fp, ir1->simtempvals, ir2->simtempvals, std::min(ir1->fepvals->n_lambda, ir2->fepvals->n_lambda), ftol, abstol);
     }
     cmp_int(fp, "inputrec->bExpanded", -1, ir1->bExpanded, ir2->bExpanded);
     if ((ir1->bExpanded == ir2->bExpanded) && (ir1->bExpanded))
     {
-        cmp_expandedvals(fp, ir1->expandedvals, ir2->expandedvals, min(ir1->fepvals->n_lambda, ir2->fepvals->n_lambda), ftol, abstol);
+        cmp_expandedvals(fp, ir1->expandedvals, ir2->expandedvals, std::min(ir1->fepvals->n_lambda, ir2->fepvals->n_lambda), ftol, abstol);
     }
     cmp_int(fp, "inputrec->nwall", -1, ir1->nwall, ir2->nwall);
     cmp_int(fp, "inputrec->wall_type", -1, ir1->wall_type, ir2->wall_type);
@@ -976,7 +972,6 @@ void comp_tpx(const char *fn1, const char *fn2,
               gmx_bool bRMSD, real ftol, real abstol)
 {
     const char  *ff[2];
-    t_tpxheader  sh[2];
     t_inputrec   ir[2];
     t_state      state[2];
     gmx_mtop_t   mtop[2];
@@ -1060,21 +1055,21 @@ void comp_frame(FILE *fp, t_trxframe *fr1, t_trxframe *fr2,
     }
     if (cmp_bool(fp, "bX", -1, fr1->bX, fr2->bX))
     {
-        cmp_rvecs(fp, "x", min(fr1->natoms, fr2->natoms), fr1->x, fr2->x, bRMSD, ftol, abstol);
+        cmp_rvecs(fp, "x", std::min(fr1->natoms, fr2->natoms), fr1->x, fr2->x, bRMSD, ftol, abstol);
     }
     if (cmp_bool(fp, "bV", -1, fr1->bV, fr2->bV))
     {
-        cmp_rvecs(fp, "v", min(fr1->natoms, fr2->natoms), fr1->v, fr2->v, bRMSD, ftol, abstol);
+        cmp_rvecs(fp, "v", std::min(fr1->natoms, fr2->natoms), fr1->v, fr2->v, bRMSD, ftol, abstol);
     }
     if (cmp_bool(fp, "bF", -1, fr1->bF, fr2->bF))
     {
         if (bRMSD)
         {
-            cmp_rvecs(fp, "f", min(fr1->natoms, fr2->natoms), fr1->f, fr2->f, bRMSD, ftol, abstol);
+            cmp_rvecs(fp, "f", std::min(fr1->natoms, fr2->natoms), fr1->f, fr2->f, bRMSD, ftol, abstol);
         }
         else
         {
-            cmp_rvecs_rmstol(fp, "f", min(fr1->natoms, fr2->natoms), fr1->f, fr2->f, ftol, abstol);
+            cmp_rvecs_rmstol(fp, "f", std::min(fr1->natoms, fr2->natoms), fr1->f, fr2->f, ftol, abstol);
         }
     }
     if (cmp_bool(fp, "bBox", -1, fr1->bBox, fr2->bBox))
@@ -1133,25 +1128,25 @@ static real ener_tensor_diag(int n, int *ind1, int *ind2,
                              int *tensi, int i,
                              t_energy e1[], t_energy e2[])
 {
-    int  d1, d2;
-    int  len;
-    int  j;
-    real prod1, prod2;
-    int  nfound;
+    int    d1, d2;
+    int    j;
+    real   prod1, prod2;
+    int    nfound;
+    size_t len;
 
     d1 = tensi[i]/DIM;
     d2 = tensi[i] - d1*DIM;
 
     /* Find the diagonal elements d1 and d2 */
-    len    = strlen(enm1[ind1[i]].name);
+    len    = std::strlen(enm1[ind1[i]].name);
     prod1  = 1;
     prod2  = 1;
     nfound = 0;
     for (j = 0; j < n; j++)
     {
         if (tensi[j] >= 0 &&
-            strlen(enm1[ind1[j]].name) == len &&
-            strncmp(enm1[ind1[i]].name, enm1[ind1[j]].name, len-2) == 0 &&
+            std::strlen(enm1[ind1[j]].name) == len &&
+            std::strncmp(enm1[ind1[i]].name, enm1[ind1[j]].name, len-2) == 0 &&
             (tensi[j] == d1*DIM+d1 || tensi[j] == d2*DIM+d2))
         {
             prod1 *= fabs(e1[ind1[j]].e);
@@ -1162,7 +1157,7 @@ static real ener_tensor_diag(int n, int *ind1, int *ind2,
 
     if (nfound == 2)
     {
-        return 0.5*(sqrt(prod1) + sqrt(prod2));
+        return 0.5*(std::sqrt(prod1) + std::sqrt(prod2));
     }
     else
     {
@@ -1174,15 +1169,15 @@ static gmx_bool enernm_equal(const char *nm1, const char *nm2)
 {
     int len1, len2;
 
-    len1 = strlen(nm1);
-    len2 = strlen(nm2);
+    len1 = std::strlen(nm1);
+    len2 = std::strlen(nm2);
 
     /* Remove " (bar)" at the end of a name */
-    if (len1 > 6 && strcmp(nm1+len1-6, " (bar)") == 0)
+    if (len1 > 6 && std::strcmp(nm1+len1-6, " (bar)") == 0)
     {
         len1 -= 6;
     }
-    if (len2 > 6 && strcmp(nm2+len2-6, " (bar)") == 0)
+    if (len2 > 6 && std::strcmp(nm2+len2-6, " (bar)") == 0)
     {
         len2 -= 6;
     }
@@ -1206,7 +1201,7 @@ static void cmp_energies(FILE *fp, int step1, int step2,
     {
         ii       = ind1[i];
         tensi[i] = -1;
-        len      = strlen(enm1[ii].name);
+        len      = std::strlen(enm1[ii].name);
         if (len > 3 && enm1[ii].name[len-3] == '-')
         {
             d1 = enm1[ii].name[len-2] - 'X';
@@ -1238,7 +1233,7 @@ static void cmp_energies(FILE *fp, int step1, int step2,
             if (abstol_i > 0)
             {
                 /* We found a diagonal, we need to check with the minimum tolerance */
-                abstol_i = min(abstol_i, abstol);
+                abstol_i = std::min(abstol_i, abstol);
             }
             else
             {
@@ -1374,10 +1369,9 @@ static void cmp_eblocks(t_enxframe *fr1, t_enxframe *fr2, real ftol, real abstol
 
 void comp_enx(const char *fn1, const char *fn2, real ftol, real abstol, const char *lastener)
 {
-    int            nre, nre1, nre2, block;
+    int            nre, nre1, nre2;
     ener_file_t    in1, in2;
     int            i, j, maxener, *ind1, *ind2, *have;
-    char           buf[256];
     gmx_enxnm_t   *enm1 = NULL, *enm2 = NULL;
     t_enxframe    *fr1, *fr2;
     gmx_bool       b1, b2;
@@ -1431,7 +1425,7 @@ void comp_enx(const char *fn1, const char *fn2, real ftol, real abstol, const ch
     maxener = nre;
     for (i = 0; i < nre; i++)
     {
-        if ((lastener != NULL) && (strstr(enm1[i].name, lastener) != NULL))
+        if ((lastener != NULL) && (std::strstr(enm1[i].name, lastener) != NULL))
         {
             maxener = i+1;
             break;
similarity index 97%
rename from src/gromacs/tools/convert_tpr.c
rename to src/gromacs/tools/convert_tpr.cpp
index 94e24ffe32832132bd41dd248c7fad02c89ebef2..01c772c9c2bfb1ccd16eb3f09648ada47b725587 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/enxio.h"
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/gmxpreprocess/readir.h"
 #include "gromacs/legacyheaders/checkpoint.h"
 #include "gromacs/legacyheaders/macros.h"
@@ -54,6 +54,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
@@ -349,9 +350,9 @@ int gmx_convert_tpr(int argc, char *argv[])
     };
 
     const char       *top_fn, *frame_fn;
-    t_fileio         *fp;
+    struct t_fileio  *fp;
     ener_file_t       fp_ener = NULL;
-    t_trnheader       head;
+    gmx_trr_header_t  head;
     int               i;
     gmx_int64_t       nsteps_req, run_step, frame;
     double            run_t, state_t;
@@ -359,8 +360,7 @@ int gmx_convert_tpr(int argc, char *argv[])
     gmx_bool          bFrame, bUse, bSel, bNeedEner, bReadEner, bScanEner, bFepState;
     gmx_mtop_t        mtop;
     t_atoms           atoms;
-    t_inputrec       *ir, *irnew = NULL;
-    t_gromppopts     *gopts;
+    t_inputrec       *ir;
     t_state           state;
     rvec             *newx = NULL, *newv = NULL, *tmpx, *tmpv;
     matrix            newbox;
@@ -404,7 +404,6 @@ int gmx_convert_tpr(int argc, char *argv[])
         { "-init_fep_state", FALSE, etINT, {&init_fep_state},
           "fep state to initialize from" },
     };
-    int             nerror = 0;
 
     /* Parse the command line */
     if (!parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa,
@@ -466,9 +465,9 @@ int gmx_convert_tpr(int argc, char *argv[])
 
         if (EI_SD(ir->eI) || ir->eI == eiBD)
         {
-            fprintf(stderr, "\nChanging ld-seed from %"GMX_PRId64 " ", ir->ld_seed);
+            fprintf(stderr, "\nChanging ld-seed from %" GMX_PRId64 " ", ir->ld_seed);
             ir->ld_seed = (gmx_int64_t)gmx_rng_make_seed();
-            fprintf(stderr, "to %"GMX_PRId64 "\n\n", ir->ld_seed);
+            fprintf(stderr, "to %" GMX_PRId64 "\n\n", ir->ld_seed);
         }
 
         frame_fn = ftp2fn(efTRN, NFILE, fnm);
@@ -490,7 +489,7 @@ int gmx_convert_tpr(int argc, char *argv[])
                     "\nREADING COORDS, VELS AND BOX FROM TRAJECTORY %s...\n\n",
                     frame_fn);
 
-            fp = open_trn(frame_fn, "r");
+            fp = gmx_trr_open(frame_fn, "r");
             if (bScanEner)
             {
                 fp_ener = open_enx(ftp2fn(efEDR, NFILE, fnm), "r");
@@ -506,7 +505,7 @@ int gmx_convert_tpr(int argc, char *argv[])
             frame  = 0;
             while (bFrame)
             {
-                bFrame = fread_trnheader(fp, &head, &bOK);
+                bFrame = gmx_trr_read_frame_header(fp, &head, &bOK);
                 if (bOK && frame == 0)
                 {
                     if (mtop.natoms != head.natoms)
@@ -521,7 +520,7 @@ int gmx_convert_tpr(int argc, char *argv[])
                 bFrame = bFrame && bOK;
                 if (bFrame)
                 {
-                    bOK = fread_htrn(fp, &head, newbox, newx, newv, NULL);
+                    bOK = gmx_trr_read_frame_data(fp, &head, newbox, newx, newv, NULL);
                 }
                 bFrame = bFrame && bOK;
                 bUse   = FALSE;
@@ -573,7 +572,7 @@ int gmx_convert_tpr(int argc, char *argv[])
                 free_enxframe(fr_ener);
                 free_enxnms(nre, enm);
             }
-            close_trn(fp);
+            gmx_trr_close(fp);
             fprintf(stderr, "\n");
 
             if (!bOK)
index bb7fc46c445bb55f2f4219956b5eea05451a3ece..23c52ffa7e3ceff1cf8163e6fc502e05b99968fa 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_TOOLS_CONVERT_TPR_H
 #define GMX_TOOLS_CONVERT_TPR_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 /*! \brief Implements gmx convert-tpr
  *
  * \param[in] argc  argc value passed to main().
@@ -49,8 +42,4 @@ extern "C" {
  */
 int gmx_convert_tpr(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
similarity index 92%
rename from src/gromacs/tools/dump.c
rename to src/gromacs/tools/dump.cpp
index b3ac4582c84b94e1ebf2ed481e5f6fa16ee88e27..305abf88f6153b6b70d647118f87190700cd105f 100644 (file)
 
 #include "config.h"
 
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cassert>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/enxio.h"
@@ -50,7 +50,7 @@
 #include "gromacs/fileio/tngio.h"
 #include "gromacs/fileio/tngio_for_tools.h"
 #include "gromacs/fileio/tpxio.h"
-#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/trrio.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/gmxpreprocess/gmxcpp.h"
 #include "gromacs/legacyheaders/checkpoint.h"
@@ -67,7 +67,7 @@ static void list_tpx(const char *fn, gmx_bool bShowNumbers, const char *mdpfn,
                      gmx_bool bSysTop)
 {
     FILE         *gp;
-    int           fp, indent, i, j, **gcount, atot;
+    int           indent, i, j, **gcount, atot;
     t_state       state;
     rvec         *f = NULL;
     t_inputrec    ir;
@@ -100,10 +100,9 @@ static void list_tpx(const char *fn, gmx_bool bShowNumbers, const char *mdpfn,
         if (available(stdout, &tpx, 0, fn))
         {
             indent = 0;
-            indent = pr_title(stdout, indent, fn);
+            pr_title(stdout, indent, fn);
             pr_inputrec(stdout, 0, "inputrec", tpx.bIr ? &(ir) : NULL, FALSE);
 
-            indent = 0;
             pr_header(stdout, indent, "header", &(tpx));
 
             if (!bSysTop)
@@ -204,59 +203,57 @@ static void list_top(const char *fn)
     }
 }
 
-static void list_trn(const char *fn)
+static void list_trr(const char *fn)
 {
-    t_fileio       *fpread, *fpwrite;
-    int             nframe, indent;
-    char            buf[256];
-    rvec           *x, *v, *f;
-    matrix          box;
-    t_trnheader     trn;
-    gmx_bool        bOK;
-
-    fpread  = open_trn(fn, "r");
-    fpwrite = open_tpx(NULL, "w");
-    gmx_fio_setdebug(fpwrite, TRUE);
+    t_fileio         *fpread;
+    int               nframe, indent;
+    char              buf[256];
+    rvec             *x, *v, *f;
+    matrix            box;
+    gmx_trr_header_t  trrheader;
+    gmx_bool          bOK;
+
+    fpread  = gmx_trr_open(fn, "r");
 
     nframe = 0;
-    while (fread_trnheader(fpread, &trn, &bOK))
+    while (gmx_trr_read_frame_header(fpread, &trrheader, &bOK))
     {
-        snew(x, trn.natoms);
-        snew(v, trn.natoms);
-        snew(f, trn.natoms);
-        if (fread_htrn(fpread, &trn,
-                       trn.box_size ? box : NULL,
-                       trn.x_size   ? x : NULL,
-                       trn.v_size   ? v : NULL,
-                       trn.f_size   ? f : NULL))
+        snew(x, trrheader.natoms);
+        snew(v, trrheader.natoms);
+        snew(f, trrheader.natoms);
+        if (gmx_trr_read_frame_data(fpread, &trrheader,
+                                    trrheader.box_size ? box : NULL,
+                                    trrheader.x_size   ? x : NULL,
+                                    trrheader.v_size   ? v : NULL,
+                                    trrheader.f_size   ? f : NULL))
         {
             sprintf(buf, "%s frame %d", fn, nframe);
             indent = 0;
             indent = pr_title(stdout, indent, buf);
             pr_indent(stdout, indent);
             fprintf(stdout, "natoms=%10d  step=%10d  time=%12.7e  lambda=%10g\n",
-                    trn.natoms, trn.step, trn.t, trn.lambda);
-            if (trn.box_size)
+                    trrheader.natoms, trrheader.step, trrheader.t, trrheader.lambda);
+            if (trrheader.box_size)
             {
                 pr_rvecs(stdout, indent, "box", box, DIM);
             }
-            if (trn.x_size)
+            if (trrheader.x_size)
             {
-                pr_rvecs(stdout, indent, "x", x, trn.natoms);
+                pr_rvecs(stdout, indent, "x", x, trrheader.natoms);
             }
-            if (trn.v_size)
+            if (trrheader.v_size)
             {
-                pr_rvecs(stdout, indent, "v", v, trn.natoms);
+                pr_rvecs(stdout, indent, "v", v, trrheader.natoms);
             }
-            if (trn.f_size)
+            if (trrheader.f_size)
             {
-                pr_rvecs(stdout, indent, "f", f, trn.natoms);
+                pr_rvecs(stdout, indent, "f", f, trrheader.natoms);
             }
         }
         else
         {
             fprintf(stderr, "\nWARNING: Incomplete frame: nr %d, t=%g\n",
-                    nframe, trn.t);
+                    nframe, trrheader.t);
         }
 
         sfree(x);
@@ -267,10 +264,9 @@ static void list_trn(const char *fn)
     if (!bOK)
     {
         fprintf(stderr, "\nWARNING: Incomplete frame header: nr %d, t=%g\n",
-                nframe, trn.t);
+                nframe, trrheader.t);
     }
-    close_tpx(fpwrite);
-    close_trn(fpread);
+    gmx_trr_close(fpread);
 }
 
 void list_xtc(const char *fn)
@@ -409,7 +405,7 @@ void list_trx(const char *fn)
             list_xtc(fn);
             break;
         case efTRR:
-            list_trn(fn);
+            list_trr(fn);
             break;
         case efTNG:
             list_tng(fn);
@@ -422,13 +418,11 @@ void list_trx(const char *fn)
 
 void list_ene(const char *fn)
 {
-    int            ndr;
     ener_file_t    in;
     gmx_bool       bCont;
     gmx_enxnm_t   *enm = NULL;
     t_enxframe    *fr;
     int            i, j, nre, b;
-    real           rav, minthird;
     char           buf[22];
 
     printf("gmx dump: %s\n", fn);
@@ -442,7 +436,6 @@ void list_ene(const char *fn)
         printf("%5d  %-24s (%s)\n", i, enm[i].name, enm[i].unit);
     }
 
-    minthird = -1.0/3.0;
     snew(fr, 1);
     do
     {
index cf0195e1e3f3379586942d8bfa602983a0a0e100..c1457d097e506da4862c8f283d4ae45cb334b8ef 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_TOOLS_DUMP_H
 #define GMX_TOOLS_DUMP_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
 /*! \brief Implements gmx dump
  *
  * \param[in] argc  argc value passed to main().
@@ -49,8 +42,4 @@ extern "C" {
  */
 int gmx_dump(int argc, char *argv[]);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 308476ea764b87d249d83d201d3b0f2d56982bb8..e5ec0c205380cb3f4154b07a4cd916084b25093b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/legacyheaders/types/inputrec.h"
 #include "gromacs/utility/basedefinitions.h"
 
+/* Ugly hack to convince some compilers that returning t_topology (or other
+ * structs) from an extern "C" function is OK; can probably go when the extern
+ * "C" blocks go.
+ */
+#include "gromacs/topology/topology.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
index 678088f47842a79d9eacfc45b67dfead0d784115..07c11cdd42e6af41b8d3b6265d9303cfdbc4c418 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,6 +45,7 @@
 
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index b42defaaa610f6e899c34e627f51a58e96a3fa9a..0939204c8f1941218f11eb4a39878444e7abdbbc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -42,6 +42,8 @@
 #ifndef GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_IMPL_H
 #define GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_IMPL_H
 
+#include <string>
+
 #include "gromacs/analysisdata/modules/plot.h"
 #include "gromacs/options/timeunitmanager.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
@@ -73,6 +75,9 @@ class TrajectoryAnalysisSettings::Impl
         bool                 bRmPBC;
         //! Whether to pass PBC information to the analysis module.
         bool                 bPBC;
+
+        //! Help text for the module.
+        std::string          helpText_;
 };
 
 } // namespace gmx
index da9031abb82b40b91daefafe620f3ba63d6f68c5..03689a8fca4658712fb3e1c0867765a685ce9271 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
 
 #include "analysissettings-impl.h"
 
@@ -161,6 +163,18 @@ TrajectoryAnalysisSettings::setFrameFlags(int frflags)
     impl_->frflags = frflags;
 }
 
+const std::string &
+TrajectoryAnalysisSettings::helpText() const
+{
+    return impl_->helpText_;
+}
+
+void
+TrajectoryAnalysisSettings::setHelpText(const ConstArrayRef<const char *> &help)
+{
+    impl_->helpText_ = joinStrings(help, "\n");
+}
+
 
 /********************************************************************
  * TopologyInformation
index 20383df9cd0fa39a8b858687617906be9e5ddaa4..ba2b6a1225af0870fb86e63045a2a616359774b8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,6 +43,8 @@
 #ifndef GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_H
 #define GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_H
 
+#include <string>
+
 #include "gromacs/math/vectypes.h"
 #include "gromacs/options/timeunitmanager.h"
 #include "gromacs/utility/classhelpers.h"
@@ -52,6 +54,8 @@ struct t_topology;
 namespace gmx
 {
 
+template <typename T> class ConstArrayRef;
+
 class AnalysisDataPlotSettings;
 class Options;
 class TrajectoryAnalysisRunnerCommon;
@@ -218,6 +222,11 @@ class TrajectoryAnalysisSettings
          */
         void setFrameFlags(int frflags);
 
+        //! Returns the help text.
+        const std::string &helpText() const;
+        //! \copydoc ICommandLineOptionsModuleSettings::setHelpText(const std::string &)
+        void setHelpText(const ConstArrayRef<const char *> &help);
+
     private:
         class Impl;
 
index a6e3107cfbc1020c50b29c827496fbce68e099fb..5ac15b6281f04b4386ebe8ea77f95d6855d4a70f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -58,7 +58,7 @@
 #include "gromacs/trajectoryanalysis/analysismodule.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/filestream.h"
 #include "gromacs/utility/gmxassert.h"
 
 #include "runnercommon.h"
@@ -139,7 +139,7 @@ TrajectoryAnalysisCommandLineRunner::Impl::parseOptions(
 
     common->initIndexGroups(selections, bUseDefaultGroups_);
 
-    const bool bInteractive = File::standardInput().isInteractive();
+    const bool bInteractive = StandardInputStream::instance().isInteractive();
     seloptManager.parseRequestedFromStdin(bInteractive);
     common->doneIndexGroups(selections);
 
@@ -273,7 +273,7 @@ TrajectoryAnalysisCommandLineRunner::writeHelp(const CommandLineHelpContext &con
     selections.initOptions(&selectionOptions);
 
     CommandLineHelpWriter(options)
-        .setShowDescriptions(true)
+        .setHelpText(settings.helpText())
         .setTimeUnitString(settings.timeUnitManager().timeUnitAsString())
         .writeHelp(context);
 }
@@ -285,7 +285,7 @@ TrajectoryAnalysisCommandLineRunner::writeHelp(const CommandLineHelpContext &con
  * \ingroup module_trajectoryanalysis
  */
 class TrajectoryAnalysisCommandLineRunner::Impl::RunnerCommandLineModule
-    : public CommandLineModuleInterface
+    : public ICommandLineModule
 {
     public:
         /*! \brief
index 200aed1924fc44c206c63639f48936e4a74b3823..8968c49690135fc1bb83325e75cab9b21639c1e3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -304,7 +304,7 @@ Angle::Angle()
 
 
 void
-Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Angle::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] computes different types of angles between vectors.",
@@ -359,7 +359,7 @@ Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
     static const char *const cGroup2TypeEnum[] =
     { "none", "vector", "plane", "t0", "z", "sphnorm" };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
                            .store(&fnAverage_).defaultBasename("angaver")
@@ -686,21 +686,38 @@ Angle::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
     {
         rvec  v1, v2;
         rvec  c1, c2;
+
+        // v2 & c2 are conditionally set in the switch statement below, and conditionally
+        // used in a different switch statement later. Apparently the clang static analyzer
+        // thinks there are cases where they can be used uninitialzed (which I cannot find),
+        // but to avoid trouble if we ever change just one of the switch statements it
+        // makes sense to clear them outside the first switch.
+
+        clear_rvec(v2);
+        clear_rvec(c2);
+
         switch (g2type_[0])
         {
             case 'z':
-                clear_rvec(v2);
                 v2[ZZ] = 1.0;
-                clear_rvec(c2);
                 break;
             case 's':
                 copy_rvec(sel2_[g].position(0).x(), c2);
                 break;
+            default:
+                // do nothing
+                break;
         }
+
         dh.selectDataSet(g);
         for (int n = 0; n < angleCount_[g]; ++n, iter1.nextValue(), iter2.nextValue())
         {
             rvec x[4];
+            // x[] will be assigned below based on the number of atoms used to initialize iter1,
+            // which in turn should correspond perfectly to g1type_[0] (which determines how many we read),
+            // but unsurprisingly the static analyzer chokes a bit on that.
+            clear_rvecs(4, x);
+
             real angle;
             // checkSelections() ensures that this reflects all the involved
             // positions.
index 4b07d1483a4f5f81da6bba393b2f4a65d0c736bb..bc9fb9687eed8c046772211c9a262a5e7a72d8d4 100644 (file)
@@ -132,7 +132,7 @@ Distance::Distance()
 
 
 void
-Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Distance::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] calculates distances between pairs of positions",
@@ -156,7 +156,7 @@ Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*
         "distances, use [gmx-pairdist]."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
                            .store(&fnAverage_).defaultBasename("distave")
index b489c2a933920764d1591ddb6e34087cd34a878a..a99215cffd6df62af3073d3fb686859f2b33f76f 100644 (file)
@@ -196,8 +196,7 @@ FreeVolume::initOptions(Options                    *options,
         "the terminal."
     };
 
-    // Add the descriptive text (program help text) to the options
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     // Add option for optional output file
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile()
index 37b2bbbef53e8281c8e5f9cb77eae47ce3086cbf..0d365ffa34be4257c474666b1cc80638c842f20e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -177,7 +177,7 @@ PairDistance::PairDistance()
 
 
 void
-PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] calculates pairwise distances between one reference",
@@ -214,7 +214,7 @@ PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings * /*setti
         "[gmx-distance] may be a more suitable tool."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required()
                            .store(&fnDist_).defaultBasename("dist")
index 468b729873fb6c321d28f49e05b16183129eb276..448095bdf3f328534b285fab0212465ce88459b7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -200,7 +200,7 @@ Rdf::Rdf()
 }
 
 void
-Rdf::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Rdf::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] calculates radial distribution functions from one",
@@ -240,7 +240,7 @@ Rdf::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
         "i.e. the average number of particles within a distance r.[PAR]"
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required()
                            .store(&fnRdf_).defaultBasename("rdf")
index cf243b44190d23983da444ea20e2e5edeaa7291d..edff30830f3311f17a373206b4b51f39ceddcca0 100644 (file)
@@ -445,7 +445,7 @@ Sasa::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
         "that are both too high."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required()
                            .store(&fnArea_).defaultBasename("area")
index 443c4a129c7934aa0668eca5b4bfdfb68a350541..0239d188603c6ae2749689be43a94b3b631ce883 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -327,7 +327,7 @@ Select::Select()
 
 
 void
-Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Select::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] writes out basic data about dynamic selections.",
@@ -391,7 +391,7 @@ Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
         "dynamic selections."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("os").filetype(eftPlot).outputFile()
                            .store(&fnSize_).defaultBasename("size")
index 4d9513ed28d6268e8245c7eebea9125b1f535e7f..f7db22934184a287a8330d4c5f7f4c85e7b2a7f3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,8 +45,8 @@
 
 #include <string.h>
 
+#include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/timecontrol.h"
-#include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trx.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/legacyheaders/oenv.h"
@@ -60,6 +60,7 @@
 #include "gromacs/selection/selectionfileoption.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/programcontext.h"
index 1ae38d84525b8dfc62b0f5178ad9305cb3948268..b6e9bcfdb67f16b17e6b79715d4980024cf82b08 100644 (file)
@@ -68,4 +68,31 @@ and use the copy_xsl.sh script to copy it to relevant locations.
     <xsl:value-of select="."/>
 </xsl:template>
 
+<xsl:template match="InteractiveSession">
+    <pre>
+        <xsl:for-each select="*">
+            <xsl:choose>
+                <xsl:when test="starts-with(@Name, 'Output')">
+                    <xsl:value-of select="substring(.,2)"/>
+                </xsl:when>
+                <xsl:when test="string-length(.)=1">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:when>
+                <xsl:when test="contains(substring(.,2), '&#10;')">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="translate(substring(.,2), '&#10;', '&#x23ce;')"/>
+                    <xsl:text>&#10;</xsl:text>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="substring(.,2)"/>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:for-each>
+        <xsl:text>[EOF]</xsl:text>
+    </pre>
+</xsl:template>
+
 </xsl:stylesheet>
index e8153b6e2e3af9a2e68b580fa2e38e9709387158..c0868646e6f2d685ae1cf76dd0129406f10b7395 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -99,14 +99,14 @@ SelectionTester::printSelections()
 }
 
 void
-SelectionTester::initOptions(Options                   *options,
-                             TrajectoryAnalysisSettings * /*settings*/)
+SelectionTester::initOptions(Options                    *options,
+                             TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "This is a test program for selections."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(SelectionOption("select").storeVector(&selections_)
                            .required().multiValue()
index 213f698280ab6760a42773a19d6d95e314bb8439..158328682137cd280997fc8f5b5361f03171b819 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * containers to simplify implementation of other code.  Contents of the module
  * are discussed in more details under the different headings below.
  * Some of the code in installed headers in the module is intended for use
- * directly from code outside the Gromacs library, but a significant portion is
- * exposed only because other public headers depend on it.
+ * directly from code outside the \Gromacs library, but a significant portion
+ * is exposed only because other public headers depend on it.
  *
  * Since this module implements error handling, it should be at the lowest
  * level: it should not depend on other modules.  Any functionality needed by
  * the error handling code should also be kept in this module.
  *
- * <H3>Error Handling</H3>
+ * <H3>Error handling</H3>
  *
  * Exception classes used in the library are declared in the exceptions.h header
- * file.  Most Gromacs-specific exceptions derive from gmx::GromacsException.
+ * file.  Most \Gromacs-specific exceptions derive from gmx::GromacsException.
  *
  * This header also declares a ::GMX_THROW macro that should be used for
  * throwing exceptions.  ::GMX_THROW_WITH_ERRNO is also provided for reporting
  * \endif
  *
  *
- * <H3>Basic %File Handling</H3>
+ * \if libapi
+ *
+ * <H3>Basic file handling and streams</H3>
  *
- * The header file.h declares a gmx::File class for basic I/O support.
+ * The header textstream.h declares interfaces for simple text format streams.
+ * Headers filestream.h and stringstream.h provide implementations for these
+ * streams for reading/writing files and for writing to in-memory strings.
  *
- * The header path.h declares helpers for manipulating paths and for managing
- * directories.
+ * The header fileredirector.h provides interfaces for redirecting file input
+ * and/or output to alternative streams, for use in testing, as well as default
+ * implementations for these interfaces that just use the file system.
  *
- * The fate of these headers depends on what is decided in Redmine issue #950.
+ * The header textwriter.h provides gmx::TextWriter for more formatting support
+ * when writing to a text stream.  Similarly, textreader.h provides more
+ * formatting support when reading from a text stream.
  *
+ * The header path.h declares helpers for manipulating paths as strings and for
+ * managing directories and files.
+ * The fate of this header depends on what is decided in Redmine issue #950.
+ *
+ * \endif
  *
- * <H3>Implementation Helpers</H3>
+ * <H3>Implementation helpers</H3>
  *
  * The header basedefinitions.h contains common definitions and macros used
  * throughout \Gromacs.  It includes fixed-width integer types (`gmx_int64_t`
  * safety when using bit flag fields.
  *
  *
- * <H3>Other Functionality</H3>
+ * <H3>Other functionality</H3>
  *
  * The header init.h declares gmx::init() and gmx::finalize() for initializing
  * and deinitializing the \Gromacs library.
  * The header sysinfo.h declares gmx_getpid() for getting the current process
  * id.
  *
- * The header programcontext.h declares a gmx::ProgramContextInterface that is
+ * The header programcontext.h declares a gmx::IProgramContext that is
  * used to
  * initialize and access information about the running program, such as the
  * name and path of the executable.  This information is used, e.g., by the
index 1933e660a6ce406932b430e016d7cb4439e5d129..1ce2ce4b20fd1ea87e347a8b6dbe4823279b16d9 100644 (file)
@@ -44,7 +44,6 @@ gmx_install_headers(
     errorcodes.h
     exceptions.h
     fatalerror.h
-    file.h
     flags.h
     futil.h
     gmxassert.h
similarity index 99%
rename from src/gromacs/utility/cstringutil.c
rename to src/gromacs/utility/cstringutil.cpp
index bb0c250776f07540bef543c0404b5b973b1e1aeb..358201c6882caf3d6da15e128ddea39838aed66f 100644 (file)
 
 #include "cstringutil.h"
 
-#include <assert.h>
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+
+#include <cassert>
+#include <cctype>
+#include <cstring>
 
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/fatalerror.h"
@@ -129,7 +130,6 @@ void upstring (char *str)
 
 void ltrim (char *str)
 {
-    char *tr;
     int   i, c;
 
     if (NULL == str)
@@ -533,7 +533,7 @@ str_to_int64_t(const char *str, char **endptr)
 
 char *gmx_step_str(gmx_int64_t i, char *buf)
 {
-    sprintf(buf, "%"GMX_PRId64, i);
+    sprintf(buf, "%" GMX_PRId64, i);
     return buf;
 }
 
index 2bc6a9b875015052bd5bfca2fec774ca94c33a37..e773fff84b2a55db6f2c69199d288f9e43088ab0 100644 (file)
@@ -51,7 +51,7 @@
 #include "buildinfo.h"
 #include "gromacs/utility/directoryenumerator.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/filestream.h"
 #include "gromacs/utility/path.h"
 #include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/stringutil.h"
@@ -133,7 +133,7 @@ FILE *DataFileFinder::openFile(const DataFileOptions &options) const
         fprintf(debug, "Opening library file %s\n", fn);
     }
 #endif
-    return File::openRawHandle(filename, "r");
+    return TextInputFile::openRawHandle(filename);
 }
 
 std::string DataFileFinder::findFile(const DataFileOptions &options) const
index f675fceba4fe71411c46a34362a96cb5e2979a0e..488c6c65de10a93c3dafb2ec24523a2b2dea0618 100644 (file)
@@ -171,7 +171,7 @@ class DataFileFinder
          * Constructs a default data file finder.
          *
          * The constructed finder searches only in the directory specified by
-         * the global program context (see ProgramContextInterface), and
+         * the global program context (see IProgramContext), and
          * optionally in the current directory.
          *
          * Does not throw.
index 00c57aa67c4ac86d3f71fba0b1c96aaedf72d883..59df7ce47edf9f71a23b65f437ffb2a3c5438bb4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,7 +45,7 @@
 
 #include <cstdlib>
 
-#include "thread_mpi/mutex.h"
+#include "gromacs/utility/mutex.h"
 
 #include "errorformat.h"
 
@@ -100,7 +100,7 @@ void standardErrorHandler(int retcode, const char *msg,
 //! Global error handler set with setFatalErrorHandler().
 ErrorHandlerFunc g_errorHandler = standardErrorHandler;
 //! Mutex for protecting access to ::g_errorHandler.
-tMPI::mutex      handler_mutex;
+Mutex            handler_mutex;
 
 //! \}
 
@@ -117,8 +117,8 @@ const char *getErrorCodeString(int errorcode)
 
 ErrorHandlerFunc setFatalErrorHandler(ErrorHandlerFunc handler)
 {
-    tMPI::lock_guard<tMPI::mutex> lock(handler_mutex);
-    ErrorHandlerFunc              oldHandler = g_errorHandler;
+    lock_guard<Mutex> lock(handler_mutex);
+    ErrorHandlerFunc  oldHandler = g_errorHandler;
     g_errorHandler = handler;
     return oldHandler;
 }
@@ -131,7 +131,7 @@ void fatalError(int retcode, const char *msg, const char *file, int line)
 {
     ErrorHandlerFunc handler = NULL;
     {
-        tMPI::lock_guard<tMPI::mutex> lock(handler_mutex);
+        lock_guard<Mutex> lock(handler_mutex);
         handler = g_errorHandler;
     }
     if (handler != NULL)
index 14fe155e434e892d378d644b6eecefa24b8e4377..5d85ec506bca05a77274d73378928b1c2199e4b2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -60,6 +60,7 @@
 #include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "errorformat.h"
 
@@ -253,10 +254,10 @@ namespace
  * exceptions while still supporting output to different formats (e.g., to a
  * string or to \c stderr).
  */
-class MessageWriterInterface
+class IMessageWriter
 {
     public:
-        virtual ~MessageWriterInterface() {}
+        virtual ~IMessageWriter() {}
 
         /*! \brief
          * Writes a single line of text into the output.
@@ -282,7 +283,7 @@ class MessageWriterInterface
  * Formats the messages into the provided FILE handle without checking for
  * errors in std::fprintf() calls.
  */
-class MessageWriterFileNoThrow : public MessageWriterInterface
+class MessageWriterFileNoThrow : public IMessageWriter
 {
     public:
         //! Initializes a writer that writes to the given file handle.
@@ -308,10 +309,43 @@ class MessageWriterFileNoThrow : public MessageWriterInterface
         FILE                   *fp_;
 };
 
+/*! \brief
+ * Exception information writer to format into a TextOutputStream.
+ */
+class MessageWriterTextWriter : public IMessageWriter
+{
+    public:
+        //! Initializes a writer that writes to the given stream.
+        explicit MessageWriterTextWriter(TextWriter *writer) : writer_(writer)
+        {
+        }
+
+        virtual void writeLine(const char *text, int indent)
+        {
+            writer_->wrapperSettings().setIndent(indent);
+            writer_->writeLine(text);
+        }
+        virtual void writeErrNoInfo(int errorNumber, const char *funcName,
+                                    int indent)
+        {
+            writer_->wrapperSettings().setIndent(indent);
+            writer_->writeLine(formatString("Reason: %s", std::strerror(errorNumber)));
+            if (funcName != NULL)
+            {
+                writer_->writeLine(
+                        formatString("(call to %s() returned error code %d)",
+                                     funcName, errorNumber));
+            }
+        }
+
+    private:
+        TextWriter     *writer_;
+};
+
 /*! \brief
  * Exception information writer to format into an std::string.
  */
-class MessageWriterString : public MessageWriterInterface
+class MessageWriterString : public IMessageWriter
 {
     public:
         //! Post-processes the output string to not end in a line feed.
@@ -360,7 +394,7 @@ class MessageWriterString : public MessageWriterInterface
  *
  * Does not throw unless the writer throws.
  */
-void formatExceptionMessageInternal(MessageWriterInterface *writer,
+void formatExceptionMessageInternal(IMessageWriter *writer,
                                     const std::exception &ex, int indent)
 {
     const boost::exception *boostEx = dynamic_cast<const boost::exception *>(&ex);
@@ -519,6 +553,13 @@ void formatExceptionMessageToFile(FILE *fp, const std::exception &ex)
     formatExceptionMessageInternal(&writer, ex, 0);
 }
 
+void formatExceptionMessageToWriter(TextWriter           *writer,
+                                    const std::exception &ex)
+{
+    MessageWriterTextWriter messageWriter(writer);
+    formatExceptionMessageInternal(&messageWriter, ex, 0);
+}
+
 int processExceptionAtExit(const std::exception & /*ex*/)
 {
     int returnCode = 1;
index 40d723b8f516190447e1de215306c071d46d9a0d..493ee6bb6052a5b8d13e3de8d4318a24e57193c1 100644 (file)
@@ -60,6 +60,8 @@
 namespace gmx
 {
 
+class TextWriter;
+
 namespace internal
 {
 //! Internal container type for storing a list of nested exceptions.
@@ -444,6 +446,15 @@ std::string formatExceptionMessageToString(const std::exception &ex);
  * \throws    std::bad_alloc if out of memory.
  */
 void formatExceptionMessageToFile(FILE *fp, const std::exception &ex);
+/*! \brief
+ * Formats an error message for reporting an exception.
+ *
+ * \param     writer  Writer to use for writing the message.
+ * \param[in] ex      Exception to format.
+ * \throws    std::bad_alloc if out of memory.
+ */
+void formatExceptionMessageToWriter(TextWriter           *writer,
+                                    const std::exception &ex);
 /*! \brief
  * Handles an exception that is causing the program to terminate.
  *
diff --git a/src/gromacs/utility/file.cpp b/src/gromacs/utility/file.cpp
deleted file mode 100644 (file)
index 7614734..0000000
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \internal \file
- * \brief
- * Implements gmx::File.
- *
- * \author Teemu Murtola <teemu.murtola@gmail.com>
- * \ingroup module_utility
- */
-#include "gmxpre.h"
-
-#include "file.h"
-
-#include "config.h"
-
-#include <cerrno>
-#include <cstdio>
-#include <cstring>
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-#include <sys/stat.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/stringutil.h"
-
-namespace gmx
-{
-
-/*! \internal \brief
- * Private implementation class for File.
- *
- * \ingroup module_utility
- */
-class File::Impl
-{
-    public:
-        /*! \brief
-         * Initialize a file object with the given handle.
-         *
-         * \param[in]  fp     %File handle to use (may be NULL).
-         * \param[in]  bClose Whether this object should close its file handle.
-         */
-        Impl(FILE *fp, bool bClose);
-        ~Impl();
-
-        //! File handle for this object (may be NULL).
-        FILE                   *fp_;
-        /*! \brief
-         * Whether \p fp_ should be closed by this object.
-         *
-         * Can be true if \p fp_ is NULL.
-         */
-        bool                    bClose_;
-};
-
-File::Impl::Impl(FILE *fp, bool bClose)
-    : fp_(fp), bClose_(bClose)
-{
-}
-
-File::Impl::~Impl()
-{
-    if (fp_ != NULL && bClose_)
-    {
-        if (fclose(fp_) != 0)
-        {
-            // TODO: Log the error somewhere
-        }
-    }
-}
-
-// static
-FILE *File::openRawHandle(const char *filename, const char *mode)
-{
-    FILE *fp = fopen(filename, mode);
-    if (fp == NULL)
-    {
-        GMX_THROW_WITH_ERRNO(
-                FileIOError(formatString("Could not open file '%s'", filename)),
-                "fopen", errno);
-    }
-    return fp;
-}
-
-// static
-FILE *File::openRawHandle(const std::string &filename, const char *mode)
-{
-    return openRawHandle(filename.c_str(), mode);
-}
-
-File::File(const char *filename, const char *mode)
-    : impl_(new Impl(NULL, true))
-{
-    open(filename, mode);
-}
-
-File::File(const std::string &filename, const char *mode)
-    : impl_(new Impl(NULL, true))
-{
-    open(filename, mode);
-}
-
-File::File(const FileInitializer &initializer)
-    : impl_(new Impl(NULL, true))
-{
-    open(initializer.filename_, initializer.mode_);
-}
-
-File::File(FILE *fp, bool bClose)
-    : impl_(new Impl(fp, bClose))
-{
-}
-
-File::~File()
-{
-}
-
-void File::open(const char *filename, const char *mode)
-{
-    GMX_RELEASE_ASSERT(impl_->fp_ == NULL,
-                       "Attempted to open the same file object twice");
-    // TODO: Port all necessary functionality from gmx_ffopen() here.
-    impl_->fp_ = openRawHandle(filename, mode);
-}
-
-void File::open(const std::string &filename, const char *mode)
-{
-    open(filename.c_str(), mode);
-}
-
-void File::close()
-{
-    GMX_RELEASE_ASSERT(impl_->fp_ != NULL,
-                       "Attempted to close a file object that is not open");
-    GMX_RELEASE_ASSERT(impl_->bClose_,
-                       "Attempted to close a file object that should not be");
-    bool bOk = (fclose(impl_->fp_) == 0);
-    impl_->fp_ = NULL;
-    if (!bOk)
-    {
-        GMX_THROW_WITH_ERRNO(
-                FileIOError("Error while closing file"), "fclose", errno);
-    }
-}
-
-bool File::isInteractive() const
-{
-    GMX_RELEASE_ASSERT(impl_->fp_ != NULL,
-                       "Attempted to access a file object that is not open");
-#ifdef HAVE_UNISTD_H
-    return isatty(fileno(impl_->fp_));
-#else
-    return true;
-#endif
-}
-
-FILE *File::handle()
-{
-    GMX_RELEASE_ASSERT(impl_->fp_ != NULL,
-                       "Attempted to access a file object that is not open");
-    return impl_->fp_;
-}
-
-void File::readBytes(void *buffer, size_t bytes)
-{
-    errno = 0;
-    FILE  *fp = handle();
-    // TODO: Retry based on errno or something else?
-    size_t bytesRead = std::fread(buffer, 1, bytes, fp);
-    if (bytesRead != bytes)
-    {
-        if (feof(fp))
-        {
-            GMX_THROW(FileIOError(
-                              formatString("Premature end of file\n"
-                                           "Attempted to read: %d bytes\n"
-                                           "Successfully read: %d bytes",
-                                           static_cast<int>(bytes),
-                                           static_cast<int>(bytesRead))));
-        }
-        else
-        {
-            GMX_THROW_WITH_ERRNO(FileIOError("Error while reading file"),
-                                 "fread", errno);
-        }
-    }
-}
-
-bool File::readLine(std::string *line)
-{
-    if (!readLineWithTrailingSpace(line))
-    {
-        return false;
-    }
-    size_t endPos = line->find_last_not_of(" \t\r\n");
-    if (endPos != std::string::npos)
-    {
-        line->resize(endPos + 1);
-    }
-    return true;
-}
-
-bool File::readLineWithTrailingSpace(std::string *line)
-{
-    line->clear();
-    const size_t bufsize = 256;
-    std::string  result;
-    char         buf[bufsize];
-    buf[0] = '\0';
-    FILE        *fp = handle();
-    while (fgets(buf, bufsize, fp) != NULL)
-    {
-        size_t length = std::strlen(buf);
-        result.append(buf, length);
-        if (length < bufsize - 1 || buf[length - 1] == '\n')
-        {
-            break;
-        }
-    }
-    if (ferror(fp))
-    {
-        GMX_THROW_WITH_ERRNO(FileIOError("Error while reading file"),
-                             "fgets", errno);
-    }
-    *line = result;
-    return !result.empty() || !feof(fp);
-}
-
-void File::writeString(const char *str)
-{
-    if (fprintf(handle(), "%s", str) < 0)
-    {
-        GMX_THROW_WITH_ERRNO(FileIOError("Writing to file failed"),
-                             "fprintf", errno);
-    }
-}
-
-void File::writeLine(const char *line)
-{
-    size_t length = std::strlen(line);
-
-    writeString(line);
-    if (length == 0 || line[length-1] != '\n')
-    {
-        writeString("\n");
-    }
-}
-
-void File::writeLine()
-{
-    writeString("\n");
-}
-
-// static
-bool File::exists(const char *filename)
-{
-    if (filename == NULL)
-    {
-        return false;
-    }
-    FILE *test = fopen(filename, "r");
-    if (test == NULL)
-    {
-        return false;
-    }
-    else
-    {
-        fclose(test);
-        // Windows doesn't allow fopen of directory, so we don't need to check
-        // this separately.
-#ifndef GMX_NATIVE_WINDOWS
-        struct stat st_buf;
-        int         status = stat(filename, &st_buf);
-        if (status != 0 || !S_ISREG(st_buf.st_mode))
-        {
-            return false;
-        }
-#endif
-        return true;
-    }
-}
-
-// static
-bool File::exists(const std::string &filename)
-{
-    return exists(filename.c_str());
-}
-
-// static
-File &File::standardInput()
-{
-    static File stdinObject(stdin, false);
-    return stdinObject;
-}
-
-// static
-File &File::standardOutput()
-{
-    static File stdoutObject(stdout, false);
-    return stdoutObject;
-}
-
-// static
-File &File::standardError()
-{
-    static File stderrObject(stderr, false);
-    return stderrObject;
-}
-
-// static
-std::string File::readToString(const char *filename)
-{
-    // Binary mode is required on Windows to be able to determine a size
-    // that can be passed to fread().
-    File  file(filename, "rb");
-    FILE *fp = file.handle();
-
-    if (std::fseek(fp, 0L, SEEK_END) != 0)
-    {
-        GMX_THROW_WITH_ERRNO(FileIOError("Seeking to end of file failed"),
-                             "fseek", errno);
-    }
-    long len = std::ftell(fp);
-    if (len == -1)
-    {
-        GMX_THROW_WITH_ERRNO(FileIOError("Reading file length failed"),
-                             "ftell", errno);
-    }
-    if (std::fseek(fp, 0L, SEEK_SET) != 0)
-    {
-        GMX_THROW_WITH_ERRNO(FileIOError("Seeking to start of file failed"),
-                             "fseek", errno);
-    }
-
-    std::vector<char> data(len);
-    file.readBytes(&data[0], len);
-    file.close();
-
-    std::string result(&data[0], len);
-    // The below is necessary on Windows to make newlines stay as '\n' on a
-    // roundtrip.
-    result = replaceAll(result, "\r\n", "\n");
-
-    return result;
-}
-
-// static
-std::string File::readToString(const std::string &filename)
-{
-    return readToString(filename.c_str());
-}
-
-// static
-void File::writeFileFromString(const std::string &filename,
-                               const std::string &text)
-{
-    File file(filename, "w");
-    file.writeString(text);
-    file.close();
-}
-
-} // namespace gmx
diff --git a/src/gromacs/utility/file.h b/src/gromacs/utility/file.h
deleted file mode 100644 (file)
index 5e45736..0000000
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \file
- * \brief
- * Declares gmx::File.
- *
- * \author Teemu Murtola <teemu.murtola@gmail.com>
- * \inpublicapi
- * \ingroup module_utility
- */
-#ifndef GMX_UTILITY_FILE_H
-#define GMX_UTILITY_FILE_H
-
-#include <cstdio>
-
-#include <string>
-
-#include "gromacs/utility/classhelpers.h"
-
-namespace gmx
-{
-
-class File;
-
-/*! \brief
- * Parameters for creating a File object.
- *
- * This class (mostly) replaces the ability to return a File object from a
- * function (since File is not copyable): returning a FileInitializer instead
- * allows the caller to construct the File object.
- *
- * \inpublicapi
- * \ingroup module_utility
- */
-class FileInitializer
-{
-    public:
-        /*! \brief
-         * Creates the initializer with given parameters.
-         *
-         * The passed strings must remain valid until the initializer is used
-         * to construct a File object.
-         */
-        FileInitializer(const char *filename, const char *mode)
-            : filename_(filename), mode_(mode)
-        {
-        }
-
-    private:
-        const char *filename_;
-        const char *mode_;
-
-        /*! \brief
-         * Needed to allow access to the parameters without otherwise
-         * unnecessary accessors.
-         */
-        friend class File;
-};
-
-/*! \brief
- * Basic file object.
- *
- * This class provides basic file I/O functionality and uses exceptions
- * (FileIOError) for error reporting.
- *
- * \inpublicapi
- * \ingroup module_utility
- */
-class File
-{
-    public:
-        /*! \brief
-         * Opens a file and returns a `FILE` handle.
-         *
-         * \param[in] filename  Path of the file to open.
-         * \param[in] mode      Mode to open the file in (for fopen()).
-         * \throws    FileIOError on any I/O error.
-         *
-         * Instead of returning `NULL` on errors, throws an exception with
-         * additional details (including the file name and `errno`).
-         */
-        static FILE *openRawHandle(const char *filename, const char *mode);
-        //! \copydoc openRawHandle(const char *, const char *)
-        static FILE *openRawHandle(const std::string &filename, const char *mode);
-        /*! \brief
-         * Creates a file object and opens a file.
-         *
-         * \param[in] filename  Path of the file to open.
-         * \param[in] mode      Mode to open the file in (for fopen()).
-         * \throws    std::bad_alloc if out of memory.
-         * \throws    FileIOError on any I/O error.
-         *
-         * \see open(const char *, const char *)
-         */
-        File(const char *filename, const char *mode);
-        //! \copydoc File(const char *, const char *)
-        File(const std::string &filename, const char *mode);
-        /*! \brief
-         * Creates a file object and opens a file.
-         *
-         * \param[in] initializer  Parameters to open the file.
-         * \throws    std::bad_alloc if out of memory.
-         * \throws    FileIOError on any I/O error.
-         */
-        File(const FileInitializer &initializer);
-        /*! \brief
-         * Destroys the file object.
-         *
-         * If the file is still open, it is closed.
-         * Any error conditions will be ignored.
-         */
-        ~File();
-
-        /*! \brief
-         * Opens a file.
-         *
-         * \param[in] filename  Path of the file to open.
-         * \param[in] mode      Mode to open the file in (for fopen()).
-         * \throws    FileIOError on any I/O error.
-         *
-         * The file object must not be open.
-         */
-        void open(const char *filename, const char *mode);
-        //! \copydoc open(const char *, const char *)
-        void open(const std::string &filename, const char *mode);
-        /*! \brief
-         * Closes the file object.
-         *
-         * \throws  FileIOError on any I/O error.
-         *
-         * The file must be open.
-         */
-        void close();
-
-        /*! \brief
-         * Returns whether the file is an interactive terminal.
-         *
-         * Only works on Unix, otherwise always returns true.
-         * It only makes sense to call this for File::standardInput() and
-         * friends.
-         *
-         * Thie file must be open.
-         * Does not throw.
-         */
-        bool isInteractive() const;
-        /*! \brief
-         * Returns a file handle for interfacing with C functions.
-         *
-         * The file must be open.
-         * Does not throw.
-         */
-        FILE *handle();
-
-        /*! \brief
-         * Reads given number of bytes from the file.
-         *
-         * \param[out] buffer  Pointer to buffer that receives the bytes.
-         * \param[in]  bytes   Number of bytes to read.
-         * \throws     FileIOError on any I/O error.
-         *
-         * The file must be open.
-         */
-        void readBytes(void *buffer, size_t bytes);
-        /*! \brief
-         * Reads a single line from the file.
-         *
-         * \param[out] line    String to receive the line.
-         * \returns    false if nothing was read because the file ended.
-         * \throws     std::bad_alloc if out of memory.
-         * \throws     FileIOError on any I/O error.
-         *
-         * On error or when false is returned, \p line will be empty.
-         * Trailing space will be removed from the line.
-         * To loop over all lines in the file, use:
-         * \code
-           std::string line;
-           while (file.readLine(&line))
-           {
-               // ...
-           }
-           \endcode
-         */
-        bool readLine(std::string *line);
-        /*! \brief
-         * Reads a single line from the file.
-         *
-         * \param[out] line    String to receive the line.
-         * \returns    false if nothing was read because the file ended.
-         * \throws     std::bad_alloc if out of memory.
-         * \throws     FileIOError on any I/O error.
-         *
-         * On error or when false is returned, \p line will be empty.
-         * Works as readLine(), except that terminating newline will be present
-         * in \p line if it was present in the file.
-         *
-         * \see readLine()
-         */
-        bool readLineWithTrailingSpace(std::string *line);
-
-        /*! \brief
-         * Writes a string to the file.
-         *
-         * \param[in]  str  String to write.
-         * \throws     FileIOError on any I/O error.
-         *
-         * The file must be open.
-         */
-        void writeString(const char *str);
-        //! \copydoc writeString(const char *)
-        void writeString(const std::string &str) { writeString(str.c_str()); }
-        /*! \brief
-         * Writes a line to the file.
-         *
-         * \param[in]  line  Line to write.
-         * \throws     FileIOError on any I/O error.
-         *
-         * If \p line does not end in a newline, one newline is appended.
-         * Otherwise, works as writeString().
-         *
-         * The file must be open.
-         */
-        void writeLine(const char *line);
-        //! \copydoc writeLine(const char *)
-        void writeLine(const std::string &line) { writeLine(line.c_str()); }
-        /*! \brief
-         * Writes a newline to the file.
-         *
-         * \throws     FileIOError on any I/O error.
-         */
-        void writeLine();
-
-        /*! \brief
-         * Checks whether a file exists and is a regular file.
-         *
-         * \param[in] filename  Path to the file to check.
-         * \returns   true if \p filename exists and is accessible.
-         *
-         * Does not throw.
-         */
-        static bool exists(const char *filename);
-        //! \copydoc exists(const char *)
-        static bool exists(const std::string &filename);
-
-        /*! \brief
-         * Returns a File object for accessing stdin.
-         *
-         * \throws    std::bad_alloc if out of memory (only on first call).
-         */
-        static File &standardInput();
-        /*! \brief
-         * Returns a File object for accessing stdout.
-         *
-         * \throws    std::bad_alloc if out of memory (only on first call).
-         */
-        static File &standardOutput();
-        /*! \brief
-         * Returns a File object for accessing stderr.
-         *
-         * \throws    std::bad_alloc if out of memory (only on first call).
-         */
-        static File &standardError();
-
-        /*! \brief
-         * Reads contents of a file to a std::string.
-         *
-         * \param[in] filename  Name of the file to read.
-         * \returns   The contents of \p filename.
-         * \throws    std::bad_alloc if out of memory.
-         * \throws    FileIOError on any I/O error.
-         */
-        static std::string readToString(const char *filename);
-        //! \copydoc readToString(const char *)
-        static std::string readToString(const std::string &filename);
-        /*! \brief
-         * Convenience method for writing a file from a string in a single call.
-         *
-         * \param[in] filename  Name of the file to read.
-         * \param[in] text      String to write to \p filename.
-         * \throws    FileIOError on any I/O error.
-         *
-         * If \p filename exists, it is overwritten.
-         */
-        static void writeFileFromString(const std::string &filename,
-                                        const std::string &text);
-
-    private:
-        /*! \brief
-         * Initialize file object from an existing file handle.
-         *
-         * \param[in]  fp     %File handle to use (may be NULL).
-         * \param[in]  bClose Whether this object should close its file handle.
-         * \throws     std::bad_alloc if out of memory.
-         *
-         * Used internally to implement standardOutput() and standardError().
-         */
-        File(FILE *fp, bool bClose);
-
-        class Impl;
-
-        PrivateImplPointer<Impl> impl_;
-};
-
-} // namespace gmx
-
-#endif
index 405702bd7280e180f17002a0abd6713d32adab96..9757afafb0389c2c9a12c60d288bc378723e6f1f 100644 (file)
 
 #include "fileredirector.h"
 
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/filestream.h"
+#include "gromacs/utility/path.h"
 
 namespace gmx
 {
 
-FileInputRedirectorInterface::~FileInputRedirectorInterface()
+IFileInputRedirector::~IFileInputRedirector()
 {
 }
 
-FileOutputRedirectorInterface::~FileOutputRedirectorInterface()
+IFileOutputRedirector::~IFileOutputRedirector()
 {
 }
 
@@ -67,7 +68,7 @@ namespace
  *
  * \ingroup module_utility
  */
-class DefaultInputRedirector : public FileInputRedirectorInterface
+class DefaultInputRedirector : public IFileInputRedirector
 {
     public:
         virtual bool fileExists(const char *filename) const
@@ -85,29 +86,29 @@ class DefaultInputRedirector : public FileInputRedirectorInterface
  *
  * \ingroup module_utility
  */
-class DefaultOutputRedirector : public FileOutputRedirectorInterface
+class DefaultOutputRedirector : public IFileOutputRedirector
 {
     public:
-        virtual File &standardOutput()
+        virtual TextOutputStream &standardOutput()
         {
-            return File::standardOutput();
+            return TextOutputFile::standardOutput();
         }
-        virtual FileInitializer openFileForWriting(const char *filename)
+        virtual TextOutputStreamPointer openTextOutputFile(const char *filename)
         {
-            return FileInitializer(filename, "w");
+            return TextOutputStreamPointer(new TextOutputFile(filename));
         }
 };
 
 }   // namespace
 
 //! \cond libapi
-FileInputRedirectorInterface &defaultFileInputRedirector()
+IFileInputRedirector &defaultFileInputRedirector()
 {
     static DefaultInputRedirector instance;
     return instance;
 }
 
-FileOutputRedirectorInterface &defaultFileOutputRedirector()
+IFileOutputRedirector &defaultFileOutputRedirector()
 {
     static DefaultOutputRedirector instance;
     return instance;
index d0a7c6e47edf55ffaac4a34be22d3f100ce53acb..fe670460f1ae9ff9a4ff9a20ea3f8a53c4802676 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \libinternal \file
  * \brief
- * Declares gmx::FileOutputRedirectorInterface.
+ * Declares gmx::IFileOutputRedirector.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
@@ -45,7 +45,7 @@
 
 #include <string>
 
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/textstream.h"
 
 namespace gmx
 {
@@ -55,11 +55,10 @@ namespace gmx
  *
  * The calling code should take in this interface and use the methods in it
  * all file system operations that need to support this redirection.
- * By default, the code can then use defaultFileInputRedirector() in case no
- * redirection is needed.
  *
  * This allows tests to override the file existence checks without actually
- * using the file system.
+ * using the file system.  See IFileOutputRedirector for notes on
+ * a typical usage pattern.
  *
  * With some further refactoring of the File class, this could also support
  * redirecting input files from in-memory buffers as well, but for now the
@@ -68,10 +67,10 @@ namespace gmx
  * \inlibraryapi
  * \ingroup module_utility
  */
-class FileInputRedirectorInterface
+class IFileInputRedirector
 {
     public:
-        virtual ~FileInputRedirectorInterface();
+        virtual ~IFileInputRedirector();
 
         /*! \brief
          * Checks whether the provided path exists (and is a file).
@@ -88,46 +87,55 @@ class FileInputRedirectorInterface
 /*! \libinternal \brief
  * Allows capturing `stdout` and file output from code that supports it.
  *
- * The calling code should take in this interface and use the File objects
+ * The calling code should take in this interface and use the stream objects
  * it returns for all output that needs to support this redirection.
- * By default, the code can then use defaultFileOutputRedirector() in case no
- * redirection is needed.
  *
- * This allows tests to capture the file output without duplicating the
- * knowledge of which files are actually produced.  With some further
- * refactoring of the File class, this could support capturing the output into
- * in-memory buffers as well, but for now the current capabilities are
- * sufficient.
+ * Currently, the (nearly) only purpose for this interface is for unit tests to
+ * capture the file output without duplicating the knowledge of which files are
+ * actually produced.  The tests can also replace actual files with in-memory
+ * streams (e.g., a StringOutputStream), and test the output without actually
+ * accessing the file system and managing actual files.
+ *
+ * As the main user for non-default implementation of this interface is tests,
+ * code using this interface generally uses a pattern where the redirector is
+ * initialized to defaultFileOutputRedirector(), and a separate setter is
+ * provided for tests to change the default.  This allows code outside the
+ * tests (and outside the code actually calling the redirector) to be written
+ * as if this interface did not exist (i.e., they do not need to pass the
+ * default instance).
+ *
+ * Also, the interface only supports text files, but can be generalized if/when
+ * there is a need for binary streams (see also TextOutputStream).
  *
  * \inlibraryapi
  * \ingroup module_utility
  */
-class FileOutputRedirectorInterface
+class IFileOutputRedirector
 {
     public:
-        virtual ~FileOutputRedirectorInterface();
+        virtual ~IFileOutputRedirector();
 
         /*! \brief
-         * Returns a File object to use for `stdout` output.
+         * Returns a stream to use for `stdout` output.
          */
-        virtual File &standardOutput() = 0;
+        virtual TextOutputStream &standardOutput() = 0;
         /*! \brief
-         * Returns a File object to use for output to a given file.
+         * Returns a stream to use for output to a file at a given path.
          *
          * \param[in] filename  Requested file name.
          */
-        virtual FileInitializer openFileForWriting(const char *filename) = 0;
+        virtual TextOutputStreamPointer openTextOutputFile(const char *filename) = 0;
 
-        //! Convenience method to open a file using an std::string path.
-        FileInitializer openFileForWriting(const std::string &filename)
+        //! Convenience method to open a stream using an std::string path.
+        TextOutputStreamPointer openTextOutputFile(const std::string &filename)
         {
-            return openFileForWriting(filename.c_str());
+            return openTextOutputFile(filename.c_str());
         }
 };
 
 //! \cond libapi
 /*! \brief
- * Returns default implementation for FileInputRedirectorInterface.
+ * Returns default implementation for IFileInputRedirector.
  *
  * The returned implementation does not redirect anything, but just uses the
  * file system normally.
@@ -136,9 +144,9 @@ class FileOutputRedirectorInterface
  *
  * \ingroup module_utility
  */
-FileInputRedirectorInterface &defaultFileInputRedirector();
+IFileInputRedirector &defaultFileInputRedirector();
 /*! \brief
- * Returns default implementation for FileOutputRedirectorInterface.
+ * Returns default implementation for IFileOutputRedirector.
  *
  * The returned implementation does not redirect anything, but just opens the
  * files at requested locations.
@@ -147,7 +155,7 @@ FileInputRedirectorInterface &defaultFileInputRedirector();
  *
  * \ingroup module_utility
  */
-FileOutputRedirectorInterface &defaultFileOutputRedirector();
+IFileOutputRedirector &defaultFileOutputRedirector();
 //! \endcond
 
 } // namespace gmx
diff --git a/src/gromacs/utility/filestream.cpp b/src/gromacs/utility/filestream.cpp
new file mode 100644 (file)
index 0000000..5f24585
--- /dev/null
@@ -0,0 +1,285 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements classes from filestream.h.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_utility
+ */
+#include "gmxpre.h"
+
+#include "filestream.h"
+
+#include "config.h"
+
+#include <cerrno>
+#include <cstdio>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/stringutil.h"
+
+namespace gmx
+{
+
+namespace
+{
+
+//! Helper function for implementing readLine() for input streams.
+bool readLineImpl(FILE *fp, std::string *line)
+{
+    line->clear();
+    const size_t bufsize = 256;
+    std::string  result;
+    char         buf[bufsize];
+    buf[0] = '\0';
+    while (std::fgets(buf, bufsize, fp) != NULL)
+    {
+        const size_t length = std::strlen(buf);
+        result.append(buf, length);
+        if (length < bufsize - 1 || buf[length - 1] == '\n')
+        {
+            break;
+        }
+    }
+    if (std::ferror(fp))
+    {
+        GMX_THROW_WITH_ERRNO(FileIOError("Error while reading file"),
+                             "fgets", errno);
+    }
+    *line = result;
+    return !result.empty() || !std::feof(fp);
+}
+
+}   // namespace
+
+namespace internal
+{
+
+/********************************************************************
+ * FileStreamImpl
+ */
+
+class FileStreamImpl
+{
+    public:
+        explicit FileStreamImpl(FILE *fp)
+            : fp_(fp), bClose_(false)
+        {
+        }
+        FileStreamImpl(const char *filename, const char *mode)
+            : fp_(NULL), bClose_(true)
+        {
+            fp_ = std::fopen(filename, mode);
+            if (fp_ == NULL)
+            {
+                GMX_THROW_WITH_ERRNO(
+                        FileIOError(formatString("Could not open file '%s'", filename)),
+                        "fopen", errno);
+            }
+        }
+        ~FileStreamImpl()
+        {
+            if (fp_ != NULL && bClose_)
+            {
+                if (std::fclose(fp_) != 0)
+                {
+                    // TODO: Log the error somewhere
+                }
+            }
+        }
+
+        FILE *handle()
+        {
+            GMX_RELEASE_ASSERT(fp_ != NULL,
+                               "Attempted to access a file object that is not open");
+            return fp_;
+        }
+
+        void close()
+        {
+            GMX_RELEASE_ASSERT(fp_ != NULL,
+                               "Attempted to close a file object that is not open");
+            GMX_RELEASE_ASSERT(bClose_,
+                               "Attempted to close a file object that should not be");
+            const bool bOk = (std::fclose(fp_) == 0);
+            fp_ = NULL;
+            if (!bOk)
+            {
+                GMX_THROW_WITH_ERRNO(
+                        FileIOError("Error while closing file"), "fclose", errno);
+            }
+        }
+
+    private:
+        //! File handle for this object (NULL if the stream has been closed).
+        FILE  *fp_;
+        //! Whether \p fp_ should be closed by this object.
+        bool   bClose_;
+};
+
+}   // namespace internal
+
+using internal::FileStreamImpl;
+
+/********************************************************************
+ * StandardInputStream
+ */
+
+bool StandardInputStream::isInteractive() const
+{
+#ifdef HAVE_UNISTD_H
+    return isatty(fileno(stdin));
+#else
+    return true;
+#endif
+}
+
+bool StandardInputStream::readLine(std::string *line)
+{
+    return readLineImpl(stdin, line);
+}
+
+// static
+StandardInputStream &StandardInputStream::instance()
+{
+    static StandardInputStream stdinObject;
+    return stdinObject;
+}
+
+/********************************************************************
+ * TextInputFile
+ */
+
+// static
+FILE *TextInputFile::openRawHandle(const char *filename)
+{
+    FILE *fp = fopen(filename, "r");
+    if (fp == NULL)
+    {
+        GMX_THROW_WITH_ERRNO(
+                FileIOError(formatString("Could not open file '%s'", filename)),
+                "fopen", errno);
+    }
+    return fp;
+}
+
+// static
+FILE *TextInputFile::openRawHandle(const std::string &filename)
+{
+    return openRawHandle(filename.c_str());
+}
+
+TextInputFile::TextInputFile(const std::string &filename)
+    : impl_(new FileStreamImpl(filename.c_str(), "r"))
+{
+}
+
+TextInputFile::TextInputFile(FILE *fp)
+    : impl_(new FileStreamImpl(fp))
+{
+}
+
+TextInputFile::~TextInputFile()
+{
+}
+
+FILE *TextInputFile::handle()
+{
+    return impl_->handle();
+}
+
+bool TextInputFile::readLine(std::string *line)
+{
+    return readLineImpl(impl_->handle(), line);
+}
+
+void TextInputFile::close()
+{
+    impl_->close();
+}
+
+/********************************************************************
+ * TextOutputFile
+ */
+
+TextOutputFile::TextOutputFile(const std::string &filename)
+    : impl_(new FileStreamImpl(filename.c_str(), "w"))
+{
+}
+
+TextOutputFile::TextOutputFile(FILE *fp)
+    : impl_(new FileStreamImpl(fp))
+{
+}
+
+TextOutputFile::~TextOutputFile()
+{
+}
+
+void TextOutputFile::write(const char *str)
+{
+    if (std::fprintf(impl_->handle(), "%s", str) < 0)
+    {
+        GMX_THROW_WITH_ERRNO(FileIOError("Writing to file failed"),
+                             "fprintf", errno);
+    }
+}
+
+void TextOutputFile::close()
+{
+    impl_->close();
+}
+
+// static
+TextOutputFile &TextOutputFile::standardOutput()
+{
+    static TextOutputFile stdoutObject(stdout);
+    return stdoutObject;
+}
+
+// static
+TextOutputFile &TextOutputFile::standardError()
+{
+    static TextOutputFile stderrObject(stderr);
+    return stderrObject;
+}
+
+} // namespace gmx
diff --git a/src/gromacs/utility/filestream.h b/src/gromacs/utility/filestream.h
new file mode 100644 (file)
index 0000000..23c354c
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares implementations for textstream.h interfaces for file input/output.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_FILESTREAM_H
+#define GMX_UTILITY_FILESTREAM_H
+
+#include <cstdio>
+
+#include <string>
+
+#include "gromacs/utility/classhelpers.h"
+#include "gromacs/utility/textstream.h"
+
+namespace gmx
+{
+
+namespace internal
+{
+class FileStreamImpl;
+}
+
+/*! \libinternal \brief
+ * Text input stream implementation for reading from `stdin`.
+ *
+ * Implementations for the TextInputStream methods throw FileIOError on any
+ * I/O error.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class StandardInputStream : public TextInputStream
+{
+    public:
+        /*! \brief
+         * Returns whether `stdin` is an interactive terminal.
+         *
+         * Only works on Unix, otherwise always returns true.
+         *
+         * Does not throw.
+         */
+        bool isInteractive() const;
+
+        // From TextInputStream
+        virtual bool readLine(std::string *line);
+        virtual void close() {}
+
+        /*! \brief
+         * Returns a stream for accessing `stdin`.
+         *
+         * Does not throw.
+         */
+        static StandardInputStream &instance();
+};
+
+/*! \libinternal \brief
+ * Text input stream implementation for reading from a file.
+ *
+ * Implementations for the TextInputStream methods throw FileIOError on any
+ * I/O error.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class TextInputFile : public TextInputStream
+{
+    public:
+        /*! \brief
+         * Opens a file and returns a `FILE` handle.
+         *
+         * \param[in] filename  Path of the file to open.
+         * \throws    FileIOError on any I/O error.
+         *
+         * Instead of returning `NULL` on errors, throws an exception with
+         * additional details (including the file name and `errno`).
+         */
+        static FILE *openRawHandle(const char *filename);
+        //! \copydoc openRawHandle(const char *, const char *)
+        static FILE *openRawHandle(const std::string &filename);
+
+        /*! \brief
+         * Opens a text file as a stream.
+         *
+         * \param[in]  filename  Path to the file to open.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     FileIOError on any I/O error.
+         */
+        explicit TextInputFile(const std::string &filename);
+        /*! \brief
+         * Initializes file object from an existing file handle.
+         *
+         * \param[in]  fp     File handle to use.
+         * \throws     std::bad_alloc if out of memory.
+         *
+         * The caller is responsible of closing the file; close() does nothing
+         * for an object constructed this way.
+         */
+        explicit TextInputFile(FILE *fp);
+        virtual ~TextInputFile();
+
+        /*! \brief
+         * Returns a raw handle to the input file.
+         *
+         * This is provided for interoperability with older C-like code.
+         */
+        FILE *handle();
+
+        // From TextInputStream
+        virtual bool readLine(std::string *line);
+        virtual void close();
+
+    private:
+        PrivateImplPointer<internal::FileStreamImpl> impl_;
+};
+
+/*! \libinternal \brief
+ * Text output stream implementation for writing to a file.
+ *
+ * Implementations for the TextOutputStream methods throw FileIOError on any
+ * I/O error.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class TextOutputFile : public TextOutputStream
+{
+    public:
+        //! \copydoc TextInputFile::TextInputFile(const std::string &)
+        explicit TextOutputFile(const std::string &filename);
+        //! \copydoc TextInputFile::TextInputFile(FILE *)
+        explicit TextOutputFile(FILE *fp);
+        virtual ~TextOutputFile();
+
+        // From TextOutputStream
+        virtual void write(const char *text);
+        virtual void close();
+
+        /*! \brief
+         * Returns a stream for accessing `stdout`.
+         *
+         * \throws    std::bad_alloc if out of memory (only on first call).
+         */
+        static TextOutputFile &standardOutput();
+        /*! \brief
+         * Returns a stream for accessing `stderr`.
+         *
+         * \throws    std::bad_alloc if out of memory (only on first call).
+         */
+        static TextOutputFile &standardError();
+
+    private:
+        PrivateImplPointer<internal::FileStreamImpl> impl_;
+};
+
+} // namespace gmx
+
+#endif
index 55285b292be7a7478f34024929a35b9de2da0697..2ca5514005b934bce484410de85303e6402c4af7 100644 (file)
@@ -165,7 +165,7 @@ void push_ps(FILE *fp)
 #ifdef gmx_ffclose
 #undef gmx_ffclose
 #endif
-#if (!defined(HAVE_PIPES) && !defined(__native_client__))
+#if (!HAVE_PIPES && !defined(__native_client__))
 static FILE *popen(const char *nm, const char *mode)
 {
     gmx_impl("Sorry no pipes...");
@@ -179,7 +179,7 @@ static int pclose(FILE *fp)
 
     return 0;
 }
-#endif /* !defined(HAVE_PIPES) && !defined(__native_client__) */
+#endif /* !HAVE_PIPES && !defined(__native_client__) */
 #endif /* GMX_FAHCORE */
 
 int gmx_ffclose(FILE *fp)
index 1a9cd02901351b935df4d657d84fc68cd75b5297..4b3270eca7296f775c29dd7e26252c3e80646ffa 100644 (file)
 
 #include "config.h"
 
-#if defined(HAVE_POSIX_REGEX)
-#include <sys/types.h>
+#if HAVE_POSIX_REGEX
+#    include <sys/types.h>
 // old Mac needs sys/types.h before regex.h
-#include <regex.h>
-#define USE_POSIX_REGEX
-#elif defined(HAVE_CXX11_REGEX)
-#include <regex>
-#define USE_CXX11_REGEX
+#    include <regex.h>
+#elif HAVE_CXX11_REGEX
+#    include <regex>
 #endif
 
 #include "gromacs/utility/exceptions.h"
@@ -64,14 +62,14 @@ namespace gmx
 // static
 bool Regex::isSupported()
 {
-#if defined(USE_POSIX_REGEX) || defined(USE_CXX11_REGEX)
+#if HAVE_POSIX_REGEX || HAVE_CXX11_REGEX
     return true;
 #else
     return false;
 #endif
 }
 
-#if defined(USE_POSIX_REGEX)
+#if HAVE_POSIX_REGEX
 class Regex::Impl
 {
     public:
@@ -113,7 +111,7 @@ class Regex::Impl
 
         regex_t                 regex_;
 };
-#elif defined(USE_CXX11_REGEX)
+#elif HAVE_CXX11_REGEX
 class Regex::Impl
 {
     public:
similarity index 62%
rename from src/gromacs/mdlib/genborn_sse2_double.h
rename to src/gromacs/utility/mutex.h
index 0bf4ea9d6946ac565442f67e81510ab86c353c8e..34c7375f223d96e588633e3118cbec3a8050f247 100644 (file)
@@ -1,9 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifndef _genborn_sse2_double_h
-#define _genborn_sse2_double_h
+/*! \libinternal \file
+ * \brief
+ * Declares C++11-style basic threading primitives
+ * (gmx::Mutex, gmx::lock_guard).
+ *
+ * For now, the implementation is imported from thread-MPI.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_THREADING_MUTEX_H
+#define GMX_THREADING_MUTEX_H
 
-#include "gromacs/legacyheaders/typedefs.h"
+#include "thread_mpi/mutex.h"
 
-int
-calc_gb_rad_still_sse2_double(t_commrec *cr, t_forcerec *fr, int natoms, gmx_localtop_t *top,
-                              double *x, t_nblist *nl, gmx_genborn_t *born);
+namespace gmx
+{
 
-int
-calc_gb_chainrule_sse2_double(int natoms, t_nblist *nl, double *dadx, double *dvda, double *xd, double *f,
-                              double *fshift, double *shift_vec, int gb_algorithm,
-                              gmx_genborn_t *born, t_mdatoms *md);
+//! \cond libapi
+/*! \libinternal \brief
+ * C++11-compatible basic mutex.
+ */
+typedef tMPI::mutex Mutex;
+//! \endcond
+using tMPI::lock_guard;
 
-int
-calc_gb_rad_hct_obc_sse2_double(t_commrec *cr, t_forcerec *fr, int natoms, gmx_localtop_t *top,
-                                double *x, t_nblist *nl, gmx_genborn_t *born, t_mdatoms *md, int gb_algorithm);
+} // namespace gmx
 
-#endif /* _genborn_sse2_double_h */
+#endif
diff --git a/src/gromacs/utility/nodelete.h b/src/gromacs/utility/nodelete.h
new file mode 100644 (file)
index 0000000..7f9fe0c
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares no_delete deleter for boost::shared_ptr.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_NODELETE_H
+#define GMX_UTILITY_NODELETE_H
+
+namespace gmx
+{
+
+/*! \libinternal \brief
+ * Deleter for boost::shared_ptr that does nothing.
+ *
+ * This is useful for cases where a class needs to keep a reference to another
+ * class, and optionally also manage the lifetime of that other class.
+ * The simplest construct (that does not force all callers to use heap
+ * allocation and boost::shared_ptr for the referenced class) is to use a
+ * single boost::shared_ptr to hold that reference, and use no_delete as the
+ * deleter if the lifetime is managed externally.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+template <class T>
+struct no_delete
+{
+    //! Deleter that does nothing.
+    void operator()(T *) {}
+};
+
+} // namespace gmx
+
+#endif
index d6aa17140d65db27cd77cd0f31ef291dd0a6903a..60c0e0cd7adbb164f5c3a1ad20f47f7762e71b16 100644 (file)
 
 #include <cctype>
 #include <cerrno>
+#include <cstdio>
 #include <cstdlib>
 #include <cstring>
 
 #include <algorithm>
+#include <string>
 
 #include <sys/stat.h>
 
@@ -386,6 +388,44 @@ std::string Path::resolveSymlinks(const std::string &path)
     return result;
 }
 
+/********************************************************************
+ * File
+ */
+
+// static
+bool File::exists(const char *filename)
+{
+    if (filename == NULL)
+    {
+        return false;
+    }
+    FILE *test = std::fopen(filename, "r");
+    if (test == NULL)
+    {
+        return false;
+    }
+    else
+    {
+        std::fclose(test);
+        // Windows doesn't allow fopen of directory, so we don't need to check
+        // this separately.
+#ifndef GMX_NATIVE_WINDOWS
+        struct stat st_buf;
+        int         status = stat(filename, &st_buf);
+        if (status != 0 || !S_ISREG(st_buf.st_mode))
+        {
+            return false;
+        }
+#endif
+        return true;
+    }
+}
+
+// static
+bool File::exists(const std::string &filename)
+{
+    return exists(filename.c_str());
+}
 
 /********************************************************************
  * Directory
index ef2b3e884879ca7c7ecbc8ea4f282037379b8911..8dba41e84c0f1947cb21c62b907eb601e4ad911e 100644 (file)
@@ -85,6 +85,25 @@ class Path
         Path();
 };
 
+class File
+{
+    public:
+        /*! \brief
+         * Checks whether a file exists and is a regular file.
+         *
+         * \param[in] filename  Path to the file to check.
+         * \returns   `true` if \p filename exists and is accessible.
+         *
+         * Does not throw.
+         */
+        static bool exists(const char *filename);
+        //! \copydoc exists(const char *)
+        static bool exists(const std::string &filename);
+
+    private:
+        // Disallow instantiation.
+        File();
+};
 
 class Directory
 {
index 5edf9aa284c57da018f13e3315e523b61ccd7803..4de54036ab0948f8babc697f4be49ebe67a9e5ac 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \internal \file
  * \brief
- * Implements gmx::ProgramContextInterface and related methods.
+ * Implements gmx::IProgramContext and related methods.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_utility
@@ -55,14 +55,14 @@ namespace
 //! \{
 
 /*! \brief
- * Default implementation of ProgramContextInterface.
+ * Default implementation of IProgramContext.
  *
  * This implementation is used if nothing has been set with
  * setProgramContext().
  *
  * Since it is constructed using a global initializer, it should not throw.
  */
-class DefaultProgramContext : public ProgramContextInterface
+class DefaultProgramContext : public IProgramContext
 {
     public:
         DefaultProgramContext() {}
@@ -78,7 +78,7 @@ class DefaultProgramContext : public ProgramContextInterface
 };
 
 //! Global program info; stores the object set with setProgramContext().
-const ProgramContextInterface *g_programContext;
+const IProgramContext         *g_programContext;
 //! Default program context if nothing is set.
 const DefaultProgramContext    g_defaultContext;
 
@@ -86,7 +86,7 @@ const DefaultProgramContext    g_defaultContext;
 
 }   // namespace
 
-const ProgramContextInterface &getProgramContext()
+const IProgramContext &getProgramContext()
 {
     if (g_programContext != NULL)
     {
@@ -95,7 +95,7 @@ const ProgramContextInterface &getProgramContext()
     return g_defaultContext;
 }
 
-void setProgramContext(const ProgramContextInterface *programContext)
+void setProgramContext(const IProgramContext *programContext)
 {
     g_programContext = programContext;
 }
index d7aede1988c088f43f50e618ee4ccde90c25cac8..9ac17299364133d5bf51d7af91460b89f1eb88c3 100644 (file)
@@ -34,7 +34,7 @@
  */
 /*! \file
  * \brief
- * Declares gmx::ProgramContextInterface and related methods.
+ * Declares gmx::IProgramContext and related methods.
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inpublicapi
@@ -51,7 +51,7 @@ namespace gmx
 
 /*! \brief
  * Provides information about installation prefix (see
- * ProgramContextInterface::installationPrefix()).
+ * IProgramContext::installationPrefix()).
  *
  * \inpublicapi
  */
@@ -109,7 +109,7 @@ struct InstallationPrefixInfo
  * \see setProgramContext()
  * \inpublicapi
  */
-class ProgramContextInterface
+class IProgramContext
 {
     public:
         /*! \brief
@@ -164,11 +164,11 @@ class ProgramContextInterface
         virtual const char *commandLine() const = 0;
 
     protected:
-        virtual ~ProgramContextInterface() {}
+        virtual ~IProgramContext() {}
 };
 
 /*! \brief
- * Returns the global ProgramContextInterface instance.
+ * Returns the global IProgramContext instance.
  *
  * \returns The context set with setProgramContext().
  *
@@ -185,11 +185,11 @@ class ProgramContextInterface
  * the presence of such calls.  For example, initForCommandLine() assumes that
  * such calls do not exist to be able to free the context before exiting.
  *
- * \see ProgramContextInterface
+ * \see IProgramContext
  */
-const ProgramContextInterface &getProgramContext();
+const IProgramContext &getProgramContext();
 /*! \brief
- * Sets the global ProgramContextInterface instance.
+ * Sets the global IProgramContext instance.
  *
  * \param[in] context  Program context to set
  *     (can be NULL to restore the default context).
@@ -209,9 +209,9 @@ const ProgramContextInterface &getProgramContext();
  *
  * Does not throw.
  *
- * \see ProgramContextInterface
+ * \see IProgramContext
  */
-void setProgramContext(const ProgramContextInterface *context);
+void setProgramContext(const IProgramContext *context);
 
 //! \}
 
similarity index 98%
rename from src/gromacs/utility/qsort_threadsafe.c
rename to src/gromacs/utility/qsort_threadsafe.cpp
index 0f0849076d9d86296102516e970934c9d7c2b5d7..6a63bf225f43857a984686b22a2954ead4c47384 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -131,6 +131,11 @@ gmx_qsort(void *           base,
     int    t, v;
     size_t s, st;
 
+    if (size == 0)
+    {
+        return;
+    }
+
     cbase = (char *)base;
 
     swaptype = (size_t)(cbase - (char *)0) % sizeof(int) || size % sizeof(int) ? 2 : size == sizeof(int) ? 0 : 1;
@@ -175,8 +180,8 @@ gmx_qsort(void *           base,
     }
     else
     {
-        pv = (char*)(void*)&v;
         v  = *(int *)pm;
+        pv = (char*)(void*)&v;
     }
 
     pa = pb = cbase;
index 1e7909ed31309803793c699d6582b10d2fa0d014..1b1e2bdf175e9cb7e26896dc6b2530096ca4d343 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -89,7 +89,7 @@ class scoped_cptr
         //! Returns the stored pointer.
         T *get() const { return ptr_; }
         //! Check for non-null pointer in boolean context.
-#ifdef GMX_CXX11
+#if GMX_CXX11
         explicit
 #endif
         operator bool () const { return ptr_ != 0; }
similarity index 95%
rename from src/gromacs/utility/smalloc.c
rename to src/gromacs/utility/smalloc.cpp
index 876675ecd440ad17f2346181bbed9b69c810e053..ac8fd499b0e6849de70030b19d7e9755ba3feb30 100644 (file)
@@ -43,7 +43,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #ifdef WITH_DMALLOC
 #include <dmalloc.h>
@@ -52,6 +51,8 @@
 #include <malloc.h>
 #endif
 
+#include <cstring>
+
 #include "thread_mpi/threads.h"
 
 #include "gromacs/utility/dir_separator.h"
@@ -131,7 +132,7 @@ void *save_malloc(const char *name, const char *file, int line, size_t size)
         if ((p = malloc(size)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to malloc %"GMX_PRId64 " bytes for %s\n"
+                      "Not enough memory. Failed to malloc %" GMX_PRId64 " bytes for %s\n"
                       "(called from file %s, line %d)",
                       (gmx_int64_t)size, name, file, line);
         }
@@ -169,8 +170,8 @@ void *save_calloc(const char *name, const char *file, int line,
         if ((p = malloc((size_t)nelem*(size_t)elsize)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to calloc %"GMX_PRId64
-                      " elements of size %"GMX_PRId64
+                      "Not enough memory. Failed to calloc %" GMX_PRId64
+                      " elements of size %" GMX_PRId64
                       " for %s\n(called from file %s, line %d)",
                       (gmx_int64_t)nelem, (gmx_int64_t)elsize,
                       name, file, line);
@@ -180,8 +181,8 @@ void *save_calloc(const char *name, const char *file, int line,
         if ((p = calloc((size_t)nelem, (size_t)elsize)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to calloc %"GMX_PRId64
-                      " elements of size %"GMX_PRId64
+                      "Not enough memory. Failed to calloc %" GMX_PRId64
+                      " elements of size %" GMX_PRId64
                       " for %s\n(called from file %s, line %d)",
                       (gmx_int64_t)nelem, (gmx_int64_t)elsize, name, file, line);
         }
@@ -225,7 +226,7 @@ void *save_realloc(const char *name, const char *file, int line, void *ptr,
         if (p == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to realloc %"GMX_PRId64 " bytes for %s, %s=%x\n"
+                      "Not enough memory. Failed to realloc %" GMX_PRId64 " bytes for %s, %s=%x\n"
                       "(called from file %s, line %d)",
                       (gmx_int64_t)size, name, name, ptr, file, line);
         }
@@ -343,7 +344,6 @@ void *save_calloc_aligned(const char *name, const char *file, int line,
 /* This routine can NOT be called with any pointer */
 void save_free_aligned(const char gmx_unused *name, const char gmx_unused *file, int gmx_unused line, void *ptr)
 {
-    int   i, j;
     void *free = ptr;
 
     if (NULL != ptr)
@@ -375,7 +375,7 @@ int over_alloc_dd(int n)
 {
     if (g_bOverAllocDD)
     {
-        return OVER_ALLOC_FAC*n + 100;
+        return static_cast<int>(OVER_ALLOC_FAC*n + 100);
     }
     else
     {
diff --git a/src/gromacs/utility/stringstream.cpp b/src/gromacs/utility/stringstream.cpp
new file mode 100644 (file)
index 0000000..7a93d34
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements classes from stringstream.h.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_utility
+ */
+#include "gmxpre.h"
+
+#include "stringstream.h"
+
+#include <string>
+
+namespace gmx
+{
+
+void StringOutputStream::write(const char *str)
+{
+    str_.append(str);
+}
+
+void StringOutputStream::close()
+{
+}
+
+} // namespace gmx
diff --git a/src/gromacs/utility/stringstream.h b/src/gromacs/utility/stringstream.h
new file mode 100644 (file)
index 0000000..899a304
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares implementations for textstream.h interfaces for input/output to
+ * in-memory strings.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_STRINGSTREAM_H
+#define GMX_UTILITY_STRINGSTREAM_H
+
+#include <string>
+
+#include "gromacs/utility/classhelpers.h"
+#include "gromacs/utility/textstream.h"
+
+namespace gmx
+{
+
+/*! \libinternal \brief
+ * Text output stream implementation for writing to an in-memory string.
+ *
+ * Implementations for the TextOutputStream methods throw std::bad_alloc if
+ * reallocation of the string fails.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class StringOutputStream : public TextOutputStream
+{
+    public:
+        //! Returns the text written to the stream so far.
+        const std::string &toString() const { return str_; }
+
+        // From TextOutputStream
+        virtual void write(const char *text);
+        virtual void close();
+
+    private:
+        std::string str_;
+};
+
+} // namespace gmx
+
+#endif
index 86abf82a085e9c370569609e6a6d188f994eb06f..54b32214926a49b5cd98658a72dbbbc0fe5f284b 100644 (file)
 namespace gmx
 {
 
-bool endsWith(const std::string &str, const char *suffix)
+bool endsWith(const char *str, const char *suffix)
 {
-    if (suffix == NULL || suffix[0] == '\0')
+    if (isNullOrEmpty(suffix))
     {
         return true;
     }
-    size_t length = std::strlen(suffix);
-    return (str.length() >= length
-            && str.compare(str.length() - length, length, suffix) == 0);
+    const size_t strLength    = std::strlen(str);
+    const size_t suffixLength = std::strlen(suffix);
+    return (strLength >= suffixLength
+            && std::strcmp(&str[strLength - suffixLength], suffix) == 0);
 }
 
 std::string stripSuffixIfPresent(const std::string &str, const char *suffix)
@@ -247,7 +248,7 @@ replaceAllWords(const std::string &input, const std::string &from,
 
 TextLineWrapperSettings::TextLineWrapperSettings()
     : maxLength_(0), indent_(0), firstLineIndent_(-1),
-      bStripLeadingWhitespace_(false), continuationChar_('\0')
+      bKeepFinalSpaces_(false), continuationChar_('\0')
 {
 }
 
@@ -256,13 +257,19 @@ TextLineWrapperSettings::TextLineWrapperSettings()
  * TextLineWrapper
  */
 
+bool TextLineWrapper::isTrivial() const
+{
+    return settings_.lineLength() == 0 && settings_.indent() == 0
+           && settings_.firstLineIndent_ <= 0;
+}
+
 size_t
 TextLineWrapper::findNextLine(const char *input, size_t lineStart) const
 {
     size_t inputLength = std::strlen(input);
     bool   bFirstLine  = (lineStart == 0 || input[lineStart - 1] == '\n');
     // Ignore leading whitespace if necessary.
-    if (!bFirstLine || settings_.bStripLeadingWhitespace_)
+    if (!bFirstLine)
     {
         lineStart += std::strspn(input + lineStart, " ");
         if (lineStart >= inputLength)
@@ -307,7 +314,7 @@ TextLineWrapper::formatLine(const std::string &input,
     size_t inputLength = input.length();
     bool   bFirstLine  = (lineStart == 0 || input[lineStart - 1] == '\n');
     // Strip leading whitespace if necessary.
-    if (!bFirstLine || settings_.bStripLeadingWhitespace_)
+    if (!bFirstLine)
     {
         lineStart = input.find_first_not_of(' ', lineStart);
         if (lineStart >= inputLength)
@@ -318,9 +325,12 @@ TextLineWrapper::formatLine(const std::string &input,
     int  indent        = (bFirstLine ? settings_.firstLineIndent() : settings_.indent());
     bool bContinuation = (lineEnd < inputLength && input[lineEnd - 1] != '\n');
     // Strip trailing whitespace.
-    while (lineEnd > lineStart && std::isspace(input[lineEnd - 1]))
+    if (!settings_.bKeepFinalSpaces_ || lineEnd < inputLength || input[inputLength - 1] == '\n')
     {
-        --lineEnd;
+        while (lineEnd > lineStart && std::isspace(input[lineEnd - 1]))
+        {
+            --lineEnd;
+        }
     }
 
     const size_t lineLength = lineEnd - lineStart;
index e7e11a6d9ef5c9bf5d1d3a04a7a7dd22add7df77..004daae3e0353708bfa75d731a5fe6fd2db4b0db 100644 (file)
@@ -59,7 +59,7 @@ namespace gmx
  *
  * Does not throw.
  */
-bool inline isNullOrEmpty(const char *str)
+static inline bool isNullOrEmpty(const char *str)
 {
     return str == NULL || str[0] == '\0';
 }
@@ -74,12 +74,12 @@ bool inline isNullOrEmpty(const char *str)
  * Returns true if \p prefix is empty.
  * Does not throw.
  */
-bool inline startsWith(const std::string &str, const std::string &prefix)
+static inline bool startsWith(const std::string &str, const std::string &prefix)
 {
     return str.compare(0, prefix.length(), prefix) == 0;
 }
 //! \copydoc startsWith(const std::string &, const std::string &)
-bool inline startsWith(const char *str, const char *prefix)
+static inline bool startsWith(const char *str, const char *prefix)
 {
     return std::strncmp(str, prefix, std::strlen(prefix)) == 0;
 }
@@ -94,7 +94,12 @@ bool inline startsWith(const char *str, const char *prefix)
  * Returns true if \p suffix is NULL or empty.
  * Does not throw.
  */
-bool endsWith(const std::string &str, const char *suffix);
+bool endsWith(const char *str, const char *suffix);
+//! \copydoc endsWith(const char *, const char *)
+static inline bool endsWith(const std::string &str, const char *suffix)
+{
+    return endsWith(str.c_str(), suffix);
+}
 
 /*! \brief
  * Removes a suffix from a string.
@@ -335,7 +340,7 @@ class TextLineWrapperSettings
          *  - No maximum line width (only explicit line breaks).
          *  - No indentation.
          *  - No continuation characters.
-         *  - Ignore whitespace after an explicit newline.
+         *  - Do not keep final spaces in input strings.
          */
         TextLineWrapperSettings();
 
@@ -366,18 +371,18 @@ class TextLineWrapperSettings
          */
         void setFirstLineIndent(int indent) { firstLineIndent_ = indent; }
         /*! \brief
-         * Sets whether to remove spaces after an explicit newline.
+         * Sets whether final spaces in input should be kept.
          *
-         * \param[in] bStrip  If true, spaces after newline are ignored.
+         * \param[in] bKeep  Whether to keep spaces at the end of the input.
          *
-         * If not removed, the space is added to the indentation set with
-         * setIndent().
-         * The default is to not strip such whitespace.
+         * This means that wrapping a string that ends in spaces also keeps
+         * those spaces in the output.  This allows using the wrapper for
+         * partial lines where the initial part of the line may end in a space.
+         * By default, all trailing whitespace is removed.  Note that this
+         * option does not affect spaces before an explicit newline: those are
+         * always removed.
          */
-        void setStripLeadingWhitespace(bool bStrip)
-        {
-            bStripLeadingWhitespace_ = bStrip;
-        }
+        void setKeepFinalSpaces(bool bKeep) { bKeepFinalSpaces_ = bKeep; }
         /*! \brief
          * Sets a continuation marker for wrapped lines.
          *
@@ -424,8 +429,8 @@ class TextLineWrapperSettings
          * If -1, \a indent_ is used.
          */
         int                     firstLineIndent_;
-        //! Whether to ignore or preserve space after a newline.
-        bool                    bStripLeadingWhitespace_;
+        //! Whether to keep spaces at end of input.
+        bool                    bKeepFinalSpaces_;
         //! If not \c '\0', mark each wrapping point with this character.
         char                    continuationChar_;
 
@@ -503,6 +508,9 @@ class TextLineWrapper
          */
         TextLineWrapperSettings &settings() { return settings_; }
 
+        //! Returns true if the wrapper would not modify the input string.
+        bool isTrivial() const;
+
         /*! \brief
          * Finds the next line to be wrapped.
          *
index a002c762c3f3d91d2d001eca20826f516356bf27..c980a24363ae2883e27f62dcf377ce9c0b1e2117 100644 (file)
@@ -35,4 +35,6 @@
 gmx_add_unit_test(UtilityUnitTests utility-test
                   arrayref.cpp
                   bitmask32.cpp bitmask64.cpp bitmask128.cpp
-                  stringutil.cpp)
+                  stringutil.cpp
+                  textwriter.cpp
+                  )
index f277fc930b97c4ba9836c38f9b0d203ea8c22603..1bb9fb422799f30449e826cc210bca64490a9c0a 100644 (file)
@@ -1,12 +1,7 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
 <ReferenceData>
-  <String Name="WrappedAt14StripLeading"><![CDATA[
-A quick brown
-fox jumps
-over the lazy
-dog]]></String>
-  <String Name="WrappedAt14PreserveLeading"><![CDATA[
+  <String Name="WrappedAt14"><![CDATA[
  A quick brown
 fox jumps
  over the lazy
diff --git a/src/gromacs/utility/tests/refdata/TextWriterTest_WritesLines.xml b/src/gromacs/utility/tests/refdata/TextWriterTest_WritesLines.xml
new file mode 100644 (file)
index 0000000..25f4a2f
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="Output"><![CDATA[
+Explicit newline
+Implicit newline
+Explicit newline
+Implicit newline
+
+]]></String>
+</ReferenceData>
diff --git a/src/gromacs/utility/tests/refdata/TextWriterTest_WritesLinesInParts.xml b/src/gromacs/utility/tests/refdata/TextWriterTest_WritesLinesInParts.xml
new file mode 100644 (file)
index 0000000..703467f
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="Output"><![CDATA[
+Partial spaced line
+Partial spaced line
+]]></String>
+</ReferenceData>
diff --git a/src/gromacs/utility/tests/refdata/TextWriterTest_WritesLinesInPartsWithWrapper.xml b/src/gromacs/utility/tests/refdata/TextWriterTest_WritesLinesInPartsWithWrapper.xml
new file mode 100644 (file)
index 0000000..703467f
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="Output"><![CDATA[
+Partial spaced line
+Partial spaced line
+]]></String>
+</ReferenceData>
diff --git a/src/gromacs/utility/tests/refdata/TextWriterTest_WritesWrappedLines.xml b/src/gromacs/utility/tests/refdata/TextWriterTest_WritesWrappedLines.xml
new file mode 100644 (file)
index 0000000..a87ee7d
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="Output"><![CDATA[
+  Wrapped and
+  indented text
+  Wrapped and
+  indented text
+
+]]></String>
+</ReferenceData>
index ba1683d06d236ae5a99f15c9506bb203c601a243..7145fdb109a48cddf46ce992ad2fa340e5fce318 100644 (file)
@@ -256,7 +256,23 @@ TEST_F(TextLineWrapperTest, HandlesEmptyStrings)
     EXPECT_EQ("", wrapper.wrapToString(""));
     EXPECT_EQ("", wrapper.wrapToString("   "));
     EXPECT_TRUE(wrapper.wrapToVector("").empty());
-    EXPECT_TRUE(wrapper.wrapToString("   ").empty());
+    {
+        std::vector<std::string> wrapped(wrapper.wrapToVector("   "));
+        ASSERT_EQ(1U, wrapped.size());
+        EXPECT_EQ("", wrapped[0]);
+    }
+}
+
+TEST_F(TextLineWrapperTest, HandlesTrailingWhitespace)
+{
+    gmx::TextLineWrapper wrapper;
+
+    EXPECT_EQ("line", wrapper.wrapToString("line   "));
+    EXPECT_EQ("line\n", wrapper.wrapToString("line   \n"));
+
+    wrapper.settings().setKeepFinalSpaces(true);
+    EXPECT_EQ("line   ", wrapper.wrapToString("line   "));
+    EXPECT_EQ("line\n", wrapper.wrapToString("line   \n"));
 }
 
 TEST_F(TextLineWrapperTest, HandlesTrailingNewlines)
@@ -368,14 +384,10 @@ TEST_F(TextLineWrapperTest, HandlesContinuationCharacter)
 TEST_F(TextLineWrapperTest, WrapsCorrectlyWithExtraWhitespace)
 {
     gmx::TextLineWrapper wrapper;
-
     wrapper.settings().setLineLength(14);
-    wrapper.settings().setStripLeadingWhitespace(true);
-    checkText(wrapper.wrapToString(g_wrapTextWhitespace),
-              "WrappedAt14StripLeading");
-    wrapper.settings().setStripLeadingWhitespace(false);
+
     checkText(wrapper.wrapToString(g_wrapTextWhitespace),
-              "WrappedAt14PreserveLeading");
+              "WrappedAt14");
 }
 
 } // namespace
diff --git a/src/gromacs/utility/tests/textwriter.cpp b/src/gromacs/utility/tests/textwriter.cpp
new file mode 100644 (file)
index 0000000..d1cc1ed
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Tests for gmx::TextWriter.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_utility
+ */
+#include "gmxpre.h"
+
+#include "gromacs/utility/textwriter.h"
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include "gromacs/utility/stringstream.h"
+#include "gromacs/utility/stringutil.h"
+
+#include "testutils/stringtest.h"
+
+namespace
+{
+
+class TextWriterTest : public gmx::test::StringTestBase
+{
+    public:
+        TextWriterTest() : writer_(&stream_)
+        {
+        }
+
+        void checkOutput()
+        {
+            checkText(stream_.toString(), "Output");
+        }
+
+        gmx::StringOutputStream  stream_;
+        gmx::TextWriter          writer_;
+};
+
+TEST_F(TextWriterTest, WritesLines)
+{
+    writer_.writeLine("Explicit newline\n");
+    writer_.writeLine("Implicit newline");
+    writer_.writeLine(std::string("Explicit newline\n"));
+    writer_.writeLine(std::string("Implicit newline"));
+    writer_.writeLine();
+    checkOutput();
+}
+
+TEST_F(TextWriterTest, WritesLinesInParts)
+{
+    writer_.writeString("Partial ");
+    writer_.writeString("spaced");
+    writer_.writeString(" line");
+    writer_.writeLine();
+    writer_.writeString(std::string("Partial "));
+    writer_.writeString(std::string("spaced"));
+    writer_.writeString(std::string(" line"));
+    writer_.writeLine();
+    checkOutput();
+}
+
+TEST_F(TextWriterTest, WritesWrappedLines)
+{
+    writer_.wrapperSettings().setIndent(2);
+    writer_.wrapperSettings().setLineLength(15);
+    writer_.writeLine("Wrapped and indented text");
+    writer_.writeLine(std::string("Wrapped and indented text"));
+    writer_.writeLine();
+    checkOutput();
+}
+
+TEST_F(TextWriterTest, WritesLinesInPartsWithWrapper)
+{
+    writer_.wrapperSettings().setLineLength(50);
+    writer_.writeString("Partial ");
+    writer_.writeString("spaced");
+    writer_.writeString(" line");
+    writer_.writeLine();
+    writer_.writeString(std::string("Partial "));
+    writer_.writeString(std::string("spaced"));
+    writer_.writeString(std::string(" line"));
+    writer_.writeLine();
+    checkOutput();
+}
+
+} // namespace
diff --git a/src/gromacs/utility/textreader.cpp b/src/gromacs/utility/textreader.cpp
new file mode 100644 (file)
index 0000000..4366149
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements gmx::TextReader.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_utility
+ */
+#include "gmxpre.h"
+
+#include "textreader.h"
+
+#include "gromacs/utility/filestream.h"
+#include "gromacs/utility/nodelete.h"
+#include "gromacs/utility/textstream.h"
+
+namespace gmx
+{
+
+// static
+std::string TextReader::readFileToString(const char *filename)
+{
+    std::string result;
+    TextReader  reader(filename);
+    std::string line;
+    while (reader.readLine(&line))
+    {
+        result.append(line);
+    }
+    reader.close();
+    return result;
+}
+
+// static
+std::string TextReader::readFileToString(const std::string &filename)
+{
+    return readFileToString(filename.c_str());
+}
+
+class TextReader::Impl
+{
+    public:
+        explicit Impl(const TextInputStreamPointer &stream)
+            : stream_(stream)
+        {
+        }
+
+        TextInputStreamPointer stream_;
+};
+
+TextReader::TextReader(const std::string &filename)
+    : impl_(new Impl(TextInputStreamPointer(new TextInputFile(filename))))
+{
+}
+
+TextReader::TextReader(TextInputStream *stream)
+    : impl_(new Impl(TextInputStreamPointer(stream, no_delete<TextInputStream>())))
+{
+}
+
+TextReader::TextReader(const TextInputStreamPointer &stream)
+    : impl_(new Impl(stream))
+{
+}
+
+TextReader::~TextReader()
+{
+}
+
+bool TextReader::readLine(std::string *line)
+{
+    return impl_->stream_->readLine(line);
+}
+
+bool TextReader::readLineTrimmed(std::string *line)
+{
+    if (!readLine(line))
+    {
+        return false;
+    }
+    const size_t endPos = line->find_last_not_of(" \t\r\n");
+    if (endPos != std::string::npos)
+    {
+        line->resize(endPos + 1);
+    }
+    return true;
+}
+
+void TextReader::close()
+{
+    impl_->stream_->close();
+}
+
+} // namespace gmx
diff --git a/src/gromacs/utility/textreader.h b/src/gromacs/utility/textreader.h
new file mode 100644 (file)
index 0000000..62607c6
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares gmx::TextReader.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_TEXTREADER_H
+#define GMX_UTILITY_TEXTREADER_H
+
+#include <string>
+
+#include "gromacs/utility/classhelpers.h"
+#include "gromacs/utility/textstream.h"
+
+namespace gmx
+{
+
+/*! \libinternal \brief
+ * Reads text from a TextInputStream.
+ *
+ * This class provides more formatted reading capabilities than reading raw
+ * lines from the stream (and a natural place to implement more such
+ * capabilities).
+ *
+ * All methods that read from the stream can throw any exceptions that the
+ * underlying stream throws.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class TextReader
+{
+    public:
+        /*! \brief
+         * Reads contents of a file to a std::string.
+         *
+         * \param[in] filename  Name of the file to read.
+         * \returns   The contents of \p filename.
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    FileIOError on any I/O error.
+         */
+        static std::string readFileToString(const char *filename);
+        //! \copydoc readFileToString(const char *)
+        static std::string readFileToString(const std::string &filename);
+
+        /*! \brief
+         * Creates a reader that reads from specified file.
+         *
+         * \param[in]  filename  Path to the file to open.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     FileIOError on any I/O error.
+         *
+         * This constructor is provided for convenience for reading directly
+         * from a file, without the need to construct multiple objects.
+         */
+        explicit TextReader(const std::string &filename);
+        /*! \brief
+         * Creates a reader that reads from specified stream.
+         *
+         * \param[in]  stream  Stream to read from.
+         * \throws     std::bad_alloc if out of memory.
+         *
+         * The caller is responsible of the lifetime of the stream (should
+         * remain in existence as long as the reader exists).
+         *
+         * This constructor is provided for convenience for cases where the
+         * stream is not allocated with `new` and/or not managed by a
+         * boost::shared_ptr (e.g., if the stream is an object on the stack).
+         */
+        explicit TextReader(TextInputStream *stream);
+        /*! \brief
+         * Creates a reader that reads from specified stream.
+         *
+         * \param[in]  stream  Stream to read from.
+         * \throws     std::bad_alloc if out of memory.
+         *
+         * The reader keeps a reference to the stream, so the caller can pass
+         * in a temporary if necessary.
+         */
+        explicit TextReader(const TextInputStreamPointer &stream);
+        ~TextReader();
+
+        /*! \brief
+         * Reads a single line (including newline) from the stream.
+         *
+         * \param[out] line    String to receive the line.
+         * \returns    `false` if nothing was read because the file ended.
+         *
+         * On error or when false is returned, \p line will be empty.
+         * Newlines will be returned as part of \p line if it was present in
+         * the stream.
+         * To loop over all lines in the stream, use:
+         * \code
+           std::string line;
+           while (reader.readLine(&line))
+           {
+               // ...
+           }
+           \endcode
+         */
+        bool readLine(std::string *line);
+        /*! \brief
+         * Reads a single line from the stream.
+         *
+         * \param[out] line    String to receive the line.
+         * \returns    false if nothing was read because the file ended.
+         *
+         * On error or when false is returned, \p line will be empty.
+         * Works as readLine(), except that trailing whitespace will be removed
+         * from \p line.
+         *
+         * \see readLine()
+         */
+        bool readLineTrimmed(std::string *line);
+
+        /*! \brief
+         * Closes the underlying stream.
+         */
+        void close();
+
+    private:
+        class Impl;
+
+        PrivateImplPointer<Impl> impl_;
+};
+
+} // namespace gmx
+
+#endif
diff --git a/src/gromacs/utility/textstream.h b/src/gromacs/utility/textstream.h
new file mode 100644 (file)
index 0000000..14fbfd4
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares interfaces for simple input/output streams.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_TEXTSTREAM_H
+#define GMX_UTILITY_TEXTSTREAM_H
+
+#include <boost/shared_ptr.hpp>
+
+namespace gmx
+{
+
+/*! \libinternal \brief
+ * Interface for reading text.
+ *
+ * Concrete implementations can read the text from, e.g., a file or an in-memory
+ * string.  The main use is to allow unit tests to inject in-memory buffers
+ * instead of writing files to be read by the code under test, but there are
+ * also use cases outside the tests where it is useful to abstract out whether
+ * the input is from a real file or something else.
+ *
+ * To use more advanced formatting than reading raw lines, use TextReader.
+ *
+ * Both methods in the interface can throw std::bad_alloc or other exceptions
+ * that indicate failures to read from the stream.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class TextInputStream
+{
+    public:
+        virtual ~TextInputStream() {}
+
+        /*! \brief
+         * Reads a line (with newline included) from the stream.
+         *
+         * \param[out] line    String to receive the line.
+         * \returns    `false` if nothing was read because the stream ended.
+         *
+         * On error or when `false` is returned, \p line will be empty.
+         */
+        virtual bool readLine(std::string *line) = 0;
+        /*! \brief
+         * Closes the stream.
+         *
+         * It is not allowed to read from a stream after it has been closed.
+         * See TextOutputStream::close() for rationale for a close() method
+         * separate from the destructor.  For input, failures during close
+         * should be rare, but it is clearer to keep the interface symmetric.
+         */
+        virtual void close() = 0;
+};
+
+/*! \libinternal \brief
+ * Interface for writing text.
+ *
+ * Concrete implementations can write the text to, e.g., a file or an in-memory
+ * string.  The main use is to allow unit tests to inject in-memory buffers
+ * instead of reading in files produced by the code under test, but there are
+ * also use cases outside the tests where it is useful to abstract out whether
+ * the output is into a real file or something else.
+ *
+ * To use more advanced formatting than writing plain strings, use TextWriter.
+ *
+ * The current implementation assumes text-only output in several places, but
+ * this interface could possibly be generalized also for binary files.
+ * However, since all binary files currently written by \Gromacs are either
+ * XDR- or TNG-based, they may require a different approach.  Also, it is worth
+ * keeping the distinction between text and binary files clear, since Windows
+ * does transparent `LF`-`CRLF` newline translation for text files, so mixing
+ * modes when reading and/or writing the same file can cause subtle issues.
+ *
+ * Both methods in the interface can throw std::bad_alloc or other exceptions
+ * that indicate failures to write to the stream.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class TextOutputStream
+{
+    public:
+        virtual ~TextOutputStream() {}
+
+        /*! \brief
+         * Writes a given string to the stream.
+         */
+        virtual void write(const char *text) = 0;
+        /*! \brief
+         * Closes the stream.
+         *
+         * It is not allowed to write to a stream after it has been closed.
+         * A method separate from the destructor is provided such that errors
+         * that occur while closing the stream (e.g., when closing the file)
+         * can be handled using exceptions.
+         * The destructor is not allowed to throw, so code that wants to
+         * observe such errors needs to call close() after it has finished
+         * writing to the stream.
+         */
+        virtual void close() = 0;
+};
+
+//! Shorthand for a smart pointer to a TextInputStream.
+typedef boost::shared_ptr<TextInputStream> TextInputStreamPointer;
+//! Shorthand for a smart pointer to a TextOutputStream.
+typedef boost::shared_ptr<TextOutputStream> TextOutputStreamPointer;
+
+} // namespace gmx
+
+#endif
diff --git a/src/gromacs/utility/textwriter.cpp b/src/gromacs/utility/textwriter.cpp
new file mode 100644 (file)
index 0000000..4b1e58c
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements gmx::TextWriter.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_utility
+ */
+#include "gmxpre.h"
+
+#include "textwriter.h"
+
+#include <cstring>
+
+#include "gromacs/utility/filestream.h"
+#include "gromacs/utility/nodelete.h"
+#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textstream.h"
+
+namespace gmx
+{
+
+class TextWriter::Impl
+{
+    public:
+        explicit Impl(const TextOutputStreamPointer &stream)
+            : stream_(stream)
+        {
+            wrapper_.settings().setKeepFinalSpaces(true);
+        }
+
+        void writeWrappedString(const std::string &str)
+        {
+            stream_->write(wrapper_.wrapToString(str).c_str());
+        }
+
+        TextOutputStreamPointer stream_;
+        TextLineWrapper         wrapper_;
+};
+
+// static
+void TextWriter::writeFileFromString(const std::string &filename,
+                                     const std::string &text)
+{
+    TextWriter file(filename);
+    file.writeString(text);
+    file.close();
+}
+
+TextWriter::TextWriter(const std::string &filename)
+    : impl_(new Impl(TextOutputStreamPointer(new TextOutputFile(filename))))
+{
+}
+
+TextWriter::TextWriter(FILE *fp)
+    : impl_(new Impl(TextOutputStreamPointer(new TextOutputFile(fp))))
+{
+}
+
+TextWriter::TextWriter(TextOutputStream *stream)
+    : impl_(new Impl(TextOutputStreamPointer(stream, no_delete<TextOutputStream>())))
+{
+}
+
+TextWriter::TextWriter(const TextOutputStreamPointer &stream)
+    : impl_(new Impl(stream))
+{
+}
+
+TextWriter::~TextWriter()
+{
+}
+
+TextOutputStream &TextWriter::stream()
+{
+    return *impl_->stream_;
+}
+
+TextLineWrapperSettings &TextWriter::wrapperSettings()
+{
+    return impl_->wrapper_.settings();
+}
+
+void TextWriter::writeString(const char *str)
+{
+    if (impl_->wrapper_.isTrivial())
+    {
+        impl_->stream_->write(str);
+    }
+    else
+    {
+        impl_->writeWrappedString(str);
+    }
+}
+
+void TextWriter::writeString(const std::string &str)
+{
+    impl_->writeWrappedString(str);
+}
+
+void TextWriter::writeLine(const char *line)
+{
+    writeString(line);
+    if (!endsWith(line, "\n"))
+    {
+        writeLine();
+    }
+}
+
+void TextWriter::writeLine(const std::string &line)
+{
+    writeString(line);
+    if (!endsWith(line, "\n"))
+    {
+        writeLine();
+    }
+}
+
+void TextWriter::writeLine()
+{
+    writeString("\n");
+}
+
+void TextWriter::close()
+{
+    impl_->stream_->close();
+}
+
+} // namespace gmx
diff --git a/src/gromacs/utility/textwriter.h b/src/gromacs/utility/textwriter.h
new file mode 100644 (file)
index 0000000..5f70083
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares gmx::TextWriter.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_TEXTWRITER_H
+#define GMX_UTILITY_TEXTWRITER_H
+
+#include <cstdio>
+
+#include <string>
+
+#include "gromacs/utility/classhelpers.h"
+#include "gromacs/utility/textstream.h"
+
+namespace gmx
+{
+
+class TextLineWrapperSettings;
+
+/*! \libinternal \brief
+ * Writes text into a TextOutputStream.
+ *
+ * This class provides more formatting and line-oriented writing capabilities
+ * than writing raw strings into the stream.
+ *
+ * All methods that write to the stream can throw any exceptions that the
+ * underlying stream throws.
+ *
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+class TextWriter
+{
+    public:
+        /*! \brief
+         * Convenience method for writing a file from a string in a single call.
+         *
+         * \param[in] filename  Name of the file to read.
+         * \param[in] text      String to write to \p filename.
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    FileIOError on any I/O error.
+         *
+         * If \p filename exists, it is overwritten.
+         */
+        static void writeFileFromString(const std::string &filename,
+                                        const std::string &text);
+
+        /*! \brief
+         * Creates a writer that writes to specified file.
+         *
+         * \param[in]  filename  Path to the file to open.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     FileIOError on any I/O error.
+         *
+         * This constructor is provided for convenience for writing directly to
+         * a file, without the need to construct multiple objects.
+         */
+        explicit TextWriter(const std::string &filename);
+        /*! \brief
+         * Creates a writer that writes to specified file.
+         *
+         * \param[in]  fp  File handle to write to.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     FileIOError on any I/O error.
+         *
+         * This constructor is provided for interoperability with C-like code
+         * for writing directly to an already opened file, without the need to
+         * construct multiple objects.
+         *
+         * The caller is responsible of closing \p fp; it is not allowed to
+         * call close() on the writer.
+         */
+        explicit TextWriter(FILE *fp);
+        /*! \brief
+         * Creates a writer that writes to specified stream.
+         *
+         * \param[in]  stream  Stream to write to.
+         * \throws     std::bad_alloc if out of memory.
+         *
+         * The caller is responsible of the lifetime of the stream (should
+         * remain in existence as long as the writer exists).
+         *
+         * This constructor is provided for convenience for cases where the
+         * stream is not allocated with `new` and/or not managed by a
+         * boost::shared_ptr (e.g., if the stream is an object on the stack).
+         */
+        explicit TextWriter(TextOutputStream *stream);
+        /*! \brief
+         * Creates a writer that writes to specified stream.
+         *
+         * \param[in]  stream  Stream to write to.
+         * \throws     std::bad_alloc if out of memory.
+         *
+         * The writer keeps a reference to the stream, so the caller can pass
+         * in a temporary if necessary.
+         */
+        explicit TextWriter(const TextOutputStreamPointer &stream);
+        ~TextWriter();
+
+        //! Returns the underlying stream for this writer.
+        TextOutputStream &stream();
+
+        /*! \brief
+         * Allows adjusting wrapping settings for the writer.
+         *
+         * \todo
+         * Wrapping is not currently implemented for code that writes partial
+         * lines with writeString().
+         */
+        TextLineWrapperSettings &wrapperSettings();
+
+        /*! \brief
+         * Writes a string to the stream.
+         *
+         * \param[in]  str  String to write.
+         */
+        void writeString(const char *str);
+        //! \copydoc writeString(const char *)
+        void writeString(const std::string &str);
+        /*! \brief
+         * Writes a line to the stream.
+         *
+         * \param[in]  line  Line to write.
+         *
+         * If \p line does not end in a newline, one newline is appended.
+         * Otherwise, works as writeString().
+         */
+        void writeLine(const char *line);
+        //! \copydoc writeLine(const char *)
+        void writeLine(const std::string &line);
+        //! Writes a newline to the stream.
+        void writeLine();
+
+        /*! \brief
+         * Closes the underlying stream.
+         */
+        void close();
+
+    private:
+        class Impl;
+
+        PrivateImplPointer<Impl> impl_;
+};
+
+} // namespace gmx
+
+#endif
index 330f04b53832e8e090c33ce9762495bb5d44daf9..ad9c7fc2669d18d6422a69abe13ce2d3aefc0c64 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -46,7 +46,7 @@
 
 #include "config.h"
 
-#ifdef GMX_CXX11   // C++11 Compiler
+#if GMX_CXX11      // C++11 Compiler
 #include <memory>  // IWYU pragma: export
 #include <utility> // IWYU pragma: export
 #else              // C++03 Compiler
@@ -78,7 +78,7 @@ namespace gmx
  * \brief The smart pointer type.
  * Work-around for the non-existence of template typedefs in C++03.
  */
-#ifdef GMX_CXX11 // C++11 Compiler
+#if GMX_CXX11 // C++11 Compiler
 using std::move;
 template<typename T>
 struct gmx_unique_ptr
index 9872b06c4d5802410f8adf5e62a0082f76e054cc..2b3a9b40dc26c645133f25ce126f871c2047aa62 100644 (file)
@@ -69,7 +69,7 @@ namespace
  * Prints a message directing the user to a wiki page describing replacement
  * options.
  */
-class ObsoleteToolModule : public gmx::CommandLineModuleInterface
+class ObsoleteToolModule : public gmx::ICommandLineModule
 {
     public:
         //! Creates an obsolete tool module for a tool with the given name.
@@ -115,7 +115,7 @@ class ObsoleteToolModule : public gmx::CommandLineModuleInterface
 
 // TODO: Consider removing duplication with CMainCommandLineModule from
 // cmdlinemodulemanager.cpp.
-class NoNiceModule : public gmx::CommandLineModuleInterface
+class NoNiceModule : public gmx::ICommandLineModule
 {
     public:
         //! \copydoc gmx::CommandLineModuleManager::CMainFunction
@@ -233,7 +233,7 @@ void registerLegacyModules(gmx::CommandLineModuleManager *manager)
     registerModuleNoNice(manager, &gmx_mdrun, "mdrun",
                          "Perform a simulation, do a normal mode analysis or an energy minimization");
 
-    gmx::CommandLineOptionsModuleInterface::registerModule(
+    gmx::ICommandLineOptionsModule::registerModule(
             manager, gmx::InsertMoleculesInfo::name,
             gmx::InsertMoleculesInfo::shortDescription,
             &gmx::InsertMoleculesInfo::create);
index f1372731958a627d77d317fab8fa1976527874a6..92c8335fbd7fba876233c83c6209ea47fd3ce747 100644 (file)
@@ -46,8 +46,8 @@
 
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/domdec/domdec_network.h"
-#include "gromacs/ewald/pme-load-balancing.h"
 #include "gromacs/ewald/pme.h"
+#include "gromacs/ewald/pme-load-balancing.h"
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/mdoutf.h"
 #include "gromacs/fileio/trajectory_writing.h"
index c878c17316b477b060cb42ab747ae4d2daa6ddd8..f25ad46c9b9c3b7bf35ba5d9927ce902b21bae19 100644 (file)
@@ -83,6 +83,7 @@
 #include "gromacs/swap/swapcoords.h"
 #include "gromacs/timing/wallcycle.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/gmxmpi.h"
 #include "gromacs/utility/smalloc.h"
index 845aa58ac0fadebb683eebd647bb366c4567b342..b793af46c56d853cbbeb4e3a69ef496b1ca47ca3 100644 (file)
@@ -50,8 +50,8 @@
 #include "gromacs/options/options.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/basenetwork.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxmpi.h"
+#include "gromacs/utility/textwriter.h"
 #include "programs/mdrun/mdrun_main.h"
 
 #include "testutils/cmdlinetest.h"
@@ -133,13 +133,13 @@ SimulationRunner::useStringAsMdpFile(const char *mdpString)
 void
 SimulationRunner::useStringAsMdpFile(const std::string &mdpString)
 {
-    gmx::File::writeFileFromString(mdpInputFileName_, mdpString);
+    gmx::TextWriter::writeFileFromString(mdpInputFileName_, mdpString);
 }
 
 void
 SimulationRunner::useStringAsNdxFile(const char *ndxString)
 {
-    gmx::File::writeFileFromString(ndxFileName_, ndxString);
+    gmx::TextWriter::writeFileFromString(ndxFileName_, ndxString);
 }
 
 void
index 1e11fd5ef456af6076a2e069af50d757b3128f2f..e19e7497a4db5d537cac0975451d3ca633070723 100644 (file)
@@ -82,7 +82,7 @@ TEST_P(MdrunRerun, WithDifferentInputFormats)
  * version. */
 const char *trajectoryFileNames[] = {
     "../../../gromacs/gmxana/legacytests/spc2-traj.trr",
-#if defined GMX_USE_TNG && defined HAVE_ZLIB
+#if defined GMX_USE_TNG && HAVE_ZLIB
     "../../../gromacs/gmxana/legacytests/spc2-traj.tng",
 #endif
     "../../../gromacs/gmxana/legacytests/spc2-traj.xtc",
index 84a7df32fc75eb20c38f421ece5376bfabf18086..82d583709f72ccf6dda7bad42d6d90e06692c623 100644 (file)
  */
 #include "gmxpre.h"
 
-#include <string.h>
+#include <cstring>
 
 #include <algorithm>
 
 #include "gromacs/legacyheaders/macros.h"
 #include "gromacs/topology/index.h"
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/dir_separator.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
@@ -123,10 +124,10 @@ t_dlg *select_filter(t_x11 *x11, t_gmx *gmx)
     char               tmpfile[STRLEN];
     int                i, j, k, len, tlen, ht, ncol, nrow, x0;
 
-    len = strlen(title);
+    len = std::strlen(title);
     for (i = 0; (i < (int)gmx->filter->grps->nr); i++)
     {
-        len = std::max(len, (int)strlen(gmx->filter->grpnames[i]));
+        len = std::max(len, static_cast<int>(std::strlen(gmx->filter->grpnames[i])));
     }
     len += 2;
 
@@ -144,7 +145,7 @@ t_dlg *select_filter(t_x11 *x11, t_gmx *gmx)
     {
         ht = 1+(gmx->filter->grps->nr+1)*2+3;
     }
-    strcpy(tmpfile, "filterXXXXXX");
+    std::strcpy(tmpfile, "filterXXXXXX");
     gmx_tmpnam(tmpfile);
 #ifdef DEBUG
     fprintf(stderr, "file: %s\n", tmpfile);
index 7690b98ad78830bd2244e30b1d91baac8d59bf41..15d3f8ee51bd300661af3a61c0afeb57544115c1 100644 (file)
@@ -50,7 +50,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
-#ifdef GMX_X11
+#if GMX_X11
 
 #include "gromacs/fileio/writeps.h"
 
@@ -405,7 +405,7 @@ int gmx_view(int argc, char *argv[])
     if (parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm,
                           0, NULL, asize(desc), desc, asize(bugs), bugs, &oenv))
     {
-#ifndef GMX_X11
+#if !GMX_X11
         fprintf(stderr, "Compiled without X-Windows - can not run viewer.\n");
 #else
         t_x11 *x11;
index 131d9351f5de5ed471f404d874e6d7fa806807b4..a2a5cdde513b344965bc02c57a480a67d217da30 100644 (file)
@@ -37,6 +37,7 @@ include_directories(${LIBXML2_INCLUDE_DIR})
 set(TESTUTILS_SOURCES
     cmdlinetest.cpp
     integrationtests.cpp
+    interactivetest.cpp
     mpi-printer.cpp
     refdata.cpp
     stringtest.cpp
index 3d5a956fca8c09fd79a121b81dddc618572cb3f8..3a848c94548aeaf0ff8dd9e3e4624d20a3740334 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/commandline/cmdlineoptionsmodule.h"
 #include "gromacs/commandline/cmdlineprogramcontext.h"
 #include "gromacs/utility/arrayref.h"
-#include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textreader.h"
+#include "gromacs/utility/textwriter.h"
 
 #include "testutils/refdata.h"
 #include "testutils/testfilemanager.h"
@@ -263,7 +264,7 @@ class CommandLineTestHelper::Impl
 
 // static
 int CommandLineTestHelper::runModule(
-        CommandLineModuleInterface *module, CommandLine *commandLine)
+        ICommandLineModule *module, CommandLine *commandLine)
 {
     CommandLineModuleSettings settings;
     module->init(&settings);
@@ -272,12 +273,12 @@ int CommandLineTestHelper::runModule(
 
 // static
 int CommandLineTestHelper::runModule(
-        CommandLineOptionsModuleInterface::FactoryMethod  factory,
+        ICommandLineOptionsModule::FactoryMethod          factory,
         CommandLine                                      *commandLine)
 {
     // The name and description are not used in the tests, so they can be NULL.
-    boost::scoped_ptr<CommandLineModuleInterface> module(
-            CommandLineOptionsModuleInterface::createModule(NULL, NULL, factory));
+    boost::scoped_ptr<ICommandLineModule> module(
+            ICommandLineOptionsModule::createModule(NULL, NULL, factory));
     return runModule(module.get(), commandLine);
 }
 
@@ -297,7 +298,7 @@ void CommandLineTestHelper::setInputFileContents(
     GMX_ASSERT(extension[0] != '.', "Extension should not contain a dot");
     std::string fullFilename = impl_->fileManager_.getTemporaryFilePath(
                 formatString("%d.%s", args->argc(), extension));
-    File::writeFileFromString(fullFilename, contents);
+    TextWriter::writeFileFromString(fullFilename, contents);
     args->addOption(option, fullFilename);
 }
 
@@ -308,7 +309,7 @@ void CommandLineTestHelper::setInputFileContents(
     GMX_ASSERT(extension[0] != '.', "Extension should not contain a dot");
     std::string fullFilename = impl_->fileManager_.getTemporaryFilePath(
                 formatString("%d.%s", args->argc(), extension));
-    File        file(fullFilename, "w");
+    TextWriter  file(fullFilename);
     ConstArrayRef<const char *>::const_iterator i;
     for (i = contents.begin(); i != contents.end(); ++i)
     {
@@ -345,7 +346,7 @@ void CommandLineTestHelper::checkOutputFiles(TestReferenceChecker checker) const
              outfile != impl_->outputFiles_.end();
              ++outfile)
         {
-            std::string output = File::readToString(outfile->path);
+            std::string output = TextReader::readFileToString(outfile->path);
             outputChecker.checkStringBlock(output, outfile->option.c_str());
         }
     }
index 519911f16e75b342f3a0444a0bf1335c3c8777ec..5c1feec7ea4477258598af5ac6c764790158b9a3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -55,8 +55,8 @@
 namespace gmx
 {
 
-class CommandLineModuleInterface;
-class CommandLineOptionsModuleInterface;
+class ICommandLineModule;
+class ICommandLineOptionsModule;
 
 namespace test
 {
@@ -206,7 +206,7 @@ class CommandLineTestHelper
 {
     public:
         /*! \brief
-         * Runs a command-line program that implements CommandLineModuleInterface.
+         * Runs a command-line program that implements ICommandLineModule.
          *
          * \param[in,out] module       Module to run.
          *     The function does not take ownership.
@@ -216,10 +216,10 @@ class CommandLineTestHelper
          * \throws  unspecified  Any exception thrown by the module.
          */
         static int
-        runModule(CommandLineModuleInterface *module, CommandLine *commandLine);
+        runModule(ICommandLineModule *module, CommandLine *commandLine);
         /*! \brief
          * Runs a command-line program that implements
-         * CommandLineOptionsModuleInterface.
+         * ICommandLineOptionsModule.
          *
          * \param[in] factory          Factory method for the module to run.
          * \param[in,out] commandLine  Command line parameters to pass.
@@ -229,7 +229,7 @@ class CommandLineTestHelper
          *     module.
          */
         static int
-        runModule(CommandLineOptionsModuleInterface *(*factory)(),
+        runModule(ICommandLineOptionsModule         *(*factory)(),
                   CommandLine                      *commandLine);
 
         /*! \brief
index 1ae38d84525b8dfc62b0f5178ad9305cb3948268..b6e9bcfdb67f16b17e6b79715d4980024cf82b08 100644 (file)
@@ -68,4 +68,31 @@ and use the copy_xsl.sh script to copy it to relevant locations.
     <xsl:value-of select="."/>
 </xsl:template>
 
+<xsl:template match="InteractiveSession">
+    <pre>
+        <xsl:for-each select="*">
+            <xsl:choose>
+                <xsl:when test="starts-with(@Name, 'Output')">
+                    <xsl:value-of select="substring(.,2)"/>
+                </xsl:when>
+                <xsl:when test="string-length(.)=1">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:when>
+                <xsl:when test="contains(substring(.,2), '&#10;')">
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="translate(substring(.,2), '&#10;', '&#x23ce;')"/>
+                    <xsl:text>&#10;</xsl:text>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:text>&#x25ba;</xsl:text>
+                    <xsl:value-of select="substring(.,2)"/>
+                    <xsl:text>&#xb6;</xsl:text>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:for-each>
+        <xsl:text>[EOF]</xsl:text>
+    </pre>
+</xsl:template>
+
 </xsl:stylesheet>
index 20fa85f566a0159ee8007e9fe9290f90fca5c850..9913f6053ee00b7ff7e115d0596b669d8434aa62 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -46,7 +46,7 @@
 #include <stdio.h>
 
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/textwriter.h"
 
 namespace gmx
 {
@@ -69,7 +69,7 @@ void
 IntegrationTestFixture::redirectStringToStdin(const char* theString)
 {
     std::string fakeStdin("fake-stdin");
-    gmx::File::writeFileFromString(fakeStdin, theString);
+    gmx::TextWriter::writeFileFromString(fakeStdin, theString);
     if (NULL == std::freopen(fakeStdin.c_str(), "r", stdin))
     {
         GMX_THROW_WITH_ERRNO(FileIOError("Failed to redirect a string to stdin"),
diff --git a/src/testutils/interactivetest.cpp b/src/testutils/interactivetest.cpp
new file mode 100644 (file)
index 0000000..ce8c854
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements classes from interactivetest.h.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_testutils
+ */
+#include "gmxpre.h"
+
+#include "interactivetest.h"
+
+#include <string>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textstream.h"
+
+#include "testutils/refdata.h"
+#include "testutils/stringtest.h"
+
+namespace gmx
+{
+namespace test
+{
+
+// These two classes cannot be in an unnamed namespace (easily), since
+// then their use as members below would trigger warnings.
+// But if anyone needs these outside this file, they can easily be moved to a
+// separate header.
+
+class MockTextInputStream : public TextInputStream
+{
+    public:
+        MOCK_METHOD1(readLine, bool(std::string *));
+        MOCK_METHOD0(close, void());
+};
+
+class MockTextOutputStream : public TextOutputStream
+{
+    public:
+        MOCK_METHOD1(write, void(const char *));
+        MOCK_METHOD0(close, void());
+};
+
+class InteractiveTestHelper::Impl
+{
+    public:
+        explicit Impl(TestReferenceChecker checker)
+            : checker_(checker), bLastNewline_(true),
+              currentLine_(0), bHasOutput_(false)
+        {
+            using ::testing::_;
+            using ::testing::Invoke;
+            EXPECT_CALL(inputStream_, readLine(_))
+                .WillRepeatedly(Invoke(this, &Impl::readInputLine));
+            EXPECT_CALL(inputStream_, close()).Times(0);
+            EXPECT_CALL(outputStream_, write(_))
+                .WillRepeatedly(Invoke(this, &Impl::addOutput));
+            EXPECT_CALL(outputStream_, close()).Times(0);
+        }
+
+        bool readInputLine(std::string *line)
+        {
+            checkOutput();
+            line->clear();
+            const bool bPresent = (currentLine_ < inputLines_.size());
+            if (bPresent)
+            {
+                line->assign(inputLines_[currentLine_]);
+                if (bLastNewline_ || currentLine_ + 1 < inputLines_.size())
+                {
+                    line->append("\n");
+                }
+            }
+            ++currentLine_;
+            const std::string id = formatString("Input%d", static_cast<int>(currentLine_));
+            StringTestBase::checkText(&checker_, *line, id.c_str());
+            return bPresent;
+        }
+        void addOutput(const char *str)
+        {
+            bHasOutput_ = true;
+            currentOutput_.append(str);
+        }
+
+        void checkOutput()
+        {
+            const std::string id = formatString("Output%d", static_cast<int>(currentLine_));
+            if (checker_.checkPresent(bHasOutput_, id.c_str()))
+            {
+                StringTestBase::checkText(&checker_, currentOutput_, id.c_str());
+            }
+            bHasOutput_ = false;
+            currentOutput_.clear();
+        }
+        void checkPendingInput()
+        {
+            const std::string id = formatString("Input%d", static_cast<int>(currentLine_+1));
+            checker_.checkPresent(false, id.c_str());
+        }
+
+        TestReferenceChecker             checker_;
+        ConstArrayRef<const char *>      inputLines_;
+        bool                             bLastNewline_;
+        size_t                           currentLine_;
+        bool                             bHasOutput_;
+        std::string                      currentOutput_;
+        MockTextInputStream              inputStream_;
+        MockTextOutputStream             outputStream_;
+};
+
+InteractiveTestHelper::InteractiveTestHelper(TestReferenceChecker checker)
+    : impl_(new Impl(checker.checkCompound("InteractiveSession", "Interactive")))
+{
+}
+
+InteractiveTestHelper::~InteractiveTestHelper()
+{
+}
+
+void InteractiveTestHelper::setLastNewline(bool bInclude)
+{
+    impl_->bLastNewline_ = bInclude;
+}
+
+void InteractiveTestHelper::setInputLines(
+        const ConstArrayRef<const char *> &inputLines)
+{
+    impl_->inputLines_  = inputLines;
+    impl_->currentLine_ = 0;
+}
+
+TextInputStream &InteractiveTestHelper::inputStream()
+{
+    return impl_->inputStream_;
+}
+
+TextOutputStream &InteractiveTestHelper::outputStream()
+{
+    return impl_->outputStream_;
+}
+
+void InteractiveTestHelper::checkSession()
+{
+    impl_->checkOutput();
+    impl_->checkPendingInput();
+}
+
+} // namespace test
+} // namespace gmx
diff --git a/src/testutils/interactivetest.h b/src/testutils/interactivetest.h
new file mode 100644 (file)
index 0000000..66167f1
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Provides helper classes for testing interactive prompts.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_testutils
+ */
+#ifndef GMX_TESTUTILS_INTERACTIVETEST_H
+#define GMX_TESTUTILS_INTERACTIVETEST_H
+
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/classhelpers.h"
+
+namespace gmx
+{
+
+class TextInputStream;
+class TextOutputStream;
+
+namespace test
+{
+
+class TestReferenceChecker;
+
+/*! \libinternal \brief
+ * Helper class for testing interactive sessions.
+ *
+ * The calling test can set the user input using setInputLines() (and possibly
+ * setLastNewline()), pass the streams from inputStream() and outputStream() to
+ * the code that executes the interactive session, and then call checkSession()
+ * after the session is finished.
+ * The input is provided from the array set with setInputLines(), and all
+ * output is checked using the reference data framework.
+ * The reference XML data can be viewed with the XSLT stylesheet to show
+ * exactly how the session went.
+ *
+ * \inlibraryapi
+ * \ingroup module_testutils
+ */
+class InteractiveTestHelper
+{
+    public:
+        /*! \brief
+         * Initializes the helper.
+         *
+         * \param[in] checker  Parent reference checker to use.
+         *
+         * The helper creates a compound item under \p checker for the
+         * interactive session it tests.
+         */
+        explicit InteractiveTestHelper(gmx::test::TestReferenceChecker checker);
+        ~InteractiveTestHelper();
+
+        //! Sets whether the last input line contains a newline (by default, it does).
+        void setLastNewline(bool bInclude);
+        /*! \brief
+         * Sets the input lines for the interactive session.
+         *
+         * Calls to TextInputStream::readLine() will return strings from this
+         * array in sequence.
+         * Newlines are added at the end automatically (except for the last
+         * line if `setLastNewLine(false)` has been called).
+         * If there are more `readLine()` calls than there are input lines,
+         * the remaining calls return end-of-input.
+         */
+        void setInputLines(const ConstArrayRef<const char *> &inputLines);
+
+        //! Returns the input stream for the session.
+        TextInputStream  &inputStream();
+        //! Returns the output stream for the session.
+        TextOutputStream &outputStream();
+
+        /*! \brief
+         * Finalizes the checking for the session.
+         *
+         * This must be called after all input and output from a session has
+         * occurred, as the helper will not otherwise know when output after
+         * the last input has finished.  This method also checks that the
+         * required number of input lines were read in the session.
+         */
+        void checkSession();
+
+    private:
+        class Impl;
+
+        PrivateImplPointer<Impl> impl_;
+};
+} // namespace test
+} // namespace gmx
+
+#endif
index 7ce6008345f5ee323fcd8ee11bf075a04f09d39c..ad63a444f72a73bedd704209f4dcb0642478b510 100644 (file)
 
 #include "stringtest.h"
 
-#include <algorithm>
 #include <string>
-#include <utility>
-#include <vector>
 
 #include <boost/scoped_ptr.hpp>
 
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/options.h"
-#include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
-#include "gromacs/utility/fileredirector.h"
+#include "gromacs/utility/textreader.h"
 
 #include "testutils/refdata.h"
-#include "testutils/testexceptions.h"
-#include "testutils/testfilemanager.h"
 #include "testutils/testoptions.h"
 
 namespace gmx
@@ -70,27 +63,6 @@ namespace
 {
 //! Stores the -stdout flag value to print out values instead of checking them.
 bool g_bWriteToStdOut = false;
-
-/*! \brief
- * Helper for checking a block of text, e.g., implementing the `-stdout`
- * option.
- *
- * \ingroup module_testutils
- */
-void checkTextImpl(TestReferenceChecker *checker, const std::string &text,
-                   const char *id)
-{
-    if (g_bWriteToStdOut)
-    {
-        printf("%s:\n", id);
-        printf("%s[END]\n", text.c_str());
-    }
-    else
-    {
-        checker->checkStringBlock(text, id);
-    }
-}
-
 }
 
 // TODO: Only add this option to those test binaries that actually need it
@@ -106,74 +78,6 @@ GMX_TEST_OPTIONS(StringTestOptions, options)
 }
 //! \endcond
 
-/********************************************************************
- * TestFileOutputRedirector
- */
-
-/*! \internal
- * \brief
- * Implementation of FileOutputRedirectorInterface for tests.
- *
- * This class redirects all output files to temporary files managed by a
- * TestFileManager, and supports checking the contents of these files using the
- * reference data framework.
- *
- * \ingroup module_testutils
- */
-class TestFileOutputRedirector : public FileOutputRedirectorInterface
-{
-    public:
-        //! Initializes the redirector with the given file manager.
-        explicit TestFileOutputRedirector(TestFileManager *fileManager)
-            : fileManager_(*fileManager)
-        {
-        }
-
-        virtual File &standardOutput()
-        {
-            if (!stdoutFile_)
-            {
-                const std::string path = fileManager_.getTemporaryFilePath("stdout.txt");
-                stdoutFile_.reset(new File(path, "w"));
-                fileList_.push_back(FileListEntry("<stdout>", path));
-            }
-            return *stdoutFile_;
-        }
-        virtual FileInitializer openFileForWriting(const char *filename)
-        {
-            std::string       suffix = filename;
-            std::replace(suffix.begin(), suffix.end(), '/', '_');
-            const std::string path = fileManager_.getTemporaryFilePath(suffix);
-            fileList_.push_back(FileListEntry(filename, path));
-            return FileInitializer(fileList_.back().second.c_str(), "w");
-        }
-
-        /*! \brief
-         * Checks the contents of all redirected files.
-         */
-        void checkRedirectedFiles(TestReferenceChecker *checker)
-        {
-            if (stdoutFile_)
-            {
-                stdoutFile_->close();
-                stdoutFile_.reset();
-            }
-            std::vector<FileListEntry>::const_iterator i;
-            for (i = fileList_.begin(); i != fileList_.end(); ++i)
-            {
-                const std::string text = File::readToString(i->second);
-                checkTextImpl(checker, text, i->first.c_str());
-            }
-        }
-
-    private:
-        typedef std::pair<std::string, std::string> FileListEntry;
-
-        TestFileManager            &fileManager_;
-        boost::scoped_ptr<File>     stdoutFile_;
-        std::vector<FileListEntry>  fileList_;
-};
-
 /********************************************************************
  * StringTestBase::Impl
  */
@@ -183,31 +87,34 @@ class StringTestBase::Impl
     public:
         TestReferenceData                           data_;
         boost::scoped_ptr<TestReferenceChecker>     checker_;
-        boost::scoped_ptr<TestFileOutputRedirector> redirector_;
 };
 
 /********************************************************************
  * StringTestBase
  */
 
-StringTestBase::StringTestBase()
-    : impl_(new Impl)
+// static
+void StringTestBase::checkText(TestReferenceChecker *checker,
+                               const std::string &text, const char *id)
 {
+    if (g_bWriteToStdOut)
+    {
+        printf("%s:\n", id);
+        printf("%s[END]\n", text.c_str());
+    }
+    else
+    {
+        checker->checkStringBlock(text, id);
+    }
 }
 
-StringTestBase::~StringTestBase()
+StringTestBase::StringTestBase()
+    : impl_(new Impl)
 {
 }
 
-FileOutputRedirectorInterface &
-StringTestBase::initOutputRedirector(TestFileManager *fileManager)
+StringTestBase::~StringTestBase()
 {
-    if (impl_->redirector_)
-    {
-        GMX_THROW(TestException("initOutputRedirector() called more than once"));
-    }
-    impl_->redirector_.reset(new TestFileOutputRedirector(fileManager));
-    return *impl_->redirector_;
 }
 
 TestReferenceChecker &
@@ -223,24 +130,27 @@ StringTestBase::checker()
 void
 StringTestBase::checkText(const std::string &text, const char *id)
 {
-    checkTextImpl(&checker(), text, id);
+    checkText(&checker(), text, id);
 }
 
 void
 StringTestBase::checkFileContents(const std::string &filename, const char *id)
 {
-    const std::string text = File::readToString(filename);
+    const std::string text = TextReader::readFileToString(filename);
     checkText(text, id);
 }
 
 void
-StringTestBase::checkRedirectedOutputFiles()
+StringTestBase::testFilesEqual(const std::string &refFilename,
+                               const std::string &testFilename)
 {
-    if (!impl_->redirector_)
+    const std::string expectedContents = TextReader::readFileToString(refFilename);
+    const std::string contents         = TextReader::readFileToString(testFilename);
+    if (g_bWriteToStdOut)
     {
-        GMX_THROW(TestException("initOutputRedirector() not called"));
+        printf("%s[END]\n", contents.c_str());
     }
-    impl_->redirector_->checkRedirectedFiles(&checker());
+    EXPECT_EQ(expectedContents, contents);
 }
 
 } // namespace test
index 67e89113a3b7e6dc0d2b06275ae0b53eae0c241c..7f475b8e316c2b7b7de9b4644ed3c098863f7cc6 100644 (file)
 namespace gmx
 {
 
-class FileOutputRedirectorInterface;
-
 namespace test
 {
 
-class TestFileManager;
 class TestReferenceChecker;
 
 /*! \libinternal \brief
@@ -74,20 +71,18 @@ class TestReferenceChecker;
 class StringTestBase : public ::testing::Test
 {
     public:
-        StringTestBase();
-        ~StringTestBase();
-
         /*! \brief
-         * Creates a redirector that directs all output to temporary files.
-         *
-         * \param[in] fileManager  File manager to use for temporary files.
-         *
-         * Can only be called once in a test.
+         * Checks a block of text.
          *
-         * \see checkRedirectedOutputFiles()
+         * This static method is provided for code that does not derive from
+         * StringTestBase to use the same functionality, e.g., implementing the
+         * `-stdout` option.
          */
-        FileOutputRedirectorInterface &
-        initOutputRedirector(TestFileManager *fileManager);
+        static void checkText(TestReferenceChecker *checker,
+                              const std::string &text, const char *id);
+
+        StringTestBase();
+        ~StringTestBase();
 
         /*! \brief
          * Returns the root checker for this test's reference data.
@@ -114,20 +109,15 @@ class StringTestBase : public ::testing::Test
          * single string and calls checkText().
          */
         void checkFileContents(const std::string &filename, const char *id);
+
         /*! \brief
-         * Checks contents of all files redirected with initOutputRedirector().
-         *
-         * Uses the same logic as checkFileContents() to check each file
-         * (including `stdout`) that has been created using the redirector
-         * returned by initOutputRedirector().
+         * Tests that contents of two files are equal.
          *
-         * initOutputRedirector() must have been called.
-         * This method should not be called if the redirector will still be
-         * used for further output in the test.  Behavior is not designed for
-         * checking in the middle of the test, although that could potentially
-         * be changed if necessary.
+         * \param[in] refFilename   File with the expected contents.
+         * \param[in] testFilename  File with the contents to be tested.
          */
-        void checkRedirectedOutputFiles();
+        void testFilesEqual(const std::string &refFilename,
+                            const std::string &testFilename);
 
     private:
         class Impl;
index 62ea64812b3d056c6e82da0aa1e57986329f63b2..eebcca434fa37645c1f27f06930c69a323a335f6 100644 (file)
 
 #include <set>
 #include <string>
+#include <utility>
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+
+#include "gromacs/utility/stringstream.h"
+
+#include "testutils/stringtest.h"
 
 namespace gmx
 {
 namespace test
 {
 
+/********************************************************************
+ * TestFileInputRedirector
+ */
+
 TestFileInputRedirector::TestFileInputRedirector()
 {
 }
@@ -69,5 +81,59 @@ bool TestFileInputRedirector::fileExists(const char *filename) const
     return existingFiles_.count(filename) > 0;
 }
 
+/********************************************************************
+ * TestFileOutputRedirector::Impl
+ */
+
+class TestFileOutputRedirector::Impl
+{
+    public:
+        typedef boost::shared_ptr<StringOutputStream> StringStreamPointer;
+        typedef std::pair<std::string, StringStreamPointer> FileListEntry;
+
+        StringStreamPointer         stdoutStream_;
+        std::vector<FileListEntry>  fileList_;
+};
+
+/********************************************************************
+ * TestFileOutputRedirector
+ */
+
+TestFileOutputRedirector::TestFileOutputRedirector()
+    : impl_(new Impl)
+{
+}
+
+TestFileOutputRedirector::~TestFileOutputRedirector()
+{
+}
+
+TextOutputStream &TestFileOutputRedirector::standardOutput()
+{
+    if (!impl_->stdoutStream_)
+    {
+        impl_->stdoutStream_.reset(new StringOutputStream);
+        impl_->fileList_.push_back(Impl::FileListEntry("<stdout>", impl_->stdoutStream_));
+    }
+    return *impl_->stdoutStream_;
+}
+
+TextOutputStreamPointer
+TestFileOutputRedirector::openTextOutputFile(const char *filename)
+{
+    Impl::StringStreamPointer stream(new StringOutputStream);
+    impl_->fileList_.push_back(Impl::FileListEntry(filename, stream));
+    return stream;
+}
+
+void TestFileOutputRedirector::checkRedirectedFiles(TestReferenceChecker *checker)
+{
+    std::vector<Impl::FileListEntry>::const_iterator i;
+    for (i = impl_->fileList_.begin(); i != impl_->fileList_.end(); ++i)
+    {
+        StringTestBase::checkText(checker, i->second->toString(), i->first.c_str());
+    }
+}
+
 } // namespace test
 } // namespace gmx
index 711c6c8ac14e735cc573e100b912c270b10ef87d..550acf55a21c59fc7efd37479bb7360ba0c22b1b 100644 (file)
@@ -54,8 +54,10 @@ namespace gmx
 namespace test
 {
 
+class TestReferenceChecker;
+
 /*! \libinternal \brief
- * In-memory implementation for FileInputRedirectorInterface for tests.
+ * In-memory implementation for IFileInputRedirector for tests.
  *
  * By default, this implementation will return `false` for all file existence
  * checks.  To return `true` for a specific path, use addExistingFile().
@@ -63,7 +65,7 @@ namespace test
  * \inlibraryapi
  * \ingroup module_testutils
  */
-class TestFileInputRedirector : public FileInputRedirectorInterface
+class TestFileInputRedirector : public IFileInputRedirector
 {
     public:
         TestFileInputRedirector();
@@ -78,7 +80,7 @@ class TestFileInputRedirector : public FileInputRedirectorInterface
          */
         void addExistingFile(const char *filename);
 
-        // From FileInputRedirectorInterface
+        // From IFileInputRedirector
         virtual bool fileExists(const char *filename) const;
 
     private:
@@ -87,6 +89,40 @@ class TestFileInputRedirector : public FileInputRedirectorInterface
         GMX_DISALLOW_COPY_AND_ASSIGN(TestFileInputRedirector);
 };
 
+/*! \libinternal \brief
+ * In-memory implementation of IFileOutputRedirector for tests.
+ *
+ * This class redirects all output files to in-memory buffers, and supports
+ * checking the contents of these files using the reference data framework.
+ *
+ * \ingroup module_testutils
+ */
+class TestFileOutputRedirector : public IFileOutputRedirector
+{
+    public:
+        TestFileOutputRedirector();
+        virtual ~TestFileOutputRedirector();
+
+        /*! \brief
+         * Checks contents of all redirected files (including stdout).
+         *
+         * This method should not be called if the redirector will still be
+         * used for further output in the test.  Behavior is not designed for
+         * checking in the middle of the test, although that could potentially
+         * be changed if necessary.
+         */
+        void checkRedirectedFiles(TestReferenceChecker *checker);
+
+        // From IFileOutputRedirector
+        virtual TextOutputStream &standardOutput();
+        virtual TextOutputStreamPointer openTextOutputFile(const char *filename);
+
+    private:
+        class Impl;
+
+        PrivateImplPointer<Impl> impl_;
+};
+
 } // namespace test
 } // namespace gmx
 
index 0fd8d1100b1784407475280e25f382c6930a47f9..a8bead662c4ba9a0118d619ebd7d9b1bc89d5c07 100644 (file)
@@ -60,7 +60,7 @@
 #include "gromacs/options/options.h"
 #include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/filestream.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/path.h"
 #include "gromacs/utility/programcontext.h"
@@ -88,7 +88,7 @@ namespace
  *
  * \ingroup module_testutils
  */
-class TestProgramContext : public ProgramContextInterface
+class TestProgramContext : public IProgramContext
 {
     public:
         /*! \brief
@@ -96,7 +96,7 @@ class TestProgramContext : public ProgramContextInterface
          *
          * \param[in] context  Current \Gromacs program context.
          */
-        explicit TestProgramContext(const ProgramContextInterface &context)
+        explicit TestProgramContext(const IProgramContext &context)
             : context_(context), dataPath_(CMAKE_SOURCE_DIR)
         {
         }
@@ -131,7 +131,7 @@ class TestProgramContext : public ProgramContextInterface
         }
 
     private:
-        const ProgramContextInterface   &context_;
+        const IProgramContext           &context_;
         std::string                      dataPath_;
 };
 
@@ -142,7 +142,7 @@ void printHelp(const Options &options)
     std::fprintf(stderr,
                  "\nYou can use the following GROMACS-specific command-line flags\n"
                  "to control the behavior of the tests:\n\n");
-    CommandLineHelpContext context(&File::standardError(),
+    CommandLineHelpContext context(&TextOutputFile::standardError(),
                                    eHelpOutputFormat_Console, NULL, program);
     context.setModuleDisplayName(program);
     CommandLineHelpWriter(options).writeHelp(context);
index 9bc036f51dd9cd3463a9a4bade3bec64e62579f1..976b8d79892061c74a6ac35928e68428165fdd30 100644 (file)
@@ -45,9 +45,8 @@
 
 #include <list>
 
-#include "thread_mpi/mutex.h"
-
 #include "gromacs/utility/classhelpers.h"
+#include "gromacs/utility/mutex.h"
 
 namespace gmx
 {
@@ -75,7 +74,7 @@ class TestOptionsRegistry
         //! Adds a provider into the registry.
         void add(const char * /*name*/, TestOptionsProvider *provider)
         {
-            tMPI::lock_guard<tMPI::mutex> lock(listMutex_);
+            lock_guard<Mutex> lock(listMutex_);
             providerList_.push_back(provider);
         }
 
@@ -87,7 +86,7 @@ class TestOptionsRegistry
 
         typedef std::list<TestOptionsProvider *> ProviderList;
 
-        tMPI::mutex             listMutex_;
+        Mutex                   listMutex_;
         ProviderList            providerList_;
 
         GMX_DISALLOW_COPY_AND_ASSIGN(TestOptionsRegistry);
@@ -97,7 +96,7 @@ void TestOptionsRegistry::initOptions(Options *options)
 {
     // TODO: Have some deterministic order for the options; now it depends on
     // the order in which the global initializers are run.
-    tMPI::lock_guard<tMPI::mutex> lock(listMutex_);
+    lock_guard<Mutex>             lock(listMutex_);
     ProviderList::const_iterator  i;
     for (i = providerList_.begin(); i != providerList_.end(); ++i)
     {
index 045e7c5616b2e4ace992cdb142f168d2f0d3db8f..351584dab7ea6fa08b6fb86b64cc3588ca669f93 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2011,2012,2014, by the GROMACS development team, led by
+# Copyright (c) 2011,2012,2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -33,5 +33,6 @@
 # the research papers on the package. Check out http://www.gromacs.org.
 
 gmx_add_unit_test(TestUtilsUnitTests testutils-test
+                  interactivetest.cpp
                   refdata_tests.cpp
                   testasserts_tests.cpp)
diff --git a/src/testutils/tests/interactivetest.cpp b/src/testutils/tests/interactivetest.cpp
new file mode 100644 (file)
index 0000000..4a3d390
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Self-tests for interactive test helpers.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_testutils
+ */
+#include "gmxpre.h"
+
+#include "testutils/interactivetest.h"
+
+#include <vector>
+
+#include <gtest/gtest.h>
+#include <gtest/gtest-spi.h>
+
+#include "gromacs/utility/textstream.h"
+
+#include "testutils/refdata.h"
+
+namespace
+{
+
+class InteractiveSession
+{
+    public:
+        InteractiveSession(gmx::test::ReferenceDataMode mode)
+            : data_(mode), helper_(data_.rootChecker()), nextInputLine_(0)
+        {
+        }
+
+        void addOutput(const char *output)
+        {
+            events_.push_back(Event(WriteOutput, output));
+        }
+        void addInputLine(const char *inputLine)
+        {
+            inputLines_.push_back(inputLine);
+        }
+        void addReadInput()
+        {
+            events_.push_back(Event(ReadInput, ""));
+        }
+        void addInput(const char *inputLine)
+        {
+            addInputLine(inputLine);
+            addReadInput();
+        }
+        void addInputNoNewline(const char *inputLine)
+        {
+            addInputLine(inputLine);
+            helper_.setLastNewline(false);
+            events_.push_back(Event(ReadInputNoNewline, ""));
+        }
+
+        void run()
+        {
+            gmx::TextInputStream              &input  = helper_.inputStream();
+            gmx::TextOutputStream             &output = helper_.outputStream();
+            helper_.setInputLines(inputLines_);
+            std::vector<Event>::const_iterator event;
+            for (event = events_.begin(); event != events_.end(); ++event)
+            {
+                if (event->first == WriteOutput)
+                {
+                    output.write(event->second);
+                }
+                else
+                {
+                    std::string expectedLine;
+                    const bool  bInputRemaining = (nextInputLine_ < inputLines_.size());
+                    if (bInputRemaining)
+                    {
+                        expectedLine = inputLines_[nextInputLine_];
+                        if (event->first != ReadInputNoNewline)
+                        {
+                            expectedLine.append("\n");
+                        }
+                    }
+                    ++nextInputLine_;
+                    std::string line;
+                    EXPECT_EQ(bInputRemaining, input.readLine(&line));
+                    EXPECT_EQ(expectedLine, line);
+                }
+            }
+            helper_.checkSession();
+        }
+
+    private:
+        enum EventType
+        {
+            ReadInput,
+            ReadInputNoNewline,
+            WriteOutput
+        };
+        // The latter is the output string.
+        typedef std::pair<EventType, const char *> Event;
+
+        gmx::test::TestReferenceData     data_;
+        gmx::test::InteractiveTestHelper helper_;
+        std::vector<const char *>        inputLines_;
+        size_t                           nextInputLine_;
+        std::vector<Event>               events_;
+};
+
+TEST(InteractiveTestHelperTest, ChecksSimpleSession)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n");
+        session.addOutput("> ");
+        session.addInput("input");
+        session.addOutput("Second line\n");
+        session.addOutput("> ");
+        session.addReadInput();
+        session.addOutput("\n");
+        session.addOutput(".\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n");
+        session.addOutput("> ");
+        session.addInput("input");
+        session.addOutput("Second line\n");
+        session.addOutput("> ");
+        session.addReadInput();
+        session.addOutput("\n");
+        session.addOutput(".\n");
+        session.run();
+    }
+}
+
+TEST(InteractiveTestHelperTest, ChecksSessionWithoutLastNewline)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n");
+        session.addOutput("> ");
+        session.addInput("input");
+        session.addOutput("Second line\n");
+        session.addOutput("> ");
+        session.addInputNoNewline("input2");
+        session.addOutput("\n");
+        session.addOutput(".\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n");
+        session.addOutput("> ");
+        session.addInput("input");
+        session.addOutput("Second line\n");
+        session.addOutput("> ");
+        session.addInputNoNewline("input2");
+        session.addOutput("\n");
+        session.addOutput(".\n");
+        session.run();
+    }
+}
+
+TEST(InteractiveTestHelperTest, ChecksSessionWithMissingOutput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addInput("input2");
+        session.addOutput("Second line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addInput("input2");
+        session.addOutput("Second line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+}
+
+TEST(InteractiveTestHelperTest, ChecksSessionWithEquivalentOutput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n");
+        session.addOutput("> ");
+        session.addInput("input");
+        session.addOutput("Second line\n> ");
+        session.addReadInput();
+        session.addOutput("\n");
+        session.addOutput(".\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Second line\n");
+        session.addOutput("> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+}
+
+TEST(InteractiveTestHelperTest, DetectsIncorrectOutput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Second line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Incorrect line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        EXPECT_NONFATAL_FAILURE(session.run(), "");
+    }
+}
+
+TEST(InteractiveTestHelperTest, DetectsMissingOutput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Second line\n> ");
+        session.addInput("input2");
+        session.addOutput("Third line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addInput("input2");
+        session.addOutput("Third line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        EXPECT_NONFATAL_FAILURE(session.run(), "");
+    }
+}
+
+TEST(InteractiveTestHelperTest, DetectsMissingFinalOutput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Second line\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Second line\n> ");
+        session.addReadInput();
+        EXPECT_NONFATAL_FAILURE(session.run(), "");
+    }
+}
+
+TEST(InteractiveTestHelperTest, DetectsExtraOutput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addInput("input2");
+        session.addOutput("More output\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addOutput("First line\n> ");
+        session.addInput("input");
+        session.addOutput("Extra output\n> ");
+        session.addInput("input2");
+        session.addOutput("More output\n> ");
+        session.addReadInput();
+        session.addOutput("\n.\n");
+        EXPECT_NONFATAL_FAILURE(session.run(), "");
+    }
+}
+
+TEST(InteractiveTestHelperTest, DetectsMissingInput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addInput("input");
+        session.addInput("input2");
+        session.addReadInput();
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addInputLine("input");
+        session.addInputLine("input2");
+        session.addReadInput();
+        session.addReadInput();
+        EXPECT_NONFATAL_FAILURE(session.run(), "");
+    }
+}
+
+TEST(InteractiveTestHelperTest, DetectsExtraInput)
+{
+    {
+        InteractiveSession session(gmx::test::erefdataUpdateAll);
+        session.addInput("input");
+        session.addInput("input2");
+        session.addReadInput();
+        session.run();
+    }
+    {
+        InteractiveSession session(gmx::test::erefdataCompare);
+        session.addInputLine("input");
+        session.addInputLine("input2");
+        session.addReadInput();
+        session.addReadInput();
+        session.addReadInput();
+        session.addReadInput();
+        EXPECT_NONFATAL_FAILURE(session.run(), "");
+    }
+}
+
+} // namespace
index 61c948359bd2832e0adba5447ced50374adff564..ec095624591f0f48dded05a5ce44225874494e30 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,8 +45,8 @@
 
 #include <vector>
 
-#include <gtest/gtest-spi.h>
 #include <gtest/gtest.h>
+#include <gtest/gtest-spi.h>
 
 namespace
 {
index a99fccd9dac05911488d62b1c6d4d85fa27b274a..5c627688abd8e4057ebd41b5d1769ba546567490 100644 (file)
  *    temporary files that need to be created during the test.
  *  - gmx::test::TestFileInputRedirector (in testfileredirector.h) provides
  *    functionality for capturing file existence checks in code that uses
- *    gmx::FileInputRedirectorInterface.
+ *    gmx::IFileInputRedirector.
+ *  - gmx::test::TestFileOutputRedirector (in testfileredirector.h) provides
+ *    functionality for capturing file output (including `stdout`) from code
+ *    that uses gmx::IFileOutputRedirector, and checking that output
+ *    against reference data.
+ *  - gmx::test::InteractiveTestHelper (in interactivetest.h) provides
+ *    a helper class for testing an interactive session that uses
+ *    gmx::TextInputStream and gmx::TextOutputStream for prompting input and
+ *    printing status messages.
  *  - #GMX_TEST_OPTIONS macro provides facilities for adding custom command
  *    line options for the test binary.
  *  - testasserts.h provides several custom test assertions for better