Type conflict of maxloc in Fortran











up vote
2
down vote

favorite












I have the following Fortran program



PROGRAM main

IMPLICIT NONE

INTEGER :: i
INTEGER,dimension(:),allocatable :: x0

allocate(x0(1:25))
DO i=1,25
x0(i)=i
END DO

print*,"maxloc de x0 est 25, en effet",maxloc(x0)

print*,"Cinq fois maxloc(x0)",INT(maxloc(x0))

print*,"f applique a la fonction",f(maxloc(x0))

print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))

CONTAINS

FUNCTION f(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER,dimension(1) :: maxlocec
!Sorties
INTEGER,dimension(1) :: f

f=maxlocec**2

END FUNCTION f

FUNCTION f1(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER :: maxlocec
!Sorties
INTEGER :: f1

f1=maxlocec**2

END FUNCTION f1

END PROGRAM


when I execute it i get the following error message:



print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))
1
Error: Rank mismatch in argument 'maxlocec' at (1) (0 and 1)


I have tried f1(maxloc(x0)) and it was not working, so I thought f1(INT(maxloc(x0))) would work and it is not.



The output of maxloc seems to be an integer but is not. What it is the way to solve it?










share|improve this question




















  • 2




    Do you understand that an array with one element is not the same thing as a scalar?
    – francescalus
    Nov 20 at 9:54






  • 1




    Note also that the error is about a rank mismatch not a type conflict, and it's a compile-time error not run-time. Perhaps you could edit the question/title if you understand the difference?
    – francescalus
    Nov 20 at 17:48















up vote
2
down vote

favorite












I have the following Fortran program



PROGRAM main

IMPLICIT NONE

INTEGER :: i
INTEGER,dimension(:),allocatable :: x0

allocate(x0(1:25))
DO i=1,25
x0(i)=i
END DO

print*,"maxloc de x0 est 25, en effet",maxloc(x0)

print*,"Cinq fois maxloc(x0)",INT(maxloc(x0))

print*,"f applique a la fonction",f(maxloc(x0))

print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))

CONTAINS

FUNCTION f(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER,dimension(1) :: maxlocec
!Sorties
INTEGER,dimension(1) :: f

f=maxlocec**2

END FUNCTION f

FUNCTION f1(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER :: maxlocec
!Sorties
INTEGER :: f1

f1=maxlocec**2

END FUNCTION f1

END PROGRAM


when I execute it i get the following error message:



print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))
1
Error: Rank mismatch in argument 'maxlocec' at (1) (0 and 1)


I have tried f1(maxloc(x0)) and it was not working, so I thought f1(INT(maxloc(x0))) would work and it is not.



The output of maxloc seems to be an integer but is not. What it is the way to solve it?










share|improve this question




















  • 2




    Do you understand that an array with one element is not the same thing as a scalar?
    – francescalus
    Nov 20 at 9:54






  • 1




    Note also that the error is about a rank mismatch not a type conflict, and it's a compile-time error not run-time. Perhaps you could edit the question/title if you understand the difference?
    – francescalus
    Nov 20 at 17:48













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have the following Fortran program



PROGRAM main

IMPLICIT NONE

INTEGER :: i
INTEGER,dimension(:),allocatable :: x0

allocate(x0(1:25))
DO i=1,25
x0(i)=i
END DO

print*,"maxloc de x0 est 25, en effet",maxloc(x0)

print*,"Cinq fois maxloc(x0)",INT(maxloc(x0))

print*,"f applique a la fonction",f(maxloc(x0))

print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))

CONTAINS

FUNCTION f(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER,dimension(1) :: maxlocec
!Sorties
INTEGER,dimension(1) :: f

f=maxlocec**2

END FUNCTION f

FUNCTION f1(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER :: maxlocec
!Sorties
INTEGER :: f1

f1=maxlocec**2

END FUNCTION f1

END PROGRAM


when I execute it i get the following error message:



print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))
1
Error: Rank mismatch in argument 'maxlocec' at (1) (0 and 1)


I have tried f1(maxloc(x0)) and it was not working, so I thought f1(INT(maxloc(x0))) would work and it is not.



The output of maxloc seems to be an integer but is not. What it is the way to solve it?










share|improve this question















I have the following Fortran program



PROGRAM main

IMPLICIT NONE

INTEGER :: i
INTEGER,dimension(:),allocatable :: x0

allocate(x0(1:25))
DO i=1,25
x0(i)=i
END DO

print*,"maxloc de x0 est 25, en effet",maxloc(x0)

print*,"Cinq fois maxloc(x0)",INT(maxloc(x0))

print*,"f applique a la fonction",f(maxloc(x0))

print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))

CONTAINS

