Transpiling fortran code to golang code

f4go

Build Status Go Report Card codecov GitHub license GoDoc Maintainability

Example of use

> # Install golang
> # Compile f4go
> go get -u github.com/Konstantin8105/f4go
> cd $GOPATH/src/github.com/Konstantin8105/f4go
> go build
> ./f4go ./testdata/blas/caxpy.f
> # Look on Go result source
> less ./testdata/blas/caxpy.go

Transpiling fortran code to golang code

Present result:

*> \brief \b CAXPY
*
*  =========== DOCUMENTATION ===========
*
* Online html documentation available at
*            http://www.netlib.org/lapack/explore-html/
*
*  Definition:
*  ===========
*
*       SUBROUTINE CAXPY(N,CA,CX,INCX,CY,INCY)
*
*       .. Scalar Arguments ..
*       COMPLEX CA
*       INTEGER INCX,INCY,N
*       ..
*       .. Array Arguments ..
*       COMPLEX CX(*),CY(*)
*       ..
*
*
*> \par Purpose:
*  =============
*>
*> \verbatim
*>
*>    CAXPY constant times a vector plus a vector.
*> \endverbatim
*
*  Arguments:
*  ==========
*
*> \param[in] N
*> \verbatim
*>          N is INTEGER
*>         number of elements in input vector(s)
*> \endverbatim
*>
*> \param[in] CA
*> \verbatim
*>          CA is COMPLEX
*>           On entry, CA specifies the scalar alpha.
*> \endverbatim
*>
*> \param[in] CX
*> \verbatim
*>          CX is COMPLEX array, dimension ( 1 + ( N - 1 )*abs( INCX ) )
*> \endverbatim
*>
*> \param[in] INCX
*> \verbatim
*>          INCX is INTEGER
*>         storage spacing between elements of CX
*> \endverbatim
*>
*> \param[in,out] CY
*> \verbatim
*>          CY is COMPLEX array, dimension ( 1 + ( N - 1 )*abs( INCY ) )
*> \endverbatim
*>
*> \param[in] INCY
*> \verbatim
*>          INCY is INTEGER
*>         storage spacing between elements of CY
*> \endverbatim
*
*  Authors:
*  ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2017
*
*> \ingroup complex_blas_level1
*
*> \par Further Details:
*  =====================
*>
*> \verbatim
*>
*>     jack dongarra, linpack, 3/11/78.
*>     modified 12/3/93, array(1) declarations changed to array(*)
*> \endverbatim
*>
*  =====================================================================
      SUBROUTINE CAXPY(N,CA,CX,INCX,CY,INCY)
*
*  -- Reference BLAS level1 routine (version 3.8.0) --
*  -- Reference BLAS is a software package provided by Univ. of Tennessee,    --
*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*     November 2017
*
*     .. Scalar Arguments ..
      COMPLEX CA
      INTEGER INCX,INCY,N
*     ..
*     .. Array Arguments ..
      COMPLEX CX(*),CY(*)
*     ..
*
*  =====================================================================
*
*     .. Local Scalars ..
      INTEGER I,IX,IY
*     ..
*     .. External Functions ..
      REAL SCABS1
      EXTERNAL SCABS1
*     ..
      IF (N.LE.0) RETURN
      IF (SCABS1(CA).EQ.0.0E+0) RETURN
      IF (INCX.EQ.1 .AND. INCY.EQ.1) THEN
*
*        code for both increments equal to 1
*
         DO I = 1,N
            CY(I) = CY(I) + CA*CX(I)
         END DO
      ELSE
*
*        code for unequal increments or equal increments
*          not equal to 1
*
         IX = 1
         IY = 1
         IF (INCX.LT.0) IX = (-N+1)*INCX + 1
         IF (INCY.LT.0) IY = (-N+1)*INCY + 1
         DO I = 1,N
            CY(IY) = CY(IY) + CA*CX(IX)
            IX = IX + INCX
            IY = IY + INCY
         END DO
      END IF
*
      RETURN
      END

Go code:

package main

