Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

gstream.hpp

Go to the documentation of this file.
00001 //************************************************************************************//
00002 // Module       : gstream.hpp
00003 // Date         : 12/10/02 (DLR)
00004 // Copyright    : 2002-2006 Copyright University Corporation for Atmospheric
00005 //                Research
00006 // Description  : Encapsulates the methods and data associated with
00007 //                the GStream object.
00008 // Derived From : none.
00009 // Modifications:
00010 //************************************************************************************//
00011 #if !defined(GSTREAM_HPP)
00012 #define GSTREAM_HPP 
00013 #include "gtypes.h"
00014 #include "gdd_file.h"
00015 #include "gtbuffer.hpp"
00016 #include <iostream.h>
00017 #include <fstream.h>
00018 #include "gcomm.hpp"
00019 #include "gtbuffer.hpp"
00020 #if defined(MPI_IO_DEFAULT)
00021 #include "mpi.h"
00022 #endif
00023 
00024 extern char *streamerror_[] ;
00025 
00026 class GStream: public fstream
00027 {
00028 public:
00029 //   public  data:
00030 #if defined(MPI_IO_DEFAULT)
00031          enum gios_open_mode {
00032          app       = MPI_MODE_APPEND,
00033          ate       = MPI_MODE_APPEND,
00034          binary    = 0,
00035          in        = MPI_MODE_RDONLY,
00036          nocreate  = 0,
00037          create    = MPI_MODE_CREATE,
00038          noreplace = MPI_MODE_EXCL,
00039          out       = MPI_MODE_WRONLY,
00040          inout     = MPI_MODE_RDWR,
00041          trunc     = ios::trunc};
00042 //       trunc     = MPI_MODE_NOPRECEDE };
00043 #else
00044          enum gios_open_mode {
00045          app       = ios::app,
00046          ate       = ios::ate,
00047          binary    = ios::binary,
00048          in        = ios::in,
00049          nocreate  = 0,  //ios::nocreate,
00050          create    = 0,
00051          noreplace = 0,  //ios::noreplace,
00052          out       = ios::out,
00053          inout     = ios::in | ios::out,
00054          trunc     = ios::trunc };
00055 #endif
00056 
00057                           GStream(GBOOL isCollective=FALSE, GBOOL isIndependent=TRUE, GSHORT  ioTaskID=0);
00058 //                        GStream(const GStream &);
00059                          ~GStream();
00060 virtual  GBOOL            Open(const char *, GIOS_MODE iomode, GBOOL bDelete=FALSE);
00061 virtual  void             Close();
00062          GBOOL            SetFileView(GFPOS disp);          // Set file view for collective writes
00063          void             FileSynch();                      // Synch file
00064          GBOOL            Access(char *fn);                 // Does file, fn, exist?
00065          const char      *Error();
00066          GINT             ErrorID();
00067          GBOOL            NewComm();
00068 
00069          void             InitCommList(GINT);
00070               GBOOL                      SwitchedComms(GINT);
00071               GBOOL                      SwitchingComms(GINT);
00072               void                       FinishedLoop();         
00073 
00074          void             read (GUCHAR *, GINT  nGUCHARs);
00075          void             get(char &ch);
00076          void             write(GUCHAR *, GINT  nGUCHARs);
00077          void             seekp(GFPOS offset, seek_dir origin);
00078          void             seekg(GFPOS offset, seek_dir origin);
00079          char             peek();
00080          GFPOS            tellp();
00081          GFPOS            tellg();
00082          GBOOL            eof(); 
00083          GBOOL            fail(); 
00084          GBOOL            ignore(const char *delim);
00085 
00086 
00087 protected:
00088 //    methods:
00089 
00090 //    data:
00091          enum ERRNO {
00092             ERRNONE     , ERREOF         , ERRFILENAME,
00093             ERRHEADER   , ERRFILETYPE    , ERRCORRUPT,
00094             ERRDIMENSION, ERRNODATA      , ERRNOFILE ,
00095             ERRMISC     , ERRMALLOC      , ERRDATANOTFND,
00096             ERRBADDATA  , ERRHAVEDATA    , ERRBADSNUM,
00097             ERRMETAW    , ERRCOORDBLKW   , ERRDATABLKW,
00098             ERRMETAR    , ERRCOORDBLKR   , ERRDATABLKR ,
00099             ERRFILEXISTS, ERRFILENOTEXIST, ERRMPI      , ERRMAX
00100            };
00101 
00102 
00103          GINT             iLen_;
00104          ERRNO            ierror_;
00105          GBOOL            isOpen_;
00106          GBOOL            isFile_;
00107          GBOOL            iscollective_;
00108          GBOOL            isindependent_;
00109          GBOOL            deletefirst_;
00110          GBOOL            bNewComm_ ;          // was new comm created in call to EndLoop?        
00111          GSHORT           iotaskid_;
00112          GINT             nLoopPMax_;
00113          char             *filename_;
00114 //       char             *serrmsg;
00115          char             sErr_[GMAX_ERROR_STRING];
00116          GIBuffer         procExcluded_;
00117          GIBuffer         pexcl_;
00118               GIBuffer         nLoopP_;
00119               GIBuffer         iRanks_;
00120          fstream          *ios_;
00121 
00122               void                       EndLoop(GINT index);
00123 
00124 #if defined(MPI_IO_DEFAULT)
00125          MPI_File         fhMPI_;              // MPI file handle
00126          MPI_Offset       voffsetMPI_;         // MPI offset value (measured from beg. of MPI view)
00127          MPI_Offset       doffsetMPI_;         // MPI offset value (measured from beg. of file)
00128          MPI_Datatype     etypeMPI_;           // MPI datatype
00129          MPI_Datatype     filetypeMPI_;        // MPI file type
00130          MPI_Status       statusMPI_;          // MPI status flag
00131          MPI_Info         infoMPI_;            // MPI info structure
00132          MPI_Comm         IOCommMPI_;          // MPI communicator representing IO tasks
00133          MPI_Group        currentGroup_;       // MPI group used when not all processors are wanted
00134               MPI_Group        groupWorld_;         // MPI group used when all processors are wanted
00135          GFPOS            putposnMPI_;         // put position w/in file = View offset + pviewMPI_
00136          GFPOS            getposnMPI_;         // get position w/in file = View offset + gviewMPI_
00137          GFPOS            pviewMPI_;           // put posn wrt process's MPI view
00138          GFPOS            gviewMPI_;           // get posn wrt process's MPI view
00139          GBOOL            bEvenDist_;          // is the total number of dataset loops same on all procs?
00140          GSHORT           ierrorMPI_;          // MPI error code
00141          GSHORT           *iotasklist_;        // IO task list: for each procid, its iotaskid_
00142          GSHORT           *sisterids_;         // Proc ids from which to receive data for output
00143          GINT             nrecvs_;             // Number of procs from which to recv data
00144          char             datarepMPI_[MPI_MAX_DATAREP_STRING];  // MPI data representation string
00145 
00146 
00147          GINT             PostDataRecvs(GUCHAR **&buff, GINT  maxbufflen);
00148          MPI_Comm         BuildComm();
00149 #else
00150          GINT             IOCommMPI_;          // integer communicator representing IO tasks
00151 #endif
00152 private:
00153          void            DeleteDynamic(); 
00154          GBOOL           in_list(GSBuffer  *ilist, GINT  imember, GINT  &index);
00155 
00156 };
00157 
00158 #endif

Generated on Wed Dec 21 16:00:48 2005 for Geophysics & Astrophysics Spectral Element Adaptive Refinement (GASpAR) 2D Code by  doxygen 1.4.4