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 "phString.h" 11 #include "syncio.h" 12 #include "posixio.h" 13 #include "streamio.h" 14 #include "setsyncioparam.h" 15 #include "tmrc.h" 16 17 void 18 read_d2wall( int* pid, 19 int* numnp, 20 double* array1, 21 int* foundd2wall ) { 22 int isize, nitems; 23 int iarray[10]; 24 int j; 25 double iotime = 0; 26 for ( j = 0; j < 10; j++) { 27 /*Initialize iarray to 0 so that we can assess the result of readheader*/ 28 iarray[j] = 0; 29 } 30 31 int nfields; 32 int numparts; 33 int irank; 34 int nprocs; 35 36 /* Retrieve and compute the parameters required for SyncIO */ 37 numparts = workfc.numpe; 38 irank = *pid; /* workfc.myrank; */ 39 nprocs = workfc.numpe; 40 41 /* Calculate number of parts each proc deal with and where it start and end ... */ 42 int nppp = numparts/nprocs;/* nppp : Number of parts per proc ... */ 43 assert(nppp==1); 44 int startpart = irank * nppp +1;/* Part id from which I (myrank) start ... */ 45 int endpart = startpart + nppp - 1;/* Part id to which I (myrank) end ... */ 46 47 phio_fp handle; 48 char filename[255],path[255]; 49 memset((void*)filename,0,255); 50 *foundd2wall = 0; 51 /* First we try to read dwal from the restart files. */ 52 53 iotime = TMRC(); 54 if( outpar.input_mode == -1 ) 55 streamio_setup_read(&handle, streamio_get_gr()); 56 else if( outpar.input_mode == 0 ) 57 posixio_setup(&handle, 'r'); 58 else if( outpar.input_mode > 0 ) 59 syncio_setup_read(outpar.nsynciofiles, &handle); 60 phio_constructName(handle,"restart",filename); 61 phstr_appendInt(filename, timdat.lstep); 62 phstr_appendStr(filename, "."); 63 phio_openfile(filename, handle); 64 65 int i; 66 for ( i = 0; i < nppp; i++) { /*This loop is useful only if several parts per processor*/ 67 nitems = 2; 68 phio_readheader(handle, "dwal", (void*)iarray, &nitems, "double", phasta_iotype); 69 70 if (iarray[0] == (*numnp)) { 71 if (irank==0) { 72 printf("d2wall field found in %s\n",filename); 73 } 74 *foundd2wall = 1; 75 isize = (*numnp); 76 phio_readdatablock(handle, "dwal", (void*)(array1), &isize, "double", phasta_iotype ); 77 } 78 else { /*d2wall fields was not found in the restart file*/ 79 *foundd2wall = 0; 80 if (irank==0) { 81 printf("d2wall field not found in %s - trying d2wall files now\n",filename); 82 } 83 } 84 } 85 phio_closefile(handle); 86 iotime = TMRC() - iotime; 87 if (irank==0) { 88 printf("time to read d2wall (seconds) %f\n",iotime); 89 printf("\n"); 90 } 91 } 92