Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

A lot of parameters to be passed in subroutine

$
0
0

Hello,

Would you please advise me how it is better to write code in fortran.
In my programs I use many subprograms like this:

 pure subroutine SofcElStateUpdate( &
    ! input
    OptionTerm, ActiveAreaCm2, ElThick, AnSigmaP, CtSigmaP, OhmCoeff, OhmTMult,   & 
    CtActivCoeff1, CtDiffCoeff1, OhmConstCm2, T, FuelP, FuelMFrac, OxidantP,   & 
    OxidantMFrac, OptionCalc, FuelG, OxidantG, &
    ! output
    AnGasP, AnGasG, AnGasMFrac, CtGasP, CtGasG, CtGasMFrac, Alpha,   & 
    YSZConduction, MeanPO2Ct, MeanPInertCt, OhmCm2YSZ, OhmCm2Rest, OhmCm2CtActiv, OhmCm2CtDiff,   & 
    EMF0, EMF, VoltLossYSZ, VoltLossRest, VoltLossConst, VoltLossCtActiv, VoltLossCtDiff,   & 
    VoltLossMass, Volt, Current, CurrentLim, CurrentCm2, CurrentCm2Lim, CurrentCm2LimDiff,   & 
    Pow, PowCm2, DeltaH, DeltaS, DeltaG, KPDTerm, KPDVolt,   & 
    RInner, RLoad, KR, QHeat, QHeatEntropy, QHeatOhm, SGasUtil,  O2Util, O2ElToAnIn )
  real, intent(in) :: &
    OptionTerm, ActiveAreaCm2, ElThick, AnSigmaP, CtSigmaP, OhmCoeff, OhmTMult,   & 
    CtActivCoeff1, CtDiffCoeff1, OhmConstCm2, T, FuelP, FuelMFrac, OxidantP,   & 
    OxidantMFrac, OptionCalc, FuelG, OxidantG
  real, intent(out) :: &
    AnGasP, AnGasG, AnGasMFrac, CtGasP, CtGasG, CtGasMFrac, Alpha,   & 
    YSZConduction, MeanPO2Ct, MeanPInertCt, OhmCm2YSZ, OhmCm2Rest, OhmCm2CtActiv, OhmCm2CtDiff,   & 
    EMF0, EMF, VoltLossYSZ, VoltLossRest, VoltLossConst, VoltLossCtActiv, VoltLossCtDiff,   & 
    VoltLossMass, Volt, Current, CurrentLim, CurrentCm2, CurrentCm2Lim, CurrentCm2LimDiff,   & 
    Pow, PowCm2, DeltaH, DeltaS, DeltaG, KPDTerm, KPDVolt,   & 
    RInner, RLoad, KR, QHeat, QHeatEntropy, QHeatOhm, SGasUtil,  O2Util, O2ElToAnIn
    .......
end subroutine 

As you can see there is a lot of variables to be passed to the subprogram. Moreover there is
a need to repeat declaration of all variables. Logically it would be better if fortran let the following form of declaration:

 pure subroutine SofcElStateUpdate( &
  real, intent(in) :: &
    OptionTerm, ActiveAreaCm2, ElThick, AnSigmaP, CtSigmaP, OhmCoeff, OhmTMult,   & 
    CtActivCoeff1, CtDiffCoeff1, OhmConstCm2, T, FuelP, FuelMFrac, OxidantP,   & 
    OxidantMFrac, OptionCalc, FuelG, OxidantG,
 
  real, intent(out) :: &
    AnGasP, AnGasG, AnGasMFrac, CtGasP, CtGasG, CtGasMFrac, Alpha,   & 
    YSZConduction, MeanPO2Ct, MeanPInertCt, OhmCm2YSZ, OhmCm2Rest, OhmCm2CtActiv, OhmCm2CtDiff,   & 
    EMF0, EMF, VoltLossYSZ, VoltLossRest, VoltLossConst, VoltLossCtActiv, VoltLossCtDiff,   & 
    VoltLossMass, Volt, Current, CurrentLim, CurrentCm2, CurrentCm2Lim, CurrentCm2LimDiff,   & 
    Pow, PowCm2, DeltaH, DeltaS, DeltaG, KPDTerm, KPDVolt,   & 
    RInner, RLoad, KR, QHeat, QHeatEntropy, QHeatOhm, SGasUtil,   & 
    O2Util, O2ElToAnIn   )
     
    .......
end subroutine 

In this form there is no duplicating of variable declaration.

However the problem is as following:

Using pure procedures and implicite declaration as well as atributes like intent(in) intent(out) let compose safe programs. Compiler can warn that all output data will be initialized, that all input data will be not changed and so on. And if the subroutine is called as:

 call SofcElStateUpdate( OptionTerm = 1, ActiveAreaCm2 = ActiveAreaCm2, ElThick = ElThick , AnSigmaP = SigmaP, &
                       CtSigmaP = SigmaP  ..... )  

so it is guaranteed that all variables are positioned correctly.

But what is to do with so many variables in the interface of the subroutine?
Is it a bad practice to use such subprograms with a lot of variables to be passed?
I now that using types (structures) or global variables leads to the fact that no more garanty can be given if all input data are initialized, if all output data became defined and so on.

thanks in advance.


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>