Android SDK刷机

0)Remove battery, connect the mobile with computer using USB cable
1)Press Power+Home until the logo is gone(recovery mode)
2)install drivers necessary for the phone
3)when type “adb devices”, no devices may be found. But it is normal.
4)use fastboot

Posted in Uncategorized | Leave a comment

Linux Books

Web site: http://www.linuxforum.net/books/

名 称 作者|译者|来源
关于堆栈溢出的白皮书 小牟 [推荐]
GNUThe Documentation Format 王立 [编译]
使用CVS进行版本管理 廖斌 [编译] 何伟平 [校对]
《PostgreSQL 7.0 手册》 何伟平[编译][本站数据库版版主]
《Mysql 3.23.7-alpha手册》 晏子 [译][友情提供]
UTF-8 and Unicode FAQ 中国LINUX论坛翻译小组 xLoneStar[译]
VIM手册 VIM手册(英文) 中国LINUX论坛翻译小组[译]
Linux以太网-HOWTO 中国LINUX论坛翻译小组戈绍男(geya)[译]
软件发行惯例HOWTO 王 立[译][本站Linux编程版版主]
GNU Automake 王 立[译][本站Linux编程版版主]
autoconf(2.13)手册 王 立[译][本站Linux编程版版主]
GNU编码标准 王 立[译][本站Linux编程版版主]
Linux讲义 何斌武[友情提供]
Mysql 和 PHP BOY工作室 [友情提供]
PHP3中文参考手册 Sadly [友情提供]
Linux 核心 Banyan & fifa [友情提供]
QPL,一种开放源代码许可证 王 立[译][本站Linux编程版版主]
GNU库通用公共许可证 王 立[译][本站Linux编程版版主]
GPL (通用公共许可证) G N U
Posted in Books | Leave a comment

Automake and autoconf

Automake and autoconf can generate Makefile and configure automatically. Here is an example tested by myself. In this example, the program first generates libraries (shared and static) from a template class. Then it links the correct library automatically for the testing program.

In the current directory, files are:
Double_2D.h  Double_2D.c++ examples  Makefile.am

in sub directory examples/, files are:Makefile.am  testdouble.c++

  1. run autoscan to generate configure.scan
  2. modify configure.scan and change the name to configure.ac, configure.ac shows
  3. run aclocal
  4. run libtoolize
  5. run autoheader
  6. run automake -a
  7. run autoconf

And now you should have a configure file ready.

Makefile.am

ACLOCAL_AMFLAGS=-I m4
lib_LTLIBRARIES=libDouble_2D.la
libDouble_2D_la_SOURCES=Double_2D.c++
include_HEADERS=Double_2D.h
SUBDIRS=examples/

examples/Makefile.am

AM_CXXFLAGS=-I../src
AM_LDFLAGS=-L../src/.libs
noinst_PROGRAMS=test
test_SOURCES=testdouble.c++

configure.ac has

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])
AC_INIT([Double2DTest], [0.1], [McDonalds and KFC<email@test.com>])
LT_INIT
AM_INIT_AUTOMAKE([-Wall, -Werror foreign])
AC_CONFIG_SRCDIR([Double_2D.h])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
AC_CHECK_LIB([m], [sin])

AC_CONFIG_MACRO_DIR([m4])
# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE

# Checks for library functions.

AC_CONFIG_FILES([Makefile examples/Makefile])
AC_OUTPUT
Posted in Computers and Internet | Leave a comment

gcc template and shared library

All template classes must be instantiate before compiling, otherwise, they will not be compiled, and you will have error message like “not defined reference to”.

There are two ways to solve the problem.

  1. Put all declarations and implements in the same .h file
  2. Put declarations in .h file, and put impliments in .C file, but at the end of the .C file, instantiate the class.

eg.

