"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.1/src/metgm/MetGmGroup1Ptr.cc" (30 Oct 2019, 5300 Bytes) of package /linux/privat/fimex-1.4.1.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 "MetGmGroup1Ptr.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Fimex
    3  *
    4  * (C) Copyright 2011, 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 // internals
   25 //
   26 #include "MetGmFileHandlePtr.h"
   27 #include "MetGmHandlePtr.h"
   28 #include "MetGmTimeTag.h"
   29 #include "MetGmCommentAttributeParser.h"
   30 #include "MetGmGroup1Ptr.h"
   31 
   32 // fimex
   33 //
   34 #include "fimex/CDM.h"
   35 #include "fimex/CDMReader.h"
   36 #include "fimex/CDMVariable.h"
   37 #include "fimex/String2Type.h"
   38 #include "fimex/TimeUnit.h"
   39 
   40 // standard
   41 #include <iostream>
   42 
   43 namespace MetNoFimex {
   44 
   45 std::shared_ptr<MetGmGroup1Ptr> MetGmGroup1Ptr::createMetGmGroup1PtrForReading(const std::shared_ptr<MetGmHandlePtr> pMgmHandle)
   46 {
   47     std::shared_ptr<MetGmGroup1Ptr> gp1 = std::shared_ptr<MetGmGroup1Ptr>(new MetGmGroup1Ptr(pMgmHandle));
   48 
   49     gp1->analysis_t     = mgm_get_analysis_date_time(*pMgmHandle);
   50     gp1->start_t        = mgm_get_start_date_time(*pMgmHandle);
   51     gp1->freeText_      = mgm_get_free_text(*pMgmHandle);
   52     gp1->modelType_     = mgm_get_model_type(*pMgmHandle);
   53     gp1->productNation_ = mgm_get_production_nation(*pMgmHandle);
   54     gp1->dataType_      = mgm_get_data_type(*pMgmHandle);
   55 
   56     return gp1;
   57 }
   58 
   59 std::shared_ptr<MetGmGroup1Ptr> MetGmGroup1Ptr::createMetGmGroup1PtrForWriting(const CDMReader_p pCdmReader)
   60 {
   61     std::shared_ptr<MetGmGroup1Ptr> gp1 = std::shared_ptr<MetGmGroup1Ptr>(new MetGmGroup1Ptr);
   62 
   63     const CDM& cdmRef = pCdmReader->getCDM();
   64 
   65     gp1->tTag_ = MetGmTimeTag::createMetGmTimeTagGlobal(pCdmReader);
   66 
   67     gp1->start_t = gp1->tTag_->startTime();
   68 
   69     gp1->parser_ = MetGmCommentAttributeParser::createMetGmCommentAttributeParser(pCdmReader);
   70 
   71     // set analysis date time
   72     if(!gp1->parser_->analysisDateTime().empty()) {
   73 
   74         const std::string a_date(gp1->parser_->analysisDateTime());
   75         const FimexTime analysis = string2FimexTime(a_date);
   76 
   77         TimeUnit tu("seconds since 1970-01-01 00:00:00");
   78         double unit_time = tu.fimexTime2unitTime(analysis);
   79         gp1->analysis_t = tu.unitTime2epochSeconds(unit_time);
   80     } else {
   81         gp1->analysis_t = gp1->tTag_->analysisTime();
   82     }
   83 
   84     CDMAttribute metgmFreeTextAttribute;
   85     gp1->freeText_= std::string("comment---------------------------------");
   86     if(!gp1->parser_->freeText().empty()) {
   87         /* value from xml */
   88         gp1->freeText_ = gp1->parser_->freeText();
   89     } else if(cdmRef.getAttribute(cdmRef.globalAttributeNS(), FREE_TEXT, metgmFreeTextAttribute)) {
   90         /* value from cdm model */
   91         gp1->freeText_ = metgmFreeTextAttribute.getStringValue();
   92     }
   93 
   94     CDMAttribute metgmDataTypeAttribute;
   95     gp1->dataType_ = 4;
   96     if(!gp1->parser_->dataType().empty()) {
   97         /* value from xml */
   98         gp1->dataType_ = string2type<unsigned int>(gp1->parser_->dataType().c_str());
   99     } else if(cdmRef.getAttribute(cdmRef.globalAttributeNS(), DATA_TYPE, metgmDataTypeAttribute)) {
  100         /* value from cdm model */
  101         gp1->dataType_ = string2type<unsigned int>(metgmDataTypeAttribute.getStringValue().c_str());
  102     }
  103 
  104     CDMAttribute metgmModelTypeAttribute;
  105     gp1->modelType_= std::string("----------------");
  106     if(!gp1->parser_->modelType().empty()) {
  107         /* value from xml */
  108         gp1->modelType_ = gp1->parser_->modelType();
  109     } else if(cdmRef.getAttribute(cdmRef.globalAttributeNS(), MODEL_TYPE, metgmModelTypeAttribute)) {
  110         /* value from cdm model */
  111         gp1->modelType_ = metgmModelTypeAttribute.getStringValue();
  112     }
  113 
  114     CDMAttribute metgmProductNationAttribute;
  115     gp1->productNation_ = "NOR";
  116     if(!gp1->parser_->productNation().empty()) {
  117         /* value from xml */
  118         gp1->productNation_ = gp1->parser_->productNation();
  119     } else if(cdmRef.getAttribute(cdmRef.globalAttributeNS(), PRODUCTION_NATION, metgmProductNationAttribute)) {
  120         /* value from cdm model */
  121         gp1->productNation_ = metgmProductNationAttribute.getStringValue();
  122     }
  123 
  124     return gp1;
  125 }
  126 
  127     std::string MetGmGroup1Ptr::dataTypeAsString()
  128     {
  129         switch(dataType()) {
  130         case 0:
  131             return std::string("0"); //("0 - Climatological Data");
  132         case 1:
  133             return std::string("1"); //("1 - Numerical weather analysis");
  134         case 2:
  135             return std::string("2"); //("2 - Numerical weather prediction");
  136         case 3:
  137             return std::string("3"); //("3 - Observations");
  138         case 4:
  139             return std::string("4");  //("4 - Compound data");
  140         case 5:
  141             return std::string("5");  //("5 - REQGM");
  142         default:
  143             return std::string();
  144         };
  145         return std::string();
  146     }
  147 
  148 }