Data analysis in ns2-use of gawk/xgraph/gnuplot

Source: Internet
Author: User
Document directory
  • 1.1 gawk Introduction
  • 1.2 Main program structure
  • 1.3 Basic gawk commands
  • 1.4 patterns
  • 2.1 xgraph
  • 2.2 gnuplot

After running a Tcl script, the data in the entire simulation process is stored in the trace file. To study the wireless network, you need to use some tools to analyze the trace file. this document introduces the tool gawk/xgraph/gnuplot used for analysis files. improving...

1. Use gawk to analyze the trace file 1.1 gawk Introduction

Awk is a scripting language with strong row processing capabilities and no variable type. gawk is the awk developed by GNU, including all gawk functions.

Usage:

Gawk-F programfile inputfile1 inputfile2...

It can also be executed as a command line.

Field variable Meaning
$0 It is a character whose content is a record currently read by awk.
$1 Data of the first field on $0
$2 Data of the Second Field on $0
... ...

1.2 Main program structure

Pattern1 {actions1}

Pattern2 {actions2}

Pattern3 {actions3}

........

Patternn {actionsn}

Match by row. If the current $0 matches parttern, the corresponding action is executed.

In the gawk program, pattern/action can be omitted, but cannot be ignored at the same time. If no pattern exists, action is always executed. If no action exists, the default operation is output.

The awk language has two special patterns: Begin/end. As the name suggests, the program is executed once at the beginning and end of the program and is not involved in comparison.

1.3 Basic gawk commands

<1> I/O commands

Print command for direct output;

Printf format, Item1, item2.... formatted output.

<2> process control commands

Similar to C, if/For/while/break/continue .....

1.4 patterns

<1> Pattern Type

/Regular expression/conforms to the regular expression;

The conditional expression specified by expression;

Start and end of the begin/end program;

Null is null. It is valid at any time;

<2> Regular Expression

The substring represented by the regular expression. You can use ~ Equals ;!~ Not equal;

2. Drawing tools

Gawk can be used to extract or compute the data we are interested in, but it is not intuitive. Therefore, it must be represented by a graphic rendering tool.

2.1 xgraph

Xgraph is a small drawing tool that comes with NS2. it is a plotting tool that generates a Plane Chart Based on two columns of data.

Usage:

Xgraph filename1, filename... {-options}

You can use parameters (options) to customize the appearance. The usage is relatively simple, but the function is not as good as the gunplot of another drawing tool.

2.2 gnuplot

Gnuplot is a scientific plotting tool developed by Colin Kelly and Thomas Williams in 1986. It supports multiple platforms and is designed to help researchers draw various function curves and data graphs.

Gnuplot supports 2D and 3D graphics, and supports interactive command line mode and batch processing.

2.2.1 gnuplot Basics

In terminal, type 'gnuplot' to perform the gnuplot command line interface.

The command for drawing two-dimensional images is plot cos (x), which is similar to the processing method of MATLAB. If you have been in contact with MATLAB, you can see it.

To exit, enter the quit or exit command.

Gnuplot supports many mathematical functions. In addition, you can also draw data files. Specific commands:

Gnuplot> plot 'filename'

The '#' in the file is a comment. The first column is the X axis and the second column is the Y axis,

2.2.2 custom appearance

We can use the set command to set these parameters and use the show command to view these parameters.

<1> axis-related parameters

<2> identity Parameters

<3> set the curve style

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.