#ifndef DOUBLE_2D_H
#define DOUBLE_2D_H
#include <string>
#include <math.h>
#include <iostream>
template <class T>
class Real_2D{
    protected:
        T * array;
        int nx;
        int ny;
    public:
        Real_2D();
        Real_2D(int x_size, int y_size);
        ~Real_2D();
        void allocate_memory(int x_size, int y_size);
        void copy(const Real_2D<T> & other_array);
        inline void set(int x, int y, T value){
            array[x*ny+y]=value;
        };
        inline T get(int x, int y) const {
            return array[x*ny+y];
        };
        inline int get_size_x() const {
            return nx;
        };
        inline int get_size_y() const {
            return ny;
        };
        T get_sum() const;
        inline T* c_array(){
            return array;
        }
};
#ifdef DOUBLE_PRECISION
#define MPI_MYREAL MPI_DOUBLE
typedef Real_2D<double> Double_2D;
#else
typedef Real_2D<float> Double_2D;
#endif
#endif
#include"Double_2D.h"

template<class T>
Real_2D<T>::Real_2D()
    :nx(0),ny(0){

    }

template<class T>
Real_2D<T>::Real_2D(int x_size, int y_size){
    allocate_memory(x_size,y_size);
}

template<class T>
Real_2D<T>::~Real_2D(){
    if(nx > 0 ){
        delete [] array;
    }
}

template<class T>
void Real_2D<T>::allocate_memory(int x_size,int y_size){
    nx = x_size;
    ny = y_size;
    array = new T[nx*ny];

    for(int i=0; i<nx; i++)
        for(int j=0; j<ny; j++)
            array[i*ny+j]=0;
}

template<class T>
void Real_2D<T>::copy(const Real_2D<T> &other_array){
   // memcpy(array,other_array.array, sizeof(T)*nx*ny);
}

template<class T>
T Real_2D<T>::get_sum() const{
    T total = 0;
    for(int i=0; i<nx; i++)
        for(int j=0; j<ny; j++)
            total+=array[i*ny+j];
    return total;
} 
 
template class Real_2D<double>;
template class Real_2D<float>;
Posted in Computers and Internet | Leave a comment

Eclipse and GCC

1 Installation

If Eclipse has been installed correctly, at the right top corner, you should see a  C/C++ perspective view. If not, then go to menu Help->Install New Software

In the dialog window, at Work with: choose –All Available Sites–, then in the list area, choose CDT to install.

Install GCC and automake in the terminal if they are not installed.

2 Work with new project

In Eclipse, it quite straightforward to create a new C/C++ project, just like you do it in Microsoft Visual Stdio.

3 Import from make project

If you have some source file with Makefile and/or configure file, i.e. source codes downloaded from Internet, you can import them into Eclipse.

  1. Menu: file->import->Existing Codes as Makefile Project
  2. Click Next, give the Project Name, and choose the path, in Toolchain list, choose Linux GCC.
  3. Click Finish to finish the importing.

§3.1 Trouble Shooting

  1. Unresolved inclusion
    If the file has an extension of .c, but includes some c++ header file, this error will occur. To get rid of this error, change the extension to c++/cpp, and change the correspondent items in Makefile.in
  2. Could not read/write file error
    This occurs if the default working directory is not changed. Go to menu: Run->Run Configurations, under C++ Application, {Project} Default, then choose Arguments Tab, at Working Directory, don’t check Use default, instead choose a correct one from the File System…
  3. Could not debug: “No source available for ‘main()'”
    This is because the gcc/g++ flags are not set to debug. To enable debugging, in the configure.in, add the following:
  4. AC_ARG_ENABLE(debug, [ --enable-debug    Turn on debugging],
                    [case "${enableval}" in
                        yes) debug=true ;;
                        no)  debug=false ;;
                        *) AC_MSG_ERROR(bad value ${enableval} for –enable-debug) ;;
                    esac],[debug=false])
    	AM_CONDITIONAL(debug, test x$debug = xtrue)
    	if test "$enable_debug"
    	then
        		CXXFLAGS="-g3 -ggdb $CXXFLAGS"
    	else
        		CXXFLAGS="-O3 $CXXFLAGS"
    	fi

    Then in the terminal,

    $ autoreconf

    $./configure –enable-debug

    $make

  5. No scrollbars in Ubuntu 10.4+
    This is because Unity tools in Ubuntu. To recover the scrollbar, use this command

    $ echo “export LIBOVERLAY_SCROLLBAR=0” >/etc/X11/Xsession.d/80overlayscrollbars

    Then log out and login.

