source: ThirdParty/mpqc_open/src/lib/util/state/state_bin.cc@ 00f983

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 00f983 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: 4.7 KB
Line 
1//
2// state_bin.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#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <scconfig.h>
33#include <util/state/state_bin.h>
34
35using namespace std;
36using namespace sc;
37
38#define DEBUG 0
39
40static ClassDesc StateOutBin_cd(
41 typeid(StateOutBin),"StateOutBin",1,"public StateOutFile");
42
43StateOutBin::StateOutBin() :
44 StateOutFile()
45{
46 file_position_ = 0;
47}
48
49StateOutBin::StateOutBin(ostream& s):
50 StateOutFile(s)
51{
52 file_position_ = 0;
53 // needed here since only StateOutFile::open has been called so far
54 put_header();
55}
56
57StateOutBin::StateOutBin(const char *path) :
58 StateOutFile(path)
59{
60 file_position_ = 0;
61 // needed here since only StateOutFile::open has been called so far
62 put_header();
63}
64
65StateOutBin::~StateOutBin()
66{
67 // must close here since close() is overridden in this class
68 close();
69}
70
71int
72StateOutBin::open(const char *f)
73{
74 int r = StateOutFile::open(f);
75 put_header();
76 return r;
77}
78
79void
80StateOutBin::close()
81{
82 if (buf_ && use_directory()) {
83 int dir_loc = tell();
84 seek(dir_loc_loc_);
85 put_array_int(&dir_loc,1);
86 seek(dir_loc);
87 put_directory();
88 }
89
90 StateOutFile::close();
91}
92
93int
94StateOutBin::tell()
95{
96 return file_position_;
97}
98
99void
100StateOutBin::seek(int loc)
101{
102 file_position_ = loc;
103#if defined(HAVE_PUBSEEKOFF)
104 buf_->pubseekoff(loc,ios::beg,ios::out);
105#elif defined(HAVE_SEEKOFF)
106 buf_->seekoff(loc,ios::beg,ios::out);
107#endif
108}
109
110int
111StateOutBin::seekable()
112{
113#if defined(HAVE_PUBSEEKOFF) || defined(HAVE_SEEKOFF)
114 return 1;
115#else
116 return 0;
117#endif
118}
119
120int
121StateOutBin::use_directory()
122{
123 return seekable();
124}
125
126////////////////////////////////////////////////////////////////
127
128static ClassDesc StateInBin_cd(typeid(StateInBin),
129 "StateInBin",1,"public StateInFile",
130 0, create<StateInBin>);
131
132StateInBin::StateInBin() :
133 StateInFile()
134{
135 file_position_ = 0;
136}
137
138StateInBin::StateInBin(istream& s) :
139 StateInFile(s)
140{
141 file_position_ = 0;
142 get_header();
143 find_and_get_directory();
144}
145
146StateInBin::StateInBin(const char *path) :
147 StateInFile(path)
148{
149 file_position_ = 0;
150 get_header();
151 find_and_get_directory();
152}
153
154StateInBin::StateInBin(const Ref<KeyVal> &keyval)
155{
156 char *path = keyval->pcharvalue("file");
157 if (!path) {
158 ExEnv::errn() << "StateInBin(const Ref<KeyVal>&): no path given" << endl;
159 }
160 open(path);
161 delete[] path;
162}
163
164StateInBin::~StateInBin()
165{
166}
167
168int
169StateInBin::open(const char *f)
170{
171 file_position_ = 0;
172 int r = StateInFile::open(f);
173 get_header();
174 find_and_get_directory();
175 return r;
176}
177
178int
179StateInBin::tell()
180{
181 return file_position_;
182}
183
184void
185StateInBin::seek(int loc)
186{
187 file_position_ = loc;
188#if defined(HAVE_PUBSEEKOFF)
189 buf_->pubseekoff(loc,ios::beg,ios::in);
190#elif defined(HAVE_SEEKOFF)
191 buf_->seekoff(loc,ios::beg,ios::in);
192#endif
193}
194
195int
196StateInBin::seekable()
197{
198#if defined(HAVE_PUBSEEKOFF) || defined(HAVE_SEEKOFF)
199 return 1;
200#else
201 return 0;
202#endif
203}
204
205int
206StateInBin::use_directory()
207{
208 return seekable();
209}
210
211////////////////////////////////////////////////////////////////
212
213int StateOutBin::put_array_void(const void*p,int size)
214{
215 if (buf_->sputn((const char *)p,size) != size) {
216 ExEnv::errn() << "StateOutBin::put_array_void: failed" << endl;
217 abort();
218 }
219 file_position_ += size;
220 return size;
221}
222
223int StateInBin::get_array_void(void*p,int size)
224{
225 if (buf_->sgetn((char*)p,size) != size) {
226 ExEnv::errn() << "StateInBin::get_array_void: failed" << endl;
227 abort();
228 }
229#if DEBUG
230 ExEnv::outn() << "Read " << size << " bytes: ";
231 for (int i=0; i<size; i++) {
232 ExEnv::outn() << ((unsigned char*)p)[i];
233 }
234 ExEnv::outn() << endl;
235#endif
236 file_position_ += size;
237 return size;
238}
239
240/////////////////////////////////////////////////////////////////////////////
241
242// Local Variables:
243// mode: c++
244// c-file-style: "CLJ"
245// End:
Note: See TracBrowser for help on using the repository browser.