Chaste  Release::3.4
Citations.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "Citations.hpp"
37 #include "PetscTools.hpp"
38 
39 // Initialise 'member' variables
40 std::vector<const char *> Citations::mCitations;
42 
43 void Citations::Register(const char pCitation[], PetscBool* pSet)
44 {
45  // Figure out if we can use PETSc's implementation.
46  // Note that the effect of this if() is to ensure we don't switch implementation if PETSc is initialised after the first citation is registered.
47  // (If PETSc is finalised after the first citation is registered we will probably switch implementation, but there's no way to avoid that.)
49  {
50 #if ( (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=5) || PETSC_VERSION_MAJOR>3 )
52 #else
54 #endif
55  }
56 
58  {
59 #if ( (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=5) || PETSC_VERSION_MAJOR>3 )
60  PetscCitationsRegister(pCitation, pSet);
61 #endif
62  }
63  else if (!(*pSet))
64  {
65  // Not yet added this one
66  mCitations.push_back(pCitation);
67  *pSet = PETSC_TRUE;
68  }
69 }
70 
72 {
74  {
75  if ( PetscTools::AmMaster() && CommandLineArguments::Instance()->OptionExists("-citations") )
76  {
77  std::ostream * p_output = &(std::cout);
78  bool writing_to_file = false;
79 
81  {
82  // We've got a file to write to - assume the user has given us something sensible!
83  writing_to_file = true;
84  std::string out_file_path = CommandLineArguments::Instance()->GetStringCorrespondingToOption("-citations");
85  p_output = new std::ofstream( out_file_path.c_str(), std::ios::out );
86  EXCEPT_IF_NOT( p_output->good() );
87  }
88 
89  /* Write header */
90  (*p_output) << "If you publish results based on this computation please cite the following:" << std::endl;
91  (*p_output) << "===========================================================================" << std::endl;
92  /* Write citations */
93  for ( unsigned i=0; i<mCitations.size(); ++i )
94  {
95  (*p_output) << mCitations[i];
96  }
97  /* Write footer */
98  (*p_output) << "===========================================================================" << std::endl;
99 
100  if ( writing_to_file )
101  {
102  delete p_output;
103  }
104  }
105  }
106 }
static bool mUseChasteImplementation
Definition: Citations.hpp:82
static bool AmMaster()
Definition: PetscTools.cpp:120
std::string GetStringCorrespondingToOption(const std::string &rOption, int valueNumber=1)
#define EXCEPT_IF_NOT(test)
Definition: Exception.hpp:158
static void Register(const char *pCitation, PetscBool *pSet)
Definition: Citations.cpp:43
static CommandLineArguments * Instance()
static bool IsInitialised()
Definition: PetscTools.cpp:85
int GetNumberOfArgumentsForOption(const std::string &rOption, bool throwIfNone=false)
static std::vector< const char * > mCitations
Definition: Citations.hpp:79
static void Print()
Definition: Citations.cpp:71