github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/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 // fortran64 is a float64 type that prints as a double precision constant in 15 // Fortran format. 16 type fortran64 float64 17 18 func (f fortran64) String() string { 19 // Replace exponent with D 20 s := fmt.Sprintf("%0.16E", f) 21 s = strings.Replace(s, "E", "D", 1) 22 return s 23 } 24 25 // printFortranArray prints a Go slice as an array that can be copied into a 26 // fortran script. 27 func printFortranArray(z []float64, name string) { 28 fmt.Printf("%s(1:%d) = (/%v, &\n", name, len(z), fortran64(z[0])) 29 for i := 1; i < len(z)-1; i++ { 30 fmt.Printf("%v, &\n", fortran64(z[i])) 31 } 32 fmt.Printf("%s/)\n", fortran64(z[len(z)-1])) 33 }