So I need to code a simple program, and I need to define 2D coordinates?
Is there any coordinate system I can use in Fortran?
I was told it might have to be all in arrays? And if so, can anybody push me in the right direction as to how to set up 2d arrays?
Many thanks.
5
You could create a 2D array. Googling for fortran 2d array
led me to: How to initialize two-dimensional arrays in Fortran
Which includes:
INTEGER, DIMENSION(3, 3) :: array
array = reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), shape(array))
which you can easily change to your situation.
Alternatively, you can create a custom coordinate
type, and fill an array with those custom types. See for example: Array of derived type: select entry
which includes:
type Element
logical active
integer type
real width
! etc
end type
type(Element), allocatable :: elements(:)
Which, if adapted to your situation, would provide a nice way to having an allocatable array of 2D coordinates.
Although mathematically you need 2D concept to deal with points in a 2D space, you can use 1D arrays in your Fortran code to accomplish your task. For instance, if you have 100 points in a 2D plane to work with, you can define two 1D arrays x and y as follows:
real:: x(100), y(100)
and then you can treat x(i) and y(i) as a pair representing the ith point, and perform whatever calculation you want.