This thread is now over a decade old, but has been left without a proper closure.

The problem posed by bayes777 is quite reasonable and commonly encountered. Given vector variables x and y, and a vector function F(x,y), one wishes to specify values for y and solve for x, when F and x have the same number of elements, and y has zero or more elements.

The attempts to use NEQNF after packing x and y into a single array, i.e., to define z = [x; y] and call NEQNF to solve F(z) = 0, are not going to work, for the following reason. NEQNF, when called with the F95 interface, assumes that z and F have as many elements, N, as there are coupled equations, and this assumption is not satisfied when the artifice of ignoring some elements of x is used. Secondly, the user-provided FCN routine will be called from NEQNF with different values of x, and FCN must compute N elements of F given N elements of x.

A simple way of solving the problem is to pass the parameter array y to FCN through means other than its argument list. Here, for example, is the example code from https://docs.roguewave.com/imsl/fort....10.10.html%23 , modified to use C(1), C(2) and C(3) in place of 27, 10 and 7 in FCN. The value of C is passed through a module that is USEd in the main program as well as in FCN. The main program sets the values into C, and these values are used in computing F(x,C).

Code:

module params
implicit none
real C(3)
end module
program xneqnf
USE NEQNF_INT
USE UMACH_INT
use params
IMPLICIT NONE
!
INTEGER N
PARAMETER (N=3)
!
INTEGER K, NOUT
REAL FNORM, X(N), XGUESS(N)
EXTERNAL FCN
! Set values of initial guess
! XGUESS = ( 4.0 4.0 4.0 )
!
DATA XGUESS/4.0, 4.0, 4.0/
!
!
CALL UMACH (2, NOUT)
C = [27.0, 10.0, 7.0] ! original values
! Find the solution
CALL NEQNF (FCN, X, xguess=xguess, fnorm=fnorm)
! Output
WRITE (NOUT,99999) (X(K),K=1,N), FNORM
C = [27.0, 10.0, 8.0] ! C(3) is changed from 7 to 8
xguess = x
! Find the solution
CALL NEQNF (FCN, X, xguess=xguess, fnorm=fnorm)
! Output
WRITE (NOUT,99999) (X(K),K=1,N), FNORM
99999 FORMAT (' The solution to the system is', /, ' X = (', 3F9.5, &
')', /, ' with FNORM =', es10.3, //)
!
END
! User-defined subroutine
SUBROUTINE FCN (X, F, N)
use params
INTEGER N
REAL X(N), F(N)
!
REAL EXP, SIN
INTRINSIC EXP, SIN
!
F(1) = X(1) + EXP(X(1)-1.0) + (X(2)+X(3))*(X(2)+X(3)) - C(1)
F(2) = EXP(X(2)-2.0)/X(1) + X(3)*X(3) - C(2)
F(3) = X(3) + SIN(X(2)-2.0) + X(2)*X(2) - C(3)
RETURN
END