source: ThirdParty/mpqc_open/src/lib/util/psi3/libpsio/open.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: 3.2 KB
Line 
1/*!
2 \file open.cc
3 \ingroup (PSIO)
4*/
5
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
9#include <string.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <util/psi3/libpsio/psio.h>
13
14namespace psi3 {
15namespace libpsio {
16
17/*!
18** PSIO_OPEN(): Opens a multivolume PSI direct access file for
19** reading/writing data.
20**
21** \param unit = The PSI unit number used to identify the file to all
22** read and write functions.
23** \param status = Indicates if the file is old (PSIO_OPEN_OLD) or new
24** (PSIO_OPEN_NEW).
25**
26** \ingroup (PSIO)
27*/
28
29int psio_open(unsigned int unit, int status)
30{
31 unsigned int i, j;
32 int errcod, stream, tocstat;
33 char name[PSIO_MAXSTR],path[PSIO_MAXSTR],fullpath[PSIO_MAXSTR];
34 psio_ud *this_unit;
35
36 this_unit = &(psio_unit[unit]);
37
38 /* First check to see if this unit is aleady open */
39 if(this_unit->vol[0].stream != -1) psio_error(unit,PSIO_ERROR_REOPEN);
40
41 /* Get number of volumes to stripe across */
42 this_unit->numvols = psio_get_numvols(unit);
43 if(this_unit->numvols > PSIO_MAXVOL) psio_error(unit,PSIO_ERROR_MAXVOL);
44
45 if(!(this_unit->numvols)) this_unit->numvols = 1;
46
47 /* Get the file name prefix */
48 errcod = psio_get_filename(unit,name);
49
50 /* Build the name for each volume and open the file */
51 for(i=0; i < this_unit->numvols; i++) {
52 errcod = psio_get_volpath(unit, i, path);
53
54 if(errcod && this_unit->numvols > 1)
55 psio_error(unit,PSIO_ERROR_NOVOLPATH);
56
57 sprintf(fullpath, "%s%s.%u", path, name, unit);
58 this_unit->vol[i].path = (char *) malloc(strlen(fullpath)+1);
59 strcpy(this_unit->vol[i].path,fullpath);
60
61 /* Check if any previously opened volumes have the same path */
62 for(j=0; j < i; j++)
63 if (!strcmp(this_unit->vol[i].path,this_unit->vol[j].path))
64 psio_error(unit,PSIO_ERROR_IDENTVOLPATH);
65
66 /* Now open the volume */
67 if(status == PSIO_OPEN_OLD) {
68 this_unit->vol[i].stream =
69 open(this_unit->vol[i].path,O_CREAT|O_RDWR,0644);
70 if(this_unit->vol[i].stream == -1)
71 psio_error(unit,PSIO_ERROR_OPEN);
72 }
73 else if(status == PSIO_OPEN_NEW) {
74 this_unit->vol[i].stream =
75 open(this_unit->vol[i].path,O_CREAT|O_RDWR|O_TRUNC,0644);
76 if(this_unit->vol[i].stream == -1)
77 psio_error(unit,PSIO_ERROR_OPEN);
78 }
79 else psio_error(unit,PSIO_ERROR_OSTAT);
80 }
81
82 if (status == PSIO_OPEN_OLD) tocstat = psio_tocread(unit);
83 else if (status == PSIO_OPEN_NEW) {
84
85 /* Init the TOC stats and write them to disk */
86 this_unit->tocaddress.page = 0;
87 this_unit->tocaddress.offset = 3*sizeof(ULI);
88 this_unit->toclen = 0;
89 this_unit->toc = NULL;
90
91 /* Seek vol[0] to its beginning */
92 stream = this_unit->vol[0].stream;
93 errcod = lseek(stream, 0L, SEEK_SET);
94 if(errcod == -1) psio_error(unit,PSIO_ERROR_LSEEK);
95
96 errcod = write(stream, (char *) &(this_unit->tocaddress.page),
97 sizeof(ULI));
98 if(errcod != sizeof(ULI)) psio_error(unit,PSIO_ERROR_WRITE);
99 errcod = write(stream, (char *) &(this_unit->tocaddress.offset),
100 sizeof(ULI));
101 if(errcod != sizeof(ULI)) psio_error(unit,PSIO_ERROR_WRITE);
102 errcod = write(stream, (char *) &(this_unit->toclen), sizeof(ULI));
103 if(errcod != sizeof(ULI)) psio_error(unit,PSIO_ERROR_WRITE);
104
105 }
106 else psio_error(unit,PSIO_ERROR_OSTAT);
107
108 return(0);
109}
110
111}
112}
Note: See TracBrowser for help on using the repository browser.