Warning, /frameworks/syntax-highlighting/autotests/input/highlight.f90 is written in an unsupported language. File is not indexed.
0001 ! This file is an example to test the syntax highlighting file fortran-free.xml 0002 ! (for fortran, free format) 0003 0004 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0005 ! THIS IS AN EXAMPLE OF A MODULE ! 0006 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0007 module module_example 0008 0009 ! use 'implicit none' when you want all variables to be declared 0010 implicit none 0011 0012 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0013 ! PUBLICS AND PRIVATES 0014 0015 ! In fortran 90 you can define your own operator 0016 public :: operator(.norm.) 0017 public :: operator(+) ! <-- you can also overload the usual operators 0018 public :: factorial 0019 public :: example_fn 0020 0021 private :: point3d_add 0022 private :: point3d_norm 0023 0024 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0025 ! USER-DEFINED TYPES... 0026 0027 ! This is a definition to use in declarations of real variables, 0028 ! parameters, etc. 0029 integer, parameter, public :: kr = selected_real_kind(10) 0030 0031 ! This is a user-defined type 0032 type, public :: point3d 0033 real(kind=kr) :: x, y, z 0034 end type point3d 0035 0036 ! This type is useless: it is only an example of type definition! 0037 type, public :: example_type 0038 complex(kind=kr) :: c ! <-- a complex number (two reals of kind kr)! 0039 real, dimension(-10:10) :: & ! <-- this line does not end here! 0040 r1, r2 ! <-- this is the final part of the previous line 0041 real, pointer, dimension(:) :: pointer_to_array_of_real 0042 real, dimension(:), pointer :: array_of_pointer_to_real 0043 end type example_type 0044 0045 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0046 ! INTERFACES... 0047 0048 ! Interface for the norm of a 3-D vector 0049 interface operator(.norm.) 0050 module procedure point3d_norm 0051 end interface 0052 0053 ! Interface for the operator '+' 0054 interface operator(+) 0055 module procedure point3d_add 0056 end interface 0057 0058 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0059 ! SOME DECLARATIONS... 0060 0061 ! A real number can be declared with the following line: 0062 real(kind=kr) :: real_var1 0063 ! But if you are not interested on the precision of floating point numbers, 0064 ! you can use simply: 0065 real :: real_var2 0066 0067 ! An array can be declared in two ways: 0068 real(kind=kr), dimension(1:10, -4:5), private :: a, b, c 0069 real(kind=kr), private :: d(1:10, -4:5) 0070 0071 ! This is a string with fixed lenght 0072 character(len=10) :: str_var 0073 0074 ! This is an allocatable array, which can be a target of a pointer 0075 type(example_type), private, dimension(:), allocatable, target :: & 0076 many_examples 0077 0078 ! Fortran 90 hasn't got its own preprocessor, it uses the C preprocessor! 0079 #ifdef XXX 0080 0081 #endif 0082 0083 contains 0084 0085 0086 ! The sum of two points 0087 pure function point3d_add(a, b) result(rs) 0088 type(point3d) :: rs 0089 type(point3d), intent(in) :: a, b 0090 rs%x = a%x + b%x 0091 rs%y = a%y + b%y 0092 rs%z = a%z + b%z 0093 end function point3d_add 0094 0095 0096 ! The norm of a point 0097 pure function point3d_norm(a) result(rs) 0098 real(kind=kr) :: rs 0099 type(point3d), intent(in) :: a 0100 rs = sqrt(a%x * a%x + a%y * a%y + a%z * a%z) 0101 end function point3d_norm 0102 0103 0104 ! A simple recursive function 0105 recursive function factorial(i) result (rs) 0106 integer :: rs 0107 integer, intent(in) :: i 0108 if ( i <= 1 ) then 0109 rs = 1 0110 else 0111 rs = i * factorial(i - 1) 0112 end if 0113 end function factorial 0114 0115 0116 ! This is a useless function 0117 subroutine example_fn(int_arg, real_arg, str_arg) 0118 integer, intent(in) :: int_arg 0119 real(kind=kr), intent(out) :: real_arg 0120 character(len=*), intent(in) :: str_arg 0121 0122 type(example_type), pointer :: p 0123 integer :: n, i, j 0124 logical :: flag 0125 0126 flag = .true. ! .true. is not an operator! 0127 if ( flag .and. flag ) then ! .and. is a pre-defined operator 0128 print *, "blabla" 0129 end if 0130 0131 ! Examples of inquiry functions: allocated, lbound, ubound. 0132 if ( .not. allocated(many_examples) ) then 0133 allocate( many_examples(10) ) 0134 end if 0135 print *, "Lower bound = ", lbound(many_examples, 1) 0136 print *, "Upper bound = ", ubound(many_examples, 1) 0137 0138 p => many_examples(5) ! <-- p is a pointer 0139 0140 ! A strange way to calculate i*i: add the first i odd numbers 0141 i = 6 0142 j = 0 0143 do n = 1, i 0144 j = j + (2*n - 1) 0145 end do 0146 print *, "i*i = ", i*i, j 0147 0148 real_arg = real(j) ! <-- here the highlighting is not very good: 0149 ! it is unable to distinguish between this and a definition like: 0150 ! real(kind=kr) :: a 0151 deallocate( many_examples ) 0152 end subroutine example_fn 0153 0154 end module module_example 0155 0156 0157 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0158 ! THIS IS THE MAIN PROGRAM ! 0159 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0160 program example 0161 use module_example 0162 0163 ! this is another example of use of the 'implicit' keyword 0164 implicit double precision (a-h,o-z) 0165 0166 real(kind=kr) :: var_out 0167 0168 type(point3d) :: & 0169 a = point3d(0.0_kr, 1.0_kr, 2.0_kr), & 0170 b = point3d(4.0_kr, 5.0_kr, 6.0_kr) 0171 0172 print *, "a + b = ", .norm. (a + b) 0173 print *, "factorial of 5 = ", factorial(5) 0174 0175 call example_fn(1, var_out, "hello!") 0176 0177 end program example