I have tried the following program with two compilers, and they both
accept it:
program Test_Merge
print *, merge( 1.0, 2.0, (/ .true., .false., .true. /) ) ! 1
print *, merge( (/ 1.0, 2.0 /), (/ 4.0, 5.0 /), .false. ) ! 2
print *, merge( 1.0, (/ 2.0, 3.0 /), .false. ) ! 3
print *, merge( 1.0, (/ 2.0, 3.0 /), .true. ) ! 4
print *, merge( (/ 2.0, 3.0 /), 1.0, .false. ) ! 5
print *, merge( (/ 2.0, 3.0 /), 1.0, .true. ) ! 6
end program Test_Merge
Both print:
1.0000000 2.0000000 1.0000000
4.0000000 5.0000000
2.0000000 3.0000000
1.0000000 1.0000000
1.0000000 1.0000000
2.0000000 3.0000000
with minor variations in spacing.
The standard says the result of MERGE has the same characteristics as
its first argument (TSOURCE), so oughtn't 1, 3 and 4 to produce scalar
results?
I tried varying the size of the first or second argument in #2, and
both compilers objected. I put a 3-element array for third argument
in #3, and both compilers objected.
The obvious interpretation the compilers have put on MERGE is that
all of the arguments that are arrays have to be the same shape, the
result has their shape, and any arguments that are scalars are
broadcast to the same shape as array arguments.
I rather like the way this works, but I suspect it's not a portable
"extension."
Does your compiler accept this? If so, what does it print?
--
What fraction of Americans believe | Van Snyder
Wrestling is real and NASA is fake? | [log in to unmask]
Any alleged opinions are my own and have not been approved or disapproved
by JPL, CalTech, NASA, Dan Goldin, George Bush, the Pope, or anybody else.
|