47 mwpointer,
dimension(*) :: plhs
56 mwpointer,
dimension(*) :: prhs
58 mwpointer :: mxgetpr, mxcreatedoublematrix, mxgetstring
59 integer :: mxIsNumeric, mxIsChar
60 mwsize :: mxgetm, mxgetn
62 mwsize :: n_e0s, n_ths, n_projs, n_targs, n_combinations
63 integer :: err, i, p, t, c, ind
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
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.')
91 n_ths = mxgetm(prhs(1))
92 if(mxgetn(prhs(1)) /= 1)
then
93 call mexerrmsgtxt(
'Input #1 must be a column vector.')
96 n_e0s = mxgetn(prhs(2))
97 if(mxgetm(prhs(2)) /= 1)
then
98 call mexerrmsgtxt(
'Input #2 must be a row vector.')
101 n_projs = mxgetm(prhs(3))
102 projs_length = mxgetn(prhs(3))
103 n_targs = mxgetm(prhs(4))
104 targs_length = mxgetn(prhs(4))
106 n_combinations = max(n_projs, n_targs)
108 allocate(projs(n_combinations))
109 allocate(targs(n_combinations))
111 ths_pr = mxgetpr(prhs(1))
112 e0s_pr = mxgetpr(prhs(2))
114 err = mxgetstring(prhs(3), projsstr, max_str_len)
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)
121 end do foreachprojectile
122 projs(n_projs:n_combinations) = projs(n_projs)
124 err = mxgetstring(prhs(4), targsstr, max_str_len)
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)
132 targs(n_targs:n_combinations) = targs(n_targs)
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))
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')
147 allocate(ys(n_ths,n_e0s))
148 call mxcopyptrtoreal8(e0s_pr, e0s, n_e0s)
149 call mxcopyptrtoreal8(ths_pr, ths, n_ths)
151 if(version ==
"2001")
then
153 inquire(file=fileth, exist=ifexist, iostat=err)
154 if (.not.ifexist .or. err.ne.0)
155 &
call mexerrmsgtxt(
'File not found: '//trim(fileth))
160 call mexerrmsgtxt(
'initialization error in ESPUTR')
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)
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
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')
187 call mexerrmsgtxt(
'error in ESPUTR')
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
subroutine mexfunction(nlhs, plhs, nrhs, prhs)
Matlab interface for calculation of sputtering yield for normal incidence.
subroutine, public esputr2001_deallocate(err)
Deallocate dynamic arrays used by this module.
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)