4 Automake

autoscan can generate a template for configure.in

autoconf/autoreconf can generate configure

configure will generate Makefile from Makefile.in

Posted in Uncategorized | Leave a comment

gcc and inline

gcc默认不编译inline定义的函数,除非该函数地址在其他地方得到引用。如
/**
* File Name: test.h
*/
#ifndef _TEST_H_
#define _TEST_H_

class Test{
private:
int a;
public:
Test();
Test(int);
int getA();

};
#endif

/**
* File Name: test.c++
*/
#include "test.h"
Test::Test(){
a=0;
}

Test::Test(int b){
a=b;
}

inline int Test::getA(){
return a;
}

/**
* testtest.c++
*/
#include
#include "test.h"
int main(){
Test T(12);
cout<<T.getA()<<endl;
return 0;
}

$ g++ test.c++ testtest.c++ -o testbin
testtest.c++:(.text+0x21): undefined reference to `Test::getA()’
collect2: ld returned 1 exit status
now
$ g++ test.c++ testtest.c++ -fkeep-inline-functions -o testbin

successful!

Posted in Computers and Internet | Leave a comment

Fresnel Number and Far Field

1. Definition

Fresnel Number is a very important number in optics simulation. It is defined as

NF = \frac{d^2}{\lambda z}
Usually, we think that NF<0.1 is “far field”, so that Fraunhoffer diffraction equation can be used. Otherwise, Fresnel diffraction should be used. To check this, we can simulate some results here. For scalar diffraction theory, the field after the sample at distance z is
U(p) = FT\left\{T(x) \exp(i\pi x^2/\lambda z) \right\} =\sum_{k=1}^{M} T(k\Delta) \exp(i\pi k^2\Delta^2/\lambda z) \exp(-i 2\pi p k/M) (1)
where \Delta is the size of the pixel in the sample plane and k is an integer, and W is the width of the slit in pixels. while
NF = \frac{d^2}{\lambda z}=\frac{W^2\Delta^2}{\lambda z}(2)
So
\frac{\Delta^2}{\lambda z} =\frac{NF}{W^2}(3)
Bearing Eq(3) in mind, and substitute \lambda z in  Eq(1) with Eq(3), we have
U1(p)=\sum_{k=1} ^{M} T(k\Delta) \exp[i\pi(k/W)^2 NF] \exp(-i 2\pi p k/M)
On the other hand, for Fraunhoffer diffraction, U(p) can also be expressed as
$latex U2(p) = \textrm{sinc} \left( \frac{W\Delta p \delta}{\lambda z} \right)=
\textrm{sinc}\left( \frac{Wp}{M}\right)$
If we define I1 = |U1^2|, I2=|U2^2|, so we can calculate the error metric as
\Omega = \sum (I1-I2)^2

2.Simulation

In this simulation, we first fix W=50, M=1024, but change NF from 0.001 to 1.
Error between I1 and I2

The error between I1 and I2 with different Fresnel Number

From this figure, we can see that when NF<0.1, the error is small, which confirms the priori.

Number of pixels vs Error metric

Now we change the total pixel number M, and plot the W vs NF when error metric is the minimum for that particular M.
From this picture, we can see the wider the slit, the smaller NF is needed.  And also, the total number of pixels will not affect the result.

3.Conclusion

We can say safely that for a medium sized sample(~300 pixels), the farfield condition is NF<0.1!
Posted in Physics | Leave a comment

CCD Noise Model

CCD Noise Model

Posted in Physics | Leave a comment

Broadcom 43xx Wireless with Debian

This is originated from http://wiki.debian.org/wl#Squeeze

  1. To check the model of the chip, use

lspci|grep -i broadcom
aptitude install module-assistant wireless-tools
m-a a-i broadcom-sta
echo blacklist brcm80211 >> /etc/modprobe.d/broadcom-sta-common.conf
update-initramfs -u -k $(uname -r)
modprobe -r b44 b43 b43legacy ssb brcm80211
modprobe wl
iwconfig

Posted in Computers and Internet | Leave a comment

Latex Post Test

e^{\i \pi} + 1 = 0

Posted in Computers and Internet | Leave a comment