A homepage subtitle here And an awesome description here!

22 June 2020

How to read a CSV file in R | Lecture 4

How to read a CSV file in R

CSV is called as Comma Separated Value file which can be easily generated using any spreadsheet application like OpenOffice, LibreOffice, MS Office, etc... 

We can also create csv files using any text editor as well as given below. 

Create a csv file as per the format given below:

Name, Age, Science, Maths, Social
Kumar,14,57,67,78
Anand,24,98,97,90
Balakumar, 25,35,45,56

To read this file

> mydata=read.csv("users.csv");
> mydata

       name age science maths social
1     kumar  14      57    67     78
2     Anand  24      98    97     90
3 Balakumar  25      35    45     56

To create a new file,

df <- data.frame(name = c("Jon", "Bill", "Maria"), age = c(23, 41, 32), science=c(20,30,40), maths=c(56,67,78), social=c(98,76,65))
write.csv(df,"anewfile.csv", row.names = FALSE)

CSV file in R


Arrays and Matrices in R | Lecture 3

Arrays and Matrices in R
Arrays are declared in R using the dim() or array() functions. 

For example:

> mycarsale.array<-1:30
> mycarsale.array
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
[17] 17 18 19 20 21 22 23 24 25 26 27 28 29 30

The above command allocates a vector of 1 to 30 to the variable array called mycarsale.array 
To make it as a matrix, we can use dim() function as given below 

> dim(mycarsale.array)<-c(3,5,2)
> mycarsale.array
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5    8   11   14
[3,]    3    6    9   12   15

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]   16   19   22   25   28
[2,]   17   20   23   26   29
[3,]   18   21   24   27   30

In the above output 3 indicates the number of columns, 5 indicate the number of columns and 2 indicates the number of tables.

Array in R
Array in R

> mycarsale.array[2,3,1]
[1] 8
> mycarsale.array[2,3,2]
[1] 23

How to Use R as a Calculator | Lecture 2

R as a Calculator
How to use R as a calculator 

Open R Studio either through GUI or through Command/Terminal Mode by typing 

$] rstudio

In the Console Window, type the following 

> 2+3

> log(10)

>log10(10)

> 3^2+4^3

> exp(5)

> exp(1)

Check the output given in the following Window.
R

To clear the console Window, use the Shortcut key Ctl+L, 

in R, pi is recognised as PI = 3.141

>pi 
[1] 3.141593

We can use -ve sign also in front of the numbers 

> -9 + 1
[1] -8




Basics of R | Lecture 1

Basics of R

Its a software and programming language used for statistical computing and report generation. 
Its Free and open source with GPL Licensing 
It has a GUI to work upon called as RStudio. 

This software can be installed using the following command in  Ubuntu

$] sudo apt update
$] sudo apt install build-essential autoconf automake libxmu-dev
$] sudo apt install r-base rstudio

To open the software, you can use either through the GUI or through terminal using 

$] rstudio

The GUI looks like this 
R Studio
R Studio

Features of R
  • Its based on object oriented design
  • R Commands can be included or embedded with other software or applications or programming languages namely C++. Java and other commercial tools.
  • It supports multiple Operating systems like Windows, Linux, Mac OS, etc.
Advantages of R
  • Good community to help 
  • Works in a interactive way
  • Plotting and graphs are easy to plot using the libraries.
  • New libraries can be easily generated.
  • Its completely modular and object oriented.
See the following screenshot that shows the RStudio Window. We can run the commands in Console window and get the output interactively.

We can write a script directly in the Script window and execute the program using Run Button and other two window namely environment and file window. 
R STudio
R Studio

Disadvantages
R needs more memory, so large datasets can be processed with the maximum available memory in the machine. 


18 June 2020

Printing Linux Environment using C Program


Linux provides each running program with an environment. The environment is a collection of variable/value pairs. Both environment variable names and their values are character strings. By convention, environment variable names are spelled in all capital letters. You’re probably familiar with several common environment variables already.

For instance:

USER contains your username.

HOME contains the path to your home directory.

PATH contains a colon-separated list of directories through which Linux searches for commands you invoke.

DISPLAY contains the name and display number of the X Window server on which windows from graphical X Window programs will appear.

//Printing the Execution Environment
#include <stdio.h>
/* The ENVIRON variable contains the environment. */
extern char** environ;
int main ()
{
char** var;
for (var = environ; *var != NULL; ++var)
printf (“%s\n”, *var);
return 0;
}


Printing the Uptime and Idle Time of processor (Linux)

