File: fortran.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (35 lines) | stat: -rw-r--r-- 992 bytes parent folder | download
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
35
// 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.

//lint:file-ignore U1000 A number of functions are here that may be used in future.

// fortran64 is a float64 type that prints as a double precision constant in
// Fortran format.
type fortran64 float64

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.
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]))
}