Changeset 8913
- Timestamp:
- 07/11/11 17:01:58 (14 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Makefile.am
r8910 r8913 406 406 ./io/Disk/pfopen.cpp\ 407 407 ./io/Disk/pfclose.cpp\ 408 ./io/Disk/FetchData.cpp\409 408 ./io/Matlab/matlabio.h\ 410 409 ./io/Matlab/WriteMatlabData.cpp\ … … 1080 1079 ./io/Disk/pfopen.cpp\ 1081 1080 ./io/Disk/pfclose.cpp\ 1082 ./io/Disk/FetchData.cpp\1083 1081 ./io/Matlab/matlabio.h\ 1084 1082 ./io/Matlab/WriteMatlabData.cpp\ -
issm/trunk/src/c/io/Disk/IoModelFetchData.cpp
r8910 r8913 15 15 /*FUNCTION IoModelFetchData(double** pmatrix,int* pM,int* pN,FILE* model_handle,char* data_name){{{1*/ 16 16 void IoModelFetchData(double** pmatrix,int* pM,int* pN,FILE* model_handle,char* data_name){ 17 18 extern int my_rank; 19 extern int num_procs; 20 21 /*output: */ 22 int M,N; 23 double* matrix=NULL; 17 24 18 25 FILE* fid=NULL; … … 22 29 23 30 /*Now fetch: */ 24 FetchData(pmatrix,pM,pN,fid); 31 32 /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */ 33 /*numberofelements: */ 34 if(my_rank==0){ 35 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 36 } 37 38 MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 39 40 if(my_rank==0){ 41 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 42 } 43 MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 44 45 /*Now allocate matrix: */ 46 if(M*N){ 47 matrix=(double*)xmalloc(M*N*sizeof(double)); 48 49 /*Read matrix on node 0, then broadcast: */ 50 if(my_rank==0){ 51 if(fread(matrix,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix "); 52 } 53 54 MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 55 } 56 57 /*Assign output pointers: */ 58 *pmatrix=matrix; 59 if (pM)*pM=M; 60 if (pN)*pN=N; 25 61 26 62 } … … 29 65 void IoModelFetchData(char** pstring,FILE* model_handle,char* data_name){ 30 66 31 FILE* fid=NULL; 67 extern int my_rank; 68 extern int num_procs; 69 FILE* fid=NULL; 70 71 /*output: */ 72 char* string=NULL; 73 int string_size; 32 74 33 75 /*Set file pointer to beginning of the data: */ … … 35 77 36 78 /*Now fetch: */ 37 FetchData(pstring,fid); 79 80 /*We have to read a string from disk. First read the dimensions of the string, then the string: */ 81 if(my_rank==0){ 82 if(fread(&string_size,sizeof(int),1,fid)!=1) _error_(" could not read length of string "); 83 } 84 85 MPI_Bcast(&string_size,1,MPI_INT,0,MPI_COMM_WORLD); 86 87 /*Now allocate string: */ 88 if(string_size){ 89 string=(char*)xmalloc((string_size+1)*sizeof(char)); 90 string[string_size]='\0'; 91 92 /*Read string on node 0, then broadcast: */ 93 if(my_rank==0){ 94 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 95 } 96 MPI_Bcast(string,string_size,MPI_CHAR,0,MPI_COMM_WORLD); 97 } 98 else{ 99 string=(char*)xmalloc(sizeof(char)); 100 string[0]='\0'; 101 } 102 103 104 /*Assign output pointers: */ 105 *pstring=string; 38 106 } 39 107 /*}}}*/ … … 41 109 void IoModelFetchData(double* pscalar,FILE* model_handle,char* data_name){ 42 110 43 FILE* fid=NULL; 44 45 /*Set file pointer to beginning of the data: */ 46 fid=SetFilePointerToData(model_handle,data_name); 47 48 /*Now fetch: */ 49 FetchData(pscalar,fid); 111 112 extern int my_rank; 113 extern int num_procs; 114 FILE* fid=NULL; 115 116 /*output: */ 117 double scalar; 118 119 /*Set file pointer to beginning of the data: */ 120 fid=SetFilePointerToData(model_handle,data_name); 121 122 /*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */ 123 if(my_rank==0){ 124 if(fread(&scalar,sizeof(double),1,fid)!=1)_error_(" could not read scalar "); 125 } 126 MPI_Bcast(&scalar,1,MPI_DOUBLE,0,MPI_COMM_WORLD); 127 128 /*Assign output pointers: */ 129 *pscalar=scalar; 130 50 131 } 51 132 /*}}}*/ … … 53 134 void IoModelFetchData(int* pinteger,FILE* model_handle,char* data_name){ 54 135 55 FILE* fid=NULL; 56 57 /*Set file pointer to beginning of the data: */ 58 fid=SetFilePointerToData(model_handle,data_name); 59 60 /*Now fetch: */ 61 FetchData(pinteger,fid); 136 extern int my_rank; 137 extern int num_procs; 138 FILE* fid=NULL; 139 140 /*output: */ 141 int integer; 142 143 /*Set file pointer to beginning of the data: */ 144 fid=SetFilePointerToData(model_handle,data_name); 145 146 /*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */ 147 if(my_rank==0){ 148 if(fread(&integer,sizeof(int),1,fid)!=1) _error_(" could not read integer "); 149 } 150 151 MPI_Bcast(&integer,1,MPI_INT,0,MPI_COMM_WORLD); 152 153 /*Assign output pointers: */ 154 *pinteger=integer; 155 62 156 } 63 157 /*}}}*/ -
issm/trunk/src/c/io/Disk/diskio.h
r8910 r8913 16 16 void pfclose(FILE* fid,char* filename); 17 17 18 void FetchData(double** pmatrix, int* pM,int* pN,FILE* fid);19 void FetchData(char** pstring,FILE* fid);20 void FetchData(double* pscalar,FILE* fid);21 void FetchData(int* pinteger,FILE* fid);22 23 18 void IoModelFetchData(double** pmatrix,int* pM,int* pN,FILE* model_handle,char* data_name); 24 19 void IoModelFetchData(char** pstring,FILE* model_handle,char* data_name);
Note:
See TracChangeset
for help on using the changeset viewer.