FUNCTION f(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER,dimension(1) :: maxlocec
!Sorties
INTEGER,dimension(1) :: f

f=maxlocec**2

END FUNCTION f

FUNCTION f1(maxlocec)
IMPLICIT NONE
!Entrées
INTEGER :: maxlocec
!Sorties
INTEGER :: f1

f1=maxlocec**2

END FUNCTION f1

END PROGRAM


when I execute it i get the following error message:



print*,"f1 applique a la fonction",f1(INT(maxloc(x0)))
1
Error: Rank mismatch in argument 'maxlocec' at (1) (0 and 1)


I have tried f1(maxloc(x0)) and it was not working, so I thought f1(INT(maxloc(x0))) would work and it is not.



The output of maxloc seems to be an integer but is not. What it is the way to solve it?







fortran rank






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 13:58









francescalus

16.9k73256




16.9k73256










asked Nov 20 at 9:23









Data Joe

163




163








  • 2




    Do you understand that an array with one element is not the same thing as a scalar?
    – francescalus
    Nov 20 at 9:54






  • 1




    Note also that the error is about a rank mismatch not a type conflict, and it's a compile-time error not run-time. Perhaps you could edit the question/title if you understand the difference?
    – francescalus
    Nov 20 at 17:48














  • 2




    Do you understand that an array with one element is not the same thing as a scalar?
    – francescalus
    Nov 20 at 9:54






  • 1




    Note also that the error is about a rank mismatch not a type conflict, and it's a compile-time error not run-time. Perhaps you could edit the question/title if you understand the difference?
    – francescalus
    Nov 20 at 17:48








2




2




Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 at 9:54




Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 at 9:54




1




1




Note also that the error is about a rank mismatch not a type conflict, and it's a compile-time error not run-time. Perhaps you could edit the question/title if you understand the difference?
– francescalus
Nov 20 at 17:48




Note also that the error is about a rank mismatch not a type conflict, and it's a compile-time error not run-time. Perhaps you could edit the question/title if you understand the difference?
– francescalus
Nov 20 at 17:48












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










The maxloc routine does not return an int but, in this case, a 1-dimensional array of size 1 of type int.
From the standard:




MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or
MAXLOC (ARRAY [, MASK, KIND, BACK])



...



Result Characteristics. Integer. If KIND is present, the kind type
parameter is that specified by the value of KIND; otherwise the kind
type parameter is that of default integer type. If DIM does not
appear, the result is an array of rank one and of size equal to the
rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1,
d2, . . . , dDIM−1, dDIM+1, . . . , dn], where [d1, d2, . . . , dn] is
the shape of ARRAY.




So in your case yo will probably need:
print*,"f1 applique a la fonction",f1(maxloc(x0,1))






share|improve this answer





















  • Thank you very much ! Have a nice day :)
    – Data Joe
    Nov 20 at 10:38











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389803%2ftype-conflict-of-maxloc-in-fortran%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










The maxloc routine does not return an int but, in this case, a 1-dimensional array of size 1 of type int.
From the standard:




MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or
MAXLOC (ARRAY [, MASK, KIND, BACK])



...



Result Characteristics. Integer. If KIND is present, the kind type
parameter is that specified by the value of KIND; otherwise the kind
type parameter is that of default integer type. If DIM does not
appear, the result is an array of rank one and of size equal to the
rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1,
d2, . . . , dDIM−1, dDIM+1, . . . , dn], where [d1, d2, . . . , dn] is
the shape of ARRAY.




So in your case yo will probably need:
print*,"f1 applique a la fonction",f1(maxloc(x0,1))






share|improve this answer





















  • Thank you very much ! Have a nice day :)
    – Data Joe
    Nov 20 at 10:38















up vote
2
down vote



accepted










The maxloc routine does not return an int but, in this case, a 1-dimensional array of size 1 of type int.
From the standard:




MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or
MAXLOC (ARRAY [, MASK, KIND, BACK])



...



Result Characteristics. Integer. If KIND is present, the kind type
parameter is that specified by the value of KIND; otherwise the kind
type parameter is that of default integer type. If DIM does not
appear, the result is an array of rank one and of size equal to the
rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1,
d2, . . . , dDIM−1, dDIM+1, . . . , dn], where [d1, d2, . . . , dn] is
the shape of ARRAY.




So in your case yo will probably need:
print*,"f1 applique a la fonction",f1(maxloc(x0,1))






share|improve this answer





















  • Thank you very much ! Have a nice day :)
    – Data Joe
    Nov 20 at 10:38













up vote
2
down vote



accepted







up vote
2
down vote



accepted






The maxloc routine does not return an int but, in this case, a 1-dimensional array of size 1 of type int.
From the standard:




MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or
MAXLOC (ARRAY [, MASK, KIND, BACK])



...



Result Characteristics. Integer. If KIND is present, the kind type
parameter is that specified by the value of KIND; otherwise the kind
type parameter is that of default integer type. If DIM does not
appear, the result is an array of rank one and of size equal to the
rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1,
d2, . . . , dDIM−1, dDIM+1, . . . , dn], where [d1, d2, . . . , dn] is
the shape of ARRAY.




So in your case yo will probably need:
print*,"f1 applique a la fonction",f1(maxloc(x0,1))






share|improve this answer












The maxloc routine does not return an int but, in this case, a 1-dimensional array of size 1 of type int.
From the standard:




MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or
MAXLOC (ARRAY [, MASK, KIND, BACK])



...



Result Characteristics. Integer. If KIND is present, the kind type
parameter is that specified by the value of KIND; otherwise the kind
type parameter is that of default integer type. If DIM does not
appear, the result is an array of rank one and of size equal to the
rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1,
d2, . . . , dDIM−1, dDIM+1, . . . , dn], where [d1, d2, . . . , dn] is
the shape of ARRAY.




So in your case yo will probably need:
print*,"f1 applique a la fonction",f1(maxloc(x0,1))







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 9:52









albert

2,71221021




2,71221021












  • Thank you very much ! Have a nice day :)
    – Data Joe
    Nov 20 at 10:38


















  • Thank you very much ! Have a nice day :)
    – Data Joe
    Nov 20 at 10:38
















Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 at 10:38




Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 at 10:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389803%2ftype-conflict-of-maxloc-in-fortran%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'