plotting yahoo

This commit is contained in:
antonl 2026-03-18 15:16:21 +01:00
parent 470033c01e
commit d1c5ba8b29
4 changed files with 135 additions and 5 deletions

View File

@ -8,7 +8,8 @@ if "%~1"=="run" (
pushd build pushd build
del /F /Q * del /F /Q *
odin %buildcmd% ../src/ -keep-executable -out:femodin.exe popd build
odin %buildcmd% src/ -keep-executable -out:build/femodin.exe
popd

101
output/test.dat Normal file
View File

@ -0,0 +1,101 @@
0.000 0.000
0.010 0.005
0.020 0.010
0.030 0.015
0.040 0.020
0.050 0.025
0.060 0.030
0.070 0.035
0.080 0.040
0.090 0.045
0.100 0.050
0.110 0.055
0.120 0.060
0.130 0.065
0.140 0.070
0.150 0.075
0.160 0.080
0.170 0.085
0.180 0.090
0.190 0.095
0.200 0.100
0.210 0.105
0.220 0.110
0.230 0.115
0.240 0.120
0.250 0.125
0.260 0.130
0.270 0.135
0.280 0.140
0.290 0.145
0.300 0.150
0.310 0.155
0.320 0.160
0.330 0.165
0.340 0.170
0.350 0.175
0.360 0.180
0.370 0.185
0.380 0.190
0.390 0.195
0.400 0.200
0.410 0.205
0.420 0.210
0.430 0.215
0.440 0.220
0.450 0.225
0.460 0.230
0.470 0.235
0.480 0.240
0.490 0.245
0.500 0.250
0.510 0.255
0.520 0.260
0.530 0.265
0.540 0.270
0.550 0.275
0.560 0.280
0.570 0.285
0.580 0.290
0.590 0.295
0.600 0.300
0.610 0.305
0.620 0.310
0.630 0.315
0.640 0.320
0.650 0.325
0.660 0.330
0.670 0.335
0.680 0.340
0.690 0.345
0.700 0.350
0.710 0.355
0.720 0.360
0.730 0.365
0.740 0.370
0.750 0.375
0.760 0.380
0.770 0.385
0.780 0.390
0.790 0.395
0.800 0.400
0.810 0.405
0.820 0.410
0.830 0.415
0.840 0.420
0.850 0.425
0.860 0.430
0.870 0.435
0.880 0.440
0.890 0.445
0.900 0.450
0.910 0.455
0.920 0.460
0.930 0.465
0.940 0.470
0.950 0.475
0.960 0.480
0.970 0.485
0.980 0.490
0.990 0.495
1.000 0.500

4
plot.bat Normal file
View File

@ -0,0 +1,4 @@
set PLOTNAME=%~1
gnuplot -p -e "set grid; plot 'output/%PLOTNAME%' with linespoints pt 13"

View File

@ -1,14 +1,12 @@
package main package main
import "core:fmt" import "core:fmt"
import "core:os"
// -------------------------------------------------------------------------------------// // -------------------------------------------------------------------------------------//
// We use the built in array for general vectors // We use the built in array for general vectors
VecF32 :: []f32 VecF32 :: []f32
vec_make_f32 :: proc(n: i32, allocator := context.allocator) -> VecF32 {
return make([]f32, n, allocator)
}
// But we need our custom format for matrices. // But we need our custom format for matrices.
// We will use col-major storage. // We will use col-major storage.
@ -18,6 +16,28 @@ MatF32 :: struct {
cols: i32, cols: i32,
} }
// -------------------------------------------------------------------------------------//
plot_xy_f32 :: proc(x: []f32, y: []f32, fname: string) {
f, err := os.create(fname)
if err != nil {
fmt.println("Error creating file", fname)
return
}
defer os.close(f)
for i in 0 ..< len(x) {
fmt.fprintf(f, "%f %f\n", x[i], y[i])
}
fmt.println("Wrote ", fname)
return
}
vec_make_f32 :: proc(n: i32, allocator := context.allocator) -> VecF32 {
return make([]f32, n, allocator)
}
mat_make_f32 :: proc(nrows: i32, ncols: i32, allocator := context.allocator) -> MatF32 { mat_make_f32 :: proc(nrows: i32, ncols: i32, allocator := context.allocator) -> MatF32 {
out: MatF32 out: MatF32
out.data = make([]f32, nrows * ncols, allocator) out.data = make([]f32, nrows * ncols, allocator)
@ -48,10 +68,14 @@ main :: proc() {
dx := (x_end - x_start) / cast(f32)num_elements dx := (x_end - x_start) / cast(f32)num_elements
x_axis := vec_make_f32(num_nodes) x_axis := vec_make_f32(num_nodes)
y := vec_make_f32(cast(i32)len(x_axis))
for i in 0 ..< num_nodes { for i in 0 ..< num_nodes {
x_axis[i] = cast(f32)i * (dx) x_axis[i] = cast(f32)i * (dx)
y[i] = 0.5 * cast(f32)i * dx
} }
plot_xy_f32(x_axis, y, "output/test.dat")
} }