source: ThirdParty/mpqc_open/src/lib/util/psi3/libpsio/tocwrite.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: 2.3 KB
Line 
1/*!
2 \file tocwrite.c
3 \ingroup (PSIO)
4*/
5
6#include <stdlib.h>
7#include <unistd.h>
8#include <util/psi3/libpsio/psio.h>
9#include <util/psi3/libpsio/psifiles.h>
10
11namespace psi3 {
12namespace libpsio {
13
14/*!
15** PSIO_TOCWRITE(): Write the table of contents for file number 'unit'.
16**
17** \ingroup (PSIO)
18*/
19int psio_tocwrite(unsigned int unit)
20{
21 unsigned int i;
22 int errcod, volume, entry_size, stream;
23 psio_ud *this_unit;
24 psio_tocentry *this_entry;
25
26 this_unit = &(psio_unit[unit]);
27 entry_size = sizeof(psio_tocentry) - 2*sizeof(psio_tocentry *);
28
29 /* Check that this unit is actually open */
30 if(this_unit->vol[0].stream == -1) return(0);
31
32 /* Seek vol[0] to its beginning */
33 stream = this_unit->vol[0].stream;
34 errcod = lseek(stream, 0L, SEEK_SET);
35 if(errcod == -1) {
36 fprintf(stderr, "Error in PSIO_TOCWRITE()!\n");
37 exit(PSI_RETURN_FAILURE);
38 }
39
40 /* Dump the TOC stats to disk */
41 errcod = write(stream, (char *) &(this_unit->tocaddress.page), sizeof(ULI));
42 if(errcod != sizeof(ULI)) {
43 fprintf(stderr, "Error in PSIO_TOCWRITE()!\n");
44 exit(PSI_RETURN_FAILURE);
45 }
46 errcod = write(stream, (char *) &(this_unit->tocaddress.offset), sizeof(ULI));
47 if(errcod != sizeof(ULI)) {
48 fprintf(stderr, "Error in PSIO_TOCWRITE()!\n");
49 exit(PSI_RETURN_FAILURE);
50 }
51 errcod = write(stream, (char *) &(this_unit->toclen), sizeof(ULI));
52 if(errcod != sizeof(ULI)) {
53 fprintf(stderr, "Error in PSIO_TOCWRITE()!\n");
54 exit(PSI_RETURN_FAILURE);
55 }
56
57 /* Seek the TOC volume to the correct position */
58 volume = (this_unit->tocaddress.page) % (this_unit->numvols);
59 errcod = psio_volseek(&(this_unit->vol[volume]), this_unit->tocaddress.page,
60 this_unit->tocaddress.offset,this_unit->numvols);
61 if(errcod == -1) {
62 fprintf(stderr, "Error in PSIO_TOCWRITE()!\n");
63 exit(PSI_RETURN_FAILURE);
64 }
65
66 this_entry = this_unit->toc;
67 for(i=0; i < this_unit->toclen; i++) {
68
69 /* This write() assumes a fixed ordering on the members of this_toc */
70 errcod = write(this_unit->vol[volume].stream, (char *) this_entry,
71 entry_size);
72 if(errcod != entry_size) {
73 fprintf(stderr, "Error in PSIO_TOCWRITE()!\n");
74 exit(PSI_RETURN_FAILURE);
75 }
76
77 this_entry = this_entry->next;
78 }
79
80 return(0);
81}
82
83}
84}
Note: See TracBrowser for help on using the repository browser.