-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgnuplot.c
More file actions
209 lines (173 loc) · 5.22 KB
/
gnuplot.c
File metadata and controls
209 lines (173 loc) · 5.22 KB
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
#include <stdio.h>
#include <math.h>
#include "gnuplot.h"
#include "func.h"
#include "config.h"
char *plot_name (char *name, double tau, double h1, double h2, int t)
{
//sprintf(name, "../plotdata/th%02d%02d/level%d.log", (int)(tau*100), (int)(h*100), t);
sprintf (name, "t%02dh%02dh%02dl%d.log", (int) (tau * 100), (int) (h1 * 100), (int) (h2 * 100), t);
//printf("%s", name);
return name;
}
char *tex_name (char *name, double tau, double h1, double h2, int t)
{
//sprintf(name, "../plotdata/th%02d%02d/level%d.tex", (int)(tau*100), (int)(h*100), t);
sprintf (name, "t%02dh%02dh%02dl%d.tex", (int) (tau * 100), (int) (h1 * 100), (int) (h2 * 100), t);
return name;
}
void print_plot (const char *file_name, double *X, double *Y,
double *G, double *V1, double *V2,
int size, double tt)
{
FILE *fp;
int i;
if (!file_name)
{
printf ("Incorrect filename by time %lf\n", tt);
}
if (! (fp = fopen (file_name, "w+")))
{
printf ("Cannot create file %s\n", file_name);
return;
}
for (i = 0; i < size; i++)
{
//printf("%i \n", i);
fprintf (fp, "%f %f %f %f %f\n", Y[i], X[i], V2[i], V1[i], exp (G[i]));
if ( i < size - 1 && fabs (Y[i] - Y[i + 1]) > 1e-6)
{
fprintf (fp, "\n");
}
}
fclose (fp);
}
void print_data (const char *file_name, double *G, double *V1, double *V2, int size)
{
FILE *fp;
int i;
if (!file_name)
{
printf ("Incorrect filename\n");
}
if (! (fp = fopen (file_name, "w")))
{
printf ("Cannot create file %s\n", file_name);
return;
}
fprintf (fp, "%d \n", size);
for (i = 0; i < size; i++)
{
fprintf (fp, "%lf ", G[i]);
}
fprintf (fp, "\n");
for (i = 0; i < size; i++)
{
fprintf (fp, "%lf ", V1[i]);
}
fprintf (fp, "\n");
for (i = 0; i < size; i++)
{
fprintf (fp, "%lf ", V2[i]);
}
fprintf (fp, "\n");
fclose (fp);
}
int make_graph (const char *texname, const char *plotname, double h1, double h2, double tau, double t)
{
FILE *fout;
if ((fout = fopen (texname, "w")))
{
fprintf (fout, "\\begin{minipage}{\\linewidth}\n"
"\\centering\n");
if (h1 > 0.)
fprintf (fout,
"$\\tau = %1.3f$, $h = \\left(%1.3f, %1.3f\\right)$, $t = %1.3f$\n\n\n",
tau, h1, h2, t);
fprintf (fout,
"\\begin{minipage}{0.49 \\linewidth}\n"
"\\begin{figure}[H]\n"
"\\begin{gnuplot}\n"
"set terminal epslatex color size 7cm,7cm\n"
"set size ratio 1\n"
"set xrange [0:3]\n"
"set yrange [0:3]\n"
"set xlabel \"X\" font ',18'\n"
"set ylabel \"Y\" offset 1,0 font ',18'\n"
"unset key\n"
"set colorbox\n"
"load 'paired.plt'\n"
"plot '%s' every 4:4 using 2:1:($4/(4*sqrt($4*$4+$3*$3))):"
"($3/(4*sqrt($4*$4+$3*$3))):(sqrt($4*$4+$3*$3)) "
"with vectors filled lc palette title ' '\n"
"\\end{gnuplot}\n"
"\\caption{Скорость}\n"
"\\end{figure}\n"
"\\end{minipage}\n"
"\\hfill\n"
"\\begin{minipage}{0.49\\linewidth}\n"
"\\begin{figure}[H]\n"
"\\begin{gnuplot}\n"
"set terminal epslatex color size 9cm,9cm\n"
"set size ratio 1\n"
"set xrange [0:3]\n"
"set yrange [0:3]\n"
"set xlabel \"X\" font ',18'\n"
"set ylabel \"Y\" offset 1,0 font ',18'\n"
///"unset colorbox\n"
"set view equal xy\n"
"set view 0, 0\n"
"unset ztics\n"
"splot '%s' using 2:1:5 with pm3d at b t ' ' \n"
"\\end{gnuplot}\n"
"\\caption{Плотность}\n"
"\\end{figure}\n"
"\\end{minipage}\n"
"\\end{minipage}\n"
"\\vspace{1cm}\n", plotname,
plotname);
}
else
{
printf ("Can't open file %s\n", texname);
return -1;
}
fclose (fout);
if (calc_type == SMOOTH)
{
fout = fopen (OUTTEX_SMOOTH, "a+");
}
else
{
fout = fopen (OUTTEX_ABRUPT, "a+");
}
if (fout != NULL)
{
fprintf (fout, "\\input{%s} \n", texname);
}
else
{
printf ("Can't open OUTTEX file\n");
return -1;
}
fclose (fout);
return 0;
}
void printhead (FILE *fout)
{
fprintf (fout, "\\documentclass[a4paper, 12pt]{article} \n");
fprintf (fout, "\\usepackage[utf8]{inputenc} \n");
fprintf (fout, "\\usepackage[left=1cm,right=1cm,top=2cm,bottom=2cm,"
"bindingoffset=0cm]{geometry} \n");
fprintf (fout, "\\usepackage[english,russian]{babel} \n");
fprintf (fout, "\\usepackage{amsmath,amssymb,amsfonts,textcomp,latexsym,"
"pb-diagram,amsopn} \n");
fprintf (fout, "\\usepackage{cite,enumerate,float,indentfirst} \n");
fprintf (fout, "\\usepackage{graphicx,xcolor} \n");
fprintf (fout, "\\usepackage{gnuplottex} \n");
fprintf (fout, "\\begin{document} \n");
}
void printtail (FILE *fout)
{
fprintf (fout, "\\end{document} \n");
}