1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // SpeciesCmd.cpp
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 #include "SpeciesCmd.h"
20 #include "SpeciesReader.h"
21 #include "Species.h"
22 using namespace std;
23 
24 class Species;
25 
26 ////////////////////////////////////////////////////////////////////////////////
action(int argc,char ** argv)27 int SpeciesCmd::action(int argc, char **argv)
28 {
29   if ( argc != 3 )
30   {
31     if ( ui->onpe0() )
32       cout << "  Use: species name uri" << endl;
33     return 1;
34   }
35 
36   if ( ui->onpe0() )
37   {
38     cout << "  SpeciesCmd: defining species " << argv[1]
39          << " as " << argv[2] << endl;
40   }
41 
42   string xmlstr;
43   SpeciesReader sp_reader;
44   if ( ui->onpe0() )
45     sp_reader.uri_to_string(argv[2], argv[1], xmlstr);
46 
47   int length;
48   if ( MPIdata::onpe0() )
49     length = xmlstr.size();
50   MPI_Bcast(&length,1,MPI_INT,0,MPIdata::comm());
51   char* buf = new char[length+1];
52   xmlstr.copy(buf,length,0);
53   buf[length]='\0';
54   MPI_Bcast(buf,length+1,MPI_CHAR,0,MPIdata::comm());
55   xmlstr = buf;
56   delete [] buf;
57 
58   //s->ctxt_.string_bcast(xmlstr,0);
59   Species* sp = new Species("argv[1]");
60   sp_reader.string_to_species(xmlstr,*sp);
61   s->atoms.addSpecies(sp,argv[1]);
62 
63   return 0;
64 }
65