Ice Sheet System Model  4.18
Code documentation
Functions
diskio.h File Reference
#include <stdio.h>

Go to the source code of this file.

Functions

FILE * pfopen (char *filename, const char *format, bool errorout=true)
 
FILE * pfopen0 (char *filename, const char *format)
 
void pfclose (FILE *fid, char *filename)
 
void WriteLockFile (char *filename)
 

Function Documentation

◆ pfopen()

FILE* pfopen ( char *  filename,
const char *  format,
bool  errorout = true 
)

Definition at line 30 of file pfopen.cpp.

30  {
31 
32  FILE* fid=NULL;
33 
34  /*recover my_rank:*/
35  int my_rank = IssmComm::GetRank();
36  int num_proc = IssmComm::GetSize();
37 
38  /*Open handle to data on disk (one by one to avoid errors)*/
39  for(int i=0;i<num_proc;i++){
40  if(my_rank==i) fid = fopen(filename,format);
42  }
43  if(errorout && fid==NULL)_error_("could not open file " << filename << " for binary reading or writing");
44 
45  return fid;
46 }

◆ pfopen0()

FILE* pfopen0 ( char *  filename,
const char *  format 
)

Definition at line 16 of file pfopen.cpp.

16  {
17 
18  FILE* fid=NULL;
19 
20  /*recover my_rank:*/
21  int my_rank = IssmComm::GetRank();
22  if(my_rank) _error_("This function should only be called by cpu 0");
23 
24  /*Open handle to data on disk*/
25  fid = fopen(filename,format);
26  if(fid==NULL)_error_("could not open file " << filename << " for binary reading or writing");
27 
28  return fid;
29 }

◆ pfclose()

void pfclose ( FILE *  fid,
char *  filename 
)

Definition at line 14 of file pfclose.cpp.

14  {
15 
16  /*Close file handle: */
17  _assert_(fid);
18  if(fclose(fid)!=0)_error_("could not close file " << filename);
19 }

◆ WriteLockFile()

void WriteLockFile ( char *  filename)

Definition at line 10 of file WriteLockFile.cpp.

10  {
11 
12  /*recover my_rank:*/
13  int my_rank=IssmComm::GetRank();
14 
15  /* output: */
16  FILE* fid=NULL;
17 
18  /* Open lock file and write 1 into it: */
19  if(my_rank==0){
20  fid=fopen(filename,"w");
21  if(fid==NULL) _error_("error message: could not open lock file " << filename);
22 
23  /*Close file: */
24  if(fclose(fid)!=0) _error_("could not close lock file " << filename);
25  }
26 
27 }
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
IssmComm::GetSize
static int GetSize(void)
Definition: IssmComm.cpp:46
IssmComm::GetRank
static int GetRank(void)
Definition: IssmComm.cpp:34
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
ISSM_MPI_Barrier
int ISSM_MPI_Barrier(ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:148