I had a question about the correct way of programming user-defined operators in Fortran. To be more specific, I will provide the example of my problem. I am working on creating a user-defined data type for spherical particles called 'Particle'. I want to define an operator that takes an existing array of Particle objects and adds a new Particle object to it. I was wondering how I would go about defining user defined operators to do such an action.
Currently I have, within the type definition for Particle, the following lines:
procedure, public:: addNewParticleTo
generic:: operator(.spawn.) => addNewParticleTo
Following which, I have a subroutine that is defined as follows:
subroutine addNewParticleTo(a_LHS, a_RHS)
implicit none
class(Particle), dimension(:), allocatable, intent(in):: a_LHS
class(Particle), dimension(:), allocatable, intent(inout):: a_RHS
<rest of the code>
end subroutine addNewParticleTo
I intend for the operator to be invoked as:
particle .spawn. particleArray
I was wondering if this is the correct way to go about doing this. Any suggestions or advise on this will be very helpful.