Export fields

From CUDOS
Jump to: navigation, search

Numerical values of the electric, magnetic and Poynting vector fields of a mode contained in a bcf or fbb file can be exported using Winfield and Batchfield.

Winfield

Fields of a mode displayed in winfield can be exported at the same resolution as the field is displayed (that is with (resolution )x( resolution) spatial data points). To do so, open the 'advanced tools' dialog by clicking the 'more options' button in the main Winfield Dialog.

Writefielddlg.png

Controls in the Field group (see image) enable you to write the computed fields to files in various formats. The file format can be selected in the Format drop down list. Once you have chosen the file format, click on the Write file... button to open a standard windows ’Save As’ dialog. File formats are as follows:

selected part text xyz (*.txt)
Writes the selected part (real, imaginary, abs, phase, log(abs)) of the selected component and field (as selected in the main dialog) to a text file in three columns separated by spaces. The first two columns are the x and y coordinates, the third column is the value of the selected part / component / field. Note that by default no file extension is added to the file name, so that you have to type in the desired file extension in the ’Save As’ dialog.
selected complex field text xyz (*.txt)
Writes the selected component and field (as selected in the main dialog) to a text file in four columns separated by spaces. The first two columns are the x and y coordinates, the third and fourth column are the real and imaginary part of the selected component and field. Note that by default no file extension is added to the file name, so that you have to type in the desired file extension in the ’Save As’ dialog.
Selected part text matrix (*.txt)
Writes the selected part (real, imaginary, abs, phase, log(abs)) of the selected component and field (as selected in the main dialog) to a text file in matrix format. The file contains a resolution×resolution matrix of numbers representing the value of the selected part/component/field for each pixel. You can write the x,y coordinates associated with each pixel in the same format using the x,y coor matrix (*.txt) option (see below). Note that by default no file extension is added to the file name, so that you have to type in the desired file extension in the ’Save As’ dialog.
selected complex field text matrix (*.txt)
Writes imaginary and real parts of the selected component and field (as selected in the main dialog) to a two text files in matrix format. The names of the matrix file containing the real and imaginary part are formed by adding ’_r’ and ’_i’, respectively, to the file name selected in the ’Save As’ dialog. The files contains a resolution×resolution matrix of numbers representing the real/imaginary part of the selected component and field for each pixel. You can write the x,y coordinates associated with each pixel in the same format using the x,y coor matrix (*.txt) option (see below). Note that by default no file extension is added to the file name, so that you have to type in the desired file extension in the ’Save As’ dialog. This format is particularly suitable for importing the complex fields in matrix manipulating software eg Matlab or Octave.
x,y coor matrix (*.txt)
Writes the x and y coordinates of each pixel in matrix form in two different files. The names of the matrix file containing the x and y coordinates are formed by adding ’_x’ and ’_y’, respectively, to the file name selected in the ’Save As’ dialog. The files contains a resolution×resolution matrix of numbers representing the x/y coordinates of each pixel. Note that by default no file extension is added to the file name, so that you have to type in the desired file extension in the ’Save As’ dialog.
as seen Windows Bitmap(*.bmp)
Writes the exact content of the Winfield’s field window to a windows bitmap file you can open with any Windows image editor (eg Paint, Windows Picture and Fax viewer etc.). If no file extension is added in the ’Save As’ dialog, the .bmp extension is automatically added.
all fields
Write all components of all fields as well a refractive index map into a single file, that can then easily be loaded in matlab for further use. The file is a comma separated value file containing resolution2 lines corresponding to all calculated field values. Each line contains
x, y, real(local refractive index), imag(local refractive index), material, real(e_x), imag(e_x),real(e_y), imag(e_y),real(e_z), imag(e_z), real(h_x), imag(h_x), real(h_y), imag(h_y), real(h_z), imag(h_z)

material is the ordinal index of the local material at x,y. If

  • material=0, then the material is defined without material dispersion, and has refractive index given by 'local refractive index' at all wavelengths.
  • material=-1, the internal Wijngaard expansion for silica has been used.
  • material>0, a user defined material has been used. The number typically refers to the order in which the user defined materials are defined in the structure file.

The matlab function CMUloadfields.m can then be used to import all fields and refractive index map into matlab:

fieldstructure=CMUloadfields('filename.dat')

will create load all the fields into a structure with following components:

fieldstructure.x(resolution,resolution)
x coordinate of each point in the array
fieldstructure.y(resolution,resolution)
y coordinate of each point in the array
fieldstructure.n(resolution,resolution)
refractive index at each point in the array
fieldstructure.mat(resolution,resolution)
material ordinal index of each point in the array
fieldstructure.ex(resolution,resolution)
x component of the electric field at each point in the array
fieldstructure.ey(resolution,resolution)
y component of the electric field at each point in the array
fieldstructure.ez(resolution,resolution)
z component of the electric field at each point in the array
fieldstructure.hx(resolution,resolution)
x component of the magnetic field at each point in the array
fieldstructure.hy(resolution,resolution)
y component of the magnetic field at each point in the array
fieldstructure.hz(resolution,resolution)
z component of the magnetic field at each point in the array

For example after saving all fields into a file called allfieldstext.dat in winfield using the all fields option, in matlab

a=CMUloadfields('allfieldstext.dat')
h=pcolor(a.x,a.y,real(a.ez));set(h,'EdgeColor','None')

will load all the fields in variable a, and then plot the Ez field.