Array initialization inside function to be called repeatedly I have written a Fortran95 function that will be called many times in a loop.  A much reduced version of it, called myFunction, is below.  Examples of its use is the fitting of data points to this function, or numerical integration of this function.  This function is part of a small module myFunctionCollection, which can be called from the user's main program.
My worry is that I am reinitializing the local variables arrayIn1, arrayIn2, ... arrayOut3 each time it is called during runtime, and will be unnecessarily slow down the whole calculation.  Is my worry unfounded?  Or, how can I rewrite this function inside the module so that it can more efficiently be called repeatedly, without reinitializing everything over and over again?
MODULE myFunctionCollection

USE bigFatPackage   ! contains bigFatSubroutine
IMPLICIT NONE

CONTAINS

DOUBLE COMPLEX FUNCTION myFunction(a,b,c,d)

  DOUBLE COMPLEX, INTENT(IN) :: a,b,c,d
  DOUBLE COMPLEX :: arrayIn1(7), arrayIn2(7), arrayIn3(7)
  DOUBLE COMPLEX :: arrayOut1(7), arrayOut2(7), arrayOut3(7)

  arrayIn1(1:7) = (/a, a+b, c, c+d, a+d, c+d, d**2/)
  arrayIn2(1:7) = (/a**2, a-b, c, c-d, a-d, dcmplx(0d0,0d0), d**2/)
  arrayIn3(1:7) = (/a**2, (a+b)**2, c, c, c, dcmplx(0d0,0d0),dcmplx(0d0,0d0)/)

  CALL bigFatSubroutine(arrayOut1, arrayIn1, 7, 7)
  CALL bigFatSubroutine(arrayOut2, arrayIn2, 7, 7)
  CALL bigFatSubroutine(arrayOut3, arrayIn3, 7, 7)

  myFunction = arrayOut1(6) + 2d0*arrayOut2(7) + (1/2d0)*arrayOut3(2) + !... more

END FUNCTION

END MODULE

Any further suggestions on coding style is welcome!
In your function myFunction, you are initializing the vectors arrayIn* with values that depend on all the input parameters a, b, c, d, so it is unclear why you claim that you are needlessly &quot;reinitializing&quot; them at each call. If the function is true to its name, as it should, one would assume that the input parameters would change from call to call, in which case recomputing arrayIn* is not optional.
If, on the other hand, the parameters a, b, c, d are indeed invariant from call to call, but the result of the function changes nonetheless due to some hidden dependencies, then you should:

make the dependencies explicit (&quot;despaghettify&quot; your code)
initialize arrayIn* separately from the function call, e.g., through a call to an init subroutine.

For example:
MODULE myFunctionCollection

  USE bigFatPackage   
  IMPLICIT NONE
  private

  DOUBLE COMPLEX :: arrayIn1(7), arrayIn2(7), arrayIn3(7)
  public :: myFunction
  
CONTAINS

  subroutine myInit(a,b,c,d)
    DOUBLE COMPLEX, INTENT(IN) :: a,b,c,d
    arrayIn1(1:7) = (/a, a+b, c, c+d, a+d, c+d, d**2/)
    arrayIn2(1:7) = (/a**2, a-b, c, c-d, a-d, dcmplx(0d0,0d0), d**2/)
    arrayIn3(1:7) = (/a**2, (a+b)**2, c, c, c, dcmplx(0d0,0d0),dcmplx(0d0,0d0)/)
  end subroutine myInit
    
  DOUBLE COMPLEX FUNCTION myFunction( FormerlyHiddenParameter )
    DOUBLE COMPLEX, INTENT(IN) :: FormerlyHiddenParameter
    CALL bigFatSubroutine(arrayOut1, arrayIn1, 7, 7, FormerlyHiddenParameter )
    CALL bigFatSubroutine(arrayOut2, arrayIn2, 7, 7, FormerlyHiddenParameter )
    CALL bigFatSubroutine(arrayOut3, arrayIn3, 7, 7, FormerlyHiddenParameter )
    myFunction = arrayOut1(6) + 2d0*arrayOut2(7) + (1/2d0)*arrayOut3(2) + !... more
  END FUNCTION myFunction

end MODULE myFunctionCollection

Finally, the operations that you are trying not to repeat are computationally very cheap, and it is unclear if you save much time, compared to the time required to execute bigFatSubroutine [sic!]. Chances are that the speed up would be negligible. To identify the real bottlenecks in your code, you should measure the duration of its parts. The rest of the code should be improved for readability, maintainability, extensibility, usability, etc. etc. Any change that increases complexity with no real gain in efficiency should be avoided.
PS: For readers not familiar with the simple syntax of modern Fortran, I suggest the following quick modern Fortran tutorial.