Redirect to STDOUT Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordan Glassman

    Redirect to STDOUT Problem

    Trying to do something fairly routine... drop output into a file to
    graph, but the following command at the bash command line:

    ising output

    produces a blinking cursor, an empty file named "output," and a
    program that runs forever. With no redirect, the output is normal.
    Below is the printf statement used to generate output.

    printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f \
    Chi=%5.2f\n",be ta,(energy/n2),(moment/n2), \
    (summe2-summe*summe)/n2, \
    (summm2-summm*summm)/n2);

    I verified that things like 'ls output' work fine, and that I can
    also redirect output from other c programs I've written. Something is
    funny about this one.

    Any thoughts?



  • Ben Bacarisse

    #2
    Re: Redirect to STDOUT Problem

    Jordan Glassman <jordanglassman @gmail.comwrite s:
    Trying to do something fairly routine... drop output into a file to
    graph, but the following command at the bash command line:
    >
    ising output
    On modern systems, . is often not in your path. Did you just forget
    to type ./ising?
    produces a blinking cursor, an empty file named "output," and a
    program that runs forever. With no redirect, the output is normal.
    Below is the printf statement used to generate output.
    >
    printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f \
    Chi=%5.2f\n",be ta,(energy/n2),(moment/n2), \
    (summe2-summe*summe)/n2, \
    (summm2-summm*summm)/n2);
    Nothing here can explain what is happening. The printf is correct.
    Of course, if n2 == 0 you won't get any output but that will happen
    with and without the redirect.
    I verified that things like 'ls output' work fine, and that I can
    also redirect output from other c programs I've written. Something is
    funny about this one.
    >
    Any thoughts?
    The problem is probably not in the C code. You need someone to watch
    exactly what you are doing and they'll probably spot it in no time. I
    think a group like comp.unix.progr ammer might be better.

    --
    Ben.

    Comment

    • Jordan Glassman

      #3
      Re: Redirect to STDOUT Problem

      Ben,

      Thanks for the reply...
      On modern systems, . is often not in your path. Did you just forget
      to type ./ising?
      No, that's not the problem.
      Nothing here can explain what is happening. The printf is correct.
      Of course, if n2 == 0 you won't get any output but that will happen
      with and without the redirect.
      >
      The problem is probably not in the C code. You need someone to watch
      exactly what you are doing and they'll probably spot it in no time. I
      think a group like comp.unix.progr ammer might be better.
      I tend to agree, but since *everything else* works except this
      particular c program, which contains nothing more than a few
      calculations inside loops and this one output statement, I decided to
      post here first.

      -j

      Comment

      • Peter Nilsson

        #4
        Re: Redirect to STDOUT Problem

        Jordan Glassman wrote:
        ...
        I tend to agree, but since *everything else* works except this
        particular c program, which contains nothing more than a few
        calculations inside loops and this one output statement, I
        decided to post here first.
        Though for some reason you decided not to post the code.
        Still, your loss...

        --
        Peter

        Comment

        • Jordan Glassman

          #5
          Re: Redirect to STDOUT Problem

          >
          Though for some reason you decided not to post the code.
          Still, your loss...
          >
          My loss? Here it is...

          #include <stdio.h>
          #include <stdlib.h>
          #include <time.h>
          #include <math.h>
          #include <curses.h>

          #include <unistd.h// ANSI C???

          #define N 40
          #define NITERS 5000000

          void filllattice(int (*m)[N]);
          void seed(void); /* bad bad bad */
          void printlattice(in t (*m)[N]);
          void ising(int (*m)[N],double beta);

          int main(){

          int lattice[N][N];
          double beta=0.0;

          seed();

          for(beta=0.5;be ta<=1.2;beta+=0 .01){

          filllattice(lat tice);

          // clear();

          // printlattice(la ttice);

          ising(lattice,b eta);

          }

          return 0;

          }

          void filllattice(int (*m)[N]){

          int i,j;

          for(i=0;i<N;i++ ){
          for(j=0;j<N;j++ ){
          if((((float)ran d()/(float)RAND_MAX )) 0.5) m[i][j]= 1;
          else m[i][j] = -1;
          }
          }

          }

          void seed(void){

          struct tm *mt;
          int i;
          time_t t;
          char timestr[3];

          t=time(NULL);
          mt=localtime(&t );
          strftime(timest r,3,"%S",mt);

          srand(atoi(time str));

          }

          void printlattice(in t (*m)[N]){

          int i,j;

          /* system("clear") ; */
          move(0,0);

          for(i=0;i<N;i++ ){
          putchar('\n');
          for(j=0;j<N;j++ ){
          if(m[i][j]==1)printf(" 1");
          else printf(" -1");
          }
          }

          putchar('\n');
          }

          void ising(int (*m)[N],double beta){

          int i,j,k;
          double energy,moment;
          double summe,summm,sum me2,summm2;
          int numsteps=0;
          double sum_nn,sums;
          double deltaH;
          double sum_nnn;
          int n2=N*N;
          double half=NITERS/2;

          k=0;

          energy=moment=0 .0;
          summe=summm=sum me2=summm2=0.0;

          // pick a site randomly

          for(i=0;i<N;i++ ){
          for(j=0;j<N;j++ ){
          moment += m[i][j];
          energy -= 2*m[i][j]*(m[(i+1)%N][j]+m[i][(j+1)%N]+m[(i+1)%N][(j
          +1)%N]/5);
          }
          }

          for(k=0;k<NITER S;k++){

          i=rand()%N;
          j=rand()%N;

          sum_nn=m[i][((j+1)%N)]+m[i][((j-1+N)%N)]+m[((i+1)%N)][j]+m[((i-1+N)
          %N)][j];
          sum_nnn=(m[((i+1)%N)][((j+1)%N)]+m[((i-1+N)%N)][((j-1+N)%N)]
          +m[((i-1+N)%N)][((j+1)%N)]+m[((i+1)%N)][((j-1+N)%N)])/5;
          sums=sum_nn+sum _nnn;
          deltaH=m[i][j]*sums;
          if((exp(-1.3*deltaH*beta ))>((float)rand ()/(float)RAND_MAX ) ||
          (deltaH < 0) ){
          energy += 2*deltaH;
          moment -= 2*m[i][j];
          m[i][j] *= -1;
          }

          if(k>half){
          summe+=energy;
          summe2+=energy* energy;
          summm+=moment;
          summm2+=moment* moment;
          }

          /* if(k>10000){
          k=0;
          putchar('\n');
          printf("E=%f m=%f",(energy/n2),(moment/n2));
          printlattice(m) ;
          sleep(1);
          } */

          }

          summe /= half;
          summe2 /= half;
          summm /= half;
          summm2 /= half;

          printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f Chi=%5.2f\n",be ta,(energy/
          n2),(moment/n2),(summe2-summe*summe)/n2,(summm2-summm*summm)/n2);

          }



          Comment

          • Richard Heathfield

            #6
            Re: Redirect to STDOUT Problem

            Jordan Glassman said:
            >>
            >Though for some reason you decided not to post the code.
            >[...]
            [...] Here it is...
            >
            #include <stdio.h>
            #include <stdlib.h>
            #include <time.h>
            #include <math.h>
            #include <curses.h>
            >
            #include <unistd.h// ANSI C???
            This // comment really screwed up my compiler. To answer your question
            redoubled in spades, neither curses.h nor unistd.h are ANSI C. // comments
            have become so officially (since 1999), but in practice almost nobody has
            a compiler that conforms to C99 in *every* respect, so those of us who
            prefer to use a conforming mode have no choice but to conform to an
            earlier standard (C90 or C95), in which // is merely a syntax error. In
            this case, my compiler saw // ANSI C??? as part of the filename to
            include!

            Anyway, that's easy enough to fix (I removed the comment!), but doing so
            exposed a whole bunch of compilation issues with your code - dozens of
            errors. Oddly, however, removing or replacing the remaining // comments
            sorted most of these out. The remaining nits were:
            int main(){
            My compiler (rightly) prefers int main(void) rather than just int main(),
            but really this is no big deal. You have the return type (int) exactly
            right, and that's what matters here.
            if((((float)ran d()/(float)RAND_MAX )) 0.5)
            The compiler says: "warning: cast does not match function type"

            In almost all cases, a cast on a human being indicates a broken limb.
            In almost all cases, a cast in a C program indicates a broken line.

            In C, the normal way to do (pseudo) random numbers selected from N
            possibilities (in the range 0 to N-1) is to get a value in the half-open
            range [0, 1) like this:

            rand() / (RAND_MAX + 1.0)

            and then multiply by N to get a value in the half-open range [0, N).
            It seems that you want a value in the half-open range [0, 1) so you can
            omit the multiplication step:

            if(rand() / (RAND_MAX + 1.0) 0.5)

            (This happens in one other place in the code, too.)

            Running this code gives me a bunch of results as follows:

            B=0.50 E= -0.8500 m= -0.0325 Cv= 3.52 Chi= 9.21
            B=0.51 E= -0.8225 m= 0.1338 Cv= 3.42 Chi=10.27
            B=0.52 E= -0.8500 m= -0.1550 Cv= 3.65 Chi=13.73
            B=0.53 E= -0.8100 m= 0.0325 Cv= 3.69 Chi=16.82
            B=0.54 E= -0.8975 m= 0.0488 Cv= 3.72 Chi=13.67
            B=0.55 E= -0.9200 m= -0.0088 Cv= 4.08 Chi=20.47
            B=0.56 E= -0.9975 m= 0.0563 Cv= 4.18 Chi=19.43
            B=0.57 E= -0.9525 m= 0.0125 Cv= 4.59 Chi=34.67
            B=0.58 E= -1.1075 m= -0.1938 Cv= 4.12 Chi=22.44
            B=0.59 E= -1.0425 m= 0.1288 Cv= 4.83 Chi=30.55
            B=0.60 E= -1.0675 m= -0.1750 Cv= 5.23 Chi=38.14
            B=0.61 E= -1.0475 m= -0.0775 Cv= 5.36 Chi=55.96
            B=0.62 E= -1.1625 m= 0.2350 Cv= 4.85 Chi=87.07
            B=0.63 E= -1.1850 m= -0.0050 Cv= 6.26 Chi=127.39

            but it didn't appear to stop. I reduced NITERS from 5000000 to 5 and N from
            40 to 4, and it worked just fine, producing 70 lines of output.
            Redirection of stdout to a file named 'output' worked just fine with no
            weirdities going on. Looks fine to me.

            --
            Richard Heathfield <http://www.cpax.org.uk >
            Email: -http://www. +rjh@
            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
            "Usenet is a strange place" - dmr 29 July 1999

            Comment

            • Ben Bacarisse

              #7
              Re: Redirect to STDOUT Problem

              Jordan Glassman <jordanglassman @gmail.comwrite s:
              >Though for some reason you decided not to post the code.
              >Still, your loss...
              >>
              >
              My loss? Here it is...
              Yes. I can now tell you how to get it to work (but
              comp.unix.progr ammer is still the better place).
              #include <stdio.h>
              #include <stdlib.h>
              #include <time.h>
              #include <math.h>
              #include <curses.h>
              curses programs can't usually have their put redirected (ask in
              c.u.p for when and why).
              #include <unistd.h// ANSI C???
              No, not ANSI C.

              <snip>
              void seed(void){
              >
              struct tm *mt;
              int i;
              time_t t;
              char timestr[3];
              >
              t=time(NULL);
              mt=localtime(&t );
              strftime(timest r,3,"%S",mt);
              >
              srand(atoi(time str));
              >
              }
              The comp.lang.c FAQ has some advice seeding rand().

              void printlattice(in t (*m)[N]){
              >
              int i,j;
              >
              /* system("clear") ; */
              move(0,0);
              Comment this out. You don't need the curses functionality (at least
              not yet). If you do more with it in future versions, it may be worth
              the price of losing output re-direction.
              for(i=0;i<N;i++ ){
              putchar('\n');
              for(j=0;j<N;j++ ){
              if(m[i][j]==1)printf(" 1");
              else printf(" -1");
              }
              }
              >
              putchar('\n');
              }
              >
              void ising(int (*m)[N],double beta){
              >
              int i,j,k;
              double energy,moment;
              double summe,summm,sum me2,summm2;
              int numsteps=0;
              double sum_nn,sums;
              double deltaH;
              double sum_nnn;
              int n2=N*N;
              double half=NITERS/2;
              >
              k=0;
              >
              energy=moment=0 .0;
              summe=summm=sum me2=summm2=0.0;
              >
              // pick a site randomly
              >
              for(i=0;i<N;i++ ){
              for(j=0;j<N;j++ ){
              moment += m[i][j];
              energy -= 2*m[i][j]*(m[(i+1)%N][j]+m[i][(j+1)%N]+m[(i+1)%N][(j
              +1)%N]/5);
              }
              }
              >
              for(k=0;k<NITER S;k++){
              >
              i=rand()%N;
              j=rand()%N;
              >
              sum_nn=m[i][((j+1)%N)]+m[i][((j-1+N)%N)]+m[((i+1)%N)][j]+m[((i-1+N)
              %N)][j];
              sum_nnn=(m[((i+1)%N)][((j+1)%N)]+m[((i-1+N)%N)][((j-1+N)%N)]
              +m[((i-1+N)%N)][((j+1)%N)]+m[((i+1)%N)][((j-1+N)%N)])/5;
              sums=sum_nn+sum _nnn;
              deltaH=m[i][j]*sums;
              if((exp(-1.3*deltaH*beta ))>((float)rand ()/(float)RAND_MAX ) ||
              (deltaH < 0) ){
              energy += 2*deltaH;
              moment -= 2*m[i][j];
              m[i][j] *= -1;
              }
              >
              if(k>half){
              summe+=energy;
              summe2+=energy* energy;
              summm+=moment;
              summm2+=moment* moment;
              }
              >
              /* if(k>10000){
              k=0;
              putchar('\n');
              printf("E=%f m=%f",(energy/n2),(moment/n2));
              printlattice(m) ;
              sleep(1);
              } */
              >
              }
              >
              summe /= half;
              summe2 /= half;
              summm /= half;
              summm2 /= half;
              >
              printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f Chi=%5.2f\n",be ta,(energy/
              n2),(moment/n2),(summe2-summe*summe)/n2,(summm2-summm*summm)/n2);
              Add:

              fflush(stdout);

              to be sure to get what data you have written so far. I did not wait for
              the program to finish -- if you do there is no need to call fflush.

              --
              Ben.

              Comment

              • Ben Bacarisse

                #8
                Re: Redirect to STDOUT Problem

                Ben Bacarisse <ben.usenet@bsb .me.ukwrites:
                curses programs can't usually have their put redirected (ask in
                c.u.p for when and why).
                Oh the perils of off-topic answers. Please don't get into this here.
                I know it is wrong -- I was over-simplifying to the point of being
                plain wrong. Berate me in comp.unix.progr ammer if you must!

                --
                Ben.

                Comment

                • Peter Nilsson

                  #9
                  Re: Redirect to STDOUT Problem

                  [Other replies notwithstanding ...]

                  Jordan Glassman wrote:
                  #define NITERS 5000000
                  int i,j,k;
                  for(k=0;k<NITER S;k++){
                  Are you perchance running on a machine with 16-bit ints?

                  If so, this loop will likely run forever (assuming 16-bit overflow
                  from INT_MAX to INT_MIN.)
                  void ising(int (*m)[N],double beta){
                  Identifiers starting with is (or to) and a lowercase letter are
                  reserved for use as external identifiers.

                  This is not likely to be the source of your problem, but it is
                  still a fault with your code.

                  Apart from that, the program does take some time to run.
                  Are you leaving it for long enough? With such relatively
                  small output, many systems won't actually flush to the
                  redirected file until the program (and stream) closes.

                  --
                  Peter

                  Comment

                  • Jordan Glassman

                    #10
                    Re: Redirect to STDOUT Problem

                    Ben,

                    Taking out the curses.h and all associated functions did it. I'm
                    still not sure why the printf didn't work, though... not of the
                    curses.h functions were actually being used in that code I posted...
                    they were all commented out! It's as if curses replaces printf with
                    another version.

                    Dunno. In any case, thanks for the help.

                    -j

                    On May 12, 9:01 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
                    Jordan Glassman <jordanglass... @gmail.comwrite s:
                    Though for some reason you decided not to post the code.
                    Still, your loss...
                    >
                    My loss? Here it is...
                    >
                    Yes. I can now tell you how to get it to work (but
                    comp.unix.progr ammer is still the better place).
                    >
                    #include <stdio.h>
                    #include <stdlib.h>
                    #include <time.h>
                    #include <math.h>
                    #include <curses.h>
                    >
                    curses programs can't usually have their put redirected (ask in
                    c.u.p for when and why).
                    >
                    #include <unistd.h// ANSI C???
                    >
                    No, not ANSI C.
                    >
                    <snip>
                    >
                    void seed(void){
                    >
                    struct tm *mt;
                    int i;
                    time_t t;
                    char timestr[3];
                    >
                    t=time(NULL);
                    mt=localtime(&t );
                    strftime(timest r,3,"%S",mt);
                    >
                    srand(atoi(time str));
                    >
                    }
                    >
                    The comp.lang.c FAQ has some advice seeding rand().http://c-faq.com/lib/srand.html
                    >
                    void printlattice(in t (*m)[N]){
                    >
                    int i,j;
                    >
                    /* system("clear") ; */
                    move(0,0);
                    >
                    Comment this out. You don't need the curses functionality (at least
                    not yet). If you do more with it in future versions, it may be worth
                    the price of losing output re-direction.
                    >
                    >
                    >
                    for(i=0;i<N;i++ ){
                    putchar('\n');
                    for(j=0;j<N;j++ ){
                    if(m[i][j]==1)printf(" 1");
                    else printf(" -1");
                    }
                    }
                    >
                    putchar('\n');
                    }
                    >
                    void ising(int (*m)[N],double beta){
                    >
                    int i,j,k;
                    double energy,moment;
                    double summe,summm,sum me2,summm2;
                    int numsteps=0;
                    double sum_nn,sums;
                    double deltaH;
                    double sum_nnn;
                    int n2=N*N;
                    double half=NITERS/2;
                    >
                    k=0;
                    >
                    energy=moment=0 .0;
                    summe=summm=sum me2=summm2=0.0;
                    >
                    // pick a site randomly
                    >
                    for(i=0;i<N;i++ ){
                    for(j=0;j<N;j++ ){
                    moment += m[i][j];
                    energy -= 2*m[i][j]*(m[(i+1)%N][j]+m[i][(j+1)%N]+m[(i+1)%N][(j
                    +1)%N]/5);
                    }
                    }
                    >
                    for(k=0;k<NITER S;k++){
                    >
                    i=rand()%N;
                    j=rand()%N;
                    >
                    sum_nn=m[i][((j+1)%N)]+m[i][((j-1+N)%N)]+m[((i+1)%N)][j]+m[((i-1+N)
                    %N)][j];
                    sum_nnn=(m[((i+1)%N)][((j+1)%N)]+m[((i-1+N)%N)][((j-1+N)%N)]
                    +m[((i-1+N)%N)][((j+1)%N)]+m[((i+1)%N)][((j-1+N)%N)])/5;
                    sums=sum_nn+sum _nnn;
                    deltaH=m[i][j]*sums;
                    if((exp(-1.3*deltaH*beta ))>((float)rand ()/(float)RAND_MAX ) ||
                    (deltaH < 0) ){
                    energy += 2*deltaH;
                    moment -= 2*m[i][j];
                    m[i][j] *= -1;
                    }
                    >
                    if(k>half){
                    summe+=energy;
                    summe2+=energy* energy;
                    summm+=moment;
                    summm2+=moment* moment;
                    }
                    >
                    /* if(k>10000){
                    k=0;
                    putchar('\n');
                    printf("E=%f m=%f",(energy/n2),(moment/n2));
                    printlattice(m) ;
                    sleep(1);
                    } */
                    >
                    }
                    >
                    summe /= half;
                    summe2 /= half;
                    summm /= half;
                    summm2 /= half;
                    >
                    printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f Chi=%5.2f\n",be ta,(energy/
                    n2),(moment/n2),(summe2-summe*summe)/n2,(summm2-summm*summm)/n2);
                    >
                    Add:
                    >
                    fflush(stdout);
                    >
                    to be sure to get what data you have written so far. I did not wait for
                    the program to finish -- if you do there is no need to call fflush.
                    >
                    --
                    Ben.

                    Comment

                    • Jordan Glassman

                      #11
                      Re: Redirect to STDOUT Problem

                      Ben,

                      Taking out the curses.h and all associated functions did it. I'm
                      still not sure why the printf didn't work, though... not of the
                      curses.h functions were actually being used in that code I posted...
                      they were all commented out! It's as if curses replaces printf with
                      another version.

                      Dunno. In any case, thanks for the help.

                      -j

                      On May 12, 9:01 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
                      Jordan Glassman <jordanglass... @gmail.comwrite s:
                      Though for some reason you decided not to post the code.
                      Still, your loss...
                      >
                      My loss? Here it is...
                      >
                      Yes. I can now tell you how to get it to work (but
                      comp.unix.progr ammer is still the better place).
                      >
                      #include <stdio.h>
                      #include <stdlib.h>
                      #include <time.h>
                      #include <math.h>
                      #include <curses.h>
                      >
                      curses programs can't usually have their put redirected (ask in
                      c.u.p for when and why).
                      >
                      #include <unistd.h// ANSI C???
                      >
                      No, not ANSI C.
                      >
                      <snip>
                      >
                      void seed(void){
                      >
                      struct tm *mt;
                      int i;
                      time_t t;
                      char timestr[3];
                      >
                      t=time(NULL);
                      mt=localtime(&t );
                      strftime(timest r,3,"%S",mt);
                      >
                      srand(atoi(time str));
                      >
                      }
                      >
                      The comp.lang.c FAQ has some advice seeding rand().http://c-faq.com/lib/srand.html
                      >
                      void printlattice(in t (*m)[N]){
                      >
                      int i,j;
                      >
                      /* system("clear") ; */
                      move(0,0);
                      >
                      Comment this out. You don't need the curses functionality (at least
                      not yet). If you do more with it in future versions, it may be worth
                      the price of losing output re-direction.
                      >
                      >
                      >
                      for(i=0;i<N;i++ ){
                      putchar('\n');
                      for(j=0;j<N;j++ ){
                      if(m[i][j]==1)printf(" 1");
                      else printf(" -1");
                      }
                      }
                      >
                      putchar('\n');
                      }
                      >
                      void ising(int (*m)[N],double beta){
                      >
                      int i,j,k;
                      double energy,moment;
                      double summe,summm,sum me2,summm2;
                      int numsteps=0;
                      double sum_nn,sums;
                      double deltaH;
                      double sum_nnn;
                      int n2=N*N;
                      double half=NITERS/2;
                      >
                      k=0;
                      >
                      energy=moment=0 .0;
                      summe=summm=sum me2=summm2=0.0;
                      >
                      // pick a site randomly
                      >
                      for(i=0;i<N;i++ ){
                      for(j=0;j<N;j++ ){
                      moment += m[i][j];
                      energy -= 2*m[i][j]*(m[(i+1)%N][j]+m[i][(j+1)%N]+m[(i+1)%N][(j
                      +1)%N]/5);
                      }
                      }
                      >
                      for(k=0;k<NITER S;k++){
                      >
                      i=rand()%N;
                      j=rand()%N;
                      >
                      sum_nn=m[i][((j+1)%N)]+m[i][((j-1+N)%N)]+m[((i+1)%N)][j]+m[((i-1+N)
                      %N)][j];
                      sum_nnn=(m[((i+1)%N)][((j+1)%N)]+m[((i-1+N)%N)][((j-1+N)%N)]
                      +m[((i-1+N)%N)][((j+1)%N)]+m[((i+1)%N)][((j-1+N)%N)])/5;
                      sums=sum_nn+sum _nnn;
                      deltaH=m[i][j]*sums;
                      if((exp(-1.3*deltaH*beta ))>((float)rand ()/(float)RAND_MAX ) ||
                      (deltaH < 0) ){
                      energy += 2*deltaH;
                      moment -= 2*m[i][j];
                      m[i][j] *= -1;
                      }
                      >
                      if(k>half){
                      summe+=energy;
                      summe2+=energy* energy;
                      summm+=moment;
                      summm2+=moment* moment;
                      }
                      >
                      /* if(k>10000){
                      k=0;
                      putchar('\n');
                      printf("E=%f m=%f",(energy/n2),(moment/n2));
                      printlattice(m) ;
                      sleep(1);
                      } */
                      >
                      }
                      >
                      summe /= half;
                      summe2 /= half;
                      summm /= half;
                      summm2 /= half;
                      >
                      printf("B=%4.2f E=%8.4f m=%8.4f Cv=%5.2f Chi=%5.2f\n",be ta,(energy/
                      n2),(moment/n2),(summe2-summe*summe)/n2,(summm2-summm*summm)/n2);
                      >
                      Add:
                      >
                      fflush(stdout);
                      >
                      to be sure to get what data you have written so far. I did not wait for
                      the program to finish -- if you do there is no need to call fflush.
                      >
                      --
                      Ben.

                      Comment

                      • Default User

                        #12
                        Re: Redirect to STDOUT Problem - TPA

                        Jordan Glassman wrote:
                        Ben,

                        Please don't top-post. Your replies belong following or interspersed
                        with properly trimmed quotes. See the majority of other posts in the
                        newsgroup, or:
                        <http://www.caliburn.nl/topposting.html >

                        Comment

                        • Jordan Glassman

                          #13
                          Re: Redirect to STDOUT Problem - TPA

                          Please don't top-post.

                          Lesson learned...

                          Comment

                          • Default User

                            #14
                            Re: Redirect to STDOUT Problem - TPA

                            Jordan Glassman wrote:
                            Please don't top-post.
                            >
                            Lesson learned...
                            Thanks!




                            Brian

                            Comment

                            • viza

                              #15
                              Re: Redirect to STDOUT Problem

                              On May 13, 5:03 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                              Jordan Glassman said:
                              if((((float)ran d()/(float)RAND_MAX )) 0.5)
                              >
                              In C, the normal way to do (pseudo) random numbers selected from N
                              possibilities (in the range 0 to N-1) is to get a value in the half-open
                              range [0, 1) like this:
                              >
                              rand() / (RAND_MAX + 1.0)
                              >
                              and then multiply by N to get a value in the half-open range [0, N).
                              It seems that you want a value in the half-open range [0, 1) so you can
                              omit the multiplication step:
                              >
                              if(rand() / (RAND_MAX + 1.0) 0.5)
                              In this case, why not just use:

                              if( rand() & 1 )

                              If RAND_MAX is odd (which it usually is) then this is perfect, and
                              doesn't need an FPU.

                              If RAND_MAX is even, then it gets very close to perfect as long as
                              RAND_MAX is large. Remember that the float method isn't perfect
                              either.

                              If your rand() isn't evenly distributed, then you are screwed whatever
                              you do.

                              viza

                              Comment

                              Working...