Esempio n. 1
0
		ParametersMap MapRequest::run( std::ostream& stream, const Request& request ) const
		{
			if (!_map.get())
			{
				return ParametersMap();
			}

			// Prepare the map (once for all renderings!)
			_map->prepare ();

			// Create a temporary file name based on system time
			const filesystem::path tempDir(MapModule::GetParameter (MapModule::PARAM_HTTP_TEMP_DIR), filesystem::native);

			RenderingConfig conf;

			// Choose the renderer
			boost::shared_ptr<Renderer> renderer(Factory<Renderer>::create(_output));

			// Generate an id for the map file based on current time
			ptime timems (boost::date_time::microsec_clock<ptime>::local_time ());
			std::string filePrefix = "map_" + to_iso_string (timems);

			std::string resultFilename = renderer->render (tempDir, filePrefix, _temporaryEnvironment.getRegistry<JourneyPattern>(), *_map, conf);

			// Broadcast of the result
			std::string resultURL = MapModule::GetParameter (MapModule::PARAM_HTTP_TEMP_URL)
			    + "/" + resultFilename;

			// Send the URL to the the generated local JPEG file.
			stream << resultURL;

			Log::GetInstance ().debug ("Sent result url " + resultURL);

			return ParametersMap();
		}
Esempio n. 2
0
void save(Archive & ar, 
          const ::boost::gregorian::date & d, 
          unsigned int /* version */)
{
  std::string ds = to_iso_string(d);
  ar & make_nvp("date", ds);
}
void MainApplication::createCrashIndicationFile(void)
{
    BoostPath TheFilePath(getCrashIndicationFilePath());
    if(!boost::filesystem::exists(TheFilePath))
    {
        std::ofstream IndicatorFile(TheFilePath.string().c_str());
        IndicatorFile << to_iso_string(_DateTimeRun);
        IndicatorFile.close();
    }
}
 /*!\ingroup time_format
  */
 inline
 std::string to_iso_string(ptime t)
 {
   std::string ts = gregorian::to_iso_string(t.date());// + "T";
   if(!t.time_of_day().is_special()) {
     return ts + "T" + to_iso_string(t.time_of_day());
   }
   else {
     return ts;
   }
 }
Esempio n. 5
0
int main()
{
	
	std::cout << "Hello world!" << std::endl;
	while (true)
	{
		ptime now = second_clock::local_time();
		date today = now.date();
		std::cout << to_simple_string(now) << std::endl;
		std::cout << to_iso_string(now) << std::endl;
		
	}
	
	return 0;
}
Esempio n. 6
0
 std::string pack(InfoHolder::DirectoryContainer<std::string>& backup_dir) {
   
   const std::string find_options = " -follow -depth -print ";
   const std::string cpio_options = " cpio --verbose -o -a -O ";
   boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
   const std::string archive_name = "OKBackup_" + to_iso_string(now) + ".cpio";
   backup_dir.archive(archive_name);
   const std::string command = "find " + backup_dir.source() + find_options + '|' + cpio_options + archive_name;
   
   std::cout << command << '\n';
   SystemHandling::System_bash S;
   SystemHandling::SystemOutput Out = S(command);
   if (not bool(Out)) throw Backup::Error::Command_Error("Unable to create archive file!");
   std::string on_stdout = Out;
   return on_stdout;
 }
