github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/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 // fortran64 is a float64 type that prints as a double precision constant in 15 // Fortran format. 16 type fortran64 float64 //nolint:unused 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 //nolint:deadcode,unused 28 func printFortranArray(z []float64, name string) { 29 fmt.Printf("%s(1:%d) = (/%v, &\n", name, len(z), fortran64(z[0])) 30 for i := 1; i < len(z)-1; i++ { 31 fmt.Printf("%v, &\n", fortran64(z[i])) 32 } 33 fmt.Printf("%s/)\n", fortran64(z[len(z)-1])) 34 }