-
Notifications
You must be signed in to change notification settings - Fork 0
/
fortran.go
34 lines (28 loc) · 948 Bytes
/
fortran.go
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
// Copyright ©2015 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package testlapack
import (
"fmt"
"strings"
)
// This file implements types for helping to convert to Fortran testing capabilities.
// fortran64 is a float64 type that prints as a double precision constant in
// Fortran format.
type fortran64 float64 //nolint:unused
func (f fortran64) String() string {
// Replace exponent with D
s := fmt.Sprintf("%0.16E", f)
s = strings.Replace(s, "E", "D", 1)
return s
}
// printFortranArray prints a Go slice as an array that can be copied into a
// fortran script.
//nolint:deadcode,unused
func printFortranArray(z []float64, name string) {
fmt.Printf("%s(1:%d) = (/%v, &\n", name, len(z), fortran64(z[0]))
for i := 1; i < len(z)-1; i++ {
fmt.Printf("%v, &\n", fortran64(z[i]))
}
fmt.Printf("%s/)\n", fortran64(z[len(z)-1]))
}