Splitting and type casting huge string into arrays

Hello,
I'm developing an application which is supposed to read measurement files. Files contain I16 and SGL data which is type casted into string. I16 data is data from analog input and SGL is from CAN-bus data in channel form. CAN and analog data is recorded using same scan rate.
For example, if we have 6 analog channels and 2 CAN channels string will be (A represents analog and C represents CAN):
A1 A2 A3 A4 A5 A6 C1 C2 A1 A2 A3 A4 A5 A6 C1 C2 A1 A2 .... and so on
Anyway, I have problems reading this data fast enough into arrays. Most obvious solution to me was to use shift registers and split string in for loop. I created a for loop with two inner for loops. Number of scans to read from string is wired to N terminal of the outermost loop. Shift register is initialized with string read from file.
First of the inner loops reads analog input data. Number of analog channels is wired to its N terminal. It's using split string to read 2 bytes at a time and then type casts data to I16. Rest of the string is wired to shift register. When every I16 channel from scan is read, rest of the string is passed to shift register of the second for loop.
Second loop is for reading CAN channels. It's similar to first loop except data is read 4 bytes at a time and type casted to SGL. When every CAN channel from scan is read, rest of the string is passed to shift register of the outermost loop. Outputs of type cast functions are tunneled out of loops to produce 2D arrays.
This way reading about 500 KB of data can take for example tens of seconds depending on PC and number of channels. That's way too long as we want to read several megabytes at a time.
I created also an example with one inner loop and all data is type casted to I16. That is extremely fast when compared to two inner loops!
Then I also made a test with two inner loops where I replaced shift register and split string with string subset. That's also faster than two inner loops + shift register, but still not fast enough. Any improvement ideas are highly appreciated. Shift register example attached (LV 7.1)
Thanks in advance,
Jakke Palonen
Attachments:
String to I16 and SGL arrays.vi ‏39 KB

OK, there is clearly room for improvement. I did some timing and my two above suggestions are already about 100x faster than yours. A few teeaks led to a version that is now over 500x faster than the original code.
A few timings on my rather slow computer (1GHz PIII Laptop) are shown on the front panel. For example with 10000 scans (~160kB data as 6+2) my new fastest version (Reshape II) takes 14 ms versus the original 7200ms! It can do 100000 scans (1.6MB data) in under 200 ms and 1000000 scans (15MB data) in under 2 seconds.
I am sure the code could be further improved. I recommend the Reshape II algoritm. It is fastest and can deal with variable channel counts. Modify as needed.
Attached is a LabVIEW 7.1 version of the benchmarking code, containing all algorithms. I have verified that all algorithms produce the same result (with the limitation that the cluster version only works for 6*I16+2*SGL data, of course). Remember that the reshape function is extremely efficient, because it does not move the data in memory. I have some ideas for further improvements, but this should get you going.
Message Edited by altenbach on 08-05-2005 03:06 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
StringI16SGLCastingTimer.png ‏48 KB
StringtoI16andSGLArraysMODTimer.vi ‏120 KB

