December 12, 2005

New String Functions

In my role as part of the LabVIEW documentation team, I use LabVIEW a lot, but often not the way the typical user would. Though I have some NI hardware installed, I rarely acquire, analyze, or present a signal. I use it mainly for… string manipulation. You read right. I use LabVIEW for string manipulation – searching, splitting, and replacing text. Historically, this is not one of LabVIEW’s strengths.
My VIs have a lot of string functions, each handling some specific string manipulating operation – one that splits the string, another that splits the remaining string, one that searches the resulting string of the previous two splits, etc. Also, I’m reading files, moving files around, changing file permissions, taking strings from one file and moving it to another file IF something in the string matches something else, etc. I use a lot of For Loops and a lot of While Loops with shift registers that I get the stop condition wrong on half the time. I’m sure there are ways I could make my VIs more streamline, but I’ve been doing things the same way for so many years, I’m just sort of stuck in my LabVIEW coding ways. Right now my block diagrams look like Jackson Pollack paintings.
So, now, 8.0 is out the door (of course, I had to use 7.1 to develop tools used to document 8.0) and I’m thinking to myself, maybe it’s time to teach this old dog some new tricks. What’s 8.0 got to improve string parsing and file I/O? I was in for a very pleasant surprise.
First, there’s this function called the Match Regular Expression function. I used it the other day for the first time for real (not like when I’m writing documentation for a feature, which is when I try and come up with the most ridiculous use case I can come up with that may or may not have a correlation in the real world, just so I can understand the intricacies of the feature).
So, right away I’m using a single function to parse the data from a whole text file. No searching and splitting functions. No While Loop with shift registers that I need figure out the stop condition for; just a single function with four wires. The magic is this function uses Perl-like syntax. In fact, it talks to an open-source Perl library developed at Cornell. I know next-to-no Perl script, but within minutes I was using this function exactly as I wanted to.
Second, the File I/O VIs are no longer VIs. They’re functions – nifty polymorphic functions. I can’t tell you how many times I’ve had to replace the “Read Characters from File” VI with the Open and Read File functions because I need to work with a File I/O function that only accepts a refnum for some other reason later in my data flow. Those days are over because most of the File I/O functions accept refnums and path names.
Yes, I could try and go home and relay this epiphany to my family around the dinner table, but I’m not it would meet with much enthusiasm (especially from my kids – ages 2 years and six months). This forum seemed the best place to share my enthusiasm.

3 comments:

  1. I you are doing string manipulation, then Regular Expressions are an absolute must. Also, for working with documentation, I have a set of tools for doing keyword substitution in strings and files. This allows me to quickly instanciate documentation templates. I use dictionaries to store associative arrays of keywords and values and manage several namespaces (dictionaries) that can be merged depending on the item that is accessing them. For example, I have a project namespace, a component namespace, and a VI namespace. When I am documenting a VI I merge all three namespaces for instanciating the VI documentation template.

    ReplyDelete
  2. I am another internal NI customer of LabVIEW. I use tools written in LabVIEW to create search friendly documentation to post on ni.com, such as the LabVIEW 8 Help.

    I am equally not-confident about the strength and efficiency of the algorithms that I have developed, but they are effective nonetheless. The new 8 function, however, is quite intriguing and I am looking forward to playing with it.

    ReplyDelete
  3. How to stop the output graph's output waveform from returning back to 0 after a recorded values from my loadcells? It keeps drops back to 0 and back up to my recoreded values. How to i maintain the recorded value?? Which function or template do i have to use?

    ReplyDelete