ESPUTR
calculation of sputtering yields
esputr_YN.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
55  mwpointer, dimension(*) :: prhs
56 
57  mwpointer :: mxgetpr, mxcreatedoublematrix, mxgetstring
58  integer :: mxIsNumeric, mxIsChar
59  mwsize :: mxgetm, mxgetn
60 
61  mwsize :: n_e0s, n_projs, n_targs, n_combinations
62  integer :: err, i, p, t, c, ind
63  mwpointer :: e0s_pr, ys_pr
64  real(kind=8), dimension(:), allocatable :: E0s
65  real(kind=8), dimension(:), allocatable :: Ys
66  integer, parameter :: MAX_STR_LEN = 255
67  character(MAX_STR_LEN) :: projsstr, targsstr
68  character(MAX_STR_LEN), dimension(:), allocatable :: projs, targs
69  mwsize :: projs_length, targs_length
70  character(MAX_STR_LEN) :: version, fileN
71  logical :: ifexist
72  integer :: io
73  intrinsic trim
74 
75  if (nrhs /= 5) then
76  call mexerrmsgtxt('5 arguments required.')
77  elseif (mxisnumeric(prhs(1)) /= 1) then
78  call mexerrmsgtxt('Input # 1 is not a numeric array.')
79  elseif(mxischar(prhs(2)) /= 1) then
80  call mexerrmsgtxt('Input # 2 must be a string.')
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  endif
88 
89  n_e0s = mxgetn(prhs(1))
90  if(mxgetm(prhs(1)) /= 1) then
91  call mexerrmsgtxt('Input #1 must be a row vector.')
92  endif
93 
94  n_projs = mxgetm(prhs(2))
95  projs_length = mxgetn(prhs(2))
96  n_targs = mxgetm(prhs(3))
97  targs_length = mxgetn(prhs(3))
98 
99  n_combinations = max(n_projs, n_targs)
100 
101  allocate(projs(n_combinations))
102  allocate(targs(n_combinations))
103 
104  e0s_pr = mxgetpr(prhs(1))
105  ! If the string array contains several rows, they are copied, one
106  ! column at a time, into one long string array. So we must
107  ! "transpose" the strings here.
108  err = mxgetstring(prhs(2), projsstr, max_str_len)
109  projs = " "
110  foreachprojectile: do p = 1, n_projs
111  foreachchar: do c = 1, projs_length
112  ind = (c-1)*n_projs+p
113  projs(p)(c:c) = projsstr(ind:ind)
114  end do foreachchar
115  end do foreachprojectile
116  projs(n_projs:n_combinations) = projs(n_projs)
117 
118  err = mxgetstring(prhs(3), targsstr, max_str_len)
119  targs = " "
120  foreachtarget: do t = 1, n_targs
121  foreachchar2: do c = 1, targs_length
122  ind = (c-1)*n_targs+t
123  targs(t)(c:c) = targsstr(ind:ind)
124  end do foreachchar2
125  end do foreachtarget
126  targs(n_targs:n_combinations) = targs(n_targs)
127 
128  err = mxgetstring(prhs(4), version, max_str_len)
129  err = mxgetstring(prhs(5), filen, max_str_len)
130 
131  allocate(e0s(n_e0s))
132  allocate(ys(n_e0s))
133  call mxcopyptrtoreal8(e0s_pr, e0s, n_e0s)
134 
135  esputr_unit=0 !VK in order to print ESPUTR messages to the terminal
136 
137  !VK check if input file exist
138  inquire(file=filen,exist=ifexist,iostat=io)
139  if (.not.ifexist.or.io.ne.0)
140  f call mexerrmsgtxt('File not found: '//trim(filen))
141 
142  if(version == "1993") then
143  call esputr1993_init(filen, err)
144  else if(version == "2001") then
145  call esputr2001_initn(filen, err)
146  else
147  call mexerrmsgtxt('unknown model: '//trim(version))
148  end if
149  if(err /= 0) then
150  call esputr1993_deallocate(err)
151  call esputr2001_deallocate(err)
152  call mexerrmsgtxt('initialization error in ESPUTR')
153  endif
154 
155  foreachcombination: do c=1, n_combinations
156  call esputr_yn(e0s, n_e0s, projs(c), targs(c), version,
157  & ys, err)
158  if(err /= 0) then
159  if(err == 101) then
160  call mexerrmsgtxt('projectile '//trim(projs(c))//
161  & ' not found')
162  else if(err == 102) then
163  call mexerrmsgtxt('target '//trim(targs(c))//
164  & ' not found')
165  else if(err == 151) then
166  call mexerrmsgtxt('projectile-target combination '//
167  & trim(projs(c))//'-'//trim(targs(c))//' not found')
168  else
169  call mexerrmsgtxt('error in ESPUTR')
170  endif
171  call esputr1993_deallocate(err)
172  call esputr2001_deallocate(err)
173  endif
174  plhs(c) = mxcreatedoublematrix(1,n_e0s,0)
175  ys_pr = mxgetpr(plhs(c))
176  call mxcopyreal8toptr(ys,ys_pr,n_e0s)
177  end do foreachcombination
178 
179  call esputr1993_deallocate(err)
180  call esputr2001_deallocate(err)
181 
182  deallocate(e0s)
183  deallocate(ys)
184 
185  end subroutine mexfunction
subroutine, public esputr1993_deallocate(err)
Deallocate dynamic arrays used by the module ESPUTR1993.
Definition: esputr1993.f90:329
subroutine mexfunction(nlhs, plhs, nrhs, prhs)
Matlab interface for calculation of sputtering yield for normal incidence.
Definition: esputr_YN.F:35
subroutine, public esputr2001_initn(fileNName, err)
Definition: esputr2001.f90:152
subroutine, public esputr1993_init(constantsFile, err)
Initialization of the 1993-model.
Definition: esputr1993.f90:82
subroutine, public esputr2001_deallocate(err)
Deallocate dynamic arrays used by this module.
Definition: esputr2001.f90:426
subroutine esputr_yn(E0s, n_E0s, proj, targ, version, YNs, err)
Calculate sputtering yield for normal incidence for selected incident energies and the specified proj...
integer, save, public esputr_unit
Index of the unit for standard output, default value 6.
Definition: esputr.f90:73