Code Improvement : sorting function

I have the PXI-5122 digitiser (that acquires in 14-bit, NI-Scope 2.5)and I do the following measurement for :
- sample rate = 50MS/s
- record length = 4M (in 16-bit)
->acquisition time = 0,08sec
and I want to sort these 4 million samples.
My algorithm is this one:
Consider that I need 2^N divisions (usually N=7 til 9)
I use a shift right function of N bit on my 4M datas so I get an index to a counter that I increment for each occurancy:
for each acquisition
for all the samples do
index = (data_16bit>>N)
hist(index)++
end
end
My PXI is a Pentium3 1,2GHz and in the worst case it seems that should take less than 1 second. But in fact it takes around 26 sec for an acquisition of 0,08se
c !!!
So I try to compare with a sortinf method not only using the output wfm of niScope Fetch Binary 16 but also the gain and offset of the channel. So I get now Voltages which are float so it should be slower to handle float than just binary numbers. It´s not the case with this float handling it takes 26,1 sec to sort the same amount of data (4M). Do LabView recognise every number nubers as float ? Because it is very weird that a basic low level application like bit shifting + counter incrementing is not faster than the same one with float.
I assume that my algorithm is not perfect so that´s why I would like to know if you have some deas that could be more convenient with LabView.
Thanks for your support.
Attachments:
sorting.bmp ‏335 KB

Instead of reading and writing to a local variable, use a shift register. This will *dramatically* improve the performace. Right-click on the array output tunnel and select "create shift register". Then wire "Count In" to the left shift register. Finally, delete the local variables.

