LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing complex data to file

Hello all!

I have been in a dilemma on how store certain data in files.  For example, I need to save data about GPIB instruments.  The data is structured in a main cluster with three seperate clusters inside, Instrument Name, Address and Channel.  In these clusters are multiple arrays, one for each type of instrument (Power Meter, Power Supply, etc.).  Now, my main problem is I wish to save this data to a txt file, be able to view it in notepad AND modify the data if necessary AND keep the hierarchy of the data.  I know this is easily done with configuration files in LabVIEW but they only allow me to have one level of hierarchy (Section -> Key).  I know I could split up the data into multiple config. files, but I do not wish to write to many files for nothing.  I though that writing to a Excel file could be handy also, but spreadsheet files only allow 2D arrays.  And finally, I know that I could write all this data to a text file and then parse the file to retreive the information, but this is only my last resort since I wish to have a more efficient way.

Thanks in advance for the help!

0 Kudos
Message 1 of 9
(4,266 Views)
Hi,

Maybe the idea of config file could work... how many level do you need ?
A couple of month ago I made a "2-level" read/write vi, the trick is to put many items in a key, separated by a coma (or other character).
This way you have :

[section_0]
  key_0=it_0,it_1,it_2
  key_1=it_0,it_1,it_2
[section_1]
  key_0=it_0,it_1,it_2
  key_1=it_0,it_1,it_2
...

If this is of interest for you, I can try to find these vis...



We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 2 of 9
(4,256 Views)
The hierarchy should be like this:

GPIB Instruments (Cluster)->

    Instrument Names (Cluster)->

        Power Meters (Array)
       Power Supplies (Array)
             ...

    Instrument Addresses (Cluster)->

        Power Meters (Array)
       Power Supplies (Array)
             ...

    Instrument Channels (Cluster)->

        Power Meters (Array)
       Power Supplies (Array)
             ...

So, in theory I should have 3 levels.

Message Edited by vmallette on 04-20-2006 08:33 AM

0 Kudos
Message 3 of 9
(4,254 Views)
I suggest you take a look at the XML subpalette under the string palette. You can flatten any LV datatype to an XML string, and then write it to a file. You will have a human readable file, and LV can automatically read it back in an convert it back to your custom cluster. It uses the LV XML schema to do the conversions. In LabVIEW 7.1 it's hidden away under Advanced>Data Manipulation>XML.

Good luck!
Chris
Message 4 of 9
(4,247 Views)
Thanks for the tip!

I actualy had a look at the XML format and thought it wasnt very easily readable...  but I have to admit its very useful. I'm still  open to suggestions!
0 Kudos
Message 5 of 9
(4,245 Views)
Does each specific array has a constant number of element ?

If yes, the "improved" config file VIs I made should do the job with almost no modification ; as spoted by C. Minnella xml it sounds like a more appropriate tool as far as labview is use to read/write ; personnally I've never used xml but I saw a couple of threads about the subject in the past weeks, maybe it's worth to gig up this way..

Is the possibility to modify from notepad really necessary Smiley Surprised ?

    - If "definitely yes", I think cfg file is a good compromise,
    - if "that would help", xml sounds cool,
    - if "in the end no", you can do something even easier, flatten the main cluster to string and write is to txt file, you won't be able to read it at all with notepad but in terms of code that's very easy.



We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 6 of 9
(4,237 Views)
Thanks for the interest Titou.

To answer your question, yes it is imperative that I could be able to modify the files without LabVIEW.  I have been looking into XML files and they seem very flexible.  Viewing them with Notepad isnt the easiest and clearest way, but I have found that Microsoft Office have a few tools that make XML files easy to use.  Through Excel, you can generate a XML schema which will generate a table.  You can even make your own schema template to view the information.  Anyways, since XML seems widely used and flexible, this seems to be the way to go for me. Again, if anyone has any comments or tips, feel welcome 😄
0 Kudos
Message 7 of 9
(4,233 Views)

If your criterion is "must be able to modify outside LabVIEW" and not "must be text", then I can highly recommend HDF5, a binary, hierarchical file format.  It is a standard file format supported by most analysis packages (e.g. Matlab, Mathematica).  You can convert HDF5 to XML (which you will need to do if you want to support Excel).  If you are interested, you can get more information at the HDF5 web page.  A LabVIEW API can be downloaded from here.  Note that HDF5 is difficult to learn, but easy to use once you do.

Another good option is the LabVIEW TDM format.  It does have a 3 level hierarchy limit, but that doesn't sound like it will effect you.  Normal TDM is XML based, so you will have no problems reading it with a text editor (although there are binary forms as well, for efficiency).  There is also an Excel plug-in available to read TDM.  You can read and write TDM files in LabVIEW using the normal read/write measurement Express VIs or, with more control, with the storage VIs.  TDM is the native file format of DIAdem, NI's data analysis and report generating software.

If you are interested in either of these approaches and need more information, let us know.

 
Message 8 of 9
(4,215 Views)

Even though my username isnt the same, it's still vmallette!

 

Thanks DFGray for the insight.  You are right, my criteria is leaned more towards, "must be able to modify outside LabVIEW" and not "must be text", but I also have to keep in mind it has to be user friendly.  HDF5 sounds perfect for this type of application, but what bothers me is that the software I am writting must be easily portable to other pc's, and easy to use for anyone.  The idea anyone having to install dll's and needing MatLab etc just for reading configuration files sounds a tad excessive.  I will look into it though!  Also, TDM looks great too, but the 3 level hierarchy limit is a drag.  I know I can use this now, but I want to keep flexibility if ever I wish to add levels of information.

Out of curiosity, do you have any LabVIEW code examples for HDF5?

Thanks again for the useful information!

 

0 Kudos
Message 9 of 9
(4,208 Views)