~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libdpd/buf4_mat_irrep_row_wrt.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include "dpd.h"
4
 
 
5
 
int dpd_buf4_mat_irrep_row_wrt(dpdbuf4 *Buf, int irrep, int pq)
6
 
{
7
 
  int method, filerow, all_buf_irrep;
8
 
  int rs;  /* dpdfile row and column indices */
9
 
  int p, q, r, s;  /* orbital indices */
10
 
  int bufpq, bufrs;  /* Input dpdbuf row and column indices */
11
 
  int filepq;
12
 
  int rowtot, coltot;  /* dpdfile row and column dimensions */
13
 
  int b_perm_pq, b_perm_rs, b_peq, b_res;
14
 
  int f_perm_pq, f_perm_rs, f_peq, f_res;
15
 
  int permute;
16
 
  double value; 
17
 
 
18
 
  all_buf_irrep = Buf->file.my_irrep;
19
 
  /* Row and column dimensions in the DPD file */
20
 
  rowtot = Buf->file.params->rowtot[irrep];
21
 
  coltot = Buf->file.params->coltot[irrep^all_buf_irrep];
22
 
 
23
 
  /* Index packing information */
24
 
  b_perm_pq = Buf->params->perm_pq; b_perm_rs = Buf->params->perm_rs;
25
 
  f_perm_pq = Buf->file.params->perm_pq; f_perm_rs = Buf->file.params->perm_rs;
26
 
  b_peq = Buf->params->peq; b_res = Buf->params->res;
27
 
  f_peq = Buf->file.params->peq; f_res = Buf->file.params->res;
28
 
 
29
 
  /* Exit if buffer is antisymmetrized */
30
 
  if(Buf->anti) {
31
 
      fprintf(stderr, "\n\tCannot write antisymmetrized buffer\n");
32
 
      fprintf(stderr,   "\tback to original DPD file!\n");
33
 
      exit(PSI_RETURN_FAILURE);
34
 
    }
35
 
 
36
 
  if((b_perm_pq == f_perm_pq) && (b_perm_rs == f_perm_rs) &&
37
 
     (b_peq == f_peq) && (b_res == f_res))   method = 12;
38
 
  else if((b_perm_pq != f_perm_pq) && (b_perm_rs == f_perm_rs) &&
39
 
          (b_res == f_res)) {
40
 
      if(f_perm_pq && !b_perm_pq) method = 21;
41
 
      else if(!f_perm_pq && b_perm_pq) method = 23;
42
 
      else {
43
 
          fprintf(stderr, "\n\tInvalid second-level method!\n");
44
 
          exit(PSI_RETURN_FAILURE);
45
 
        }
46
 
    }
47
 
  else if((b_perm_pq == f_perm_pq) && (b_perm_rs != f_perm_rs) &&
48
 
          (b_peq == f_peq)) {
49
 
      if(f_perm_rs && !b_perm_rs) method = 31;
50
 
      else if(!f_perm_rs && b_perm_rs) method = 33;
51
 
      else {
52
 
          fprintf(stderr, "\n\tInvalid third-level method!\n");
53
 
          exit(PSI_RETURN_FAILURE);
54
 
        }
55
 
    }
56
 
  else if((b_perm_pq != f_perm_pq) && (b_perm_rs != f_perm_rs)) {
57
 
      if(f_perm_pq && !b_perm_pq) {
58
 
          if(f_perm_rs && !b_perm_rs) method = 41;
59
 
          else if(!f_perm_rs && b_perm_rs) method = 42;
60
 
        }
61
 
      else if(!f_perm_pq && b_perm_pq) {
62
 
          if(f_perm_rs && !b_perm_rs) method = 43;
63
 
          else if(!f_perm_rs && b_perm_rs) method = 45;
64
 
        }
65
 
      else {
66
 
          fprintf(stderr, "\n\tInvalid fourth-level method!\n");
67
 
          exit(PSI_RETURN_FAILURE);
68
 
        }
69
 
    }
70
 
  else {
71
 
      fprintf(stderr, "\n\tInvalid method in dpd_buf_mat_irrep_rd!\n");
72
 
      exit(PSI_RETURN_FAILURE);
73
 
    }
74
 
 
75
 
 
76
 
  switch(method) {
77
 
  case 12: /* No change in pq or rs */
78
 
 
79
 
      if(Buf->file.incore) {
80
 
          for(rs=0; rs < rowtot; rs++)
81
 
              Buf->file.matrix[irrep][pq][rs] = Buf->matrix[irrep][0][rs];
82
 
          dpd_file4_cache_dirty(&(Buf->file));
83
 
        }
84
 
      else {
85
 
          Buf->file.matrix[irrep] = Buf->matrix[irrep];
86
 
          dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
87
 
        }
88
 
      
89
 
      break;
90
 
  case 21: /* Pack pq; no change in rs */
91
 
      /* Prepare the output buffer for the output DPD file */
92
 
      dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
93
 
 
94
 
      p = Buf->file.params->roworb[irrep][pq][0];
95
 
      q = Buf->file.params->roworb[irrep][pq][1];
96
 
      filepq = Buf->file.params->rowidx[p][q];
97
 
 
98
 
      filerow = Buf->file.incore ? filepq : 0;
99
 
 
100
 
      /* Loop over the columns in the dpdbuf */
101
 
      for(rs=0; rs < coltot; rs++) {
102
 
          bufrs = rs;
103
 
 
104
 
          value = Buf->matrix[irrep][0][bufrs];
105
 
 
106
 
          /* Assign the value */
107
 
          Buf->file.matrix[irrep][filerow][rs] = value;
108
 
        }
109
 
 
110
 
      /* Write out the row */
111
 
      dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, filepq);
112
 
 
113
 
      /* Close the input buffer */
114
 
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
115
 
 
116
 
      break;
117
 
  case 23: /* Unpack pq; no change in rs */
118
 
      /* I don't know if I'll ever use this, so I'll avoid it for now */
119
 
      fprintf(stderr, "\n\tShould you be using method %d?\n", method);
120
 
      exit(PSI_RETURN_FAILURE);
121
 
 
122
 
      break;
123
 
  case 31: /* No change in pq; pack rs */
124
 
      /* Prepare the output buffer for the output DPD file */
125
 
      dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
126
 
 
127
 
      filerow = Buf->file.incore ? pq : 0;
128
 
 
129
 
      /* Loop over the columns in the dpdfile */
130
 
      for(rs=0; rs < coltot; rs++) {
131
 
          r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
132
 
          s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
133
 
          bufrs = Buf->params->colidx[r][s];
134
 
 
135
 
          value = Buf->matrix[irrep][0][bufrs];
136
 
 
137
 
          /* Assign the value */
138
 
          Buf->file.matrix[irrep][filerow][rs] = value;
139
 
        }
140
 
 
141
 
      /* Write out the row */
142
 
      dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, pq);
