-2

I am working with a Fortran 90 program that, amongst many others, has the following variables declared:

real(r8) :: smp_node_lf
real(r8), pointer :: sucsat(:,:)
real(r8), pointer :: h2osoi_vol(:,:)
real(r8), pointer :: watsat(:,:)
real(r8), pointer :: bsw(:,:)

And at some point in the program, there is an algebra operation that looks like this:

do j = 1,nlevgrnd
   do c = 1,fn
      ...
      smp_node_lf = -sucsat(c,j)*(h2osoi_vol(c,j)/watsat(c,j))**(-bsw(c,j))
      ...
   end do
end do

I am trying to "translate" a dozen lines of this program to R, but the above excerpt in particular made me confused.

What is the dimension of smp_node_lf? Is it an scalar? Does it inherit the dimensions of the arrays sucsat,h2osoi_vol,watsat and bsw?

thiagoveloso
  • 2,537
  • 3
  • 28
  • 57
  • 2
    It may or may not be a scalar. Without a full example it isn't possible to tell. Assuming it is a scalar, why do you find it confusing? Note that the expression on the right-hand side appears to be scalar. – francescalus Mar 15 '18 at 21:53
  • 1
    Given it's declaration, `smp_node_lf` is a scalar as far as I can tell. What's confusing you about this operation? A bunch of array components (each a scalar) in some math operation. – Ross Mar 16 '18 at 00:35
  • @francescalus What confuses me is the lack of dimensions in `smp_node_lf` . Is it `c` x `j`? Let's say the index `j` represents soil layers and that `c` represents vegetation types. Let's say I want to print `smp_node_lf` values for j=1 and c=1 *after the loop*. Would this be possible? Had it been declared with dimensions (:,:) like the other variables, accessing its indices would be straightforward, but I am confused with it being adimensional. – thiagoveloso Mar 16 '18 at 01:18
  • 1
    @thiagoveloso there are two issues with your question: 1. You don't know whether the code works or not, so there is no "problem" and hence no solution to propose and 2. We cannot make any definite claim unless we have a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Pierre de Buyl Mar 16 '18 at 08:22

1 Answers1

1

There is a lack of dimensions for smp_node_lf because it is a scalar, and it is receiving the value of that scalar operation multiple times, being rewritten, if there is nothing to save its value to a vector or something.

It will never inherit the dimensions of any of those elements, there is never a vector to be inherited, everything it is receiving is scalar

if you have to retrieve its value, assuming the original code is capable of it as it is, there should be another part inside this very loop that saves that value before it is overwritten by another pass. If there is not such thing, implement it, you might be dealing with incomplete code that does nothing it was said to do.

I've dealt with my fair share of "perfect code" that "did miracles when I used last time" with not a single miracle to be found within its lines of code.

Macaduru
  • 26
  • 1
  • 2
    For completeness, one cannot be sure that `smp_node_lf` is a scalar. A `dimension smp_node_lf(7,23,1,5)` somewhere else may exist. – francescalus Mar 16 '18 at 06:04