save_plasmon_data.lsf 2.3 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. curdir = pwd;
  15. dirname_base = filebasename(currentfilename)+"."+fileextension(currentfilename)+".results";
  16. dirname = curdir+slash+dirname_base;
  17. files = splitstring(dir,endl);
  18. isCreated = false;
  19. for(i=1:length(files)) {
  20. if (files{i} == dirname_base) { isCreated = true;}
  21. }
  22. if (isCreated){ ?"output dir already exist";
  23. } else { system("mkdir "+dirname);}
  24. #########################################
  25. # Get FDTD material data
  26. groupscope("::model::mon");
  27. min_f = getglobalmonitor("minimum frequency");
  28. max_f = getglobalmonitor("maximum frequency");
  29. fpoints = getglobalmonitor("frequency points");
  30. fvec=linspace(min_f,max_f,fpoints);
  31. Au_name = "Au (Gold) - Johnson and Christy Copy 2";
  32. n_fdtd=getfdtdindex(Au_name,fvec,min_f,max_f);
  33. n_fdtd;
  34. #########################################
  35. ?"Save data";
  36. cd(dirname);
  37. format long;
  38. for(x=1:10) {
  39. for (media=1:2){
  40. if (media == 1){shift_sign = 1;} else {shift_sign = -1;}
  41. for(z_shift=1:2){
  42. zshift_all = z_shift*min_mesh_step;
  43. monitor_name = "mon_x"+num2str(x)+"mkm_media"+num2str(media)+"_zshift"+num2str(zshift_all*1e9)+"nm";
  44. select(monitor_name);
  45. E = getresult(monitor_name, "E");
  46. H = getresult(monitor_name, "H");
  47. len = length(E.lambda);
  48. #Save to file
  49. fname = dirname+slash+monitor_name+".txt";
  50. if (fileexists(fname)){rm(fname);}
  51. write(fname,"lambda, dip.power, Ex, Ey, Ez, Hx, Hy, Hz, n_Au");
  52. for (i=1:len){
  53. str = num2str(E.lambda(i))
  54. +", "+num2str(dipolepower(E.f(i)))
  55. +", "+num2str(E.Ex(i))
  56. +", "+num2str(E.Ey(i))
  57. +", "+num2str(E.Ez(i))
  58. +", "+num2str(H.Hx(i))
  59. +", "+num2str(H.Hy(i))
  60. +", "+num2str(H.Hz(i))
  61. +", "+num2str(n_fdtd(i))
  62. ;
  63. write(fname,str);
  64. }
  65. }
  66. }
  67. }
  68. cd(curdir);
  69. redrawon;