473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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",beta,(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?

Jun 27 '08 #1
18 2661
Jordan Glassman <jo************@gmail.comwrites:
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",beta,(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.programmer might be better.

--
Ben.
Jun 27 '08 #2
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.programmer 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
Jun 27 '08 #3
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
Jun 27 '08 #4
>
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(int (*m)[N]);
void ising(int (*m)[N],double beta);

int main(){

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

seed();

for(beta=0.5;beta<=1.2;beta+=0.01){

filllattice(lattice);

// clear();

// printlattice(lattice);

ising(lattice,beta);

}

return 0;

}

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

int i,j;

for(i=0;i<N;i++){
for(j=0;j<N;j++){
if((((float)rand()/(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(timestr,3,"%S",mt);

srand(atoi(timestr));

}

void printlattice(int (*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,summe2,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=summe2=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<NITERS;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",beta,(energy/
n2),(moment/n2),(summe2-summe*summe)/n2,(summm2-summm*summm)/n2);

}

Jun 27 '08 #5
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)rand()/(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
Jun 27 '08 #6
Jordan Glassman <jo************@gmail.comwrites:
>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.programmer 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(timestr,3,"%S",mt);

srand(atoi(timestr));

}
The comp.lang.c FAQ has some advice seeding rand().
http://c-faq.com/lib/srand.html
void printlattice(int (*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,summe2,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=summe2=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<NITERS;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",beta,(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.
Jun 27 '08 #7
Ben Bacarisse <be********@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.programmer if you must!

--
Ben.
Jun 27 '08 #8
[Other replies notwithstanding...]

Jordan Glassman wrote:
#define NITERS 5000000
int i,j,k;
for(k=0;k<NITERS;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
Jun 27 '08 #9
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.comwrites:
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.programmer 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(timestr,3,"%S",mt);
srand(atoi(timestr));
}

The comp.lang.c FAQ has some advice seeding rand().http://c-faq.com/lib/srand.html
void printlattice(int (*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,summe2,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=summe2=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<NITERS;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",beta,(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.
Jun 27 '08 #10
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.comwrites:
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.programmer 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(timestr,3,"%S",mt);
srand(atoi(timestr));
}

The comp.lang.c FAQ has some advice seeding rand().http://c-faq.com/lib/srand.html
void printlattice(int (*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,summe2,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=summe2=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<NITERS;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",beta,(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.
Jun 27 '08 #11
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>
Jun 27 '08 #12
Please don't top-post.

Lesson learned...

Jun 27 '08 #13
Jordan Glassman wrote:
Please don't top-post.

Lesson learned...
Thanks!


Brian
Jun 27 '08 #14
On May 13, 5:03 am, Richard Heathfield <r...@see.sig.invalidwrote:
Jordan Glassman said:
if((((float)rand()/(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
Jun 27 '08 #15
In article <a9**********************************@2g2000hsn.go oglegroups.com>,
viza <to******@gmail.comwrote:
>On May 13, 5:03 am, Richard Heathfield <r...@see.sig.invalidwrote:
>Jordan Glassman said:
if((((float)rand()/(float)RAND_MAX)) 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.
The low bit of rand() is often not very random at all -- often alternating
between 0 and 1 each time. It's a problem with linear congruential
pseudo-random numbers, at least if you take the bottom bits of the
new seed as being the random value. (Some implementations make sure
they never output the bottom bits to reduce this problem, but
C doesn't make any such promises.)
--
"Man's life is but a jest,
A dream, a shadow, bubble, air, a vapor at the best."
-- George Walter Thornbury
Jun 27 '08 #16
In article <g0**********@canopus.cc.umanitoba.ca>,
Walter Roberson <ro******@ibd.nrc-cnrc.gc.cawrote:
>The low bit of rand() is often not very random at all -- often alternating
between 0 and 1 each time.
This used to be true, 20-something years ago. Surely modern
implementations don't have the same problem?

-- Richard
--
:wq
Jun 27 '08 #17
In article <g0***********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>In article <g0**********@canopus.cc.umanitoba.ca>,
Walter Roberson <ro******@ibd.nrc-cnrc.gc.cawrote:
>>The low bit of rand() is often not very random at all -- often alternating
between 0 and 1 each time.
>This used to be true, 20-something years ago. Surely modern
implementations don't have the same problem?
Remember, the C89 standard was 20-something years ago, but conforming
more modern implementations (C99) are still pretty uncommon ;-)

To be fair: the C89 sample implementation works with an
unsigned long int seed, and the value returned is divided by 64K and
is mod 32768 (e.g., shift right 16 bits and mask out all but the
bottom 15 bits). With that sample algorithm, the bottom bit of rand()
should have a cycle of 64K (which would, I -suspect-, be composed
of two half-cycles of 32K each, bitwise negations of each other.)
--
"The shallow murmur, but the deep are dumb." -- Sir Walter Raleigh
Jun 27 '08 #18
produces a blinking cursor, an empty file named "output," and a
program that runs forever. *With no redirect, the output is normal.
As I see your problem has been solved. I got similar behaviour
when I did not wait for the program to completely finish.
Without redirection I saw the results immediately, but
redirection sometimes implies a buffering and the buffer
is lost if the program terminates abnormally.
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",beta,(energy/n2),(moment/n2), \
(summe2-summe*summe)/n2, \
(summm2-summm*summm)/n2);
Sorry for this remark, but, this last lines made me
suspicious: This is a 2dimensional ising model,
Cv is the specific heat, which is the energy density fluctuation,
so I expect a standard deviation there.
Don't you then miss an other 1/n2 no normalise summe and summm?
I can be completely wrong, but you might want to check this.

Szabolcs
Jun 27 '08 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
3
by: legba | last post by:
hi all.. I'm writing an application in python2.3 under linux debian which accepts new "plug-ins" in the form of c-written python extension modules. My problem is that I'd like to catch the...
10
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally...
2
by: 28tommy | last post by:
Hi there, I'm doing some TELNET and FTP sessions with my scripts. I need to redirect all the output (and not just what I print) to an output file, but still be able to see the session in process...
1
by: abcd | last post by:
I have a program which is written in C and interfaced with python via Swig. However, the function I call prints stuff out to the console. I would like to capture what it is printing out. I...
3
by: mikem76 | last post by:
How do I automatically redirect stdout and stderr when using os.popen2 to start a long running process. If the process prints a lot of stuff to stdout it will eventually stop because it runs out...
6
by: cmk128 | last post by:
Hi here is my c file, compile in gcc 3.X in linux: #include <stdio.h> int main() { printf("Hello\n"); if (fork() == 0) printf("world! \n"); }
5
by: ws.taylor | last post by:
I am in a systems programming class, using C on a Solaris 10 development server. Part of the first programming assignment calls for the output of a command executed by a child process with execvp...
3
by: Alejandro | last post by:
Hi: I want to redirect stdout to a textctrl I have. From what I read in the wxpython documentation, I can use the wxLogTextCtrl class to do this. I am doing the following: class...
10
by: Jef Driesen | last post by:
I wrote a program that writes a large amount of information to stdout (and stderr). When run from the commandline, this output either appears on the console window (the default) or can be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.