## Your Essential Guide to Mastery Fortran Abaqus

Are you seeking a concise overview of “Fortran Abaqus” and eager to craft your own subroutine? This post delves into the core aspects of the Abaqus Fortran. In Abaqus, user subroutines are mainly composed in Fortran, though you have the option to code in C or C++. Fortran stands out for its simplicity, ranking among the most beginner-friendly programming languages. Its core functionality centers on fundamental low-level operations, a universal trait among programming languages. Furthermore, its syntax exhibits similarities to MATLAB. Stay with CAE Assistant for an in-depth exploration of the Abaqus Fortran subroutines.

If you’re looking to create your first Abaqus subroutine, we’ve prepared a comprehensive guide. Simply click on ‘Start Writing Subroutine in Abaqus‘ to get started. |

## 1. Basics: what is the structure of Abaqus Fortran?

A Fortran program is just a sequence of lines of text. It has to follow a specific *structure*. Take a look at this simple piece of code:

PROGRAMCIRCLEREALR, AREACTHIS PROGRAM READS A REAL NUMBER R AND PRINTSCTHE AREA OF A CIRCLE WITH RADIUS R.WRITE(*,*) 'GIVE RADIUS R:'READ(*,*) R!THIS IS RADIUS OF THE CIRCLE AREA = 3.14159*R*RWRITE(*,*) 'AREA = ', AREASTOPEND

Originally, all Fortran programs had to be written in all uppercase letters. However, Fortran is not case-sensitive, so “X” and “x” are the same variable.

Let’s now delve into some fundamental headings for understanding the structure of Abaqus Fortran. starting with **column rules**.

⭐⭐⭐Free Abaqus Course | ⏰10 hours Video 👩🎓+1000 Students ♾️ Lifetime Access
✅ Module by Module Training ✅ Standard/Explicit Analyses Tutorial ✅ Subroutines (UMAT) Training … ✅ Python Scripting Lesson & Examples |

**Column Position Rules**

Fortran has very few rules for how to format the source code. The most important rules are the column position rules:

**»** Col. 1 Blank, or a “**C**” for comments

**» **Col. 1-5 Statement label (optional)

**» **Col. 6 Continuation of the previous line (optional)

**» **Col. 7-72 Statements

**Comments**

The lines that begin with a “**C**” here are *comments* and have no purpose other than to make the program more readable. You may also use the exclamation mark (**!**) for comments. This type of comment can be any place among your piece of code (look at ‘**!**THIS IS RADIUS OF THE CIRCLE’).

### Statement label

Statement labels are used to mark positions in the program. Typically, many loops and other statements in a single program require a statement label. The programmer is responsible for assigning a unique number to each label in each program (or subprogram). Look at **4.1. Loops Section (Do Loop)** in the second part of this article (**Under Construction**) to see a practical use of statement labels.

**Note: **If you want to start writing your first subroutine, but don’t know where to start, just read this blog and you will all set up: **Abaqus subroutine**

### Continuation

Sometimes, a statement does not fit into the 66 available columns (7-72) of a single line. One can then break the statement into two or more lines and use the continuation mark in position 6 (I mean, you put 5 spaces and then type **+**). Example:

CTHE NEXT STATEMENT GOES OVER TWO PHYSICAL LINES AREA = 3.14159265358979+* R * R

Any character can be used instead of the plus sign (**+**) as a continuation character. Also, we may use digits (using 2 for the second line, 3 for the third, and so on).

Keep reading this post to know the main points of Abaqus Fortran subroutine writing.

## 2. Data Types in Fortran

In Fortran, like in many programming languages, data types determine the kind of data that a variable can hold. Fortran offers a variety of data types to suit different needs. Let’s take a look at the familiar data types often used in Abaqus Fortran subroutines:

### Variable names

Variable names in Fortran consist of the letters **A-Z**, the digits **0-9** and the underscore (**_**). The first character must be a letter.

Like many other languages, the words which make up the Fortran language are called *reserved words* and cannot be used as names of variables. Some examples are **PROGRAM**, **REAL**, **STOP**, **END**, etc.

### Variable Types

Fortran supports several different data types to make data manipulation easier:

The most frequently used data types are **integer** and **real** (floating point) in Abaqus Fortran.

### Integers

An integer is a number that can be written without a fractional component. For example, 21, 4, 0, and −2048 are integers. Fortran has only one type for integer variables. They are usually stored as 4 bytes variables.

