/*************************************************************************** almost_utils.cpp - description ------------------- begin : Wed Jun 1 20:59:30 2005 copyright : (C) 2002 by Cavalli Andrea email : cavalli@bioc.unizh.ch **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include namespace Almost { int tcp_get(string server, string port, string path); // std::ostream & aout = std::cout; std::ostream * almost::out = &std::cout; int almost::verbose_ = 1; void almost::log(string f){ if(out!=&std::cout){ delete out;} ofstream * fout = new ofstream; fout->open(f.c_str()); out = fout; if(!*out){ cout<<"LOGFILE not OPEN"< #include #endif int alm_rank(){ #ifdef ALM_MPI_FF return Almost::MPI::instance()->rank(); #endif return 0; } int alm_size(){ #ifdef ALM_MPI_FF return Almost::MPI::instance()->size(); #endif return 1; } double alm_wtime(){ #ifdef ALM_MPI_FF return MPI_Wtime(); #else double t; struct timeval buffer; struct timezone dummy; gettimeofday (&buffer, &dummy); t = (double)buffer.tv_sec + ((double)buffer.tv_usec*1.0e-6); return (t); #endif } extern "C" { void init_almost(){ Module mod = Module("almost","Environment"); mod.def_function("log","Redirect the output to a logfile.",&Almost::almost_log) ; mod.def_function("set_verbose","Set verbosity level.", &Almost::almost_set_verbose) ; mod.def_function("verbose","Get verbosity level.", &Almost::almost_get_verbose) ; mod.def_function("banner", "Prints almost banner. The text is redirected to standard output or a file according to the logfile settings.", &Almost::banner) ; mod.def_function("rank","Return MPI rank",alm_rank); mod.def_function("size","Return MPI size",alm_size); mod.def_function("walltime","Return Wall Time",alm_wtime); mod.def_function("home","Returns the path to the user home directory", Almost::home_dir); mod.def_function("http_get","Gets a file using the http protocol",&Almost::tcp_get); } }