/proc/uptime file contains only two values in seconds, one is the Uptime of the processor (the time upto which the processor was on) and another is the idle time of all the processors (cores).

So idle is always higher than the uptime in case of multicore processors.

The following C program shows the uptime and idle time in terms of days hours and minutes. This is a very simple program just tells you how to convert a given time in days, hours, minutes and seconds.

using C FILE concept, the /proc/uptime file is been read using the “r” mode and values are fetched and then converted into days, hours and seconds.

   1:  // printing the uptime and idle time
   2:  #include <stdio.h>
   3:  /* Summarize a duration of time to standard output. TIME is the
   4:  amount of time, in seconds, and LABEL is a short descriptive label. */
   5:  void print_time (char* label, long time)
   6:  {
   7:  /* Conversion constants. */
   8:  const long minute = 60;
   9:  const long hour = minute * 60;
  10:  const long day = hour * 24;
  11:  /* Produce output. */
  12:  printf (“%s: %ld days, %ld:%02ld:%02ld\n”, label, time / day,
  13:  (time % day) / hour, (time % hour) / minute, time % minute);
  14:  }
  15:  int main ()
  16:  {
  17:  FILE* fp;
  18:  double uptime, idle_time;
  19:  /* Read the system uptime and accumulated idle time from /proc/uptime. */
  20:  fp = fopen (“/proc/uptime”, “r”);
  21:  fscanf (fp, “%lf %lf\n”, &uptime, &idle_time);
  22:  fclose (fp);
  23:  /* Summarize it. */
  24:  print_time (“uptime “, (long) uptime);
  25:  print_time (“idle time”, (long) idle_time);
  26:  return 0;
  27:  }


Square and Sinusoidal Waveform in 8051 Microcontroller

Waveforms in 8051 Microcontroller

Square Wave
To create a square wave generation using Delay.
let us say we want to construct a 1khz square waveform
the processor instruction cycle of 8051 is 1.085microseconds
so for 1khz (1milli seconds =1/1khz), is 1ms/1.085microseconds = 921.6 (this value is set to the for loop)

#include <reg51.h>
void delay()
{
int i=0;
for(i=0;i<922;i++)
}
void main()
{
P0=0xff;
delay();
P0=0x00;
delay();
}
Sine Wave generation
Since sine wave is plotted in a digital device the number of samples determines the smoothness, hence in this case, more the samples, smoother is the waveform. so a lookup table is been created to get the samples. in the following examples, there are totally 36 samples are taken, starting from 0 degrees to 360 degrees with a step of 10 degrees
DegreesA = 5 (1+Sin theta)
Where 5 is the full scale voltage
DAC = 25.6 * A
05128
307.5192
609.3239
9010256
etc…like this we need to calculate for 13 samples  with a step of 30degree
// SINE WAVE
#include<reg51.h>
int main()
{
int j;
int c[37]={128,150,172,192,210,226,239,248,254,255,254,248,239,226,210,192,172,150,128,106,84,64,46,30,17,8,2,0,2,8,17,30,46,64,84,106,128};
while(1)
{
for(j=0;j<36;j++)
{
P1=c[j];
}
P1=128;
}}   


Triangular Waveform
//Triangular wave
#include<reg51.h>     
void main()
{
int j;
while(1)
{
for(j=0;j<256;j++)
{
P0=j;
}
for(j=255;j>0;j=j-2)
{
P0=j;
}
}
}

Saw tooth or Ramp Waveform
// SAWTOOTH WAVE
#include<reg51.h>
void main()
{
int j;
while(1)
{
for(j=0;j<256;j++)
{
P1=j;
}}}

Pulse Width Modulation (PWM) Generation in 8051
#include <reg51.h>
sbit pinpwm = P2^0;          
unsigned char PWM = 0;//PWM is the variable to alter the pulse width from 0 to 255     
unsigned int temp = 0;   
int main(void)
{
  P2=0x00;
    PWM = 0; //0% duty cycle        
//Initialize the timer
    TMOD &= 0xF0;   
    TMOD |= 0x01;   
   
    TH0 = 0x00;     
    TL0 = 0x00;     
   
    ET0 = 1;         //enable timer interrupt
    EA  = 1;         //enable all interrupts
   
    TR0 = 1;         // Start Timer 0
    PWM = 220;       //a duty cycle of 220/256
  while(1)       
  {}
}
// Timer0 ISR
void Timer0_ISR (void) interrupt 1  
{
    TR0 = 0;    // Stop Timer 0
    if(pinpwm)    // if high
    {
        pinpwm= 0;
        temp = (255-PWM); //this is in decimal
        TH0  = 0xFF;
        TL0  = 0xFF - temp&0xFF;    //to handle in hex
    }
    else         // else if low
    {
        pinpwm = 1;
        temp = PWM;
        TH0  = 0xFF;
        TL0  = 0xFF - temp&0xFF;
    }
    TF0 = 0;     // Clear the interrupt flag
    TR0 = 1;     // Start Timer 0
}

