Incluidas las lineas referidas al input del desplazamiento.
[ptslat.git] / ncpack_pzo.f90
blob0451b73f8858ccc9e6853bdf4508102c5bf7c3e1
1 MODULE NCPACK_PZO
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_PZ(P_SPONT,P_PIEZO)
18 IMPLICIT NONE
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
27 ! Local variables
28 character (len = 60) :: fileName
30 real, dimension(1:XDim,1:ZDim) :: PZO_AUX
32 !-----
33 ! Initialization
34 !-----
36 fileName = PZO_Filename
39 ! --------------------
40 ! Code begins
41 ! --------------------
42 if(.not. byteSizesOK()) then
43 print *, "Compiler does not appear to support required kinds of variables."
44 stop
45 end if
47 ! Create the file
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))
57 IF(KCOOR.EQ.0) &
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
63 ! Box sizes
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"))
70 IF (KCOOR.EQ.0) THEN
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"))
74 END IF
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"))
81 ! potential grids
82 SELECT CASE(KCOOR)
83 CASE(0)
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"))
95 CASE(1)
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"))
107 END SELECT
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))
111 ! Leave define mode
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)/)) )
117 IF(KCOOR.EQ.0) &
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
124 SELECT CASE(KCOOR)
125 CASE(0)
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) )
129 CASE(1)
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) )
136 END SELECT
138 call check(nf90_close(ncFileID))
140 END SUBROUTINE NCPACK_PZ
142 SUBROUTINE NCREAD_PZ(P_SPONT,P_PIEZO)
145 IMPLICIT NONE
147 REAL,DIMENSION(:,:,:) :: P_SPONT,P_PIEZO
149 ! netcdf related variables
150 integer :: DimXID, DimYID, DimZID, &
151 pspVarID, ppzVarID
154 integer :: NcDimX,NcDimY,NcDimZ
156 real, dimension(1:XDim,1:ZDim) :: PZO_AUX
158 ! Local variables
159 character (len = 60) :: fileName
161 !-----
162 ! Initialization
163 !-----
165 fileName = PZO_Filename
167 ! --------------------
168 ! Code begins
169 ! --------------------
170 if(.not. byteSizesOK()) then
171 print *, "Compiler does not appear to support required kinds of variables."
172 stop
173 end if
175 ! Create the file
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))
181 IF(KCOOR.EQ.0) &
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))
187 IF(KCOOR.EQ.0) &
188 call check(nf90_Inquire_Dimension(ncid = ncFileID, dimid = DimYID, len = NcDimY))
189 call check(nf90_Inquire_Dimension(ncid = ncFileID, dimid = DimZID, len = NcDimZ))
191 IF(KCOOR.EQ.0) THEN
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
200 STOP
201 end if
202 ELSE
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
210 STOP
211 end if
212 END IF
214 call check(nf90_inq_varid(ncid = ncFileID, name = "P_SP", &
215 varID = pspVarID) )
216 call check(nf90_inq_varid(ncid = ncFileID, name = "P_PZ", &
217 varID = ppzVarID) )
219 ! Read the Strain distributions
221 SELECT CASE(KCOOR)
222 CASE(0)
223 call check(nf90_get_var(ncFileID, pspVarID, P_SPONT) )
224 call check(nf90_get_var(ncFileID, ppzVarID, P_PIEZO) )
225 CASE(1)
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
230 END SELECT
232 call check(nf90_close(ncFileID))
234 END SUBROUTINE NCREAD_PZ
236 SUBROUTINE NCPACK_INPUT_PZO( )
237 IMPLICIT NONE
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, &
244 varID = HdVarID) )
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, &
248 varID = RtVarID) )
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, &
252 varID = RbVarID ) )
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))
281 SELECT CASE(ISHAPE)
282 CASE(1)
283 stitle="Shape: Truncated Cone. "
284 CASE(2)
285 stitle="Shape: Cap. "
286 END SELECT
288 SELECT CASE(MTYPE)
289 CASE DEFAULT !! Anisotropic Wurtzite
290 stitle="Material Type: Anisotropic Wurtzite. "//stitle
291 END SELECT
293 ! Global attributes
294 call check(nf90_put_att(ncFileID, nf90_global, "history", &
295 "NetCDF file"))
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))
316 RETURN
318 END SUBROUTINE NCPACK_INPUT_PZO
320 END MODULE NCPACK_PZO