########################################################################### # Scriptfile: usr_create_fld.lsf # # Description: # This file will take arbitrary electric field data and create an fld file # that can be used as a source in FDTD Solutions # Do not edit this file as an incorrectly defined fld files will have # unpredictable behaviour when read into FDTD Solutions # # It uses global variables to create the file. The following variables must # be defined and dimensioned prior to calling this file # # include_H: flag to denote if H fields are defined # axis1 : the first axis (1,2,3 for x,y,z) # axis2 : the second axis (1,2,3 for x,y,z) # min1 : the minimum value of axis 1 # max1 : the maximum value of axis 1 # min2 : the minimum value of axis 2 # max2 : the maximum value of axis 2 # depth : the depth along the 3rd axis # wavelength : the desired wavelength of the source # power : the desired total source power in W # index : the desired refractive index for input # n1 : The number of field points along axis 1 # n2 : The number of field points along axis 2 # Ex : Electric field, x component, must have dimension n1 x n2, can be complex # Ey : Electric field, y component, must have dimension n1 x n2, can be complex # Ez : Electric field, z component, must have dimension n1 x n2, can be complex # Hx : Magnetic field, x component, must have dimension n1 x n2, can be complex # Hy : Magnetic field, y component, must have dimension n1 x n2, can be complex # Hz : Magnetic field, z component, must have dimension n1 x n2, can be complex # sourcefilename: the filename of the source you would like, with no extension # # Copyright 2012, Lumerical Solutions, Inc. ########################################################################### filename = sourcefilename + ".fld"; del(filename); write(filename,"! File created to read arbitrary electric field into FDTD Solutions"); zero = num2str(0); write(filename,zero); write(filename,zero); write(filename,zero); write(filename,zero); write(filename,zero); write(filename,zero); if( (axis1 == axis2) | (axis1 < 1) | (axis1 > 3) | (axis2 < 1) | (axis2 > 3) ) { ?"Fatal problem defining axis1 and axis2"; break; } write(filename,num2str(axis1)); write(filename,num2str(axis2)); write(filename,zero); write(filename,num2str(min1)); write(filename,num2str(max1)); write(filename,num2str(n1)); write(filename,num2str(min2)); write(filename,num2str(max2)); write(filename,num2str(n2)); write(filename,num2str(depth)); write(filename,num2str(wavelength)); write(filename,num2str(power)); write(filename,num2str(index)); write(filename,num2str(1)); write(filename,zero); temp_write_matrix = matrix(n2*n1*12,1); write_position = 0; for(j = 1:n2) { ?"creating source file, " + num2str(j/n2*100) + "% complete"; for(i = 1:n1) { temp_write_matrix(write_position+1) = real(Ex(i,j)); temp_write_matrix(write_position+2) = imag(Ex(i,j)); temp_write_matrix(write_position+3) = real(Ey(i,j)); temp_write_matrix(write_position+4) = imag(Ey(i,j)); temp_write_matrix(write_position+5) = real(Ez(i,j)); temp_write_matrix(write_position+6) = imag(Ez(i,j)); if (include_H) { temp_write_matrix(write_position+7) = real(Hx(i,j)); temp_write_matrix(write_position+8) = imag(Hx(i,j)); temp_write_matrix(write_position+9) = real(Hy(i,j)); temp_write_matrix(write_position+10) = imag(Hy(i,j)); temp_write_matrix(write_position+11) = real(Hz(i,j)); temp_write_matrix(write_position+12) = imag(Hz(i,j)); } write_position = write_position+12; } } write(filename,num2str(temp_write_matrix)); write(filename,endl);