Monday, May 25, 2020

Integer arithmetics with environment variables in Bash

Here there's the trivial problem type: I have a collection of files enumerated with an index with format %03i, according to the usual C-like syntax, e.g., fileName001.dat fileName002.dat fileName003.dat .... fileName00N.dat I need to rename these files such that the second file in that series gets index 003, the 3rd file gets index 004 and so on. I essentially need to increase of one unit the value of each file index and then print it in the right format. Integer arithmetics is possible in Bash using the arithmetic evaluation compound command (( <expression> )) where <expression> is the arithmetic expression involving environment variables previously assigned integer values. To solve the previous problem, export I=2 J=$((I+1)) echo $J 3 printf -v COUNTERNEW "%03d" "$J" echo $COUNTERNEW 003 printf -v COUNTEROLD "%03d" "$I" mv fileName${COUNTEROLD}.dat fileName${COUNTERNEW}.dat See more information about the arithmetic operation compound command at http://wiki.bash-hackers.org/syntax/ccmd/arithmetic_eval.

Tuesday, April 14, 2020

Initialization of BASH sessions under Cygwin

If you are using GNU-Linux terminals under Microsoft (MS) Windows via Cygwin (which you should because MS Windows terminals, both the simple command prompt and the PowerShell are simply much, much, much ... powerful than a GNU-Linux terminal/shell), for example, the standard BASH Cygwin terminal, keep in mind that when you open such terminal, by default a login shell session is started.

When a login shell session is started, the usual BASH initial configuration file .bashrc is not automatically run ("sourced").
In addition, by default, no such BASH configuration file (.bashrc) originally exists.

If you want to create one and to put in it commands and function calls which you need at every BASH session, you need either to manually source such file after the terminal has been opened (buhhhh! very dumb and boring!!) or you need to automatically source it. How to do that?

What is automatically sourced at startup is the file .bash_profile (if you have created such file, by default it does not exist as well).

Thus, create a .bash_profile in your home folder, create a .bashrc file in the same folder and add the following BASH conditional statement inside the .bash_profile file:

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi


See here for more information.

Sunday, March 24, 2019

Close ("kill") an open user session

It may frequently happen that a user's session, with a graphical desktop, may get stuck, for whatever unknown reason.
The system admin may then need to close ("kill" in Unix/Linux language).
Here you find a few suggestions on how to kill single processes running in that session, which may be responsible for freezing the graphical desktop, or how to kill the  user session itself.

Thursday, January 3, 2019

Use your Java classes in Matlab

If you have Java classes which you want to use in your Matlab functions/scripts, you need to add the folders or the Java class themselves where they are saved into Matlab's Java class path.

Matlab's Java classpath is a list of folders which is automatically created at Matlab startup.
This list typically contains only folders of predefined Java classes which comes with Matlab itself.

To include additional Java classes, you need to:

  1. create a text file called javaclasspath.txt;
  2. insert on a line of that file the full path of the folder containing the Java class file or the full path of the Java class filename itself;
  3.  save such text file in Matlab's preferences folder.
Whether you need to include in the javaclasspath.txt file the full path of the folder containing a Java class file or the full path of the filename itself depends upon the type of Java class file. For example, for a Java class archive file (.jar file), you need to provide the full path of the filename itself. For more info, see the Matlab's online Help page about the Java class path or search Matlab's online Help for "Java class path".

To know what's your Matlab's preferences folder, type the command prefdir at Matlab's command line.


Friday, July 8, 2016

Import in Matlab temporal signals (waveforms) recorded in .hws files by a National Instruments digitizer

National Instruments digitizers can save temporal signals, i.e., waveforms, in binary files with a National Instruments' proprietary format called Hierarchical Waveform Storage, based upon the HDF5 format for data storage and representation.

A waveform stored in a file with that format contains not only the time series of the signal, rather a huge amount of other data and metadata about the measurement configuration and about the settings of the National Instruments digitizer.

These additional data and metadata can be extremely useful to recover information about scaling factors, sampling rate, instrument settings, etc. ...

A .hws is a HDF5 file, thus it can be explored and read in by Matlab using its built-in functions for reading HDF5 datasets and attributes.

See this post and this other one for a few hints about importing in Matlab a waveform stored in a .hws file.

Wednesday, December 31, 2014

Scalar or vector field on structured, uniform grid - Create VTK file for loading into Paraview

Thanks to Joe Yeh for having created a Matlab function, vtkwrite(...), to create a file where scalar and/or vector fields defined on a structured, uniform and regular grid can be saved according to the VTK format needed to be imported in Paraview.
It's a very handy function. To create scalar and vector fields defined on a structured, uniform and regular grid is easy in Matlab. To be able to load the dataset into Paraview is fantastic because one can exploit the powerful visualization and analysis tools of that software.
The Matlab function can be downloaded from this URL.

Load a 3D image in Paraview

How to import a stack of 2D images (3D image) in Paraview?
It may seem a trivial question ... but without knowing some details it may take some time the first time one tries doing that.
See some useful tips at this URL.
Thanks to the Univ. of Manchester, IT Services Group and Computational Science Community Wiki administrators for posting these tips.

Update (14. January 2019)

From version 5.6.0, it's possible to import into Paraview stacks of 2D TIFF image files interpreting them not as a time series of 2D images but as a 3D volume. See the 4.4 version release notes here (point 15.13). Search for "tomography" or for "image stack" as a keyword.
ATTENTION: compared with opening the stack in, say, ImageJ and one of its 3D rendering plugins, e.g., VolumeViewer, the images in the stack are mirrored along the vertical (Y-)axis. Be careful about that!