|  | @@ -16,6 +16,10 @@
 | 
											
												
													
														|  |        <div class="row justify-xs-center justify-sm-start items-baseline">
 |  |        <div class="row justify-xs-center justify-sm-start items-baseline">
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          <div class="col-auto">
 |  |          <div class="col-auto">
 | 
											
												
													
														|  | 
 |  | +          <q-btn
 | 
											
												
													
														|  | 
 |  | +              no-caps
 | 
											
												
													
														|  | 
 |  | +              @click="saveSpectrumSimulation"
 | 
											
												
													
														|  | 
 |  | +          >Save</q-btn>
 | 
											
												
													
														|  |          </div>
 |  |          </div>
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |        </div>
 |  |        </div>
 | 
											
										
											
												
													
														|  | @@ -29,8 +33,9 @@ import {
 | 
											
												
													
														|  |    computed, watch,
 |  |    computed, watch,
 | 
											
												
													
														|  |  } from 'vue'
 |  |  } from 'vue'
 | 
											
												
													
														|  |  import { useStore } from 'src/store'
 |  |  import { useStore } from 'src/store'
 | 
											
												
													
														|  | -import {range, rangeInt, toUnits} from 'components/utils'
 |  | 
 | 
											
												
													
														|  | 
 |  | +import { getModeName, range, rangeInt} from 'components/utils'
 | 
											
												
													
														|  |  import { cloneDeep } from 'lodash'
 |  |  import { cloneDeep } from 'lodash'
 | 
											
												
													
														|  | 
 |  | +import { saveAs } from 'file-saver'
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  export default defineComponent({
 |  |  export default defineComponent({
 | 
											
												
													
														|  |    name: 'RunSimulationSpectrum',
 |  |    name: 'RunSimulationSpectrum',
 | 
											
										
											
												
													
														|  | @@ -155,7 +160,77 @@ export default defineComponent({
 | 
											
												
													
														|  |      })
 |  |      })
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      return { isRunning, isNmieLoaded,
 |  |      return { isRunning, isNmieLoaded,
 | 
											
												
													
														|  | -      runSpectrumSimulation
 |  | 
 | 
											
												
													
														|  | 
 |  | +      runSpectrumSimulation,
 | 
											
												
													
														|  | 
 |  | +      saveSpectrumSimulation(){
 | 
											
												
													
														|  | 
 |  | +        const fileHeader = '# # You can open and plot this file using Python\n' +
 | 
											
												
													
														|  | 
 |  | +            '# # (without manually removing this header, it will be skipped), see example below.\n' +
 | 
											
												
													
														|  | 
 |  | +            '# import numpy as np\n' +
 | 
											
												
													
														|  | 
 |  | +            '# from matplotlib import pyplot as plt\n' +
 | 
											
												
													
														|  | 
 |  | +            '# data = np.genfromtxt(\'scattnlay-spectra.txt\', skip_header=21, names=True, delimiter=\', \')\n' +
 | 
											
												
													
														|  | 
 |  | +            '# x = data[data.dtype.names[0]] # x-axis has units\n' +
 | 
											
												
													
														|  | 
 |  | +            '# # Possible labels for spectrum data: Qsca, Qabs, Qext,\n' +
 | 
											
												
													
														|  | 
 |  | +            '# # Qsca_E_dipole, etc. (see last comment before spectra data)\n' +
 | 
											
												
													
														|  | 
 |  | +            '# a = data[\'Qsca\']\n' +
 | 
											
												
													
														|  | 
 |  | +            '# b = data[\'Qsca_E_dipole\']\n' +
 | 
											
												
													
														|  | 
 |  | +            '# c = data[\'Qsca_H_dipole\']\n' +
 | 
											
												
													
														|  | 
 |  | +            '# \n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.figure()\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.plot(x, a, label=\'Qsca\')\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.plot(x, b, label=\'Qsca E dipole\')\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.plot(x, c, label=\'Qsca H dipole\')\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.legend()\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.xlabel(data.dtype.names[0].replace(\'_\', \', \'))\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.ylabel(\'Normalized cross-sections\')\n' +
 | 
											
												
													
														|  | 
 |  | +            '# plt.show()\n\n'
 | 
											
												
													
														|  | 
 |  | +        let xTitle = 'x'
 | 
											
												
													
														|  | 
 |  | +        if ( $store.state.plotRuntime.spectraPlot.layout.xaxis ) {
 | 
											
												
													
														|  | 
 |  | +          xTitle = String($store.state.plotRuntime.spectraPlot.layout.xaxis.title)
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        let columnNames = '# ' + xTitle + ', Qsca, Qabs, Qext, '
 | 
											
												
													
														|  | 
 |  | +        const mode_n = rangeInt($store.state.simulationSetup.current.numberOfModesToPlot, 1);
 | 
											
												
													
														|  | 
 |  | +        const mode_types = range(0, 1);
 | 
											
												
													
														|  | 
 |  | +        for (const n of mode_n) {
 | 
											
												
													
														|  | 
 |  | +          for (const mode_type of mode_types) {
 | 
											
												
													
														|  | 
 |  | +            const modeTypeName = mode_type == 0 ? 'E' : 'H'
 | 
											
												
													
														|  | 
 |  | +            columnNames += 'Qsca_' + modeTypeName + '_' +getModeName(n)+', '
 | 
											
												
													
														|  | 
 |  | +            columnNames += 'Qabs_' + modeTypeName + '_' +getModeName(n)+', '
 | 
											
												
													
														|  | 
 |  | +            columnNames += 'Qext_' + modeTypeName + '_' +getModeName(n)+', '
 | 
											
												
													
														|  | 
 |  | +          }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        columnNames = columnNames.slice(0, -2)
 | 
											
												
													
														|  | 
 |  | +        columnNames += '\n'
 | 
											
												
													
														|  | 
 |  | +        let body = ''
 | 
											
												
													
														|  | 
 |  | +        const WLs = $store.state.plotRuntime.WLsInUnits
 | 
											
												
													
														|  | 
 |  | +        const Qsca = $store.state.plotRuntime.Qsca
 | 
											
												
													
														|  | 
 |  | +        const Qabs = $store.state.plotRuntime.Qabs
 | 
											
												
													
														|  | 
 |  | +        const Qext = $store.state.plotRuntime.Qext
 | 
											
												
													
														|  | 
 |  | +        const Qsca_n = $store.state.plotRuntime.Qsca_n
 | 
											
												
													
														|  | 
 |  | +        const Qabs_n = $store.state.plotRuntime.Qabs_n
 | 
											
												
													
														|  | 
 |  | +        const Qext_n = $store.state.plotRuntime.Qext_n
 | 
											
												
													
														|  | 
 |  | +        for (let i = 0; i < WLs.length; ++i) {
 | 
											
												
													
														|  | 
 |  | +          let row = WLs[i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +              + Qsca[i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +              + Qabs[i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +              + Qext[i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +          for (const n of mode_n) {
 | 
											
												
													
														|  | 
 |  | +            for (const mode_type of mode_types) {
 | 
											
												
													
														|  | 
 |  | +              row += Qsca_n[mode_type][n - 1][i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +              row += Qabs_n[mode_type][n - 1][i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +              row += Qext_n[mode_type][n - 1][i].toString() + ', '
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +          }
 | 
											
												
													
														|  | 
 |  | +          row = row.slice(0, -2)
 | 
											
												
													
														|  | 
 |  | +          row += '\n'
 | 
											
												
													
														|  | 
 |  | +          body += row
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        const scattnlaySpectra = new Blob([fileHeader+columnNames+body],
 | 
											
												
													
														|  | 
 |  | +            {type: 'text/plain;charset=utf-8',
 | 
											
												
													
														|  | 
 |  | +              endings: 'native'}  //TODO test if newline is correctly written in Windows, MacOS
 | 
											
												
													
														|  | 
 |  | +        )
 | 
											
												
													
														|  | 
 |  | +        saveAs(scattnlaySpectra, 'scattnlay-spectra.txt');
 | 
											
												
													
														|  | 
 |  | +      }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |    },
 |  |    },
 | 
											
												
													
														|  |  })
 |  |  })
 |