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