DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting values smaller than the desired increment

Solved!
Go to solution

Hello,

 

when performing a multibody simulation with a fix step size I recieve in the output data some additional values smaller than the normal increment or the values are duplicated. The time-channel looks like:

 

0

0.0002738

0.001

0.002

0.002

0.003

0.004

....

 

I think with a simple script I can delete the additional valuues (here 0.0002738, 0.002).

E suggest this code, but It doesn't work:

  Dim timechannel,i, dif 
  
  timechannel = "[1]/TIME"
   
  i = 2
  Do while i < (Val(ChnPropGet(timechannel, "length"))-1)
    dif = CHD(i,timechannel) - CHD(i-1,timechannel)
        
    if dif = 0.001 then
      MsgBox("i="& Str(i) & " Wert:  " & CHD(i, timechannel) & " i-1=" & Str(i-1) & "Wert: " & CHD(i-1, timechannel) & " dif= " & Str(dif))
      i = i+1     
    else     
      MsgBox("i="& Str(i) & " Wert:  " & CHD(i, timechannel) & " i-1=" & Str(i-1) & "Wert: " & CHD(i-1, timechannel) & " dif= " & Str(dif) & " ->DELETE")
      Call DataBlDel(timechannel,i,1) '... ChnNoStr,ChnRow,ValNo,ValDelOnly
    end if
  loop

 

 The problem is that sometimes the variable dif recieves the value 0.001 but anyway the value at this position is deleted. I don't know why.

I addedthe script and simulation data.

 

Thanks for help

Gabriel

0 Kudos
Message 1 of 5
(3,795 Views)

Hello fischerg,

 

I think there is a more efficient way to do this. What version of DIAdem are you using ?

Or better, what is the oldest version of DIAdem this script should work with?

 

Andreas

0 Kudos
Message 2 of 5
(3,794 Views)

Hello,

 

I use DIAdem 11.0. Sometimes I use 10.0, but it's not necessary that your solution works with this.

I'm curious what you suggest.

 

Gabriel

0 Kudos
Message 3 of 5
(3,790 Views)
Solution
Accepted by topic author fischerg

Hello Fischerg,

 

let me know how this works:

 

Option Explicit
Dim   timechannel,CLength,CNumber,dBase,Epsilon,Limit,K,CurrValue,Delta

timechannel = "[1]/TIME"
CLength     = Val(ChnPropGet(timechannel, "length"))
CNumber     = CNo(timechannel)

Epsilon     = 0.00001
Limit       = 0.001 - Epsilon


dBase = CHDx(1,CNumber)
For K = 2 To CLength
  CurrValue = CHDx(K,CNumber)
  Delta     = CurrValue-dBase
  ' Compare using Epsilon value. Comparing float numbers
  ' with "=" doesn't always work
  If ( Delta < Limit ) Then
    CHDx(K,CNumber) = NULL
  Else
    ' Set new base
    dBase = CurrValue
  End If
Next
Call ChnCharacter(timechannel)
' remove tagged values. If there are more channels in parallel to the "TIME" channel,
' those can be adjusted with the same call. See ChnNovHandle online help for details
Call ChnNovHandle(timechannel,"","Delete","X",1,1,0)

0 Kudos
Message 4 of 5
(3,786 Views)

Hello Andreas,

 

Thank you, it works very well. 

Gabriel

0 Kudos
Message 5 of 5
(3,782 Views)