- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I have this if clause:
if(index==0 .and. value(index) > 0.) then
When value is an array from 1 to n and index is 0, I get an error, because value(0) doesnt exist.
Is there a || comparism in Fortan? AFAIK, when using in C
if(index > 0&& value(index) > 0)
the expression value(index) will not be evaluated whenindex == 0.
My workaround looks like this:
if(index == 0) then
...do something
else if(value(index) > 0) then
...do the same something again...
end if
Is there a more elegant way?
Thanks in advance,
Markus
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
i have seen the same problem in my work. This is the reason why i havent transfert many of my programs from cvf to ivf. Cvf was able to solve the problem. All i have understand from statements from Steve Lionel is: IVF works in this way and you have to live with it. In my point of view there only one way to go: adding a feature request.
Frank
i have seen the same problem in my work. This is the reason why i havent transfert many of my programs from cvf to ivf. Cvf was able to solve the problem. All i have understand from statements from Steve Lionel is: IVF works in this way and you have to live with it. In my point of view there only one way to go: adding a feature request.
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess the root of the problem possibly lies in the fact that C has "sequence points" and therefore ensures that if the first clause fails then the second clause is not executed. Fortran doesn't have "sequence points" and indeed optimisation may result in clause 2 being evaluated before clause 1.
Les
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>if(index>0 .and. value(index) > 0.) then
nest the clauses (keep C++ syntax as comment)
! ** if(index>0&& value(index) > 0.) then **
if(index>0) then
if(value(index) > 0.) then
...
endif
endif
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The direct Fortran equivalent of the C code
if(index > 0&& value(index) > 0){
...
}
would be
if(index > 0)then
if(value(index) > 0))then
....
endif
endif
This has been explained several times on this forum, including the explanation that CVF didn't actually implement the proposed extension to Fortran, but a few people got away with coding something different from what they meant.
if(index > 0&& value(index) > 0){
...
}
would be
if(index > 0)then
if(value(index) > 0))then
....
endif
endif
This has been explained several times on this forum, including the explanation that CVF didn't actually implement the proposed extension to Fortran, but a few people got away with coding something different from what they meant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, in my original posting I mistyped the C if clause... It should be
if(index== 0 && value(index) > 0) { ... }
This means, the expression value(index) will not be evaluated when index == 0 and the instructions inside the brackets will be processed.
In Fortran, I have to use this:
if(index == 0) then
...do something
else if(value(index) > 0) then
...do the same something again...
end if
There seems no other way rather then typing the intructions two times.
Markus
if(index== 0 && value(index) > 0) { ... }
This means, the expression value(index) will not be evaluated when index == 0 and the instructions inside the brackets will be processed.
In Fortran, I have to use this:
if(index == 0) then
...do something
else if(value(index) > 0) then
...do the same something again...
end if
There seems no other way rather then typing the intructions two times.
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems pointless to me to continue in this vein of "why doesn't Fortran offer the same compound conditionals as C."
Do you have a rule in your C style guide against writing
if(index== 0)if(value(index) > 0) { ... }
or is that unacceptably straightforward?
You can't impose your C practices on Fortran. In this case, Fortran doesn't have as many ways of writing the same thing as C.
In C, if you wanted to give the compiler the option of "optimizing" this expression, you could write
if(index== 0 & value(index) > 0) { ... }
and I don't think you can convince me that Fortran shouldn't have an equivalent to the latter version.
Anyway, it's too late to revise history which goes back over 50 years for Fortran and over 30 years for C.
Do you have a rule in your C style guide against writing
if(index== 0)if(value(index) > 0) { ... }
or is that unacceptably straightforward?
You can't impose your C practices on Fortran. In this case, Fortran doesn't have as many ways of writing the same thing as C.
In C, if you wanted to give the compiler the option of "optimizing" this expression, you could write
if(index== 0 & value(index) > 0) { ... }
and I don't think you can convince me that Fortran shouldn't have an equivalent to the latter version.
Anyway, it's too late to revise history which goes back over 50 years for Fortran and over 30 years for C.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - tropfen
Hello,
i have seen the same problem in my work. This is the reason why i havent transfert many of my programs from cvf to ivf. Cvf was able to solve the problem. All i have understand from statements from Steve Lionel is: IVF works in this way and you have to live with it. In my point of view there only one way to go: adding a feature request.
Frank
i have seen the same problem in my work. This is the reason why i havent transfert many of my programs from cvf to ivf. Cvf was able to solve the problem. All i have understand from statements from Steve Lionel is: IVF works in this way and you have to live with it. In my point of view there only one way to go: adding a feature request.
Frank
Since Steve is away, I'll refer you toone of his previous responses on this topic.
Note that CVF didn't "solve the problem." If it worked for you,that wasfortuitous. If you change your code, it may no longer work. If you change the compilation switches, it may no longer work. You are depending on undefinedcompiler behaviour.
Jeff

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page