Here the PWM Waveform is generated with a duty cycle of 220/256(86%) duty cycle. PWM are advantageous in controlling the power to machines be reducing the supply voltage by altering the pulse width.
Duty Cycle means, the time percentage for which the duty is done. in the image show above, the high waveform for 86% and low waveform (0) for 14%.


Pradeep Kumar TS

Terminal Based Youtube downloader for Linux (youtube-dl)

Terminal Based Youtube downloader for Linux (youtube-dl)

Downloading youtube.com videos to local machine is always a challenge as the streaming sites keep on updating their policies in blocking the videos.
But there is a tool that is available in the command line (Terminal based) on Linux Operating Systems.
That is youtube-dl, this is a python based code and can be executed in linux OS without any hassles.

youtube-dl in windows or Mac OS can be achieved by installing python interpreter and try it.

for installing in linux, the command is
$prompt] sudo yum install youtube-dl (in redhat or centos or fedora)
$prompt] sudo apt-get install youtube-dl (ubuntu or linux mint)
See the image for downloading in Fedora 20
fedora20
Youtube-dl in Fedora 20

In ubuntu, you can update the sudo package before installing the youtube-dl.
sudo apt-get update

To download videos 
$prompt] youtube-dl http://www.youtube.com/watch?v=D980jXvyKUY

the above command will download the video in the best possible format. See the image below.
The video downloaded is of the format webm (Its a Web Movie format from Google for optimized view in web browsers)
youtube
Youtube-dl
To view all formats, use the following command,
$prompt] youtube-dl -F http://www.youtube.com/watch?v=D980jXvyKUY
[youtube] Setting language
[youtube] D980jXvyKUY: Downloading webpage
[youtube] D980jXvyKUY: Downloading video info webpage
[youtube] D980jXvyKUY: Extracting video information
[info] Available formats for D980jXvyKUY:
format code extension resolution  note
139         m4a       audio only  DASH audio , audio@ 48k (worst)
140         m4a       audio only  DASH audio , audio@128k
160         mp4       192p        DASH video
133         mp4       240p        DASH video
17          3gp       176x144    
36          3gp       320x240    
5           flv       400x240    
18          mp4       640x360     

43          webm      640x360     (best)

The above is output and to download the corresponding video format, then here is the command
$prompt] youtube-dl -f 18 http://www.youtube.com/watch?v=D980jXvyKUY
The above command will download the file in the mp4 format as specified in the option obtained in the previous command.

if you need any help on the commands, you can use the following command 
$prompt] youtube-dl --help

Often, youtube-dl is updated, it can be easily updated as given below,
$prompt] sudo youtube-dl -U

Also now youtube-dl supports various other video streaming sites also, to name a few, vimeo.com, dailymotion.com, etc.

If you are behind the proxy, type the command in the terminal  
export http_proxy=172.16.1.1:8080/ 
or copy the above line in /etc/profile.d/proxy.sh (this will be set for all the users of the computer, also need root password)

Download and Enjoy!!!

Pradeep Kumar TS

nohup command in Linux/Unix


nohup command in Linux/Unix
Often you come across a situation where you try to open a machine remotely using ssh and try to start a server or run a command indefinitely. But once you close the ssh session, your session also terminates and the background process also terminates. So here is a solution.

To open ssh remotely,

prompt $] ssh username@machinename
Ex: ssh root@172.16.1.1
Ex: ssh root@example.com 
prompt $] ssh -X username @machinename 
Ex. ssh -X root@172.16.1.1 

(this -X indicates the remote session can be opened in X window (GUI) mode)

Assume we need to start a httpd server in the remote machine.
we can issue the command like this

usage:
prompt$] nohup command 
if any error or log information may be stored in the nohup.out file. if you want to redirect to a file use the redirected symbol (1>  indicates standard output and 2> indicates standard Error). Specify the filenames for the output. Here is the typical nohup command to start the httpd server.

