06-08-2020 10:30 AM
Hi,
I am quite new to the labview and I am currently trying to convert some Fortran 95 code into Labview. I have a Do loop which I need to write in Labview 2019. Can someone guide me with a sample program to do so. Below is the code i want to convert.
IMPLICIT DOUBLE PRECISION (A-H, O-Z)
DIMENSION F(7), Q(5)
COMMON /SC/ C(41,2), CL(8,8)
T2 = T*T
F(1) = 1.D0
DO 40 J = 1, 5
40 Q(J) = 0.D0
DO 60 K = 1, 6
DO 50 J = 1, 5
50 Q(J) = Q(J) + F(K)*C(6*J+K-1, M) ( here is the confusion).
60 F(K+1) = F(K)*X
PRESA2 = Q(1)+T2*(Q(2)+T2*(Q(3)+T2*(Q(4)+T2*Q(5))))
END
Thanks for your time!.
Regards,
Raj
Solved! Go to Solution.
06-08-2020 02:31 PM
At the beginning of this Forum, there are links to learn LabVIEW. It is really very easy and logical (though, due to the graphical nature of LabVIEW, you probably want it installed on your Computer so you don't have to be drawing Block Diagrams and pictures of, say, the Add function.
Learn how to create Arrays. Learn about Controls (input variables), Indicators (output variables), and "wires" (in which data "flows", allowing you to declare and use many fewer variables than, say, a Fortran program requires).
Looking at your code, for example, "T" is a numeric control. By default, numeric controls are Dbls.
Learn about For loops. Learn that you can initialize an array (Q) to be an array of 5 zeros with a single Array function (called Initialize Array). Learn about Shift Registers (which means you don't need F -- it becomes a value carried on a Shift Register, initialized before the outer For Loop with 1, and update by being multiplied by the undefined (ERROR) quantity "X" before starting the next "60" loop.
Learn LabVIEW. You'll be amazed how easy it is to code this mess using LabVIEW functions and wires (do NOT try to replicate this code with, say, a "Math" node), and how much easier it is to "look at the code" and see what is going on.
Bob Schor
06-09-2020 12:33 AM
Apparently your only confusion is with statement 50, so I must assume that the rest is mostly in place already. Can you post your Vi (i.e. what you have so far) so we can better see what needs to be done to complete it.
Also remember that loops and array indices in LabVIEW are zero based, so account for that when dealing with iterations and indices.
06-09-2020 01:08 AM
Hi Altenbach,
I am attaching the VI. Please have a look and advice. Thanks for your time.
Regrads,
Raj
06-09-2020 01:11 AM
Hi Altenbach,
I am attaching the VI. Please have a look and advice. Thanks for your time.
Regrads,
Raj
06-09-2020 01:55 AM
Hi Altenbach,
I am sending the modified VI, replacing while loop with for loop. I am also confused about implementing the equation PRESA2 ( Iterative equation).
Guide me!
Regards,
rajram
06-09-2020 08:37 AM
Here is what I was thinking about the first part of your computation (up to computing Presa2):
Notice that Q and F are "wires", and X lives "mostly in the wire". The way you index C suggests that it is really a 3D array (though its size seems wrong, but you index it as though it had a 2D array "played out in row-major order") -- if you define/create it as such, using it will be much easier.
Your final computation of Presa2 introduces a bit of "magic" called Recursion. You are basically evaluating a polynomial. If I write the polynomial in the form a0 + a1 * x^1 + a2 * x^2 + ..., and make the coefficients into an array [a0, a1, ...], consider the following function:
I claim that f[array, x] is the function you want.
Suppose you only have a0. f[a0] (by the second rule) = a0 + f[empty array, x] = a0. OK so far.
Now how about [a0, a1]? f[a0, a1] = a0 + f[a1, x] = a0 + a1*x. I'll let you work out f[a0, a1, a2] for yourself.
Not every programming language supports Recursion (I don't believe that Fortran does). LabVIEW does, but you need to learn about sub-VIs, then you need to learn about re-entrant sub-VIs, a little more advanced, perhaps, than you are ready for.
There are ways to implement recursion using other means, but they tend to be a little clumsy, kind of like writing out the formula for Presa2 that you have in your Fortran code.
Bob Schor
06-10-2020 12:00 AM
Hi,
Thanks for your detailed guidance. I will modify my VI with your suggestions. Meanwhile, I am sharing the VI which I have created.
Regards,
rajram
06-10-2020 02:19 AM
Hi Bob,
I have implemented Recursion loop. But it seems that loop cant stop. Could you help further?.
regards,
Rajram
06-10-2020 02:21 AM
Forgot to add sub vi. Here it is.