LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Binary File to ASCI File

Hello, I'm having a little trouble writing a labview program to read a binary file and save it to an ASCI file. The binary file may be large so I've tried to read the file in chunks. I will appreciate any help you could offer. I've attached my .vi below

 

thanks,

joe

 

0 Kudos
Message 1 of 14
(3,941 Views)
Well, for one thing you're not converting anything to ASCII. All you're doing is writing out the same data to another file. Your example VI seems to read in one number at a time and write out the number to a new file. Presumably you want the value in ASCII, so you need to insert on the number->string conversion functions, depending on the datatype of the number you're reading. See attached modification.

One thing to note is that your loop counter control has a constant that says "bytes/DBL", but the data type you're using for the Read function is an I32. Is your data floating points, or integers?

Also, you need to build some data dependency between the two file dialog functions so which one appears first is consistent. As it is, you don't know which one is going to appear first, and this can be confusing. In fact, when I ran it I got both cases.
0 Kudos
Message 2 of 14
(3,926 Views)

Thanks a million, I really appreciate taking time to look over my app. These newsgroups are the greatest thing for newbies like me.

 

0 Kudos
Message 3 of 14
(3,921 Views)
There is typically no need to do millions of file operations, reading and writing a few bytes at a time. Just "read-> cast->format->write" in one simple swoop.
 
No loop needed! 😉
 
Of course there are many other ways to do this. It also depends what kind of seperator you want in the ASCII file, so modify as required by your specifications.
 
(See attached, LabVIEW 7.1)
Message 4 of 14
(3,918 Views)

Hello, thanks for responding to my post. Your solution is pretty slick, will it handle large files, greater than 1Gbyte? I'm working on an application that will record data from an NI-6534 Digital I/O card and store the data in binary formate. I need to convert that to ASCI for the customer, so  the file sizes could get really large.

Thanks again, I really appreciate everything you've suggestioned,

 

joe

0 Kudos
Message 5 of 14
(3,903 Views)
If the files are really huge, you could use a hybrid approach, converting a few MB at a time. It would probably need careful design to optimize for speed and memory. What is you OS?
0 Kudos
Message 6 of 14
(3,895 Views)

smercurio_fc,

 

Hi, thanks for giving me a hand in getting my .vi to work. Can I ask one more time? Now I want to save the data to a spreadsheet, but I can't get it to work. The binary data will be unsigned int. When I run the .vi the data from the binary file are really huge numbers and don't match what is expected. Could you look it over and give point our my error?

 

thanks,

joe

0 Kudos
Message 7 of 14
(3,872 Views)
I don't really understand what you mean by "the data from the binary file are really huge numbers and don't match what is expected". Are you specifying the correct datatype to the Read function?

As far as your VI is concerned: Your initial statements indicated that you wanted to read this in chunks since you're dealing with very large files. However, while your VI reads in one number at a time, it writes out the whole thing in one big chunk. This is going to be a huge memory draw. You need to write the data to the ASCII file at the same time as when you read it, not after you've read it all. Given this, it makes no sense to only read one number at a time as you're doing. You're going to be performing a disk I/O operation for each number! This is going to take forever, not to mention take a nice bite out of the life expectancy of your hard drive. I don't say this often, but you need to restructure your VI to something like this:

1. Provide dialog to ask for the file to read.
2. Provide dialog to ask for the file to write to.
3. Write out your header to the output file.
4. Start a loop where the number of iterations is based on the number of times you have to read the file using a max chunk size. This is based on the file size and the size of the chunk that you're comfortable in reading. The chunk size is dependent on your machine - i.e., speed and amount of RAM.
5. Read that many numbers and write out the converted numbers.
6. Repeat until done.
7. Close both files.

See attached file as a starting point. The error handling is not that great, so keep that in mind.

Message Edited by smercurio_fc on 03-17-2006 05:20 PM

0 Kudos
Message 8 of 14
(3,866 Views)

smercurio_fc,

Thanks again, I changed to a different binary file and it is working, so there must be a problem with my other binary file.  I'll get it going sooner or later.

joe

 

0 Kudos
Message 9 of 14
(3,860 Views)
OK, but my comments regarding your VI still stand. You're still dealing with the entire dataset at the write portion, which is contrary to what you wanted to do in the first place.
0 Kudos
Message 10 of 14
(3,859 Views)