### Floating-point variables

When a number is not an integer, it is considered a decimal. Fortran has two different types of decimal (floating point) variables, called **REAL** and **DOUBLE PRECISION**. Numerical calculations in subroutines usually need very high precision, and **DOUBLE PRECISION** should be used. Usually, a real is a 4-byte variable, and the double-precision is 8 bytes. You may use the syntax **REAL*8** to denote 8-byte floating-point variables in Abaqus Fortran subroutines.

### Declarations

Every variable *should* be defined in a *declaration*. This establishes the *type* of the variable. The most common declarations are:

INTEGERVariable1, Variable2,…REALVariable1, Variable2,…DOUBLE PRECISIONVariable1, Variable2,…

Each variable should be declared exactly once. If a variable is undeclared, Fortran uses a set of *implicit rules* to establish the type. This means all variables starting with the letters **I**, **J**, **K**, **L**, **M** and** N** are **integers** and **all others** are **real**. *You have to be very careful with variable names.*

However, you can make a habit of putting a simple piece of code at the top of each of your subroutines:

** IMPLICIT** NONE

Then, you must explicitly declare every variable that your subroutine uses or needs.

### Parameters

Some constants appear many times in a program. Therefore, it is often desirable to define them only once, at the beginning of the program. This is called **PARAMETER** in Fortran:

- To reduce the number of typos (i.e., typing errors).
- To facilitate changing a constant that appears many times in a program.
- To increase the readability of the code.

For example, we can rewrite the example code above (circle area) as:

PROGRAMCIRCLEREALR, AREA, PIPARAMETER(PI = 3.14159) C THIS PROGRAM READS A REAL NUMBER R AND... . . .END

The syntax of the parameter statement is

PARAMETER(name1 = value1, name2 = value2, …)

The PARAMETER statement(s) must come before the first executable statement.

### Arrays

Many computations in Abaqus Fortran subroutines use vectors and matrices. The data type Fortran uses for representing such objects is the array. A one-dimensional array corresponds to a vector, while a two-dimensional array corresponds to a matrix. |

#### 1D arrays

It is just a linear sequence of elements stored consecutively in memory. For example,

REALA(6)

declares A as a real array of length 6. By convention, Fortran arrays are indexed from 1 and up. Each element of an array can be thought of as a separate variable. You reference the **i**th element of array **A** by **A**(**i**).

#### 2D arrays

Matrices are very important in linear algebra. They are usually represented by two-dimensional arrays. For example, the declaration

REALA(3,5)

defines a two-dimensional array of 3 × 5 = 15 real numbers. It is useful to think of the first index as the row index and the second as the column index.

In the following, we will discuss the remaining topics such as Operators and Expressions (for Variables and Matrices), Conditional (**IF**) and Loop (**DO**) Statements, some Build-in Functions in Fortran, and finally, a brief talk about How to Write to files from inside Fortran. Follow this post to know more about Fortran for Abaqus subroutines.

## 3. Operators in Fortran | Common Fortran Abaqus operators

The simplest non-constant expressions are of the form:

operand **operator** operand

The result of an expression is itself an operand; hence we can nest expressions together.

*ℜemember:*

- The order of precedence is essential: arithmetic expressions are evaluated first, then relational operators, and finally logical operators (Take a look at Quiz Time question 3).
- Logical expressions are frequently used in conditional statements like the
statement.*IF*

Operators are really helpful when you’re writing code. In “Fortran Abaqus,” they play a big part in conditional statements, as you’ll see in the next section. Keep reading to learn more.

**4. Controls in Fortran Abaqus**

Fortran for Abaqus subroutine has some control features presented here briefly.

**4.1. Conditional Statements **

The most common *conditional statement *in Fortran is the IF statement, which has several forms:

#### I. One-line (one *executable* statement)

IF(logical expression)executable statement

Example:

IF(X.LT.0) X = -X

#### II. More than one *executable* statement

IF(logical expression)THENStatement1Statement2 .. .END IF

#### III. General Form

IF(logical expression1)THENstatements1ELSE IF(logical expression2)THENstatements2. . .ELSEstatementsnEND IF

The conditional expressions are evaluated in a row until one is found to be true. Then the associated statements are executed, and the control resumes after the endif.

⭐⭐⭐Free Abaqus Course | ⏰10 hours Video 👩🎓+1000 Students ♾️ Lifetime Access
✅ Module by Module Training ✅ Standard/Explicit Analyses Tutorial ✅ Subroutines (UMAT) Training … ✅ Python Scripting Lesson & Examples |

