array in gfortran,

To create an array in Fortran using gfortran, you can follow these steps:

  1. Declare the array: Use the DIMENSION statement to declare the array and specify its size. For example, to declare a one-dimensional array of integers with 10 elements, you can use the following code:

fortran INTEGER, DIMENSION(10) :: myArray

  1. Initialize the array (optional): You can initialize the array elements to specific values using assignment statements. For example, to initialize all elements of the array to zero, you can use the following code:

fortran myArray = 0

  1. Access and modify array elements: You can access individual elements of the array using array indexing. Array indexing in Fortran starts from 1. For example, to access the third element of the array, you can use the following code:

fortran myArray(3) = 42

  1. Use the array in your program: You can use the array in your program by referencing it in other statements or expressions. For example, you can use the array in arithmetic operations or pass it as an argument to subroutines or functions.

Here's an example that demonstrates the above steps:

PROGRAM ArrayExample
  INTEGER, DIMENSION(10) :: myArray
  INTEGER :: i

  ! Initialize the array
  myArray = 0

  ! Modify array elements
  myArray(3) = 42
  myArray(7) = 99

  ! Print array elements
  DO i = 1, 10
    PRINT *, myArray(i)

END PROGRAM ArrayExample

This program declares an array myArray with 10 elements, initializes all elements to zero, modifies the third and seventh elements, and then prints all the elements.

I hope this helps! Let me know if you have any further questions.