0

I wish to check if one 2D array contains a value from other 1D array.

   do i=1,nlines
   do j=1,nchecks(i)
   if (type(i).eq.4) then
   do k=1,nlines
   do l=1,nchecks(k)
   if (type(k).eq.3) then
   if (ANY(con(i,j)==id(k))) then
   ...

But I face following error:

test1.f(98): error #6361: An array-valued argument is required in this context.   [ANY]
       if (ANY(conn(i,j)==id2(k))) then

What am I doing wrong? I also tried something like

   do i=1,nlines
   do j=1,nchecks(i)
   if (type(i).eq.4) then
   r1=conn(i,j)
   do k=1,nlines
   do l=1,nchecks(k)
   if (type(k).eq.3) then
   if (ANY(r1==id(k))) then
   ...

But this also brought the same error. All variables are properly defined, and no mistakes in format. Am I using ANY command in wrong way?

9
  • 1
    Yes, you are using ANY incorrectly. At the moment you are just testing individual scalar elements of the arrays, so no ANY required. However, we don't know what's in the loops so it's impossible to know what you really want to do. Also, you can probably hoist those if tests on i and k outside the inner j and l loops respectively and/or reorder the loops by the looks. Commented Apr 24, 2020 at 3:22
  • 1
    Second @RussF, also please don't say "All variables are properly defined", show them - variable declarations are vital to understanding a problem. But by far best, as RussF implies, is to show a short, complete program which displays the problem you are having Commented Apr 24, 2020 at 6:37
  • This - stackoverflow.com/questions/29631649/… - may be useful. It may even be a duplicate but I haven't checked closely. Commented Apr 24, 2020 at 7:20
  • No, it's not a duplicate, but it is closely related Commented Apr 24, 2020 at 8:05
  • 1
    Well, looks like the smilers are winning right now @IanBush, the question's been reopened :-) Commented Apr 24, 2020 at 11:46

1 Answer 1

2

Your problem is that ANY is a reduction operation, it takes many values stored in a logical array and reduces them down to a single value, in this case the value .True. is any of the values in the array are true, or .False. if all of them are false. Here's a very simple example

ian@eris:~/work/stack$ cat any.f90
Program Any_test

  Implicit None

  Write( *, * ) Any( [ .True. , .False. ] )
  Write( *, * ) Any( [ .False., .False. ] )

End Program Any_test

ian@eris:~/work/stack$ gfortran -std=f2008 -Wall -Wextra -fcheck=all any.f90 
ian@eris:~/work/stack$ ./a.out
 T
 F

Your immediate problem is that you are just providing ANY with a scalar value, not an array, hence the error. Simply

if (r1==id(k)) then

will fix the immediate problem.

But there is a probably way in here where you could use ANY, and this might be the best way to address what you are doing. However without the rest of the code including the variable declarations it is impossible to say.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.