xref: /phasta/phSolver/common/test/phIOwrite.cc (revision fe88b52d35537d3736cc3d33d9db7e51353aba7d)
1 #include <mpi.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include "phIO.h"
6 
7 int main(int argc, char* argv[]) {
8   MPI_Init(&argc,&argv);
9   int rank;
10   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
11   int size;
12   MPI_Comm_size(MPI_COMM_WORLD, &size);
13   if( argc != 2 ) {
14     fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]);
15     MPI_Finalize();
16     return 1;
17   }
18   const char* phrase = "number of fishes";
19   const char* type = "double";
20   const char* iotype = "binary";
21   int fish = 2;
22   int numFish[2] = {0,0};
23   double fishWeight[2] = {1.23,1.23};
24   int nfiles[2] = {atoi(argv[1]), 1};
25   const char* filename[2] = {"water-dat.", "water.dat."};
26   phio_fp file;
27   int one = 1;
28   int ppf = size/nfiles[0];
29   for(int i=0; i<2; i++) {
30     phio_openfile_write(filename[i], &(nfiles[i]), &one, &ppf, &file);
31     phio_writeheader(file, phrase, &fish, &one, &one, type, iotype);
32     phio_writedatablock(file, phrase, &(fishWeight[i]), &one, type, iotype);
33     phio_closefile_write(file);
34   }
35   for(int i=0; i<2; i++) {
36     phio_openfile_read(filename[i], &(nfiles[i]), &file);
37     phio_readheader(file, phrase, &(numFish[i]), &one, type, iotype);
38     phio_readdatablock(file, phrase, &(fishWeight[i]), &one, type, iotype);
39     phio_closefile_read(file);
40   }
41   int match = (numFish[0] == numFish[1]) && (fishWeight[0] == fishWeight[1]);
42   if(!rank && match)
43     fprintf(stderr, "number of fish match!\n");
44   if(!rank && !match)
45     fprintf(stderr, "number of fish don't match... :(\n");
46   MPI_Finalize();
47   return !match;
48 }
49