# my binary file is imported into paraview, it crashes,

**URL:** https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472
**Category:** ParaView Support
**Created:** [April 20, 2022, 10:59am UTC](https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472 "2022-04-20T10:59:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![wu\_ying](https://discourse.paraview.org/user_avatar/discourse.paraview.org/wu_ying/32/9035_2.png) [@wu\_ying](https://discourse.paraview.org/u/wu_ying)
#### Post date: [April 20, 2022, 10:59am UTC](https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472/1 "2022-04-20T10:59:59Z")

</div>

Hello, help, my binary file is imported into paraview, it crashes,

```
FILE* fp;  
char filename[1024];

cols = 10;
int num_nodes = 1, list_nodes = 1, cell_type = 1;

for (i = 0; i < nn; i++) {
	sprintf(filename, "c:\\00yf\\dh_v\\bin-time%d.vtk", i);
	fp = fopen(filename, "wb");

	if (fp == NULL) {
		printf("File open error!\n");
		return 0; //等价退出
	}
	else
	{
		fprintf(fp, "# vtk DataFile Version 3.0\n");  
		fprintf(fp, "points cloud\n");
		fprintf(fp, "BINARY\n");
		fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");

		fprintf(fp, "POINTS	%d float\n", cols);			
		for (j = 0; j < cols; j++) {
			fwrite(&xx[i * cols + j], sizeof(float), 1, fp);		
			fwrite(&yy[i * cols + j], sizeof(float), 1, fp);
			fwrite(&zz[i * cols + j], sizeof(float), 1, fp);
		}

		fprintf(fp, "\nCELLS %d %d\n",cols,cols*2);
		for (j = 0; j < cols; j++) {
			fwrite(&num_nodes, sizeof(int), 1, fp);
			fwrite(&j, sizeof(int), 1, fp);				
		}

		fprintf(fp, "\nCELL_TYPES %d\n",cols);	

		for (j = 0; j < cols; j++) {
			fwrite(&cell_type, sizeof(int), 1, fp);					
		}

	}
}
```

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [April 20, 2022, 11:33pm UTC](https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472/2 "2022-04-20T23:33:25Z")

</div>

The binary format of the legacy VTK file must be big-endian, so the endianness must be swapped.

---

<div class="post-metadata">

### Author: ![wu\_ying](https://discourse.paraview.org/user_avatar/discourse.paraview.org/wu_ying/32/9035_2.png) [@wu\_ying](https://discourse.paraview.org/u/wu_ying)
#### Post date: [April 21, 2022, 3:49am UTC](https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472/3 "2022-04-21T03:49:29Z")

</div>

Thank you for your reply, which version of the binary is written in little endian, I am writing binary in C language, the default is little endian, how should I rewrite it?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [April 21, 2022, 4:33am UTC](https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472/4 "2022-04-21T04:33:13Z")

</div>

Would you refer to the following link?

> <https://stackoverflow.com/questions/10913666/error-writing-binary-vtk-files>

---

<div class="post-metadata">

### Author: ![wu\_ying](https://discourse.paraview.org/user_avatar/discourse.paraview.org/wu_ying/32/9035_2.png) [@wu\_ying](https://discourse.paraview.org/u/wu_ying)
#### Post date: [April 21, 2022, 10:38am UTC](https://discourse.paraview.org/t/my-binary-file-is-imported-into-paraview-it-crashes/9472/5 "2022-04-21T10:38:51Z")

</div>

Thanks for your reply, very useful
