This is my own code, and it won't compile with gfortran. All I want to do is extract the location of the cell with the minimum value in an array. A seemingly simple task but one that does not work with the intrinsic function minloc, for reasons I do not understand.(adsbygoogle = window.adsbygoogle || []).push({});

The error message:

The code:Code (Text):iclosept=minloc(dist)

1

Error: Incompatible ranks 0 and 1 in assignment at (1)

Code (Text):

subroutine distance_to_trench(pt,tr,mindist,iclosept)

! find (great circle) distance from point to each point on the trench

! distance = the minimum distance to the trench

type(point) :: pt

type(trench) :: tr

real, parameter :: pi=3.14159265359

real, parameter :: eradius=6371

real :: rad,deg

real :: x1,y1,z1,x2,y2,z2

real,dimension(:),allocatable :: dist

real :: mindist

integer :: ii, length, iclosept, a

rad=pi/180

deg=180/pi

length=size(tr%poly%points%x)

allocate(dist(length))

! method:

! convert lat lons to cartesian vectors

! use angle between vectors to find the distance

x1=cos(rad*pt%y)*cos(rad*pt%x)

y1=cos(rad*pt%y)*sin(rad*pt%x)

z1=sin(rad*pt%y)

do ii=1, length

x2=cos(rad*tr%poly%points(ii)%y)*cos(rad*tr%poly%points(ii)%x)

y2=cos(rad*tr%poly%points(ii)%y)*sin(rad*tr%poly%points(ii)%x)

z2=sin(rad*tr%poly%points(ii)%y)

dist(ii)=eradius*acos(x1*x2+y1*y2+z1*z2)

print *,dist(ii)

enddo

mindist=minval(dist)

a=size(dist)

print *,'size of dist', size(dist), a

iclosept=minloc(dist)

print *,'minloc', minloc(dist), iclosept

deallocate(dist)

end subroutine distance_to_trench

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Fortran bug: rank problem gfortran

Loading...

Similar Threads - Fortran rank problem | Date |
---|---|

How to buy Fortran Programming Software Commersial License | Jan 30, 2018 |

Rank mismatch and incompatible ranks 1 and 2 | Sep 15, 2015 |

Rank mismatch in argument (Fortran 90) | Mar 28, 2013 |

FORTRAN Programming Error: Incomparable ranks 0 at and 1 in assignment. | Apr 4, 2012 |

Fortran, complex array with rank one | Sep 19, 2009 |

**Physics Forums - The Fusion of Science and Community**