Good Code Development Practices
Upper-/Lower-case Letters
Upper-case Letters
- All Fortran90 commands
- PROGRAM MAIN, END PROGRAM MAIN
- IMPLICIT NONE, INCLUDE, STOP
- REAL, INTEGER, CHARACTER, DIMENSION, PARAMETER
- CALL, RETURN
- OPEN, FILE, STATUS, CLOSE
- IF, END IF, DO, END DO
- READ, WRITE, PRINT
- Module and Subroutine Names
- MAIN, SHARED_DATA, INITIA, SAVEVF
Lower-case Letters
- Variable Names
- pi, re, ma, iconbc, nstep, rkstep
- Array Names
- x, y, z, dx, dy, dz, xc, yc, zc, dxs, dys, dzs
- u, v, w, p, varray, farray, uhat, vhat, what, xinlet, yinlet
- Constant Value
- 1.0e0
- Indices
- i,j,k,ii, i2
- File names
Other Tips
Place a space after Subroutine Names
Example Program: |
A sample example is given below: |
CALL SUBROUTINE INFLOW_BC (A,B,C) ... SUBROUTINE INFLOW_BC (A,B,C) IMPLICIT NONE ... RETURN END SUBROUTINE INFLOW_BC |
How to Change Using vi Editor
Use the substitution command
Example: |
A sample example is given below: |
PROGRAM TEST_DOUBLE IMPLICIT NONE ! REAL, PARAMETER :: PI=0.12345678901234567890 ! STOP END PROGRAM TEST_DOUBLE |
In the command mode, you can use the substitution command. |
:%s/PI/pi/g |
Tips
-
Combine all programs into one file.
-
Change the long variable names
-
LENGTH, ICONBC, VARAY, FARRAY, DPMEAN,
-
Change NXT first then NX, and also DXS before DX
-
RE is difficult because of READ, also NU is difficult because of CONTINUE
-
U will be very difficult to change because there can be many names which contain U
-
Try instead U(
-
-
I, J and K will be also vey difficult because they appear everywhere. You need be very careful here.
-
Try (I or I= or I, instead of I
-
-
It is almost imposible to change the code perfectly from the upper-letter cases to the lower-letter cases. At the end, you need to work on individual cases.
Example Program: |
A sample example is given below: |
:%s/LENGTH/length/g :%s/VARRAY/VARRAY/g :%s/U(/u(/g :%s/(I/(i/g :%s/I=/i=/g :%s/I,/i,/g |
- Save the program into a different file name after a few substitutions, and compile it to see if there is any error.
- Because Fortran compiler is not case-sensitive, at the end, it does not matter if all variable names are in lower-case letters or not. It is only for the convenience of users. So, if you end up with program which contains CONTInuE, it does not matter because it does not cause any compile error.
- But if you make mistakes with lower-case file names then it does matter. So, be careful when you use the substitution command.
- Usually, Fortran90 compiler can pick up very quickly if there is any spelling errors. So, do compile as often as you can.