Save IR plot in same directory as IR file with matching filename

This commit is contained in:
Bastian Bührig
2025-07-11 12:51:04 +02:00
parent 9df7ddbe2d
commit dd21f30a7f

View File

@@ -6,6 +6,7 @@ import (
"math"
"math/cmplx"
"os"
"strings"
"image/png"
@@ -642,8 +643,13 @@ func PlotIR(ir []float64, sampleRate int, irFileName string) error {
p2.Draw(canvases[1][0])
dc.DrawImage(vg.Rectangle{Min: vg.Point{X: 0, Y: 0}, Max: vg.Point{X: width, Y: height}}, imgPlots.Image())
// Save as PNG
f, err = os.Create("ir_plot.png")
// Save as PNG in the same directory as the IR file
irDir := filepath.Dir(irFileName)
irBase := filepath.Base(irFileName)
irNameWithoutExt := strings.TrimSuffix(irBase, filepath.Ext(irBase))
plotFileName := filepath.Join(irDir, irNameWithoutExt+".png")
f, err = os.Create(plotFileName)
if err != nil {
return err
}