In my codes there is much boilerplate checking that array arguments have consistent dimensions. For arguments that are OPTIONAL I first have to check that they are PRESENT before verifying that their dimensions are correct. Should a CONFORM function be added to Fortran or the stdlib project? It would have return type logical and take two array arguments of the same rank (but possibly of different types) It would return .TRUE. if the arrays have the same dimensions or if either array is not PRESENT (to avoid requiring the user to check this). I can code CONFORM myself for a few cases, but an intrinsic function would work for arbitrary ranks and types. With the proposed CONFORM function, one could write for example
subroutine regress(x,y,coeff,tstat,resid,ierr)
! regress each column of y(:,:) on x(:,:)
real , intent(in) :: x(:,:) ! (n,nindep)
real , intent(in) :: y(:,:) ! (n,ndep)
real , intent(out) :: coeff(:,:) ! (nindep,ndep)
real , intent(out), optional :: tstat(:,:) ! (nindep,ndep)
real , intent(out), optional :: resid(:,:) ! (n,ndep)
integer, intent(out) :: ierr
if (.not. conform(yy,resid)) then
ierr = 1
else if (.not. conform(coeff,tstat)) then
ierr = 2
end if
if (ierr /= 0) return
end subroutine regress
instead of
subroutine regress(x,y,coeff,tstat,resid,ierr)
! regress each column of y(:,:) on x(:,:)
real , intent(in) :: x(:,:) ! (n,nindep)
real , intent(in) :: y(:,:) ! (n,ndep)
real , intent(out) :: coeff(:,:) ! (nindep,ndep)
real , intent(out), optional :: tstat(:,:) ! (nindep,ndep)
real , intent(out), optional :: resid(:,:) ! (n,ndep)
integer, intent(out) :: ierr
if (present(tstat)) then
if (any(shape(tstat) /= shape(coeff))) then
ierr = 1
return
end if
end if
if (present(resid)) then
if (any(shape(resid) /= shape(y))) then
ierr = 2
return
end if
end if
end subroutine regress