############################################### # scriptfile: usr_importbinary_3d.lsf # # description: The first section of this file shows how # to create a text file with binary import data # # The second section shows how to import the data # from a text file into an import object. # # Copyright 2013, Lumerical Solutions, Inc. ############################################### ############################################### # Section 1 # export binary data to a text file # generate a volume of data radius = 50; x = linspace(-radius,radius,100); y = linspace(-radius,radius,101); z = linspace(-radius,radius,102); X = meshgrid3dx(x,y,z); Y = meshgrid3dy(x,y,z); Z = meshgrid3dz(x,y,z); binary = (X^2+Y^2+Z^2) <= radius^2; # choose a filename and delete the file if it exists filename = "usr_importbinary_3d.txt"; rm(filename); # write the header write(filename,num2str(length(x)) + " " + num2str(x(1)) + " " + num2str(x(length(x)))); write(filename,num2str(length(y)) + " " + num2str(y(1)) + " " + num2str(y(length(y)))); write(filename,num2str(length(z)) + " " + num2str(z(1)) + " " + num2str(z(length(z)))); # write the vector to file, reshape to a column write(filename,num2str(reshape(binary,[length(binary),1]))); # End of section 1 ############################################### ############################################### # Section 2 # load binary data from a text file into import object # add an import objectz addimport; # choose the desired options filename = "usr_importbinary_3d.txt"; file_units = "nm"; x0 = 0; y0 = 0; z0 = 0; reverse_index_order = 0; # choose 1 to reverse order of indices as read from file # import the data from file importbinary(filename,file_units,x0,y0,z0,reverse_index_order); set("material","Au (Gold) - CRC"); # End of section 2 ###############################################