- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So I have a loop that does some drawing. I loops 48 times, but I only want to draw some things on the 2, 6, 10 etc loops
I can solve the problem with an if and set of or statements. But is there a simpler code idea to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
logical :: todraw(48) = .false.
!...
todraw([2,4,10]) = .true.
!...
where (todraw)
!Draw
end where
OR, esp. if Draw requires index i
do i = 1,48
if(.not. todraw(i))cycle
!Draw
end do
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your loop allows it, you could do:
do i = 2,48,4
do the drawing ...
enddo
but that assumes the iteration does not depend on previous steps.
If there is a dependency, then something like this comes to mind:
do i = 1,48
... preparation ...
if ( mod(i-2,4) == 0 ) then
draw the stuff
endif
enddo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or when the draw intervals are non-fixed. Create a table
do i=1,48
...
if(draw(i)) then
draw the stuff
endif
...
end do
Note, the above method, permits you to have code outside the do i loop to enable, disable, change what and when drawing occurs.
Note, with 48 possible conditions, I would probably use a bit mask in an integer(8) variable. For much larger ranges than 48 either a logical(1) array or an array of bit masks. The determination factor the impact on L1/L2 cache.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
logical :: todraw(48) = .false.
!...
todraw([2,4,10]) = .true.
!...
where (todraw)
!Draw
end where
OR, esp. if Draw requires index i
do i = 1,48
if(.not. todraw(i))cycle
!Draw
end do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
They are all better than my solution.
The problem with @negar raised some interesting issues with our University teaching. An awful lot of really large problems are coded in Fortran, but using the Civil Engineering schools for instance, the Prof wants to be quick and dirty so they teach Python. I had an interesting discussion with one of these students who had just finished the class and he was telling me that it was not necessary to declare variables with a type because they were always promoted to the correct type.
His code had an infinite loop and I pointed out he had made a simple mistake, an interesting discussion occurred where he said that his professor said that it was automatic -- I said you had an error you need to investigate it.
We are creating in interesting world, what happens when all the old Fortran programmers are dead.
Intel should run an International Competition in Fortran - say 100000 for the winner.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page