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

« back to all changes in this revision

Viewing changes to src/bin/cceom/amp_write.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 <math.h>
4
 
#include <libdpd/dpd.h>
5
 
 
6
 
struct onestack {
7
 
    double value;
8
 
    int i;
9
 
    int a;
10
 
};
11
 
 
12
 
struct twostack {
13
 
    double value;
14
 
    int i; int j;
15
 
    int a; int b;
16
 
};
17
 
 
18
 
void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen);
19
 
void twostack_insert(struct twostack *stack, double value, int i, int j, int a, int b, 
20
 
                     int level, int stacklen);
21
 
 
22
 
void amp_write_T1(dpdfile2 *T1, int length, FILE *outfile)
23
 
{
24
 
  int m, h, nirreps, Gia;
25
 
  int i, I, a, A, numt1;
26
 
  double value;
27
 
  struct onestack *t1stack;
28
 
 
29
 
  nirreps = T1->params->nirreps;
30
 
  Gia = T1->my_irrep;
31
 
 
32
 
  t1stack = (struct onestack *) malloc(length * sizeof(struct onestack));
33
 
  for(m=0; m < length; m++) { t1stack[m].value = 0; t1stack[m].i = 0; t1stack[m].a = 0; }
34
 
 
35
 
  dpd_file2_mat_init(T1);
36
 
  dpd_file2_mat_rd(T1);
37
 
 
38
 
  numt1 = 0;
39
 
  for(h=0; h < nirreps; h++) {
40
 
 
41
 
    numt1 += T1->params->rowtot[h] * T1->params->coltot[h^Gia];
42
 
 
43
 
    for(i=0; i < T1->params->rowtot[h]; i++) {
44
 
      I = T1->params->roworb[h][i];
45
 
      for(a=0; a < T1->params->coltot[h^Gia]; a++) {
46
 
        A = T1->params->colorb[h^Gia][a];
47
 
        value = T1->matrix[h][i][a];
48
 
        for(m=0; m < length; m++) {
49
 
          if((fabs(value) - fabs(t1stack[m].value)) > 1e-12) {
50
 
            onestack_insert(t1stack, value, I, A, m, length);
51
 
            break;
52
 
          }
53
 
        }
54
 
      }
55
 
    }
56
 
  }
57
 
 
58
 
  dpd_file2_mat_close(T1);
59
 
 
60
 
  for(m=0; m < ((numt1 < length) ? numt1 : length); m++)
61
 
    if(fabs(t1stack[m].value) > 1e-6)
62
 
      fprintf(outfile, "\t        %3d %3d %20.10f\n", t1stack[m].i, t1stack[m].a, t1stack[m].value);
63
 
 
64
 
  free(t1stack);
65
 
}
66
 
 
67
 
void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen)
68
 
{
69
 
  int l;
70
 
  struct onestack temp;
71
 
 
72
 
  temp = stack[level];
73
 
 
74
 
  stack[level].value = value;
75
 
  stack[level].i = i;
76
 
  stack[level].a = a;
77
 
 
78
 
  value = temp.value;
79
 
  i = temp.i;
80
 
  a = temp.a;
81
 
 
82
 
  for(l=level; l < stacklen-1; l++) {
83
 
    temp = stack[l+1];
84
 
 
85
 
    stack[l+1].value = value;
86
 
    stack[l+1].i = i;
87
 
    stack[l+1].a = a;
88
 
 
89
 
    value = temp.value;
90
 
    i = temp.i;
91
 
    a = temp.a;
92
 
  }
93
 
}
94
 
 
95
 
void amp_write_T2(dpdbuf4 *T2, int length, FILE *outfile)
96
 
{
97
 
  int m, h, nirreps, Gijab, numt2;
98
 
  int ij, ab, i, j, a, b;
99
 
  double value;
100
 
  struct twostack *t2stack;
101
 
 
102
 
  nirreps = T2->params->nirreps;
103
 
  Gijab = T2->file.my_irrep;
104
 
 
105
 
  t2stack = (struct twostack *) malloc(length * sizeof(struct twostack));
106
 
  for(m=0; m < length; m++) { 
107
 
    t2stack[m].value = 0; 
108
 
    t2stack[m].i = 0; t2stack[m].j = 0;
109
 
    t2stack[m].a = 0; t2stack[m].b = 0;
110
 
  }
111
 
 
112
 
  numt2 = 0;
113
 
  for(h=0; h < nirreps; h++) {
114
 
    dpd_buf4_mat_irrep_init(T2, h);
115
 
    dpd_buf4_mat_irrep_rd(T2, h);
116
 
 
117
 
    numt2 += T2->params->rowtot[h] * T2->params->coltot[h^Gijab];
118
 
 
119
 
    for(ij=0; ij < T2->params->rowtot[h]; ij++) {
120
 
      i = T2->params->roworb[h][ij][0];
121
 
      j = T2->params->roworb[h][ij][1];
122
 
      for(ab=0; ab < T2->params->coltot[h^Gijab]; ab++) {
123
 
        a = T2->params->colorb[h^Gijab][ab][0];
124
 
        b = T2->params->colorb[h^Gijab][ab][1];
125
 
 
126
 
        value = T2->matrix[h][ij][ab];
127
 
 
128
 
        for(m=0; m < length; m++) {
129
 
          if((fabs(value) - fabs(t2stack[m].value)) > 1e-12) {
130
 
            twostack_insert(t2stack, value, i, j, a, b, m, length);
131
 
            break;
132
 
          }
133
 
        }
134
 
      }
135
 
    }
136
 
 
137
 
    dpd_buf4_mat_irrep_close(T2, h);
138
 
  }
139
 
 
140
 
  for(m=0; m < ((numt2 < length) ? numt2 : length); m++)
141
 
    if(fabs(t2stack[m].value) > 1e-6)
142
 
      fprintf(outfile, "\t%3d %3d %3d %3d %20.10f\n", t2stack[m].i, t2stack[m].j, 
143
 
              t2stack[m].a, t2stack[m].b, t2stack[m].value);
144
 
 
145
 
  free(t2stack);
146
 
}
147
 
 
148
 
void twostack_insert(struct twostack *stack, double value, int i, int j, int a, int b, 
149
 
                     int level, int stacklen)
150
 
{
151
 
  int l;
152
 
  struct twostack temp;
153
 
 
154
 
  temp = stack[level];
155
 
 
156
 
  stack[level].value = value;
157
 
  stack[level].i = i;
158
 
  stack[level].j = j;
159
 
  stack[level].a = a;
160
 
  stack[level].b = b;
161
 
 
162
 
  value = temp.value;
163
 
  i = temp.i;
164
 
  j = temp.j;
165
 
  a = temp.a;
166
 
  b = temp.b;
167
 
 
168
 
  for(l=level; l < stacklen-1; l++) {
169
 
    temp = stack[l+1];
170
 
 
171
 
    stack[l+1].value = value;
172
 
    stack[l+1].i = i;
173
 
    stack[l+1].j = j;
174
 
    stack[l+1].a = a;
175
 
    stack[l+1].b = b;
176
 
 
177
 
    value = temp.value;
178
 
    i = temp.i;
179
 
    j = temp.j;
180
 
    a = temp.a;
181
 
    b = temp.b;
182
 
  }
183
 
}
184