01-15-2010 03:06 PM
Hi,
I am using Diadem to analyse some data and create reports which summarize the results. I am using VB scripting extensively for that end. However, I started to notice that the execution time of my scripts is really long and I am wondering if it is possible to transfer some analysis from VB scripts to C++ modules.
Do you know if there is a way to use C++ with Diadem? And if so, do you think it will be more efficient than VBS?
Thank you
Egor
01-16-2010 01:41 AM
Hello Egor!
You can use the DIAdem General Programming Interface (GPI) to seamless integrate C++ (or Delphi) DLLs into DIAdem. For C++ you need a MS C++ Compiler starting vom version 6. Note: AFAIK it is not possible to use the MS VS Express Edition. You can get all necessary informations, headers, etc. form here.
Be prepared that you have to learn something about the interaction with DIAdem from the DLL wich is a little bit different from what you are accustomed vom VB. The result will be verry fast and the functions will look like build-in DIAdem functions. From my point of view is it a good practice not to port a whole application to the DLL. Just build small functions for the critical path wich you can reuse in other projects.
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
01-17-2010 04:41 PM
Hi Egor,
Ideally the DIAdem VBScript is just used to order and parametrize built in DIAdem functions. If you have an analysis routine built in VBScript, it's likely that this could be replaced by an existing DIAdem ANALYSIS or Channel Calculator function. It's quite rare that you need to actually build an analysis routine in VBScript. For the rare situations where that is the case, then Twigeater's suggestion of the GPI-DLL is the correct avenue. What functionality are you thinking about turning to C++ to get?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
01-19-2010 02:49 PM
Hi Brad,
First of all I am looking for faster sorting technics from C++. Also, I am hoping to loop and perform mathematical computations faster.
I am not sure if it will be more efficient in C, than in VBS.
Egor
01-19-2010 03:10 PM
@Egor: In general calculations with C++ will be much faster than in VBS!
@Brad: R&D knows about my DLL and the implemented functions. These are good examples what DIAdem is missing (e.g. splitting, mapping, searching, ...)
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
01-20-2010 10:09 AM
Hi Egor,
If you want to sort multiple channels based on the numeric or string values of one channel, then the built-in DIAdem ANALYSIS function "Sort Channel Values". This will run as fast or faster than external C code. If, on the other hand, you want to do primary, secondary, tertiary sorting like Excel has, then DIAdem has nothing to offer and I fully endorse looking to external C code. If you're wanting to do something other than either of these two, I would be interested to know what it is.
The short rule of thumb is that if you're looping in VBScript and reading out Channel values with ChD() or Channel.Values(), then there's usually a better way by using either DIAdem ANALYSIS functions or the ChnFind() or ChnCalculate() functions. None of these functions will help with primary-secondary sorting, however.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
05-31-2011 10:08 PM
Hi All,
Before I discovered this post, I wrote a VBS script to do primary and secondary channel sorting on a numeric 3 channel block. It may be useful to someone who doesn't want to go down the C code path. I have found it to be fast and (so far) bug-free. It sorts 3 channels (3rd channel values just moved, not sorted) of about 250,000 records each in about 10 s on my old laptop.
Dave.
'Note: this script was written to process 3 channels by sorting the first 2 successively '(i.e. sorting by first channel then by second) and simply moving the correpsonding values 'of the 3rd channel. The approach could be expanded successively to sort more than 2 channels, 'but other methods may be better (e.g. using external library functions). The channel names are: '1) Channel1 '2) Channel2 '3) Channel3 (not sorted) Option Explicit 'Forces the explicit declaration of all the variables in a script. Dim DefaultGrp Dim i Dim TotalSortRows, SortStartPoint, SortEndPoint, SortStartValue Dim BlockEndDetected Set DefaultGrp = Data.Root.ActiveChannelGroup 'Note: multiple channel sorting is difficult in DIAdem as there is no standard function to sort 'multiple channels by successively sorting primary, secondary, tertiary etc channels (e.g. like in MS Excel). 'The function ChnMultipleSort() is poorly named as it only sorts one channel and simply moves corresponding 'values in other channels. The approach below is to apply this function twice, first as just described on 'the whole data set and then in a block-wise fashion on everything except the first data channel. 'Sort the entire data set by the first channel. Call ChnMultipleSort("[]/Channel1","'[]/Channel2','[]/Channel3'",False,True) 'Now sort the second and third channels by the second channel. i = 1 TotalSortRows = DefaultGrp.Channels("Channel1").Size Do 'Repeatedly establish a range of rows in the first channel that have equal values. This 'becomes the block for secondary sorting. SortStartPoint = i SortStartValue = ChD(i,"[]/Channel1") BlockEndDetected = False Do While i < TotalSortRows And Not BlockEndDetected i = i + 1 If ChD(i,"[]/Channel1") > SortStartValue Then BlockEndDetected = True End If Loop If BlockEndDetected Then SortEndPoint = i - 1 Else 'Reached end of data. SortEndPoint = i i = i + 1 'Causes Do...While loop termination. End If 'Sort the block of data identified as having the same value for the first channel. 'Create temporary channels to hold copied blocks of data. Call DefaultGrp.Channels.Add("TempChn2",DataTypeFloat64,DefaultGrp.Channels.Count + 1) Call DefaultGrp.Channels.Add("TempChn3",DefaultGrp.Channels("Channel3").DataType,DefaultGrp.Channels.Count + 1) 'Copy blocks of data to be sorted to temporary channels. Call DataBlCopy("[]/Channel2",SortStartPoint,SortEndPoint - SortStartPoint + 1,"[]/TempChn2",1) Call DataBlCopy("[]/Channel3",SortStartPoint,SortEndPoint - SortStartPoint + 1,"[]/TempChn3",1) 'Sort the copied block, then overwite back into original data set. Call ChnMultipleSort("[]/TempChn2","[]/TempChn3",False,True) Call DataBlCopy("[]/TempChn2",1,DefaultGrp.Channels("TempChn2").Size,"[]/Channel2",SortStartPoint) Call DataBlCopy("[]/TempChn3",1,DefaultGrp.Channels("TempChn3").Size,"[]/Channel3",SortStartPoint) 'Now delete the temporarily copied data for sorting. Call DefaultGrp.Channels.Remove("TempChn2") Call DefaultGrp.Channels.Remove("TempChn3") Loop While i <= TotalSortRows