LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

string exponent number to integer and double conversion

Anyone who can help please,

 

I am receiving data back from an Agilent E4407B with the noise figure option in the following form:

 

+1.00000000E+008,+1.52799997E+001,+1.00000000E+009,+1.52200003E+001,+2.00000000E+009,+1.51099997E+001,+3.00000000E+009,+1.50799999E+001,

 

for up to 401 pairs of frequencies and amplitude figures.  This is all coming back in one long string.

 

I want to read the pairs of figures into a 2 dimensional array, so that the first part of the array has the frequency in an double format, but NO exponent, and the second part of the array has the ENR value agan in a double format and also with NO exponent.

 

I have been using:

 

double ENR_Data[401][2];

Scan(Databuf,"%s>%401f[x]",&ENR_Data);

 

This reads the data into the array, but retains the exponent - please can someone show me the correct Scan formatting functions to use so that I keep just the number, and loose the scientific exponent format?

 

Many thanks for any help,

 

Allen Cherry

0 Kudos
Message 1 of 5
(5,304 Views)

Allen:

 

I'm not clear on what you are trying to do. 

 

You have created an array of doubles (ENR_data).  CVI will store doubles internally in a floating point format, which will include an exponent.  But that internal representation in memory has nothing to do with the way the number is formatted when it is displayed.

 

When you talk about the format of the number, it sounds like you are displaying the number somewhere.  How are you doing that?    Using ANSI C printf(), you have options on how the number is displayed (%f = decimal representation with no exponent or %e = exponent notation).

0 Kudos
Message 2 of 5
(5,298 Views)

Thank you for the interest and help.

 

I need to use the array to interpolate the ENR value for frequencies that fall between the 'fixed' values received from the E4407B.  Testing the array, I have seen the the values are not being correctly inerpolated - the exponent does not have any effect - i.e. for a frequency value (to be interpolated) of (say) 25000000000, all the vales in the array are ignored as being 'less' than the value to be interpolated.  Hence it would appear that the values int he array should be 'real' values (e.g. 2000000000 and 3000000000) for the interpolation to work, rather than 2.0E+9 and 3.0E+9 which the array holds as the values.  (I may have the number of zeros wrong by 1 or 2 in the example!!)

 

Does that make the situation a bit more clear?

 

Many thanks,

 

Allen

0 Kudos
Message 3 of 5
(5,290 Views)

Allen:

 

It doesn't matter how you represent the doubles: the compiler represents them the same.

 

double a = 2000000000.00;

double b = 2e9;

 

As far as the compiler is concerned (and as far as you should be concerned), a==b.

 

In your last reply, your interpolated value of (say) 25000000000 = 2.5e10, which is greater than 2e9 and 3e9.  You said you may have the wrong number of zeros in the example, but please make sure you have the right number of zeros in your code.

 

Are you sure you are handling the array correctly?  Remember that the array subscripts are [row][column].  From your sample data, the frequency values are in column 0.  The first frequency value would be ENR_Data[0][0].  The second frequency value would be ENR_Data[1][0], followed by ENR_Data[2][0], etc.

 

Check the code I included below.  It's based on the numbers shown in your example.  It correctly determines if a number is greater than or less than a desired interpolated point.

 

P.S. What algorithm are you using to do you interpolation?  I don't even know why you are searching for a number greater than some known value: you should be interpolating between points read from the array.

 

#include <ansi_c.h>
#include <utility.h>
#include <formatio.h>
main()
{
 char Databuf[] = "+1.00000000E+008,+1.52799997E+001,+1.00000000E+009,+1.52200003E+001,"
     "+2.00000000E+009,+1.51099997E+001,+3.00000000E+009,+1.50799999E+001";
 
 double ENR_Data[401][2];
 
 double interpValue = 2.5E9;
 // same as
 // double interpValue = 2500000000.00;

 int i;
 
 Scan(Databuf,"%s>%401f[x]",&ENR_Data);

 for (i=0; i<4; i++)
 {
  if (ENR_Data[i][0] > interpValue)
   printf("%f (%e) > %f (%e)\n",
    ENR_Data[i][0], ENR_Data[i][0],
    interpValue, interpValue);
  else
   printf("%f (%e) <= %f (%e)\n",
    ENR_Data[i][0], ENR_Data[i][0],
    interpValue, interpValue);
 }
   
 printf("Press any key to continue...\n");
 GetKey();

}

0 Kudos
Message 4 of 5
(5,284 Views)

Thank you for the assistance. 

 

I was confused over the format when I used the variable 'view' facility, and the first value was shown without an exponent, whist the other values all had exponents:-

 

100000000.000000000000000 15.279999699999999
1.000000000000000E+9         15.220000300000001
2.000000000000000E+9         15.109999699999999
3.000000000000000E+9         15.079999900000001
4.000000000000000E+9         14.779999699999999

etc. etc. etc

 

I still do not understand why the first frequency value in the array is not shown as 1.000000000000000E+8.  Do you have any explanation?

 

However, the interpolation is working, and I am now deriving the correct ENR values for frequencies that fall in between the calibrated values shown in the table.

 

Many thanks for your help,

 

Allen

 

 

 

0 Kudos
Message 5 of 5
(5,225 Views)