Friday, December 9, 2011

9 Powerful Awk Built-in Functions for Numeric

9 Powerful Awk Built-in Functions for Numeric

awk also has lot of built-in functions for numeric, string, input, and ouput operations. Awk has the following three types of high level built-in function categories.

  1. Built-in functions for numeric operations
  2. Built-in functions for String operations
  3. Built-in functions for Input Output operations



In this article, we will review awk Numeric built-in functions.

1. Awk int(n) Function

int() function gives you the integer part of the given argument. This produces the lowest  integer part of given n. n is any number with or with out floating point. If you give the whole number as an argument, this function returns the same. For floating point number, it truncates.

Example

 $ awk 'BEGIN{ print int(3.534); print int(4); print int(-5.223); print int(-5); }' 3 4 -5 -5

2. Awk log(n) Function

log() function provides natural logarithmic of given argument n. log() returns logarithm value only when n is positive number. If you give any invalid number (even negative) it throws an error.

Example

 $ awk 'BEGIN{ print log(12); print log(0); print log(1); print log(-1); }' 2.48491 -inf 0 nan

In the above output you can identify that log(0) is infinity which was shown as -inf, and log(-1) gives you the error nan (Not a Number)

3. Awk sqrt(n) Function

sqrt function gives the positive square root for the given integer n. This function also accepts the positive number, and it returns nan error if you give the negative number as an argument.

Example

 $ awk 'BEGIN{ print sqrt(16); print sqrt(0); print sqrt(-12); }' 4 0 nan

4. Awk exp(n) Function

exp function provides e to the power of n.

Example

 $ awk 'BEGIN{ print exp(123434346); print exp(0); print exp(-12); }' inf 1 6.14421e-06

In the above output, for exp(1234346), it gives you the output infinity, because this is out of range.

5. Awk sin(n) Function

sin() function gives sine value of n, with n in radians.

Example

 $ awk 'BEGIN { print sin(90); print sin(45); }' 0.893997 0.850904

6. Awk cos(n) Function

cos() returns cosine value of n, with n in radians.

Example

 $ awk 'BEGIN { print cos(90); print cos(45); }' -0.448074 0.525322

7. Awk atan2(m,n) Function

This function gives you the arc-tangent of m/n in radians.

Example

 $ awk 'BEGIN { print atan2(30,45);  }' 0.588003

8. Awk rand() Function

rand() is used to generate the random number between 0 and 1. It never return 0 and 1. It always returns the value between 0 and 1. Numbers are random with in one awk run, but predictable from run to run. Awk uses some algorithm to generate the random numbers. Since this algorithm is fixed, the numbers are repeatable.

Example

The following example generates 1000 random numbers between 0 to 100 and shows how often each number was used

 $cat rand.awk BEGIN { while(i<1000) { 	n = int(rand()*100); 	rnd[n]++; 	i++; } for(i=0;i<=100;i++) { 	print i,"Occured", rnd[i], "times"; } } $

Pasted some of the output of the above script here.

 $awk -f rand.awk 0 Occured 6 times 1 Occured 16 times 2 Occured 12 times 3 Occured 6 times 4 Occured 13 times 5 Occured 13 times 6 Occured 8 times 7 Occured 7 times 8 Occured 16 times 9 Occured 9 times 10 Occured 6 times 11 Occured 9 times 12 Occured 17 times 13 Occured 12 times

From the above output, sure that rand() function can generate repeatable numbers very often.

9. Awk srand(n) Function

srand() is used to initialize the random generation with the given argument n. So that whenever the program execution starts, it starts generating the number from n. If no argument is given, it uses the time of the day to generate the seed.

