-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.c
94 lines (65 loc) · 2.28 KB
/
io.c
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
#include "definitions.h"
#include "functions.h"
#include "global_vars.h"
#include "model_definitions.h"
#include "model_functions.h"
#include "model_global_vars.h"
#include <fftw3.h>
#include <stdlib.h>
#include <math.h>
void write_fft_file(double *freq, double *out, double TIME_INIT){
struct stat st = {0};
char folder[64] = "output";
char filename[256] = "";
if (stat(folder, &st) == -1) {
mkdir(folder, 0700);
}
fprintf(stderr,"%d\n",(int)TIME_INIT);
sprintf(filename, "%s/FFT_%d.dat", folder,(int)TIME_INIT);
FILE *specfile = fopen(filename, "w");
for(int i=0;i<UNI2/2;i++){
fprintf(specfile, "%+.15e %+.15e\n",freq[i], out[i]);
}
fclose(specfile);
}
void write_spec_file(double *spec,double TIME_INIT){
struct stat st = {0};
char folder[64] = "output";
char filename[256] = "";
if (stat(folder, &st) == -1) {
mkdir(folder, 0700);
}
fprintf(stderr,"%d\n",(int)TIME_INIT);
sprintf(filename, "%s/spec_%d.dat", folder,(int)TIME_INIT);
int lfac_dec=10;
int Ndec=4;
double lfac_min = 1.e-3;
double dlfac;
int Nlfac=(Ndec*lfac_dec);
// dlfac = (lfac_max-lfac_min)/(1.0*Nlfac);
FILE *specfile = fopen(filename, "w");
for(int i=0;i<Nlfac;i++){
dlfac = lfac_min*pow(10,((double)(i+1))/lfac_dec) - lfac_min*pow(10,((double)(i))/lfac_dec);
fprintf(specfile,"%e %e\n",lfac_min*pow(10,(double)i/lfac_dec)+dlfac/2.,(double)spec[i]);
// fprintf(stderr,"%e\n",lfac_min*pow(10,(double)i/lfac_dec)+dlfac/2.);
// fprintf(specfile,"%e %e\n",lfac_min+i*dlfac,spec[i]);
}
fclose(specfile);
}
void write_profile_file(double *out, char* param,double TIME_INIT){
double X;
struct stat st = {0};
char folder[64] = "output";
char filename[256] = "";
if (stat(folder, &st) == -1) {
mkdir(folder, 0700);
}
fprintf(stderr,"%d\n",(int)TIME_INIT);
sprintf(filename, "%s/profile_%s_%d.dat", folder,param,(int)TIME_INIT);
FILE *specfile = fopen(filename, "w");
for(int i=0;i<UNI1;i++){
X=XMIN + i * (XMAX-XMIN)/((double)UNI1);
fprintf(specfile,"%e %e\n",X,out[i]);
}
fclose(specfile);
}