DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

A weird problem!

Hi All,
 
       I am using the following code to calculate the maximum correlation and then copy the max. corr. value to a new channel.  The code is as follows:
 
Dim MyChnName: MyChnName = ChnAlloc("Time_Offset",1, 1,DATATYPEFLOAT64)  'Allocate 1 numeric channels
Call ChnPropValSet("CoG_Vars/Time_Offset", "length" , 1)
Dim row_cor: row_cor = ChnFind("ValEqual(Ch(""Cog_Vars/NormalizedCrossCorrelated""), CMax(""Cog_Vars/NormalizedCrossCorrelated""))")
Dim chan_num_time_offset: chan_num_time_offset = CNo("CoG_Vars/Time_Offset")
Dim chan_num_cross_corr: chan_num_cross_corr = CNo("CoG_Vars/CrossCorrelatedX")
ChDX(1, chan_num_time_offset) = ChDX(row_cor, chan_num_cross_corr) '... Update the offset value
 
      The problem is little vague. If I run this code as a separate script, then it works perfectly. However, if I copy this section at the end of other scripts or automate all the scripts, then it fails. The variable 'row_cor' returns 0 if it is run in a single go with other sections of the code. 'row_cor' returns correct value (say 350 i.e., the row which has the max corr value) if I run it manually as a separate script.
 
     Any pointer about how to solve it & why this is happening will be highly appreciated.
 
With warm regards,
Saurav
0 Kudos
Message 1 of 8
(4,987 Views)
Hello Saurav!
 
With a quick look on your code I can not see a problem. What I recommend are some changes to your code to make it more robust:
 
Call ChnPropValSet("CoG_Vars/Time_Offset", "length" , 1)
should be changed to
Call ChnPropValSet(MyChnName(0), "length" , 1)
The line
Dim chan_num_time_offset: chan_num_time_offset = CNo("CoG_Vars/Time_Offset")
should be
Dim chan_num_time_offset: chan_num_time_offset = CNo(MyChnName(0))
 
I also recommend to add an if clause around the ChDX command. This cann look like this:
 
If row_cor > 0 Then
  ChDX(1, chan_num_time_offset) = ChDX(row_cor, chan_num_cross_corr) '... Update the offset value
Else
  MsgBox "Not Found"
End If
 
Are you sure that the channel characteristics of the Cog_Vars/NormalizedCrossCorrelated channel are calcualetd? If you use ChdX to set values you have to call ChnCharacter for the channel!
 
Do you use the 'Option Explicit' phrase at the top of your code? If not add it.
 
Hope this helps a little bit. For additional help I need the complete code and some test data.
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 2 of 8
(4,981 Views)
Hello Matthias,
 
        Thanks for the quick help. However the problem is not yet solved. Here are my answers to some of your queries.
1.  I use the 'Option Explicit' phrase at the top of my code.
2.  I cannot add an if clause around the ChDX command because it can actually return a zero value (indicating that the two serieses are in perfect correlation).
3.  I do not understand what is meant by channel characteristics? I can see that Cog_Vars/NormalizedCrossCorrelated channel is calculated correctly. Please let me know how to use ChnCharacter in conjunction with ChdX.
4.  Regarding the changes u suggested, could you please let me know what are basic difference in these two modes? I use "CoG_Vars/Time_Offset" etc. because I keep all the new channels, calculations etc separately under the group "CoG_Vars" for ease of debug & data management.
        Please let me know if you need my scripts.
        The problem is: If I run all the scripts automatically, it fails to calculate 'row_cor'. If I run the scripts manually one after the other, it calculates properly!!
 
With warm regards,
Saurav
0 Kudos
Message 3 of 8
(4,974 Views)

Hi Matthias,

Kindly ignore point 3 of my previous mail. Actually I cannot have a 'row_cor' with zero value. It must be having a minium of 1, else the entire calculation has no meaning.

 

With warm regards,

Saurav

0 Kudos
Message 4 of 8
(4,968 Views)
Hello Saurav!
 
I ignore point 2! OK?
 
1.) Perfect!
3.) Channel characteristics are the statistic values like minimum or maximum. These values are not always calculated. If you use the ChdX command for example you have to call the ChnCharacter command to force DIAdem to calculate them!
4.)  MyChnName(0) ensures that you realy use the allocated channel. Sometiems the name is changed and this is the save method. Your way wasn't wrong.
 
Can you please add a messageboxes before the ChnFind command to display the CMax("Cog_Vars/NormalizedCrossCorrelated") value. Run the automatic sequence with the runtime error.
 
Matthias
 
 
 
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 5 of 8
(4,961 Views)

Thanks a lot, Matthias! Here are my observations.

1. If I add a message box before the ChnFind command to display the CMax("Cog_Vars/NormalizedCrossCorrelated") value & run the automatic sequence, the message box displays the error 'Invalid use of Null', meaning the statistics are not being calculated.

2. When I called the ChnCharacter command to force DIAdem to calculate them, the values are calculated and the automation works fine.

With warm regards,

Saurav

0 Kudos
Message 6 of 8
(4,946 Views)

Hello Saurav,

I see that you have made some progress with the help of Matthais, but I wanted to see if you needed any more help with the issue.  You mention that you do get the automation to run using the ChnCharacter command, but from the context of your message I take it that this might not a desirable solution?  If you were to post some test data and the code we could do some further work on this issue, but if everything seems to be running fine then don't worry about it.

John B.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 8
(4,877 Views)

Hello John,

         Thanks for your offer to help. But I have already solved this problem with Matthias's help. However I am facing another problem. Please see: http://forums.ni.com/ni/board/message?board.id=60&thread.id=8073. It will be great if you can provide some insight on how to tackle it. In the meanwhile, I am trying out the available suggestions.

With warm regards,

Saurav

0 Kudos
Message 8 of 8
(4,860 Views)