Coder Social home page Coder Social logo

i-don-t-know-fortran's Introduction

I don't know ForTRAN

This repository will contain chunks of fortran code that will be useful while writing codes.

Here are some useful functions / pieces of code that you would find helpful while using these commands on your projects. Please report any issues / comments on issues section of this repository.

Functions

Check if file exists

Check if a file exists

! DEFINE FEXISTS as LOGICAL
LOGICAL FEXISTS 
INQUIRE (FILE = 'Filename.DAT', EXIST = FEXISTS)
  IF( FEXISTS )THEN

  ELSE

  ENDIF

Conditional debugging in FORTRAN

While debugging the code, we might be interested to debug line by line when certain conditions is met. To do that in visual studio, we need to first create a break point and right click on the break point. The following options will pop up:

Breakpoint Options

Then we can click on Condition and then insert the condition as if we were writing an if statement.

Breakpoint Condition

Open and close files in FORTRAN

To open files in FORTRAN simply use:

OPEN(7, FILE = 'hello.txt', STATUS = 'UNKNOWN')

where 7 = the unique number assigned to the file that is being opened.

To close the files we can simply use :

CLOSE(7)

If we want to delete the file then we can use CLOSE(7, STATUS = 'DELETE')

Append files in FORTRAN

To do the appends in FORTRAN we could do something like:

OPEN(95,FILE=OUTDIR//'*.OUT',POSITION='APPEND',STATUS='OLD',  FORM='BINARY')
! Some code 
CLOSE(95) 

In the above code 95 is just used arbitrarily.

Allocatable arrays in FORTRAN 90

In FORTRAN 90, one can assign allocatable arrays with the syntax as follows:

REAL,ALLOCATABLE,DIMENSION(:)::RSSBCW
REAL, ALLOCATABLE, DIMENSION(:,:):: TESTDF

In the above example, RSSBCW is a 1-D vector whereas TESTDF is a 2 dimensional array.

Using modules

A simple module structure would look something like:

MODULE COMPUTATION

! Assign some variables 
SAVE

! Add pieces of code / Functions 

END MODULE COMPUTATION

Now, while referring to the main program, you can use a simple syntax as follows:

USE COMPUTATION

After that we would be able to access all the code written in the modules. So, I think it is very useful way to write bunch of functions and subroutines into one program.

i-don-t-know-fortran's People

Contributors

janeshdev avatar

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.