Saving an Array

Hi,
Possibly a stupid question, dont know. I have written a program that produces a very large array of Bitset objects. I want to be able to save this array for use at a later date (once the next program is written), so as not to have to re run the program which generates the array. This takes a few days.
I know I could save it as textfile of the toString outpput, and then read this back in some how , but wondered if there was a better way.
Craig

You're a better Javite than I. I haven't attempted to memorize the API, yet. ;o)When Bill Gates finally crushes Sun and squelches Java, a small band of true believers
will come together to memorize the entire API -- well, maybe not the deprecated parts --
so as to preserved it for future generations

Similar Messages

  • Problem saving 2D array to binary file

    I am getting some strange results when trying to write a transposed 2D array of Unisgned 8-bit data to a binary file. Attached is an example program ("071026_ArraySave_Bug.vi") which demonstrates the suspicious behavior.
    The program generates a small 2D array of U8 data, then saves it to two temporary files using two different methods.
    1) Row-by-row: The 2D array is auto-indexed, and the indexed row is written to file at once (with the prepended size option disabled).
    2) Point-by-point: Two For loops are used to auto-index each element and write it to file individually.
    The saved files are then reopened and the data is read into two 1D arrays for display.
    The bug occurs when the generated 2D array is transposed before being saved to file. In the point-by-point method, the data is always saved to the file as desired, i.e. by row or by column depending on whether the data was transposed. However, in the row-by-row method the data is incorrectly saved when the input data is transposed. Without transposing the array, the row-by-row results are correct.
    Saving the array row-by-row is significantly faster for larger arrays, so this method is desired.
    Note that the option to transpose the input data in the attached VI is performed using a case structure with a boolean constant ("Bug Control"). This is important because:
    1) The bug does not occur if the boolean constant is replaced with a control.
    2) The bug does not occur if the case structure is replaced with a "Select" node from the Comparison Palette.
    3) The bug still occurs if the case structure is removed such that the array is always transposed (i.e. keep the True case).
    For now, I have been able to circumvent the bug in practice by transposing the array and then passing it through a Select with a constant True (the False case uses the untransposed array). This allows the faster row-by-row method to be used without error, but requires new memory allocation for the transposed array.
    I will appreciate any help that can be given regarding this problem, or simply confirmation that it is indeed a bug in Labview 8.5. It is worth noting that the same program did not produce any errors when run in Labview 7.
    Thank you for your help,
    David Viggiano
    Attachments:
    071026_ArraySave_Bug.vi ‏29 KB

    This is a known bug (CAR : 4DP855N3) , related to memory management. see this thread
    If I remember well, Altenbach shown somewhere that forcing the transpose operation to produce a copy of the memory was a proper workaround.
    Message Edité par chilly charly le 10-26-2007 08:40 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    071026_ArraySave_Bug[1].png ‏2 KB

  • Saving an array of sprite with filestream

    hi I am looking for a way to save an array of sprite on the user drive and then read this array...
    I saw method for saving text file. It quite simple... but it seems that saving an array is not very documented.
    Any help  tuto/ code wil be appriciated
    Thanks

    Hi so maybee it 's a better idea to convert spite to bitmapdata
    var mySprite:Sprite = new Sprite();
    var bData:BitmapData = new BitmapData(mySprite.width, mySprite.height, true);
    bData.draw(mySprite);
    var bmap:Bitmap = new Bitmap(bData);
    and then save the bitmapdata ?
    I will look at the bae 64 and join split method.

  • Problem saving an array using a shift register

    In the attached VI I'm building a 1D array of strings, then trying to save it using a shift register. For some reason my data isn't being saved and I dont understand why.
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    Shift_Reg.vi ‏15 KB

    Try this...
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Shift_RegMOD.vi ‏10 KB

  • Advice on saving an Array to a file on the client hard drive with Flex/Air

    hi.
    i've created a datagrid in Flex with 5 columns across with an
    unspecified number of rows as the user can "add' more rows as
    required....the user inputs text into each cell of the
    datagrid.......the dataprovider is an array....i've pretty much
    setup all the necessary save, open, etc. functions.....my main
    issue is how the datagrid--->array can best be saved as a
    file....
    thanks for your help.

    Well, in AIR you have SqlLite at your disposal. So you might
    want to create a table and stick these values in there.
    For Flex, of course, if you want to have a file you'd need to
    store this data on the server side. SharedObject gives you some
    very limited to store this data on client side.

  • Saving int [][][][] array to a file

    Hello...
    I realize that I can save the array to a file by saving each bit of information separately, and then recalling it...
    I was curious whether it is possible to save an int[][][][] array to a file "as it is". that is, some way of just exporting the array to a file and then recalling it. if it is not possible, saying so is also helpful.
    Thanks.

    yes... well... i didn't necessarily mean a 4D array was common. i meant it would seem a common desire to store any array, even 1d, or an ArrayList, or anything really... other than being able to write JUST at int, or just a String, or just a double. see... it can take about 10 minutes to create this 4d array; so i can save that time by just recalling it from a file in about 2 seconds... would have figured this wasn't too uncommon of a desire... though not common enough probably.

  • Saving string array in Standard State Machine.

    I use a Standard State Machine to control a laser unit with multiple lasers. When I give the unit a command, it gives me much information back. When LabVIEW is reading this information, it is putting it in a string array.
    But the program shows only the information in the array when I enable 'Highlight Execution'.  What do I have to do to solve this problem?
    Thanks for all commands,
    Bjorn
    Attachments:
    StandardStateMachine 1.vi ‏26 KB
    statemachine.ctl ‏5 KB

    Does your device use a termination charcter at the end of each transmission?  You are already set up to use 0xA as a termination character (default on the Configure Serial Port).  If so, do not do the big mess with the checking of bytes at port and what not.  Just use a VISA Read with a very large number for the bytes to read.  The read will complete when that termination character is reached.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Saving String-Array in mySQL DB

    Hello.
    How can I save an dynamic array in a DB, without looping over
    the content.
    I think serialization is the key word. Can anybody give me
    further information, pls?
    Thx an lot.
    Regards, Philipp

    I am working with 3-dimensional string arrays, which have
    differet sizes.
    I think enum-Cols can't solve my problem.

  • Saving an array of multi-line text cells in a format that can be read in later

    I can create an array of multi-line text entries that my program can then pick cells and compile them into a list of text.
    I would like to be able to Save the array as a file, then change my program to read in the file.
    If I use the Save Spreadsheet file vi, the data is corrupted by the carriage returns within the cells and the data read in is messed up.
    Can someone recommend a way to save the array that preserves the carriage returns?

    As far as I know, this cannot be done automatically with the basic VIs from the palletes.  I would convert the [LF] into another group of characters (likely "\n") and then save the text array to a CSV file.  Don't forget to escape any good "\" string with an extra "\.  Regular expressions would work really well:
    Just make sure you parse your entire array of strings with this.
    Olivier
    Attachments:
    SaveToCSV_WithMultiLine.vi ‏9 KB

  • Spot the error!!!! float not saved in array

    I have the following class file which compiles fine and runs, but for some reason the salary is never stored into the file when saved, i am outputting store to the terminal window and everything comes up apart from salary which always says 0.0 can anybody see any errors has it is driving me mad lol!
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import bank.BankUI;
    import bank.*;
    public class CreateSequentialFile extends JFrame {
       private ObjectOutputStream output;
       private BankUI userInterface;
       private JButton enterButton, openButton;
       private Store store;
       private Employee record;
       // set up GUI
       public CreateSequentialFile()
          super( "Creating a Sequential File of Objects" ); // appears in top of gui
          // create instance of reusable user interface
          userInterface = new BankUI( 9 );  // four textfields
          getContentPane().add( userInterface, BorderLayout.CENTER );
          openButton = userInterface.getDoTask1Button();
          openButton.setText( "Save to file" );
          openButton.addActionListener(
             // anonymous inner class to handle openButton event
             new ActionListener() {
                // call openFile when button pressed
                public void actionPerformed( ActionEvent event )
                   openFile();
             } // end anonymous inner class
          ); // end call to addActionListener
          // configure button doTask2 for use in this program
          enterButton = userInterface.getDoTask2Button();
          enterButton.setText( "Save to file..." );
          enterButton.setEnabled( false );  // disable button
          // register listener to call addRecord when button pressed
          enterButton.addActionListener(
             // anonymous inner class to handle enterButton event
             new ActionListener() {
                // call addRecord when button pressed
                public void actionPerformed( ActionEvent event )
                   addRecord();
             } // end anonymous inner class
          ); // end call to addActionListener
          // register window listener to handle window closing event
          addWindowListener(
             // anonymous inner class to handle windowClosing event
             new WindowAdapter() {
                // add current record in GUI to file, then close file
                public void windowClosing( WindowEvent event )
                             if ( output != null )
                                addRecord();
                                  closeFile();
             } // end anonymous inner class
          ); // end call to addWindowListener
          setSize( 600, 500 );
          setVisible( true );
         store = new Store(100);
       } // end CreateSequentialFile constructor
       // allow user to specify file name
       private void openFile()
          // display file dialog, so user can choose file to open
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
          int result = fileChooser.showSaveDialog( this );
          // if user clicked Cancel button on dialog, return
          if ( result == JFileChooser.CANCEL_OPTION )
             return;
          File fileName = fileChooser.getSelectedFile(); // get selected file
          // display error if invalid
          if ( fileName == null || fileName.getName().equals( "" ) )
             JOptionPane.showMessageDialog( this, "Invalid File Name",
                "Invalid File Name", JOptionPane.ERROR_MESSAGE );
          else {
             // open file
             try {
                output = new ObjectOutputStream(
                   new FileOutputStream( fileName ) );
                openButton.setEnabled( false );
                enterButton.setEnabled( true );
             // process exceptions from opening file
             catch ( IOException ioException ) {
                JOptionPane.showMessageDialog( this, "Error Opening File",
                   "Error", JOptionPane.ERROR_MESSAGE );
          } // end else
       } // end method openFile
       // close file and terminate application
       private void closeFile()
          // close file
          try {
                                                 int storeSize = store.getCount();
                                            for (int i = 0; i<storeSize;i++)
                                            output.writeObject(store.elementAt(i));
             output.close();
             System.exit( 0 );
          // process exceptions from closing file
          catch( IOException ioException ) {
             JOptionPane.showMessageDialog( this, "Error closing file",
                "Error", JOptionPane.ERROR_MESSAGE );
             System.exit( 1 );
       } // end method closeFile
       // add record to file
       public void addRecord()
          int employeeNumber = 0;
          String fieldValues[] = userInterface.getFieldValues();
          // if account field value is not empty
          if ( ! fieldValues[ BankUI.IDNUMBER ].equals( "" ) ) {
             // output values to file
             try {
                employeeNumber = Integer.parseInt(
                   fieldValues[ BankUI.IDNUMBER ] );
                        String dob = fieldValues[ BankUI.DOB ];
                        String[] dateofBirth = dob.split ("-");
                        String sDate = fieldValues[ BankUI.START ];
                        String[] startDate = sDate.split ("-");
                        String sex = fieldValues[ BankUI.GENDER ];
                        char gender = (sex.charAt(0));
    if ( employeeNumber >= 0 ) {
                    record  = new Employee(
                    fieldValues[ BankUI.NAME ],
                        gender,
                    new Date(     Integer.parseInt(dateofBirth[0]),
                              Integer.parseInt(dateofBirth[1]),
                              Integer.parseInt(dateofBirth[2])),
                        fieldValues[ BankUI.ADDRESS ],
                        fieldValues[ BankUI.NATINTNO ],
                        fieldValues[ BankUI.PHONE ],
                        fieldValues[ BankUI.IDNUMBER ],
              new Date(     Integer.parseInt(startDate[0]),
                              Integer.parseInt(startDate[1]),
                              Integer.parseInt(startDate[2])),
              Float.parseFloat( fieldValues[ BankUI.SALARY ] ));
                        if (!store.isFull())
                             store.add(record);
                        else
                        JOptionPane.showMessageDialog( this, "The Store is full you cannot add\n"+
                         "anymore employees. \nPlease Save Current File and Create a New File." );
                             System.out.println("Store full");
                        store.displayAll();
                        System.out.println("Count is " + store.getCount());
                                  // output record and flush buffer
                        //should be written to fuile in the close file method.
                                                 output.flush();
                else
                    JOptionPane.showMessageDialog( this,
                       "Account number must be greater than 0",
                       "Bad account number", JOptionPane.ERROR_MESSAGE );
                // clear textfields
                userInterface.clearFields();
             } // end try
             // process invalid account number or balance format
             catch ( NumberFormatException formatException ) {
                JOptionPane.showMessageDialog( this,
                   "Bad ID number, Date or Salary", "Invalid Number Format",
                   JOptionPane.ERROR_MESSAGE );
             // process exceptions from file output
             catch ( ArrayIndexOutOfBoundsException ArrayException ) {
                 JOptionPane.showMessageDialog( this, "Error with Start Date or Date of Birth",
                    "IO Exception", JOptionPane.ERROR_MESSAGE );
                      // process exceptions from file output
             catch ( IOException ioException ) {
                 JOptionPane.showMessageDialog( this, "Error writing to file",
                    "IO Exception", JOptionPane.ERROR_MESSAGE );
                closeFile();
          } // end if
       } // end method addRecord
       public static void main( String args[] )
          new CreateSequentialFile();
    } // end class CreateSequentialFile

    I don't see any salary-related code in what you posted. Is there salary information in that Employee class or something? If so you should look there to see if it's working correctly. Or better still, test the Employee class properly before allowing other classes to use it.

  • Saving Data: Array -- XML file?

    Hi there,
    I have meta data that I want to save in an archive. Should I push this into an multidimentional array then create a method that writes the contents of the array to an xml doc?
    The user will go through a news feed, choose items that are important to the company, then archive the newsfeed metadata (title, URL, source, abstract).
    Thanks in advance for your help!

    If this is an AIR app you can write to disk, but if it is a Flex app can't access local hard drive, though FP 10 might make this possible.
    If the data is small enough you could use a SharedObject, its like a Flex cookie.
    Or just upload data to server and write to file using PHP, Python, etc.

  • Best way of saving an array of integers to use later?

    I am having trouble figuring out where to initialize an array of integers so it is available everywhere. It's just a simple array of integers to be used as indices into another array. So I figured an ordinary C array like this is sufficient:
    int arrayOfIndices[] = {3, 11, 12, 25, 26, 43, 50, 53, 58, 59, 62, 76, 77, 81, 94, 95, 110, 113, 114, 117, 118, 123, 136, 152};
    It's ok to just use an ordinary C array for this, right? It seems that it is much harder to initialize a similar NSArray of integers. Or is there an easy way to do that?
    One problem I'm having is I'm having trouble figure out where to stick the above array so that it is usable through the program. With my NSArray objects I've been defining them in the interface, then initializing them in viewDidLoad with retain.
    Is there something analogous I can do with ordinary C int arrays? Or, alternatively, an easy way to initialize an NSArray of integers so I can deal with them like I do with other NSArrays?
    Thanks,
    doug

    Never mind. It looks like just not putting anything in the interface file and sticking the definition of the C int array at the top of my implementation file where I import files and define some other stuff works fine.
    doug

  • Saving an array to a file

    i have the following code:
      public static void saveData(String[][] data, String fileName) throws IOException
        //need a file output steam for the specified file
        FileOutputStream fileOutputStream =
          new FileOutputStream(fileName);
        //need an object output stream connected to our file output stream
        ObjectOutputStream objectOutputStream =
          new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(data);
        objectOutputStream.flush();
        fileOutputStream.close();
      }I'm trying to save the containts of a string array to a text file - from which I also want to reload it again later. However I keep getting some sort of unreported exception error when I try.
    Any suggestions?

    Are you sure that it is complaining about the method
    you have shown us here? You have declared the method
    to throw the IOException unless you haven't imported
    the java.io package. Also this isn't going to compile
    because writeObject takes an Object as the argument
    and you are trying to pass in a String[][] you will
    need to loop through you array of arrays and
    writeObject for each one I think.hmmm...i suspect it might work if I used a vector intead of my 2 dimensional string array...but that would mean re-writing a huge amount of code.
    i dont supose its possible to convert my array to a vector?

  • Is there any way to create a circular buffer using the INSERT ARRAY function?

    I saw the example using the REPLACE ARRAY function, but it uses too much CPU power on my laptop. I'm using it for a very sensitive application and saw that the INSERT ARRAY function used much less CPU power.
    I am also not wiring the index on the INSERT ARRAY function so that whatever is read from the buffer is added to the array.
    However, since it is not indexed, I don't know how to set the "write" index back to 0 when it reaches a certain sized array (ie 1000 elements). I was looking for an array property node, but couldn't figure out if one exists for the "current write index".
    Can anyone help?
    Thanks

    I will try to answer this question to my best understanding. I apologize if I interpreted the question wrong.
    You are using the "Insert Array" vi without wiring the index. By doing that, new elements will be added (appended) to the array.
    If you just want to know the current index to stop your acquisition when the array reach certain amount of elements, then you can use the "Array Size" vi to keep track of the size of the growing array. Remember that Array Size = last index + 1 because the index start at zero.
    A second option is that you may want to start over the array when it hits the maximum number of elements that you will allow. If that's the case, then you may want to re-initialize the array to a NULL state by stablishing a condition (for example, when the
    size of the array is 1000, re-initialize). I provided an example attached to this message showing how this can be accomplished. In the example, an 1D array grows in size using the "Insert Array" vi and inserting a random number. When the array reach 4 elements, it is re-initialized. You can expand this example by saving the array first to a file or some other holder before re-initializing the array. The example is in LabVIEW 6.
    Finally, if you want to replace the current values with new values, I think you do not have other choice but to use the "Replace Array" vi.
    Hope this can be of help.
    Regards;
    Enrique Vargas
    www.vartortech.com
    Attachments:
    array_example.vi ‏20 KB

  • Gaps in data saved as LVM

    I am using 2 USB-6009s to collect 16 channels of analog data and the 2 devices are not synced.  The data files attached were collected at 1,000 Hz for 2 sec using the Write to Measurement File function.
    1. When the data were saved as a text (lvm) file [the csv file attached], there are gaps in the data.  However, there are no gaps when saved as an Excel file.
    2. When saved as Excel with 'absolute' timestamps, the time column starts with 00.000 and then reset to 00.000 at non-regular intervals (as in the spreadsheet attached).  The time column has continuous time when the 'absolute' option is deselected,
    If the gaps are related to the non-synchronization of the 2 devices, why are there no gaps when saved as Excel files?  Thanks for your time.
    Attachments:
    Analog_16Ch_Timed_Datalogging_Dell.vi ‏90 KB
    AI16_1000Hz_2s(absolute timestamp).xlsx ‏126 KB
    AI16_1000Hz_2s.csv ‏304 KB

    Hi Riccardo:
    At your suggestion, I used the Convert From Dynamice Data to 2D array before saving the array using Write to Spreadsheet File.  When I collected 2 seconds of data at 1,000 Hz, there are fewer than 200 lines of data in the spreadsheet file (no gaps in the data, see the txt file attached). For comparison, the file saved using Write to Measurement File has close to 1,000 lines (with gaps in the data, see the xlsx file attached).  Thanks for your time.
    John
    Attachments:
    A16D1_1000Hz_2s.txt ‏20 KB
    A16D1_1000Hz_2s.xlsx ‏133 KB
    Analog_16AI_1DI_Timed_Datalogging(WriteSpreadsheet).vi ‏116 KB

Maybe you are looking for