4
int dpd_buf4_mat_irrep_row_wrt(dpdbuf4 *Buf, int irrep, int pq)
6
int method, filerow, all_buf_irrep;
7
int rs; /* dpdfile row and column indices */
8
int p, q, r, s; /* orbital indices */
9
int bufpq, bufrs; /* Input dpdbuf row and column indices */
11
int rowtot, coltot; /* dpdfile row and column dimensions */
12
int b_perm_pq, b_perm_rs, b_peq, b_res;
13
int f_perm_pq, f_perm_rs, f_peq, f_res;
17
all_buf_irrep = Buf->file.my_irrep;
18
/* Row and column dimensions in the DPD file */
19
rowtot = Buf->file.params->rowtot[irrep];
20
coltot = Buf->file.params->coltot[irrep^all_buf_irrep];
22
/* Index packing information */
23
b_perm_pq = Buf->params->perm_pq; b_perm_rs = Buf->params->perm_rs;
24
f_perm_pq = Buf->file.params->perm_pq; f_perm_rs = Buf->file.params->perm_rs;
25
b_peq = Buf->params->peq; b_res = Buf->params->res;
26
f_peq = Buf->file.params->peq; f_res = Buf->file.params->res;
28
/* Exit if buffer is antisymmetrized */
30
fprintf(stderr, "\n\tCannot write antisymmetrized buffer\n");
31
fprintf(stderr, "\tback to original DPD file!\n");
32
exit(PSI_RETURN_FAILURE);
35
if((b_perm_pq == f_perm_pq) && (b_perm_rs == f_perm_rs) &&
36
(b_peq == f_peq) && (b_res == f_res)) method = 12;
37
else if((b_perm_pq != f_perm_pq) && (b_perm_rs == f_perm_rs) &&
39
if(f_perm_pq && !b_perm_pq) method = 21;
40
else if(!f_perm_pq && b_perm_pq) method = 23;
42
fprintf(stderr, "\n\tInvalid second-level method!\n");
43
exit(PSI_RETURN_FAILURE);
46
else if((b_perm_pq == f_perm_pq) && (b_perm_rs != f_perm_rs) &&
48
if(f_perm_rs && !b_perm_rs) method = 31;
49
else if(!f_perm_rs && b_perm_rs) method = 33;
51
fprintf(stderr, "\n\tInvalid third-level method!\n");
52
exit(PSI_RETURN_FAILURE);
55
else if((b_perm_pq != f_perm_pq) && (b_perm_rs != f_perm_rs)) {
56
if(f_perm_pq && !b_perm_pq) {
57
if(f_perm_rs && !b_perm_rs) method = 41;
58
else if(!f_perm_rs && b_perm_rs) method = 42;
60
else if(!f_perm_pq && b_perm_pq) {
61
if(f_perm_rs && !b_perm_rs) method = 43;
62
else if(!f_perm_rs && b_perm_rs) method = 45;
65
fprintf(stderr, "\n\tInvalid fourth-level method!\n");
66
exit(PSI_RETURN_FAILURE);
70
fprintf(stderr, "\n\tInvalid method in dpd_buf_mat_irrep_rd!\n");
71
exit(PSI_RETURN_FAILURE);
76
case 12: /* No change in pq or rs */
78
if(Buf->file.incore) {
79
for(rs=0; rs < rowtot; rs++)
80
Buf->file.matrix[irrep][pq][rs] = Buf->matrix[irrep][0][rs];
81
dpd_file4_cache_dirty(&(Buf->file));
84
Buf->file.matrix[irrep] = Buf->matrix[irrep];
85
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
89
case 21: /* Pack pq; no change in rs */
90
/* Prepare the output buffer for the output DPD file */
91
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
93
p = Buf->file.params->roworb[irrep][pq][0];
94
q = Buf->file.params->roworb[irrep][pq][1];
95
filepq = Buf->file.params->rowidx[p][q];
97
filerow = Buf->file.incore ? filepq : 0;
99
/* Loop over the columns in the dpdbuf */
100
for(rs=0; rs < coltot; rs++) {
103
value = Buf->matrix[irrep][0][bufrs];
105
/* Assign the value */
106
Buf->file.matrix[irrep][filerow][rs] = value;
109
/* Write out the row */
110
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, filepq);
112
/* Close the input buffer */
113
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
116
case 23: /* Unpack pq; no change in rs */
117
/* I don't know if I'll ever use this, so I'll avoid it for now */
118
fprintf(stderr, "\n\tShould you be using method %d?\n", method);
119
exit(PSI_RETURN_FAILURE);
122
case 31: /* No change in pq; pack rs */
123
/* Prepare the output buffer for the output DPD file */
124
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
126
filerow = Buf->file.incore ? pq : 0;
128
/* Loop over the columns in the dpdfile */
129
for(rs=0; rs < coltot; rs++) {
130
r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
131
s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
132
bufrs = Buf->params->colidx[r][s];
134
value = Buf->matrix[irrep][0][bufrs];
136
/* Assign the value */
137
Buf->file.matrix[irrep][filerow][rs] = value;
140
/* Write out the row */
141
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
143
/* Close the input buffer */
144
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
147
case 33: /* No change in pq; unpack rs */
148
/* I'm not sure if I'll ever need this, so I'm removing it for now */
149
fprintf(stderr, "\n\tShould you be using method %d?\n", method);
150
exit(PSI_RETURN_FAILURE);
153
case 41: /* Pack pq and rs */
154
/* Prepare the output buffer for the output DPD file */
155
dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
157
p = Buf->file.params->roworb[irrep][pq][0];
158
q = Buf->file.params->roworb[irrep][pq][1];
159
filepq = Buf->file.params->rowidx[p][q];
161
filerow = Buf->file.incore ? filepq : 0;
164
/* Loop over the columns in the dpdfile */
165
for(rs=0; rs < coltot; rs++) {
166
r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
167
s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
168
bufrs = Buf->params->colidx[r][s];
170
value = Buf->matrix[irrep][0][bufrs];
172
/* Assign the value */
173
Buf->file.matrix[irrep][filerow][rs] = value;
176
/* Write out the row */
177
dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, filepq);
179
/* Close the input buffer */
180
dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
183
case 42: /* Pack pq; unpack rs */
184
fprintf(stderr, "\n\tHaven't programmed method 42 yet!\n");
185
exit(PSI_RETURN_FAILURE);
188
case 43: /* Unpack pq; pack rs */
189
fprintf(stderr, "\n\tHaven't programmed method 43 yet!\n");
190
exit(PSI_RETURN_FAILURE);
193
case 45: /* Unpack pq and rs */
194
/* I'm not sure if I'll ever need this, so I'm removing it for now */
195
fprintf(stderr, "\n\tShould you be using method %d?\n", method);
196
exit(PSI_RETURN_FAILURE);
199
default: /* Error trapping */
200
fprintf(stderr, "\n\tInvalid switch case in dpd_buf_mat_irrep_rd!\n");
201
exit(PSI_RETURN_FAILURE);