Example. Generate 5 random number starting from 5 to 50

 $cat srand.awk BEGIN { #initialize the seed with 5. srand(5); # Totally I want to generate 5 numbers. total=5; #maximum number is 50. max=50; count=0; while(count < total) { 	rnd = int(rand() * max); 	if ( array[rnd] == 0 ) { 		count++; 		array[rnd]++; 	} } for ( i=5; i<=max; i++) { 	if ( array[i] ) 		print i; } }

In this srand.awk, using rand() function, generate the number and multiply with max value to produce the number with the max of 50, and check if the generated random number is already exist in the array, if it does not exist, increment its index and as well as increment loop count. so that it generates 5 number like this and finally in the for loop from minimum number to maximum, and prints the index only which has the value.

Here is the output of the above script

 $ awk -f  srand.awk 9 15 26 37 39

Practical Programming in Tcl and Tk

Practical Programming in Tcl and Tk, 3rd Edition 

Author(s) : Brent Welch 
Publication date : Jan 2000 
ISBN : 0-13-022028-0 
Pages : 832 
Publisher : Prentice Hall PTR 

Book excerpts: 

Practical Programming in Tcl and Tk is meant as a practical guide to help the readers get the most out of Tcl and Tk and avoid some of the frustrations. It assumes that the readers have some programming experience, although they should be able to get by even if they are a complete novice. Knowledge of UNIX shell programming will help, but it is not required. 

This book is meant to be useful to the beginner in Tcl as well as the expert. For the beginner and expert alike, a careful study of Chapter 1, Tcl Fundamentals, is recommended. The programming model of Tcl is designed to be simple, but it is different from many programming languages. The model is based on string sub- stitutions, and it is important that you understand it properly to avoid trouble in complex cases. The remainder of the book consists of examples that demonstrate how to use Tcl and Tk productively. For your reference, each chapter has tables that summarize the Tcl commands and Tk widgets they describe. 

You are assumed to have some programming experience, although you should be able to get by even if you are a complete novice. Knowledge of UNIX shell programming will help, but it is not required. Where aspects of win-dow systems are relevant, some background information is provided. Chapter 2 describes the details of using Tcl and Tk on UNIX, Windows, and Macintosh. 

Arrow View/Download Practical Programming in Tcl and Tk
http://www.beedub.com/book/
source:
http://www.freetechbooks.com/practical-programming-in-tcl-and-tk-3rd-edition-t22.html

Wednesday, December 7, 2011

University of Hyderabad Departments and Centers

University of Hyderabad Departments and Centers
The University of Hyderabad, highly reputed university in India has
several schools, centers and departments of study under it's purview.
The University, much popular as HCU, is offering variety of PG and
Advanced PG diploma courses apart from its rigorous focus on research
activity. University of Hyderabad was established on 2nd October 1974
as a Central University and completely funded by the University Grants
Commission. The Hyderabad University has been growing rapidly in these
days as it was recognized as center of excellence and also accredited
with five star status by NAAC.

Hyderabad Central University is located at the distance for 20 kms
from main city of Hyderabad, Andhra Pradesh. But the area surrounding
the University has become c crowdy these day with growing population
and spread of population into outskirts of the city. The university
focuses on interdisciplinary studies and research in all the
disciplines and centers. The University is located in the Old Bombay
road and spread in 2000 acres of greenery. The Central University of
Hyderabad also has a city campus named The Golden Threshold, which is
a residence of the late Sarojini Naidu. Following are details of
Schools of Study, Departments and Centers of Study in University of
Hyderabad:

Schools of Study in University of Hyderabad

1) School of Mathematics and Computer and Information Sciences
2) School of Life Sciences
3) Sarojini Naidu School of Arts and Communication
4) School of Humanities
5) School of Management Studies
6) School of Social Sciences
7) School of Physics
8) School of Chemistry
9) School of Medical Sciences
10) School of Engineering Sciences and Technology

The Schools of Chemistry, Management Studies, Physics, and Engineering
Sciences and Technology are single discipline schools. They offer only
one discipline or subject or course in the concerned school. All other
schools are multi-department schools and offer different subjects and
courses. Following are details of Departments or Centers of Study in
University of Hyderabad:

1) The School of Mathematics and Computer or Information Sciences:

a) Department of Mathematics and Statistics
b) Department of Computer and Information Sciences

2) The School of Life Sciences:

a) Department of Biochemistry
b) Department of Plant Sciences
c) Department of Animal Sciences
d) Department of Biotechnology
e) UoH DBT Center for Research and Education in Biology and
Biotechnology (CREBB)

3) The School of Humanities:

a) Department of English
b) Department of Telugu
c) Center for the Study of Foreign Languages
d) Department of Philosophy
e) Center for Comparative Literature
f) Department of Hindi
g) Center for Applied Linguistics & Translation Studies
h) Department of Urdu
i) Department of Sanskrit Studies
j) Center for English Language Studies

4) The School of Social Sciences:

a) Department of Political Science
b) Department of Anthropology
c) Department of Sociology
d) Department of Economics
e) Department of History
f) Center for Regional Studies
g) Center for the Study of Indian Diaspora
h) Center for Folk Culture Studies
i) Center for Human Rights
j) Center for Knowledge, Culture & Innovation Studies
k) Center for Social Exclusion and Inclusive Policy
l) Center for Gandhian Economic Thought

5) The S.N. School of Arts and Communication:

a) Department of Communication
b) Department of Theatre Arts
c) Department of Dance
d) Department of Fine Arts

6) The School of Medical Sciences has the following Center: Center for
Physical Fitness and Sports Sciences

7) Other Centers offering Academic Programmes:

a) Center for Integrated Studies (CIS)
b) Advanced Center of Research in High Energy Materials (ACRHEM)
c) University Center for Earth and Space Sciences (UCESS)
d) Center for Neural and Cognitive Sciences
e) Center for Health Psychology
f) Center for Buddhist Studies
g) Center for Women's Studies
h) Center for Modelling Simulation and Design (CMSD)

All the above schools, centers and departments of the University are
located in the main campus at Gachibowli, Hyderabad. Financial support
is being offered by UGC for various centers under Special Assistance
Programme. The University has produced good number of Ph.D. as the
emphasis is on research programmes. It is estimated that out of total
number of students, about 30 percent will be research scholars. 32
percent of students are women candidates. The unique feature of the
university is that it has more professors than associate professors
and assistant professors.