Esempio n. 1
0
long Universe::getClassPathExt(vector<StdString>& tokens,
        const StdString& arg) const {
#define EXT_TOKENS 2
    long result = ERR_SUCCESS;
    long fpIndex = arg.find_last_of(fileSeparator);
    long ssepIndex = arg.find(".som");

    if (fpIndex == StdString::npos) { //no new path
        //different from CSOM (see also HandleArguments):
        //we still want to strip the suffix from the filename, so
        //we set the start to -1, in order to start the substring
        //from character 0. npos is -1 too, but this is to make sure
        fpIndex = -1;
        //instead of returning here directly, we have to remember that
        //there is no new class path and return it later
        result = ERR_FAIL;
    } else
        tokens[0] = arg.substr(0, fpIndex);

    //adding filename (minus ".som" if present) to second slot
    ssepIndex =
            ((ssepIndex != StdString::npos) && (ssepIndex > fpIndex)) ?
                    (ssepIndex - 1) : arg.length();
    tokens[1] = arg.substr(fpIndex + 1, ssepIndex - (fpIndex));
    return result;
}
Esempio n. 2
0
StdString OracleWriter::getDateFormatString(StdString const &oValue, bool bTimestamp) const
{
    StdString pattern = "0000-00-00 00:00:00";

    if(oValue.length() == 10)
        return "YYYY.MM.DD";

    if(oValue.length() >= 19 || bTimestamp == false)
        return "YYYY.MM.DD HH24:MI:SS";

    pattern += ".";
    StdString format = "YYYY.MM.DD HH24:MI:SS.";

    StdString v = oValue.substr(pattern.length(), oValue.length());
    for(size_t i = 0; i < v.length(); i++)
    {
        if(v[i] >= '0' && v[i] <= '9')
        {
            format += 'F';
            continue;
        }
        break;
    }

    return format;
}
Esempio n. 3
0
StdString SociContainer::selectorToQuery(void)
{
	StdString q = getSelector();
	if(q.length() == 0)
		return q;

	if(q[0] == '{' && q != "{}" && q.length() > 1)
		q = "select * from "+ q.substr(1, q.length()-2);
	else
		q = mQuery;

	return q;
}
Esempio n. 4
0
void SociContainer::setSelector(StdString const &oId)
{
	Progress prg("Loading from Table ...");

	if(oId.length() > 0 && oId[0] == '{') // If it is a table we select it
	{
		mTablename = oId.substr(1, oId.length()-2);
		selectTable(mTablename, false);
	}
	else
		mTablename = "";

	super::setSelector(oId);
	refreshPreview(selectorToQuery(), mPreviewLimit);
}
Esempio n. 5
0
	/**
	 * 計測データをHTTPのGETメソッドのパラメータとして出力します。
	 * http://example.jp/record.cgi?temp=25.543&humid=45.123 のような形式でアクセスします。
	 */
	void OutputToHTTP(const SYSTEMTIME &currTime, double temp, double humid)
	{
		if(outputHTTPURL_.empty()){
			return;
		}

		///@todo ポート指定できるようにする。
		///@todo 先頭に http:// と入れても大丈夫なようにする。
		const StdString::size_type firstSlashPos = outputHTTPURL_.find_first_of('/');
		const StdString destHostName = (firstSlashPos != StdString::npos) ? outputHTTPURL_.substr(0, firstSlashPos) : outputHTTPURL_;
		const StdString destURL      = (firstSlashPos != StdString::npos) ? outputHTTPURL_.substr(firstSlashPos) : "/";

		struct Local
		{
			static bool connectToHost(SOCKET &sock, const char *hostname)
			{
				sockaddr_in server;
				server.sin_family = AF_INET;
				server.sin_port = htons(80);
				server.sin_addr.S_un.S_addr = inet_addr(hostname);

				if(server.sin_addr.S_un.S_addr == 0xffffffff) {
					hostent *host = gethostbyname(hostname);
					if(host == NULL){
						return false;
					}

					unsigned int **addrptr = (unsigned int **)host->h_addr_list;
					for(; *addrptr != NULL; ++addrptr){
						server.sin_addr.S_un.S_addr = *(*addrptr);

						if(connect(sock, (sockaddr *)&server, sizeof(server)) == 0){
							break;
						}
					}
					if(*addrptr == NULL){
						return false;
					}
				}
				else{
					if (connect(sock, (sockaddr *)&server, sizeof(server)) != 0){
						return false;
					}
				}
				return true;
			}
		};

		SOCKET sock;
		sock = socket(AF_INET, SOCK_STREAM, 0);
		if(sock != INVALID_SOCKET) {

			// 接続
			if(Local::connectToHost(sock, destHostName.c_str())){

				// リクエスト作成
				char requestParams[1024];
				std::sprintf(requestParams, "?temp=%lf&humid=%lf", temp, humid);
				std::string request = std::string("GET ") + destURL + requestParams + " HTTP/1.0\r\n\r\n";

				// HTTPリクエスト送信
				bool error = false;
				int n = send(sock, request.c_str(), request.size(), 0);
				if(n < 0) {
					error = true;
				}

				// HTTPメッセージ受信
				std::string result;
				while(n > 0){
					char buf[128];
					n = recv(sock, buf, sizeof(buf), 0);
					if(n < 0) {
						error = true;
						break;
					}

					// 受信結果
					result.append(buf, n);
				}
			}

			closesocket(sock);
		}
	}
