save_1D_monitor.lsf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. clear;
  2. redrawoff;
  3. slash = "/";
  4. if (operatingsystem == "windows") {slash = "\\";}
  5. #########################################
  6. # Set constants
  7. mkm = 1e-6;
  8. groupscope("::model");
  9. select("FDTD");
  10. min_mesh_step=get("min mesh step");
  11. select("sub-Au");
  12. sub_Au_z_max = get("z max");
  13. #########################################
  14. # Create results dir if needed
  15. monitor_name = "monitor_2";
  16. curdir = pwd;
  17. dirname_base = filebasename(currentfilename)+"."+fileextension(currentfilename)+".1D."+monitor_name+".results";
  18. dirname = curdir+slash+dirname_base;
  19. files = splitstring(dir,endl);
  20. isCreated = false;
  21. for(i=1:length(files)) {
  22. if (files{i} == dirname_base) { isCreated = true;}
  23. }
  24. if (isCreated){ ?"output dir already exist";
  25. } else { system("mkdir "+dirname);}
  26. #########################################
  27. # Get FDTD material data
  28. #groupscope("::model::mon");
  29. min_f = getglobalmonitor("minimum frequency");
  30. max_f = getglobalmonitor("maximum frequency");
  31. fpoints = getglobalmonitor("frequency points");
  32. fvec=linspace(min_f,max_f,fpoints);
  33. #Au_name = "Au (Gold) - Johnson and Christy Copy 2";
  34. Au_name = "Au-McPeak";
  35. n_fdtd=getfdtdindex(Au_name,fvec,min_f,max_f);
  36. #n_fdtd;
  37. #########################################
  38. ?"Save data";
  39. cd(dirname);
  40. ?dirname;
  41. format long;
  42. #z_arr = [5, 20];
  43. #########################################
  44. E = getresult(monitor_name, "E");
  45. H = getresult(monitor_name, "H");
  46. wl_len = length(E.lambda);
  47. z_len = length(E.z);
  48. for (j=1:wl_len){
  49. #Save to file
  50. fname = dirname+slash+"wl"+num2str(E.lambda(j))+".txt";
  51. ?E.lambda(j);
  52. if (fileexists(fname)){rm(fname);}
  53. write(fname,"z, dip.power, Ex, Ey, Ez, Hx, Hy, Hz, n_Au");
  54. for (i=1:z_len){
  55. str = num2str(E.z(i))
  56. +", "+num2str(dipolepower(E.f(j)))
  57. +", "+num2str(E.Ex(1,1,i,j))
  58. +", "+num2str(E.Ey(1,1,i,j))
  59. +", "+num2str(E.Ez(1,1,i,j))
  60. +", "+num2str(H.Hx(1,1,i,j))
  61. +", "+num2str(H.Hy(1,1,i,j))
  62. +", "+num2str(H.Hz(1,1,i,j))
  63. +", "+num2str(n_fdtd(j))
  64. ;
  65. write(fname,str);
  66. }
  67. }
  68. cd(curdir);
  69. redrawon;