📄 dump.c
字号:
/*
* dump.c - routine to write a binary file of atom heights
! Format is the following: a header
fwrite(width,sizeof(int), 1, fp);
fwrite(length,sizeof(int), 1, fp);
fwrite(timeVal,sizeof(float), 1, fp);
! followed by the 'height' field (width x length)
fwrite(hfield,sizeof(unsigned char), gridSize, fp);
*/
#undef DUMPASCII
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
FILE *fp;
unsigned char *hfield;
struct timeval *tp;
struct timezone *tzp;
double prevTime = -1.0;
double thisTime,timeDel;
#define SECONDS(tv) ((double)((tv)->tv_sec) + (tv)->tv_usec / 1000000.0)
void dumpbinary_(int *firstFrame, char fname[20], int *totalNum, float *timeVal, int *width, int *length, int *height)
{
int idx,idy,k;
int gridSize, imin,imax;
printf("---- dump:\n");
/* printf("fname = %s\n",fname); */
printf("totalNum = %d\n",*totalNum);
printf("timeVal = %f\n",*timeVal);
printf("width = %d\n",*width);
printf("length = %d\n",*length);
/* for (idy=0; idy<50; idy++)
printf("height[i] = %d\n",height[idy]); */
if (*firstFrame) {
printf(" opening foo.bin...\n");
fp = fopen("foo.bin","w");
/* fp = fopen(fname,"w"); */
tp = (struct timeval *) malloc(sizeof(struct timeval));
tzp = (struct timezone *) malloc(sizeof(struct timezone));
}
/* fprintf(fp,"%d\n",*totalNum); */
/* fprintf(fp,"%d %d\n", *width, *length);
fprintf(fp,"%f\n",*timeVal); */
fwrite(width,sizeof(int), 1, fp);
fwrite(length,sizeof(int), 1, fp);
fwrite(timeVal,sizeof(float), 1, fp);
#ifdef DUMPASCII
for (idy=0; idy<*length; idy++) {
yoff = idy * *width;
for (idx=0; idx<*width; idx++) {
for (k=0; k<height[yoff + idx]; k++) {
if (k%2)
fprintf(fp,"FOO %f %f %d\n",(float)idx,(float)idy,k);
else
fprintf(fp,"FOO %f %f %d\n",(float)idx+0.5,(float)idy-0.5,k);
}
}
}
#endif
gridSize = *width * *length;
if (*firstFrame)
hfield = (unsigned char *) malloc(sizeof(unsigned char)*gridSize);
imin = 1000;
imax = -imin;
for (idx=0; idx<gridSize; idx++) {
hfield[idx] = height[idx];
if (hfield[idx] > imax) imax = hfield[idx];
if (hfield[idx] < imin) imin = hfield[idx];
}
printf("imin,imax = %d %d\n",imin,imax);
fwrite(hfield,sizeof(unsigned char), gridSize, fp);
fflush(fp);
gettimeofday(tp, tzp);
thisTime = SECONDS(tp);
printf("secs = %f\n",thisTime);
if (prevTime > 0.0) {
timeDel = thisTime - prevTime;
printf("elapsed time: %f secs, %f mins\n",timeDel,timeDel/60.0);
}
prevTime = thisTime;
/* fclose(fp); */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -