#include #include #include #include #include //memset #include #include "common_c.h" #include "phastaIO.h" #include "phIO.h" #include "syncio.h" #include "posixio.h" #include "streamio.h" #include "setsyncioparam.h" void read_d2wall( int* pid, int* numnp, double* array1, int* foundd2wall ) { int isize, nitems; int iarray[10]; int j; for ( j = 0; j < 10; j++) { //Initialize iarray to 0 so that we can assess the result of readheader iarray[j] = 0; } int nfiles; int nfields; int numparts; int irank; int nprocs; // Retrieve and compute the parameters required for SyncIO nfiles = outpar.nsynciofiles; numparts = workfc.numpe; irank = *pid; // workfc.myrank; nprocs = workfc.numpe; // Calculate number of parts each proc deal with and where it start and end ... int nppp = numparts/nprocs;// nppp : Number of parts per proc ... assert(nppp==1); int startpart = irank * nppp +1;// Part id from which I (myrank) start ... int endpart = startpart + nppp - 1;// Part id to which I (myrank) end ... phio_fp handle; char filename[255],path[255]; memset((void*)filename,0,255); *foundd2wall = 0; //////////////////////////////////////////////////// // First we try to read dwal from the restart files. //////////////////////////////////////////////////// phio_format fmt = 0; stream* grstream; if( nfiles == -1 ) { fmt = PHIO_STREAM; streamio_setup(grstream, &handle); } else if( nfiles == 0 ) { fmt = PHIO_POSIX; posixio_setup(&handle, 'r'); } else if( nfiles == 1 ) { fmt = PHIO_SYNC; syncio_setup_read(nfiles, &handle); } phio_constructName(fmt,"restart",filename); phio_appendInt(filename, timdat.lstep); phio_openfile(filename, handle); int i; for ( i = 0; i < nppp; i++) { //This loop is useful only if several parts per processor nitems = 2; phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype); if (iarray[0] == (*numnp)) { if (irank==0) { printf("d2wall field found in %s\n",filename); } *foundd2wall = 1; isize = (*numnp); phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype ); } else { //d2wall fields was not found in the restart file *foundd2wall = 0; if (irank==0) { printf("d2wall field not found in %s - trying d2wall files now\n",filename); } } } phio_closefile(handle); if (irank==0) { printf("\n"); } }