Search This Blog

Wednesday, June 9, 2010

Add a system independent sleep/clock to your program

Add a system independent sleep/clock to your program

http://www.faqs.org/faqs/unix-faq/faq/part4/section-6.html

extern int        select();

int
usleep( usec ) /* returns 0 if ok, else -1 */
long usec; /* delay in microseconds */
{
static struct /* `timeval' */
{
long tv_sec; /* seconds */
long tv_usec; /* microsecs */
} delay; /* _select() timeout */

delay.tv_sec = usec / 1000000L;
delay.tv_usec = usec % 1000000L;

return select( 0, (long *)0, (long *)0, (long *)0, &delay );
}

Monday, April 26, 2010

Cool ways of adding numbers in a text file in bash:

awk '{s+=$0} END {print s}' /tmp/file.txt

paste -sd+ /tmp/file.txt | bc

Source: http://unstableme.blogspot.com/2009/11/sum-of-numbers-in-file-unix.html

Saturday, April 24, 2010

Problem with Fortran + C code compilation:

undefined reference to `iargc_'
undefined reference to `getarg_'


Solution: use '_gfortran_iargc()' and '_gfortran_getarg_i4()' instead of 'iargc_()' and 'getargc_()'. This is specific to the situation where you link C with Fortran.
On the cluster, these are defined in /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgfortran.a.

http://osdir.com/ml/gcc.fortran/2005-02/msg00297.html
http://old.nabble.com/getarg-and-iargc-in-gcc-4.0.2-td1803996.html

Other links on Fortran + C compilation:

http://www.fnal.gov/docs/UNIX/unix_a.../uatf-107.html
http://astro.berkeley.edu/~wright/f2c.html
http://www.yolinux.com/TUTORIALS/Lin...rtranAndC.html