File: TRAN_Print.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (238 lines) | stat: -rw-r--r-- 4,255 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <mpi.h>
#include "tran_prototypes.h"

static double eps=1.0e-7;
static int max=500;


void TRAN_Print2_set_eps(double e1)
{
  eps = e1;
  printf("TRAN_Print2 eps changed , eps=%le\n",eps);
}

void TRAN_Print2_set_max(int m1)
{
  max=m1;
  printf("TRAN_Print2 max changed , max=%i\n",max);
}


void TRAN_Print2_dcomplex(char *name, int n1,int n2,dcomplex *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total;

  total=0;
  printf("TRAN_Print2_dcomplex <%s> n=%d %d\n",name,n1,n2);
  for (j=0;j<n2;j++) {
    for (i=0;i<n1;i++) {
      if ( fabs(gc_ref(i,j).r)>eps || fabs(gc_ref(i,j).i)> eps ) {
	printf("%d %d (%le %le)\n", i,j, gc_ref(i,j).r, gc_ref(i,j).i);
	total++;
	if (total > max) { 
	  printf("# of print >max\n");
	  return;
	}
      }
    }
  }

}


void TRAN_Print2_double(char *name, int n1,int n2,double *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total;

  total=0;
  printf("TRAN_Print2_double <%s> n=%d %d\n",name,n1,n2);
  for (j=0;j<n2;j++) {
    for (i=0;i<n1;i++) {
      if (fabs(gc_ref(i,j)) > eps) {
	printf("%d %d %d %le\n", i,j,n1*(j)+i, gc_ref(i,j));
	total++;
	if ( total >max ){
	  printf("# of print >max\n");
	  return;
	}

      }
    }
  }

}

void TRAN_Print2_dx_dcomplex(char *name, int n1,int dx1, int n2,int dx2, dcomplex *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total=0;


  printf("TRAN_Print2_dcomplex <%s> n=%d %d\n",name,n1,n2);
  for (j=0;j<n2;j+=dx2) {
    for (i=0;i<n1;i+=dx1) {
      if ( fabs(gc_ref(i,j).r) > eps || fabs(gc_ref(i,j).i) > eps ) {
	printf("%d %d (%le %le)\n",i,j, gc_ref(i,j).r, gc_ref(i,j).i);
	total++;
	if (total >max) {
	  printf("# of print >max\n");
	  return;
	}
      }
    }
  }

}



void TRAN_Print2_dx_double(char *name, int n1,int dx1,int n2,int dx2,double *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total=0;


  printf("TRAN_Print2_double <%s> n=%d %d\n",name,n1,n2);
  for (j=0;j<n2;j+=dx2) {
    for (i=0;i<n1;i+=dx1) {
      if (fabs(gc_ref(i,j)) > eps ) {
	printf("%d %d %le\n",i,j, gc_ref(i,j));
	total++;
	if (total >max) { 
	  printf("# of print >max\n");
	  return;
	}
      }
    }
  }

}


void TRAN_FPrint2_double(char *name, int n1,int n2,double *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total;
  static int max=10000;
  FILE *fp;

  total=0;
  if ( (fp=fopen(name,"w"))==NULL) {
    printf("can not open %s\nexit\n",name);
    return;
  }
  fprintf(fp,"TRAN_FPrint2_double <%s> n=%d %d\n",name,n1,n2);
  for (j=0;j<n2;j++) {
    for (i=0;i<n1;i++) {
      if (fabs(gc_ref(i,j)) > eps) {
	fprintf(fp,"%d %d %le\n", i,j, gc_ref(i,j));
	total++;
	if ( total >max ){
	  fprintf(fp,"# of print >max\n");
	  return;
	}

      }
    }
  }
  fclose(fp);

}

void TRAN_FPrint2_dcomplex(char *name, int n1,int n2,dcomplex *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total;
  static double eps=1.0e-30;
  FILE *fp;

  total=0;
  if ( (fp=fopen(name,"w"))==NULL) {
    printf("can not open %s\nexit\n",name);
    return;
  }
  fprintf(fp,"TRAN_FPrint2_double <%s> n=%d %d\n",name,n1,n2);
  for (j=0;j<n2;j++) {
    for (i=0;i<n1;i++) {
      if (fabs(gc_ref(i,j).r) > eps || fabs(gc_ref(i,j).i) > eps) {
	fprintf(fp,"%d %d %30.15lf %30.15lf\n", i,j, gc_ref(i,j).r, gc_ref(i,j).i );
	total++;

      }
    }
  }
  fclose(fp);

}



void TRAN_FPrint2_binary_double(FILE *fp, int n1,int n2,double *gc)
#define gc_ref(i,j) gc[ n1*(j)+i ]
{
  int i,j;
  int total;
  static double eps=1.0e-12;
  double *v;
  int    iv[10];
  int i0,i1;
  int count;

  v = (double*)malloc(sizeof(double)*n1);

  i=0;
  iv[i++]=n1;
  iv[i++]=n2;
  fwrite(iv,sizeof(int),2,fp);

  for (j=0;j<n2;j++) { 
    i0=0;
    i1=-1;
    for (i=0;i<n1;i++) {
      if (fabs(gc_ref(i,j)) >eps ) {
	i0=i;
	break;
      }
    }
    for (i=n1-1;i>=0;i--) {
      if (fabs(gc_ref(i,j)) >eps ) {
	i1=i;
	break;
      }
    }
    count=0;
    iv[count++]=j;
    iv[count++]=i0;
    iv[count++]=i1;
    fwrite(iv,sizeof(int),count,fp);

#if 0
    printf("%d of %d, i= [%d: %d]\n",j,n2,i0,i1);
#endif

    if (i0<=i1) {
      for (i=i0;i<=i1;i++) {
        v[i-i0]=gc_ref(i,j);
      }
      fwrite(v,sizeof(double), i1-i0+1, fp);
    }

  }


  free(v);

}