< Back

Convert Solution Time Format for Display


Problem:

My solution time is in seconds (ssss.ss), and I want to display it as hours:minutes:seconds (hh:mm:ss.ss).

Solution:

Use a Tecplot macro to loop over time and retrieve the solution time.

Assign the hours, minutes, and seconds to new variables and refer to their max values using dynamic text.

 

Macro Procedure (see link to the GitHub script below):

  • Retrieve the number of time steps:
$!EXTENDEDCOMMAND COMMANDPROCESSORID='extend time mcr'
  COMMAND='QUERY.NUMTIMESTEPS NUMTIMESTEPS'
  • Loop over time:
$!LOOP |NUMTIMESTEPS|
  $!EXTENDEDCOMMAND COMMANDPROCESSORID='extend time mcr'
    COMMAND='SET.CURTIMESTEP |LOOP|'
  [...]
$!ENDLOOP
  • At each time step, retrieve the current solution time:
$!EXTENDEDCOMMAND COMMANDPROCESSORID='extend time mcr'
  COMMAND='QUERY.TIMEATSTEP |LOOP| CURTIME'
  • Calculate the seconds, minutes and hours:
$!VARSET|SECONDS|=(frac(|CURTIME|/60)*60)
$!VARSET|MINUTES|=(int(frac(|CURTIME|/3600)*60))
$!VARSET|HOURS|=(int(|CURTIME|/3600))
  • Assign the results to the variables on the active zones:
$!EXTENDEDCOMMAND COMMANDPROCESSORID='extendmcr'
  COMMAND='QUERY.ACTIVEZONES ZNUM'
$!AlterData  [|ZNUM|]
  Equation = '{Hours}=|HOURS|'
$!AlterData  [|ZNUM|]
  Equation = '{Minutes}=|MINUTES|'
$!AlterData  [|ZNUM|]
  Equation = '{Seconds}=|SECONDS|'
  • Finally, refer to the variables maximums using dynamic text:
$!AttachText
  AnchorPos
    {
    X = 10
    Y = 90
    }
  TextShape
    {
    IsBold = No
    }
  Text = 'Time: &(MAXVAR[|numHours|])h:&(MAXVAR[|numMinutes|])m:&(MAXVAR[|numSeconds|]%.2f)s'

 

Download Convert_SolutionTime.mcr  from our handyscripts GitHub page.

Tip: For faster access, consider placing the macro in your Quick Macro Panel.