- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We used to be able to do this kind of thing (see source code) -
but now the compiler insists on passing an array reference in the second argument (at line 7)
Basically I want to sum N elements of an array, starting at position M.I guess it doesn't like us to pass addresses around anymore.
Is there a way to get around this?
---------------------------------------------------------------------
PROGRAM TEST_SUM
integer(8) a(10),sum,asum
data a/10,9,8,7,6,5,4,3,2,1/
do while (.true.)
print *,"input array position, no. of elements"
read *,ia,na
asum=sum(na,a(ia))
print *,"sum=",asum
end do
end program
integer(8) function sum(nx,x)
integer*2 nx,kk
integer(8) x(1)
sum=0
do kk=1,nx
sum=sum+x(kk)
end do
end function
[bash] [/bash]----------------------------------------------------------------------------------------------
Error 1 error #6361: An array-valued argument is required in this context. [SUM] C:\\Documents and Settings\\William\\My Documents\\Visual Studio 2008\\Projects\\test_sum\\test_sum.F90 7
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SUM is an intrrinsic and is insisting that the first argument be an array. If you want to use your SUM, add EXTERNAL SUM (or make it a contained or module procedure).
You also have a kind mismatch for the NX argument. You should declare na as integer*2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your response -
Actually, that was a watered down example to avoid sending a whole project.
But if SUM is an intrinsic, why doesn't it get highlighted by the editor? I've noticed
that other intrinsics DO get highlighted, such at INT.I noticed the same behavior with Qfloat, for example.
When you pass a literal as an argument, is the compiler smart enough to
know how to type it in the calling sequence, or do I need need to specify it, like
int(2) as opposed to just 2?
Or should I use a DATA stement, i.e
integer(4) Two/2/
Doesn't the compiler have a default typing for literals that can be specified in
compiler properties?
A write-up about this would be very helpful, if not already available somewhere.
BTW, where is this REFRESH command located? I can't find it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The editor's coloring of functions is missing some. I've asked that this be fixed.
If you have an integer of the form 2, it is, as the language defines, "default integer". In Intel Fortran, that is INTEGER(4). If you want any other kind, you have to say so, such as 2_2 (the _2 means "kind 2".) Many people who use multiple kinds declare PARAMETER constants with the kind values, like so:
integer, parameter :: short = SELECTED_INT_KIND(4)
which gives you the smallest kind value that can hold at least 4 decimal digits. Then you could write 2_short.
The standard says that the type and kind of arguments must match. Intel Fortran has an extension where, for integer literal constants being passed to a routine where the kind is known to be different, the constant will be converted quietly. If you ask for standards checking, this will be flagged.
The questions you are asking are all standard Fortran language issues. You may benefit from one of the several good books on the current Fortran language.
I don't understand the reference to REFRESH.

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