//*> \brief \b CAXPY
//*
//*  =========== DOCUMENTATION ===========
//*
//* Online html documentation available at
//*            http://www.netlib.org/lapack/explore-html/
//*
//*  Definition:
//*  ===========
//*
//*       SUBROUTINE CAXPY(N,CA,CX,INCX,CY,INCY)
//*
//*       .. Scalar Arguments ..
//*       COMPLEX CA
//*       INTEGER INCX,INCY,N
//*       ..
//*       .. Array Arguments ..
//*       COMPLEX CX(*),CY(*)
//*       ..
//*
//*
//*> \par Purpose:
//*  =============
//*>
//*> \verbatim
//*>
//*>    CAXPY constant times a vector plus a vector.
//*> \endverbatim
//*
//*  Arguments:
//*  ==========
//*
//*> \param[in] N
//*> \verbatim
//*>          N is INTEGER
//*>         number of elements in input vector(s)
//*> \endverbatim
//*>
//*> \param[in] CA
//*> \verbatim
//*>          CA is COMPLEX
//*>           On entry, CA specifies the scalar alpha.
//*> \endverbatim
//*>
//*> \param[in] CX
//*> \verbatim
//*>          CX is COMPLEX array, dimension ( 1 + ( N - 1 )*abs( INCX ) )
//*> \endverbatim
//*>
//*> \param[in] INCX
//*> \verbatim
//*>          INCX is INTEGER
//*>         storage spacing between elements of CX
//*> \endverbatim
//*>
//*> \param[in,out] CY
//*> \verbatim
//*>          CY is COMPLEX array, dimension ( 1 + ( N - 1 )*abs( INCY ) )
//*> \endverbatim
//*>
//*> \param[in] INCY
//*> \verbatim
//*>          INCY is INTEGER
//*>         storage spacing between elements of CY
//*> \endverbatim
//*
//*  Authors:
//*  ========
//*
//*> \author Univ. of Tennessee
//*> \author Univ. of California Berkeley
//*> \author Univ. of Colorado Denver
//*> \author NAG Ltd.
//*
//*> \date November 2017
//*
//*> \ingroup complex_blas_level1
//*
//*> \par Further Details:
//*  =====================
//*>
//*> \verbatim
//*>
//*>     jack dongarra, linpack, 3/11/78.
//*>     modified 12/3/93, array(1) declarations changed to array(*)
//*> \endverbatim
//*>
//*  =====================================================================
func CAXPY(N *int, CA *complex128, CX *[]complex128, INCX *int, CY *[]complex128, INCY *int) {
	I := new(int)
	IX := new(int)
	IY := new(int)
	//*
	//*  -- Reference BLAS level1 routine (version 3.8.0) --
	//*  -- Reference BLAS is a software package provided by Univ. of Tennessee,    --
	//*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
	//*     November 2017
	//*
	//*     .. Scalar Arguments ..
	//*     ..
	//*     .. Array Arguments ..
	//*     ..
	//*
	//*  =====================================================================
	//*
	//*     .. Local Scalars ..
	//*     ..
	//*     .. External Functions ..
	//*     ..
	if (*(N)) <= 0 {
		return
	}
	if (*SCABS1((CA))) == 0.0e+0 {
		return
	}
	if (*(INCX)) == 1 && (*(INCY)) == 1 {
		//*
		//*        code for both increments equal to 1
		//*
		for (*I) = 1; (*I) <= (*(N)); (*I)++ {
			(*(CY))[(*I)-(1)] = (*(CY))[(*I)-(1)] + (*(CA))*(*(CX))[(*I)-(1)]
		}
	} else {
		//*
		//*        code for unequal increments or equal increments
		//*          not equal to 1
		//*
		(*IX) = 1
		(*IY) = 1
		if (*(INCX)) < 0 {
			(*IX) = (-(*(N))+1)*(*(INCX)) + 1
		}
		if (*(INCY)) < 0 {
			(*IY) = (-(*(N))+1)*(*(INCY)) + 1
		}
		for (*I) = 1; (*I) <= (*(N)); (*I)++ {
			(*(CY))[(*IY)-(1)] = (*(CY))[(*IY)-(1)] + (*(CA))*(*(CX))[(*IX)-(1)]
			(*IX) = (*IX) + (*(INCX))
			(*IY) = (*IY) + (*(INCY))
		}
	}
	//*
	return
}

Notes

Fortran 77 Golang
all arguments of function are pointers ?
all arguments of intrisic function are pointers ?
all internal function variables are pointers ?

IDENT:

  • constants
  • arrays, matrixes

Operations:

  • assign
  • initialization
  • boolean

Fortran test sources

Comments
  • f4go fails to transpile PYTHIA

    f4go fails to transpile PYTHIA

    I tried to transpile a CERN-based FORTRAN77 code used to simulate high energy physics processes:

    • http://home.thep.lu.se/~torbjorn/pythia6/pythia6428.f

    but the transpilation processes failed. here are a couple of the error messages:

    $> curl -O -L http://home.thep.lu.se/~torbjorn/pythia6/pythia6428.f
    $> f4go ./pythia6428.f
    [...]
    pythia6428.f : Parsing error : Cannot identify token in left part separation :, in MIN ( 1e0 , MAX ( PARJ ( 129 ) , ( 2e0 * PARU ( 112 ) / ECM ) ** 2 ) )
    
    [...]
    pythia6428.f : Parsing error : Recover parseStmt pos{{54565 7}}: Not acceptable type : X ( 1 )
    [...]
    

    some of these errors may come from the use of IMPLICIT, though.

  • cleanup f4go. add logging facilities. better intrinsics

    cleanup f4go. add logging facilities. better intrinsics

    Hey, thought you could use some improvements to logging since running f4go in parallel usually spits out too much data to meaningfully process and no trace of which file was being processed when panic happened. Please take a look!

  • Transpiling MYSTRAN to Go

    Transpiling MYSTRAN to Go

    I intend to transpile this Finite Element Analysis program from FORTRAN to Go:

    https://github.com/dr-bill-c/MYSTRAN

    Due to the complexity of MYSTRAN code structure, I have a difficult time to do so. I wonder if there is any example of transpiling a large project from FORTRAN to Go. So that I can refer to the example to get started. Thanks :)

  • Better README - Project Motivation?

    Better README - Project Motivation?

    Hi,

    I just learned that FORTRAN is faster than C code, but I am not sure what is the motivation or goal of this project. Would be nice if the readme file could be updated for clueless people like me!

    Thanks!

  • missing support for EQUIVALENCE statement

    missing support for EQUIVALENCE statement

    hi,

    I was trying out transpiling one last remnant of a FORTRAN dependency from CERN: CERNLIB, and more precisely its ZEBRA library.:

    $> curl -O -L https://raw.githubusercontent.com/root-project/root/master/misc/minicern/src/zebra.f
    $> f4go -p minicern ./zebra.f
    [...]
    Scan: end of postprocessor
               ./zebra.f : Parsing error :  EQUIVALENCE ( CQLETT ( 1 ) , CQALLC ( 1 : 1 ) )
               ./zebra.f : Parsing error :  EQUIVALENCE ( CQNUM ( 1 ) , CQALLC ( 27 : 27 ) )
    [...]
               ./zebra.f : Parsing error :  EQUIVALENCE ( IQTABV ( 1 ) , LQPSTO )
               ./zebra.f : Parsing error :  EQUIVALENCE ( LQRS , LQSYSS ( 7 ) )
    
