The proper mechanism to add an external force is to use fix external fix external command — LAMMPS documentation
The proper mechanism to add a time dependent force than can be computed from per-atom properties would be to use fix addforce with an atom style variable (that variable can depend on the time/timestep): fix addforce command — LAMMPS documentation
If you want to modify the source code, then you are free to do it, but then you have to read, learn and understand how LAMMPS works internally. You will not likely find people willing to help you with the rather blunt and very hackish approach that you seem to be looking at.