Giter VIP home page Giter VIP logo

fortranio.jl's Introduction

FortanIO.jl

Fortran binary (unformatted) file input/output for Julia.

Example

Assume we have some fortran code like the following that saves out data to data.bin.

    integer*8 :: x(100)
    real*8 :: y(100)
    
    ! ... code that calculates something in x and y ...

    open(unit=9, file="data.bin", form="unformatted")
    write(9) x
    write(9) y
    close(9)

This can be read into julia as follows:

    load("FortranIO")
    f = open("data.bin")
    x = FortranIO.read_record_array(f, Int64)
    y = FortranIO.read_record_array(f, Float64)
    close(f)

An array of the appropriate size is returned by FortranIO.read_record_array.

If, instead of two separate calls to write in the fortran code above, a single call had been used:

    write(9) x, y

Then, the values can be loaded in julia using

    FortranIO.read_record(f, Array(Int64,100), Array(Float64,100))

Values can also be written:

    f = open("file.bin", "w")
    # Write a record containing one Int64
    FortranIO.write_record(f, 10)
    # Write a second record containing several values of different types
    FortranIO.write_record(f, [1,2,3], int32(4), 5.0)
    close(f)

TODO

Handle strings

fortranio.jl's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.