143
 
 
144
 
      /* Close the input buffer */
145
 
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
146
 
 
147
 
      break;
148
 
  case 33: /* No change in pq; unpack rs */
149
 
      /* I'm not sure if I'll ever need this, so I'm removing it for now */
150
 
      fprintf(stderr, "\n\tShould you be using method %d?\n", method);
151
 
      exit(PSI_RETURN_FAILURE);
152
 
 
153
 
      break;
154
 
  case 41: /* Pack pq and rs */
155
 
      /* Prepare the output buffer for the output DPD file */
156
 
      dpd_file4_mat_irrep_row_init(&(Buf->file), irrep);
157
 
 
158
 
      p = Buf->file.params->roworb[irrep][pq][0];
159
 
      q = Buf->file.params->roworb[irrep][pq][1];
160
 
      filepq = Buf->file.params->rowidx[p][q];
161
 
 
162
 
      filerow = Buf->file.incore ? filepq : 0;
163
 
 
164
 
 
165
 
      /* Loop over the columns in the dpdfile */
166
 
      for(rs=0; rs < coltot; rs++) {
167
 
          r = Buf->file.params->colorb[irrep^all_buf_irrep][rs][0];
168
 
          s = Buf->file.params->colorb[irrep^all_buf_irrep][rs][1];
169
 
          bufrs = Buf->params->colidx[r][s];
170
 
 
171
 
          value = Buf->matrix[irrep][0][bufrs];
172
 
 
173
 
          /* Assign the value */
174
 
          Buf->file.matrix[irrep][filerow][rs] = value;
175
 
        }
176
 
 
177
 
      /* Write out the row */
178
 
      dpd_file4_mat_irrep_row_wrt(&(Buf->file), irrep, filepq);
179
 
 
180
 
      /* Close the input buffer */
181
 
      dpd_file4_mat_irrep_row_close(&(Buf->file), irrep);
182
 
 
183
 
      break;
184
 
  case 42: /* Pack pq; unpack rs */
185
 
      fprintf(stderr, "\n\tHaven't programmed method 42 yet!\n");
186
 
      exit(PSI_RETURN_FAILURE);
187
 
 
188
 
      break;
189
 
  case 43: /* Unpack pq; pack rs */
190
 
      fprintf(stderr, "\n\tHaven't programmed method 43 yet!\n");
191
 
      exit(PSI_RETURN_FAILURE);
192
 
 
193
 
      break;
194
 
  case 45: /* Unpack pq and rs */
195
 
      /* I'm not sure if I'll ever need this, so I'm removing it for now */
196
 
      fprintf(stderr, "\n\tShould you be using method %d?\n", method);
197
 
      exit(PSI_RETURN_FAILURE);
198
 
 
199
 
      break;
200
 
  default:  /* Error trapping */
201
 
      fprintf(stderr, "\n\tInvalid switch case in dpd_buf_mat_irrep_rd!\n");
202
 
      exit(PSI_RETURN_FAILURE);
203
 
      break;
204
 
    }
205
 
  
206
 
  return 0;
207
 
 
208
 
}