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.
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.
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:
To know what's your Matlab's preferences folder, type the command prefdir at Matlab's command line.
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:
- create a text file called javaclasspath.txt;
- 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;
- save such text file in Matlab's preferences folder.
To know what's your Matlab's preferences folder, type the command prefdir at Matlab's command line.
Labels:
Java,
Matlab,
Matlab initial configuration
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.
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.
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!
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!
Sunday, August 24, 2014
Thursday, July 31, 2014
Memory management in ImageJ: memory release
A few important details about how memory release/emptying in ImageJ:
Wednesday, July 30, 2014
Create a new shortcut to a command in ImageJ/Fiji
Very useful when you frequently call a command and you want to avoid wandering around/through the command menu trees.
Go to the Plugins menu. Choose Shortcuts, then the Create shortcut... command.
Go to the Plugins menu. Choose Shortcuts, then the Create shortcut... command.
Labels:
Fiji,
Image analysis and processing,
ImageJ
Thursday, June 12, 2014
Extract data from a Matlab plot
Very useful instructions about how to extract the data plotted in a figure saved as a Matlab figure (.fig format file), in order to be able to re-plot the data in a different way.
http://www.mathworks.com/matlabcentral/answers/100687-how-do-i-extract-data-from-matlab-figures
http://www.mathworks.com/matlabcentral/answers/100687-how-do-i-extract-data-from-matlab-figures
Thursday, June 5, 2014
7-Zip unavailable for 64-bit Cygwin
7-Zip is one of the most used programs for compression/decompression of files and archives.
p7zip is the porting of 7-Zip for GNU-Linux/POSIX-based systems.
It is not yet available for the 64-bit version of Cygwin.
In this post by Michael Hirsch, there are the instructions for running the 64-bit version of 7-Zip from the Cygwin terminal, which is of fundamental importance if you want to use 7-Zip in scripts for batch backing up of data.
p7zip is the porting of 7-Zip for GNU-Linux/POSIX-based systems.
It is not yet available for the 64-bit version of Cygwin.
In this post by Michael Hirsch, there are the instructions for running the 64-bit version of 7-Zip from the Cygwin terminal, which is of fundamental importance if you want to use 7-Zip in scripts for batch backing up of data.
Tuesday, January 14, 2014
User's session ID under MS Windows 7 and Server 2008 R2
This may be needed sometimes under MS Windows 7 or Server 2008 R2, for any reason ...
find which session ID is associated to a user logged to the machine, interactively or by a Remote Desktop Connection (RDP).
There is a built-in command that you can run from the DOS shell or by the MS PowerShell which is called qwinsta and provides you with all the details about any user session at the moment.
find which session ID is associated to a user logged to the machine, interactively or by a Remote Desktop Connection (RDP).
There is a built-in command that you can run from the DOS shell or by the MS PowerShell which is called qwinsta and provides you with all the details about any user session at the moment.
More than 2 Remote Desktop Connections on a MS Windows Server 2008 R2
On a server running on MS Windows Server 2008 R2, by default configuration, only 2 Remote Desktop Connections (RDPs) are allowed. If you need to change that setup, read the following instructions at
http://technet.microsoft.com/en-us/library/cc753380.aspx
http://technet.microsoft.com/en-us/library/cc753380.aspx
Friday, December 13, 2013
How to add slide numbers in a Microsoft Powerpoint slide
This is not a scientific computing issue ... but it took me a while till I found a decent explanation about how to do that ....
http://blogs.mccombs.utexas.edu/the-most/2012/06/04/when-the-slide-number-doesnt-show-in-powerpoint/
http://blogs.mccombs.utexas.edu/the-most/2012/06/04/when-the-slide-number-doesnt-show-in-powerpoint/
Friday, July 19, 2013
Mount a remote directory on a SFTP server to you local machine
How to mount to your local machine a remote directory on a machine having a running SFTP server:
http://blog.damontimm.com/how-to-mount-a-sftp-folder-ssh-ftp-on-ubuntu-linux-using-sshfs-fuse/
http://blog.damontimm.com/how-to-mount-a-sftp-folder-ssh-ftp-on-ubuntu-linux-using-sshfs-fuse/
Wednesday, July 17, 2013
Wednesday, July 10, 2013
Define a ROI by coordinates and size in ImageJ
Problem: I need to create a ROI in a very large 3D image (4020 x 4020 x 880) by ImageJ. The use of the mouse pointer is not so handy because it's not easy to locate the top-left vertex of the ROI at the exact wanted voxel location, due to the large size of the image.
Solution: Edit/Selection/Specify opens a plugin that allows defining manually the coordinates of the top-left vertex of the ROI, its height, width and on which slice to show you (if you are working with a stack of 2D images).
Labels:
Fiji,
Image analysis and processing,
ImageJ
Monday, May 20, 2013
Two interesting articles about Data Science and Big Data,
http://sciencecareers.sciencemag.org/career_magazine/previous_issues/articles/2013_05_13/caredit.a1300099
http://www.spiegel.de/international/business/big-data-enables-companies-and-researchers-to-look-into-the-future-a-899964.html
http://sciencecareers.sciencemag.org/career_magazine/previous_issues/articles/2013_05_13/caredit.a1300099
http://www.spiegel.de/international/business/big-data-enables-companies-and-researchers-to-look-into-the-future-a-899964.html
Friday, April 12, 2013
Change the format for displaying numbers in Matlab's workspace
By default, Matlab shows in its workspace and at the command line numbers in a format that may not be suitable in all cases, e.g., when you have a large number of decimal digits.
The format of the number display can be changed by the built-in command
where Style indicates different formats.
See the Help page of the format built-in command for its syntax and the list of possible formats.
The format of the number display can be changed by the built-in command
format Style
where Style indicates different formats.
See the Help page of the format built-in command for its syntax and the list of possible formats.
Subscribe to:
Posts (Atom)
