00001
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <math.h>
00008 #include <libdpd/dpd.h>
00009
00010 namespace psi { namespace cis {
00011
00012 struct onestack {
00013 double value;
00014 int i;
00015 int a;
00016 };
00017
00018 void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen);
00019
00020 void amp_write_T1(dpdfile2 *T1, int length, FILE *outfile)
00021 {
00022 int m, h, nirreps, Gia;
00023 int i, I, a, A, numt1;
00024 double value;
00025 struct onestack *t1stack;
00026
00027 nirreps = T1->params->nirreps;
00028 Gia = T1->my_irrep;
00029
00030 t1stack = (struct onestack *) malloc(length * sizeof(struct onestack));
00031 for(m=0; m < length; m++) { t1stack[m].value = 0; t1stack[m].i = 0; t1stack[m].a = 0; }
00032
00033 dpd_file2_mat_init(T1);
00034 dpd_file2_mat_rd(T1);
00035
00036 numt1 = 0;
00037 for(h=0; h < nirreps; h++) {
00038
00039 numt1 += T1->params->rowtot[h] * T1->params->coltot[h^Gia];
00040
00041 for(i=0; i < T1->params->rowtot[h]; i++) {
00042 I = T1->params->roworb[h][i];
00043 for(a=0; a < T1->params->coltot[h^Gia]; a++) {
00044 A = T1->params->colorb[h][a];
00045 value = T1->matrix[h][i][a];
00046 for(m=0; m < length; m++) {
00047 if((fabs(value) - fabs(t1stack[m].value)) > 1e-12) {
00048 onestack_insert(t1stack, value, I, A, m, length);
00049 break;
00050 }
00051 }
00052 }
00053 }
00054 }
00055
00056 dpd_file2_mat_close(T1);
00057
00058 for(m=0; m < ((numt1 < length) ? numt1 : length); m++)
00059 if(fabs(t1stack[m].value) > 1e-6)
00060 fprintf(outfile, "\t %3d %3d %20.10f\n", t1stack[m].i, t1stack[m].a, t1stack[m].value);
00061
00062 free(t1stack);
00063 }
00064
00065 void onestack_insert(struct onestack *stack, double value, int i, int a, int level, int stacklen)
00066 {
00067 int l;
00068 struct onestack temp;
00069
00070 temp = stack[level];
00071
00072 stack[level].value = value;
00073 stack[level].i = i;
00074 stack[level].a = a;
00075
00076 value = temp.value;
00077 i = temp.i;
00078 a = temp.a;
00079
00080 for(l=level; l < stacklen-1; l++) {
00081 temp = stack[l+1];
00082
00083 stack[l+1].value = value;
00084 stack[l+1].i = i;
00085 stack[l+1].a = a;
00086
00087 value = temp.value;
00088 i = temp.i;
00089 a = temp.a;
00090 }
00091 }
00092
00093
00094 }}