0

I want to element wise multiply two arrays A and a sub array of B in fortran(90)

A is 4d and B is 5d. Initially I tried this but the compiler doesn't like it

C(:,:,:,:)=A(:,:,:,:)*B(:,:,:,:,1)

is there an easy way to extract B(:,:,:,:,1) as a 4d array such that I can do the binary operation *?

edit - error message from compiler

tracer1_field(:,:,:,:) = tbase(:,:,:,:,1)*domain(:,:,:,:) ! *12*12*!2 due to grid size.
                              1
Error: Rank mismatch in array reference at (1) (5/4)
4
  • 1
    How did the compiler complain? What was the error message if any? What idiom of Fortran are you using and what compiler and/or compiler options were used? Commented Aug 23, 2017 at 14:26
  • @PierredeBuyl i'll add the error message to the original post. I'm compiling with gfortran at the moment although I may move over to the cray compiler at a later stage. I'm writing it in f90 as that's what the original codebase for the model was written in but I'm relatively new to Fortran so not sure of the differences between idioms Commented Aug 23, 2017 at 14:33
  • 2
    Can you add to the post the declaration lines of the arrays? The error seems to be that tbase is of rank 4 instead of anything else. I'd check that before anything. Commented Aug 23, 2017 at 14:50
  • @PierredeBuyl you're right on checking I'd been putting tbase into the wrong allocation function, thanks! Commented Aug 23, 2017 at 14:55

1 Answer 1

1

The error refers to the rank of the array tbase that is declared with four indices and not five.

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

Comments

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.