Sort 1D array of clusters by the second element in the cluster

Hello Folks,
I need to sort 1D array of clusters [Point (X & Y)] using the second element (Y) of the Point cluster. Can anyone guide!!!!
Thanks.
Manu

I see Darren is a bit faster than me.
Here's my solution (LabVEWI 7.0), it is pretty similar.
Message Edited by altenbach on 03-22-200602:01 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
SortByElement2.png ‏4 KB
SortByElement2.vi ‏27 KB

Similar Messages

  • Call library function node with array of clusters using array data pointer

    Hello all.
    I am writing a LabVIEW wrapper for an existing DLL function.
    The function has, as one of its parameters, an array of structs.  The struct is very simple, containing two integers.  I am using the call library function node to access it.
    In Labview I created an array of clusters, where the cluster has two 32-bit integers as its members.  So far, so good.
    Now I have to pass this in to the Call Library Function Node.  Here I am running into trouble.
    I have used The topic in LAVA and The topic in the knowledge base as my primary sources of information, though I have read a bunch of forum topics on the subject too.
    I do understand that I could write a new function which takes as a parameter a struct with the size as the first member and an array as the second, and I might just do this and have it call the regular function, but I was hoping to do it more simply.
    According to the C file which LabVIEW generates for me from the CLFN when I choose "Adapt to Type" and "Array Data Pointer", the prototype it is expecting is:
    int32_t myFunc(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, void data[], int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    And the prototype of the function in my DLL is
    int borland_dll myFunc(DWORD handle, usint channel,
    int FIFOnumber, struct mStruct *data, int numWords, int *actualLoaded, int *actualStartIndex);
    This looks like a match to me, but it doesn't work (I get garbage in data).  From the topic in LAVA referenced above, I understood that it would work.  It does not.
    If I cast data to the pointer-to-pointer I get when I generate c code by wiring my struct to a CIN and generating, then I seem to get what I expect. But this seems to work when I choose "pointers to handles" too, and I would expect array data pointer to give a different result.
    Is there any way to get this to work directly, or will I have to create a wrapper?  (I am currently using LabVIEW 2011, but we have customers using 2009 and 2012, if not other versions as well).
    Thank you.
    Batya
    Solved!
    Go to Solution.

    OK, here is more detailed information.
    I have attached the VI.
    This is the code from the  "C" file created by right-clicking the CLN and creating a "C" file. 
    When the parameter in the CLN is set to "array data pointer":
    /* Call Library source file */
    #include "extcode.h"
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, void data[], int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, void data[], int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex)
    /* Insert code here */
     When the parameter is "pointers to handles":
    /* Call Library source file */
    #include "extcode.h"
    /* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
    #include "lv_prolog.h"
    /* Typedefs */
    typedef struct {
    int32_t control;
    int32_t data;
    } TD2;
    typedef struct {
    int32_t dimSize;
    TD2 data[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    #include "lv_epilog.h"
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex)
    /* Insert code here */
     When the parameter is set to "handles by value":
    /* Call Library source file */
    #include "extcode.h"
    /* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
    #include "lv_prolog.h"
    /* Typedefs */
    typedef struct {
    int32_t control;
    int32_t data;
    } TD2;
    typedef struct {
    int32_t dimSize;
    TD2 data[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    #include "lv_epilog.h"
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex);
    int32_t Load_Transmit_FIFO_RTx(uint32_t handle, uint16_t channel,
    int32_t FIFOnumber, TD1Hdl *data, int32_t numWords, int32_t *actualLoaded,
    int32_t *actualStartIndex)
    /* Insert code here */
    As to the DLL function, it is a bit more complicated than I explained above, in the current case.  My VI calls the function by this name in one DLL, and that DLL loads a DLL and calls a function (with the same name) in the second DLL, which does the work. (Thanks Rolfk, for helping me with that one some time back!)
    Here is the code in the first ("dispatcher") DLL:
    int borland_dll Load_Transmit_FIFO_RTx(DWORD handle, usint channel, int FIFOnumber, struct FIFO_DATA_CONTROL *data, int numWords, int *actualLoaded, int *actualStartIndex)
    t_DispatchTable *pDispatchTable = (t_DispatchTable *) handle;
    int retStat = 0;
    retStat = mCheckDispatchTable(pDispatchTable);
    if (retStat < 0)
    return retStat;
    if (pDispatchTable->pLoad_Transmit_FIFO_RTx == NULL)
    return edispatchercantfindfunction;
    return pDispatchTable->pLoad_Transmit_FIFO_RTx(pDispatchT​able->handlertx, channel, FIFOnumber, data, numWords, actualLoaded, actualStartIndex);
    borland_dll is just "__declspec(dllexport)"
    The current code in the DLL that does the work is:
    // TEMP
    typedef struct {
    int control;
    int data;
    } TD2;
    typedef struct {
    int dimSize;
    TD2 data[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    // END TEMP
    int borland_dll Load_Transmit_FIFO_RTx(int handlertx, usint channel, int FIFOnumber, struct FIFO_DATA_CONTROL *data, int numWords, int *actualLoaded, int *actualStartIndex){
    struct TRANSMIT_FIFO *ptxFIFO; //pointer to transmit FIFO structure
    usint *pFIFOlist; //pointer to array of FIFO pointers to FIFO structures
    int FIFOentry, numLoaded;
    usint *lclData;
    usint nextEntryToTransmit;
    // TEMP
    FILE *pFile;
    int i;
    TD1** ppTD = (TD1**) data;
    TD1 *pTD = *ppTD;
    pFile = fopen("LoadFIFOLog.txt", "w");
    fprintf(pFile, "Starting Load FIFO with %d data words, data pointer 0x%x, with the following data&colon; \n", numWords, data);
    for (i = 0; i < numWords; i++) {
    fprintf(pFile, "%d: control--0x%x, data--0x%x \n", i, data[i].control, data[i].data);
    fflush(pFile);
    fprintf(pFile, "OK, using CIN generated structures: dimSize %d, with the following data&colon; \n", pTD->dimSize);
    for (i = 0; i < numWords; i++) {
    fprintf(pFile, "%d: control--0x%x, data--0x%x \n", i, pTD->data[i].control, pTD->data[i].data);
    fflush(pFile);
    // END TEMP
    if ((handlertx) <0 || (handlertx >= NUMCARDS)) return ebadhandle;
    if (cardrtx[handlertx].allocated != 1) return ebadhandle;
    pFIFOlist = (usint *) (cardrtx[handlertx].segaddr + cardrtx[handlertx].glob->dpchn[channel].tr_stk_ptr​);
    pFIFOlist += FIFOnumber;
    ptxFIFO = (struct TRANSMIT_FIFO *)(cardrtx[handlertx].segaddr + *pFIFOlist);
    //use local copy of ptxFIFO->nextEntryToTransmit to simplify algorithm
    nextEntryToTransmit = ptxFIFO->nextEntryToTransmit;
    //on entering this routine nextEntryToLoad is set to the entry following the last entry loaded
    //this is what we need to load now unless it's at the end of the FIFO in which case we need to wrap around
    if ( ptxFIFO->nextEntryToLoad >= ptxFIFO->numEntries)
    *actualStartIndex = 0;
    else
    *actualStartIndex = ptxFIFO->nextEntryToLoad;
    //if nextEntryToLoad points to the last entry in the FIFO and nextEntryToTransmit points to the first, the FIFO is full
    //also if nextEntryToLoad == nextEntryToTransmit the FIFO is full and we exit without loading anything
    if (( (( ptxFIFO->nextEntryToLoad >= ptxFIFO->numEntries) && (nextEntryToTransmit == 0)) ||
    ( ptxFIFO->nextEntryToLoad == nextEntryToTransmit)) && (ptxFIFO->nextEntryToLoad != INITIAL_ENTRY)){
    *actualLoaded = 0; //FIFO is full already, we can't add anything
    return 0; //this is not a failure, we just have nothing to do, this is indicated in actualLoaded
    numLoaded = 0;
    lclData = (usint *)data; //must use 16 bit writes to the module
    //conditions are dealt with inside the for loop rather than in the for statement itself
    for (FIFOentry = *actualStartIndex; ; FIFOentry++) {
    //if we reached the end of the FIFO
    //if the module is about to transmit the first element of the FIFO, the FIFO is full and we're done
    //OR if the module is about to transmit the element we're about to fill in, we're done - the
    //exception is if this is the first element we're filling in which means the FIFO is empty
    if ((( FIFOentry >= ptxFIFO->numEntries) && (nextEntryToTransmit == 0)) ||
    ((FIFOentry == nextEntryToTransmit) && (FIFOentry != *actualStartIndex) )){
    *actualLoaded = numLoaded;
    //set nextEntryToLoad to the end of the FIFO, we'll set it to the beginning next time
    //this allows us to distinguish between full and empty: nextEntryToLoad == nextEntryToTransmit means empty
    ptxFIFO->nextEntryToLoad = FIFOentry;
    return 0;
    //we reached the end but can continue loading from the top of the FIFO
    if ( FIFOentry >= ptxFIFO->numEntries)
    FIFOentry = 0;
    //load the control word
    ptxFIFO->FifoData[FIFOentry * 3] = *lclData++;
    //skip the high of the control word, the module only has a 16 bit field for control
    lclData++;
    //now put in the data
    ptxFIFO->FifoData[(FIFOentry * 3) + 2] = *lclData++;
    ptxFIFO->FifoData[(FIFOentry * 3) + 1] = *lclData++;
    numLoaded++;
    //we're done because we loaded everything the user asked for
    if (numLoaded >= numWords) {
    *actualLoaded = numLoaded;
    ptxFIFO->nextEntryToLoad = FIFOentry+1;
    return 0;
    //if we reached here, we're done because the FIFO is full
    *actualLoaded = numLoaded;
    ptxFIFO->nextEntryToLoad = FIFOentry;
    fclose (pFile);
    return 0;
     As you can see, I added a temporary diagnostic with the structures that were created in the "Handles by value" case, and print out the data.  I see what is expected, whichever of the options I pick in the CLN!  
    I understood (from the information in the two links I mentioned in my original post, and from the name of the option itself) that "array data pointer" should pass the array of data itself, without the dimSize field.  But that does not seem to be what is happening.
    Batya
    Attachments:
    ExcM4k Load Transmit FIFO.vi ‏15 KB

  • Keyboard "tab" control in Array of Clusters

    I'm trying to polish some of my LabVIEW user interfaces so that my users can work faster in them and so that they follow more "Windows UI Standards" (or whatever).
    I have an array of clusters.  The cluster has 3 numerics.
    When a user "focusses" on the first numeric within a cluster and hits the tab key, it moves the focus to the second numeric.  Hit tab again, and it jumps to the 3rd numeric.  Hit the tab key a 3rd time and it jumps back to the first numeric in the cluster.  What I want to happen is for the focus to move to the first numeric in the next element of the array.
    I've started to play around with the "Key Down" event case that has a conditional looking for "TAB" and then checks the "FindCtrlWithKeyFocus" with the last numeric.  My probes within this event show that the "TAB" key detection is working, but the "FindCtrlWithKeyFocus" never has a TRUE output from the "CtrlFound?" output of the Invoke Node.
    Even if I did know if tab was pressed in the last element, I'm not real sure how to move focus to the first numeric within the next cluster element of the array.
    A numeric array behaves in the correct way.  I could get the program working the way I want with a 2d array of numerics.  However, each numeric has different data entry parameters and there is also a lost of "self documentation".  I would like to find a solution because this has come up with other, more complex, array of clusters that would not be solveable with a 2d array of a base type.
    Seems overly complicated to me.
    Bonus Question: The default value of my numerics is 0.  When my user clicks a numeric the cursor is on either side of the 0 and the user has to delete the 0 prior to their data input.  When a numeric is entered via the Tab key, the whole field is selected.  When the whole field is selected, whatever the user inputs will replace the original "0" that was in the field.  Anyway to have the whole field selected when the user uses the mouse?
    Sorry for the wall-of-text post (and the preposition hell).  Thanks for your input.
    Solved!
    Go to Solution.

    Well I've gone and gotten the tabbing behavior you're looking for.
    -the key is to set "skip when tabbing" on the controls inside the clusters to true, and leave it false for the array elements.  Now when keyfocus is on one of the cluster controls and Tab is pressed, LV will put the keyfocus on the next visible array element.
    -then use a "key down?" filtering event to check and see if any of those controls have keyfocus when Tab is pressed.  If so, and it's not the last control in the cluster, discard the keypress and programmatically advance keyfocus to the next item.  
    -Finally if the Tab press was not discarded, use a normal "key down" UI event to check if one of the array elements now has keyfocus and if so, set KF to the first control in its array.
    So in short, this setup turns off tabbing along a row so that every tab will move to the next row.  Then it filters out Tab if it's not yet at the end of the row.  Finally, it automatically puts the cursor in the first column when the row has advanced.
    One significant drawback is that it only tabs between visible array elements.  You can probably make it auto scroll.
    I'll leave it as an exercise for the reader to handle the shift+Tab (reverse tabbing) key presses.
    To me, this runs up against three holes in LV UI programming:
    1) Array Element events should be available.     The Array:Key Down event only handles key presses when the array has keyfocus, not when things inside it do.  Any kind of key filtering has to be done at the VI level (!!!).
        The data source for these events should include the element index (eg what cell was clicked on?)
    2) There aren't effective ways in VI server to deal with individual array elements.  I recognize that some of it is the basis that array elements have the same properties, but there are display and selection properties that do differ between cells.  I ought to be able to specify that a particular cell index has keyfocus.  Arrays, why can't you be more like Tables?
    3)Tab order should be flat, not hierarchical.
    edit: in case the snippet messes things up, file is attached.
    -Barrett
    CLD
    Attachments:
    Tab through cluster array elements.vi ‏28 KB

  • Sort Grid array and find the 4 corner dots.

    What I am trying to do is this:  I am using NI Visions find circles vi on a grid array or dots which gives me a 1D array of clusters.  In these clusters is the x,y coordinates of the grid dots that have been found.  I need to figure out which ones are the 4 corner dots and the 4 center dots along the edges.  The problem is the 1D array the find circle routine outputs is not in a logical order.  My grid could possibly change in size too.  Right now it is 14x12 but could be 13x12 or 14x13 or something like that. 
    I have found that if I send the 1D array of clusters though the sort 1D array it will sort it from top to bottom left to right, which I will then know that teh 1st element is the top left corner and the last element is the bottom right corner, but I am not sure what the easiest way is to figure out the rest of them. 
    Any help would be appreciated.
    I am using labview 7.1 and NI Vision 8.0
    Thanks
    Brad
    Brad Remenak
    Certified LabVIEW Architect

    Hi Brad,
    If you want to get the coordinates of specific dots on the image, you
    can search for the dots using different ROIs that only focus on certain
    areas of the image (ex: use an ROI that only searches in the
    upper-right corner so that you know the 1 match that shows up is
    definitely there).  Without knowing how consistent the dot
    locations are, I would suggest dividing up the ROI dimensions based on
    the variable size of the grid.
    Hope this helps,
    Irene Chow
    National Instruments

  • How can I modify the cluster values in an array of clusters?

    Hi all - I can't believe that I am having trouble with this but for some reason I am completely wrapped around the axel with it. I have an array of clusters, they are all strings but with different names. I am using key configuration VIs to setup a readable text file for the user. I also want the user to be able to load up the array of clusters with the values that are in the text file. So I am reading the keys and trying to populate the array of clusters to show what is in the text file and then run the test using those values. However I am not able to get the clusters populated correctly. Does any one have an example of what I am trying to do? Basically I am trying to populate an existing array of clusters with new values. That is what it comes down to. Thanks in advance for any help.

    Go to jki and dowload VIPM (VI Package Maager). From there you ca install OpenG. Lot's of useful stuff.
    Also if you cosider XML to be readable you can use flatten to/from XML.
    =====================
    LabVIEW 2012

  • I need to sort an array of strings based on the number in each string.

    Basically, I have a directory of files that all have the same name but each with a different number on the end.
    example: image 1.jpg, image 2.jpg, etc.
    When I use the List Directory function that returns an array of strings containing the file names in the directory, they don't come out in a 1, 2, 3, order like they appear in the directory. It sorts them character by character so that they come out like: 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22 etc.
    Is there a simple way of sorting this array of strings with the file names (as above) so that they are in numerical order?

    It's a while since this thread was started, but I am sure others will have use for this so here goes:
    The in-built array sort function sorts the strings the same way DOS and Windows do. Microsoft has fixed this in the Explorer that comes with XP, however the rest of the OS(s) still sorts the old way.
    The attached "AlphaLogical String Array Sort" VIs will sort strings arrays the same way as the new XP Explorer. There are three different implementations of the sorting, one based on the Insertion sort algorithm, a Quick Sort based on recursive calls (the most elegant way, but unfortunately LabVIEW has too much overhead when doing recursive calls so this is actually a very slow alternative) and finally the fastest; a stack based Quick Sort. There is also a test VI that will show you how the different implementations perform.
    I had not used recursive calls in LV much until I made the attached quick sort and was a bit disappointed by the fact that it is so slow, but it's a good learning example...The ability to do recursive calls this way was introduced in LV7 I believe...There is an example here on the zone that shows how you can calulate a factorial by using recursive calls, however - unlike for the quick sort (normally) - recursive calls are actually not the optimal solution for that calculation.
    Message Edited by Mads on 09-13-2005 02:30 AM
    MTO
    Attachments:
    AlphaLogical Sorting.zip ‏142 KB

  • Labview How to specify 1d array of clusters as data types for variant to data

    Hi, I'm new to labview. Can anyone tell me how to specify 1d array of clusters as data types for variant to data?

    First of all, you should be sure that there is such a data type within the variant; otherwise, you will run into errors.
    I recommend you to create the cluster and create a type definition from it. Then drop an array shell from the array palette and drop the cluster type into that array.
    Connect that constant to the data type input of the Variant To Data function.
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Array Of Clusters Not Initializing or Possible Race Conditions

    Hi all,
    I've been working on a fairly complex project for work, and I haven't worked with Labview before. Unfortunately nobody in my office really has experience with it so I'm on my own. I've mostly got the project working, and it might be a little cumbersome, but if it works that's fine.
    Essentially it's a temperature control device and I made it so it's expandable, thus the clusters and arrays everywhere.
    My question is this. I've got an array of clusters indicating the status of all the plates in the system. When I start up the VI for the first time they do not initialize. They just stay grey, but when I stop it and start it once, it will work every time. I think this is kind of strange behavior. I've heard of race conditions and while I've tried to make sure t hat's not happening, it might be without me noticing.
    I've tried putting an initialize array block in the first call while loop and that doesn't do anything, and if I remove the initializer from the shift register in the top while loop that stops them being initalized altogether.
    I guess I was hoping someone might have an idea what's causing it, or could possible give my code the once over. The main bulk of it is in the very top of the code, but there are a lot of smaller events taking care of GUI type stuff.
    I've included all source code. It might be a little much but I didn't want to start pulling it apart if I don't know what's happening.
    Thanks in advance.
    Chris.
    Solved!
    Go to Solution.
    Attachments:
    Error During Cycle Controls.zip ‏3107 KB
    Stop Cycle Controls.zip ‏2115 KB
    Stop Cycle Controls.zip ‏4975 KB

    Chris Johnson wrote:
    So just to confirm, I can have one event structure with say 10 events happening? In this case could an event happen simultaneously with another? I thought I read something about each event having it's own event structure and while loop to make sure this works out.
    Each event case must complete before it can handle the next event, but many events will complete so quickly that this is not an issue (such as your "pause chart" button).  In general you should have only one event loop.  If you expect an event to take a long time to process, use a queue to hand that task off to another dedicated-purpose loop, so that the event structure can go back to waiting.  This is one example of the producer-consumer structure often mentioned on this forum: the producer is the loop containing the event structure, and it queues (produces) items to process.  A separate loop dequeues (consumes) those items and handles them appropriately.
    As GerdW mentioned, you have race conditions all over the place.  You'll never know whether the Plate Info Cluster Array is properly updated because it's being written and read simultaneously in so many places.  I'm assuming that is also where you're seeing the issue that inspired the post, and, in fact, one of those race conditions could explain what you're seeing.
    Chris Johnson wrote:
    Also, again, to confirm what I think I already know. When the event completes it outputs whatever data you output from the structure and then you can place it in a shift register. Where does this go until the next event takes place?
    I don't understand what you're asking.  Where does what go until the next event?  If by this you mean the data in the shift register - it stays in the shift register, accessible at the corresponding terminal on the left side of the loop.

  • Programmatically create array from common cluster items inside array of clusters

    I have seen many questions and responses on dealing with arrays of clusters, but none that discuss quite what I am looking for. I am trying to programmatically create an array from common cluster items inside array of clusters. I have a working solution but looking for a cleaner approach.  I have an array of clusters representing channels of data.  Each cluster contains a mixture of control data types, i.e.. names, types, range, values, units, etc. The entire cluster is a typedef made up of other typedefs such as the type, range and units and native controls like numeric and boolean. One array is a “block” or module. One cluster is a channel of data. I wrote a small vi to extract all the data with the same units and “pipe” them into another array so that I can process all the data from all the channels of the same units together.  It consists of a loop to iterate through the array, in which there is an unbundle by name and a case structure with a case for each unit.  Within a specific case, there is a build array for that unit and all the other non-relevant shift registers pass through.  As you can see from the attached snapshots, the effort to add an additional unit grows as each non-relevant case must be wired through.  It is important to note that there is no default case.  My question:  Is there a cleaner, more efficient and elegant way to do this?
    Thanks in advance!
    Solved!
    Go to Solution.
    Attachments:
    NI_Chan units to array_1.png ‏35 KB
    NI_Chan units to array_2.png ‏50 KB

    nathand wrote:
    Your comments made me curious, so I put together a quick test. Maybe there's an error in the code (below as a snippet, and attached as a VI) or maybe it's been fixed in LabVIEW 2013, but I'm consistently getting faster times from the IPE (2-3 ms versus 5-6ms for unbundle/index). See if you get the same results. For fun I flipped the order of the test and got the same results (this is why the snippet and the VI execute the tests in opposite order).
    This seems like a poster child for using the IPES!  We can look at the index array + replace subset and recognize that it is in place, but the compiler is not so clever (yet!).  The bundle/unbundle is a well-known "magic pattern" so it should be roughly equivalent to the IPES, with a tiny penalty due to overhead.
    Replace only the array operation with an IPES and leave the bundle/unbundle alone and I wager the times will be roughly the same as using the nested IPES.  Maybe even a slight lean toward the magic pattern now if I recall correctly.
    If you instantly recognize all combinations which the compiler will optimize and not optimize, or you want to exhaustively benchmark all of your code then pick and choose between the two to avoid the slight overhead.  Otherwise I think the IPES looks better, at best works MUCH better, and at worst works ever-so-slightly worse.  And as a not-so-gentle reminder to all:  if you really care about performance at this level of detail: TURN OFF DEBUGGING!

  • Reference to Array of Clusters with an array element

    Hi,
    I have an array of clusters CONTROL (calling it as "top level cluster array") with one of the cluster elements being a cluster array (please see attached).
    I plan to pass "Reference" of this top level cluster to different VIs (like add element VI, insert element VI, delete element VI etc) and access (add/modify delete) the elements in this array.
    In my code, how do I typecast the Array Element (cluster) to the inner cluster (as shown in the figure) ?
    I am using LV RT on PXI.
    Solved!
    Go to Solution.

    You cannot use references in the same way that you use pointers around in C. LabVIEW does not manage memory in the same way that C does. This is actually a good thing, though C programmers find it "cumbersome" or "restrictive". I have also programmed in C, and frankly I prefer LabVIEW's memory management any day of the week.
    You had not initially mentioned that this was going to be done in multiple places at (potentially) the same time. Given that, my recommendation is to look into using Action Engines. They provide a means of basically providing a one-location acccess for your data. By using a single VI to access/modify your data you preclude the generation of race conditions. You may also want to join this with the concept of using variants to provide a means to quickly find your data rather than looping to find the element you're interested in. This technique has been around for a while and it has been discussed before. There are examples floating around. Will need to check to find one. 
    As for your question regarding using the reference method which you tried to employ in your initial approach, that's simply not going to gain you anything. You will still be creating buffers when you try to access the cluster elements. But you already have this information in the array inside the outer for loop, so you're just creating unnecessary extra programming for yourself. 

  • Unbundle shows disabled element in the cluster

    Hello Everybody
    See the enclosed gif to see my problem.
    The unbundle by name shows that the element of the cluster is disabled, whereas the "step by ste" unbundle by name shows all cluster element ready to use.
    I have found the simmilar problem here:
    simmlilar problem
    but there was no answer for that.
    Do you have any clues?
    thanks in advance.
    Pawel
    Attachments:
    unboundle.psp ‏161 KB

    Hello,
    I just want to add some more info to the subject, since I have found interesting stuff yesterday.
    I enclose the control I am talking about.
    The control contains cluster and inside the cluster there is another clusters. As I have shown in the previous post, some of the elements in the cluster are disabled. What is really funny in all of it, is that by adding or remowing some elements of the basic cluster, the disability is shifted to other cluster elements. Yes, just like that. Do it by your own, try to to add a boolean in the big - front pannel - cluster. Then do not forget to rearange the order of elements to have your control somewhere in the beggining. You will see that now other elements are disabled. What the heck it that??????
    What
    is interesting that, the disable view of the elements occur also in other sub-cluster. When you add the boolean the disability is also shifter. This shift equals the amount of controls you put to the cluster. I count that if I expand all clusters and treat their elements as one cluster, than the distance between disabled positions equals 9 !!!. This distance is unchanged.
    I enclose two vi with the control I am talking about and with corresponding pictures.
    What to do with it???
    kind regards
    Pawel
    Attachments:
    mistery.vi ‏102 KB
    Image1.gif ‏46 KB
    Image2.gif ‏49 KB

  • Sort Second Element in Array of Strict Type Def Clusters

    I need to sort the an array of strict type def clusters by the second or third element in the cluster.  In the past I have used 1-D array sort and sorted by the first element of the cluster.  When I need to sort by the second, third, or fourth element of the cluster I just break down the cluster and rebuild it placing the desired sort element in the first position of the new cluster.  This works for simple tasks and clusters, but as the cluster gets more complicated this becomes a pain to do this.  There must be a cleaner way to sort by other elements within the original array of strict type def clusters.  Has anyone succeeded in doing this a different way?

    Hello,
    Here's the way I would do it...just create a new cluster array, where each cluster contains two elements...the unbundled item you want to sort by, and the cluster itself.  Then sort the new cluster array, then unbundle the sorted cluster array to get the original clusters (now sorted).  Here is a screenshot:
    There may be a better way, but this is the first thing I thought of.
    -D
    Message Edited by Darren on 03-16-200610:00 AM
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman
    Attachments:
    Sorted_cluster.jpg ‏30 KB

  • How can i segregate an array of clusters with channels id in the cluster

    Hi All
    i am using a keithley 2010 DMM for power measurements,
    i am using the 2010 scan read VI which gives the reading output as an array of clusters, these clusters contain the measurement,units,channel.
    i have 6 channels for measuring voltage across and i want to make 5 readings per second on each channel which makes upto 30 readings per second.
    i want to segregate these clusters from the array according to the channel id and take the results,
    please tell me if we have function for this or you have any possible solution for the same.
    i would be very happy to hear from you and get this solved
    please help
    Thanks in advance
    Sandeep K Shyam

    yeah this looks great...thanks for your response,
    i have modified accordingly and attaching the VI, can you please look into this once
    also one more problem i have with this VI is whenever i am trying to run the VI, the  sub VI (Scan config.vi) gets popped up and waits for user response (next) cntrl+right arrow,  how can i get rid of this and run the VI in continues mode?
    i am attaching my VI along with the kei2010 lib,
    please check this
    Thanks again
    sandeep K shyam
    Attachments:
    sandeep-FinalKeithley20101.vi ‏822 KB
    kei2010.llb ‏901 KB

  • The time complexity of "Sort 1D Array"

    Does anyone know the time complexity of "Sort 1D Array"? The document of this function does not say anything about that, so I write test VI to sort an array of 10000 integer elements. It seems that the excution time is less than 1 second, so I guess the complexity is O(n*logn). Any suggestion would be appreciated, thanks.

    A few thoughts based on my recollection of that old coding challenge.  There are different kinds of algorithmic approaches you may consider.
    1. A simple approach to that challenge could involve a lot of search / lookup functions.  Each time you parse a word, you perform a search to see if it's in your list already.  If so, increment its count.  If not, add it to the list with count=1.
       This was far too slow for word counting large docs.  Too many slow-ish searches.  But pretty easy to implement and maybe good enough for smaller docs.
    2. I pursued an approach that used hashing instead of searches.  It *seemed* too slow, but some months after the challenge when I had another use for the core hash table functionality, I found a really dumb bug that I'd overlooked before.  Fixing it improved the speed by something like 100x.  (Missed one spot where I needed a shift register to enforce in-placeness).
       This is largely the same approach, merely trying to speed up the lookup/search function via a more complex technique (hash tables).  As I found out, the complexity makes it more bug-prone.  Still, once fixed, lookup speed is in the order of constant with no clear dependency on the number of elements in the hash table.  (Note: it *is* still dependent on the "fill ratio".  You want enough memory available to size your table for maybe ~25% usage or less.)
    3.  One idea I tried out was to maintain a separate list of the 10 or 25 most-common words, sorted by count.  (The main reason was that there could be a tie for 4th place at the end, and I wanted enough extra candidates around to get the correct tie-breaker result.)  Each time I parsed another word and incremented its count, I'd check to see whether its new count qualified it to belong in the special most-common list.  I still did a lot of lookup and sort stuff, but it was always on a very
    There are surely other kinds of data structures and algorithms available.  Do you have a specific app in mind for this?  Or just generally curious?  I ask because some of the things one might do to optimize for a specific app (or code challenge) wouldn't be so appropriate as a general-purpose routine.
    -Kevin P.

  • Can I sort by the second element in my vector?

    The first element is first name and the second is lastname. Right now I am using java.util.Collections.sort(v); This searches on the first name. I would like to search on the last name which is the second element. Any ideas?

    Write a subclass of Comparator that looks at the second element, and give an instance of it to the sort method along with the array.

Maybe you are looking for

  • Can I use bind variable instaed of writing static COLUMN Name

    Hi , I am having a table containing id and column names, the data is stored against that id in other tables. Now I wish to update data into another table so that it goes into apppropriate column without using decode function. I am trying to do this:

  • Battery X, trouble powering up...I'm deep in the jungle, please help!

    On Jan 14th I bought a new MacBook Pro 13" Retina from MicroCenter.  I am traveling deep in the jungle in a remote part of Costa Rica and I started noticing that it wasn't holding a charge (at first I assumed it had just ran out and I didn't plug in

  • How to call Web URL's as values of an BW InfoObject via BEx Web

    Hi experts, I want to call Web URL´s as values of an BW InfoObject via BEx Web. Is there any option to convert the character into a direct URL link to call the Web adress directly? Example: no direct URL (e.g. http://help.sap.com) to call the Web add

  • Cross join of dimensions

    Hi, For example:  two dimension tables and one fact table. dim1: branch branch1 branch2 dim2: time day1 day2 fact: sales branch1, day2, 100 what I want in answers when using branch and time and sales without any filters: Branch1, day1, 0 branch1, day

  • Cannot Access updates in app store

    My computer says I have a software update, but then when I access the App Store, all I get is a blank page. I can see "featured", "top Charts" and everything else, but when I click updates (It says I have one update) It is just blank and won't go the