IODA
ObsIoFileRead.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2019 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include "ioda/Engines/Factory.h"
9 
10 #include "ioda/io/ObsIoFileRead.h"
11 
12 namespace ioda {
13 
14 static ObsIoMaker<ObsIoFileRead> maker("FileRead");
15 
16 //------------------------------ public functions --------------------------------
17 //--------------------------------------------------------------------------------
19  const ObsSpaceParameters & obsSpaceParams) : ObsIo() {
20  Engines::BackendNames backendName;
22  Group backend;
23 
24  std::string fileName = ioParams.fileName;
25  oops::Log::trace() << "Constructing ObsIoFileRead: Opening file for read: "
26  << fileName << std::endl;
27 
28  // Open an hdf5 file, read only
29  backendName = Engines::BackendNames::Hdf5File;
30  if (ioParams.readFromSeparateFiles) {
31  // We are initializing from a prior run and therefore reading in the
32  // separate ioda files produced from that prior run.
33  backendParams.fileName = uniquifyFileName(fileName, obsSpaceParams.getMpiRank(),
34  obsSpaceParams.getMpiTimeRank());
35  read_separate_files_ = true;
36  } else {
37  backendParams.fileName = fileName;
38  }
41 
42  // Create the backend and attach it to an ObsGroup
43  backend = constructBackend(backendName, backendParams);
44  ObsGroup og(backend);
45  obs_group_ = og;
46 
47  // Collect variable and dimension infomation for downstream use
50 
51  // record number of locations
53 
54  // record variables by which observations should be grouped into records
55  obs_grouping_vars_ = ioParams.obsGrouping.value().obsGroupVars;
56 }
57 
59 
61  return read_separate_files_;
62 }
63 
64 //------------------------------ private functions ----------------------------------
65 //-----------------------------------------------------------------------------------
66 void ObsIoFileRead::print(std::ostream & os) const {
67  os << "ObsIoFileRead: " << std::endl;
68 }
69 
70 } // namespace ioda
Definitions for setting up backends with file and memory I/O.
Groups are a new implementation of ObsSpaces.
Definition: Group.h:159
oops::Parameter< bool > readFromSeparateFiles
oops::RequiredParameter< std::string > fileName
input obs file name
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
Definition: ObsGroup.h:32
ObsIoFileRead(const Parameters_ &ioParams, const ObsSpaceParameters &obsSpaceParams)
bool eachProcessGeneratesSeparateObs() const override
return true if each process generates a separate series of observations (e.g. read from different fil...
void print(std::ostream &os) const override
print routine for oops::Printable base class
Dimensions_t max_var_size_
maximum variable size (ie, first dimension size)
Definition: ObsIo.h:97
Dimensions_t nlocs_
number of locations from source (file or generator)
Definition: ObsIo.h:100
VarNameObjectList var_list_
list of regular variables from source (file or generator)
Definition: ObsIo.h:103
std::vector< std::string > obs_grouping_vars_
names of variables to be used to group observations into records
Definition: ObsIo.h:112
VarNameObjectList dim_var_list_
list of dimension scale variables from source (file or generator)
Definition: ObsIo.h:106
VarDimMap dims_attached_to_vars_
map containing variables with their attached dimension scales
Definition: ObsIo.h:109
ObsGroup obs_group_
ObsGroup object representing io source/destination.
Definition: ObsIo.h:94
oops::Parameter< ObsGroupingParameters > obsGrouping
options controlling obs record grouping
int getMpiTimeRank() const
get the MPI rank number
std::size_t getMpiRank() const
get the MPI rank number
Has_Variables vars
Use this to access variables.
Definition: Group.h:123
virtual Variable open(const std::string &name) const
Open a Variable by name.
virtual Dimensions getDimensions() const
Definition: Variable.cpp:160
BackendNames
Backend names.
Definition: Factory.h:27
IODA_DL Group constructBackend(BackendNames name, BackendCreationParameters &params)
This is a simple factory style function that will instantiate a different backend based on a given na...
Definition: Factory.cpp:123
@ Open
Open an existing file.
@ Hdf5File
HDF5 file access.
@ Read_Only
Open the file in read-only mode.
static DistributionMaker< Halo > maker("Halo")
std::string uniquifyFileName(const std::string &fileName, const std::size_t rankNum, const int timeRankNum)
uniquify the output file name
Definition: IodaUtils.cc:343
void collectVarDimInfo(const ObsGroup &obsGroup, VarNameObjectList &varObjectList, VarNameObjectList &dimVarObjectList, VarDimMap &dimsAttachedToVars, Dimensions_t &maxVarSize0)
collect variable and dimension information from a ioda ObsGroup
Definition: IodaUtils.cc:125
std::vector< Dimensions_t > dimsCur
The dimensions of the data.
Definition: Dimensions.h:23
Used to specify backend creation-time properties.
Definition: Factory.h:56