1 #include <stdlib.h> 2 #include <FCMangle.h> 3 #include <new_interface.h> 4 #include <stdio.h> 5 #include <string.h> //memset 6 #include <assert.h> 7 #include "common_c.h" 8 #include "phastaIO.h" 9 #include "phIO.h" 10 #include "setsyncioparam.h" 11 12 void 13 read_d2wall( int* pid, 14 int* numnp, 15 double* array1, 16 int* foundd2wall ) { 17 int isize, nitems; 18 int iarray[10]; 19 int j; 20 for ( j = 0; j < 10; j++) { 21 //Initialize iarray to 0 so that we can assess the result of readheader 22 iarray[j] = 0; 23 } 24 25 int nfiles; 26 int nfields; 27 int numparts; 28 int irank; 29 int nprocs; 30 31 // Retrieve and compute the parameters required for SyncIO 32 nfiles = outpar.nsynciofiles; 33 numparts = workfc.numpe; 34 irank = *pid; // workfc.myrank; 35 nprocs = workfc.numpe; 36 37 // Calculate number of parts each proc deal with and where it start and end ... 38 int nppp = numparts/nprocs;// nppp : Number of parts per proc ... 39 assert(nppp==1); 40 int startpart = irank * nppp +1;// Part id from which I (myrank) start ... 41 int endpart = startpart + nppp - 1;// Part id to which I (myrank) end ... 42 43 phio_fp handle; 44 char filename[255],path[255]; 45 memset((void*)filename,0,255); 46 *foundd2wall = 0; 47 //////////////////////////////////////////////////// 48 // First we try to read dwal from the restart files. 49 //////////////////////////////////////////////////// 50 51 if ( nfiles == 0 ) { 52 sprintf(filename,"restart.%d.", timdat.lstep); 53 } 54 else { 55 sprintf(filename,"restart-dat.%d.", timdat.lstep); 56 } 57 phio_openfile_read(filename, &nfiles, &handle); 58 59 int i; 60 for ( i = 0; i < nppp; i++) { //This loop is useful only if several parts per processor 61 nitems = 2; 62 phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype); 63 64 if (iarray[0] == (*numnp)) { 65 if (irank==0) { 66 printf("d2wall field found in %s\n",filename); 67 } 68 *foundd2wall = 1; 69 isize = (*numnp); 70 phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype ); 71 } 72 else { //d2wall fields was not found in the restart file 73 *foundd2wall = 0; 74 if (irank==0) { 75 printf("d2wall field not found in %s - trying d2wall files now\n",filename); 76 } 77 } 78 } 79 phio_closefile_read(handle); 80 81 if (irank==0) { 82 printf("\n"); 83 } 84 } 85