Pages

Thursday, April 18, 2013

Convert Fortran code to Matlab code


Download f2matlab.

1. Put the f2matlab file in a folder (eg. /home/khan/)
2. Open matlab and add the documents directory to your matlab path
- put "addpath '/home/khan' " at the matlab command prompt.
3. Call the f2matlab function with your fortran program name:
- put " f2matlab('msphere.f') " at the matlab command prompt.

Source

Wednesday, April 17, 2013

Downloading files in folders with wget


wget  -r -nH --cut-dirs=2 --no-parent ftp://aurapar2u.ecs.nasa.gov/data/s4pa///Aura_OMI_Level2/OMAERUV.003//2012/183/*

The above command will create directory structure /Aura_OMI_Level2/OMAERUV.003/2013/183/ and download all files in it. If there are any subdirectories in /183, they will also be created automatically.

Plotting on a world map with Matlab


%Initialize the map
load coast;
worldmap('world');
set(gcf,'color','white');
plotm(lat,long, 'k-');

%Plot data
surfm(Lat, Lon, data);
colorbar('horiz');

%set colorbar limits
set(gca, 'CLim',[min(data(~isnan(data))) 
max(data(~isnan(data)))]);
title('20080601');

Mounting writable Samba share in Ubuntu

The line below will be written at the end of /etc/fstab:

//192.168.1.5/my/folder /home/mounts/localmount cifs user=admin,password=123,rw,iocharset=utf8,uid=1000,gid=1000 0 0

replace the server, folder and user information.

Source

Monday, April 8, 2013

g++ useful flags while compiling


g++ -Wall -Wextra -pedantic -o test test.cpp

Wall: Warnings all.
Wextra: Warnings extra.
pedantic: Check for forbidden extensions.

Sunday, April 7, 2013

Calling Fortran from C++

Compilers: gfortran, g++

increment.f90:
subroutine increment(n)
integer n
n=n+1
return
end subroutine

callf.cpp:
#include<iostream>

extern "C" { int increment_( int& ); }

int main(int argc, char **argv) {
  int i=0;
  int j=0;
  for(j=0;j<10;j++)
  {
 increment_(i);
 std::cout << i << "\n";
  }
  return 1;
}

Commands:
$ gfortran -c increment.f90 
$ g++ -o called callf.cpp increment.o -lgfortran

Output:
$ ./called 
1
2
3
4
5
6
7
8
9
10