### 4.2. Loops

For repeated execution of similar things, *loops* are used. Here we only take a look at **DO**-loop in Fortran.

#### Do-loop

This loop repeats a series of one or more Fortran statements a set number of times. The general format is:

DOcount_variable=start, stop, step.fortran statement(s).END DO

*count_variable* is the loop variable (often called the ‘*loop index’ or ‘counter’*).

*start* specifies the initial value of *count_variable*,

*stop * is the terminating bound,

*step *is the increment (step).

Where the *count_variable* must be an integer variable. *start*, *stop*, and *step* are integer variables or integer expressions. The *step* value is optional. If it is omitted, the default value is 1.

Also, another general form of the DO loop that you may see is as follows:

DOlabelcount_variable = start, stop, step . fortran statement(s) .labelCONTINUE

Here is a simple example that prints the cumulative sums of the integers from 1 through N (assume N has been assigned a value elsewhere):

INTEGERI, N, SUM SUM = 0DO10I = 1, N SUM = SUM + IWRITE(*,*) 'I =', IWRITE(*,*) 'SUM =', SUM10CONTINUE

The number **10** is a *statement label*. Recall that column positions 1-5 are reserved for statement labels and the numerical value of statement labels has no significance (see the explanation of **Statement Label **and **Column Position Rules** in the above parts.

The variable defined in the **DO**-statement is incremented by 1 by default. However, you can define the *step* to be any number but zero. This program segment prints the even numbers between 1 and 10 in decreasing order:

INTEGERIDOI = 10, 1, -2WRITE(*,*) 'i =', IEND DO

*ℜemember:*

- Other statements within the loop must never change the
**DO**-loop variable! Doing so may cause great confusion. - The loop index can be of type
**REAL**, but due to round-off errors, may not take on precisely the expected sequence of values.

**5. Built-in Functions**

Some useful functions have been included in Fortran. For example, most of the practical mathematical functions:

Clearly, these built-in functions come in handy when working with Abaqus Fortran subroutines. Now, let’s explore arrays and matrices in Fortran:

## 6. Array and Matrix Operations

Fortran operates on vectors and matrices much like Matlab:

### 6.1. Vectorial Operations:

In the statements like

` U = `**SIN **(V)

U and V can be vectors, so you do not have to calculate such statements member by member (in a loop).

### 6.2. Matrix Multiplication

MATMUL(A,B)

Which is of great importance in FEA. Note that:

C = A * B

is NOT a matrix multiplication. However, it will multiply the elements of A and B to create C.

### 6.3. Inner Product

DOT_PRODUCT(U,V)

Compute a general dot product that is particularly useful in Abaqus subroutines.

### 6.4. Dimension of Vectors and Matrices

LENGTH =SIZE(vector_array)

Returns LENGTH as a single integer (2, 3, 6, …) to determine the length of a vector_*array.*

DIMS =SHAPE(matrix_array)

Returns DIMS as an integer vector ( (2,2), (3,1), (3,3), …) to determine the dimensions of a matrix. For a 2D matrix, simply shows the number of rows and number of columns, respectively.

Once you have understood the basics of “Fortran Abaqus,” the important next step is saving your data in files. We’ll explain this in the next section.

## 7. Writing data to files

In Fortran, the general syntax to write a file is:

WRITE(unit number, format string) list of variables

The *unit number *is an integer-valued variable that is defined when opening the file.

*format string *describes how the output is to be formatted (This is something like %s or %d in MATLAB or C).

For debugging purposes in your Abaqus subroutines, you can write to the default (*unit number=6)*, which is the Printed Output file:

WRITE (6,*) "Number 1 = ",num1, "Number 2 = ",num2

In Fortran, ***** means default. So, this will simply use standard defaults to print integers, double-precision numbers, etc.

With the above statement, the values held by *num1* and* num2 *variables can be displayed. The information inside the quotes is shown as it is, including capitalization and any spelling errors. When you do not use quotes, it is interpreted as a variable.

Notes:

- Also, you can use:

Write(*,*)

Since the default output is *unit number=6 (*Printed Output file) for Abaqus Subroutine Interface.

- For
**Abaqus/Explicit**, printed output is a .log file (**Log**tab in**Job Monitor**window displays the contents of this file during the analysis). The counterpart for**Abaqus/Standard**is a**.dat file**(and Data tab). If you are more curious, take a look at**Fortran unit numbers that Abaqus uses**.

Default formatting is OK for printing a few variables but not much good for printing an array, which will be largely incomprehensible. The *format string *is a character string that has a special meaning for Fortran, for example:

‘I4’ an integer length 4

‘1X’ a single blank space

‘E12.4’ a floating-point number in Exponent format with total length 12 and 4 decimal places

A10 a character string with 10 characters

For a handy reference of these format codes, you can see the **Format Statements in Stanford Fortran Tutorial**.

## 8. Your path to expertise Abaqus Fortran subroutines!

Here below, I have listed some main Abaqus Fortran tutorials that you may encounter when using Abaqus at an advanced level as a graduate student or researcher. Good news for you! You can learn each subroutine you want by clicking on that at CAE Assistant.

## 9. Calling a Subroutine within Another Abaqus Fortran Subroutine

Abaqus Fortran Subroutines often have many lines. So, it may be hard to understand and manage them. This happens specifically when we deal with complex engineering problems. To make such Fortran Abaqus models simpler, we can take out a piece of the code and write it in a separate Fortran subroutine. Then, we just call it in the other Abaqus Fortran Subroutines. This makes the Fortran Abaqus codes more understandable.

To explore this matter, consider the following Fortran program. It takes the radius of a circle and calculates its area. Let’s assume there is a rule in the program to modify the area under a special condition. It is presented by the IF statement.

PROGRAMCIRCLEREALR, AREACTHIS PROGRAM READS A REAL NUMBER R AND PRINTSCTHE AREA OF A CIRCLE WITH RADIUS R.WRITE(*,*) 'GIVE RADIUS R:'READ(*,*) R!THIS IS RADIUS OF THE CIRCLEAREA = 3.14159*R*RCAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONIF(AREA == 0.0)THENAREA = 10.0ENDIFWRITE(*,*) 'AREA = ', AREASTOPEND

You can call a subroutine, instead of the IF statement in the program. This enhances its clarity. We have chosen the name “CORRECTION” for the subroutine. In the following code, we have called it within the “CIRCLE” program. It takes the parameters R, and AREA, as its input.

PROGRAMCIRCLEREALR, AREACTHIS PROGRAM READS A REAL NUMBER R AND PRINTSCTHE AREA OF A CIRCLE WITH RADIUS R.WRITE(*,*) 'GIVE RADIUS R:'READ(*,*) R!THIS IS RADIUS OF THE CIRCLEAREA = 3.14159*R*RCAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONCALLCORRECTION(R, AREA)WRITE(*,*) 'AREA = ', AREASTOPEND

The “CORRECTION” subroutine takes the parameters R, and AREA. Then, it modifies the AREA if needed, and returns it back to the “CIRCLE” program. So, we have to write the “CORRECTION” subroutine in the following form. We will put it after the “CIRCLE” program in the code.

SUBROUTINECORRECTION(R, AREA)REALR, AREACAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONIF(AREA == 0.0)THENAREA = 10.0ENDIFRETURNEND

Now, let us show you how calling a subroutine helps us simplify a Fortran code in a common scenario. In this scenario, we have a code with repetitive algorithms. This is a common phenomenon in many Fortran Abaqus models. In this case, we have to rewrite an algorithm many times in an Abaqus Fortran code. Instead, we can write the algorithm once in a Fortran subroutine. Then, just call it in the main program when needed. To understand how to deal with this matter, consider the following code. In this code, the program modifies the input radius and recalculates the circle’s area.

PROGRAMCIRCLEREALR, AREACTHIS PROGRAM READS A REAL NUMBER R AND PRINTSCTHE AREA OF A CIRCLE WITH RADIUS R.WRITE(*,*) 'GIVE RADIUS R:'READ(*,*) R!THIS IS RADIUS OF THE CIRCLEAREA = 3.14159*R*RCAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONIF(AREA == 0.0)THENAREA = 10.0ENDIFWRITE (*,*) 'AREA = ', AREAR = R - 5.00AREA = 3.14159*R*RCAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONIF(AREA == 0.0)THENAREA = 10.0ENDIFWRITE(*,*) 'AREA = ', AREASTOPEND

As you can see, the proposed Fortran program is long and we have repeated the following part twice.

AREA = 3.14159*R*RIF(AREA == 0.0)THENAREA = 10.0ENDIF

With the capability of calling subroutines in Fortran, we can make the program shorter and simpler. As you can see, we have called the CORRECTION subroutine to calculate the area in this program. So, we don’t need to repeat the IF statement multiple times. The subroutine will return the parameter AREA to the CIRCLE program.

PROGRAMCIRCLEREALR, AREACTHIS PROGRAM READS A REAL NUMBER R AND PRINTSCTHE AREA OF A CIRCLE WITH RADIUS R.WRITE(*,*) 'GIVE RADIUS R:'READ(*,*) R!THIS IS RADIUS OF THE CIRCLECAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONCALLCORRECTION(R, AREA)WRITE(*,*) 'AREA = ', AREAR = R - 5.00CAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITIONCALLCORRECTION(R, AREA)WRITE(*,*) 'AREA = ', AREASTOPEND

Now, you just need to write the Fortran subroutine “CORRECTION” once after the program.

SUBROUTINECORRECTION(R, AREA)REALR, AREACAPPLYING A RULE TO MODIFY THE AREA IN A SPECIAL CONDITION AREA = 3.14159*R*RIF(AREA == 0.0)THENAREA = 10.0ENDIFRETURNEND

Have you noticed how using subroutines within a program can make it simpler and easier to understand? Now you know that Fortran has the feature of allowing subroutines to call each other. We can call a subroutine in a Fortran Abaqus code, instead of writing a part of the code multiple times. So, the Fortran Abaqus models will become more understandable. Moreover, it helps us to minimize errors when writing the subroutine.

To learn more about calling a Fortran subroutine within a program, you can check out this link. Moreover, we suggest you see this learning video on the YouTube website. It explains how to call a subroutine within another Abaqus Fortran subroutine.

In this blog post, we’ve introduced you to “Fortran Abaqus “, a tool for engineering simulations. We’ve explained how Fortran programs are structured, discussed different types of data like numbers, and how to set constants. We’ve even talked about using arrays and matrices to handle groups of data. additionally, we’ve covered operators (like math operations), ways to control your program (if-else statements and loops), and built-in functions to help you do more. We’ve also shown you how to save your results in files. This CAE Assistant blog post is your guide to becoming a pro in Abaqus Fortran programming, so don’t miss out.

Additionally, we’d love to hear your thoughts, **Your comments mean the world to us!** They not only make our tutorials better but also bring us closer to our ultimate goal: **serving all your CAE needs without any extra tutorials**.

you can get the PDF of this post by clicking on ** caeassistant.com – Fortran for Abaqus subroutines**

## References:

**FORTRAN 77 for Engineers and Scientists with an Introduction to Fortran 90**, L. Nyhoff and S. Leestma, Prentice Hall**Fortran 77 Tutorial**, Stanford University

Explore our comprehensive Abaqus tutorial page, featuring free PDF guides and detailed videos for all skill levels. Discover both free and premium packages, along with essential information to master Abaqus efficiently. Start your journey with our Abaqus tutorial now!

✅ Subscribed students | +80,000 |

✅ Upcoming courses | +300 |

✅ Tutorial hours | +300 |

✅ Tutorial packages | +100 |

#### What is the use of Fortran in Abaqus?

Fortran is one of the easiest programming languages to learn because it can do virtually nothing other than basic low-level operations common to all languages. Its syntax is also very similar to MATLAB. Furthermore, you need to know only an even smaller subset of FORTRAN to write a subroutine code in Abaqus.

#### How do I comment in Fortran?

The lines that begin with a “**C**” in Fortran are *comments* and have no purpose other than to make the program more readable. You may also use the exclamation mark (**!**) for comments. This type of comment can be any place among your piece of code.

#### What is the control structure in Fortran?

Fortran encompasses various control features, including conditional statements like IF statements, and loops such as DO loops. Each of these can be further categorized into different types.

#### What are the built-in functions in Fortran?

The Built-in functions can be very useful for performing various calculations and operations in your Fortran code. Some commonly used intrinsic functions include **SIN**, **COS**, **SQRT** for trigonometric and mathematical operations, **LEN** for string length determination, and **MAX**/**MIN** for finding maximum and minimum values, among many others.

#### What does write (* *) mean in Fortran?

In Fortran, the general syntax to write a file is:

WRITE (*unit number, format string) list of variables *

Additionally, ***** means default. So, write (* *) will simply use standard defaults to print integers, double-precision numbers, etc.