Others will comment on standard conformance.
I'd write a subroutine with two optional,
so that you can pass either array or both, e.g.:
program test
integer :: ie,je,ke
real, allocatable :: field2d(:,:)
real, allocatable :: field3d(:,:,:)
ie=2; je=2; ke=2
allocate( field2d(ie,je), source = 0.0 )
allocate( field3d(ie,je,ke), source = 0.0 )
call lbc( optfld2=field2d )
write (*,*) "only field 2", field2d, field3d
call lbc( optfld3=field3d )
write (*,*) "only field 3", field2d, field3d
call lbc( field2d, field3d )
write (*,*) "both fields", field2d, field3d
contains
subroutine lbc( optfld2, optfld3 )
real, intent(inout), optional, allocatable :: optfld2(:,:), optfld3(:,:,:)
if ( present(optfld2) ) field2d = 1.0
if ( present(optfld3) ) field3d = 1.0
end subroutine lbc
end program test
$ ./a.out
only field 2 1.000000 1.000000 1.000000 1.000000
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00
0.0000000E+00 0.0000000E+00 0.0000000E+00
only field 3 1.000000 1.000000 1.000000 1.000000
1.000000 1.000000 1.000000 1.000000 1.000000
1.000000 1.000000 1.000000
both fields 1.000000 1.000000 1.000000 1.000000
1.000000 1.000000 1.000000 1.000000 1.000000
1.000000 1.000000 1.000000
$
Anton
|