3
\brief Enter brief description of file here
8
#include <libpsio/psio.h>
15
/* dpd_file4_init(): Prepares a dpd four-index file on disk for
19
** dpdfile4 *File: A pointer to the dpdfile4 to be initialized.
20
** int filenum: The PSI unit number for this file.
21
** int irrep: The irrep of this quantity.
22
** int pqnum: The index combination for the bra indices for the
23
** data as it will be stored on disk.
24
** int rsnum: The index combination for the ket indices for the
25
** data as it will be stored on disk.
26
** char *label: A string labelling for this buffer.
29
int dpd_file4_init(dpdfile4 *File, int filenum, int irrep, int pqnum,
30
int rsnum, const char *label)
33
int maxrows, rowtot, coltot;
34
unsigned int priority;
35
struct dpd_file4_cache_entry *this_entry;
36
psio_address irrep_ptr;
38
File->dpdnum = dpd_default;
39
File->params = &(dpd_list[dpd_default].params4[pqnum][rsnum]);
41
strcpy(File->label,label);
42
File->filenum = filenum;
43
File->my_irrep = irrep;
45
this_entry = dpd_file4_cache_scan(filenum, irrep, pqnum, rsnum, label, dpd_default);
46
if(this_entry != NULL) {
48
File->matrix = this_entry->matrix;
52
File->matrix = (double ***) malloc(File->params->nirreps*sizeof(double **));
55
/* Construct logical subfile pointers */
56
File->lfiles = (psio_address *) malloc(File->params->nirreps *
57
sizeof(psio_address));
58
File->lfiles[0] = PSIO_ZERO;
59
for(i=1; i < File->params->nirreps; i++) {
61
rowtot = File->params->rowtot[i-1];
62
coltot = File->params->coltot[(i-1)^irrep];
65
/* number of rows for which we can compute the address offset directly */
66
maxrows = DPD_BIGNUM/(coltot*sizeof(double));
68
fprintf(stderr, "\nLIBDPD Error: each row of %s is too long to compute an address.\n",
70
dpd_error("dpd_file4_init", stderr);
73
else maxrows = DPD_BIGNUM;
75
/* compute the file offset by increments */
76
irrep_ptr = File->lfiles[i-1];
77
for(; rowtot > maxrows; rowtot -= maxrows)
78
irrep_ptr = psio_get_address(irrep_ptr, maxrows*coltot*sizeof(double));
79
irrep_ptr = psio_get_address(irrep_ptr, rowtot*coltot*sizeof(double));
81
File->lfiles[i] = irrep_ptr;
84
/* Put this file4 into cache if requested */
85
if(dpd_main.cachefiles[filenum] && dpd_main.cachelist[pqnum][rsnum])
87
/* Get the file4's cache priority */
88
if(dpd_main.cachetype == 1)
89
priority = dpd_file4_cache_get_priority(File);
92
dpd_file4_cache_add(File, priority);
94
/* Make sure this cache entry can't be deleted until we're done */
95
dpd_file4_cache_lock(File);