LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a filepath as input to MathScript node?

Hello,

I have a working Matlab function (an .m file) for reading MiniSEED (data-only) datafile. It works great in Matlab and requires a filepath as an input parameter. If no file is input it opens a dialog to select one. However, when I import this m file into a MathScript node, LV insists that an input parameter is mandatory.

I cannot create a filepath input parameter (seems as MathScript node does not allow this?) - Is this possible and how? I would be very surprised if MathScript nodes only expect DBLs as inputs. Is there a workarround?

Thanks in advance,

G

0 Kudos
Message 1 of 6
(3,473 Views)

I imagine that Mathscript files would treat filepaths as strings.  So use some file dialog functions, and convert the filepath to a string before passing to the mathscript node.

0 Kudos
Message 2 of 6
(3,471 Views)

Damn! Now I noticed - this is a function expecting variable number of input args and a status output arg. This is why LV shows broken run arrow and msgs following error:

 

A function is defined in this script. You must save and call the
function with appropriate input values to execute the function.

 

BTW, thank you RF, a string converted froma filepath is acceptable for the MathScript node.

 

Here is my situation, I can follow the m code, however cannot alter it though - not familiar! Since I would use it with only a single parameter (selected file) how should I "reformat" it not to be seen as a function, but rather as working code?

 

It is pretty readbale and well commented - anybody willing to parse it and remove the problem?

0 Kudos
Message 3 of 6
(3,462 Views)

Why not simply code it in LabVIEW?  If all it's doing is reading in a file and doing some simple parsing (as I gather from your comments), this should be duck soup.  How complicated is the Matlab file?  Can you post something?

 

Bob Schor

0 Kudos
Message 4 of 6
(3,434 Views)

Hi Bob,

It is not simple at all. Attached is the file itself. I just realized the very 1st line which is the function declaration (so far I though of the listing as a kind of "main"). So filepath is not the input parameter but an array of cmd params (not exceeding 6 as I understand below). It reads block by block of data, each headered with a blockette that might differ. So my reluctance to code it in LV is based on the obvious fact that the structure X might differ from block to block. The X[i]s are read in a for loop and I can't figure out how Matlab knows the exact structure of read block.

Of course I will end up writing my own LV reader, but if I can make this work within a MathScript by using the "version" with just filepath as input parameter (other params implicit) I would save me a precious time 🙂

Comments are wellcome,

0 Kudos
Message 5 of 6
(3,409 Views)

Wow, that is ugly.

  • The name, "rdmseed", seems mnemonic for RandomSeed, suggesting that it is a mechanism for starting ("seeding") a random-number generator.  Of course it has nothing to do with random numbers.
  • The function has 5 inputs, and can be called with varying numbers of them set.  It does appear, however, that the intended use is either no parameters are specified or at least the first, a File Path, is specified.  LabVIEW can handle this by setting appropriate Default values and, if necessary, testing the input.  For example, if the File input is an empty path, "open user interface to select the file from disk".
  • A trickier proposition involves the output arguments, which can be 0, 1, or 2.  In particular, the call with zero output arguments does an entirely different (and largely-unrelated) concatenate-and-plot action instead of a file input action.  Handling the one-or-two output argument situation is much simpler -- just supply both outputs, and let the user choose "to wire, or not to wire, that is the Question".  One possible way to handle this is to create a reference to an Output Cluster (which would have both X and I elements) and wire "Not a Refnum" for the zero-output-argument case.

Of course, there are other issues.  Many of the FDSN codes would be easy to implement (ASCII, the integer and Float formats), but others are unknown to me (Steim, GEOSCOPE).  The meaning and implication of some of the I-structure fields don't mean much to me, but clearly may have an implication on how the data in the blocks are combined.  And then there's the nature of the plots.

 

Still, if this is the only place you would need to interact with Matlab, it becomes a judgment call whether it might be simpler, faster, more maintainable, dare we say "better?" to byte the bullet and write Read miniSEED File.vi.  If it were my project, I'd invest at least a day or two in the attempt ...

 

Bob Schor

 

0 Kudos
Message 6 of 6
(3,378 Views)