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