4 Use Dot_Geometry
, ONLY
: Rqd_Base
,Rqd_Top
,Hqd
,ISHAPE
6 Use Auxiliar_Procedures
, ONLY
: MTYPE
, check
, open_over
9 INTEGER,PRIVATE
:: ncFileID
, HdVarID
, RtVarID
, RbVarID
, NDots_XVarID
, &
10 NDots_YVarID
,NDots_ZVarID
, A1VarID
, A2VarID
, A3VarID
, &
16 SUBROUTINE NCPACK_PZ(P_SPONT
,P_PIEZO
)
20 REAL,DIMENSION(:,:,:) :: P_SPONT
,P_PIEZO
22 ! netcdf related variables
23 integer :: DimXID
, DimYID
, DimZID
,i
, &
24 pspVarID
, ppzVarID
, pttVarID
,&
25 DimXVarID
, DimYVarID
, DimZVarID
28 character (len
= 60) :: fileName
30 real, dimension(1:XDim
,1:ZDim
) :: PZO_AUX
36 fileName
= PZO_Filename
39 ! --------------------
41 ! --------------------
42 if(.not
. byteSizesOK()) then
43 print *, "Compiler does not appear to support required kinds of variables."
49 call open_over(fileName
) !Check if a file with the same name exists
51 call check(nf90_create(path
= trim(fileName
), cmode
= nf90_clobber
, ncid
= ncFileID
))
53 CALL NCPACK_INPUT_PZO( )
55 ! Define the dimensions
56 call check(nf90_def_dim(ncid
= ncFileID
, name
= "dimx", len
= XDim
, dimid
= DimXID
))
58 call check(nf90_def_dim(ncid
= ncFileID
, name
= "dimy", len
= YDim
, dimid
= DimYID
))
59 call check(nf90_def_dim(ncid
= ncFileID
, name
= "dimz", len
= ZDim
, dimid
= DimZID
))
61 ! Create variables and attributes
66 call check(nf90_def_var(ncFileID
, "dimx", nf90_float
, dimids
= DimXID
, varID
= DimXVarID
) )
67 call check(nf90_put_att(ncFileID
, DimXVarID
, "long_name", "Radial dimension"))
68 call check(nf90_put_att(ncFileID
, DimXVarID
, "units", "Angstroms"))
71 call check(nf90_def_var(ncFileID
, "dimy", nf90_float
, dimids
= DimYID
, varID
= DimYVarID
) )
72 call check(nf90_put_att(ncFileID
, DimYVarID
, "long_name", "Z dimension"))
73 call check(nf90_put_att(ncFileID
, DimYVarID
, "units", "Angstroms"))
76 call check(nf90_def_var(ncFileID
, "dimz", nf90_float
, dimids
= DimZID
, varID
= DimZVarID
) )
77 call check(nf90_put_att(ncFileID
, DimZVarID
, "long_name", "Z dimension"))
78 call check(nf90_put_att(ncFileID
, DimZVarID
, "units", "Angstroms"))
84 call check(nf90_def_var(ncid
= ncFileID
, name
= "P_SP", xtype
= nf90_float
, &
85 dimids
= (/ DimXID
, DimYID
, DimZID
/), varID
= pspVarID
) )
86 call check(nf90_put_att(ncFileID
, pspVarID
, "long_name", "Potential SP"))
88 call check(nf90_def_var(ncid
= ncFileID
, name
= "P_PZ", xtype
= nf90_float
, &
89 dimids
= (/ DimXID
, DimYID
, DimZID
/), varID
= ppzVarID
) )
90 call check(nf90_put_att(ncFileID
, ppzVarID
, "long_name", "Potential PZ"))
92 call check(nf90_def_var(ncid
= ncFileID
, name
= "P_TOT", xtype
= nf90_float
, &
93 dimids
= (/ DimXID
, DimYID
, DimZID
/), varID
= pttVarID
) )
94 call check(nf90_put_att(ncFileID
, pttVarID
, "long_name", "Total Potential"))
96 call check(nf90_def_var(ncid
= ncFileID
, name
= "P_SP", xtype
= nf90_float
, &
97 dimids
= (/ DimXID
, DimZID
/), varID
= pspVarID
) )
98 call check(nf90_put_att(ncFileID
, pspVarID
, "long_name", "Potential SP"))
100 call check(nf90_def_var(ncid
= ncFileID
, name
= "P_PZ", xtype
= nf90_float
, &
101 dimids
= (/ DimXID
, DimZID
/), varID
= ppzVarID
) )
102 call check(nf90_put_att(ncFileID
, ppzVarID
, "long_name", "Potential PZ"))
104 call check(nf90_def_var(ncid
= ncFileID
, name
= "P_TOT", xtype
= nf90_float
, &
105 dimids
= (/ DimXID
, DimZID
/), varID
= pttVarID
) )
106 call check(nf90_put_att(ncFileID
, pttVarID
, "long_name", "Total Potential"))
108 ! In the C++ interface the define a scalar variable - do we know how to do this?
109 !call check(nf90_def_var(ncFileID, "ScalarVariable", nf90_real, scalarVarID))
112 call check(nf90_enddef(ncfileID
))
114 ! Write the dimension variables
116 call check(nf90_put_var(ncFileID
, DimXVarId
, (/(X_Min
+REAL(I
-1)*X_Inc
, i
=1,XDim
)/)) )
118 call check(nf90_put_var(ncFileID
, DimYVarId
, (/(Y_Min
+REAL(I
-1)*Y_Inc
, i
=1,YDim
)/)) )
119 call check(nf90_put_var(ncFileID
, DimZVarId
, (/(Z_Min
+REAL(I
-1)*Z_Inc
, i
=1,ZDim
)/)) )
122 ! Write the Strain distributions
126 call check(nf90_put_var(ncFileID
, pspVarID
, P_SPONT
) )
127 call check(nf90_put_var(ncFileID
, ppzVarID
, P_PIEZO
) )
128 call check(nf90_put_var(ncFileID
, pttVarID
, P_SPONT
+P_PIEZO
) )
130 PZO_AUX
=P_SPONT(1:XDim
,1,1:ZDim
)
131 call check(nf90_put_var(ncFileID
, pspVarID
, PZO_AUX
) )
132 PZO_AUX
=P_PIEZO(1:XDim
,1,1:ZDim
)
133 call check(nf90_put_var(ncFileID
, ppzVarID
, PZO_AUX
) )
134 PZO_AUX
=P_SPONT(1:XDim
,1,1:ZDim
)+P_PIEZO(1:XDim
,1,1:ZDim
)
135 call check(nf90_put_var(ncFileID
, pttVarID
, PZO_AUX
) )
138 call check(nf90_close(ncFileID
))
140 END SUBROUTINE NCPACK_PZ
142 SUBROUTINE NCREAD_PZ(P_SPONT
,P_PIEZO
)
147 REAL,DIMENSION(:,:,:) :: P_SPONT
,P_PIEZO
149 ! netcdf related variables
150 integer :: DimXID
, DimYID
, DimZID
, &
154 integer :: NcDimX
,NcDimY
,NcDimZ
156 real, dimension(1:XDim
,1:ZDim
) :: PZO_AUX
159 character (len
= 60) :: fileName
165 fileName
= PZO_Filename
167 ! --------------------
169 ! --------------------
170 if(.not
. byteSizesOK()) then
171 print *, "Compiler does not appear to support required kinds of variables."
177 call check(nf90_open(path
= trim(fileName
), mode
= nf90_nowrite
, ncid
= ncFileID
))
179 ! Define the dimensions
180 call check(nf90_inq_dimid(ncid
= ncFileID
, name
= "dimx", dimid
= DimXID
))
182 call check(nf90_inq_dimid(ncid
= ncFileID
, name
= "dimy", dimid
= DimYID
))
183 call check(nf90_inq_dimid(ncid
= ncFileID
, name
= "dimz", dimid
= DimZID
))
185 ! Create variables and attributes
186 call check(nf90_Inquire_Dimension(ncid
= ncFileID
, dimid
= DimXID
, len
= NcDimX
))
188 call check(nf90_Inquire_Dimension(ncid
= ncFileID
, dimid
= DimYID
, len
= NcDimY
))
189 call check(nf90_Inquire_Dimension(ncid
= ncFileID
, dimid
= DimZID
, len
= NcDimZ
))
192 if ((NcDimX
.ne
.XDim
).or
.(NcDimY
.ne
.YDim
).or
.(NcDimZ
.ne
.ZDim
)) then
193 write(6,*)"Dimensions problem:"
194 write(6,*)"Dimensions of the NetCDF File: ",TRIM(filename
)
195 write(6,*)"DimX:",NcDimX
196 write(6,*)"DimY:",NcDimY
197 write(6,*)"DimZ:",NcDimZ
198 write(6,*)"Dimensions defined on actual run:"
199 write(6,*)"DimX-Y-Z:",XDim
,YDim
,ZDim
203 if ((NcDimX
.ne
.XDim
).or
.(NcDimZ
.ne
.ZDim
)) then
204 write(6,*)"Dimensions problem:"
205 write(6,*)"Dimensions of the NetCDF File: ",TRIM(filename
)
206 write(6,*)"DimX:",NcDimX
207 write(6,*)"DimZ:",NcDimZ
208 write(6,*)"Dimensions defined on actual run:"
209 write(6,*)"DimX-Y-Z:",XDim
,ZDim
214 call check(nf90_inq_varid(ncid
= ncFileID
, name
= "P_SP", &
216 call check(nf90_inq_varid(ncid
= ncFileID
, name
= "P_PZ", &
219 ! Read the Strain distributions
223 call check(nf90_get_var(ncFileID
, pspVarID
, P_SPONT
) )
224 call check(nf90_get_var(ncFileID
, ppzVarID
, P_PIEZO
) )
226 call check(nf90_get_var(ncFileID
, pspVarID
, PZO_AUX
) )
227 P_SPONT(1:XDim
,1,1:ZDim
)=PZO_AUX
228 call check(nf90_get_var(ncFileID
, ppzVarID
, PZO_AUX
) )
229 P_PIEZO(1:XDim
,1,1:ZDim
)=PZO_AUX
232 call check(nf90_close(ncFileID
))
234 END SUBROUTINE NCREAD_PZ
236 SUBROUTINE NCPACK_INPUT_PZO( )
239 CHARACTER(LEN
=200) :: stitle
241 call check(nf90_def_dim(ncid
= ncFileID
, name
= "vector", len
= 3, dimid
= Dim3ID
))
243 call check(nf90_def_var(ncid
= ncFileID
, name
= "HD", xtype
= nf90_float
, &
245 call check(nf90_put_att(ncFileID
, HdVarID
, "long_name", "Dot Height (Angstroms)"))
247 call check(nf90_def_var(ncid
= ncFileID
, name
= "RT", xtype
= nf90_float
, &
249 call check(nf90_put_att(ncFileID
, RtVarID
, "long_name", "Top Dot Radius (Angstroms)"))
251 call check(nf90_def_var(ncid
= ncFileID
, name
= "RB", xtype
= nf90_float
, &
253 call check(nf90_put_att(ncFileID
, RbVarID
, "long_name", "Base Dot Radius (Angstroms)"))
255 call check(nf90_def_var(ncid
= ncFileID
, name
= "ND_X", xtype
= nf90_int
, &
256 varID
= NDots_XVarID
) )
257 call check(nf90_put_att(ncFileID
, NDots_XVarID
, "long_name", "Number of Dots along X-axis"))
259 call check(nf90_def_var(ncid
= ncFileID
, name
= "ND_Y", xtype
= nf90_int
, &
260 varID
= NDots_YVarID
) )
261 call check(nf90_put_att(ncFileID
, NDots_YVarID
, "long_name", "Number of Dots along Y-axis"))
263 call check(nf90_def_var(ncid
= ncFileID
, name
= "ND_Z", xtype
= nf90_int
, &
264 varID
= NDots_ZVarID
) )
265 call check(nf90_put_att(ncFileID
, NDots_ZVarID
, "long_name", "Number of Dots along Z-axis"))
267 call check(nf90_def_var(ncFileID
, "A1", nf90_float
, dimids
= Dim3ID
, varID
= A1VarID
) )
268 call check(nf90_put_att(ncFileID
, A1VarID
, "long_name", "Vector A1 Superlattice"))
269 call check(nf90_put_att(ncFileID
, A1VarID
, "units", "Angstroms"))
271 call check(nf90_def_var(ncFileID
, "A2", nf90_float
, dimids
= Dim3ID
, varID
= A2VarID
) )
272 call check(nf90_put_att(ncFileID
, A2VarID
, "long_name", "Vector A2 Superlattice"))
273 call check(nf90_put_att(ncFileID
, A2VarID
, "units", "Angstroms"))
275 call check(nf90_def_var(ncFileID
, "A3", nf90_float
, dimids
= Dim3ID
, varID
= A3VarID
) )
276 call check(nf90_put_att(ncFileID
, A3VarID
, "long_name", "Vector A3 Superlattice"))
277 call check(nf90_put_att(ncFileID
, A3VarID
, "units", "Angstroms"))
279 call check(nf90_def_var(ncFileID
, "DWL", nf90_float
, varID
= DWL_VarID
))
283 stitle
="Shape: Truncated Cone. "
285 stitle
="Shape: Cap. "
289 CASE DEFAULT
!! Anisotropic Wurtzite
290 stitle
="Material Type: Anisotropic Wurtzite. "//stitle
294 call check(nf90_put_att(ncFileID
, nf90_global
, "history", &
296 stitle
="Electrostatic Potential. "//stitle
298 call check(nf90_put_att(ncFileID
, nf90_global
, "title", TRIM(stitle
)))
300 call check(nf90_enddef(ncfileID
))
302 call check(nf90_put_var(ncFileID
, RbVarId
, Rqd_Base
) )
303 call check(nf90_put_var(ncFileID
, RtVarId
, Rqd_Top
) )
304 call check(nf90_put_var(ncFileID
, HdVarId
, Hqd
) )
305 call check(nf90_put_var(ncFileID
, DWL_VarId
, D
*ZC
) )
306 call check(nf90_put_var(ncFileID
, NDots_XVarId
, NMax_X
-NMin_X
+1 ) )
307 call check(nf90_put_var(ncFileID
, NDots_YVarId
, NMax_Y
-NMin_Y
+1 ) )
308 call check(nf90_put_var(ncFileID
, NDots_ZVarId
, NMax_Z
-NMin_Z
+1 ) )
309 call check(nf90_put_var(ncFileID
, A1VarId
, A1_S
) )
310 call check(nf90_put_var(ncFileID
, A2VarId
, A2_S
) )
311 call check(nf90_put_var(ncFileID
, A3VarId
, A3_S
) )
314 call check(nf90_redef(ncfileID
))
318 END SUBROUTINE NCPACK_INPUT_PZO
320 END MODULE NCPACK_PZO