Similar Messages

  • How to use type cast change string to number(dbl)?can it work?

    how to use type cast change string to number(dbl)?can it work?

    Do you want to Type Cast (function in the Advanced >> Data Manipulation palette) or Convert (functions in the String >> String/Number Conversion palette)?
    2 simple examples:
    "1" cast as I8 = 49 or 31 hex.
    "1" converted to decimal = 1.
    "20" cast as I16 = 12848 or 3230 hex.
    "20" converted to decimal = 20.
    Note that type casting a string to an integer results in a byte by byte conversion to the ASCII values.
    32 hex is an ASCII "2" and 30 hex is an ASCII "0" so "20" cast as I16 becomes 3230 hex.
    When type casting a string to a double, the string must conform the the IEEE 32 bit floating point representation, which is typically not easy to enter from the keyboard.
    See tha attached LabView 6.1 example.
    Attachments:
    TypeCastAndConvert.vi ‏34 KB

  • Parse string into array for comparison

    Hi All,
    I am trying to parse a string message into an array of numbers so I can check if my event was successful.
    \FF\FE\01\FD\02\00\00\00
    I know I just need to read through and discard the \, but I don't know how to do that in Labview. I just need to check if the 6th byte = 00 or not.
    Thanks! I mostly need help with parsing in labview.

    Assuming this is a plain ASCII string containing the letters 0..F and "\" as delimiter, you can simply used "Spreadsheet string to array" with the following settings:
    Type= 1D U8 array
    format= %x
    delimiter= "\"
    One problem is the extra delimiter at the beginning, so use array subset to skip the first element.
    (EDIT: Ahh, Darin beat me with a similar solution. Mine's a little easier ).
    Message Edited by altenbach on 08-06-2009 04:30 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StringToArray.png ‏13 KB

  • How can i store values from my String into Array

    Hi guys
    i wants to store all the values from my string into an array,,,, after converting them into intergers,,,, how i can do this becs i have a peice of code which just give me a value of a character at time,,,,charat(2)...BUT i want to the values from String to store in an Array
    here is my peice of code which i m using for 1 char at time
    int[] ExampleArray2 = new int[24];
    String tempci = "Battle of Midway";
    for(int i=0;i>=tempci.length();i++)
    int ascii = tempci.charAt(i); //Get ascii value for the first character.

    public class d1
         public static final void main( String args[] )
              int[] ExampleArray2 = new int[24];
              String tempci = "Battle of Midway";
              for(int i=0;i<tempci.length();i++)
                   int ascii = tempci.charAt(i);
                   ExampleArray2=ascii;
              for(int i=0;i<ExampleArray2.length;i++)
                   System.out.println(ExampleArray2[i]);

  • String into array in oracle

    Hi,
    I have value in a column in oracle table as "DE","DS","KJ".
    now,How can I get them into string array?
    Is there any API to get this ..
    Thanks
    Chat

    I have value in a column in oracle table as "DE","DS","KJ".
    now,How can I get them into string array?Do you mean that you have a single string with quotes and commas? If so you have to parse it to extract the constituent strings. Ostermiller has a library that does this sort of thing (Google ostermiller csv) and deals with the complexity of commas and quotes within the quoted parts.
    (If you know the string value consists of quoted section separated by commas, and there is no possibility of spaces getting in the way, you could split the string based on "," and then take substrings to remove the quotes.)
    You should pick one thread for this and stick to it. Put a message in the other linking to the thread you want to use.

  • Set of string into array or a table....

    Hi Experts,
    I am using Oracle 10G, where I need to accomplish a task...
    I am getting a set of string of the sort
    "|session_id~q_id~q_key~rt_id~rt_key~request_type~field_id|session_id~q_id~q_key~rt_id~rt_key~request_type~field_id| ....."
    Here, as you can see every set which has 7 values is delimited by a "| (pipe)" and every value is delimited by a "~" ...
    I need to insert all these into a generic table and before doing that I need to split it into individual values where every set which has 7 values will get into 7 columns in a row...
    Can anyone help me out with a proper logic as to how do i go about accomplishing the same...???

    Hi,
    You have to use regular expression to tokenize string in fragments.
    This is sample for determining CRLF in a string:
    -- Tokenize rows
    FOR token IN ( SELECT REGEXP_REPLACE(REGEXP_SUBSTR(XMLCDATA('custom_string') || Chr(10), '(.*' || Chr(10) || ')', 1, LEVEL ), Chr(10), '') t
    FROM dual
    CONNECT BY REGEXP_INSTR('custom_string'||Chr(10), '(.*'||Chr(10)||')',1, LEVEL ) > 0) LOOP
    token.t --> single fragment
    END LOOP;
    Bear in mind that this forum is for Data Modeler product related issues, feedback etc. So before posting question search for appropriate forum. It's quite possible that you won't get answer while in wrong forum.
    Regards
    Edited by: Dimitar Slavov on Apr 15, 2011 2:11 AM

  • Type cast with string name

    I have a hashtable full of Objects. I also have there type represented by a String. How can I typecast these Objects back to there type. i.e.
    String str = "helpme";
    str = (Object)str;
    String type = "String";
    can I use the var type to cast str back to a String;

    I've never used reflection before so my answer maybe way off from what you're looking for.... but to solve your problem on casting an Object to a type specified by a String variable you could use a case or if statement if you know what types are available ahead of time and call the appropriate methods to return your Object type.
    For example... You could create a method for each type you expect to return.
    public String getStringValue( Object obj ) {
         return (String)obj;
    public Integer getIntegerValue( Object obj ) {
         return (Integer)obj;
    public Byte getByteValue( Object obj ) {
         return (Byte)obj;
    }Then... depending on what the value of your String type variable is you can call the appropriate method that will return the Object type you're wanting.
    String type = "String";
    if( type.equals("String") )
         String yourStr = getStringValue(yourObject);
    else if( type.equals("Integer") )
         Integer yourInt = getIntegerValue(yourObject);
    else if( type.equals("Byte") )
         Byte yourByte = getByteValue(yourObject);This maybe not be the most efficient way especially since there can be potential errors but it can work assuming the String type is really representing the type of Object yourObject is.
    I don't know.. just a possible solution that popped in my head.
    .kim

  • Type cast with String representation

    I have a hashtable full of Objects along with a String representation of their type. Is it possible to cast an Object back using a String representation of its type. ie
    String str = "helpme";
    String type = "String";
    str = (Object)str;
    now I want to get str back to String type but with using the variable type.

    Do not crosspost: http://forum.java.sun.com/thread.jsp?thread=355714&forum=4&message=1482427

  • Is there a way to type cast an array of strings to numbers and back again?

    I'm working on an application where I want to type cast a string like "power supply" into an array of existing numbers. Then sort the existing numbers, and finally convert the casted numbers back into a string so it can be read by the user. In the attachment, you can see my latest attempt with flatten/unflatten data and the 'convert string to byte array'. I can't seem to make this work. Any ideas?
    Thanks - Paul
    Attachments:
    Paul's Temp scan for components.vi ‏56 KB

    OK, here's a quickie (LabVIEW 7.0).
    Simply get the sort key from the 1D array, then build the table.
    Message Edited by altenbach on 10-27-2006 01:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortedTable.png ‏4 KB
    SortedTable.vi ‏37 KB

  • Type casting arrays

    i m reading an array of int from ObjectOutPutStream. can any body tell how do we type cast an object to array ??

    karansha:
    I'm sure you mean you're trying to read in an int[] from an ObjectInputStream that was written to an ObjectOutputStream since you can't read from an OutputStream. Use something like this:
    ObjectInputStream in = <whatever>;
    int[] intArray = (int[])in.readObject();adramolek:
    Why should you use an Integer[] instead of an int[] for serialization? All arrays of primitives -- boolean[], byte[], double[], float[], int[], long[], short[] -- are serializable as is; there is no need to convert them to arrays of their wrapper types simply to serialize them.
    In fact, the output from the following piece of code shows exactly which interfaces are implements by an int[]:
    Class cls = int[].class;
    Class[] interfaces = cls.getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        System.out.println(interfaces.getName());
    The output is:
    java.lang.Cloneable
    java.io.SerializableThe output is identical for each of boolean[], byte[], double[], float[], int[], long[], and short[], showing that each type is both serializable [i]and cloneable.
    Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Req help in conversion of string to array of args

    Hi,
    i need help in converting a string into array of args just like command line args
    i have a string s1 = 12 13 56 etc
    now i want to copy that into an array a[]
    a[0] = 12
    a[1] = 13 etc
    Thanks for help

    U can use String tokenizer.Why prefer that over split?Yah Bobby u can use split too..
    J2SE 1.4 added the split() method to simplify the task of breaking a string into substrings, or tokens.
    Thanks BigDaddy.. I realized after you told.
    try this too..
    String str = "Your string";
    String[] arr = str.split (" ");
    for (int i=0; i < arr.length; i++)
    System.out.println (arr);

  • Reading a binary file using the type cast function is not working

    Hello
    I am trying to read a binary file.  Using the Read from binary file and type cast functions I can actually get the information from the file.
    I set an indicator in the “Normal” option in Properties. I can read the header and footer but not the body of the file; For the body of the file all I can see is characters of the type
    “C¾ Ü Qþ  X@ “. One of the other options, Password, seems to provide an output of just the characters that were originally written, but then again, I can not read the characters because it is only asterisks and I can not copy them onto a word processor either.
    I tried setting the indicator in Hexadecimal mode, then creating a local variable that acts as a control and use the type cast function again to see if  could convert the Hexadecimal string to readable ASCII characters; unfortunately, this did not work either.
    I don’t know what else I should try or if there is something that I may not be doing right and for that reason I am not getting the desired results. I hope someone has an idea about this issue.
    Regards,
    Roberto

    Thank you for your reply,
    Well, actually I don’t have any information about this file. I will try to obtain information about it though.
    This is a file that contains velocity information; there are 65 channels that form a velocity profile in a pipe. Also, there are 4096 velocity profiles. I don’t know what is the format of these values.
    The software that creates the file provides a text file. Using this text file the velocity information can be processed and then plotted.
    I want to avoid all these intermediate steps and read, process and plot everything using only LabView. BTW, I am using LabView 8.2
    Roberto

  • Could not type cast in java embedding

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    org.xml.sax.InputSource in = (org.xml.sax.InputSource) getVariableData("Invoke_1_getRoutingAndFrameJumpers_OutputVariable","getRoutingAndFrameJumpersResponse");
    Document doc = db.parse(in);
    In the above code I am trying to type cast the variable getRoutingAndFrameJumpersResponse into org.xml.sax.InputSource so that i can parse.
    I am not getting any error during compilation
    but I am unable to type cast some run time error is coming in the line were I am type casting but I am not able to see the runtime error.
    How can I see the runtime error in java embedding, how to type cast a variable into xml so that I can parse it.

    Hi Arun,
    Could you try using the bpelx:rename extension in an assign activity enables a BPEL process to rename an element through use of XSD type casting.
    <bpel:assign>
    <bpelx:rename elementTo="QName1"? typeCastTo="QName2"?>
    <bpelx:target variable="ncname" part="ncname"? query="xpath_str" />
    </bpelx:rename>
    </bpel:assign>
    Cheers
    A

  • How to cast an Object into a specific type (Integer/String) at runtime

    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    Example:
    public class TestCode {
         public static Object func1()
    Integer i = new Integer(10); //or String str = new String("abc");
    Object temp= i; //or Object temp= str;
    return temp;
         public static void func2(Integer param1)
              //Performing some stuff
         public static void main(String args[])
         Object obj = func1();
    //cast obj into Integer at run time
         func2(Integer);
    Description:
    In example, func1() will be called first which will return an object. Returned object refer to an Integer object or an String object. Now at run time, I want to cast this object to the class its referring to (Integer or String).
    For e.g., if returned object is referring to Integer then cast that object into Integer and call func2() by passing Integer object.

    GDS123 wrote:
    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    There is only one way to have an object of an unknown type at compile time. That is to create the object's class at runtime using a classloader. Typically a URLClassloader.
    Look into
    Class.ForName(String)

  • How do I split a comma delimited string into an array.

    I have a string that I am passing into a function that is Comma delimited. I want to split the string into an array. Is there a way to do this.
    Thanks in advance.

    trouble confirmed on 10gR1 and 10gR2
    works with 'a,b,c'  and also with  '  "1"  , "2"  ,  "3"  '
    does not work with '1,2,3' 
    throwing ORA-6512                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Cloud Licensing - Can Adobe Acrobat 9.0.0 Standard / Professional both be used on Windows RDS 2012 R2?

    We have users that share a remote desktop server, Windows 2012 R2.   We use Adobe Acrobat 9.0.0 standard and professional.  Is there a conflict in software or legality for allowing our users both these programs simultaneously on the remote Cloud serv

  • CSS positioning for complext layout

    I've been creating web page layouts with tables for many years now and realise that it's time to move to CSS positioning instead. Having gone through various tutorials, I've mastered the art of creating a 3-column layout, however the design I'm worki

  • Messaging Server 4.15 Plug-in API

    I need to convert a messaging server 3.6 plug-in into a messaging server 4.15 plug-in. I got the messaging server 4.15 plug-in API guide. I wrote a plug-in. Building the SMTP plug-in is OK. I installed this plug-in by configuring the SMTP plug-in con

  • Why we can't rollback a firmware

    I have posted this question about why I have lost my player track on my HTC ONE X but is still not answered. now my follow up question is why we can't rollback a firmware because you ( Sony ) thinks you have solved a problem for a galaxy note or xper

  • Different Colors in Safari & Explorer

    Hello there, First to get an answer to my question to "why the colors look different on Safari and Explorer" I thought I would browse through some posts here. I found out that .jpg files should have a color profile (sRGB) assigned to them so they loo