source: ThirdParty/mpqc_open/src/lib/util/psi3/libpsio/read.cc@ 866dec

AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity PythonUI_with_named_parameters StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 866dec 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.2 KB
Line 
1/*!
2 \file read.c
3 \ingroup (PSIO)
4*/
5
6#include <unistd.h>
7#include <string.h>
8#include <util/psi3/libpsio/psio.h>
9
10namespace psi3 {
11namespace libpsio {
12
13/*!
14** PSIO_READ(): Reads data from within a TOC entry from a PSI file.
15**
16** \param unit = The PSI unit number used to identify the file to all
17** read and write functions.
18** \param key = The TOC keyword identifying the desired entry.
19** \param buffer = The buffer to store the data as it is read.
20** \param size = The number of bytes to read.
21** \param sadd = The entry-relative starting page/offset of the desired data.
22** \param eadd = A pointer to the entry-relative page/offset for the next
23** byte after the end of the read request.
24**
25** \ingroup (PSIO)
26*/
27
28int psio_read(unsigned int unit, char *key, char *buffer, ULI size,
29 psio_address sadd, psio_address *eadd)
30{
31 psio_ud *this_unit;
32 psio_address address, end_address;
33 psio_tocentry *this_entry;
34
35 this_unit = &(psio_unit[unit]);
36
37 /* Find the entry in the TOC */
38 this_entry = psio_tocscan(unit, key);
39
40 if(this_entry == NULL) {
41 fprintf(stderr, "PSIO_ERROR: Can't find TOC Entry %s\n", key);
42 psio_error(unit,PSIO_ERROR_NOTOCENT);
43 }
44 else {
45
46 /* Compute the starting page and offset for the block */
47 address = psio_get_global_address(this_entry->sadd, sadd);
48
49 /* Make sure the block starts and ends within the entry */
50 if(address.page > this_entry->eadd.page)
51 psio_error(unit,PSIO_ERROR_BLKSTART);
52 else if((address.page == this_entry->eadd.page) &&
53 (address.offset > this_entry->eadd.offset))
54 psio_error(unit,PSIO_ERROR_BLKSTART);
55
56 end_address = psio_get_address(address, size);
57 if((end_address.page > this_entry->eadd.page))
58 psio_error(unit,PSIO_ERROR_BLKEND);
59 else if((end_address.page == this_entry->eadd.page) &&
60 (end_address.offset > this_entry->eadd.offset))
61 psio_error(unit,PSIO_ERROR_BLKEND);
62
63 /* Update the eadd argument value for the caller */
64 *eadd = psio_get_address(sadd, size);
65 }
66
67 /* Now read the actual data from the unit */
68 psio_rw(unit, buffer, address, size, 0);
69
70#ifdef PSIO_STATS
71 psio_readlen[unit] += size;
72#endif
73
74 return(0);
75}
76
77}
78}
Note: See TracBrowser for help on using the repository browser.