Casting arrays from double to float

Hi, wonder if anyone can help.
I have a method of a class that creates two double arrays (the value pointed to is a double type)
x[][]
y[][]
they are essentially co-ordinates. The first dimension of the array holds the polygon number, the second the point on that polygon for the x and y respectivly.
This method is called from (and therefore the arrays returned to) a class in an applet i am designing.
I now have to get these co-ords into a general path for display. A general path only takes float values. I have tried all the normal casting tricks to try to convert these doubles into floats and nothing is working. Do you have to do anything special because they are in arrays.
Any help would be appriciated.

There is nothing special about array except that you cannot cast them.
Instead you need to create a new set of arrays and copy/cast each value individually.

Similar Messages

  • I want to cast Array to double[]

    I make an windowsForm class for draw graph.
    It has an input param
    public FormGraph(string title, string name1, Array data1)
    I need data of double[] type for draw graph. But I think users are want to input double[] or int[] ect...
    So I try to get data as Array type and cast it to double[].
    double[] series1 = (double[])data1;
    But it throw exception about fail to cast.
    How can I cast variable type of array to double[]?

    Another option is to combine Generics with this.
    You can use generics to allow the users to pass different types of data to a method, but type specific in a different way.
    public FormGraph<T>(string title, string name1, IEnumerable<T> data1)
    var series1 = data1.Select(x => Convert.ToDouble(x)).ToArray();
    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

  • How can I change two elements in an array from double to integer.

    I have my program working just fine until it comes to saving the file. I have a 2 dimensional array that has data at 0,0 0,1 and 0,2. It is being displayed perfectly the way I have it set up. The problem is where it comes to saving the file. I want elements 0,0 and 0,1 to be an integer and 0,3 to be a fractional number. I can only save it as one or the other. I am sending the data to a write to text file VI which only allows one or the other. Does anyone have any ideas of how to over come this? I know from probing that the data is getting to the write to text file VI in the format that I want it to.
    Thanks,
    Troy

    Sure.. (LabVIEW 7.0)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    VariableFormat.vi ‏20 KB

  • Will I lose data converting from double-pre​cision to single-pre​cision float?

    Before you say yes... 
    I am using a crio device in scan-mode interface. The values that the scan mode returns are in double-precision floating point. Apparently I am supposed to be able to choose between double-precision floating point ("calibrated") and fixed-point ("uncalibrated") data, but this functionality appears to be exclusive to the fpga interface and is not available with the scan engine. Both data types are 64-bits per value, so when it comes to size-on-disk, either way is basically the same anyways.
    The system is continuously recording 13 channels of double-precision floating point at 200Hz. Using the binary file write method, I have measured this to be about 92 MB/hr to disk. (over 120mb/hr with tdms and a lot more for write to spreadsheet) Simply put, this 92 mb/hr rate is just too much data to disk on this system. 
    The modules I am recording from, the 9236, 9237, and 9215 c-series modules, have 24-bit ADCs or less. Does this mean I don't need 64 bits to represent the number and maintain the same accuracy?
    Can I coerce/cast the double-precision floating point values I am receiving from the scan engine i/o variables to another, smaller data type like single-precision floating point and still maintain the same accuracy?
    Message Edited by rex1030 on 08-27-2009 04:19 PM
    [will work for kudos]
    Solved!
    Go to Solution.

    For some reason the scan interface isnt letting me output the raw U32 values. I think it might have something to do with the fact that I am using both scan engine and fpga interfaces in the project, but I am not sure. Any ideas why this is happening?
    This is a picture of me right mouse clicking on one of the modules to try to get it to put out raw U32 values like this knowledgebase article says I can.
    I put in a service request.. (Reference#7256901) because to be honest I have to know for sure whats going on. I am not one of the engineers/scientists that designed the experiment so I cannot say whether it is ok to chop some of the end of the number off. I would rather simply be able to record all the data in a smaller amount of disk space then go tell them we have to compromise somewhere, whether on sample rate or precision. 
    [will work for kudos]

  • Reading arrays of double from S7 with OPC & Datasocket

    Hi friends:
    We are developing an application with a S7-315-2DP PLC and a PC with a PCI1500PFB. We use the OPC server from Applicom. We read the data very quickly with the datasocket (arrays of boolean, arrays of doubles ...and so on, and a very big amount of data over 100 ms) but when we try to write arrays datasocket faield and we have to write item on item and the speed decrease. For intance, if we try to write doubles ( 50 items) the refresh period is over 5 seconds ( some times more since we launch the data and we read the same data on the PC). Perhaps we failed configuring the OPC but there isn´t many things to configure, perhaps the problem is the board configuration .. I don´t know.
    We
    try to find some examples that write an array of doubles on one time but..
    Thank you for yours answers.
    Javi

    Hi Javi,
    I'm not aware of any known issues writing to the Applicom OPC server. In LabVIEW there isn't anything special you need to configure to be able to write arrays of doubles through DataSocket. You can test this by using the DataSocket Server Manager, make a new member that is an array of doubles, and try reading and writing to that member. You may also want to check to make sure the data member the OPC server is expecting is an arry of doubles and not an array of singles or integers.

  • Converting array of Double Precision values to U16 for MODBUS

    Hello,
    I am trying to send over pressure and temperature information via the Input Register array in MODBUS TCP.  My question is, how to I properly send over an array of double precision values without loosing my data?
    For example, my array of data looks like:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    Thanks so much.

    Thank you Ravens Fan for replying.
    I missed one extra point of data.  Below is what I'd like to send:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    2046
    The array above is an array of double precision values.  I will convert that array to an array of single precision floating data to reduce data size.
    Since I have eight pieces of single precision floating point data now, I will need to write to 16 registers correct?  What is the best method to split up each piece of data into two consecutive registers?
    Attached is a Slave Send Data.VI that I want to send this data through.  The end goal is to have a Master PC (not using labview, but a MODBUS utility) to read my MODBUS TCP message from the "Slave Send Data.vi" 
    Thanks
    Attachments:
    Slave Send Data.vi ‏15 KB

  • Need help on returning arrays from C++ to Java

    Hi all, I hava a C++ application that contains a method that will return a float array to Java. I was able to write the Java Code, the JNI code to call the C++ method and compile them successfully. However on calling the native method from Java, the data in the array returned was not what I want. Please look through my code and see what is wrong with it.
    My Java Code:
    public native float[] Statistics(int inputKey); // This is the native method
    public float[] Stats(int k){ //Java method to call the native method so that I can use it in a Bean for a JSP.
    inputKey = k;
    float[] p = new float[4];
    p = Statistics(inputKey);
    return p;
    For this native method, an integer is passed from Java to the native side and the native method will use this integer to generate a float array size of 4 and populate it with data and return it back to Java.
    My JNI code
    extern "C"
    JNIEXPORT jfloatArray JNICALL
    Java_com_jspsmart_upload_FinalWaterMark_Statistics(JNIEnv *env, jobject obj, jint inputKey)
         jfloatArray floatArray = env->NewFloatArray(4); //This creates a new Java floatArray to store the C++ array
         CWatermarker2App p; // This is the C++ class to be used
         jfloat *stats = p.OnWatermarkStatistics(inputKey) // The C++ method returns a float pointer for an array of size 4
         env->SetFloatArrayRegion(floatArray, 0 , 4 , stats); //storing the C++ float array into the Java float Array
         return floatArray; // return the Array to Java
    In this example, I should have the data returned as [4952.0 2529.0 1706.0 33.6] in the array.
    But i am getting junk instead like 2.53E-23, 1.402E-15 etc..
    Is this a type conversion mistake?
    Please help!

    The first thing I notice - probably not the problem - is the line defining p. There is no reason to define this as an array of size 4, because the return from the native method is going to wipe that definition, replacing it with the return value of the native method. Alternatives:
    1. float[] p = null.
    2. float[] p = Statistics(inputKey);
    3. return Statistics(k);

  • How can i get a array from a JSP ?

    Hi all,
    i have a STORED PROCEDURE like this:
    static public void getMyArray(double [] xx) {
    for (int i=0; i<myarr.length;i++){
    myarr=3.145*i;
    xx=myarr;
    return ;
    how can i get the array with XSQL and transform with a XSL ?
    Is this at all possible?
    Thanks for any help.
    Achim

    u r asking how ca u get array from jsp?
    and u r asking xsql ...some stuff i couldnot understand .can u repeat the question properly?
    null

  • Reading in an array from a text file

    I'm trying to use a text file to load in some configuratin
    data (using actionscript 3) I have it working ok for simple stuff
    like gamename=Chess&gamescore=100 , etc... but some of the data
    needs to be in an array. Can someone please point me in the right
    direction to how I can read in an array from a text file?
    Thanks!

    the easiest way is to create a string with the (soon-to-be)
    array elements separated by a delimiter (like a double comma). read
    in your string, then use the split() method of strings to split
    your string into an array.

  • Calling an array from another class

    Ok I have this little program that I created to display values stored in an array. Well, I want my array to automatically be populated with the same values that are in another array that resides in a different class. Here is my code for the class that I want the values to be displayed:
    import javax.swing.*;
    import java.awt.*;
    public class GUIRead extends JFrame
         double[] interest = new double[3];
         MemicCSVReader[] interestObjectArray = new MemicCSVReader[3];
         interestObjectArray[0] = new MemicCSVReader();
         interestObjectArray[1] = new MemicCSVReader();
         interestObjectArray[2] = new MemicCSVReader():
         for(int x = 0; x < 3; x++)
         JPanel display = new JPanel();
         JTextField interestText = new JTextField(10);
         JPanel display2 = new JPanel();
         JTextField interestText2 = new JTextField(10);
         JPanel display3 = new JPanel();
         JTextField interestText3 = new JTextField(10);
         public GUIRead()
              super("Test");
              setSize(160,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              GridLayout config = new GridLayout(3,1);
              FlowLayout config2 = new FlowLayout(FlowLayout.LEFT,10,10);
              Container pane = getContentPane();
              pane.setLayout(config2);
              display.setLayout(config2);
              display.add(interestText);
              interestText.setText(interest[0]);
              interestText.setEditable(false);
              pane.add(display);
              display2.setLayout(config2);
              display2.add(interestText2);
              interestText2.setText(interest[1]);
              interestText2.setEditable(false);
              pane.add(display2);
              display3.setLayout(config2);
              display3.add(interestText3);
              interestText3.setText(interest[2]);
              interestText3.setEditable(false);
              pane.add(display3);
              setContentPane(pane);
         public static void main(String[] args)
              GUIRead run = new GUIRead();
    Here is my code that I want the double[] interest array to pull it's data from:
    public class MemicCSVReader
         double interestArray[];
         MemicCSVReader()
              String[] interestString = {"5.5","5.35","5.75"};
              for(int x = 0; x < 3; x++)
                   interestArray[x] = Double.parseDouble(interestString[x]);
    }

    Ok, thanks for your help. Now I have another problem. I can't get the values to display. Here is my code:
    This is the program that runs the application:
    import javax.swing.*;
    import java.awt.*;
    public class GUIRead extends JFrame
         MemicCSVReader readCSV = new MemicCSVReader();
         double[] interestDouble = readCSV.getInterestArray();
         String[] interest;
         JPanel display = new JPanel();
         JTextField interestText = new JTextField(10);
         JPanel display2 = new JPanel();
         JTextField interestText2 = new JTextField(10);
         JPanel display3 = new JPanel();
         JTextField interestText3 = new JTextField(10);
         public GUIRead()
              super("Test");
              setSize(160,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              GridLayout config = new GridLayout(3,1);
              FlowLayout config2 = new FlowLayout(FlowLayout.LEFT,10,10);
              Container pane = getContentPane();
              pane.setLayout(config2);
              display.setLayout(config2);
              display.add(interestText);
              interestText.setEditable(false);
              pane.add(display);
              display2.setLayout(config2);
              display2.add(interestText2);
              interestText2.setEditable(false);
              pane.add(display2);
              display3.setLayout(config2);
              display3.add(interestText3);
              interestText3.setEditable(false);
              pane.add(display3);
              setContentPane(pane);
         public void actionPerformed()
              for(int x = 0; x < 3; x++)
                   interest[x] = Double.toString(interestDouble[x]);
              interestText.setText(interest[0]);
              interestText2.setText(interest[1]);
              interestText3.setText(interest[2]);
         public static void main(String[] args)
              GUIRead run = new GUIRead();
    This is the file that it pulls the array from:
    public class MemicCSVReader
         private double[] InterestArray = new double[3];
         MemicCSVReader()
              double[] InterestArray = {5.5,5.35,5.75};
         public double[] getInterestArray()
              return InterestArray;
    }

  • Displaying array from another method

    Hello for this code I want to display the array from the first method in the second method although when I run it, it displays 6 times the whole array - well the the last iteration shows the whole array. I have only just started using different methods.
    Please could someone say why this is happening.
    Cheers
    John
    import java.util.*;
    public class Lottery
         public static void main(String[] argStrings)
              int[] lotteryArray = new int[6];
              for(int count = 0; count < 6; count++)
                   double randomNumber = Math.random();
                   double biggerRandom = (randomNumber * 50);
                   int integerNumber = (int)biggerRandom;
                   lotteryArray[count] = integerNumber;
                   displayNumbers(lotteryArray);
         public static void displayNumbers(int[] lotteryArray)
              System.out.println("Lottery numbers are:");
              for(int i = 0; i < lotteryArray.length; i++)
                   System.out.print(lotteryArray[i] + " ");
              System.out.println();
    }

    Well I know your right but actualy getting this to work for my program is proving hard. This is my progress so far:
    Cheers
    John
    public static void main(String[] argStrings)
              int[] lotteryArray = new int[6];
              int p = 0;
              boolean duplicate = false;
              while(p < 6)
                   for(int count = 0; count < lotteryArray.length; count++)
                        double randomNumber = Math.random();
                        double biggerRandom = (randomNumber * 50);
                        int integerNumber = (int)biggerRandom;
                        if (lotteryArray == lotteryArray[count])
                             duplicate = true;
                        if (duplicate == false) //not a duplicate
                             lotteryArray[++count] = integerNumber;
                   displayNumbers(lotteryArray);
         }

  • Convert from String to float

    How do I convert from String to float?

    Hi,
    you can use a Double for example - assuming value is that string to parse
    float f;
    try { Double d = new Double(value); f = d.floatValue(); }
    catch (NumberFormatException e) { f = 0.0; } // error - string value could not be parsed
    // here use your float fHope, that helps
    greetings Marsian
    P.S.: the Double class is usefull for that, because you also can get intValue(), doubleValue() or longValue() out of it for example. The StreamTokenizer for example parses numbers also only to double.

  • Consume web service I get an unable to cast array error?????

    Hi All,
    I do not know what I have done but I am getting the following error?
    Error(24,30): cannot cast array webserviceproj2.proxy.Employee[] to interface java.util.List&lt;webserviceproj2.proxy.Employee&gt;
    Here is my Scenario
    Project 1
    I have a Project which contains One class that was generated by Toplink "Employees" I have a Map with a few queries
    I Create a Java Service Facade to test and everything works fine...
    I create a session bean with a Remote, Local and Web service endpoint which generates the deploy file for me.
    I Deploy to Oracle AS 10.1.3 and test the web service. Again all is working so far.
    Project 2
    I Create an empty project and add a web service proxy, I use the WSDL from the deployed Session Bean to generate all the files. So far I have added no code.
    I create a test class. One of the methods should get a list of Employees from the web service so I can loop through the list to prove it's working, this is where it fails. For some reason findEmployees is returning a type of Employee[] rather than a List&lt;Employee&gt; which is what should be returned?
    Can anyone please help????
    List&lt;Employee&gt; emps = (List&lt;Employee&gt;)port.findEmployeesByName("Jeremy","");
    for(Iterator i = emps.iterator(); i.hasNext();)
    Employee emp = (Employee)i.next();
    System.out.println(emp.getFirstName());

    JungleTaxi Cabbie wrote:
    Csound1: iCloud: Configuring Mail with Mac OS X v10.6 or iOS 4
    Enter your Incoming Mail Server, User Name, and Password using the following settings:
    Incoming Mail Server: mail.me.com
    User Name: Your iCloud email address (excluding @me.com)
    Password: Your password
    Last Modified: Jun 27, 2013
    Maybe you should test these things before calling people out, because these settings do function perfectly well.
    iCloud is not supported on Snow Leopard or lower, why bother to mention it?
    The OP has an iCloud account, and that can not be opened without Lion or Mountain Lion (on a Mac), IOS5 or 6 (on an iPhone/iPad)
    The document I linked to is Apples documentation for iCloud on current devices,I don't care whether you believe that you know better than they do, but it will affect the people who follow your advice as it won't work
    JungleTaxi Cabbie wrote:
    Also, if you're not running Lion or Mountain Lion, there is no "Mail, Contacts & Calendars" prefpane.
    I never said that there was, perhaps you imagined it.

  • How to write a 2-D Array of Doubles to a binary file in LabView 8.5?

    Okay, this is driving me nuts. I got a program that worked fine in LabView 8.0 but refused to write any data after my institute upgraded to LabView 8.5. The data is stored in a 2-D array of doubles and is supposed to be written to a binary file, that has been correctly opened and got a header written to it containing some meta-data of the measurement. But when the doubles from the array should be written to the file, nothing happens. All I get is an (except for the header) empty file of 786 kB. I found out that writing works if I convert the data from the array to singles right before wiring them to the "write to binary file" VI, but for several reasons I need the data as doubles. Can anyone help me? I've tried everything anyone has written here about writing to binary files and more.
    Remember, it worked perfectly fine with an older version of LabView. Any ideas?

    It is possible that you run into a known memory optimization bug.
    Try to place an "always copy" primitive as discussed here.
    Message Edited by altenbach on 11-18-2008 09:11 AM
    LabVIEW Champion . Do more with less code and in less time .

  • Retun of object or Array From webservice

    Thanks pekka,
    you are right...
    It is also possible to manage the ByteStream by returning the byte[] array from web services, but the issue is when the response reaches to the client... the invoke method returns object ...as
    byte[] ret = (byte[]) call.invoke( new Object[] { "Any String" } );
    At this point the axis server throws an error.... regarding the cast of Object type to byte array... (ClassCastException)... Due to this error i thought to return ByreArrayOutputStream object from webservice function......
    Although the return of byte[] will also work for me.... but the wholw issue struck at client at client side during typecasting of returned object from web services.....
    please suggest any solution.... for its casting...
    Thanks Very much...
    Gaurav

    Dear jpday,
    Have you seen this tutorial?
    Web Services in LabVIEW 
    http://zone.ni.com/devzone/cda/tut/p/id/7350
    attached to it you will find a zip file named webservicesdemo. This demo contains a VI called Function Generator Main, which shows how to convert an array to an XML string, which you can then output from the web service VI (Function Generator Main shows how to do this). 
    Hope this helps!
    ~Nate 

Maybe you are looking for

  • Incoming numbers for characteristics in rows

    Hello everybody: I need help for creating a column in a query. We have several characteristics such as material, customer, country, billing document…, that can be used as rows. In columns we want two key figure, one the amount of sales, and the other

  • Is P6 R8 Compatible with PPM 8.0 ?

    Hi, I would know if someone tested the compatibility of PPM 8.0 with P6 R8 (by the Bridge ) I will not upgrade to P6 R8, but this info could be useful on some customer site. Thanks Fabio D'Alfonso http://www.fabiodalfonso.com

  • Connect to Microsoft Picture Manager

    hi  Microsoft Picture Manager comes with office  can we refrence that applicaton in order to take some of his featrures i want to compress the image the same way it do it - if not does anyone know a component that do the same , thanx

  • Trying to reingtall win7 on pavillion dv7 cant get past a dialog select the driver to be installed

    Hi I have a HP Pavillion DV7-4065dx Refurbished Notebook PC with the following specs: AMD Phenom II Triple-Core N830 2.1GHz 4 DDR3 500 HDD Blu-ray 17.3" Display Windows 7 Home Premium 64-Bit MPN:  RB-WQ861UA Serial Number: [Personal Information Remov

  • Problem creating service jboss.security:name=XMLLoginConfig

    Hello, I am trying to to run my application using Java 5 and JBoss 4.2.1, but i am stuck in the middle. The error which i received is as follows:- 2008-10-15 12:56:06,031 WARN | (org.jboss.system.ServiceController:337) - Problem creating service jbos