Type conflict of maxloc in Fortran
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
add a comment |
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
2
Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 '18 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 '18 at 17:48
add a comment |
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
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
fortran rank
edited Nov 20 '18 at 13:58
francescalus
17.1k73356
17.1k73356
asked Nov 20 '18 at 9:23
Data JoeData Joe
163
163
2
Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 '18 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 '18 at 17:48
add a comment |
2
Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 '18 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 '18 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 '18 at 9:54
Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 '18 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 '18 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 '18 at 17:48
add a comment |
1 Answer
1
active
oldest
votes
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))
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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))
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
add a comment |
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))
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
add a comment |
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))
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))
answered Nov 20 '18 at 9:52
albertalbert
2,88331123
2,88331123
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
add a comment |
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
Thank you very much ! Have a nice day :)
– Data Joe
Nov 20 '18 at 10:38
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Do you understand that an array with one element is not the same thing as a scalar?
– francescalus
Nov 20 '18 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 '18 at 17:48