LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan 2D array for proper data series

Hello,

I will have many .s2p files from farfield antenna measurements. I should read all data and make some calculations. Read files from folder and sorting is done.

Now:

THETA is in range from 0-180, PHI: 0-350. Both THETA and PHI can start with value different from 0 and end at value different from 180 or 350. Both THETA and PHI can have different step value, e.g. 1, 2, 3, 4, 5, 6, 10.

My problem is to check if all files in series are present.

First to check what is general step value;

Second to check if all files to read are present, e.g. I have THETA from 50-100 and PHI from 0-350. Now must be check if for THETA=50 all PHI from 0-350 with proper step are present. Next THETA=51 (means step=1), check if PHI 0-350. Next THETA=52 (means step=1), check if PHI 0-350. Next THETA=53, PHI 1-350 - error, no THETA=53_PHI=0 file.

I started, but don't know how to continue.

0 Kudos
Message 1 of 8
(3,056 Views)

If I understand your problem correctly, you require N*M files, where N is the number of discrete Theta values (starting at Theta0 and incrementing by dTheta) and M is the number of discrete Phi values (starting at Phi0 and incrementing by dPhi).  dTheta and dPhi have the values 1, 2, 3, 4, 5, 6, or 10.

 

If you know Theta0, ThetaFinal, and dTheta, you can calculate N.  Similarly, you can calculate M.  So the first test is simply to count the number of files -- if it isn't N*M, you are missing files.

 

Each Filename presumably has Theta and Phi encoded in the name.  Also, each Filename is different, hence has different Theta/Phi pairs of values (i.e. you can't have two files with Theta = 1 and Phi = 1).  So if you see you have the correct number of files, now the problem is are all of the Theta values correctly spaced from Theta0 to ThetaFinal (with spacing dTheta), with a similar question for the Phi values.  Note that you don't have to do (much) string processing -- you just need to make an integer array of all of the Theta values in the array of Filenames, and all of the Phi values, then test that all have the correct value.  An easy test for this is

  • Do they lie between Theta0 and ThetaFinal?
  • Is the remainder of (ThetaTest - Theta0) Mod dTheta = 0?

If either is No, you have a bad value.

 

Bob Schor

Message 2 of 8
(2,992 Views)

Hello,

thank You for tip, I created something, could You please check if this is OK? I suspect that it can be done easier, but...:)

Program does:

1. sorting data first by THETA, then by PHI;

2. cutting string and extracting only THETA and only PHI values (THETA_read and PHI_read);

3. extracting also filtered THETA and PHI values (without repeated) (THETA_filtered and PHI_filtered);

4. checking THETA and PHI step values between next elements (THETA_step and PHI_step) and getting Boolean if all steps are equal (THETA_step_equal? and PHI_step_equal?);

5. checking repeated next PHI value for one THETA value (Next PHI_read differ from previous?);

6. checking if files amount agree with PHI_amount*THETA_amount.

7. All to AND Boolean, at the end info if file list is proper.

 

Could You please check it if I overlooked something?

0 Kudos
Message 3 of 8
(2,981 Views)

Not bad!  A "mild" criticism is that your code would benefit by a few sub-VIs to do "repetetive things" (you'll see in a moment what I mean).  Will your code "catch" two entries that are the same?  Note that the M*N=P test might still pass, as you might have a duplicate + a missing entry.

 

So here's a slightly different slant to things.  Do you know about Clusters?  You can define an "Angle" cluster as having two components, Theta and Phi.  I'm going to try to see if I can put a Snippet in here so I can "Show" while I "Tell".

 

 

Data Series, BS.png

 

 

 

 

 

 

You will notice that I start with an UnSorted List (the same as your "Sorted List", but it doesn't have to be sorted).  I don't use an AlphaMagical Quick Sort, but do the sort later.  I always get confused with the "Extract from String" functions, so I use "Scan from String", as shown, which lets me directly pull out the Theta and Phi values in one pass, where I bundle them into my Angles cluster (which I have created as a TypeDef, allowing me to change it by changing its definition, for example, to make Theta and Phi I32 instead of Dbl).  Note the Error Line -- if any of the strings is "mal-formed" (e.g. "THETA=23,     PHI=4"), an error will be thrown and you'll be able to abort and fix the problem.

 

Next comes a simple sort of a 1D array.  Clusters sort by elements, so 10, 10 precedes 10, 20 precedes 20, 10.  Now would be a good time to compare adjacent Cluster elements (I trust you can figure out how to do this with a For loop, a Shift Register, and building a Boolean Array as you go) and check that all the elements are unique.  I left this out.

 

The next For loop pulls out two arrays, one of all the Theta values, the other of all the Phi values.  I'd write a sub-VI that sorts these arrays, removes duplicates, then checks them for "equal deltas", returning True if all are equal + the number of unique values.  Then you can check that the product of these two numbers = the size of the Cluster array.

 

Don't feel you need to change your code (except, perhaps, for the "Check if Unique" test) -- I just threw in a "little extra".

 

Bob Schor

Message 4 of 8
(2,963 Views)

About clusters not so much, but I will try follow your advice.

1. "Will your code "catch" two entries that are the same?  Note that the M*N=P test might still pass, as you might have a duplicate + a missing entry." - it is done by "Next PHI_read differ from previous?" Data are sorted, so when adjacent PHI are the same that means error.

2. According to "Scan from string" - string format is fix defined as "THETA=%f, PHI=%f". It was only an example, it can be also "THETA=%f_PHI=%f" or e.g. "THETA_%f-PHI_%f", so for me it is important to catch words "THETA" and "PHI" and extract first numbers after them. Could you help me with this?

0 Kudos
Message 5 of 8
(2,954 Views)

Accordinf to point 2.: "THETA%[\s\t=-_]%d%[\s\t,._-]PHI%[\s\t=-_]%d" - should it be enough?

0 Kudos
Message 6 of 8
(2,936 Views)

Could you please explain me what is this marked place on the photo? How you did this?Unbenannt.png

0 Kudos
Message 7 of 8
(2,931 Views)

That is a Type Def (control) for the Cluster consisting of Theta and Phi.  When I built the Control, I also created an Icon for it -- a black-outlined Yellow box with TYPE on the top and the name of the TypeDef, "Angles", in the bottom part.  When I wanted to combine Theta and Phi into this Cluster, I used Bundle by Name (the names help ensure that things get wired to the "right place"), which requires an input "from the top" to define the Cluster Elements.  I used the TypeDef (so if I ever need to change the Cluster, for example, add "Rho" as another element, or rename "Phi" to "Xi", I just change the TypeDef Control and it changes everywhere automatically).  When I drop the TypeDef Control on the Block Diagram, it looks like two Dbl Constants (of 0) stacked on top of each other.  But if you double-click the edge of the Cluster Constant, it will change to its Icon Representation!  This is a very neat trick that came in around LabVIEW 2011 or so -- I'd love to see NI extend this to other TypeDefs (like Arrays, but really any TypeDef) -- I even proposed this on the Idea Exchange, but it was "rejected because not enough people voted for it".

 

Bob Schor

0 Kudos
Message 8 of 8
(2,917 Views)