PROGRAM a
REAL::b
open (2,file="INPUTS.txt",action="read",status="OLD")
open (3,file="OUTPUTS.txt",action="write",status="REPLACE")
DO i= 1,9,2
READ(2,*)b
READ(2,*)
WRITE(3,*)(b)
END DO
b=0
DO i= 1,5
WRITE(3,*) b
END DO
CLOSE(2)
CLOSE(3)
END PROGRAM
That's just a case of swapping the order of the two reads, so that the second read is the one that stores b.
do i= 1,9,2
READ(2,*)
READ(2,*)b
WRITE(3,*)(b)
END DO
There's probably a nice clever way to do this with an if statement so you can switch back and forth between the two options, but...
Hmm. It works for me. The only way I can get an error to appear is if my INPUTS.txt file only has 9 lines of data. You'll need a 10th otherwise it runs off the end of the file with the second read.
The problem you have is that all you have done with the stride of 2 is turn a loop of 40 indexes to one of 20. The read will still read each line in turn and then write them out, so you'll just get the first 20 lines in the file. You could change the loop to this:
do i= 1,40,2
READ(2,*)b...
Hi.
Thanks for the replies. xwb, your first suggestion of setting it as a target seemed to do the trick.
Your longer example just segfaults for me when it tries to access the data within the type.
salgerman, yes, it's all common source code.
We're writing two libraries that share a lot of...
Hi.
I have a piece of code that has several libraries sharing a common code base. The libraries are compiled from this common base plus their own bits of unique code.
One piece of data that all the libraries share is a "Phase Type", a derived type containing several common pieces of data...
Hi.
One of our users is having a problem and I'm a bit stumped as well. They're trying to pass a pointer component of a derived type into a subroutine and treating it as a normal array at the other end. However the data is ending up as garbage.
Is this legal?
module mod
type deriv...
Hi there,
I've got a bit of code that I've been given to work on. It uses a structure constructor to initialise a derived type, but it uses a function within the constructor to set a pointer.
Is it legal to do this ? I'm getting different results on different compilers (Intel's compiler is...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.