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

Similar Messages

  • Problem when streaming out a binary file

    Hi,
    I am trying to stream out a binary file to an output stream (not a file, but a socket). My file is a gzip file, and I was initially simply trying to open the
    file, read it to a a byte array, and writing it out to my output stream. However, I got corrupted data at my other end and it took me quite a bit of
    debugging hours to find out why.
    I tried writing to a file the same information I was writing to my output stream but, although my file was correct, my output stream still contained
    corrupted data.
    I think I have finally narrowed down my problem to the fact that when I try to write a 0x00 value to my output stream, everything gets ignored from this
    point until I write a 0x0a byte to my output stream. Obviously this produces corrupted data, since I need all the bytes of my binary file.
    If somebody can direct me as to how to write a 0x00 value to a socket output stream, I would really appreciate your input.
    This is a sample of my code (Right now I am writing byte by byte: not very efficient, but was the only way I found where I was getting a problem):
    // out is of type OutputStream
    if (Zipped){
         // In this case we just have to stream the file out
    File myFile = new File(fileName);
         FileInputStream inputFile = new FileInputStream(myFile);
         FileOutputStream fos = new FileOutputStream(new File("/tmp/zip.gz")); //zip.gz results in a good (not corrupted) file.
         ByteArrayOutputStream out1 = new ByteArrayOutputStream(1024);
         int bytes = (int)myFile.length();
         byte[] buffer = new byte[bytes];
         bytes = inputFile.read(buffer);
         while (bytes != -1) {
              out1.write(buffer,0,bytes);
              bytes = inputFile.read(buffer);
         inputFile.close();
         try {
              int count=0;
              bytes=out1.size();
              while (count<bytes){
                   fos.write(buffer,count,1);
    out.write(buffer,count,1); // when buffer[count] == 0x00, everything after it gets ignored until a 0x0a byte is written.
                   count++;
         } catch (IOException ioe) {
              SysLog.event("IOEXCEPTION: "+ioe);
         } catch (Exception e) {
              SysLog.event("EXCEPTION: "+e);
         fos.flush();
         fos.close();
         out.flush();
    out.close();
         return;
    }

    Actually, I had thought about that and for some time I tried getting rid of some of the header information in the gzipped file, and then I stopped doing that when I realized that part of the gzipped file is a CRC value which I believe is computed taking into account both the data of the file and the header information. If this is the case, then getting rid of part of the header would produce a corrupted file ... but then, I might be wrong in this issue.
    Anyway, to make my application more clear, what I am doing is writing the code for a cgi command which is suppossed to access information from a database, create an xml file, gzip it, and then send it to the client who requested the information.
    Therefore, what I am sending is an xml file (Content-Type: text/xml) in compressed format (Content-Encoding: gzip). Note that if I don't gzip the file and then send it uncompressed to the client, I have no problems. However, for me it is very important to gzip it because the size of the file can get very large and that would just take bandwidth unnecessarily.
    On the other hand, if I try to gunzip the file locally, I have no problem either (the file is not corrupt at the server's end). Therefore, my problem is when I stream it out.
    Any further help would be really appreciated!

  • Multiple writes of a DBL 2D array to binary file

    Hello.
    Does anyone have an example of writing a 2D array to a binary file multiple times?
    Specifically, I need to write a 2D array of DBL to a binary file mulitple times and then (later) be able to read it back (reconvert to DBL). All of the examples that I've found only do one write and then close the file. I need to leave the file reference open and write data to it over the period of a few days. The data comes out of a queue that is fed from a DAQ loop. (In an acquistion loop I feed a queue and in a slower loop I dequeue the data and write it to disk)
    I believe it has something to do with the pos mode and offset mode but I can't figure it.
    I haven't been able to successfully read the data back yet from the .bin file so I'm not sure if I'm even writing it correctly.
    The closest example that I've found is the High Speed Data Logger and High Speed Data Reader but I haven't had any luck with those.
    Thanks in advance.
    Steve
    LabVIEW 7.1
    Solved!
    Go to Solution.

    To change the representation of a number, use the Numeric > Conversion sub-palette.
    The example below shows that the wires contain the representation info independently of the destination indicators : you can connect different types of numerics to the same wire and LabVIEW will automatically adapt to the type (the coercion dots indicate that a convertion has been done). Everything you should want to know about converting numbers is explained in the LabVIEW Help : "Conversion VIs and Functions"
    Message Edited by chilly charly on 07-30-2005 10:57 AM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Convert to single.png ‏27 KB

  • 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.

  • Problem saving pages documents as postscript files and pdf files

    Hello!
    My problem occurs when the pages documents are saved as pdfs -they go 'screwy'. If you save as a pdf (through file, print, print as), the certain fonts show a holding maarker rather than spaces on the screen but prints fine. If you save as a postscript (file, print, print as) and convert to a pdf in Preview the fonts are fine on the screen but are blown out when it prints and are all over the page.
    If anyone has any suggestions I am more than happy to try anything.
    Veronica

    As every user, the 'poor silly man' may download "*_Pages User Guide_*" thru the Help menu.
    Doing that, he would be able to read:
    Yvan KOENIG (VALLAURIS, France) jeudi 8 avril 2010 12:39:34

  • 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.

  • Problem saving png error (Hex 0xBFF604A5) File not found.

    Does anyone have some insight into how to correctly save a .png file that I grabbed from an IMAQ image?  I've been trying to use IMAQ write file 2.vi, but it doesn't seem to be able to create a file.  My code works fine if I pass it an existing .png file to write to, but it chokes once I tell it to save the image to a non-existing file.  I'm not very familiar with the IMAQ file I/O, but I assumed (wrongly) that it would work the same as the normal Open/Close file vi's that you can give write/replace/create permission to.  I attached my vi (sorry it's kind of a mess at this point).  Any suggestions?  Thanks,
    John
    Attachments:
    Grab and annotate pic.vi ‏127 KB
    graph and annotate pic.PNG ‏96 KB

    drummerguy-
    We have encountered this problem before. Typically the solution is checking the permissions.
    -The most common reason is if you don't have 'write' privileges in the folder you are trying to write to. 
    *If are unsure about this, you can check by trying to create a new file manually through windows explorer in the directory that LabVIEW is trying to write a file to. If you can create a file there, but LabVIEW cannot, then we can try something else. 
    -Another possible reason is if you have any illegal characters in your filename such as "%, /, \" 
    *A good filename would be something like "C:\test\test.png" for PNG files. If you are writing to a specific file type, could you try to write to a different type (JPEG, PNG, TIFF, BMP) and see if you get the same results?
    I would try these things first and see it your problem persists. I hope this works for you
    Sam S
    Applications Engineer
    National Instruments

  • Problems saving values in the configuration file

    Hello,
    I'm upgrading one of my projects from VS2005 (with .NET 2.0) to VS2013 (with .NET 4.5). I have a setup project in my solution, but this is no longer supported and I have to change to InstallShield
    deployment project. With the old setup project my app runs fine, but now with InstallShield I have a problem. I install the application in this folder: C:\Program Files (x86)\CompanyName\AppName. I use .config file to read and write some parameters.
    Reading parameters goes well, but when I write new values in the .config file a get one error. When I used the old setup project, at writing time the system created new .config file in C:\Users\me\AppData\Local\VirtualStore\Program Files (x86)\CompanyName\AppName
    (this is named isolated storage, isn't it? :S).
    These are all changes I made in the solution:
    When I opened the solution with VS 2013 the migration process went well (some warnings and messages) except setup project (of course).
    I upgrade all projects to .NET Framework 4.5 (Project properties -> Application -> Target framework).
    I have intalled InstallShielld Limited Edition and added and configured the new deployment project.
    I think that these are all changes. And this is the source code where I get the exception:
    public void SetXParamValue(string value)
    try
    Configuration conf = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
    conf.AppSettings.Settings["XParam"].Value = value;
    conf.Save();
    catch (Exception e)
    MessageBox.Show("Error setting X param.");
    And this is the exception:
    Exception messsage:
    An error occurred loading a configuration file: Access to the path 'C:\Program Files (x86)\CompanyName\AppName\oy25i1se.tmp' is denied. (C:\Program Files (x86)\CompanyName\AppName\ExeFile 1.0.192b.exe.config)
    Stack trace:
    at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
    at System.Configuration.Configuration.SaveAsImpl(String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)
    at System.Configuration.Configuration.Save()
    at VisualizadorCabecera.FormPrincipal.EstablecerIdioma(CultureInfo idioma)
    Inner exception messsage:
    Access to the path 'C:\Program Files (x86)\CompanyName\AppName\oy25i1se.tmp' is denied.
    Stack trace:
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean
    checkHost)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
    at System.CodeDom.Compiler.TempFileCollection.EnsureTempNameCreated()
    at System.CodeDom.Compiler.TempFileCollection.AddExtension(String fileExtension, Boolean keepFile)
    at System.CodeDom.Compiler.TempFileCollection.AddExtension(String fileExtension)
    at System.Configuration.Internal.WriteFileContext..ctor(String filename, String templateFilename)
    at System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext, Boolean assertPermissions)
    at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext, Boolean assertPermissions)
    at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
    at System.Configuration.ClientConfigurationHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
    at System.Configuration.UpdateConfigHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
    at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
    Any suggestions? I have to configure something else?
    Thank you,
    Jon.

    > "With the old setup project my app runs fine"
    Actually, I disagree.  Your configuration file is sitting alongside your application, in a directory that
    should be protected from changes by "regular" users and it's
    only running because Windows is intercepting your attempt to write under C:\Program Files* and rerouting those attempts to a "Virtual Store" location.  By the sounds of it, something your new installer is doing is [quite rightly]
    stopping this from happening (IIRC, virtualisation can be turned off for a program and, IMHO,
    should be).  
    You need to move the configuration file to a location that the user can write to (somewhere under C:\Users\username), even if you have to copy it the very first time it's needed. 
    Regards, Phill W.

  • 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

  • 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?

  • How to store 2C array to a singl binary file

    Hi
    I have to store multiple waveforms output that is each 1D array to a single binary file. how do i do this.
    i can store 1D array to binary file and retrieve it by reading the binary file and plotting the waveform. but i am not able to store 2D array to the single file. how do store many 1D array in one binary file,
    Thank you. Hema

    (We would also need to know your LabVIEW version. If you have a very old version, things would be quite different.)
    As Smercurio_fc already mentioned, the option to "prepend array size" would make things much easier here, because then you would read it as a single 2D array.
    Here's how that would look like. This is probably the recommended solution, just for simplicity reasons.
    Not prepending the size is more useful if you write the data in increments, but later want to read it as one.
    Message Edited by altenbach on 11-15-2008 09:02 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SaveRestore2D.png ‏21 KB

  • Write string array into cfg file

    Hi, everybody.
    I faced the problem to write array into cfg file. I am trying to put many items in a key. It should look like
    [Section1]
    Key1=el_1, el_2,el_3,.............el_n.
    each element is string of 105 characters. Everything works fine when I save the only one el_1 or multiple for the  first time, however, when I am trying to update values in a key section some extra strings appear in a file. My VI is attached.
    Thanks in advance

    Do you realize that your spreadsheet string only writes the following:
    1111111111
      2222222222222222
     33333333333333333333
    The way you wrote your VI, it sends the entire string above to the value for Write Key.vi.
    Do you realize that value is for the data type only?  So I'm not sure what you want to do....
    Without describing the problem you are having, can you describe what you actually want to do?
    R
    Message Edited by JoeLabView on 07-22-2008 11:49 AM
    Attachments:
    confused.PNG ‏26 KB

  • How to read non-java binary file?

    Hello Team,
    I have problem to read non-java binary file.
    Let me explain.... I have one binary file created in vc++ having fix structure. Structure of file is like String,int,int,int.
    Now I have to read this file in my java application. I am failed to identify length of String value of Structure in java.
    Can any body help me to solve this problem?
    Thanks in advance.
    - Pathik

    Thanks for guide me,
    I have try using 0x00. And its working.
    Now I have another problem:
    in file.ext , I have written one record having structure string,int and int.
    I have enter data as "HelloWorld", 100 and 111.
    To read first record from file file.ext, following code I am using:
    try
         FileInputStream fis = new FileInputStream("file.ext");
         DataInputStream in = new DataInputStream(fis);
         char ch;
         while((ch=(char)in.readByte()) != 0x00)
              System.out.print(ch+"");
    System.out.println();
         System.out.println("Integer 1 --> " + in.readInt());
         System.out.println("Integer 2 --> " + in.readInt());
         in.close();
         fis.close();
    catch(Exception ex)
         System.out.println(ex.toString());
    And I am getting following output:
    HelloWorld
    Integer 1 --> 0
    Integer 2 --> 0
    File file.ext is created in vc++
    I am not getting integer data. Plz guide me for this problem.
    Thanks in advance
    - Pathik

  • Problem saving gif file over the net

    I am using a simple loop to save files using a URL Connection. It grabs html files fine and they look right but when I used to to download an animated gif it had an error. It saved the file but when I tried to open the image I got a "drawing failed" message.
    I compared it to the working image and the sizes were identical. I also compared the characters in notepad and the beginning and end characters were identical. I looked at the preview in "My Computer" when you select it and it drew only the first line or so. This makes me believe it is a problem with how it switches lines when saving. I checked the ends of the lines though and they also seem identicall. Any ideas? Here is the code. Thankyou.
    FileWriter fileName = new FileWriter(saveFileName);
    BufferedReader in = new BufferedReader(
    new InputStreamReader(
    newConnection.getInputStream()
    BufferedWriter out = new BufferedWriter(fileName);
    for (;;) {
    int data = in.read();
    // Check for EOF
    if (data == -1) break;
    else {
    System.out.print ( (char) data);
    out.write(data);
    }

    GIF files are binary files and can be corrupted if you use the Reader and Writer classes. Use the *Stream classes, like FileInputStream and FileOutputStream.                                                                                                                                                                                                                                                                                                                               

  • Problems with binary files

    Hello everybody!
    I'm having deep trouble with reading from binary files.
    I have opened a DataInputStream with a FileInputStream to read the data (which consists of a lot of short-Variables) into my program.
    Then I wondered why the data read is always wrong, until I discovered the core of the problem yesterday night. It seems as if Java reads everything correct, but the 16bit unsigned int data from the file has a problem.
    It seems as if the second byte is written first, that means i.e. the decimal 2352 (Hex: 09 30) is written 30 09, and that wreaks havoc upon my program, because Java interprets this as dec 12297.
    Now I have the following questions:
    1. Is this a kind of one- or two-complement problem?
    2. Is it possible to read this in a byte array (yes), and convert this byte array afterwards into a short variable?
    3. Is it possible to read this kind of data with a Java class?
    Thank you very much in advance,
    Hans Munzel

    Thank you for your quick reply!
    I already thought that this is the right way to solve this. Now I have already looked it up:
    - I have found no class that is able to transform a byte array into a basic data type.
    - The class Integer is able to convert int variables into a Hex string, making it possible to concatenate the Strings in the correct order and convert it.
    - The class Byte is unfortunately NOT able to do this.
    So, I have tried to make a conversion via combinations of toString(), decode(), and parseInt() (and a lot of other methods, too), but this is a) very complicated and b) prone to errors which result normally in a fatal exception.
    So, am I missing something? I am using JDK 1.3.1, and have looked through the java.lang and java.math packages, but I found nothing I can use.
    The only thing close to converting a couple of bytes to a Java datatype is the DataInputStream with its readShort() etc. methods, but is is causing the problem in the first place ...

Maybe you are looking for

  • After Factory Reset - How do I restore my backed up files in Windows 7??

    My windows 7 crashed and I was unable to repair it and or do a recovery. This computer is my daughters and it has never been right because it would never back up or make an image. So, I performed a Toshiba Recovery of factory default software with us

  • PSCS4 encountered problem with display driver message

    G'day, On first opening PS CS4 I got this message," Photoshop has encountered a problem with the display driver, and has temporarily disabled GPU enhancements. Check the video card manufacturer's website for the latest software. GPU enhancements can

  • Custom tag problem (parent/child tag)

    I have a table tag and a column tag that I'm using in my application to display records. The first time through it sets up headers and keeps a coun't of the columns. The second time through it starts putting data in the fields. The problem I'm having

  • Jdeveloper Crashing When Viewing History

    When I try to view history for certain files from a project that is using version control with CVS the application throws an exception and asks me hot to proceed. I am using JDeveloper 11g 11.1.1.1.0. The exception is: java.lang.ArrayIndexOutOfBounds

  • I want to delete a video from iTunes

    I want to delete a video from iTunes> On This Phone > Movies. I have unsynced the movie so movie is in grey box but I cannot delete it using delete button. When I go back to List, I cannot find this video under Movies nor on my iphone. Why is this so