La subrutina open_over se ha incluido dentro de este modulo con procesos
[ptslat.git] / ncpack_displ.f90
bloba4c6d731721248d2e8852b1f7602e15b1d3e31ed
1 MODULE NCPACK_DPL
2 Use typeSizes
3 Use NETCDF
4 Use Dot_Geometry, ONLY : Rqd_Base,Rqd_Top,Hqd,ISHAPE
5 Use Input_Data
6 Use Auxiliar_Procedures, ONLY : MTYPE, check
7 IMPLICIT NONE
9 INTEGER,PRIVATE :: ncFileID, HdVarID, RtVarID, RbVarID, NDots_XVarID, &
10 NDots_YVarID,NDots_ZVarID, A1VarID, A2VarID, A3VarID, &
11 DWL_VarID, Dim3ID
14 CONTAINS
16 SUBROUTINE NCPACK_DPL_CART(UX,UY,UZ)
19 IMPLICIT NONE
21 REAL,DIMENSION(:,:,:) :: UX,UY,UZ
23 ! netcdf related variables
24 integer :: DimXID, DimYID, DimZID,i, &
25 uxVarID, uyVarID, uzVarID, &
26 DimXVarID, DimYVarID, DimZVarID
28 ! Local variables
29 character (len = 60) :: fileName
31 !-----
32 ! Initialization
33 !-----
35 fileName = DPL_Filename
38 ! --------------------
39 ! Code begins
40 ! --------------------
41 if(.not. byteSizesOK()) then
42 print *, "Compiler does not appear to support required kinds of variables."
43 stop
44 end if
46 ! Create the file
48 call open_over(fileName) !Check if a file with the same name exists
50 call check(nf90_create(path = trim(fileName), cmode = nf90_clobber, ncid = ncFileID))
52 CALL NCPACK_INPUT_DPL( )
54 ! Define the dimensions
55 call check(nf90_def_dim(ncid = ncFileID, name = "dimx", len = XDim, dimid = DimXID))
56 call check(nf90_def_dim(ncid = ncFileID, name = "dimy", len = YDim, dimid = DimYID))
57 call check(nf90_def_dim(ncid = ncFileID, name = "dimz", len = ZDim, dimid = DimZID))
59 ! Create variables and attributes
61 ! Box sizes
64 call check(nf90_def_var(ncFileID, "dimx", nf90_float, dimids = DimXID, varID = DimXVarID) )
65 call check(nf90_put_att(ncFileID, DimXVarID, "long_name", "X dimension"))
66 call check(nf90_put_att(ncFileID, DimXVarID, "units", "Angstroms"))
68 call check(nf90_def_var(ncFileID, "dimy", nf90_float, dimids = DimYID, varID = DimYVarID) )
69 call check(nf90_put_att(ncFileID, DimYVarID, "long_name", "Y dimension"))
70 call check(nf90_put_att(ncFileID, DimYVarID, "units", "Angstroms"))
72 call check(nf90_def_var(ncFileID, "dimz", nf90_float, dimids = DimZID, varID = DimZVarID) )
73 call check(nf90_put_att(ncFileID, DimZVarID, "long_name", "Z dimension"))
74 call check(nf90_put_att(ncFileID, DimZVarID, "units", "Angstroms"))
77 ! strain grids
78 call check(nf90_def_var(ncid = ncFileID, name = "ux", xtype = nf90_float, &
79 dimids = (/ DimXID, DimYID, DimZID /), varID = uxVarID) )
80 call check(nf90_put_att(ncFileID, uxVarID, "long_name", "ux"))
82 call check(nf90_def_var(ncid = ncFileID, name = "uy", xtype = nf90_float, &
83 dimids = (/ DimXID, DimYID, DimZID /), varID = uyVarID) )
84 call check(nf90_put_att(ncFileID, uyVarID, "long_name", "uy"))
86 call check(nf90_def_var(ncid = ncFileID, name = "uz", xtype = nf90_float, &
87 dimids = (/ DimXID, DimYID, DimZID /), varID = uzVarID) )
88 call check(nf90_put_att(ncFileID, uxVarID, "long_name", "uz"))
90 ! In the C++ interface the define a scalar variable - do we know how to do this?
91 !call check(nf90_def_var(ncFileID, "ScalarVariable", nf90_real, scalarVarID))
93 ! Leave define mode
94 call check(nf90_enddef(ncfileID))
96 ! Write the dimension variables
98 call check(nf90_put_var(ncFileID, DimXVarId,(/(X_Min+REAL(I-1)*X_Inc, i=1,XDim)/)) )
99 call check(nf90_put_var(ncFileID, DimYVarId,(/(Y_Min+REAL(I-1)*Y_Inc, i=1,YDim)/)) )
100 call check(nf90_put_var(ncFileID, DimZVarId,(/(Z_Min+REAL(I-1)*Z_Inc, i=1,ZDim)/)) )
103 ! Write the Strain distributions
105 call check(nf90_put_var(ncFileID, uxVarID, ux) )
106 call check(nf90_put_var(ncFileID, uyVarID, uy) )
107 call check(nf90_put_var(ncFileID, uzVarID, uz) )
109 call check(nf90_close(ncFileID))
111 END SUBROUTINE NCPACK_DPL_CART
113 SUBROUTINE NCPACK_DPL_CYL(UR,UZ)
115 IMPLICIT NONE
117 REAL,DIMENSION(:,:,:) :: UR,UZ
119 ! netcdf related variables
120 integer :: DimXID, DimZID,i, &
121 urVarID, uzVarID,DimXVarID, DimZVarID
123 real, dimension(1:XDim,1:ZDim) :: U_AUX
125 ! Local variables
126 character (len = 60) :: fileName
128 !-----
129 ! Initialization
130 !-----
132 fileName = DPL_Filename
134 ! --------------------
135 ! Code begins
136 ! --------------------
137 if(.not. byteSizesOK()) then
138 print *, "Compiler does not appear to support required kinds of variables."
139 stop
140 end if
142 ! Create the file
144 call open_over(fileName) !Check if a file with the same name exists
146 call check(nf90_create(path = trim(fileName), cmode = nf90_clobber, ncid = ncFileID))
148 CALL NCPACK_INPUT_DPL( )
150 ! Define the dimensions
151 call check(nf90_def_dim(ncid = ncFileID, name = "dimx", len = XDim, dimid = DimXID))
152 call check(nf90_def_dim(ncid = ncFileID, name = "dimz", len = ZDim, dimid = DimZID))
154 ! Create variables and attributes
156 ! Box sizes
158 call check(nf90_def_var(ncFileID, "dimx", nf90_float, dimids = DimXID, varID = DimXVarID) )
159 call check(nf90_put_att(ncFileID, DimXVarID, "long_name", "Radial dimension"))
160 call check(nf90_put_att(ncFileID, DimXVarID, "units", "Angstroms"))
162 call check(nf90_def_var(ncFileID, "dimz", nf90_float, dimids = DimZID, varID = DimZVarID) )
163 call check(nf90_put_att(ncFileID, DimZVarID, "long_name", "Z dimension"))
164 call check(nf90_put_att(ncFileID, DimZVarID, "units", "Angstroms"))
167 ! strain grids
168 call check(nf90_def_var(ncid = ncFileID, name = "ur", xtype = nf90_float, &
169 dimids = (/ DimXID, DimZID /), varID = urVarID) )
170 call check(nf90_put_att(ncFileID, urVarID, "long_name", "ur"))
172 call check(nf90_def_var(ncid = ncFileID, name = "uz", xtype = nf90_float, &
173 dimids = (/ DimXID, DimZID /), varID = uzVarID) )
174 call check(nf90_put_att(ncFileID, uzVarID, "long_name", "uz"))
176 ! Leave define mode
177 call check(nf90_enddef(ncfileID))
179 ! Write the dimension variables
181 call check(nf90_put_var(ncFileID, DimXVarId, (/(X_Min+REAL(I-1)*X_Inc, i=1,XDim)/)) )
182 call check(nf90_put_var(ncFileID, DimZVarId, (/(Z_Min+REAL(I-1)*Z_Inc, i=1,ZDim)/)) )
185 ! Write the Strain distributions
187 U_AUX=UR(1:XDim,1,1:ZDim)
188 call check(nf90_put_var(ncFileID, urVarID, U_AUX) )
190 U_AUX=UZ(1:XDim,1,1:ZDim)
191 call check(nf90_put_var(ncFileID, uzVarID, U_AUX) )
194 call check(nf90_close(ncFileID))
196 END SUBROUTINE NCPACK_DPL_CYL
198 SUBROUTINE NCPACK_INPUT_DPL( )
199 IMPLICIT NONE
201 CHARACTER(LEN=200) :: stitle
203 call check(nf90_def_dim(ncid = ncFileID, name = "vector", len = 3, dimid = Dim3ID))
205 call check(nf90_def_var(ncid = ncFileID, name = "HD", xtype = nf90_float, &
206 varID = HdVarID) )
207 call check(nf90_put_att(ncFileID, HdVarID, "long_name", "Dot Height (Angstroms)"))
209 call check(nf90_def_var(ncid = ncFileID, name = "RT", xtype = nf90_float, &
210 varID = RtVarID) )
211 call check(nf90_put_att(ncFileID, RtVarID, "long_name", "Top Dot Radius (Angstroms)"))
213 call check(nf90_def_var(ncid = ncFileID, name = "RB", xtype = nf90_float, &
214 varID = RbVarID ) )
215 call check(nf90_put_att(ncFileID, RbVarID, "long_name", "Base Dot Radius (Angstroms)"))
217 call check(nf90_def_var(ncid = ncFileID, name = "ND_X", xtype = nf90_int, &
218 varID = NDots_XVarID ) )
219 call check(nf90_put_att(ncFileID, NDots_XVarID, "long_name", "Number of Dots along X-axis"))
221 call check(nf90_def_var(ncid = ncFileID, name = "ND_Y", xtype = nf90_int, &
222 varID = NDots_YVarID ) )
223 call check(nf90_put_att(ncFileID, NDots_YVarID, "long_name", "Number of Dots along Y-axis"))
225 call check(nf90_def_var(ncid = ncFileID, name = "ND_Z", xtype = nf90_int, &
226 varID = NDots_ZVarID ) )
227 call check(nf90_put_att(ncFileID, NDots_ZVarID, "long_name", "Number of Dots along Z-axis"))
229 call check(nf90_def_var(ncFileID, "A1", nf90_float, dimids = Dim3ID, varID = A1VarID) )
230 call check(nf90_put_att(ncFileID, A1VarID, "long_name", "Vector A1 Superlattice"))
231 call check(nf90_put_att(ncFileID, A1VarID, "units", "Angstroms"))
233 call check(nf90_def_var(ncFileID, "A2", nf90_float, dimids = Dim3ID, varID = A2VarID) )
234 call check(nf90_put_att(ncFileID, A2VarID, "long_name", "Vector A2 Superlattice"))
235 call check(nf90_put_att(ncFileID, A2VarID, "units", "Angstroms"))
237 call check(nf90_def_var(ncFileID, "A3", nf90_float, dimids = Dim3ID, varID = A3VarID) )
238 call check(nf90_put_att(ncFileID, A3VarID, "long_name", "Vector A3 Superlattice"))
239 call check(nf90_put_att(ncFileID, A3VarID, "units", "Angstroms"))
241 call check(nf90_def_var(ncFileID, "DWL", nf90_float, varID = DWL_VarID))
243 SELECT CASE(ISHAPE)
244 CASE(1)
245 stitle="Shape: Truncated Cone. "
246 CASE(2)
247 stitle="Shape: Cap. "
248 END SELECT
250 SELECT CASE(MTYPE)
251 CASE(1) !! Isotropic Zincblende
252 stitle="Material Type: Isotropic Zincblende. "//stitle
253 CASE(2) !! Isotropic Wurtzite
254 stitle="Material Type: Isotropic Wurtzite. "//stitle
255 CASE(3) !! Anisotropic Wurtzite
256 stitle="Material Type: Anisotropic Wurtzite. "//stitle
257 END SELECT
259 ! Global attributes
260 call check(nf90_put_att(ncFileID, nf90_global, "history", &
261 "NetCDF file"))
262 stitle="Displacement distribution. "//stitle
264 call check(nf90_put_att(ncFileID, nf90_global, "title", TRIM(stitle)))
266 call check(nf90_enddef(ncfileID))
268 call check(nf90_put_var(ncFileID, RbVarId, Rqd_Base ) )
269 call check(nf90_put_var(ncFileID, RtVarId, Rqd_Top ) )
270 call check(nf90_put_var(ncFileID, HdVarId, Hqd ) )
271 call check(nf90_put_var(ncFileID, DWL_VarId, D*ZC ) )
272 call check(nf90_put_var(ncFileID, NDots_XVarId, NMax_X-NMin_X+1 ) )
273 call check(nf90_put_var(ncFileID, NDots_YVarId, NMax_Y-NMin_Y+1 ) )
274 call check(nf90_put_var(ncFileID, NDots_ZVarId, NMax_Z-NMin_Z+1 ) )
275 call check(nf90_put_var(ncFileID, A1VarId, A1_S ) )
276 call check(nf90_put_var(ncFileID, A2VarId, A2_S ) )
277 call check(nf90_put_var(ncFileID, A3VarId, A3_S ) )
280 call check(nf90_redef(ncfileID))
282 RETURN
284 END SUBROUTINE NCPACK_INPUT_DPL
287 END MODULE NCPACK_DPL