Xmipp  v3.23.11-Nereus
Classes | Functions
General functions
Collaboration diagram for General functions:

Classes

class  Tabsinc
 
class  KaiserBessel
 
class  Timer
 
class  BaseListener
 
class  TextualListener
 

Functions

bool compareTwoFiles (const FileName &fn1, const FileName &fn2, size_t offset=0)
 binary comparison of two files skipping first "offset" bytes More...
 

Numerical functions

int solve_2nd_degree_eq (double a, double b, double c, double &x1, double &x2, double prec=XMIPP_EQUAL_ACCURACY)
 
double gaussian1D (double x, double sigma, double mu=0)
 
double tstudent1D (double x, double df, double sigma, double mu=0)
 
double icdf_gauss (double p)
 
double cdf_gauss (double x)
 
double cdf_tstudent (int k, double t)
 
double cdf_FSnedecor (int d1, int d2, double x)
 
double icdf_FSnedecor (int d1, int d2, double p)
 
double gaussian2D (double x, double y, double sigmaX, double sigmaY, double ang, double muX=0, double muY=0)
 

Miscellaneous functions

size_t divide_equally (size_t N, size_t size, size_t rank, size_t &first, size_t &last)
 
size_t divide_equally_group (size_t N, size_t size, size_t myself)
 
template<class T >
void computeStats (const std::vector< T > &V, double &avg, double &stddev, T &minval, T &maxval)
 
template<class T >
void computeAvgStddev (const std::vector< T > &V, double &avg, double &stddev)
 
template<class T >
void initConstant (std::vector< T > &V, T &value)
 

Complex functions

template<typename T >
void RealImag2Complex (const T *_real, const T *_imag, std::complex< double > *_complex, int length)
 
template<typename T >
void AmplPhase2Complex (const T *_ampl, const T *_phase, std::complex< double > *_complex, int length)
 
template<typename T >
void Complex2RealImag (const std::complex< double > *_complex, T *_real, T *_imag, int length)
 
template<typename T >
void Complex2AmplPhase (const std::complex< double > *_complex, T *_ampl, T *_phase, int length)
 

Random functions

These functions allow you to work in an easier way with the random functions of the Numerical Recipes. Only an uniform and a gaussian random number generators have been implemented. In fact only a uniform generator exists and the gaussian one is based on a call to it. For this reason, if you initialize the gaussian random generator, you are also initialising the uniform one.

Here goes an example for uniform random numbers to show how to use this set of functions.

// Initialise according to the clock
// Show 10 random numbers between -1 and 1
for (int i=0; i<10; i++)
std::cout << rnd_unif(-1,1) << std::endl;
void init_random_generator (int seed=-1)
 
unsigned int randomize_random_generator ()
 
double rnd_unif ()
 
double rnd_unif (double a, double b)
 
double rnd_student_t (double nu)
 
double rnd_student_t (double nu, double a, double b)
 
double rnd_gaus ()
 
double rnd_gaus (double a, double b)
 
double gaus_within_x0 (double x0, double mean=0, double stddev=1)
 
double gaus_outside_x0 (double x0, double mean=0, double stddev=1)
 
double gaus_up_to_x0 (double x0, double mean=0, double stddev=1)
 
double gaus_from_x0 (double x0, double mean=0, double stddev=1)
 
double student_outside_probb (double p, double degrees_of_freedom)
 
double student_within_t0 (double t0, double degrees_of_freedom)
 
double student_outside_t0 (double t0, double degrees_of_freedom)
 
double student_up_to_t0 (double t0, double degrees_of_freedom)
 
double student_from_t0 (double t0, double degrees_of_freedom)
 
double chi2_up_to_t0 (double t0, double degrees_of_freedom)
 
double chi2_from_t0 (double t0, double degrees_of_freedom)
 
double rnd_log (double a, double b)
 

Time managing

These functions are used to make time measures of the algorithms. If you know the total amount of work to do then some estimation can be done about how much time is left before finishing. The time functions are very machine dependent, we've tried to accommodate the compilation for several machines, but if still programs do not work, you may configure Xmipp to avoid these time measurements, functions are then substituted by null functions doing nothing.

// Variable declaration
// Beginning of the program
...
annotate_processor_time(&t0);
// Part to be measured
...
// End of part to be measured
print_elapsed_time(t0);

While for an estimation of time to go you can make it in two ways: one analytical, and another graphical.

Analytical:

// Variable declaration
double to_go;
// Beginning of the program
...
annotate_processor_time(&t0);
// Part to be measured
for (int i=0; i<60; i++)
{
...
// Compute the time to go with the fraction of work already done
to_go = time_to_go(t0, (double) (i + 1) / 60);
std::cout << "I think you will be here " << to_go << "seconds more\n";
}
// End of part to be measured

Alternatively:

// Variable declaration
double to_go;
// Part to be measured
for (int i=0; i<60; i++)
{
...
// Compute the time to go with the fraction of work already done
to_go = time_to_go(t0, (double) (i + 1) / 60);
std::cout << "I think you will be here " << to_go << "seconds more\n";
}
// End of part to be measured

Graphical:

// Beginning of the program
...
// Init the progress bar with the total amount of work to do
// It is very important that there is no print out to stdout but
// the progress bar
init_progress_bar(60);
// Part to be measured
for (int i=0; i<60; i++)
{
...
}
// In this case the following call is useless since it has been
// already done in the loop, but there are cases where a final call
// with the total amount of work is not performed and although the
// whole task has been finished it seems that it hasn't as the
// progress bar hasn't been called with the final work but with
// a quantity a little smaller.

These functions is not ported to Python.

typedef struct tms ProcessorTimeStamp
 
typedef size_t TimeStamp
 
void time_config ()
 
void annotate_processor_time (ProcessorTimeStamp *time)
 
void annotate_time (TimeStamp *time)
 
void acum_time (ProcessorTimeStamp *orig, ProcessorTimeStamp *dest)
 
double elapsed_time (ProcessorTimeStamp &time, bool _IN_SECS=true)
 
void print_elapsed_time (ProcessorTimeStamp &time, bool _IN_SECS=true)
 
void print_elapsed_time (TimeStamp &time, bool _IN_SECS=true)
 
double time_to_go (ProcessorTimeStamp &time, double fraction_done)
 
void init_progress_bar (long total)
 
void progress_bar (long act_time)
 
char * getCurrentTimeString ()
 
void TimeMessage (const std::string &message)
 

Little/Big endian

These set of functions helps you to deal with the little/big endian problems.

size_t xmippFREAD (void *dest, size_t size, size_t nitems, FILE *&fp, bool reverse=false)
 
size_t xmippFWRITE (const void *src, size_t size, size_t nitems, FILE *&fp, bool reverse=false)
 
void mapFile (const FileName &filename, char *&map, size_t &size, int &fileDescriptor, bool readOnly=true)
 
void unmapFile (char *&map, size_t &size, int &fileDescriptor)
 
void swapbytes (char *v, unsigned long n)
 
bool IsBigEndian (void)
 
void processMemUsage (double &vm_usage, double &resident_set)
 
