04-10-2007 11:10 AM
04-10-2007 11:37 PM
Hi Wiebe,
My question is straight. Won't the Scan from String function give the outputs in the desired formats of integers even though the Inout string is in the format of a float. The context help also suggests the same as what I thought all these days.
In my VI, for the sake of maintaining uniform file writing, we follow the writing pattern of all numeric values in the format of float with 6-digit precision. This happens when you usually bind all your numerics into an array & then convert that array into a spreadsheet string.
So, while reading back the file, I know the order of the Numerics present in that String, meaning whether it is a Dbl or Int or Ring in the UI.
Thats why I tried to scan that string straight away thinking that it'll give Float, Numeric (I8/I16) and Ring (U16) for the corresponding controls in the UI.
Till now, it was perfect in the sense I didnt ve Integers & Rings written consecutively into the file, somehow a Float has got in between each Numeric/Ring in all the UIs except this particular VI. So, when I scan them, they were not giving trouble at all, because the Ring/Numerics were alternately having a Float dat after them.
But this VI has some Numeric & Ring controls in the FP that are written as the first 4 elements of the String with Tab as the delimiter for the file uniformity. Then there are 2 Voltage values (+ve & -ve) written after these 4 Ints into the String.
So, when I read them back, the Scan "FAILED" for the reason that it cannot read the Int correctly because the data in the String were of the type Float like as follows...
1.000000\t2.000000\t3.000000\t4.000000\t5.500000\t6.500000
Can you please try it out with these data & test for me ?
One inportant thing is, don't wire the Format String Input in the Scan from String function.
Even if you specify the Format String input, you ve to specify all the 6 as %f only.
If you specify as %d%d%d%d%f%f, it'll throw you an error.
If you specify as %d%f%d%f%f%f or %f%d%f%d%f%f, then it ll scan correctly.
Please test the attached VI.
04-11-2007 12:36 AM
Hi Partha,
I tried the code that u sent. Actually, if u connect an indicator to the "remaining string" of the scan from string function, u will note that if the data type (%d) does not match the input data type(%f) then the numbers after decimal points are displayed in the remaining string.
I dont know the size of the input string that you read back. But if it the case of reading only the string that u have sent in the code, why dont you try to break the string in two arrays ( first four corresponding to your numeric/ring values and second two for your voltages)
Then you can use "Decimal string to number" and "Fract string to number" to extract the values in indicators.
I dont know how tedious it will be for u.
04-11-2007 12:54 AM
@Harry02 wrote:
I dont know how tedious it will be for u.
Hi Harry,
It is not a question of tediousness. It is not tedious either, what you ve mentioened...
But it is the question of easiness for future implementations, say tomorrow, some more parameters are added in the UI, then you should exercise some sort of uniformity in your writing & reading patterns. You cannot keep track of what parameter of which datatype is written at which location.
04-11-2007 01:31 AM
Hi Partha,
I do agree to the concern for future implemetations. But anyways to use the scan from string function, you would require the exact format of the string that you read from the file.
The only problem starts as i mentioned in my earlier mail, is when you have input data type as float and you format it to integer. You do get the first value but until and unless you dont have the "remaining string" empty other values will not be displayeda as expected.
Pls find the attached image file with the code and the result that i got.
04-11-2007 01:40 AM
Hi Partha,
I do agree to the concern for future implemetations. But anyways to use the scan from string function, you would require the exact format of the string that you read from the file.
The only problem starts as i mentioned in my earlier mail, is when you have input data type as float and you format it to integer. You do get the first value but until and unless you dont have the "remaining string" empty other values will not be displayeda as expected.
Pls find the attached image file with the code and the result that i got.
04-11-2007 04:37 AM - edited 04-11-2007 04:37 AM
Message Edited by shoneill on 04-11-2007 11:38 AM
04-11-2007 05:16 AM
Hi,
I think partha has made it clear in his earlier comments that the values are stored as float in the file with a precesion of 6.
So the string which is read from the file will have 1.000000\t....6.500000 etc and not 1\t...6.500000.
Also what one can do is simply input the format type to %f%f%f..and so on and then may be connect each of them to display as either integer ao float. We can always change the display of the indicator as we desire.
Any comments?
04-11-2007 05:43 AM
04-11-2007 07:05 AM
@shoneill wrote:
it's a valid question why the string representation of an integer should be stored as a float......
Shane.
Shane,
It is for the uniformity of File writing that we follow the procedure of converting all the Numeric values ( Dbl/Int/Ring ) to be of Float String with 6 digit precision. This is because all our rest sub-VIs (UIs) that show the variouus settings for different cards have more no. of parameters that in turn are of the nature Dbl, like Voltages, Clamp Currents, Sine/Ramp Voltage values, etc.
So, they need to be written in Dbl Str format, right... ?!
Our team follows the same procedure of building them into arrays & converting them into Dbl Str arrays.
These settings for the various cards are in turn shown in the Table in the FP & converted into a Spreadsheet Str on a single stroke, and written in a txt file without extension so that it can be opened either in Notepad/Wordpad as per availability for reference.
Thats why all my confusion with the Scan from String function, if that was a minor bug...
Now I'm clear about it.
Thank you all !