08-25-2009 05:17 AM
Hello... bit of a longer one this.
I've used the script kindly posted by ChristianW ages back, and modified it to go through a mass of channels and create a group for each one, then do a rainflow analysis, and create a range-mean matrix. It works fine on the first channel, and then puts in 0 for all the other channel's matrices.
The original script is here...
http://forums.ni.com/ni/board/message?board.id=60&message.id=6159
Then my modified version is as below....
Any thoughts?
Thankyou!!!!!!
Tom
Option Explicit
sub ConvertFromTo2RangeMean(ChX,ChY,ChZ,x)'original subroutine
Dim clx, cly, clz, bError, i, j, Delta, myValue, xi, yi, oldValue
Call GroupDefaultSet(x) ' I added this line in to make sure we stay in the right group... made no other changes within the subroutine, all the other changes are at the main program at the bottom
if (ChX<=0) or (ChY<=0) or (ChZ<=0) then
exit sub
end if
clx=Cl(ChX) 'From
cly=Cl(ChY) 'To
if (clx<2) or (cly<2) or (clx<>cly) then
exit sub
end if
bError=false
for i=0 to clx-1
clz=cl(ChZ+i)
if clz<>clx then
bError=true
end if
next
if bError then
exit sub
end if
'create range vector
Delta= ChD(2,ChX)-ChD(1,ChX)
call ChnAlloc("Range",clx)
for i=1 to clx
ChD(i,"Range")= (i-1)*Delta
next
'create mean vector
call ChnAlloc("Mean",cly)
for i=1 to cly
ChD(i,"Mean")= chd(i,chx)
next
'create matrix
for i=1 to clx
call ChnAlloc("Z"&i,clx)
cl("Z"&i)=clx
next
'initialize matrix
for i=1 to clx
for j=1 to cly
Chd(i,"Z"&j)=0
next
next
for i=1 to clx
for j=1 to cly
if i<>j then 'No countings on the diagonal
myValue = Chd(i,ChZ+j-1)
if myValue<>0 then 'Any counting?
xi=abs(j-i)+1 'Range
yi=round(abs(j+i)/2+0.49) 'Mean (will be counted class wise ==> mean 3.5 is in class 4)
oldValue = Chd(xi,"Z"&yi)
Chd(xi,"Z"&yi)=oldValue+myValue
end if
end if
next
next
end sub
'------------------------------------------------------------------------------------------
' Modification to script....
'------------------------------------------------------------------------------------------
Dim x
dim j
Dim nameofgroup
Dim nGlobUsedChn
for x=2 to 5
'GroupChnCount(1)
Call GroupDefaultSet(1)
nameofgroup=ChnName(x)
Call GroupCreate(nameofgroup,x) '... GroupCreateName,TargetGroupIndex '... TargetGroupIndex
Call ChnClpCopy("[1]/["&x&"]") '... ClpSource
Call GroupDefaultSet(x)
Call ChnClpPaste(ChnNoMax+1) '... ClpTarget
Call GroupDefaultSet(x) 'make sure we are deleting the right channels
nGlobUsedChn = GlobUsedChn
' ClassMeth2 ="Automatic"
' ClassNo =30
' RainResiduumCalc =0
' RainFrequencyTyp ="Cumulative"
' RainChnContain ="Class mean"
' Hysteresis =0
' RainMatTrans(1) =0
' RainMatTrans(2) =1
' RainOneParaCalc(1)=0
' RainOneParaCalc(2)=0
' RainOneParaCalc(3)=0
' RainOneParaCalc(4)=0
' RainSpecOnePara(1)=0
' RainSpecOnePara(2)=0
' RainSpecOnePara(3)=0
' RainSpecOnePara(4)=0
Call ChnRainCalc(ChnNoMax,"Automatic",0,0,"Cumulative") '... Y,ClassMeth2,RainResiduumCalc,Hysteresis,FrequencyPara
Call ConvertFromTo2RangeMean(nGlobUsedChn+1,nGlobUsedChn+3,nGlobUsedChn+3,x)
'delete excess channels
' Call GroupDefaultSet(x) 'make sure we are deleting the right channels
' Call ChnDelete("ResidueStartClasses")
' Call ChnDelete("ResidueTargetClasses")
' Call ChnDelete("RainflowMatrixX")
' Call ChnDelete("RainflowMatrixY")
' for j = 1 to ClassNo
' Call GroupDefaultSet(x) 'make sure we are deleting the right channels
' Call ChnDelete("RainflowMatrixZ"&j)
' next
nGlobUsedChn = 0
next
Solved! Go to Solution.
08-26-2009 03:00 AM
Aha, solved it.
The problem was that multiple channels had the same name, so now I'm specifying a new name each time the subroutineruns.
Tom
08-26-2009 03:47 AM
Hello Tom,
this modification of your script should run:
Option Explicit
sub ConvertFromTo2RangeMean(ChX,ChY,ChZ,x)'original subroutine
Dim clx, cly, clz, bError, i, j, Delta, myValue, xi, yi, oldValue
Call GroupDefaultSet(x) ' I added this line in to make sure we stay in the right group... made no other changes within the subroutine, all the other changes are at the main program at the bottom
if (ChX<=0) or (ChY<=0) or (ChZ<=0) then
exit sub
end if
clx=Cl(ChX) 'From
cly=Cl(ChY) 'To
if (clx<2) or (cly<2) or (clx<>cly) then
exit sub
end if
bError=false
for i=0 to clx-1
clz=cl(ChZ+i)
if clz<>clx then
bError=true
end if
next
if bError then
exit sub
end if
'create range vector
Delta= ChD(2,ChX)-ChD(1,ChX)
call ChnAlloc("Range",clx)
for i=1 to clx
ChD(i,"/Range")= (i-1)*Delta
next
'create mean vector
call ChnAlloc("Mean",cly)
for i=1 to cly
ChD(i,"/Mean")= chd(i,chx)
next
'create matrix
for i=1 to clx
call ChnAlloc("Z"&i,clx)
cl("/Z"&i)=clx
next
'initialize matrix
for i=1 to clx
for j=1 to cly
Chd(i,"/Z"&j)=0
next
next
for i=1 to clx
for j=1 to cly
if i<>j then 'No countings on the diagonal
myValue = Chd(i,ChZ+j-1)
if myValue<>0 then 'Any counting?
xi=abs(j-i)+1 'Range
yi=round(abs(j+i)/2+0.49) 'Mean (will be counted class wise ==> mean 3.5 is in class 4)
oldValue = Chd(xi,"/Z"&yi)
Chd(xi,"/Z"&yi)=oldValue+myValue
end if
end if
next
next
end sub
'------------------------------------------------------------------------------------------
' Modification to script....
'------------------------------------------------------------------------------------------
Dim x
dim j
Dim nameofgroup
Dim nGlobUsedChn
for x=2 to 5
'GroupChnCount(1)
Call GroupDefaultSet(1)
nameofgroup=ChnName(x)
Call GroupCreate(nameofgroup,x) '... GroupCreateName,TargetGroupIndex '... TargetGroupIndex
Call ChnClpCopy("[1]/["&x&"]") '... ClpSource
Call GroupDefaultSet(x)
Call ChnClpPaste(ChnNoMax+1) '... ClpTarget
Call GroupDefaultSet(x) 'make sure we are deleting the right channels
nGlobUsedChn = GlobUsedChn
' ClassMeth2 ="Automatic"
ClassNo =30
' RainResiduumCalc =0
' RainFrequencyTyp ="Cumulative"
RainChnContain ="Class mean"
' Hysteresis =0
RainMatTrans(1) =0
RainMatTrans(2) =1
RainOneParaCalc(1)=0
RainOneParaCalc(2)=0
RainOneParaCalc(3)=0
RainOneParaCalc(4)=0
RainSpecOnePara(1)=0
RainSpecOnePara(2)=0
RainSpecOnePara(3)=0
RainSpecOnePara(4)=0
Call ChnRainCalc(ChnNoMax,"Automatic",0,0,"Cumulative") '... Y,ClassMeth2,RainResiduumCalc,Hysteresis,FrequencyPara
Call ConvertFromTo2RangeMean(nGlobUsedChn+1,nGlobUsedChn+2,nGlobUsedChn+3,x)
'delete excess channels
' Call GroupDefaultSet(x) 'make sure we are deleting the right channels
' Call ChnDelete("ResidueStartClasses")
' Call ChnDelete("ResidueTargetClasses")
' Call ChnDelete("RainflowMatrixX")
' Call ChnDelete("RainflowMatrixY")
' for j = 1 to ClassNo
' Call GroupDefaultSet(x) 'make sure we are deleting the right channels
' Call ChnDelete("RainflowMatrixZ"&j)
' next
nGlobUsedChn = 0
next
The changes I made are in detail:
Christian