source: ThirdParty/mpqc_open/src/lib/util/misc/formio.cc@ bbc982

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since bbc982 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 6.0 KB
Line 
1//
2// formio.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#include <util/misc/formio.h>
29#include <util/misc/exenv.h>
30
31#include <stdio.h> // for vsprintf
32#include <stdlib.h>
33#include <string.h>
34#include <stdarg.h>
35
36using namespace std;
37using namespace sc;
38
39char *SCFormIO::default_basename_ = 0;
40int SCFormIO::ready_ = 0;
41int SCFormIO::xalloc_inited_ = 0;
42long SCFormIO::nindent_ = 0;
43long SCFormIO::indent_size_ = 0;
44long SCFormIO::skip_indent_ = 0;
45long SCFormIO::verbose_ = 0;
46long SCFormIO::initialized_ = 0;
47int SCFormIO::node_to_print_ = 0;
48int SCFormIO::debug_ = 0;
49int SCFormIO::parallel_ = 0;
50int SCFormIO::me_ = 0;
51
52char *
53SCFormIO::fileext_to_filename(const char *ext)
54{
55 const char *basename;
56
57 if (default_basename_) basename = default_basename_;
58 else basename = "SC";
59
60 char * res = new char[strlen(basename) + strlen(ext) + 1];
61 strcpy(res, basename);
62 strcat(res, ext);
63
64 return res;
65}
66
67void
68SCFormIO::set_default_basename(const char *basename)
69{
70 if (default_basename_) delete[] default_basename_;
71
72 if (basename)
73 default_basename_ = strcpy(new char[strlen(basename)+1], basename);
74 else
75 default_basename_ = 0;
76}
77
78const char *
79SCFormIO::default_basename()
80{
81 return default_basename_;
82}
83
84int
85SCFormIO::set_printnode(int n)
86{
87 int r = node_to_print_;
88 node_to_print_ = n;
89 return r;
90}
91
92void
93SCFormIO::set_debug(int n)
94{
95 debug_ = n;
96}
97
98void
99SCFormIO::init_mp(int me)
100{
101 if (!ready_) init();
102 me_ = me;
103 parallel_=1;
104}
105
106void
107SCFormIO::init_ostream(ostream &o)
108{
109 if (!xalloc_inited_) {
110 xalloc_inited_ = 1;
111 nindent_ = ios::xalloc();
112 indent_size_ = ios::xalloc();
113 skip_indent_ = ios::xalloc();
114 verbose_ = ios::xalloc();
115 initialized_ = ios::xalloc();
116 }
117
118 if (o.iword(initialized_)) return;
119
120 o.iword(skip_indent_) = 0;
121 o.iword(indent_size_) = 0;
122 o.iword(nindent_) = 2;
123 o.iword(verbose_) = 0;
124 o.iword(initialized_) = 1;
125}
126
127void
128SCFormIO::init()
129{
130 ready_ = 1;
131
132 init_ostream(cout);
133 init_ostream(cerr);
134}
135
136ios&
137SCFormIO::indent(ios&o)
138{
139 if (!ready_) init();
140 long &skip = o.iword(skip_indent_);
141 if (skip) {
142 skip--;
143 return o;
144 }
145 if (debug_ && parallel_) {
146 char nn[24];
147 sprintf(nn,"node %5d:",me_);
148 for (size_t i=0; i < strlen(nn); i++) o.rdbuf()->sputc(nn[i]);
149 }
150 long n = o.iword(nindent_);
151 for (int i=0; i<n; i++) o.rdbuf()->sputc(' ');
152 return o;
153}
154
155ios&
156SCFormIO::incindent(ios&o)
157{
158 if (!ready_) init();
159 long &n = o.iword(nindent_);
160 long size = o.iword(indent_size_);
161 if (size == 0) size = 2;
162 else if (size < 0) size = 0;
163 n += size;
164 return o;
165}
166
167ios&
168SCFormIO::decindent(ios&o)
169{
170 if (!ready_) init();
171 long &n = o.iword(nindent_);
172 long size = o.iword(indent_size_);
173 if (size == 0) size = 2;
174 else if (size < 0) size = 0;
175 n -= size;
176 if (n<0) n=0;
177 return o;
178}
179
180long
181SCFormIO::getindent(ios&o)
182{
183 if (!ready_) init();
184 return o.iword(nindent_);
185}
186
187void
188SCFormIO::setindent(ios&o, long n)
189{
190 if (!ready_) init();
191 o.iword(nindent_) = n;
192}
193
194long
195SCFormIO::getverbose(ios&o)
196{
197 if (!ready_) init();
198 return o.iword(verbose_);
199}
200
201void
202SCFormIO::setverbose(ios&o, long n)
203{
204 if (!ready_) init();
205 o.iword(verbose_) = n;
206}
207
208ios&
209SCFormIO::skipnextindent(ios&o)
210{
211 if (!ready_) init();
212 o.iword(skip_indent_)++;
213 return o;
214}
215
216ostream&
217SCFormIO::copyright(ostream& o)
218{
219 o << indent
220 << "Copyright (C) 1997 Limit Point Systems, Inc. and others."
221 << endl;
222
223 return o;
224}
225
226ostream&
227SCFormIO::license(ostream& o)
228{
229 o << indent
230 << "This program is open-source software; you can redistribute it and/or modify"
231 << endl << indent
232 << "it under the terms of the GNU General Public License as published by"
233 << endl << indent
234 << "the Free Software Foundation; either version 2 of the License, or"
235 << endl << indent
236 << "(at your option) any later version."
237 << endl;
238
239 return o;
240}
241
242ostream&
243SCFormIO::warranty(ostream& o)
244{
245 o << indent
246 << "This program is distributed in the hope that it will be useful,"
247 << endl << indent
248 << "but WITHOUT ANY WARRANTY; without even the implied warranty of"
249 << endl << indent
250 << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
251 << endl << indent
252 << "GNU General Public License for more details."
253 << endl;
254
255 return o;
256}
257
258ios&
259sc::indent(ios& o)
260{
261 return SCFormIO::indent(o);
262}
263
264ios&
265sc::decindent(ios& o)
266{
267 return SCFormIO::decindent(o);
268}
269
270ios&
271sc::incindent(ios& o)
272{
273 return SCFormIO::incindent(o);
274}
275
276ios&
277sc::skipnextindent(ios& o)
278{
279 return SCFormIO::skipnextindent(o);
280}
281
282/////////////////////////////////////////////////////////////////////////////
283
284scprintf::scprintf(const char *fmt, ...)
285{
286 va_list args;
287
288 va_start(args, fmt);
289
290 str[0] = '\0';
291
292 // hopefully this won't overflow
293 if (fmt && fmt[0]!='\0') {
294 if (vsprintf(str, fmt, args) > 1023) {
295 ExEnv::errn() << indent << "scprintf overflow\n";
296 abort();
297 }
298 }
299
300 va_end(args);
301}
302
303ostream&
304sc::operator<<(ostream& o, const scprintf& s)
305{
306 o << s.str << flush;
307 return o;
308}
309
310/////////////////////////////////////////////////////////////////////////////
311
312// Local Variables:
313// mode: c++
314// c-file-style: "CLJ"
315// End:
Note: See TracBrowser for help on using the repository browser.