reguarding scientific notation

Discussion in 'C Programming' started by grinder, Aug 28, 2006.

  1. grinder

    grinder Guest

    I have a program that fits a line to data points. The question is: can
    'C' understand scientific notation (as below) , and if not what can i
    do to make it work..


    0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02
    13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02

    26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02

    39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02

    51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02

    63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02

    74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02

    85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01

    96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01

    106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01

    115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01

    124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01

    133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02

    141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02

    149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02

    157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02

    165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02

    172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02

    0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02


    My data is primarily the last two columns.
    I have written a script in AWK to strip columns 4 & 5, though i have
    not tried to run this data file through my C program, i am fairly
    confident that it will not understand the syntan.


    Please help. praise the lord
     
    grinder, Aug 28, 2006
    #1
    1. Advertising

  2. grinder

    Knemon Guest

    grinder wrote:
    > I have a program that fits a line to data points. The question is: can
    > 'C' understand scientific notation (as below) , and if not what can i
    > do to make it work..
    >
    >
    > 0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02
    > 13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02
    >
    > 26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02
    >
    > 39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02
    >
    > 51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02
    >
    > 63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02
    >
    > 74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02
    >
    > 85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01
    >
    > 96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01
    >
    > 106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01
    >
    > 115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01
    >
    > 124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01
    >
    > 133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02
    >
    > 141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02
    >
    > 149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02
    >
    > 157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02
    >
    > 165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02
    >
    > 172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02
    >
    > 0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02
    >
    >
    > My data is primarily the last two columns.
    > I have written a script in AWK to strip columns 4 & 5, though i have
    > not tried to run this data file through my C program, i am fairly
    > confident that it will not understand the syntan.


    #include <stdio.h>

    int main(void)
    {
    char input[] = "0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02\n"
    "13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02\n"
    "26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02\n"
    "39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02\n"
    "51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02\n"
    "63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02\n"
    "74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02\n"
    "85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01\n"
    "96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01\n"
    "106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01\n"
    "115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01\n"
    "124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01\n"
    "133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02\n"
    "141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02\n"
    "149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02\n"
    "157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02\n"
    "165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02\n"
    "172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02\n"
    "0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02\n", *p;
    double x[5];
    int n = 0;
    printf("The input stream contains:\n%s\n", input);
    for (p = input;; p += n) {
    if (sscanf(p, "%lg%lg%lg%lg%lg%n",
    &x[0], &x[1], &x[2], &x[3], &x[4], &n) != 5)
    break;
    printf
    ("After %d more characters, the x array contains\n"
    "%g %E %E %g %E\n\n", n, x[0], x[1], x[2], x[3], x[4]);
    }
    return 0;
    }


    The input stream contains:
    0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02
    13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02
    26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02
    39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02
    51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02
    63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02
    74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02
    85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01
    96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01
    106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01
    115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01
    124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01
    133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02
    141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02
    149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02
    157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02
    165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02
    172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02
    0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02

    After 49 more characters, the x array contains
    0 3.231000E+01 0.000000E+00 0 5.642000E+01

    After 51 more characters, the x array contains
    13.191 3.421000E+01 0.000000E+00 10 5.910000E+01

    After 51 more characters, the x array contains
    26.248 2.842000E+01 0.000000E+00 20 4.758000E+01

    After 51 more characters, the x array contains
    39.047 2.325000E+01 0.000000E+00 30 3.701000E+01

    After 51 more characters, the x array contains
    51.485 1.790000E+01 0.000000E+00 40 2.664000E+01

    After 51 more characters, the x array contains
    63.483 1.313000E+01 0.000000E+00 50 1.803000E+01

    After 51 more characters, the x array contains
    74.987 9.572000E+00 0.000000E+00 60 1.201000E+01

    After 51 more characters, the x array contains
    85.971 7.565000E+00 0.000000E+00 70 8.609000E+00

    After 51 more characters, the x array contains
    96.431 7.118000E+00 0.000000E+00 80 7.326000E+00

    After 52 more characters, the x array contains
    106.379 8.017000E+00 0.000000E+00 90 7.463000E+00

    After 52 more characters, the x array contains
    115.846 9.925000E+00 0.000000E+00 100 8.379000E+00

    After 52 more characters, the x array contains
    124.87 1.246000E+01 0.000000E+00 110 9.596000E+00

    After 52 more characters, the x array contains
    133.498 1.528000E+01 0.000000E+00 120 1.081000E+01

    After 52 more characters, the x array contains
    141.781 1.809000E+01 0.000000E+00 130 1.187000E+01

    After 52 more characters, the x array contains
    149.775 2.064000E+01 0.000000E+00 140 1.272000E+01

    After 52 more characters, the x array contains
    157.536 2.277000E+01 0.000000E+00 150 1.334000E+01

    After 52 more characters, the x array contains
    165.121 2.437000E+01 0.000000E+00 160 1.376000E+01

    After 52 more characters, the x array contains
    172.59 2.536000E+01 0.000000E+00 170 1.399000E+01

    After 50 more characters, the x array contains
    0 3.240000E+01 0.000000E+00 180 5.658000E+01
     
    Knemon, Aug 29, 2006
    #2
    1. Advertising

  3. grinder

    Ben Pfaff Guest

    "grinder" <> writes:

    > The question is: can 'C' understand scientific notation (as
    > below)


    Yes. The sscanf and strtod functions are likely to do what you
    want.
    --
    "A lesson for us all: Even in trivia there are traps."
    --Eric Sosman
     
    Ben Pfaff, Aug 29, 2006
    #3
  4. grinder

    Guest

    hey knemon,

    when i compile it in gcc and try to execute it , it says
    permission denied . Doesn't mean the code is accessing any unknown
    address , it should throw SEGV or else what can be the problem ??

    Knemon wrote:

    > grinder wrote:
    > > I have a program that fits a line to data points. The question is: can
    > > 'C' understand scientific notation (as below) , and if not what can i
    > > do to make it work..
    > >
    > >
    > > 0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02
    > > 13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02
    > >
    > > 26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02
    > >
    > > 39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02
    > >
    > > 51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02
    > >
    > > 63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02
    > >
    > > 74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02
    > >
    > > 85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01
    > >
    > > 96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01
    > >
    > > 106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01
    > >
    > > 115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01
    > >
    > > 124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01
    > >
    > > 133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02
    > >
    > > 141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02
    > >
    > > 149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02
    > >
    > > 157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02
    > >
    > > 165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02
    > >
    > > 172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02
    > >
    > > 0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02
    > >
    > >
    > > My data is primarily the last two columns.
    > > I have written a script in AWK to strip columns 4 & 5, though i have
    > > not tried to run this data file through my C program, i am fairly
    > > confident that it will not understand the syntan.

    >
    > #include <stdio.h>
    >
    > int main(void)
    > {
    > char input[] = "0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02\n"
    > "13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02\n"
    > "26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02\n"
    > "39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02\n"
    > "51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02\n"
    > "63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02\n"
    > "74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02\n"
    > "85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01\n"
    > "96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01\n"
    > "106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01\n"
    > "115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01\n"
    > "124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01\n"
    > "133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02\n"
    > "141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02\n"
    > "149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02\n"
    > "157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02\n"
    > "165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02\n"
    > "172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02\n"
    > "0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02\n", *p;
    > double x[5];
    > int n = 0;
    > printf("The input stream contains:\n%s\n", input);
    > for (p = input;; p += n) {
    > if (sscanf(p, "%lg%lg%lg%lg%lg%n",
    > &x[0], &x[1], &x[2], &x[3], &x[4], &n) != 5)
    > break;
    > printf
    > ("After %d more characters, the x array contains\n"
    > "%g %E %E %g %E\n\n", n, x[0], x[1], x[2], x[3], x[4]);
    > }
    > return 0;
    > }
    >
    >
    > The input stream contains:
    > 0.000 0.3231E+02 0.0000E+00 0.00 0.5642E+02
    > 13.191 0.3421E+02 0.0000E+00 10.00 0.5910E+02
    > 26.248 0.2842E+02 0.0000E+00 20.00 0.4758E+02
    > 39.047 0.2325E+02 0.0000E+00 30.00 0.3701E+02
    > 51.485 0.1790E+02 0.0000E+00 40.00 0.2664E+02
    > 63.483 0.1313E+02 0.0000E+00 50.00 0.1803E+02
    > 74.987 0.9572E+01 0.0000E+00 60.00 0.1201E+02
    > 85.971 0.7565E+01 0.0000E+00 70.00 0.8609E+01
    > 96.431 0.7118E+01 0.0000E+00 80.00 0.7326E+01
    > 106.379 0.8017E+01 0.0000E+00 90.00 0.7463E+01
    > 115.846 0.9925E+01 0.0000E+00 100.00 0.8379E+01
    > 124.870 0.1246E+02 0.0000E+00 110.00 0.9596E+01
    > 133.498 0.1528E+02 0.0000E+00 120.00 0.1081E+02
    > 141.781 0.1809E+02 0.0000E+00 130.00 0.1187E+02
    > 149.775 0.2064E+02 0.0000E+00 140.00 0.1272E+02
    > 157.536 0.2277E+02 0.0000E+00 150.00 0.1334E+02
    > 165.121 0.2437E+02 0.0000E+00 160.00 0.1376E+02
    > 172.590 0.2536E+02 0.0000E+00 170.00 0.1399E+02
    > 0.000 0.3240E+02 0.0000E+00 180.00 0.5658E+02
    >
    > After 49 more characters, the x array contains
    > 0 3.231000E+01 0.000000E+00 0 5.642000E+01
    >
    > After 51 more characters, the x array contains
    > 13.191 3.421000E+01 0.000000E+00 10 5.910000E+01
    >
    > After 51 more characters, the x array contains
    > 26.248 2.842000E+01 0.000000E+00 20 4.758000E+01
    >
    > After 51 more characters, the x array contains
    > 39.047 2.325000E+01 0.000000E+00 30 3.701000E+01
    >
    > After 51 more characters, the x array contains
    > 51.485 1.790000E+01 0.000000E+00 40 2.664000E+01
    >
    > After 51 more characters, the x array contains
    > 63.483 1.313000E+01 0.000000E+00 50 1.803000E+01
    >
    > After 51 more characters, the x array contains
    > 74.987 9.572000E+00 0.000000E+00 60 1.201000E+01
    >
    > After 51 more characters, the x array contains
    > 85.971 7.565000E+00 0.000000E+00 70 8.609000E+00
    >
    > After 51 more characters, the x array contains
    > 96.431 7.118000E+00 0.000000E+00 80 7.326000E+00
    >
    > After 52 more characters, the x array contains
    > 106.379 8.017000E+00 0.000000E+00 90 7.463000E+00
    >
    > After 52 more characters, the x array contains
    > 115.846 9.925000E+00 0.000000E+00 100 8.379000E+00
    >
    > After 52 more characters, the x array contains
    > 124.87 1.246000E+01 0.000000E+00 110 9.596000E+00
    >
    > After 52 more characters, the x array contains
    > 133.498 1.528000E+01 0.000000E+00 120 1.081000E+01
    >
    > After 52 more characters, the x array contains
    > 141.781 1.809000E+01 0.000000E+00 130 1.187000E+01
    >
    > After 52 more characters, the x array contains
    > 149.775 2.064000E+01 0.000000E+00 140 1.272000E+01
    >
    > After 52 more characters, the x array contains
    > 157.536 2.277000E+01 0.000000E+00 150 1.334000E+01
    >
    > After 52 more characters, the x array contains
    > 165.121 2.437000E+01 0.000000E+00 160 1.376000E+01
    >
    > After 52 more characters, the x array contains
    > 172.59 2.536000E+01 0.000000E+00 170 1.399000E+01
    >
    > After 50 more characters, the x array contains
    > 0 3.240000E+01 0.000000E+00 180 5.658000E+01
     
    , Aug 29, 2006
    #4
  5. grinder

    jmcgill Guest

    wrote:
    > hey knemon,
    >
    > when i compile it in gcc and try to execute it , it says
    > permission denied . Doesn't mean the code is accessing any unknown
    > address , it should throw SEGV or else what can be the problem ??


    You shell is saying "permission denied", I assume because the output
    file from your compiler is not executable for some reason.

    The program itself doesn't have any IO that would be likely to lead
    to that message. The memory usage looks healthy, so SEGV isn't likely
    either.

    After saving the message and trimming it:

    $ gcc -o ./message ./message.c
    $ chmod 0755 ./message # should not be necessary
    $ ./message

    .... works ...
     
    jmcgill, Aug 29, 2006
    #5
  6. grinder

    grinder Guest

    so i am to understand that i do not have to change the scientific
    notation at all, and that C will understand the current syntax (in
    reguards to the last column).
     
    grinder, Aug 29, 2006
    #6
  7. grinder

    Ben Pfaff Guest

    "grinder" <> writes:

    > so i am to understand that i do not have to change the scientific
    > notation at all, and that C will understand the current syntax (in
    > reguards to the last column).


    Yes, C understands syntax like "0.5642E+02" as scientific notation.
    --
    "In My Egotistical Opinion, most people's C programs should be indented six
    feet downward and covered with dirt." -- Blair P. Houghton
     
    Ben Pfaff, Aug 29, 2006
    #7
  8. grinder

    Knemon Guest

    wrote:
    > hey knemon,
    >
    > when i compile it in gcc and try to execute it , it says
    > permission denied . Doesn't mean the code is accessing any unknown
    > address , it should throw SEGV or else what can be the problem ??


    You are invoking either the compiler or the program incorrectly.
     
    Knemon, Aug 29, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ville Ahonen

    No scientific notation?

    Ville Ahonen, Oct 19, 2004, in forum: C++
    Replies:
    2
    Views:
    458
    Mike Wahler
    Oct 19, 2004
  2. Dustan

    Scientific Notation

    Dustan, Dec 4, 2005, in forum: Python
    Replies:
    7
    Views:
    13,485
    Dustan
    Dec 4, 2005
  3. asdf
    Replies:
    2
    Views:
    569
    Rolf Magnus
    Oct 21, 2006
  4. N1GHTS

    Scientific Notation Conversion

    N1GHTS, Feb 20, 2008, in forum: C Programming
    Replies:
    1
    Views:
    583
    N1GHTS
    Feb 20, 2008
  5. Paul McNett

    Unexpected scientific notation

    Paul McNett, Jan 8, 2009, in forum: Python
    Replies:
    10
    Views:
    691
    Mark Dickinson
    Jan 9, 2009
Loading...

Share This Page