save_1D_monitor.lsf 2.0 KB

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