Created
July 22, 2019 01:02
-
-
Save oxtoacart/9e7c339001ddb44a802bd124124c487b to your computer and use it in GitHub Desktop.
Utility to convert oratory1990's CSV measurements to a Room EQ Wizard compatible format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This program converts csv measurements from oratory1990 into a format | |
// suitable for importing into Room EQ Wizard, with SPL normalized to 90dB. | |
package main | |
import ( | |
"os" | |
"io" | |
"encoding/csv" | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
if len(os.Args) < 2 { | |
fmt.Fprintln(os.Stderr, "Please specify the name(s) of one or more input files") | |
os.Exit(1) | |
} | |
for i:=1;i<len(os.Args);i++ { | |
filename := os.Args[i] | |
in, err := os.Open(filename) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "Error opening input file %v: %v\n", filename, err) | |
os.Exit(2) | |
} | |
defer in.Close() | |
out, err := os.Create(fmt.Sprintf("%v.txt", filename)) | |
if err != nil{ | |
fmt.Fprintf(os.Stderr, "Unable to create out file: %v\n", err) | |
os.Exit(3) | |
} | |
defer out.Close() | |
csvIn := csv.NewReader(in) | |
csvIn.Comma = ';' | |
csvOut := csv.NewWriter(out) | |
csvOut.Comma = '\t' | |
defer csvOut.Flush() | |
for { | |
line, err := csvIn.Read() | |
if err == io.EOF { | |
break | |
} | |
if len(line) == 2 { | |
freq, err := strconv.ParseFloat(strings.Replace(line[0], ",", ".", -1), 64) | |
if err != nil { | |
continue | |
} | |
db, err := strconv.ParseFloat(strings.Replace(line[1], ",", ".", -1), 64) | |
if err != nil { | |
continue | |
} | |
if err := csvOut.Write([]string{fmt.Sprint(freq), fmt.Sprint(db+90)}); err != nil { | |
fmt.Fprintf(os.Stderr, "Unable to write to out: %v", err) | |
os.Exit(4) | |
} | |
} | |
} | |
fmt.Fprintf(os.Stderr, "Wrote to %v.txt\n", filename) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment