"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.2/src/metgm/MetGmCDMWriterSlicedImpl.cc" (6 Jan 2020, 2972 Bytes) of package /linux/privat/fimex-1.4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "MetGmCDMWriterSlicedImpl.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.4.1_vs_1.4.2.

    1 /*
    2  * Fimex
    3  *
    4  * (C) Copyright 2011-2019, met.no
    5  *
    6  * Project Info:  https://wiki.met.no/fimex/start
    7  *
    8  * This library is free software; you can redistribute it and/or modify it
    9  * under the terms of the GNU Lesser General Public License as published by
   10  * the Free Software Foundation; either version 2.1 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This library is distributed in the hope that it will be useful, but
   14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
   16  * License for more details.
   17  *
   18  * You should have received a copy of the GNU Lesser General Public
   19  * License along with this library; if not, write to the Free Software
   20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
   21  * USA.
   22  */
   23 
   24 #include "MetGmCDMWriterSlicedImpl.h"
   25 
   26 #include "fimex/CDMException.h"
   27 #include "MetGmHandlePtr.h"
   28 
   29 namespace MetNoFimex {
   30 
   31 MetGmCDMWriterSlicedImpl::MetGmCDMWriterSlicedImpl(CDMReader_p cdmReader, const std::string& outputFile, const std::string& configFile)
   32     : MetGmCDMWriterImpl(cdmReader, outputFile, configFile)
   33 {
   34 }
   35 
   36 void MetGmCDMWriterSlicedImpl::init()
   37 {
   38     for (xml_configuration::const_iterator pIt : sorted_by_pid(xmlConfiguration_)) {
   39         const MetGmConfigurationMappings& entry = *pIt;
   40 
   41         if (std::find_if(cdmConfiguration_.begin(), cdmConfiguration_.end(), MetGmCDMVariableProfileEqName(entry.cdmName_)) != cdmConfiguration_.end()) {
   42             throw CDMException("hmmm... the variable should not be found in cdm profile map");
   43         }
   44 
   45         const CDMVariable* pVariable = &cdmReader->getCDM().getVariable(entry.cdmName_);
   46 
   47         MetGmTagsPtr tags = MetGmTags::createMetGmTagsForSlicedWriting(cdmReader, pVariable, metgmHandle_, entry.p_id_);
   48         if (!tags) {
   49             MGM_MESSAGE_POINT(std::string(" MetGmTag null -- not writing variable :").append(entry.cdmName_))
   50             continue;
   51         }
   52 
   53         MetGmCDMVariableProfile profile(entry.p_id_, entry.cdmName_, tags);
   54         // make sure that units are aligned
   55         profile.units_ = tags->units();
   56         cdmConfiguration_.push_back(profile);
   57     }
   58 }
   59 
   60 void MetGmCDMWriterSlicedImpl::writeGroup5Data(const MetGmCDMVariableProfile& profile, const CDMVariable* pVar)
   61 {
   62     size_t total_num_of_slices = 1;
   63     if (profile.pTags_->tTag()) {
   64         total_num_of_slices = profile.pTags_->tTag()->nT();
   65     }
   66 
   67     for (size_t slice_index = 0; slice_index < total_num_of_slices; ++slice_index) {
   68         size_t cSlicePos = -1;
   69         DataPtr raw_slice = cdmReader->getScaledDataSliceInUnit(pVar->getName(), profile.units_, slice_index);
   70         shared_array<float> slice_to_write = raw_slice->asFloat();
   71         profile.pTags_->sliceToMetGmLayout(slice_to_write);
   72         MGM_THROW_ON_ERROR(mgm_write_group5_slice(*metgmFileHandle_, *metgmHandle_, slice_to_write.get(), &cSlicePos));
   73     }
   74 }
   75 
   76 } // namespace MetNoFimex