02-11-2013 06:52 AM
Hi,
I have data in a text file, see attached example srm.txt, set out in X columns wide of Y lines long. Each column is of varying width of hex data.
I need to extract column Z from each line. Extract the max, min and average for that column and store this data.
This is repeated for Z+1 until the last column X.
I have been scanning the discussions and trying to adapt what I have found with little success.
I am mainly work with what I asked befor in “Line extract and split from files” but this new request differ a bit from the solution provided at that time.
Any pointers to examples or some direction would be much appreciated.
Thanks
Simon
02-13-2013 10:39 AM
Hi Srm27,
As a bit of guidance, the most popular way to read in the data from a file is through the ReadLine funciton in LabWindows, RobertoBozzolo has given a good explanation on how this works across the span of this thread. There are other ways to read from files such as through ScanFile, a nice list of which can be used can be found on this page but bear in mind cases in which you cannot read hexadecimal numbers from a file such as with the FileToArray function.
In terms of statistical functions within LabWindows you have these available to you, and if you want to convert from hex to floating point you can use this as a reference.
I hope this helps!
02-14-2013 05:46 AM - edited 02-14-2013 05:50 AM
Hi,
Thanks for the pointers.
I have the columns into the array and using the calculations can get the average.
But I am still struggling with the conversion from hex to decimal. The link provided is not working.
At the moment I read in the value, a string, from the file and on converting I think in ends up as decimal, val, with the following
val = atoi(items[i]);
Problem is if I read a true hex, with letters, I return 0.
If I read from the file F434, for example I need to get it to 62516 so I can work on it, i.e. stats.
1 can I convert directly to hex?
2 failing that how do I convert val from int to hex?
I will may be farm from what should be done, can anyone help?
Thanks
Simon
02-14-2013 06:15 AM - edited 02-14-2013 06:18 AM
You should use Scan from Formatting and I/O Library or sscanf from Ansi_C Library to decode hex digits, both with "%x" scanning code; documentation on the latter can be fonud in any good C reference manual. Both of them are powerful yet complex commands that can help you in extracting a specific column from your data while analyzing a line of text.
02-14-2013 08:57 AM
Roberto,
Thanks for that direction.
I am once more on the way.
Thanks to all for the input.
For the size of the array to hole the information is set to 100 at the start of the code, for the moment I only fill 30 location.
1. Any way to know how many locations are used? Al the moment I count in the information and know that way.
2. I have trying hard to allocate the size of the array to suit the information been put into the array, so it grows at data is added, but failing, is this really possible and if so any examples I could "borrow"?
Thanks
Simon