In the Fortran module, I have a function that takes an array and its name, receives from the database (actually calls the C function) the shape of the array, copies the array in a temporary buffer and passes the buffer to another C that processes it. This Fortran function has the name fs_WriteData_i for integer data, fs_WriteData_f for real and fs_WriteData_d for double precision. All these functions accept not only one-dimensional arrays, but also 2D, 3D and 4D arrays, and they work great. Here follows the interface of one of these routines:
subroutine fs_WriteData_d(fieldname, data) use, intrinsic :: iso_c_binding implicit none real(c_double), dimension(*) :: data character :: fieldname*(*) ! ... end subroutine fs_WriteData_d
If the user calls fs_WriteData_d('name', data) when the data is double precision, up to a 4-dimensional array, this routine does the job.
Now, to the question: I want to provide a common overloaded interface named fs_WriteData, so I use
interface fs_WriteData module procedure fs_WriteData_i, & fs_WriteData_f, & fs_WriteData_d end interface fs_WriteData
Unfortunately, this will not work: the compiler states that it cannot find the correct implementation if the user simply calls fs_WriteData('name', data) , and this is due to the rank mismatch with all these functions.
Is there any reasonable way to avoid writing all the fs_WriteData_d_1d, fs_WriteData_d_2d, ... subroutines with the same content to make the module more convenient to maintain?
Thank you very much in advance.