gonum.org/v1/gonum@v0.14.0/lapack/testlapack/fortran.go (about) 1 // Copyright ©2015 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testlapack 6 7 import ( 8 "fmt" 9 "strings" 10 ) 11 12 // This file implements types for helping to convert to Fortran testing capabilities. 13 14 //lint:file-ignore U1000 A number of functions are here that may be used in future. 15 16 // fortran64 is a float64 type that prints as a double precision constant in 17 // Fortran format. 18 type fortran64 float64 19 20 func (f fortran64) String() string { 21 // Replace exponent with D 22 s := fmt.Sprintf("%0.16E", f) 23 s = strings.Replace(s, "E", "D", 1) 24 return s 25 } 26 27 // printFortranArray prints a Go slice as an array that can be copied into a 28 // fortran script. 29 func printFortranArray(z []float64, name string) { 30 fmt.Printf("%s(1:%d) = (/%v, &\n", name, len(z), fortran64(z[0])) 31 for i := 1; i < len(z)-1; i++ { 32 fmt.Printf("%v, &\n", fortran64(z[i])) 33 } 34 fmt.Printf("%s/)\n", fortran64(z[len(z)-1])) 35 }