First up, hi!
I’m new here and to Fortran. I started my physics degree last year and felt this to be the right time to start learning a proper compiled programming language, and Fortran seemed cool half because of how old it is, and half because, well, I liked the structure when I tried it. (I like old things, by the way.)
Anyway, preliminaries aside, I’m trying to write a subroutine to normalize and convert a real array to an integer array. The problem is that the real array going into the subroutine won’t always be of the same dimensions, so I don’t know how to declare the integer array. Here’s the code I have:
subroutine prepare(realarray, integerarray)
implicit none
real, intent(in) :: realarray(:,:)
integer(2), intent(out) :: integerarray(:)
allocate(integerarray, mold=realarray)
integerarray = nint((2**15) * realarray / maxval(realarray))
end subroutine
The error that pops up is on the allocate command.
Type of entity at (1) (integerarray) is type incompatible with source-expr at (2) (realarray).
Alternatively, upon trying
allocate(integerarray(shape(realarray)))
what I get is
Rank-mismatch in array reference
Could anyone suggest how to bypass this?
Thanks in advance!