Esempio n. 6
0
   /*!
   \brief Create header of netcdf file
   There are some information to fill in header of each netcdf.
   */
   void CFile::createHeader(void)
   {
      CContext* context = CContext::getCurrent();
      CContextServer* server = context->server;

      if (!allDomainEmpty)
      {
         StdString filename = getFileOutputName();

// determine splitting format in the file name  : firstPart%start_date%middlePart%end_date%lastPart

         std::string strStartDate="%start_date%" ;
         std::string strEndDate="%end_date%" ;

         std::string firstPart ;
         std::string middlePart ;
         std::string lastPart ;
         size_t pos1, pos2 ;
         bool hasStartDate=false ;
         bool hasEndDate=false ;
         bool hasSplit = (!split_freq.isEmpty());
                  
         pos1=filename.find(strStartDate) ;
         if (pos1!=std::string::npos)
         {
           firstPart=filename.substr(0,pos1) ;
           pos1+=strStartDate.size() ;
           hasStartDate=true ;
         }
         else pos1=0 ;

         pos2=filename.find(strEndDate,pos1) ;
         if (pos2!=std::string::npos)
         {
           middlePart=filename.substr(pos1,pos2-pos1) ;           
           pos2+=strEndDate.size() ;
           lastPart=filename.substr(pos2,filename.size()-pos2) ;
           hasEndDate=true ;
         }
         else middlePart=filename.substr(pos1,filename.size()) ;

         if (!hasStartDate && !hasEndDate)
         {
           hasStartDate=true ;
           hasEndDate=true;
           firstPart=middlePart ;
           if (hasSplit) firstPart +="_";
           middlePart="-" ;
         }
   
         StdOStringStream oss;

         if (!split_freq.isEmpty())
         {
           CDate split_start ;
           CDate splitEnd ;
           if (!split_start_offset.isEmpty()) split_start=lastSplit + split_start_offset ;
           else split_start=lastSplit ;

           splitEnd = lastSplit + split_freq ;
           if (!split_last_date.isEmpty())
           {
             CDate splitLastDate=CDate::FromString(split_last_date,*CContext::getCurrent()->getCalendar()) ;
             if( splitLastDate < splitEnd)  splitEnd=splitLastDate ;
           }
            
           if (!split_end_offset.isEmpty()) splitEnd = splitEnd + split_end_offset;
           else splitEnd = splitEnd - 1 * Second;

           string splitFormat;
           if (split_freq_format.isEmpty())
           {
             if (split_freq.getValue().second != 0) splitFormat = "%y%mo%d%h%mi%s";
             else if (split_freq.getValue().minute != 0) splitFormat = "%y%mo%d%h%mi";
             else if (split_freq.getValue().hour != 0) splitFormat = "%y%mo%d%h";
             else if (split_freq.getValue().day != 0) splitFormat = "%y%mo%d";
             else if (split_freq.getValue().month != 0) splitFormat = "%y%mo";
             else splitFormat = "%y";
           }
           else splitFormat = split_freq_format;

           oss << firstPart ;
           if (hasStartDate) oss << split_start.getStr(splitFormat) ;
           oss << middlePart ;
           if (hasEndDate) oss << splitEnd.getStr(splitFormat);
           oss << lastPart ;

           StdString keySuffix("CContext_"+CContext::getCurrent()->getId()+"::CFile_"+getFileOutputName()+"::") ; 
           context->registryOut->setKey(keySuffix+"splitStart", lastSplit);
           context->registryOut->setKey(keySuffix+"splitEnd",   splitEnd);
         }
         else oss<<firstPart<<lastPart ;

        bool append = !this->append.isEmpty() && this->append.getValue();

         bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic;
         bool useCFConvention = convention.isEmpty() || convention == convention_attr::CF;

         bool multifile = true;
         if (!type.isEmpty())
         {
           if (type == type_attr::one_file) multifile = false;
           else if (type == type_attr::multiple_file) multifile = true;

         }
#ifndef USING_NETCDF_PAR
         if (!multifile)
         {
            info(0) << "!!! Warning -> Using non parallel version of netcdf, switching in multiple_file mode for file : " << filename << " ..." << endl;
            multifile = true;
          }
#endif
         if (multifile)
         {
            int commSize, commRank;
            MPI_Comm_size(fileComm, &commSize);
            MPI_Comm_rank(fileComm, &commRank);

            if (server->intraCommSize > 1)
            {
              oss << "_" ;
              int width=0; int n = commSize-1;
              while (n != 0) { n = n / 10; width++;}
              if (!min_digits.isEmpty())
                if (width < min_digits) width = min_digits;
              oss.width(width);
              oss.fill('0');
              oss << right << commRank;
            }
         }
         oss << ".nc";

         bool isCollective = par_access.isEmpty() ||  par_access == par_access_attr::collective;

         if (isOpen) data_out->closeFile();

        data_out = shared_ptr<CDataOutput>(new CNc4DataOutput(this, oss.str(), append, useClassicFormat, useCFConvention,
                                                              fileComm, multifile, isCollective, time_counter_name));
        isOpen = true;

        data_out->writeFile(CFile::get(this));

        // Do not recreate the file structure if opening an existing file
        if (!data_out->IsInAppendMode())
        {
          std::vector<CField*>::iterator it, end = this->enabledFields.end();
          for (it = this->enabledFields.begin(); it != end; it++)
          {
            CField* field = *it;
            this->data_out->writeFieldGrid(field);
          }
          this->data_out->writeTimeDimension();

          for (it = this->enabledFields.begin(); it != end; it++)
          {
            CField* field = *it;
            this->data_out->writeFieldTimeAxis(field);
          }
          
          for (it = this->enabledFields.begin(); it != end; it++)
          {
            CField* field = *it;
            this->data_out->writeField(field);
          }

          vector<CVariable*> listVars = getAllVariables();
          for (vector<CVariable*>::iterator it = listVars.begin(); it != listVars.end(); it++)
            this->data_out->writeAttribute(*it);

          this->data_out->definition_end();
        }
        else
        {
          // check time axis even in append mode
          std::vector<CField*>::iterator it, end = this->enabledFields.end();
          for (it = this->enabledFields.begin(); it != end; it++)
          {
            CField* field = *it;
            this->data_out->writeFieldTimeAxis(field);
          }
        }
      }
   }