Similar Messages

  • Javascript sort() function not working correctly

    I have an image gallery that automatically loads via a PHP readdir function which populates an array, and then I have a Javascript sort() function which sorts the images in order numerically. In Chrome and Safari, the images display as numbered in the directory. However, in Firefox and Internet Explorer, they display out of order (firefox) and not at all (ie). Here is the code for the php file: <?
    Header("content-type: application/x-javascript");
    function returnimages($dirname=".") {
    $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
    $files = array();
    $curimage=0;
    if($handle = opendir($dirname)) {
    while(false !== ($file = readdir($handle))){
    $file = basename($file,".jpg");
    echo 'myImg['.$curimage.']="'.$file .'";';
    $curimage++;
    closedir($handle);
    return($files);
    echo 'var myImg=new Array();';
    returnimages()
    ?>
    and here is the code for the javascript sort:
    function sortNumber(a,b)
    return a - b;
    myImg.sort(sortNumber);
    // Tell browser the type of file
    myImgEnd = ".jpg";
    var i = 0;
    // Create function to load image
    function loadImg(){
    document.imgSrc.src = myImg[i] + myImgEnd;
    Any ideas as to why Firefox is behaving this way?

    After you check the box to sort on the column, are you making sure to select a sort order for the same column?
    Earl

  • DRQ#  Payment Wizard Sort Function

    Hi,
    The sort function in the SAP payment wizard, loses it's settings in Step 6.  In Step 3, you can sort the BP name field to sort by alpha, but in Step 6 the sort converts back to numeric, by BP Code.  Our client is having problems with this when making their invoice selections in the wizard, as their invoice filing system is alphabetic and they have a large pile to sort through when making payments. 
    I would have thought the sort option should retain throughout the wizard from Step 3 to Step 6.  Additionally it would be nice if in Step 6 there was also the option to sort again if needed.
    Edited by: Lianne Plant on Nov 9, 2010 3:42 AM

    Hi Janne,
    I trust you are well.
    Please post the DRQ in the forum ['SAP Business One Product Development Collaboration'|/community [original link is broken];.
    All the best,
    Jesper

  • Using SORT function in mapping

    Hi,
    I am having trouble getting my head around using the SORT function.
    My interface is IDOC to File, The IDOC has a repeating segment (PAYLOAD) that can be of 3 types, either type A, B or C (this is set using a "TYPE" field).
    In my file structure I have a repeating "ROW" element which has all of the fields for each row.
    I want to group all the Type A data together, the Type B together and the Type C.
    I have tried the following mapping on the "ROW" element but it doesn't seem to work:
    "TYPE"--"sort"Split By Value (Value Change)--collapseContext--"ROW"
    for each of the mappings under ROW I just have fields copied directly.
    I think I am doing something wrong.
    Thanks.

    Hi,
       You could make this mapping
         TYPE --- +----------------+     +----------------+
               |                |     |                |
               | Concat         | --- | mySortFunction | --- NAME
               |                |     |                |
         NAME --- +----------------+     +----------------+
         TYPE --- +----------------+     +----------------+
               |                |     |                |
               | Concat         | --- | mySortFunction | --- ADDR
               |                |     |                |
         ADDR --- +----------------+     +----------------+
       Where source code of mySortFunction is like this:
    public void mySortFunction(String[] inputValues,ResultList result,Container container){
         for(int i=0;i<inputValues.length;i++)
              if(inputValues<i>.substring(0,1).equals("A"))
                   result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);               
         for(int i=0;i<inputValues.length;i++)
              if(inputValues<i>.substring(0,1).equals("B"))
                   result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);
         for(int i=0;i<inputValues.length;i++)
              if(inputValues<i>.substring(0,1).equals("C"))
                   result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);
       It is very simple. You concat TYPE whit your data, and then you sort all queue, so you have a new sort queue data. You must only then put out data.

  • Getting UNCAUGHT_EXCEPTION CX_WD_CONTEXT at using alv sort function

    Dear colleagues,
    I developed a simple application which displays records in an ALV and at lead-selection shows detailed data in a form. Everthing is working fine except one is clicking on the sort functionality at the top of the ALV short dump is thrown.
    In trx ST22 I find :
    The lead selection has not been set. V_DEFAULT
    "UNCAUGHT_EXCEPTION" "CX_WD_CONTEXT"
    "CL_WDR_CONTEXT_NODE===========CP" or "CL_WDR_CONTEXT_NODE===========CM00R"
    "_RAISE_ELEMENT_NOT_FOUND"
    Lead selection is checked and also debugging the code did not bring me any further.
    Any help is greatly appreciated.
    Thanks in advance
    Michael

    Hi Regina,
    first of all thanks for your quick answer and explanation. I'm not sure what you mean with 'register to the standard functions of the ALV' because this is a functionality which works in other ALVs without register any event method to them or do you mean that in my case I have to react to the sorting in a new method in the view controller? Concerning 'refill the subnode via supply function' I'm doing this already.
    Disabling the sorting is no option anymore because the users already know and love this feature
    Regards
    Michael

  • Sort() function used in HashMap, ArrayList or Collections?

    I need some testing codes for similar function like sort() for HashMap, Arraylist or Collection objects.
    Thanks in advance for help!

    http://developer.java.sun.com/developer/TechTips/1998/tt0421.html#tip1
    take a look at this link

  • Sort Function

    Hi Experts,
    Under my node functions in the mapping editor I do not have a Sort function...
    Is it possible for someone to write me a code to do the same?
    Thank you

    Hi,
    yes you can write the code of a generic sort function youself
    (in an advanced user defined function)
    or you can update the SP of your XI server (so it will have all new features)
    BTW
    writing it yourself will probably give you more flexibility
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

  • How can i improve this function?i need your help....

    Hi guys,
    i'm a pratical question for you.
    I've developed a jas application that reads a txt file and convert it
    into an array of byte,fro putting it into a blob field of a db mysql.
    With big file i go in heap size memory!
    I want to improve my function that makes it,but i'm a bit
    inexpert...can you help me?
    I have a file so made...
    Each line has the same number of value,but i know this number only when
    i read the file
    string1 string2 string3................
    stringx double double......(ever double)
    stringy double double......(ever double)
    and other lines equals to them from the second.
    Only the first line has only strings.
    I have read this file using a string array to read the first line and
    an arraylist of "Riga" object to read the others lines.....i've used a
    vector to store partial data from lines reading and at the end i've
    created an array of byte in which i copy the vector.
    Can you help me improving my code?
    The file has about 50000 rows......so i go in heap memory size...
    i know my code isn't too optimized.....can you help me?Please,i'm a
    newbie,help me with code if possible...
    When i encode the objects i've created into an array of byte i use a
    whitespace to separe different value and a ; to separe different lines.
    I've done it because in a second moment i've to read the array of byte.
    Thanks...this is my code
    public class MyBean {
            private UploadedFile myFile;
            private ArrayList rows = new ArrayList();
        private List lines = new ArrayList();
        public MyBean(){
        public List getLines(){
            return lines;
        public void setLines(List lines){
            this.lines=lines;
    public boolean insRighe(Riga nuovo){
               return rows.add(nuovo);
        public UploadedFile getMyFile() {
            return myFile;
        public void setMyFile(UploadedFile myFile) {
            this.myFile = myFile;
        public ArrayList getRows() {
                    return rows;
            public void setRows(ArrayList rows) {
                    this.rows = rows;
        public String carica() throws IOException {
            Riga r;
            Double val[];
            Head h;
            int col=0;
            int row=0;
            byte middlerow=' ';
            byte endrow=';';
            byte[] data=null;
            Vector temp=new Vector();
            int numberOfNumericColumns=0;
            String geneid=null;
            String g=null;
            String[]intest=null;
            BufferedReader br = new BufferedReader(new
    InputStreamReader(myFile.getInputStream()));
                    String line = null;
            while ((line = br.readLine()) != null) {
                    line = line.replace (',', '.');
                    StringTokenizer st = new StringTokenizer(line);
                    numberOfNumericColumns = (st.countTokens()-1);
                    col=(numberOfNumericColumns+1);
                //se siamo nella prima riga(contatore segna 0)
                    if(row==0){
                            intest=new String[col];
                            int j=0;
                            while(st.hasMoreTokens()){
                                    intest[j]=(st.nextToken().trim());
                                    j++;
                            h=new Head(intest);//crei l'oggetto head
                            String []qa=h.getHvalues();
                            String asd="";
                        for(int i=0;i<=qa.length-1;i++){
                            asd=asd.concat(qa[i]+" ");
                        System.out.println("head "+asd);//stampo contenuto
    dell' head
                        row=1;
                    }//fine if
                    else
                            Double[] values=new Double[numberOfNumericColumns];
                        int z=0;
                        geneid=st.nextToken();
                        while (st.hasMoreTokens()) {
                            String app=st.nextToken();
                            values[z]=Double.valueOf(app);
                            z++;
                        r=new Riga(geneid,values); //crei l'oggetto riga
                        System.out.println("riga");
                        System.out.println(r.getgeneid());
                        values=r.getvalues();
                        for(int e=0;e<values.length;e++){
                            System.out.println(values[e]);
                        insRighe(r); //aggiungi
                    row++;
                    int i = 0;
                    while (i < intest.length) {
                            byte[] bytesnew = intest.getBytes();
    // temp.addAll(bytesnew);
    // memorizza in byte un elemento del vettore alla volta
    for (byte b : bytesnew)
    temp.add(new Byte(b)); // provare Byte
    // temp.addElement(intest[i].getBytes());
    temp.addElement(Byte.valueOf(middlerow));
    i++;
    temp.addElement(Byte.valueOf(endrow));
    System.out.println("Intestazione convertita in byte");
    for (int l = 0; l < rows.size(); l++) {
    r = (Riga) rows.get(l);
    g = r.getgeneid();
    // temp.addElement(g.getBytes());
    byte[] byte2 = g.getBytes();
    for (byte c : byte2)
    temp.add(new Byte(c));
    temp.addElement(Byte.valueOf(middlerow));
    val = r.getvalues();
    byte[] tempByte1;
    for (int e = 0; e <= val.length - 1; e++) {
    // Returns a string representation of the double argument.
    tempByte1 = Double.toString(val[e]).getBytes();
    for (int j = 0; j < tempByte1.length; j++) {
    temp.addElement(Byte.valueOf(tempByte1[j]));
    temp.addElement(Byte.valueOf(middlerow));
    temp.addElement(Byte.valueOf(endrow));
    data = new byte[temp.size()];
    for (int t = 0; t < temp.size(); t++) {
    data[t] = (((Byte) temp.elementAt(t)).byteValue());
    return data;
    public class Riga{
         private String geneid=null;
         private Double[] values=null;
         public Riga(String idGene,Double[] x ) {
    this.geneid=idGene;
    this.values=x;
         public String getgeneid(){
              return this.geneid;
         public void setgeneid(String idGene){
              this.geneid=idGene;
         public Double[] getvalues(){
              return this.values;
         public void setvalues(Double[] x){
              this.values=x;
    Message was edited by:
    giubat

    Maybe I didn't understand you, but why are you putting a file with 50000 rows as one single BLOB into a DB? Don't you think it's time for a new table?

  • Sort functionality using MULTIPLE columns in a table control

    Hi all,
    I have a custom screen with table control.Now i need to provide SORT functinality in this screen for the columns in the table control.
    My questins:
    1.Is it possible to seelct MULTIPLE columns in a table control for SORTING?If yes,what explicit settings do i need to do while creatng the TABEL CONTROL in the screen?DO I need to select "Column selection " as MULTIPLE??
    2.How do I write the code for SORT functinonality for multiple columns?
    I know how to write the code for SORTING on basis of single column .
    Thanks!

    Hi Rob,
    Thanks for the reply.
    However I was thinking to apply the same logic as for single columns as follows:
    types : begin of ty_fields,
                c_fieldname(20),
               end of ty_fields.
    data  : t_fields type table of ty_fields,
               wa_fields like line of t_fields.
    WHEN 'SORTUP'.(Ascending)
          loop at TABLE tc01-cols INTO wa_tc01  where  selected = 'X'.
          SPLIT wa_tc01-screen-name AT '-' INTO g_help g_fieldname.
          wa_fields-c_fieldname = g_fieldname.
          append wa_fields to t_fields.
          endloop.
          describe table t_fields lines l_index.
          c_count = 1.
          if c_count  <= l_index.
          read table t_fields into wa_fields index c_count.
          case c_count.
          when '1'.
          l_field1 = wa_fields-c_fieldname.
          when '2'.
         l_field2 = wa_fields-c_fieldname.
        and so on depending on the no of columns in the table control...
          endcase.
          endif.
          SORT t_tvbdpl_scr BY  l_fields1 l_fields 2......l_fieldn.
    Let me know if the above method will work!Also for the above method to work will the type of fields(columns on whihc sort function will be applied) matter???
    Thanks again for your time.

  • How to code a predifined function module in sap ,in se37.

    can any one tell me how to code a predifined function module in sap ,in se37.it's an immediate requirement.if u give a brief description it'll do.

    Hi Henry,
    There are two possible ways in which I can interpret your question.
    1. You want to create a new Function Module in SE37. you will have to refer to the <a href="http://help.sap.com/saphelp_47x200/helpdata/en/d1/801e9a454211d189710000e8322d00/frameset.htm">Function Builder</a> tutorial for that.
    2. You want to use an existing function module in your program. In the code of your program in SE38, click the button <i>Pattern</i>. On the pop-up, give the name of the function module that you wish to use in your program.
    Regards,
    Anand Mandalika.

  • How to remove the sort function on the drill down and then save

    how to remove the sort function on the drill down and then save in the  change local view of the Query
    Is it possible to change the porperties of any characteristic in the local view and then save?
    If so please post the answer.

    I do not think that option is possible.
    Regards,
    Venkata Boga.

  • Sort functionality in Data Grid

    Hi Gurus,
    I am new to this DataGrid control.I want to establish the sort functionality when clicking on the headercolumns as in matrices.
    (ie.When double clicking the header column , sort the data in ascending or descending order of that column) like in system form matrices.
    How ever this is not possible when I tried with grid control.
    The problem I am facing is that I cannot get the column headers of the grid programmatically.(in duble click event or itempressed event)
    Anybody did this one previously? Also how
    we can change the column order of the grid using screen painter?
    The columns that actually come visible in the grid  are actually columns of the linked datatable object.
    In the designer ,there is no "swap" button for column re-ordering.
    Only one way I know is changing the query associated with datatable.
    This is a crucial thing ,since client may ask for re-ordering of columns frequently.
    Can anybody help?
    Regards,
    Deepesh

    Hi Deepesh,
    1. This functionality is not available with the SDK. Thus it's not possible to change it on the fly. Your only option is to change the query associated with datatable (as you mentioned). You may set up a user preference table, that the user can configure with its preference. That's the best you can do.
    2. To swap the columns in screen painter you must use SBO 2005 (it's not available on previous release). What you must do is, click on the one column you want to swap and the other you want to swap and click on the swap button (on the left bottom of the page in the columns tab)

  • Transaction code to see function group

    transaction code to see function group

    Avinash,
    there is separate T Code function group. SE37 and then go through the menu.
    Go To--> Function Groups.
    Regards,
    Ravi
    Note : Please reward and close the posts.

  • Unable to write, type anything in source code of a function module.

    Hi all,
    We have a registered name space for our client called /ABCD/EFG.
    I need to create a function module in the name space.
    So first I created a Function Group called /ABCD/EFG_FG in /ABCD/EFG. I activated it in se80.
    Then I created a Function Module called /ABCD/EFG_FM in /ABCD/EFG. I declared the import and export paramters and now I am trying to add the code in source code and the editor does not let me change the source code donu2019t know why.. and every thing is in grey color.
    Can some one tell me what is going wrong? Cant we write any logic in the function module that we create in registered name spaces? When I created the same function module as a local object in $TMP package I dint have any problem. Similarly I created the function module in a Z package and I dint have any problem but if I try to create the same function module in a registered name space it is getting created but it doesnu2019t not let me type anything in the source code of the function module.
    Did any body encounter this problem earlier? Kindly please help.
    Regards,
    Jessica Sam

    Rich,
    Thanks a lot, that worked. Now it lets me type and change the source code of the editor.
    But while i was turing off the assistant it showed me 2-3 messages saying that "i cannot track the changes" and that "during upgrade i cant track the changes " etc.
    So now i can type in source code and i am able to change in source code..but will the trurning of this assistant cause any problmes in future or during upgrade?
    Regards,
    Jessica Sam

  • Sort function doesn't work E12

    the sort function doesn't work half the time on Elements 12 organizer.

    What about FUNCTION CLOCK_INFormula
    RETURN NUMBER
    IS
        l_hours_worked  NUMBER;
        l_to_return     NUMBER;
    BEGIN
        l_hours_worked := TO_NUMBER(NVL(:ATX_CLOCK_IN,'0'));
        IF (MOD((l_hours_worked - 0.02),0.25) = 0) THEN
            l_to_return := TRUNC((l_hours_worked - 0.02) * 4) / 4;
        ELSE
            l_to_return := TRUNC((l_hours_worked + 0.23) * 4) / 4;
        END IF;
        RETURN (l_to_return);
    EXCEPTION  
        WHEN VALUE_ERROR THEN
            RAISE_APPLICATION_ERROR ( -20100
            ,   'ERROR, Cannot represent '
            ||  :ATX_CLOCK_IN
            ||  ' as a number.');
    END CLOCK_INFormula;?
    This function assumes :ATX_CLOCK_IN is always positive.
    T.

Maybe you are looking for