ESPUTR
calculation of sputtering yields
esputr_YTH.F
Go to the documentation of this file.
1 
5 
6 ! Copyright (c) 2016 Forschungszentrum Juelich GmbH
7 ! Markus Brenneis, Vladislav Kotov
8 !
9 ! This file is part of ESPUTR.
10 !
11 ! ESPUTR is free software: you can redistribute it and/or modify
12 ! it under the terms of the GNU General Public License as published by
13 ! the Free Software Foundation, either version 3 of the License, or
14 ! (at your option) any later version.
15 !
16 ! ESPUTR is distributed in the hope that it will be useful,
17 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ! GNU General Public License for more details.
20 !
21 ! You should have received a copy of the GNU General Public License
22 ! along with ESPUTR. If not, see <http://www.gnu.org/licenses/>.
23 !
24 
25 #include "fintrf.h"
26 
34  subroutine mexfunction(nlhs, plhs, nrhs, prhs)
35  use esputr
36  use esputr1993
37  use esputr2001
38  implicit none
40  integer :: nlhs
42  integer :: nrhs
47  mwpointer, dimension(*) :: plhs
56  mwpointer, dimension(*) :: prhs
57 
58  mwpointer :: mxgetpr, mxcreatedoublematrix, mxgetstring
59  integer :: mxIsNumeric, mxIsChar
60  mwsize :: mxgetm, mxgetn
61 
62  mwsize :: n_e0s, n_ths, n_projs, n_targs, n_combinations
63  integer :: err, i, p, t, c, ind
64  logical :: ifexist
65  real(kind=8) :: Emin, Emax
66  mwpointer :: e0s_pr, ths_pr, ys_pr
67  real(kind=8), dimension(:), allocatable :: E0s, THs
68  real(kind=8), dimension(:,:), allocatable :: Ys
69  integer, parameter :: MAX_STR_LEN = 255
70  character(MAX_STR_LEN) :: projsstr, targsstr
71  character(MAX_STR_LEN), dimension(:), allocatable :: projs, targs
72  mwsize :: projs_length, targs_length
73  character(MAX_STR_LEN) :: version, fileTH
74 
75  if(nrhs < 5) then
76  call mexerrmsgtxt('At least 5 arguments required.')
77  elseif (mxisnumeric(prhs(1)) /= 1) then
78  call mexerrmsgtxt('Input # 1 is not a numeric array.')
79  elseif(mxisnumeric(prhs(2)) /= 1) then
80  call mexerrmsgtxt('Input # 2 is not a numeric array.')
81  elseif(mxischar(prhs(3)) /= 1) then
82  call mexerrmsgtxt('Input # 3 must be a string.')
83  elseif(mxischar(prhs(4)) /= 1) then
84  call mexerrmsgtxt('Input # 4 must be a string.')
85  elseif(mxischar(prhs(5)) /= 1) then
86  call mexerrmsgtxt('Input # 5 must be a string.')
87  elseif(nrhs > 5 .and. mxischar(prhs(6)) /= 1) then
88  call mexerrmsgtxt('Input # 6 must be a string.')
89  endif
90 
91  n_ths = mxgetm(prhs(1))
92  if(mxgetn(prhs(1)) /= 1) then
93  call mexerrmsgtxt('Input #1 must be a column vector.')
94  endif
95 
96  n_e0s = mxgetn(prhs(2))
97  if(mxgetm(prhs(2)) /= 1) then
98  call mexerrmsgtxt('Input #2 must be a row vector.')
99  endif
100 
101  n_projs = mxgetm(prhs(3))
102  projs_length = mxgetn(prhs(3))
103  n_targs = mxgetm(prhs(4))
104  targs_length = mxgetn(prhs(4))
105 
106  n_combinations = max(n_projs, n_targs)
107 
108  allocate(projs(n_combinations))
109  allocate(targs(n_combinations))
110 
111  ths_pr = mxgetpr(prhs(1))
112  e0s_pr = mxgetpr(prhs(2))
113  ! If the string array contains several rows, they are copied, one column at a time, into one long string array.
114  err = mxgetstring(prhs(3), projsstr, max_str_len)
115  projs = " "
116  foreachprojectile: do p = 1, n_projs
117  foreachchar: do c = 1, projs_length
118  ind = (c-1)*n_projs+p
119  projs(p)(c:c) = projsstr(ind:ind)
120  end do foreachchar
121  end do foreachprojectile
122  projs(n_projs:n_combinations) = projs(n_projs)
123 
124  err = mxgetstring(prhs(4), targsstr, max_str_len)
125  targs = " "
126  foreachtarget: do t = 1, n_targs
127  foreachchar2: do c = 1, targs_length
128  ind = (c-1)*n_targs+t
129  targs(t)(c:c) = targsstr(ind:ind)
130  end do foreachchar2
131  end do foreachtarget
132  targs(n_targs:n_combinations) = targs(n_targs)
133 
134  err = mxgetstring(prhs(5), version, max_str_len)
135  if(version.ne."2001".and.version.ne."1993") then
136  call mexerrmsgtxt('unknown model: '//trim(version))
137  end if
138 
139  if(version == "2001" .and. nrhs == 6) then
140  err = mxgetstring(prhs(6), fileth, max_str_len)
141  else if(version == "2001" .and. nrhs < 6) then
142  call mexerrmsgtxt('6 arguments required')
143  end if
144 
145  allocate(e0s(n_e0s))
146  allocate(ths(n_ths))
147  allocate(ys(n_ths,n_e0s))
148  call mxcopyptrtoreal8(e0s_pr, e0s, n_e0s)
149  call mxcopyptrtoreal8(ths_pr, ths, n_ths)
150 
151  if(version == "2001") then
152  ! check if input file exists
153  inquire(file=fileth, exist=ifexist, iostat=err)
154  if (.not.ifexist .or. err.ne.0)
155  & call mexerrmsgtxt('File not found: '//trim(fileth))
156  call esputr2001_initth(fileth, err)
157  end if
158  if(err /= 0) then
159  call esputr2001_deallocate(err)
160  call mexerrmsgtxt('initialization error in ESPUTR')
161  endif
162 
163  foreachcombination: do c=1, n_combinations
164  call esputr_yth(ths, n_ths, e0s, n_e0s, projs(c),
165  + targs(c), version, ys, err)
166  if(err /= 0) then
167  if(err == 103 .or. err == 157) then
168  call mexerrmsgtxt('incorrect incident angle '//
169  & '(it must be 0 <= theta <= pi/2)')
170  else if(err == 152) then
171  call mexerrmsgtxt('projectile-target combination '//
172  & trim(projs(c))//'-'//trim(targs(c))//' not found')
173  else if(err == 156) then
174  call mexerrmsgtxt('incident energy must be > 0')
175  else if(err == 158) then
176  call esputr2001_initth(fileth, err)
178  & projs(c), targs(c), emin, emax, err)
179  write(projsstr,*) emin
180  write(targsstr,*) emax
181  call mexerrmsgtxt('no fiting parameters for all '//
182  & 'requested energies for the projectile-target combination '//
183  & trim(projs(c))//'-'//trim(targs(c))//
184  & '; available energy range: ['//
185  & trim(projsstr)//','//trim(targsstr)//'] eV')
186  else
187  call mexerrmsgtxt('error in ESPUTR')
188  endif
189  call esputr2001_deallocate(err)
190  endif
191 
192  plhs(c) = mxcreatedoublematrix(n_ths,n_e0s,0)
193  ys_pr = mxgetpr(plhs(c))
194  call mxcopyreal8toptr(ys,ys_pr,n_e0s*n_ths)
195  end do foreachcombination
196 
197  call esputr2001_deallocate(err)
198 
199  deallocate(e0s)
200  deallocate(ys)
201 
202  end subroutine mexfunction
subroutine mexfunction(nlhs, plhs, nrhs, prhs)
Matlab interface for calculation of sputtering yield for normal incidence.
Definition: esputr_YN.F:35
subroutine, public esputr2001_deallocate(err)
Deallocate dynamic arrays used by this module.
Definition: esputr2001.f90:426
subroutine esputr_yth(THs, n_THs, E0s, n_E0s, proj, targ, version, YTHs, err)
Calculate the angular dependence factor Y(E,theta)/Y(E,0) for selected incident angles and energies f...
subroutine esputr2001_getavailableenergyrangebyname(proj, targ, Emin, Emax, err)
Return the minimum and maximum energies for which the angular dependence data are defined...
subroutine, public esputr2001_initth(fileTHName, err)
Definition: esputr2001.f90:170