1 #include <fstream> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <vector> 5 #include <string.h> 6 #include <cstring> 7 #include <sys/types.h> 8 #include <dirent.h> // For opendir(),readdir(),... 9 #include <mpi.h> 10 #include "phastaIO.h" 11 12 #include "commonM2NFixBnd_c.h" 13 #include "setsyncioparamM2NFixBnd.h" 14 15 16 using namespace std; //useful for ifstream. Other solution is std::ifstream 17 18 // extern void queryphmpiio_(const char[], int*, int*); 19 // void queryphmpiio_(const char filename[],int *nfields, int *nppf) 20 21 void setIOparam() 22 { 23 int count; 24 int nfields; 25 int nppf; 26 int stepno; 27 int part; 28 char fname[255]; 29 DIR *d; 30 struct dirent *filename; 31 32 33 //Number of geombc files 34 if(workfc.myrank == 0){ 35 if( (d = opendir(".")) != NULL) { 36 count=0; 37 while(filename=readdir(d)) { 38 //printf("%s\n", filename->d_name); 39 if(strncmp(filename->d_name,"geombcRed-dat",13)==0) { 40 count=count+1; 41 } 42 } 43 closedir(d); 44 } 45 else { 46 printf("ERROR when counting geombcRed-dat\n"); 47 } 48 } 49 50 MPI_Bcast( &count, 1, MPI_INT, 0, MPI_COMM_WORLD ); 51 //printf("Here we gogo: %d %d\n",workfc.myrank,count); 52 53 outpar.nsynciofiles = count; 54 if(workfc.myrank == 0) { 55 printf("Number of geombcRed-dat and restartRed-dat files to read: %d\n", count); 56 } 57 58 } 59 60 void detectd2wallfiles(int* numd2wallfiles) 61 { 62 int count; 63 int nfields; 64 int nppf; 65 int stepno; 66 int part; 67 char fname[255]; 68 DIR *d; 69 struct dirent *filename; 70 71 //Number of d2wall files 72 if(workfc.myrank == 0){ 73 if( (d = opendir(".")) != NULL) { 74 count=0; 75 while(filename=readdir(d)) { 76 //printf("%s\n", filename->d_name); 77 if(strncmp(filename->d_name,"d2wall",6)==0) { 78 count=count+1; 79 } 80 } 81 closedir(d); 82 } 83 } 84 85 MPI_Bcast( &count, 1, MPI_INT, 0, MPI_COMM_WORLD ); 86 //printf("Here we gogo: %d %d\n",workfc.myrank,count); 87 88 *numd2wallfiles = count; 89 if(workfc.myrank == 0) { 90 printf("Number of d2wall files present in the proc_case directory: %d\n", count); 91 } 92 93 } 94 95 96 // void countfieldstowriterestart() //See new_interface.c 97