prompt $] nohup  /etc/init.d/httpd start  1> file.out 2> file.err & 
nohup is the command simply tells "no hangup". This will send the output to non-tty.
The above command will start the httpd server and any error or output will be written on to the files file.err and file.out respectively (The & indicates the background process that closes the current terminal and prompts for further inputs).
nohup
nohup in Linux


This command I learnt when i try to deploy Sage math libraries in a IBM Blade Server. We were really struggling to run the notebook in sagemath library. But finally accomplished using the nohup command.

The alternative to nohup is crontab or cronjob can be used.

Pradeep Kumar TS

How to display the Product name and System Vendor name in Linux

This post will help you to find out the
Product Name
  • System Vendor Name 
This will help you to find the suitable device drivers if any.

The following is the command to find the System Vendor (in my case it is Hewlett Packard)
prompt $] cat /sys/class/dmi/id/sys_vendor

Here is the command to find the product name

prompt $] cat /sys/class/dmi/id/product_name



Printing the System Vendor and Product Name
cat is the command to concatenate the files and print it to the standard output


Pradeep Kumar TS

time command in Linux

time command in Linux
The time command is linux is very much useful if you want to know the time information while running a program or a process.
The time command usage is as follows

prompt $] time <commandname>
Example
prompt $] time ls
The output will be
real 0m0.002s
user 0m0.004s
sys 0m0.000s


If you want to see the detailed system parameters occupied during a program or process, then the command will be 
prompt$] TIMEFORMAT="" time -v <commandname>
See the screenshot given below

The output of the above command is
Desktop  Documents  Downloads  examples.desktop  Music Pictures  Public  Templates  Videos
Command being timed: "ls"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 400%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3600
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 286
Voluntary context switches: 1
Involuntary context switches: 0
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Similarly, if a C or C++ program is compiled and linked to a file called helloc (the creation of helloc is given below)
prompt $] gcc -o helloc hello.c 
or
prompt $] g++ -o helloc tspradeep.cc 
if you want to execute this command 

prompt $] TIMEFORMAT="" time -v ./helloc

The time command will show you the memory page faults, context swtiching, swap memory used and other system parameters, etc.

If you have any added input for this command, let you write in the comment section.
Pradeep Kumar TS

How to open Ports in CentOS using i-tables

CentOS is the most preferred alternative OS for RHEL. Those who cannot afford to purchase the support license of RHEL, they can use CentOS that comes with almost similar to RHEL.

This post tells you about the usage of CentOS when web servers are installed and accessed from remote machines.

CentOS is a Server based OS and most of the ports are closed by default and you need to open it for access from outside (remote).
For ex. if wordpress is installed in CentOS with a hostname http://127.0.0.1/wordpress  which is very well accessed within the server. When the same is tried from outside like (http://192.168.54.3/wordpress), then it will not get accessed.
The problem is the closure of ports in CentOS. So you need to open it and save it to iptables, here are the commands that will help you to do that.

CentOS
CentOS











Port number : 80 is used here

$prompt] ifconfig (find out which interface uses the assigned ip, eth1, eth0, etc)

$prompt] iptables --line -vnL
(See which line the input has to be accepted and in my case it is 6) and give the following command

$prompt] iptables -I INPUT 6 -i eth1 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT

$prompt] service iptables save (Save and restart the IP Tables)

$prompt] service iptables restart


Thats all!!!! I solved this problem, when I installed MOODLE in my Blade server with Cent OS installed.

Pradeep Kumar TS

Change InnoDB file format to Barracuda

MySQL and MariaDB uses innoDB for storing the tables in a file format called Antelope.  For large sites, the Antelope format doesn't support more columns which makes the backup option a tedious process.
so it will be advised to change the file format to Barracuda. There are various options to do that. Here is a small workaround to change it to barracuda.

Open Mysql from the command prompt and execute the commands one by one

$] mysql -u root -p

The username is root here
It will ask for the password: (Input the password here).

mysql> select  version();
mysql> show variables like "%innodb_file%";

The output will be like this
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| innodb_file_format       | Antelope |
| innodb_file_format_check | ON       |
| innodb_file_format_max   | Antelope |
| innodb_file_per_table    | ON       |
+--------------------------+----------+
4 rows in set (0.00 sec)

mysql> SET GLOBAL innodb_file_format = barracuda;

mysql> show variables like "%innodb_file%";     
+--------------------------+-----------+
| Variable_name            | Value     |
+--------------------------+-----------+
| innodb_file_format       | Barracuda |
| innodb_file_format_check | ON        |
| innodb_file_format_max   | Antelope  |
| innodb_file_per_table    | ON        |
+--------------------------+-----------+
4 rows in set (0.00 sec)

