Language notes

This page collects information on Visual Studio Code, C, C++, Fortran, Java, Perl, python and R.


It is still possible to reflect the old language from here,


There have been multiple instances for suggesting migration fromtempnam to mkstemp (/usr/include/stdlib.h under Bash but not Windows) and mktemp -- the following code illustrates its use under both Bash and Windows, Nevertheless these are not standard routines, one still needs to add char *mktemp(char *) for instance.

#include <stdio.h>
#include <fcntl.h>      /* for open flags */
#include <limits.h>     /* for PATH_MAX */

int main(void)
        static char template[] = "/tmp/myfileXXXXXX";
        char fname[PATH_MAX];
        static char mesg[] =
                "Here's lookin' at you, kid!\n";        /* beats "hello, world" */
        int fd;

        strcpy(fname, template);


        printf("Filename is %s\n", fname);


        fd = open(fname, O_CREAT|O_RDWR|O_TRUNC, 0600);
        write(fd, mesg, strlen(mesg));

        /* unlink(fname); */

        return 0;

A script for testing UTF-8 support by PCRE,

#include <pcre.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    int supports_utf8;
    if (pcre_config (PCRE_CONFIG_UTF8, &supports_utf8)) {
        fprintf(stderr, "pcre_config() failed\n");
    printf("UTF-8 is supported: %s\n", supports_utf8 ? "yes" : "no");
// gcc $(pkg-config --cflags --libs libpcre) pcreutf.c
// ./a.out
// pcretest -C


The use of Google Test is noted here,


wget -qO- | \
tar xvfz -
cd googletest-release-1.11.0
mkdir build && cd build
build ..
# amending set(CMAKE_INSTALL_PREFIX "/rds/user/jhz22/hpc-work") in `cmake_install.cmake`
make install

Now it is possible to compile R/glmnet 4.1-3, i.e., find_package(GTest 1.11 CONFIG REQUIRED) of src/glmnetpp/CMakeLists.txt.


Information on modernising Fortran could be very useful in foreign language calls (e.g., R),

Debugging Fortran code

  • gdb
  • valgrind
program segfault1
  implicit none
  real, dimension(10) :: a
  integer :: i
  a = 0.
  do i = 1, 12
     a(i) = i
  end do
end program segfault1

! gfortran -g -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -fcheck=all -fbacktrace segfault1.f90 -o segfault1
! valgrind  --leak-check=full --dsymutil=yes --track-origins=yes ./segfault1
! MacOS --dsymutil=yes:
! valgrind  --leak-check=full --dsymutil=yes --track-origins=yes ./segfault1


The IDE of choice is NetBeans (e.g., DEPICT and JAM); however 8.1 from apt install under Ubuntu 18.04 crashes so it is suggested to download directly from To enable JDK it is helpful to specify --javahome option.

sudo ./ --javahome /usr/lib/jvm/java-8-oracale

or start with netbeans --javahome /usr/lib/jvm/java-8-oracle (more convenient to set alias netbeans='netbeans --javahome /usr/lib/jvm/java-8-oracle' at .bashrc).

NetBeans 9.0 is currently available from; the .zip file can be downloaded and unpacked for use.

For software such as cutadapt cython is required,

sudo apt install cython


The mermaid diagram is illustrated with mermaid.html using code available from here,

The hello world example with plotly.js is and the 3D diagram is with 3d-scatter.html based on

The base64 encode/decode is with


sudo perl -MCPAN -e shell
install DBI

for instance, as used in VEP.

Another notable example is circos, and its Google group,

wget -qO- | \
tar xvfz -
cd circos-0.69-9
bin/circos --modules
wget -qO- | \
tar xvfz -
wget -qO- | \
tar xvfz -

The following required modules can be installed

Config::General (v2.50 or later)
Set::IntSpan (v1.16 or later)

and we can enter the example/ directory to run its script. The CircosAPI module requires namespace::autoclean, Moose, JSON::PP and String::Util.


To disable upgrade of pip, add

disable-pip-version-check = True

option to $HOME/.config/pip/pip.conf

To install a particular version of package, e.g.,

sudo -H pip install pandas==0.20.1

which is required by DEPICT's Other pip options include uninstall.

The python programs in agotron_detector requires MySQL and can be installed as follows,

sudo apt-get install python-dev libmysqlclient-dev
sudo pip install MySQL-python

It is necessary to use --user option without super-user privilege.

PyStan is available with pip install pystan which uses matplotlib, and Tkinter, established with sudo apt install python-tk or sudo apt install python3-tk.

import pystan

schools_code = """
data {
    int<lower=0> J; // number of schools
    real y[J]; // estimated treatment effects
    real<lower=0> sigma[J]; // s.e. of effect estimates
parameters {
    real mu;
    real<lower=0> tau;
    real eta[J];
transformed parameters {
    real theta[J];
    for (j in 1:J)
    theta[j] = mu + tau * eta[j];
model {
    eta ~ normal(0, 1);
    y ~ normal(theta, sigma);

schools_dat = {'J': 8,
               'y': [28,  8, -3,  7, -1,  1, 18, 12],
               'sigma': [15, 10, 16, 11,  9, 11, 10, 18]}

sm = pystan.StanModel(model_code=schools_code)
fit = sm.sampling(data=schools_dat, iter=1000, chains=4)

import matplotlib.pyplot as plt
def plotGraph():
      fig = fit.plot()
      # use the save button or the following command,
      # f.savefig("foo.pdf", bbox_inches='tight')
      return fig

from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('foo.pdf')
f = plotGraph()

To install jupyter-book,

module load python/2.7.10
python -m pip install jupyter-book --user

and we can check for $HOME/.local/lib/python2.7/site-packages and start from /home/jhz22/.local/bin. We can install notebook similarly.

python -m pip install notebook --user

Owing to recent changes, it is more appropriate to use python3

module load python/3.5
export PATH=$PATH:$HOME/.local/bin
export PYTHONPATH=/usr/local/Cluster-Apps/python/3.5.1/lib/python3.5/site-packages:$HOME/.local/lib/python3.5/site-packages
python3 -m pip install jupyter-book --user


Information on R and RStudio can be seen from installation section of this,

The use of multi-byte string needs specific handling, e.g.,

# on Bash
iconv myfile -f UTF-8 -t ISO-8859-1 -c


# in R
Sys.setlocale("LC_ALL", "C")



It requires a number of software,

sudo dnf install udunits2-devel
sudo dnf install cairo-devel
sudo dnf install gdal gdal-devel
sudo dnf install proj-devel proj-static
sudo dnf install geos geos-devel

to be followed by


Calls from R

  • Basic examples using OpenMP with R, for C, C++, F77, and Fortran 2003 using Romp,
  • RFI: R to Modern Fortran Interface,
  • Stanford Utility Tools for R packages using Fortran,

Package examples for Fortran, * * *

Documentation * * *

R packages



Web:, Shiny examples

The hello world version is as follows,

ui <- fluidPage(
  "Hello, world!"
server <- function(input, output, session) {
shinyApp(ui, server)

Suppose our a directory (called shinyapps here) contains files ui.R and server.R (or combined in app.R).

Go the web site, and register an account with email address. Login from and the following information is available:

Step 1 – Install rsconnect

The rsconnect package can be installed directly from CRAN. To make sure you have the latest version run following code in your R console:


Step 2 – Authorize Account

The rsconnect package must be authorized to your account using a token and secret. To do this, click the copy button below and we'll copy the whole command you need to your clipboard. Just paste it into your console to authorize your account. Once you've entered the command successfully in R, that computer is now authorized to deploy applications to your account.

rsconnect::setAccountInfo(name='your-account', token='your token', secret='your secret')

In the future, you can manage your tokens from the Tokens page the settings menu.

Step 3 – Deploy

Once the rsconnect package has been configured, you're ready to deploy your first application. If you haven't written any applications yet, you can also checkout the Getting Started Guide for instructions on how to deploy our demo application. Run the following code in your R console.


The shiny page is then up as


It is most convient to convert Tex/LaTex formulas into MicroSoft Word equtions via pandoc, i.e., pandoc -o README.docx.

See and

For Chinese language support, try

sudo apt-get install texlive-latex-base
sudo apt-get install latex-cjk-all
sudo apt-get install texlive-latex-extra
sudo apt-get install texmaker
sudo apt-get install texlive-xetex
sudo apt-get install texlive-publishers

Now change latex to xelatex from Texmaker.

How are you?你好吗?


First, create hello.ts with two lines,

#!/usr/bin/env ts-node
console.log('Hello world!');

and set up the environment,

npm install -g npm
npm install typescript ts-node -g
chmod +x hello.ts

Visual Studio Code

There is a pointer from to Once downloaded, it can be installed with

sudo dpkg -i code_1.23.1-1525968403_amd64.deb

but it requires libgconf-2-4; when failed to install use sudo apt --fix-broken install.

See for the hello world example.