Example Code

Write and Read from Arrays (.lvm) in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

Overview

This VI exemplifies how to write and read from a .lvm file.


Description

This VI allows the user to write and read from a .lvm file. It is possible to use a custom file name and the code verifies if the generated path is valid or not. This could be useful to easily write and read a file that could stop measurement data with additional information that describes it.


You could find more information about the .lvm file format in the following document:
Specification for the LabVIEW Measurement File (.lvm)

 

Requirements
LabVIEW Base Development System.

 

Steps to Implement or Execute Code
1. Open the attached VI " Write - Read lvm Files LV 2012 - NI verified.vi".
2. Run the VI.
3. Select a valid file name.
    3.1 In case the file name is incorrect to select a valid one.
4. Click the “Save button” to save the File.
5. You can also process the read it data by pressing the “Process Data” button.

 

Additional Information or References

 Snippet 2874.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
altenbach
Knight of NI Knight of NI
Knight of NI
on

This code is 10 times (!) more complicated that it needs to be and contains many mistakes.

  • Overuse of local variables
  • Sequences that can be replaced by proper dataflow.
  • Greedy loops.
  • No main loop.
  • latch action booleans outside their event structure (they don't reset when clicked).
  • Incorrect representations. Why convert to I32 when everything is coerced back to DBL a nanosecond later?
  • Indexing with the iteration terminal instead of autoindexing.
  • "Index array" can be resized for multiple outputs
  • No diagram comments
  • complicated loop implementations of existing LabVIEW primitives (Array min/max, writee to spreadsheet file).
  • You don't need a formula express VI to see if an integer is odd or even, besides, you should never used this with DBL.

Here is a quick comparison of parts of your code with suggested alternatives.

(see also this discussion) My suggestions are just rough drafts. You might need to tweak a little bit for correct functionality.

(1) To zero all odd elements, you could do one of the following alternatives instead of your code monster (top):

(how many times do you possibly need to read from a different local variable of the same array! They all contain the same data! Don't be afraid to branch a wire)

(2) To get the minimum of each row of a 2D array and write it to a file, you could do it your way (above) or the easy way (below):