A compiler from Go to JavaScript for running Go code in a browser

GopherJS - A compiler from Go to JavaScript GopherJS compiles Go code (golang.org) to pure JavaScript code. Its main purpose is to give you the opport

Dec 30, 2022
Grumpy is a Python to Go source code transcompiler and runtime.

Grumpy: Go running Python Overview Grumpy is a Python to Go source code transcompiler and runtime that is intended to be a near drop-in replacement fo

Jan 7, 2023
Transform Go code into it's AST

Welcome to go2ast ?? Transform Go code into it's AST Usage echo "a := 1" | go run main.go Example output []ast.Stmt { &ast.AssignStmt {

Dec 13, 2022
Compile Go regular expressions to Go code

regexp2go regexp2go is an alternate backend for the regexp package that allows to perform ahead-of-time compilation of regular expressions to Go code.

Jul 11, 2022
Syntax-aware Go code search, based on the mvdan/gogrep
Syntax-aware Go code search, based on the mvdan/gogrep

gogrep WIP: this is an attempt to move modified gogrep from the go-ruleguard project, so it can be used outside of the ruleguard as a library. Acknowl

Nov 9, 2022
Golang->Haxe->CPP/CSharp/Java/JavaScript transpiler

TARDIS Go -> Haxe transpiler Haxe -> C++ / C# / Java / JavaScript Project status: a non-working curiosity, development currently on-ice The advent of

Dec 30, 2022
A JavaScript interpreter in Go (golang)

otto -- import "github.com/robertkrimen/otto" Package otto is a JavaScript parser and interpreter written natively in Go. http://godoc.org/github.com/

Jan 2, 2023
A BASIC interpreter written in golang.
A BASIC interpreter written in golang.

05 PRINT "Index" 10 PRINT "GOBASIC!" 20 PRINT "Limitations" Arrays Line Numbers IF Statement DATA / READ Statements Builtin Functions Types 30 PRINT "

Dec 24, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Jan 1, 2023
High-performance PHP-to-Golang IPC bridge

High-performance PHP-to-Golang IPC bridge Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/r

Dec 28, 2022
High-performance PHP application server, load-balancer and process manager written in Golang
High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Dec 30, 2022
Expression evaluation in golang
Expression evaluation in golang

Gval Gval (Go eVALuate) provides support for evaluating arbitrary expressions, in particular Go-like expressions. Evaluate Gval can evaluate expressio

Dec 27, 2022
golang AST matcher

goastch (GO AST matCH) Introduction Inspired by ast matcher. There are four different basic categories of matchers: Node Matchers: Matchers that match

Nov 11, 2022
Scriptable interpreter written in golang
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

Dec 23, 2022
Arbitrary expression evaluation for golang

govaluate Provides support for evaluating arbitrary C-like artithmetic/string expressions. Why can't you just write these expressions in code? Sometim

Jan 2, 2023
hotbuild - a cross platform hot compilation tool for golang
hotbuild - a cross platform hot compilation tool for golang

hotbuild A cross platform hot compilation tool By monitoring the modification of the project directory file, the recompilation and running are automat

Dec 12, 2022
The golang tool of the zig compiler automatically compiles different targets according to the GOOS GOARCH environment variable. You need to install zig.

The golang tool of the zig compiler automatically compiles different targets according to the GOOS GOARCH environment variable. You need to install zig.

Nov 18, 2022
Tgo - Test Helpers for Standard Golang Packages

Test Helpers for Standard Golang Packages see example_test.go go test --- FAIL:

Apr 26, 2022
Logexp - Logical expression compiler for golang

Logical Expression Compiler Functions: - Compile(exp string) - Match(text string

Jan 24, 2022