#include #include #define SUN #define U_CHAR 1 #define U_INT 2 #define U_FLOAT 3 char Revision[]={'1','.','1','1'}; main(argc, argv) int argc; char *argv[]; { char Rev[5]; int i, j, nsp, nnp, np[10]; float ftemp; short temp[10], temp1; FILE *DMPFile; float **x, **vx, **vy, **vz, t, sigma; float extq, extq_1, extq_2, extq_3, jwall[10]; /*********************************************************/ if(argc < 2) { puts("Must give 2 args."); exit(1); } if ((DMPFile = fopen(argv[1], "r+b")) == NULL) { puts("Conver: open failed on the first argument."); exit(1); } fread(Rev, sizeof(char), 4, DMPFile); for (i=0; i<4; i++) if (Rev[i]!=Revision[i]) { puts("Incompatible dump file version"); putchar(7); exit(1); } read_data(&t, 4, 1, DMPFile, U_FLOAT); read_data(&sigma, 4, 1, DMPFile, U_FLOAT); read_data(&extq, 4, 1, DMPFile, U_FLOAT); read_data(&extq_1, 4, 1, DMPFile, U_FLOAT); read_data(&extq_2, 4, 1, DMPFile, U_FLOAT); read_data(&extq_3, 4, 1, DMPFile, U_FLOAT); read_data(&nsp, 4, 1, DMPFile, U_INT); read_data(jwall, 4, nsp, DMPFile, U_FLOAT); read_data(np, 4, nsp, DMPFile, U_INT); /*********************************************************/ x = (float **)malloc(nsp*sizeof(float *)); vx = (float **)malloc(nsp*sizeof(float *)); vy = (float **)malloc(nsp*sizeof(float *)); vz = (float **)malloc(nsp*sizeof(float *)); for(i=0; i=0; i--) fread(ptr+j*size+i, 1, 1, stream); } /****************************************************************/ sun_write(ptr, size, nitems, stream) char *ptr; int size; int nitems; FILE *stream; { int i, j; for(j= 0; j =0; i--) fwrite(ptr+j*size+i, 1, 1, stream); } /****************************************************************/ #ifdef UNICOS unicos_read_float(ptr, nitems, stream) float *ptr; FILE *stream; int nitems; { unsigned long *iptr; unsigned char a,b,c,d,t; int j; for(j= 0; j > 7)); *iptr = ((a >> 7) << 63) | ((t -126 + 040000) << 48); *iptr |= (b | 0x80) << 40; *iptr |= c << 32; *iptr |= d << 24; } } } #endif /****************************************************************/ #ifdef UNICOS unicos_read_int(ptr, nitems, stream) int *ptr; FILE *stream; int nitems; { unsigned long *iptr; unsigned char a,b,c,d,t; int j; for(j= 0; j > 7) ? 0xffffffff00000000 : 0x0; } } #endif /****************************************************************/ #ifdef UNICOS unicos_write_float(ptr, nitems, stream) float *ptr; FILE *stream; int nitems; { unsigned long *iptr; unsigned char a,b,c,d,t; int j; for(j= 0; j > 48) & 0xff) - 040000 + 126; a = ((*iptr & (1 << 63)) ? 1 << 7 : 0) | t >> 1; b = (t & 0x1) << 7 | ((*iptr >> 40) & 0x7f); c = *iptr >> 32; d = *iptr >> 24; fwrite(&d,1,1,stream); fwrite(&c,1,1,stream); fwrite(&b,1,1,stream); fwrite(&a,1,1,stream); } } #endif /****************************************************************/ #ifdef UNICOS unicos_write_int(ptr, nitems, stream) int *ptr; FILE *stream; int nitems; { unsigned long *iptr; unsigned char a,b,c,d,t; int j; for(j= 0; j > 8 & 0xff; c = *iptr >> 16 & 0xff; d = *iptr >> 24 & 0xff; fwrite(&a,1,1,stream); fwrite(&b,1,1,stream); fwrite(&c,1,1,stream); fwrite(&d,1,1,stream); } } #endif /****************************************************************/ /* Heap sort */ sort(n, ra, rb, rc, rd) int n; float *ra, *rb, *rc, *rd; { int l, j, ir, i; float rra, rrb, rrc, rrd; l = (n >>1) +1; ir= n; for(;;) { if(l >1) { rra = ra[--l]; rrb = rb[l]; rrc = rc[l]; rrd = rd[l]; } else { rra = ra[ir]; rrb = rb[ir]; rrc = rc[ir]; rrd = rd[ir]; ra[ir]= ra[1]; rb[ir]= rb[1]; rc[ir]= rc[1]; rd[ir]= rd[1]; if(--ir == 1) { ra[1] = rra; rb[1] = rrb; rc[1] = rrc; rd[1] = rrd; return; } } i=l; j= l << 1; while(j <= ir) { if(j < ir && ra[j] < ra[j+1]) ++j; if(rra