Calling several functions inside a function?

Hi everyone.
I was wondering if you guys can point me in the right direction here. I have quite a few functions with a bunch of inputs and outputs. I just wanted to make one that would help me organize them. The inner functions do not communicate properly with each other. I keep getting that the outputs of “fix_SWF_input” cannot be read by the following functions.

All the functions are inside the same file…

Any ideas?

function SW_Disp(Model,FEM_MESH,T0,Tstep,TF,Nmodes,Earth,Elastic,Anisotropy)

println("Forfward modelling ",Nmodes," Surface Wave Modes")
# Prepare Inputs
fks,Mesh,vpv,vsv,vsv_v,vsv_h,rhov,qsv,qR,Nsolid,hsolid,Nfluid,hfluid,vpfluid,vpfv,rhofv = fix_SWF_input(TF,Tstep,T0,FEM_MESH,Model,Elastic,Anisotropy);
# Compute de Dispersion for R Wave
kkR, cR, UR, evR = Rayleigh_Forwardsp(Nsolid,vsv_v,vpv,rhov,fks,hsolid,Nmodes,Nfluid,vpfv,rhofv,hfluid,qsv,Earth,Elastic);
println("Running: R wave dispersion")
# Compute de Dispersion for L Wave
kkL, cL, UL, evL = Love_Forwardsp(Nsolid,vsv_h,rhov,fks,hsolid,Nmodes,qsv,Earth,Elastic);
println("Running: L wave dispersion")
# Organize the Outputs
T, SWV,EG_FUNC_R_Z, EG_FUNC_R_R, EG_FUNC_L = fix_SWF_output(cR, UR, evR, cL, UL, evL, fks);
println("Done!")

##
return T, SWV,EG_FUNC_R_Z, EG_FUNC_R_R, EG_FUNC_L

end

I think that it would be a good idea to combine your variables into types, probably structs. Then, you can move objects with clear names around instead of having to fall back to such long lists of variables and parameters.

Depending on how well the code is documented, so how clear it is what, for example, cL means, you might also want to use longer variable names.

2 Likes

Or use ComponentArrays!! :slight_smile:

1 Like