bool IsLittleEndian (void)
 
void printMemoryUsed ()
 
#define little22bigendian(x)   swapbytes((unsigned char*)& x,sizeof(x))
 

Detailed Description

Macro Definition Documentation

◆ little22bigendian

#define little22bigendian (   x)    swapbytes((unsigned char*)& x,sizeof(x))

Conversion little-big endian

This function is not ported to Python.

Definition at line 1203 of file xmipp_funcs.h.

Typedef Documentation

◆ ProcessorTimeStamp

typedef struct tms ProcessorTimeStamp

Definition at line 822 of file xmipp_funcs.h.

◆ TimeStamp

typedef size_t TimeStamp

Definition at line 823 of file xmipp_funcs.h.

Function Documentation

◆ acum_time()

void acum_time ( ProcessorTimeStamp orig,
ProcessorTimeStamp dest 
)

Accumulate time

Initially dest_time should be set to orig time. Then you acumulate successive times calling this function (Destination time=destination_time + (now - original time)) and finally the elapsed time is the dest time minus the first one (the one which initiliazed the dest time.

This function is not ported to Python.

Definition at line 658 of file xmipp_funcs.cpp.

659 {
660  ProcessorTimeStamp now;
661  times(&now);
662  (*dest).tms_utime += (*dest).tms_utime + (now.tms_utime - (*orig).tms_utime);
663  (*dest).tms_stime += (*dest).tms_stime + (now.tms_utime - (*orig).tms_utime);
664 }
struct tms ProcessorTimeStamp
Definition: xmipp_funcs.h:822

◆ AmplPhase2Complex()

template<typename T >
void AmplPhase2Complex ( const T *  _ampl,
const T *  _phase,
std::complex< double > *  _complex,
int  length 
)

Amplitude/Phase –> Complex

The output array(s) must be already resized.

This function is not ported to Python.

Definition at line 431 of file xmipp_funcs.h.

435 {
436  T* aux_ampl = (T*) _ampl;
437  T* aux_phase = (T*) _phase;
438  double* aux_complex = (double*) _complex;
439 
440  for (int i = 0; i < length; i++)
441  {
442  double ampl = (double)(*aux_ampl++);
443  double phase = (double)(*aux_phase++);
444  *aux_complex++ = ampl * cos(phase);
445  *aux_complex++ = ampl * sin(phase);
446  }
447 }
#define i
__host__ __device__ float length(float2 v)

◆ annotate_processor_time()

void annotate_processor_time ( ProcessorTimeStamp time)

Annotate actual time

This annotation is used later to compute the elapsed time.

This function is not ported to Python.

Definition at line 640 of file xmipp_funcs.cpp.

641 {
642  times(time);
643 }

◆ annotate_time()

void annotate_time ( TimeStamp time)

Annotate actual time

This annotation is used later to compute the elapsed time.

This function is not ported to Python.

Definition at line 646 of file xmipp_funcs.cpp.

647 {
648  struct timeval tv;
649  gettimeofday(&tv, NULL);
650  struct tm tm;
651  localtime_r(&tv.tv_sec,&tm);
652  *time = tm.tm_hour * 3600 * 1000 + tm.tm_min * 60 * 1000 + tm.tm_sec * 1000 +
653  tv.tv_usec / 1000;
654 }

◆ cdf_FSnedecor()

double cdf_FSnedecor ( int  d1,
int  d2,
double  x 
)

Cumulative distribution function for a Snedecor's F-distribution.

This function returns the value of the CDF of a univariate Snedecor's F-distribution with d1, d2 degrees of freedom at the point x.

Definition at line 364 of file xmipp_funcs.cpp.

365 {
366  return betai(0.5*d1,0.5*d2,(d1*x)/(d1*x+d2));
367 }
double betai(double a, double b, double x)
doublereal * x

◆ cdf_gauss()

double cdf_gauss ( double  x)

Cumulative distribution function for a Gaussian

This function returns the value of the CDF of a univariate gaussian function at the point x.

Definition at line 241 of file xmipp_funcs.cpp.

242 {
243  return 0.5 * (1. + erf(x/sqrt(2.)));
244 }
void sqrt(Image< double > &op)
doublereal * x

◆ cdf_tstudent()

double cdf_tstudent ( int  k,
double  t 
)

Cumulative distribution function for a t-distribution

This function returns the value of the CDF of a univariate t-distribution with k degrees of freedom at the point t. Adapted by Sjors from: http://www.alglib.net/specialfunctions/distributions/student.php

Definition at line 287 of file xmipp_funcs.cpp.

288 {
289  double EPS=5E-16;
290  double result;
291  double x;
292  double rk;
293  double z;
294  double f;
295  double tz;
296  double p;
297  double xsqk;
298  int j;
299 
300  if ( t==0 )
301  {
302  result = 0.5;
303  return result;
304  }
305  if ( t<-2.0 )
306  {
307  rk = k;
308  z = rk/(rk+t*t);
309  result = 0.5*betai(0.5*rk, 0.5, z);
310  return result;
311  }
312  if ( t<0 )
313  {
314  x = -t;
315  }
316  else
317  {
318  x = t;
319  }
320  rk = k;
321  z = 1.0+x*x/rk;
322  if ( k%2 != 0 )
323  {
324  xsqk = x/sqrt(rk);
325  p = atan(xsqk);
326  if ( k > 1 )
327  {
328  f = 1.0;
329  tz = 1.0;
330  j = 3;
331  while ( j <= k-2 && tz/f > EPS )
332  {
333  tz = tz*((j-1)/(z*j));
334  f = f+tz;
335  j = j+2;
336  }
337  p = p+f*xsqk/z;
338  }
339  p = p*2.0/PI;
340  }
341  else
342  {
343  f = 1.0;
344  tz = 1.0;
345  j = 2;
346  while ( j<= k-2 && tz/f > EPS)
347  {
348  tz = tz*((j-1)/(z*j));
349  f = f+tz;
350  j = j+2;
351  }
352  p = f*x/sqrt(z*rk);
353  }
354  if ( t<0 )
355  {
356  p = -p;
357  }
358  result = 0.5+0.5*p;
359  return result;
360 }
double betai(double a, double b, double x)
void sqrt(Image< double > &op)
doublereal * x
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double * f
double z
#define j
constexpr long double EPS
#define PI
Definition: tools.h:43

◆ chi2_from_t0()

double chi2_from_t0 ( double  t0,
double  degrees_of_freedom 
)

chi2 area from t0 to inf

By default the chi2 mean is 0 and the chi2 standard deviation is 1. There is no restriction over the sign of t0

Definition at line 577 of file xmipp_funcs.cpp.

578 {
579  return 1 -chi2_up_to_t0(t0, degrees_of_freedom);
580 }
double chi2_up_to_t0(double t0, double degrees_of_freedom)

◆ chi2_up_to_t0()

double chi2_up_to_t0 ( double  t0,
double  degrees_of_freedom 
)

chi2 area from -inf to t0

By default the chi2 mean is 0 and the chi2 standard deviation is 1. There is no restriction over the sign of t0

Definition at line 572 of file xmipp_funcs.cpp.

573 {
574  return gammp(degrees_of_freedom / 2, t0 / 2);
575 }
double gammp(double a, double x)

◆ compareTwoFiles()

bool compareTwoFiles ( const FileName fn1,
const FileName fn2,
size_t  offset 
)

binary comparison of two files skipping first "offset" bytes

Compare two files

Definition at line 1183 of file xmipp_funcs.cpp.

1184 {
1185  char *map1,*map2;
1186  int fd1, fd2;
1187  size_t size1=-1, size2=-1;
1188  mapFile(fn1,map1,size1,fd1,true);
1189  mapFile(fn2,map2,size2,fd2,true);
1190  int result=memcmp(map1+offset,map2+offset,size1-offset);
1191  unmapFile(map1,size1,fd1);
1192  unmapFile(map2,size2,fd2);
1193  return (result==0);
1194 }
void unmapFile(char *&map, size_t &size, int &fileDescriptor)
void mapFile(const FileName &filename, char *&map, size_t &size, int &fileDescriptor, bool readOnly)

◆ Complex2AmplPhase()

template<typename T >
void Complex2AmplPhase ( const std::complex< double > *  _complex,
T *  _ampl,
T *  _phase,
int  length 
)

Complex –> Amplitude/Phase

The output array(s) must be already resized.

This function is not ported to Python.

Definition at line 479 of file xmipp_funcs.h.

483 {
484  T* aux_ampl = (T*) _ampl;
485  T* aux_phase = (T*) _phase;
486  double* aux_complex = (double*) _complex;
487 
488  for (int i = 0; i < length; i++)
489  {
490  double re = *aux_complex++;
491  double im = *aux_complex++;
492  *aux_ampl++ = sqrt(re * re + im * im);
493  *aux_phase++ = atan2(im, re);
494  }
495 }
void sqrt(Image< double > &op)
#define i
__host__ __device__ float length(float2 v)

◆ Complex2RealImag()

template<typename T >
void Complex2RealImag ( const std::complex< double > *  _complex,
T *  _real,
T *  _imag,
int  length 
)

Complex –> Real/Imag

The output array(s) must be already resized.

This function is not ported to Python.

Definition at line 456 of file xmipp_funcs.h.

460 {
461  T* aux_real = (T*) _real;
462  T* aux_imag = (T*) _imag;
463  double* aux_complex = (double*) _complex;
464 
465  for (int i = 0; i < length; i++)
466  {
467  *aux_real++ = (T)(*aux_complex++);
468  *aux_imag++ = (T)(*aux_complex++);
469  }
470 }
#define i
__host__ __device__ float length(float2 v)

◆ computeAvgStddev()

template<class T >
void computeAvgStddev ( const std::vector< T > &  V,
double &  avg,
double &  stddev 
)

Compute statistics of a std::vector

Definition at line 358 of file xmipp_funcs.h.

359 {
360  if (V.size()<= 0)
361  return;
362 
363  avg = 0;
364  stddev = 0;
365 
366  size_t nmax=V.size();
367  const T* ptr=&V[0];
368  for(size_t n=0; n<nmax; ++n, ++ptr)
369  {
370  double val=*ptr;
371  avg += val;
372  stddev += val * val;
373  }
374  avg /= nmax;
375 
376  if (nmax > 1)
377  {
378  stddev = stddev / nmax - avg * avg;
379  stddev *= nmax / (nmax - 1);
380 
381  // Foreseeing numerical instabilities
382  stddev = sqrt(static_cast< double >(ABS(stddev)));
383  }
384  else
385  stddev = 0;
386 }
int * nmax
void sqrt(Image< double > &op)
#define ABS(x)
Definition: xmipp_macros.h:142
int * n

◆ computeStats()

template<class T >
void computeStats ( const std::vector< T > &  V,
double &  avg,
double &  stddev,
T &  minval,
T &  maxval 
)

Compute statistics of a std::vector

Definition at line 317 of file xmipp_funcs.h.

319 {
320  if (V.size()<= 0)
321  return;
322 
323  avg = 0;
324  stddev = 0;
325 
326  minval = maxval = V[0];
327 
328  size_t nmax=V.size();
329  const T* ptr=&V[0];
330  for(size_t n=0; n<nmax; ++n, ++ptr)
331  {
332  double val=*ptr;
333  avg += val;
334  stddev += val * val;
335 
336  if (val > maxval)
337  maxval = val;
338  else if (val < minval)
339  minval = val;
340  }
341  avg /= nmax;
342 
343  if (nmax > 1)
344  {
345  stddev = stddev / nmax - avg * avg;
346  stddev *= nmax / (nmax - 1);
347 
348  // Foreseeing numerical instabilities
349  stddev = sqrt(static_cast< double >(ABS(stddev)));
350  }
351  else
352  stddev = 0;
353 }
int * nmax
void sqrt(Image< double > &op)
#define ABS(x)
Definition: xmipp_macros.h:142
int * n

◆ divide_equally()

size_t divide_equally ( size_t  N,
size_t  size,
size_t  rank,
size_t &  first,
size_t &  last 
)

Divides a number into most equally groups

For example you want to distribute N jobs between M workers so each worker will have N/M jobs and some of them(N % M first) will have N/M + 1 jobs So for the worker 'rank' will be computed the first and last job to do Return the number of jobs assigned, that could be N/M + 1 or N/M

Divides a number into most equally groups

Definition at line 1150 of file xmipp_funcs.cpp.

1151 {
1152  size_t jobs_per_worker = N / size;
1153  size_t jobs_resting = N % size;
1154 
1155  if (rank < jobs_resting)
1156  {
1157  first = rank * (jobs_per_worker + 1);
1158  last = first + jobs_per_worker;
1159  }
1160  else
1161  {
1162  first = rank * jobs_per_worker + jobs_resting;
1163  last = first + jobs_per_worker - 1;
1164  }
1165 
1166  return last - first + 1;
1167 }
glob_log first

◆ divide_equally_group()

size_t divide_equally_group ( size_t  N,
size_t  size,
size_t  myself 
)

In which group (of divide_equally) is myself situated?

In which group from divide_equally is myself?

Definition at line 1169 of file xmipp_funcs.cpp.

1170 {
1171  size_t first, last;
1172  for (size_t rank = 0; rank < size; rank++)
1173  {
1174  divide_equally(N, size, rank, first, last);
1175  if (myself >= first && myself <= last)
1176  return rank;
1177  }
1178  return -1;
1179 
1180 }
size_t divide_equally(size_t N, size_t size, size_t rank, size_t &first, size_t &last)
glob_log first

◆ elapsed_time()

double elapsed_time ( ProcessorTimeStamp time,
bool  _IN_SECS = true 
)

Compute elapsed time since a given annotation

Given an annotation of time, this function computes the time elapsed since then in seconds. The annotation is not modified. Usually the time is shown in seconds, but you might specify to show it in clock ticks setting the variable _IN_SECS to FALSE.

...;
double elapsed = elapsed_time(t0);
...;
double elapsed = elapsed_time(t0, FALSE);

This function is not ported to Python.

Definition at line 739 of file xmipp_funcs.cpp.

740 {
741 #if !defined _NO_TIME && !defined __MINGW32__
742  ProcessorTimeStamp now;
743  times(&now);
744  double userTime = now.tms_utime - time.tms_utime;
745  double sysTime = now.tms_stime - time.tms_stime;
746  if (_IN_SECS)
747  {
748  userTime /= XmippTICKS;
749  sysTime /= XmippTICKS;
750  }
751  return userTime + sysTime;
752 #endif
753 }
int XmippTICKS
struct tms ProcessorTimeStamp
Definition: xmipp_funcs.h:822

◆ gaus_from_x0()

double gaus_from_x0 ( double  x0,
double  mean = 0,
double  stddev = 1 
)

Gaussian area from x0 to inf

By default the gaussian mean is 0 and the gaussian standard deviation is 1. There is no restriction over the sign of x0

Definition at line 499 of file xmipp_funcs.cpp.

500 {
501  if (x0 > mean)
502  return gaus_outside_x0(x0, mean, stddev) / 2;
503  else if (x0 == mean)
504  return 0.5;
505  else
506  return 1.0 -gaus_outside_x0(x0, mean, stddev) / 2;
507 }
#define x0
double gaus_outside_x0(double x0, double mean, double stddev)

◆ gaus_outside_x0()

double gaus_outside_x0 ( double  x0,
double  mean = 0,
double  stddev = 1 
)

Gaussian area outisde -x0 to x0

By default the gaussian mean is 0 and the gaussian standard deviation is 1. x0 must be positive

Definition at line 483 of file xmipp_funcs.cpp.

484 {
485  double z0 = (x0 - mean) / stddev;
486  return erfc(ABS(z0) / sqrt(2.0));
487 }
void sqrt(Image< double > &op)
#define z0
#define x0
#define ABS(x)
Definition: xmipp_macros.h:142

◆ gaus_up_to_x0()

double gaus_up_to_x0 ( double  x0,
double  mean = 0,
double  stddev = 1 
)

Gaussian area from -inf to x0

By default the gaussian mean is 0 and the gaussian standard deviation is 1. There is no restriction over the sign of x0

Definition at line 489 of file xmipp_funcs.cpp.

490 {
491  if (x0 > mean)
492  return 1.0 -gaus_outside_x0(x0, mean, stddev) / 2;
493  else if (x0 == mean)
494  return 0.5;
495  else
496  return gaus_outside_x0(x0, mean, stddev) / 2;
497 }
#define x0
double gaus_outside_x0(double x0, double mean, double stddev)

◆ gaus_within_x0()

double gaus_within_x0 ( double  x0,
double  mean = 0,
double  stddev = 1 
)

Gaussian area from -x0 to x0

By default the gaussian mean is 0 and the gaussian standard deviation is 1. x0 must be positive

Definition at line 477 of file xmipp_funcs.cpp.

478 {
479  double z0 = (x0 - mean) / stddev;
480  return erf(ABS(z0) / sqrt(2.0));
481 }
void sqrt(Image< double > &op)
#define z0
#define x0
#define ABS(x)
Definition: xmipp_macros.h:142

◆ gaussian1D()

double gaussian1D ( double  x,
double  sigma,
double  mu = 0 
)

1D gaussian value

This function returns the value of a univariate gaussian function at the point x.

Definition at line 181 of file xmipp_funcs.cpp.

182 {
183  x -= mu;
184  return 1 / sqrt(2*PI*sigma*sigma)*exp(-0.5*((x / sigma)*(x / sigma)));
185 }
void sqrt(Image< double > &op)
doublereal * x
int mu
#define PI
Definition: tools.h:43

◆ gaussian2D()

double gaussian2D ( double  x,
double  y,
double  sigmaX,
double  sigmaY,
double  ang,
double  muX = 0,
double  muY = 0 
)

2D gaussian value

This function returns the value of a multivariate (2D) gaussian function at the point (x,y) when the X axis of the gaussian is rotated ang (counter-clockwise) radians (the angle is positive when measured from the universal X to the gaussian X). X and Y are supposed to be independent.

Definition at line 197 of file xmipp_funcs.cpp.

199 {
200  // Express x,y in the gaussian internal coordinates
201  x -= muX;
202  y -= muY;
203  double xp = cos(ang) * x + sin(ang) * y;
204  double yp = -sin(ang) * x + cos(ang) * y;
205 
206  // Now evaluate
207  return 1 / sqrt(2*PI*sigmaX*sigmaY)*exp(-0.5*((xp / sigmaX)*(xp / sigmaX) +
208  (yp / sigmaY)*(yp / sigmaY)));
209 }
void sqrt(Image< double > &op)
static double * y
doublereal * x
#define PI
Definition: tools.h:43

◆ getCurrentTimeString()

char* getCurrentTimeString ( )

Function to get current time as string

Definition at line 861 of file xmipp_funcs.cpp.

862 {
863  time_t rawtime;
864  time ( &rawtime );
865  char * str = ctime (&rawtime);
866  char * pos = strrchr(str, '\n');
867  pos[0] = '\0'; //Remove \n end character
868  return str;
869 
870 }

◆ icdf_FSnedecor()

double icdf_FSnedecor ( int  d1,
int  d2,
double  p 
)

Inverse Cumulative distribution function for a Snedecor's F-distribution.

This function returns the value of the ICDF of a univariate Snedecor's F-distribution with d1, d2 degrees of freedom with probability p, i.e., it returns x such that CDF(d1,d2,x)=p

Definition at line 369 of file xmipp_funcs.cpp.

370 {
371  double xl=0, xr=1e6;
372  double xm, pm;
373  do
374  {
375  xm=(xl+xr)*0.5;
376  pm=cdf_FSnedecor(d1,d2,xm);
377  if (pm>p)
378  {
379  xr=xm;
380  }
381  else
382  {
383  xl=xm;
384  }
385  }
386  while (fabs(pm-p)/p>0.001);
387  return xm;
388 }
doublereal * xl
double cdf_FSnedecor(int d1, int d2, double x)

◆ icdf_gauss()

double icdf_gauss ( double  p)

Inverse Cumulative distribution function for a Gaussian

This function returns the z of a N(0,1) such that the probability below z is p

The function employs an fast approximation to z which is valid up to 1e-4. See http://www.johndcook.com/normal_cdf_inverse.html

Definition at line 212 of file xmipp_funcs.cpp.

213 {
214  const double c[] =
215  {
216  2.515517, 0.802853, 0.010328
217  };
218  const double d[] =
219  {
220  1.432788, 0.189269, 0.001308
221  };
222  if (p < 0.5)
223  {
224  // F^-1(p) = - G^-1(p)
225  double t=sqrt(-2.0*log(p));
226  double z=t - ((c[2]*t + c[1])*t + c[0]) /
227  (((d[2]*t + d[1])*t + d[0])*t + 1.0);
228  return -z;
229  }
230  else
231  {
232  // F^-1(p) = G^-1(1-p)
233  double t=sqrt(-2.0*log(1-p));
234  double z=t - ((c[2]*t + c[1])*t + c[0]) /
235  (((d[2]*t + d[1])*t + d[0])*t + 1.0);
236  return z;
237  }
238 }
doublereal * c
void sqrt(Image< double > &op)
doublereal * d
void log(Image< double > &op)
double z

◆ init_progress_bar()

void init_progress_bar ( long  total)

Initialise the progress bar

The progress bar is initialised to count for a total amount of work. For instance, if we are to do something 60 times, the progress bar should be initialised to that value. At the same time the bar is printed with the initial guess of time left (ie, nothing "0000/????"). The number before the slash is the elapsed time since initialisation of the progress bar, while the second number is the estimation of total time that this task will take. See Time managing for a more detailed example.

Definition at line 782 of file xmipp_funcs.cpp.

783 {
784  progress_bar(-(total));
785 }
void progress_bar(long rlen)

◆ init_random_generator()

void init_random_generator ( int  seed = -1)

Reset uniform random generator to a known point

If you initialize the random generator with this function each time, then the same random sequence will be generated

init_rnd_unif();
init_rnd_unif(17891)

Definition at line 394 of file xmipp_funcs.cpp.

395 {
396  idum = -1;
397  ran1(&idum);
398  if (seed != -1)
399  {
400  // Prevent seeds larger than 65000
401  seed %=0xffff;
402  for (int i = 0; i < seed; i++)
403  ran1(&idum);
404  }
405 }
#define i
double ran1(int *idum)
int idum

◆ initConstant()

template<class T >
void initConstant ( std::vector< T > &  V,
T &  value 
)

Initialize std::vector with constant value

Definition at line 390 of file xmipp_funcs.h.

391 {
392  const T* ptr=&V[0];
393  size_t nmax=V.size();
394  for(size_t n=0; n<nmax; ++n, ++ptr)
395  *ptr=value;
396 }
int * nmax
int * n

◆ IsBigEndian()

bool IsBigEndian ( void  )

Returns 1 if machine is big endian else 0

Returns true if machine is big endian else false

Definition at line 1092 of file xmipp_funcs.cpp.

1093 {
1094  static const unsigned long ul = 0x01000000;
1095  return ((int)(*((unsigned char *) &ul)))!=0;
1096 }

◆ IsLittleEndian()

bool IsLittleEndian ( void  )

Returns 1 if machine is little endian else 0 little-endian format (sometimes called the Intel format

Returns true if machine is little endian else false

Definition at line 1085 of file xmipp_funcs.cpp.

1086 {
1087  static const unsigned long ul = 0x00000001;
1088  return ((int)(*((unsigned char *) &ul)))!=0;
1089 }

◆ mapFile()

void mapFile ( const FileName filename,
char *&  map,
size_t &  size,
int &  fileDescriptor,
bool  readOnly = true 
)

Map file to memory.

If size is less than 0, then the whole file is mapped, and the size is correctly set to the file size.

Definition at line 970 of file xmipp_funcs.cpp.

971 {
972  if (size<0)
973  {
974  struct stat file_status;
975  if(stat(filename.c_str(), &file_status) != 0)
976  REPORT_ERROR(ERR_IO_NOPATH,"Cannot get filesize for file "+filename);
977  size = file_status.st_size;
978  }
979 #ifdef XMIPP_MMAP
980  struct stat file_status;
981  if(stat(filename.c_str(), &file_status) != 0)
982  REPORT_ERROR(ERR_IO_NOPATH,(String)"Cannot get filesize for file "+filename);
983  size = file_status.st_size;
984  if(size==0)
985  REPORT_ERROR(ERR_IO_NOPATH,(String)"File size=0, cannot read it ("+filename+")");
986 
987  if (readOnly)
988  fileDescriptor = open(filename.c_str(), O_RDONLY, S_IREAD);
989  else
990  fileDescriptor = open(filename.c_str(), O_RDWR, S_IREAD | S_IWRITE);
991  if (fileDescriptor == -1)
992  REPORT_ERROR(ERR_IO_NOPATH,(String)"Cannot open file named "+filename);
993 
994  if (readOnly)
995  map = (char *) mmap(0, size, PROT_READ, MAP_SHARED, fileDescriptor, 0);
996  else
997  map = (char *) mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
998  if (map == MAP_FAILED)
999  REPORT_ERROR(ERR_MEM_BADREQUEST,"Write can not map memory ");
1000 #else
1001 
1002  map = new char[size];
1003  fileDescriptor = open(filename.data(), O_RDONLY);
1004  if (fileDescriptor == -1)
1005  REPORT_ERROR(ERR_IO_NOPATH,(String)"Cannot open file named "+filename);
1006  int ok=read(fileDescriptor,map,size);
1007  if (ok==-1)
1008  REPORT_ERROR(ERR_IO_NOREAD,(String)"Cannot read from file named"+filename);
1009 #endif
1010 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Bad amount of memory requested.
Definition: xmipp_error.h:165
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
std::string String
Definition: xmipp_strings.h:34
Environment PATH cannot be read.
Definition: xmipp_error.h:143
file read(std::istream &is)
Definition: pdb2cif.cpp:6200

◆ print_elapsed_time() [1/2]

void print_elapsed_time ( ProcessorTimeStamp time,
bool  _IN_SECS = true 
)

Show on screen the elapsed time since a given annotation

The format of the printing is "Elapsed time: User(13) System(1)" that means that the user has used 13 seconds and the system 1, a total of 14 seconds since the last annotation in this TimeStamp variable.

Usually the time is shown in seconds, but you might specify to show it in clock ticks setting the variable _IN_SECS to FALSE.

This function is not ported to Python.

Definition at line 669 of file xmipp_funcs.cpp.

670 {
671  ProcessorTimeStamp now;
672  times(&now);
673  double userTime = now.tms_utime - time.tms_utime;
674  double sysTime = now.tms_stime - time.tms_stime;
675  if (_IN_SECS)
676  {
677  userTime /= XmippTICKS;
678  sysTime /= XmippTICKS;
679  }
680  std::cout << "Elapsed time: User(" << userTime << ") System(" << sysTime
681  << ")\n";
682 }
int XmippTICKS
struct tms ProcessorTimeStamp
Definition: xmipp_funcs.h:822

◆ print_elapsed_time() [2/2]

void print_elapsed_time ( TimeStamp time,
bool  _IN_SECS = true 
)

Show on screen the elapsed time since a given annotation

The format of the printing is "Elapsed time: User(13) System(1)" that means that the user has used 13 seconds and the system 1, a total of 14 seconds since the last annotation in this TimeStamp variable.

Usually the time is shown in seconds, but you might specify to show it in clock ticks setting the variable _IN_SECS to FALSE.

This function is not ported to Python.

Definition at line 685 of file xmipp_funcs.cpp.

686 {
687  struct timeval tv;
688  gettimeofday(&tv, NULL);
689  struct tm tm;
690  localtime_r(&tv.tv_sec,&tm);
691  TimeStamp now = tm.tm_hour * 3600 * 1000 + tm.tm_min * 60 * 1000 + tm.tm_sec * 1000 +
692  tv.tv_usec / 1000;
693  TimeStamp diff=now-time;
694 
695  std::cout << "Elapsed time: ";
696  if (_IN_SECS)
697  std::cout << diff/1000.0 << " secs." << std::endl;
698  else
699  std::cout << diff << " msecs." << std::endl;
700 }
size_t TimeStamp
Definition: xmipp_funcs.h:823

◆ printMemoryUsed()

void printMemoryUsed ( )

Print the memory used by this process.

Definition at line 1142 of file xmipp_funcs.cpp.

1143 {
1144  double virtualMemory, residentMemory;
1145  processMemUsage(virtualMemory, residentMemory);
1146  std::cout << "VM: " << virtualMemory << "kB ; RSS: " << residentMemory << " kB" << std::endl;
1147 }
void processMemUsage(double &vm_usage, double &resident_set)

◆ processMemUsage()

void processMemUsage ( double &  vm_usage,
double &  resident_set 
)

Definition at line 1105 of file xmipp_funcs.cpp.

1106 {
1107  using std::ios_base;
1108  using std::ifstream;
1109  using std::string;
1110 
1111  vm_usage = 0.0;
1112  resident_set = 0.0;
1113 
1114  // 'file' stat seems to give the most reliable results
1115  //
1116  ifstream stat_stream("/proc/self/stat",ios_base::in);
1117 
1118  // dummy vars for leading entries in stat that we don't care about
1119  //
1120  string pid, comm, state, ppid, pgrp, session, tty_nr;
1121  string tpgid, flags, minflt, cminflt, majflt, cmajflt;
1122  string utime, stime, cutime, cstime, priority, nice;
1123  string O, itrealvalue, starttime;
1124 
1125  // the two fields we want
1126  //
1127  unsigned long vsize;
1128  long rss;
1129 
1130  stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
1131  >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
1132  >> utime >> stime >> cutime >> cstime >> priority >> nice
1133  >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
1134 
1135  stat_stream.close();
1136 
1137  long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
1138  vm_usage = vsize / 1024.0;
1139  resident_set = rss * page_size_kb;
1140 }
int in

◆ progress_bar()

void progress_bar ( long  act_time)

Update progress bar

With this function you can change the already done amount of work, if something is to be done 60 times and now we have already done 13 then we could tell this to the progress bar with

The information that this thing was to be done 60 times was given at the initialisation of the progress bar. It is very important that during the use of the progress bar, nobody prints anything to stdout as it is being used by the progress bar. At the end you could make a call to progress_bar with the total amount of work just to make sure that the printout is pretty enough.

Definition at line 791 of file xmipp_funcs.cpp.

792 {
793  static time_t startt;
794  time_t currt;
795  static long totlen;
796  long t1, t2;
797  int min, i, hour;
798  double h1, h2, m1, m2;
799  bool queue = (getenv("XMIPP_IN_QUEUE") != NULL);
800 
801  if (rlen == 0)
802  return;
803  currt = time(NULL);
804 
805  if (rlen < 0)
806  {
807  totlen = -rlen;
808  startt = currt;
809  fprintf(stdout, "0000/???? sec. ");
810  if (!queue)
811  for (i = 0; i < 10; i++)
812  fprintf(stdout, "------");
813  fflush(stdout);
814  }
815  else if (totlen > 0)
816  {
817  t1 = currt - startt; // Elapsed time
818  t2 = (long)(t1 * (double)totlen / rlen); // Total time
819 
820  hour = 0;
821  min = 0;
822  if (t2 > 60)
823  {
824  m1 = (double)t1 / 60.0;
825  m2 = (double)t2 / 60.0;
826  min = 1;
827  if (m2 > 60)
828  {
829  h1 = (double)m1 / 60.0;
830  h2 = (double)m2 / 60.0;
831  hour = 1;
832  min = 0;
833  }
834  else
835  hour = 0;
836  }
837 
838  if (hour)
839  fprintf(stdout, "\r%3.2f/%3.2f %s ", h1, h2, "hours");
840  else if (min)
841  fprintf(stdout, "\r%3.2f/%3.2f %s ", m1, m2, "min");
842  else
843  fprintf(stdout, "\r%4u/%4u %4s ", (int)t1, (int)t2, "sec.");
844 
845  if (!queue)
846  {
847  i = (int)(60 * (1 - (double)(totlen - rlen) / totlen));
848  while (i--)
849  fprintf(stdout, ".");
850  }
851 
852  if (rlen == totlen)
853  {
854  fprintf(stdout, "\n");
855  totlen = 0;
856  }
857  fflush(stdout);
858  }
859 }
void min(Image< double > &op1, const Image< double > &op2)
#define i
fprintf(glob_prnt.io, "\)

◆ randomize_random_generator()

unsigned int randomize_random_generator ( )

Reset random generator according to the clock.

This time the initialisation itself assures a random sequence different each time the program is run. Be careful not to run the program twice within the same second as the initialisation will be the same for both runs. Returns seed.

Definition at line 407 of file xmipp_funcs.cpp.

408 {
409  static unsigned int seed;
410  int rand_return;
411  struct timespec highresTime;
412 
413 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
414 
415  clock_serv_t cclock;
416  mach_timespec_t mts;
417  host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
418  clock_get_time(cclock, &mts);
419  mach_port_deallocate(mach_task_self(), cclock);
420  highresTime.tv_sec = mts.tv_sec;
421  highresTime.tv_nsec = mts.tv_nsec;
422 #else
423 
424  clock_gettime(CLOCK_REALTIME, &highresTime);
425 #endif
426 
427  srand(rand()+clock()+time(NULL)+highresTime.tv_nsec);
428  rand_return = rand();
429 
430  time_t t;
431  time(&t);
432  //rand_return = abs(rand_return);
433  idum = (-(int)(t % 10000)
434  - (int)(rand_return % 10000));
435  ran1(&idum);
436  seed = (unsigned int)rand_return;
437  return seed;
438 }
double ran1(int *idum)
int idum

◆ RealImag2Complex()

template<typename T >
void RealImag2Complex ( const T *  _real,
const T *  _imag,
std::complex< double > *  _complex,
int  length 
)

Real/Imaginary –> Complex

The output array(s) must be already resized.

This function is not ported to Python.

Definition at line 408 of file xmipp_funcs.h.

412 {
413  T* aux_real = (T*) _real;
414  T* aux_imag = (T*) _imag;
415  double* aux_complex = (double*) _complex;
416 
417  for (int i = 0; i < length; i++)
418  {
419  *aux_complex++ = (double)(*aux_real++);
420  *aux_complex++ = (double)(*aux_imag++);
421  }
422 }
#define i
__host__ __device__ float length(float2 v)

◆ rnd_gaus() [1/2]

double rnd_gaus ( )

Produce a gaussian random number with mean 0 and standard deviation 1

std::cout << "This random number should follow N(0,1): " << rnd_gaus()
<< std::endl;

Definition at line 466 of file xmipp_funcs.cpp.

467 {
468  return gasdev(&idum);
469 }
double gasdev(int *idum)
int idum

◆ rnd_gaus() [2/2]

double rnd_gaus ( double  a,
double  b 
)

Produce a gaussian random number with mean a and standard deviation b

std::cout << "This random number should follow N(1,4): " << rnd_gaus(1,2)
<< std::endl;

Definition at line 470 of file xmipp_funcs.cpp.

471 {
472  if (b == 0)
473  return a;
474  else
475  return b*gasdev(&idum) + a;
476 }
doublereal * b
double gasdev(int *idum)
int idum
doublereal * a

◆ rnd_log()

double rnd_log ( double  a,
double  b 
)

Produce a log uniform random number between a and b

Watch out that the following inequation must hold 0<a<=b.

std::cout << "This random number should be between 1 and 1000: "
<< rnd_log(10,1000)<< std::endl;

Definition at line 583 of file xmipp_funcs.cpp.

584 {
585  if (a == b)
586  return a;
587  else
588  return exp(rnd_unif(log(a), log(b)));
589 }
double rnd_unif()
doublereal * b
void log(Image< double > &op)
doublereal * a

◆ rnd_student_t() [1/2]

double rnd_student_t ( double  nu)

Produce a t-distributed random number with mean 0 and standard deviation 1 and nu degrees of freedom

std::cout << "This random number should follow t(0,1) with 3 degrees of freedon: " << rnd_student_t(3.)
<< std::endl;

Definition at line 453 of file xmipp_funcs.cpp.

454 {
455  return tdev(nu, &idum);
456 }
double tdev(double nu, int *idum)
int idum

◆ rnd_student_t() [2/2]

double rnd_student_t ( double  nu,
double  a,
double  b 
)

Produce a gaussian random number with mean a and standard deviation b and nu degrees of freedom

std::cout << "This random number should follow t(1,4) with 3 d.o.f.: " << rnd_gaus(3,1,2)
<< std::endl;

Definition at line 457 of file xmipp_funcs.cpp.

458 {
459  if (b == 0)
460  return a;
461  else
462  return b*tdev(nu, &idum) + a;
463 }
doublereal * b
double tdev(double nu, int *idum)
int idum
doublereal * a

◆ rnd_unif() [1/2]

double rnd_unif ( )

Produce a uniform random number between 0 and 1

std::cout << "This random number should be between 0 and 1: " << rnd_unif()
<< std::endl;

Definition at line 440 of file xmipp_funcs.cpp.

441 {
442  return ran1(&idum);
443 }
double ran1(int *idum)
int idum

◆ rnd_unif() [2/2]

double rnd_unif ( double  a,
double  b 
)

Produce a uniform random number between a and b

std::cout << "This random number should be between 0 and 10: " << rnd_unif(0,10)
<< std::endl;

Definition at line 444 of file xmipp_funcs.cpp.

445 {
446  if (a == b)
447  return a;
448  else
449  return a + (b - a)*ran1(&idum);
450 }
doublereal * b
double ran1(int *idum)
int idum
doublereal * a

◆ solve_2nd_degree_eq()

int solve_2nd_degree_eq ( double  a,
double  b,
double  c,
double &  x1,
double &  x2,
double  prec = XMIPP_EQUAL_ACCURACY 
)

Solve second degree equation

ax^2+bx+c=0

It returns the number of real solutions, 0 if the two roots are complex and -1 if the equation is impossible to satisfy (Ex: 7=0). A number is said to be 0 if its absolute magnitude is smaller than precision. This is used to avoid dividing by 0

Definition at line 153 of file xmipp_funcs.cpp.

155 {
156  // Degenerate case?
157  if (fabs(a) < prec)
158  {
159  if (fabs(b) < prec)
160  return -1;
161  else
162  {
163  x1 = -c / b;
164  return 1;
165  }
166  }
167 
168  // Normal case
169  double d = b * b - 4 * a * c;
170  if (d < 0)
171  return 0;
172  else
173  {
174  x1 = (-b + sqrt(d)) / (2 * a);
175  x2 = (-b - sqrt(d)) / (2 * a);
176  return 2;
177  }
178 }
doublereal * c
void sqrt(Image< double > &op)
doublereal * d
doublereal * b
doublereal * a

◆ student_from_t0()

double student_from_t0 ( double  t0,
double  degrees_of_freedom 
)

student area from t0 to inf

By default the student mean is 0 and the student standard deviation is 1. There is no restriction over the sign of t0

Definition at line 548 of file xmipp_funcs.cpp.

549 {
550  return 1 -student_up_to_t0(t0, degrees_of_freedom);
551 }
double student_up_to_t0(double t0, double degrees_of_freedom)

◆ student_outside_probb()

double student_outside_probb ( double  p,
double  degrees_of_freedom 
)

t0 for a given two-sided probability

This function returns t0 such that the student probability outside t0 is equal to p

Definition at line 553 of file xmipp_funcs.cpp.

554 {
555  // Make a Bolzano search for the right value
556  double pm, t1, t2, tm;
557  t1 = 0;
558  t2 = 100;
559  do
560  {
561  tm = (t1 + t2) / 2;
562  pm = student_outside_t0(tm, degrees_of_freedom);
563  if (pm > p)
564  t1 = tm;
565  else
566  t2 = tm;
567  }
568  while (fabs(pm - p) / p > 0.005);
569  return tm;
570 }
double student_outside_t0(double t0, double degrees_of_freedom)

◆ student_outside_t0()

double student_outside_t0 ( double  t0,
double  degrees_of_freedom 
)

student area outisde -t0 to t0

By default the student mean is 0 and the student standard deviation is 1. t0 must be positive

Definition at line 535 of file xmipp_funcs.cpp.

536 {
537  return 1 -student_within_t0(t0, degrees_of_freedom);
538 }
double student_within_t0(double t0, double degrees_of_freedom)

◆ student_up_to_t0()

double student_up_to_t0 ( double  t0,
double  degrees_of_freedom 
)

student area from -inf to t0

By default the student mean is 0 and the student standard deviation is 1. There is no restriction over the sign of t0

Definition at line 540 of file xmipp_funcs.cpp.

541 {
542  if (t0 >= 0)
543  return 1.0 -student_outside_t0(t0, degrees_of_freedom) / 2;
544  else
545  return student_outside_t0(t0, degrees_of_freedom) / 2;
546 }
double student_outside_t0(double t0, double degrees_of_freedom)

◆ student_within_t0()

double student_within_t0 ( double  t0,
double  degrees_of_freedom 
)

student area from -t0 to t0

By default the student mean is 0 and the student standard deviation is 1. t0 must be positive

Definition at line 529 of file xmipp_funcs.cpp.

530 {
531  return 1 -betai(degrees_of_freedom / 2, 0.5,
532  degrees_of_freedom / (degrees_of_freedom + t0*t0));
533 }
double betai(double a, double b, double x)

◆ swapbytes()

void swapbytes ( char *  v,
unsigned long  n 
)

Conversion little-big endian

This function is not ported to Python.

Definition at line 1040 of file xmipp_funcs.cpp.

1041 {
1042  char t, t0, t1, t2, t3;
1043  switch (n)
1044  {
1045  case 4:
1046  t0 = v[0];
1047  t1 = v[1];
1048  v[0]=v[3];
1049  v[1]=v[2];
1050  v[2]=t1;
1051  v[3]=t0;
1052  break;
1053  case 2:
1054  t = v[0];
1055  v[0] = v[1];
1056  v[1] = t;
1057  break;
1058  case 1:
1059  break;
1060  case 8:
1061  t0 = v[0];
1062  t1 = v[1];
1063  t2 = v[2];
1064  t3 = v[4];
1065  v[0]=v[7];
1066  v[1]=v[6];
1067  v[2]=v[5];
1068  v[3]=v[4];
1069  v[4]=t3;
1070  v[5]=t2;
1071  v[6]=t1;
1072  v[7]=t0;
1073  break;
1074  default:
1075  for (size_t i=0; i<n/2; i++ )
1076  {
1077  t = v[i];
1078  v[i] = v[n-1-i];
1079  v[n-1-i] = t;
1080  }
1081  }
1082 }
#define i
int * n

◆ time_config()

void time_config ( )

Read the system clock frequency

This operation is needed only once in a program always we want to have a time measure, or an estimation of remaining time.

This function is not ported to Python.

Definition at line 628 of file xmipp_funcs.cpp.

629 {
630 #ifndef __MINGW32__
631  XmippTICKS = sysconf(_SC_CLK_TCK);
632 #else
633 
634  XmippTICKS = CLK_TCK;
635 #endif
636 }
int XmippTICKS

◆ time_to_go()

double time_to_go ( ProcessorTimeStamp time,
double  fraction_done 
)

Returns the estimated time left to finish

To make this estimation the starting time must have been annotated before and the fraction of the total amount of work must be estimated by the programmer. See Time managing for an example.

This function is not ported to Python.

Definition at line 757 of file xmipp_funcs.cpp.

758 {
759  ProcessorTimeStamp now;
760  times(&now);
761  double totalTime = (now.tms_utime - time.tms_utime +
762  now.tms_stime - time.tms_stime) / XmippTICKS;
763  return totalTime*(1 - fraction_done) / fraction_done;
764 }
int XmippTICKS
struct tms ProcessorTimeStamp
Definition: xmipp_funcs.h:822

◆ TimeMessage()

void TimeMessage ( const std::string &  message)

Shows a message and the time it was produced

The format of the printing is "14:11:32 (12) => Hello, world", ie, The message "Hello, world" was produced at 14:11:32 o'clock of the day 12. This function needs not to read the time configuration (see time_config).

TimeMessage("Hello, world");

This function is not ported to Python.

Definition at line 768 of file xmipp_funcs.cpp.

769 {
770  struct tm *T;
771  time_t seconds;
772 
773  if (time(&seconds) < 0)
774  seconds = 0;
775  T = localtime(&seconds);
776 
777  printf("%2d:%2d:%2d (day=%2d) =>%s ", T->tm_hour,
778  T->tm_min, T->tm_sec, T->tm_mday, message.c_str());
779 }

◆ tstudent1D()

double tstudent1D ( double  x,
double  df,
double  sigma,
double  mu = 0 
)

1D t-student value

This function returns the value of a univariate t-student function at the point x, and with df degrees of freedom

Definition at line 188 of file xmipp_funcs.cpp.

189 {
190  x -= mu;
191  double norm = exp(gammln((df+1.)/2.)) / exp(gammln(df/2.));
192  norm /= sqrt(df*PI*sigma*sigma);
193  return norm * pow((1 + (x/sigma)*(x/sigma)/df),-((df+1.)/2.));
194 
195 }
void sqrt(Image< double > &op)
T norm(const std::vector< T > &v)
Definition: vector_ops.h:399
doublereal * x
int mu
#define PI
Definition: tools.h:43
double gammln(double xx)

◆ unmapFile()

void unmapFile ( char *&  map,
size_t &  size,
int &  fileDescriptor 
)

Unmap file

Definition at line 1013 of file xmipp_funcs.cpp.

1014 {
1015 #ifdef XMIPP_MMAP
1016  if (munmap(map, size) == -1)
1017  REPORT_ERROR(ERR_MEM_NOTDEALLOC,"Cannot unmap memory");
1018 #else
1019 
1020  delete []map;
1021  map=NULL;
1022 #endif
1023 
1024  close(fileDescriptor);
1025 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Memory has not been deallocated.
Definition: xmipp_error.h:167

◆ xmippFREAD()

size_t xmippFREAD ( void *  dest,
size_t  size,
size_t  nitems,
FILE *&  fp,
bool  reverse = false 
)

Read from file

This function is the same as fread from C, but at the end there is a flag saying if data should be read in reverse order or not.

double f;
xmippFREAD(&f, sizeof(double), 1, fp, TRUE); // Reverse order
double f;
xmippFREAD(&f, sizeof(double), 1, fp); // Normal order

This function is not ported to Python.

Definition at line 902 of file xmipp_funcs.cpp.

903 {
904  size_t retval;
905  if (!reverse)
906  retval = fread(dest, size, nitems, fp);
907  else
908  {
909  char *ptr = (char *)dest;
910  bool end = false;
911  retval = 0;
912  for (size_t n = 0; n < nitems; n++)
913  {
914  char * ptrp = ptr + size - 1;
915  for (size_t i = 0; i < size; ++i, --ptrp)
916  {
917  if (fread(ptrp, 1, 1, fp) != 1)
918  {
919  end = true;
920  break;
921  }
922  }
923  if (end)
924  break;
925  else
926  retval++;
927  ptr += size;
928  }
929  }
930  if (retval != nitems)
931  REPORT_ERROR(ERR_IO_NOREAD,"XmippFREAD: An error occurred or End of File was reached.");
932 
933  return retval;
934 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define i
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
int * n

◆ xmippFWRITE()

size_t xmippFWRITE ( const void *  src,
size_t  size,
size_t  nitems,
FILE *&  fp,
bool  reverse = false 
)

Write to file

This function is the same as fread from C, but at the end there is a flag saying if data should be read in reverse order or not.

This function is not ported to Python.

Definition at line 937 of file xmipp_funcs.cpp.

939 {
940  size_t retval;
941  if (!reverse)
942  retval = fwrite(src, size, nitems, fp);
943  else
944  {
945  char *ptr = (char *)src;
946  bool end = false;
947  retval = 0;
948  for (size_t n = 0; n < nitems; n++)
949  {
950  char * ptrp = ptr + size - 1;
951  for (size_t i = 0; i < size; ++i, --ptrp)
952  {
953  if (fwrite(ptrp, 1, 1, fp) != 1)
954  {
955  end = true;
956  break;
957  }
958  }
959  if (end)
960  break;
961  else
962  retval++;
963  ptr += size;
964  }
965  }
966  return retval;
967 }
#define i
int * n