Check out the S-function Builder
block from Simulink's library (in Simulink->User Defined Functions). You can set number of states, inputs, outputs and also add code for calculating the derivatives + outputs. When you press Build
it generates C
code and you can start with that as a template. Or you could use the S-function Builder
interface for writing all your code.
Edit: Matlab also has a built-in template that you can access:
edit([matlabroot,'/simulink/src/sfuntmpl_basic.c']);