Esempio n. 7
0
fs::path JobDir::deliver(
  std::string const& contents,
  std::string const& tag
)
{
  pt::ptime t = universal_time();
  std::string file_name(to_iso_string(t));
  assert(
    file_name.size() == 15
    || file_name.size() == (unsigned)16 + pt::time_duration::num_fractional_digits()
  );

  if (file_name.size() == 15) { // without fractional seconds
    file_name += '.';
    file_name += std::string(pt::time_duration::num_fractional_digits(), '0');
  }

  file_name += '_';
  file_name += m_impl->id_str;
  if (!tag.empty()) {
    file_name += '_';
    file_name += tag;
  }

  fs::path const file(file_name, fs::native);
  fs::path tmp_path;
  fs::path new_path;
  try {
    tmp_path = m_impl->tmp_dir / file;
    new_path = m_impl->new_dir / file;
  } catch (boost::filesystem::filesystem_error const& e) {
    throw JobDirError(e.what());
  }

  fs::ofstream tmp_file(tmp_path);
  if (!tmp_file) {
    std::string msg("create failed for ");
    msg += tmp_path.string();
    msg += " (" + boost::lexical_cast<std::string>(errno) + ')';
    throw JobDirError(msg);
  }

  tmp_file << contents << std::flush;
  if (!tmp_file) {
    std::string msg("write failed for ");
    msg += tmp_path.string();
    msg += " (" + boost::lexical_cast<std::string>(errno) + ')';
    throw JobDirError(msg);
  }

  tmp_file.close(); // sync too? yes, rename doesn't sync (TODO)

  bool e = std::rename(tmp_path.string().c_str(), new_path.string().c_str());
  if (e) {
    std::string msg("rename failed for ");
    msg += tmp_path.string();
    msg += " (" + boost::lexical_cast<std::string>(errno) + ')';
    throw JobDirError(msg);
  }

  return new_path;
}
std::string ModelSerializer::pathForTimeStep(ptime time) const {
	return boost::str(boost::format("%2%/%1%-cd3-state.xml") % to_iso_string(time) % dir);
}
Esempio n. 9
0
bool Fits2D::writeFits(Mat img, ImgBitDepth imgType, string fileName, string compression) {

    int status = 0;

    long  firstPixel, nbelements;

    // 2-dimensional image.
    long naxis = 2;

    // Image size.
    long naxes[2] = { img.cols, img.rows };

    // First pixel to write.
    firstPixel = 1;

    // Number of pixels to write.
    nbelements = naxes[0] * naxes[1];

    // Fits creation date : 'YYYY-MM-JJTHH:MM:SS.SS'
    boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time();
    kDATE = to_iso_extended_string(time);

    // Date in the fits filename.
    string dateFileName = TimeDate::getYYYYMMDDThhmmss(to_iso_string(time));

    // Define CRPIX1 and CRPIX2
    kCRPIX1 = (int)naxes[0] / 2;
    kCRPIX2 = (int)naxes[1] / 2;

    fitsfile *fptr;

    const char * filename;
    const char * filename2;


    // Creation of the fits filename.
    string pathAndname = "";

    if(fileName != ""){

        pathAndname = mFitsPath + fileName  + ".fit";
        kFILENAME = fileName + ".fit";

    }else{

        pathAndname = mFitsPath + kTELESCOP + "_" + dateFileName + "_UT.fit";
        kFILENAME = kTELESCOP + "_" +  dateFileName + "_UT.fit";

    }

    filename = pathAndname.c_str();
    pathAndname += compression;
    filename2 = pathAndname.c_str();

    switch(imgType){

        // UC8
        case 0:
        {
            //https://www-n.oca.eu/pichon/Tableau_2D.pdf
            unsigned char ** tab = (unsigned char * *)malloc( img.rows * sizeof(unsigned char *)) ;

            if(tab == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned char** array (NULL).";
                return false;

            }

            tab[0] = (unsigned char  *) malloc( naxes[0] * naxes[1] * sizeof(unsigned char) ) ;

            if(tab[0] == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned char* array (NULL).";
                return false;

            }

            for( int a = 1; a<naxes[1]; a++ ){

                tab[a] = tab[a-1] + naxes[0];
            }

            // Delete old file if it already exists.
            remove(filename);

            // Create new FITS file.
            if(fits_create_file(&fptr, filename2, &status)){

                 printerror(status);
                 free(tab[0]);
                 return false;

            }

            if (fits_create_img(fptr, BYTE_IMG, naxis, naxes, &status)){

                 printerror(status);
                 free(tab[0]);
                 return false;

            }

            // Initialize the values in the fits image with the mat's values.
             for ( int j = 0; j < naxes[1]; j++){

                 unsigned char * matPtr = img.ptr<unsigned char>(j);

                 for ( int i = 0; i < naxes[0]; i++){

                     // Affect a value and inverse the image.
                     tab[img.rows-1-j][i] = (unsigned char)matPtr[i];

                }
            }

            // Write the array of unsigned short to the FITS file.
            if(fits_write_img(fptr, TBYTE, firstPixel, nbelements, tab[0], &status)){

                 printerror(status);
                 free(tab[0]);
                 return false;

            }

            // Free previously allocated memory.
            free(tab[0]);

            break;
        }

        case 1:
        {
            //https://www-n.oca.eu/pichon/Tableau_2D.pdf
            char ** tab = (char * *) malloc( img.rows * sizeof( char * ) ) ;

            if(tab == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate char** array (NULL).";
                return false;

            }

            tab[0] = (char *) malloc( naxes[0] * naxes[1] * sizeof(char) ) ;

            if(tab[0] == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate char* array (NULL).";
                return false;

            }

            for( int a = 1; a<naxes[1]; a++ ){

                tab[a] = tab[a-1] + naxes[0];
            }

            // Delete old file if it already exists.
            remove(filename);

            // Create new FITS file.
            if(fits_create_file(&fptr, filename2, &status)){

                 printerror(status);
                 free(tab[0]);
                 return false;

            }


            if(fits_create_img(fptr,  SBYTE_IMG, naxis, naxes, &status)){

                 printerror(status);
                 free(tab[0]);
                 return false;

            }

            // Initialize the values in the fits image with the mat's values.
             for( int j = 0; j < naxes[1]; j++){

                 char * matPtr = img.ptr<char>(j);

                 for(int i = 0; i < naxes[0]; i++){

                     // Affect a value and inverse the image.
                     tab[img.rows-1-j][i] = (char)matPtr[i];

                }
            }

            // Write the array of unsigned short to the FITS file.
             if(fits_write_img(fptr, TSBYTE, firstPixel, nbelements, tab[0], &status)){

                 printerror(status);
                 free(tab[0]);
                 return false;

            }

            // Free previously allocated memory.
            free(tab[0]);

            break;
        }

        case 2 :
        {

            //https://www-n.oca.eu/pichon/Tableau_2D.pdf
            unsigned short ** tab = (unsigned short * *) malloc( img.rows * sizeof( unsigned short * ) ) ;

            if(tab == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned short** array (NULL).";
                return false;

            }

            tab[0] = (unsigned short  *) malloc( naxes[0] * naxes[1] * sizeof(unsigned short) ) ;

            if(tab[0] == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate unsigned short* array (NULL).";
                return false;

            }

            for( int a = 1; a<naxes[1]; a++ ){

              tab[a] = tab[a-1] + naxes[0];
            }

            // Delete old file if it already exists.
            remove(filename);

            // Create new FITS file.
            if (fits_create_file(&fptr, filename2, &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;

            }

            if ( fits_create_img(fptr,  USHORT_IMG, naxis, naxes, &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            // Initialize the values in the fits image with the mat's values.
            for ( int j = 0; j < naxes[1]; j++){

                 unsigned short * matPtr = img.ptr<unsigned short>(j);

                 for ( int i = 0; i < naxes[0]; i++){

                     // Affect a value and inverse the image.
                     tab[img.rows-1-j][i] = (unsigned short)matPtr[i];
                }
            }

            // write the array of unsigned short to the FITS file
            if ( fits_write_img(fptr, TUSHORT, firstPixel, nbelements, tab[0], &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            // Free previously allocated memory.
            free( *tab);
            free( tab );

            break;

        }

        case 3 :
        {

            Mat newMat;

            if(img.type() == CV_16UC1) {

                // Convert unsigned short type image in short type image.
                newMat = Mat(img.rows, img.cols, CV_16SC1, Scalar(0));

                // Set bzero and bscale for print unsigned short value in soft visualization.
                kBZERO = 32768;
                kBSCALE = 1;

                unsigned short * ptr;
                short * ptr2;

                for(int i = 0; i < img.rows; i++){

                    ptr = img.ptr<unsigned short>(i);
                    ptr2 = newMat.ptr<short>(i);

                    for(int j = 0; j < img.cols; j++){

                        if(ptr[j] - 32768 > 32767){

                            ptr2[j] = 32767;

                        }else{

                            ptr2[j] = ptr[j] - 32768;
                        }
                    }
                }

            }else{

                img.copyTo(newMat);

            }

            //https://www-n.oca.eu/pichon/Tableau_2D.pdf
            short ** tab = (short * *) malloc( img.rows * sizeof( short * ) ) ;

            if(tab == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate short** array (NULL).";
                return false;

            }

            tab[0] = (short  *) malloc( naxes[0] * naxes[1] * sizeof(short) ) ;

            if(tab[0] == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate short* array (NULL).";
                return false;

            }

            for( int a = 1; a<naxes[1]; a++ ){

              tab[a] = tab[a-1] + naxes[0];
            }

            // Delete old file if it already exists.
            remove(filename);

            // Create new FITS file.
            if (fits_create_file(&fptr, filename2, &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }


            if ( fits_create_img(fptr,  SHORT_IMG, naxis, naxes, &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            // Initialize the values in the fits image with the mat's values.
            for ( int j = 0; j < naxes[1]; j++){

                 short * matPtr = newMat.ptr<short>(j);

                 for ( int i = 0; i < naxes[0]; i++){

                     // Affect a value and inverse the image.
                     tab[newMat.rows-1-j][i] = (short)matPtr[i];
                }
            }

            // write the array of signed short to the FITS file
            if ( fits_write_img(fptr, TSHORT, firstPixel, nbelements, tab[0], &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            // Free previously allocated memory.
            free( *tab);
            free( tab );

            break;

        }

        case 4 :
        {

            //https://www-n.oca.eu/pichon/Tableau_2D.pdf
            float ** tab = (float * *) malloc( img.rows * sizeof( float * ) ) ;

            if(tab == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate float** array (NULL).";
                return false;
            }

            tab[0] = (float *) malloc( naxes[0] * naxes[1] * sizeof(float) ) ;

            if(tab[0] == NULL){

                BOOST_LOG_SEV(logger, fail) << "Fail to allocate float* array (NULL).";
                return false;
            }

            for( int a = 1; a<naxes[1]; a++ ){

                tab[a] = tab[a-1] + naxes[0];
            }

            // Delete old file if it already exists.
            remove(filename);

            // Create new FITS file
            if(fits_create_file(&fptr, filename, &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            if( fits_create_img(fptr,  FLOAT_IMG, naxis, naxes, &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            // Initialize the values in the fits image with the mat's values.
            for( int j = 0; j < naxes[1]; j++){

                 float * matPtr = img.ptr<float>(j);

                 for ( int i = 0; i < naxes[0]; i++){

                     // Affect a value and inversed the image.
                     tab[img.rows-1-j][i] = (float)matPtr[i];
                 }
            }

            // Write the array of unsigned short to the FITS file.
            if( fits_write_img(fptr, TFLOAT, firstPixel, nbelements, tab[0], &status)){

                 printerror(status);
                 free( *tab);
                 free( tab );
                 return false;
            }

            // Free previously allocated memory.
            free(*tab);
            free(tab);


            break;
        }

    }

    if(!writeKeywords(fptr)){

        if(fits_close_file(fptr, &status)){

             printerror(status);
        }

        return false;
    }

    if(fits_close_file(fptr, &status)){

        printerror(status);
        return false;
    }

    return true;
}
string StorageConverter::convertTaskPtimeDurationToString(time_duration myDuration){
	string convertedPtimeDuration = to_iso_string(myDuration);
	return convertedPtimeDuration;
}
//convert ptime to string
string StorageConverter::convertTaskPtimeToString(ptime myDatetime){
	string convertedPtimeString = to_iso_string(myDatetime); 
	return convertedPtimeString;
}