Hi everyone,

I'm currently working with a complex model that contains many interconnected functions.

1) At some point, I call the function rk4.m:

`[TS.T, rk1_T, V1T, H1T, X1T, rk2_T, V2T, H2T, X2T, rk3_T, V3T, H3T, X3T, rk4_T, V4T, H4T, X4T, srf_Tflx1, sol_Tflx1, srf_Tflx2, sol_Tflx2, srf_Tflx3, sol_Tflx3, srf_Tflx4,... sol_Tflx4] = rk4(@mixtracerTS_ode, it, TS.T, In, Grd, VMxng.Mld, VMxng.Entrnmnt, LB.tmp, TS.Sig, Wnd.Tauy2, P, 'sflux', Ht.Qi, Ht.airtmp, Ht.dewptT, Wnd.Wspd10,... Ht.Qo,'source',Ht.Qi);`

rk4.m is defined as follows:

`function [y1, k_1, V1, H1, X1, k_2, V2, H2, X2, k_3, V3, H3, X3, k_4, V4, H4, X4, varargout] = rk4(ode, it, y0, In, Grd, varargin)`

2) Inside rk4.m, I call several times the function ode / mixtracerTS_ode.m. For instance, the first time:

`[k_1, V1, H1, X1, srf_Tflx1, sol_Tflx1] = ode(Grd.time(it), y0, In, Grd, varargin {:});`

mixtracerTS_ode.m is defined as follows:

` function [dxdt, V, H, X, varargout] = mixtracerTS_ode(time, tracer, In, Grd, mld, ent, lb, Sig, tauy, prate, varargin)`

a) mandatory output arguments are calculated thanks to other functions:

` V = verticalmixing(tracer, Grd, mld, ent, In, time); H = horizontalmixing(tracer, Grd, mld, lb, In, time); X = advection(tracer, lb, In, Grd, mld, tauy, Sig, prate, time); dxdt = V+ H+ X;`

b) portion to calculate varargout / srf_Tflx1 & sol_Tflx1:

` nArgs=length(varargin); if nArgs >0 opt = varargin(cellfun(@ischar,varargin)); if any(ismember(opt, {'sflux'})) Ht.Qi=varargin{2}; Ht.airtmp=varargin{3}; Ht.dewptT=varargin{4}; Wnd.Wspd10=varargin{5}; Ht.Qo=varargin{6}; ....... ....... calculation of srf_Tflx ...... varargout{1}=srf_Tflx; end opt = varargin(cellfun(@ischar,varargin)); if any(ismember(opt, {'source'})) Ht.Qi=varargin{8}; ...... ...... calculation of sol_Tflx ....... ....... varargout{2}=sol_Tflx; end end`

I get this error message:

`One or more output arguments not assigned during call to "varargout"Error in rk4 (line 39)[k_1, V1, H1, X1, srf_Tflx1, sol_Tflx1] = ode(x(it), y0, In, Grd, varargin {:});`

I really can't figure this out especially because everything works fine when I run my functions from the command window with appropriate inputs!! For example, the first function to be called

[TS.T, rk1_T,……, sol_Tflx4]=rk4(@mixtracerTS_ode, …. , Ht.Qi) gives me the expected outputs. But when I run the entire model, I get the above error message.

Any help from you would be much appreciated !!

Many thanks in advance.

## Best Answer