mysql> SET GLOBAL innodb_file_format_max = barracuda;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like "%innodb_file%";         
+--------------------------+-----------+
| Variable_name            | Value     |
+--------------------------+-----------+
| innodb_file_format       | Barracuda |
| innodb_file_format_check | ON        |
| innodb_file_format_max   | Barracuda |
| innodb_file_per_table    | ON        |
+--------------------------+-----------+
4 rows in set (0.00 sec)

See the picture below
Barracuda
Barracuda

How to access ext2, ext3 and ext4 filesystems in windows 10



Dual boot with Windows and Linux leads to the access of files in other Operating Systems. Viewing a windows partition on a Linux OS is not a big task. One can simply mount the OS and can see the files of windows within Linux.

But accessing Linux EXT2, EXT3 and EXT4 files within Windows can be done only through an external software.

EXt2FSD is a software that does this job. you can download the software from this link
Once installed, its as easy as possible to “assign a drive letter ” to the partition.  Figure below shows that.

Ext2FSD
Ext2FSD

Ext2FSD
Ext2FSD

Its just a simple process to access the linux files within windows. This is really helpful for the machines with UEFI partition. When Linux Boot loader is deleted, this will help to retrieve the files.
Any other info, please comment below.

vokoscreen - a screen recorder for Linux

There are many screen recorders available for Windows and Mac. But over these years, getting a screen recorder for Linux is always a challenge.  There have been some screen recorders like recordmydesktop, gtk-recordmydesktop, qt-recordmydeskop. They are not user friendly and not suitable for productive recordings.
So, there should be some alternatives to control the video, audio, web camera, etc. Two such tools are available.
Here is the step to do that
$] sudo add-apt-repository ppa:vokoscreen-dev/vokoscreen-daily
$] sudo apt-get update
$] sudo apt-get install vokoscreen
But in the latest version of Ubuntu (16.04), it can given directly as
$] sudo apt install vokoscreen
Once installed, its very easy to use as shown in the following figures
vokoscreen
vokoscreen Video configuration

vokoscreen
Vokoscreen Audio Control

vokoscreen
vokoscreen webcamera control

vokoscreen
vokoscreen


09 June 2020

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS



Step 1: Install the basic libraries like
    
$] sudo apt install build-essential autoconf automake libxmu-dev

Step 2: install gcc-4.8 and g++-4.8

open the file using sudo mode
$] sudo nano /etc/apt/sources.list

Include the following line
deb http://in.archive.ubuntu.com/ubuntu bionic main universe

$] sudo apt update
$] sudo apt install gcc-4.8 g++-4.8

Step 3: 
Unzip the ns2 packages to home folder

$] tar zxvf ns-allinone-2.35.tar.gz
$] cd ns-allinone-2.35/ns-2.35

Modify the following make files.

~ns-2.35/Makefile.in

Change @CC@ to gcc-4.8
change @CXX@ to g++-4.8

~nam-1.15/Makefile.in
~xgraph-12.2/Makefile.in
~otcl-1.14/Makefile.in

Change in all places 
@CC@ to gcc-4.8
@CPP@ or @CXX@ to g++-4.8

open the file:
~ns-2.35/linkstate/ls.h

Change at the Line no 137 
void eraseAll() { erase(baseMap::begin(), baseMap::end()); }

to This
void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }

All changes made

Step 4: Open a new terminal

$] cd ns-allinone-2.35/

$] ./install

Step 5 - Set the PATH
Open a new Terminal, 

$] gedit .bashrc 

Paste the following lines

export PATH=$PATH:/home/<yourusername>/ns-allinone-2.35/bin:/home/<yourusername>/ns-allinone-2.35/tcl8.5.10/unix:/home/<yourusername>/ns-allinone-2.35/tk8.5.10/unix

export LD_LIBRARY_PATH=/home/<yourusername>/ns-allinone-2.35/otcl-1.14:/home/<yourusername>/ns-allinone-2.35/lib


Logout and Login back
OR
$] source .bashrc

Thanks for watching, Subscribe and Share it to your friends...





Powered by Blogger.

About Me

Featured Post

5G Network Simulation in NS3 using mmWave | NS3 Tutorial 2024

5G Network Simulation in NS3 Using mmWave This post shows the installation of ns3mmwave in Ubuntu 24.04 and simulates 5G networks in ns3. In...

Contact form

Name

Email *

Message *

Total Pageviews

Search This Blog

Pages

Pages

Pages - Menu

Most Popular

Popular Posts