FE-Project
Loading...
Searching...
No Matches
scale_file_base_meshfield.F90
Go to the documentation of this file.
1!-------------------------------------------------------------------------------
9!-------------------------------------------------------------------------------
10#include "scaleFElib.h"
12 !-----------------------------------------------------------------------------
13 !
14 !++ Used modules
15 !
16 use scale_precision
17 use scale_io
18 use scale_file_h
19 use scale_prc, only: &
20 prc_abort
21 use scale_file_h, only: &
22 file_file_max
23
27 use scale_mesh_base1d, only: &
28 mf1d_dimtype_x => meshbase1d_dimtypeid_x, &
29 mf1d_dtype_num => meshbase1d_dimtype_num
30 use scale_mesh_base2d, only: &
31 mf2d_dimtype_x => meshbase2d_dimtypeid_x, &
32 mf2d_dimtype_y => meshbase2d_dimtypeid_y, &
33 mf2d_dtype_num => meshbase2d_dimtype_num
34 use scale_mesh_base3d, only: &
35 mf3d_dimtype_x => meshbase3d_dimtypeid_x, &
36 mf3d_dimtype_y => meshbase3d_dimtypeid_y, &
37 mf3d_dimtype_z => meshbase3d_dimtypeid_z, &
38 mf3d_dtype_num => meshbase3d_dimtype_num
39
51
54
55 !-----------------------------------------------------------------------------
56 implicit none
57 private
58 !-----------------------------------------------------------------------------
59 !
60 !++ Public type & procedures
61 !
62
63 type, public :: file_base_meshfield
64 integer :: fid
65 integer, allocatable :: vars_ncid(:)
66
67 integer :: write_buf_amount
68 logical :: file_axes_written
69
70 class(meshbase1d), pointer :: mesh1d
71 class(meshrectdom2d), pointer :: mesh2d
72 class(meshcubedspheredom2d), pointer :: meshcs2d
73 class(meshcubedom3d), pointer :: mesh3d
74 class(meshcubedspheredom3d), pointer :: meshcs3d
75 type(file_common_meshfield_diminfo), allocatable :: dimsinfo(:)
76
77 logical :: force_uniform_grid
78 contains
79 procedure :: init => file_base_meshfield_init
80 procedure :: open => file_base_meshfield_open
81 procedure :: create => file_base_meshfield_create
82
83 !-
84 procedure :: file_base_meshfield_def_var1
85 procedure :: file_base_meshfield_def_var2
86 generic :: def_var => file_base_meshfield_def_var1, file_base_meshfield_def_var2
87 procedure :: end_def => file_base_meshfield_enddef
88 !-
89 procedure :: file_base_meshfield_write_var1d
90 generic :: write_var1d => file_base_meshfield_write_var1d
91 procedure :: file_base_meshfield_write_var2d
92 generic :: write_var2d => file_base_meshfield_write_var2d
93 procedure :: file_base_meshfield_write_var3d
94 generic :: write_var3d => file_base_meshfield_write_var3d
95 !-
96 procedure :: put_globalattribute_time => file_base_meshfield_put_global_attribute_time
97 !-
98 procedure :: file_base_meshfield_read_var1d
99 procedure :: file_base_meshfield_read_var1d_local
100 procedure :: file_base_meshfield_read_var2d
101 procedure :: file_base_meshfield_read_var2d_local
102 procedure :: file_base_meshfield_read_var3d
103 procedure :: file_base_meshfield_read_var3d_local
104 generic :: read_var => &
105 file_base_meshfield_read_var1d, file_base_meshfield_read_var1d_local, &
106 file_base_meshfield_read_var2d, file_base_meshfield_read_var2d_local, &
107 file_base_meshfield_read_var3d, file_base_meshfield_read_var3d_local
108
109 !-
110 procedure :: get_commoninfo => file_base_meshfield_get_commoninfo
111 procedure :: get_datainfo => file_base_meshfield_get_datainfo
112 procedure :: get_varstepsize => file_base_meshfield_get_varstepsize
113 !-
114 procedure :: close => file_base_meshfield_close
115 procedure :: final => file_base_meshfield_final
116 end type file_base_meshfield
117
118 !-----------------------------------------------------------------------------
119 !
120 !++ Public parameters & variables
121 !
122 !-----------------------------------------------------------------------------
123 !
124 !++ Private procedures
125 !
126 !-------------------
127
128 private :: def_axes
129 private :: write_axes
130
131contains
132
133 subroutine file_base_meshfield_init( this, & ! (inout)
134 var_num, & ! (in)
135 mesh1d, & ! (in)
136 mesh2d, meshcubedsphere2d, & ! (in)
137 mesh3d, meshcubedsphere3d, & ! (in)
138 force_uniform_grid ) ! (in)
139
140 use scale_file_common_meshfield, only: &
142
143 implicit none
144
145 class(file_base_meshfield), intent(inout) :: this
146 integer, intent(in) :: var_num
147 class(meshbase1d), target, optional, intent(in) :: mesh1D
148 class(meshrectdom2d), target, optional, intent(in) :: mesh2D
149 class(meshcubedspheredom2d), target, optional, intent(in) :: meshCubedSphere2D
150 class(meshcubedom3d), target, optional, intent(in) :: mesh3D
151 class(meshcubedspheredom3d), target, optional, intent(in) :: meshCubedSphere3D
152 logical, intent(in), optional :: force_uniform_grid
153
154 logical :: check_specify_mesh
155 !--------------------------------------------------
156
157 this%fid = -1
158
159 allocate( this%vars_ncid(var_num) )
160 this%vars_ncid(:) = -1
161
162 !-
163 check_specify_mesh = .false.
164 nullify( this%mesh1D, this%mesh2D, this%mesh3D )
165 nullify( this%meshCS2D, this%meshCS3D )
166
167 if (present(mesh1d)) then
168 this%mesh1D => mesh1d
169 check_specify_mesh = .true.
170
171 allocate( this%dimsinfo(mf1d_dtype_num) )
172 call file_common_meshfield_get_dims( mesh1d, this%dimsinfo(:) )
173 end if
174 if (present(mesh2d)) then
175 this%mesh2D => mesh2d
176 check_specify_mesh = .true.
177
178 allocate( this%dimsinfo(mf2d_dtype_num) )
179 call file_common_meshfield_get_dims( mesh2d, this%dimsinfo(:) )
180 end if
181 if (present(meshcubedsphere2d)) then
182 this%meshCS2D => meshcubedsphere2d
183 check_specify_mesh = .true.
184
185 allocate( this%dimsinfo(mf2d_dtype_num) )
186 call file_common_meshfield_get_dims( meshcubedsphere2d, this%dimsinfo(:) )
187 end if
188 if (present(mesh3d)) then
189 this%mesh3D => mesh3d
190 check_specify_mesh = .true.
191
192 allocate( this%dimsinfo(mf3d_dtype_num) )
193 call file_common_meshfield_get_dims( mesh3d, this%dimsinfo(:) )
194 end if
195 if (present(meshcubedsphere3d)) then
196 this%meshCS3D => meshcubedsphere3d
197 check_specify_mesh = .true.
198
199 allocate( this%dimsinfo(mf3d_dtype_num) )
200 call file_common_meshfield_get_dims( meshcubedsphere3d, this%dimsinfo(:) )
201 end if
202
203 if ( present(force_uniform_grid) ) then
204 this%force_uniform_grid = force_uniform_grid
205 else
206 this%force_uniform_grid = .false.
207 end if
208
209 if (.not. check_specify_mesh) then
210 log_error("FILE_base_meshfield_Init",*) 'Specify a mesh among mesh1D, 2D, and 3D. Check!'
211 call prc_abort
212 end if
213
214 !-
215 this%File_axes_written = .false.
216 this%write_buf_amount = 0
217
218 return
219 end subroutine file_base_meshfield_init
220
221 subroutine file_base_meshfield_open( this, & ! (inout)
222 basename, myrank ) ! (in)
223
224 use scale_file, only: &
225 file_open
226 implicit none
227
228 class(file_base_meshfield), intent(inout) :: this
229 character(*), intent(in) :: basename
230 integer, intent(in), optional :: myrank
231 !--------------------------------------------------------------
232
233 call file_open( basename, & ! [in]
234 this%fid, & ! [out]
235 rankid=myrank ) ! [in]
236
237 return
238 end subroutine file_base_meshfield_open
239
240 subroutine file_base_meshfield_create( &
241 this, basename, title, dtype, &
242 fileexisted, &
243 myrank, tunits, calendar )
244
245 use scale_file, only: &
246 file_create
247 implicit none
248
249 class(file_base_meshfield), intent(inout) :: this
250 character(*), intent(in) :: basename
251 character(*), intent(in) :: title
252 character(*), intent(in) :: dtype
253 logical, intent(out) :: fileexisted
254 integer, intent(in), optional :: myrank
255 character(*), intent(in), optional :: calendar
256 character(*), intent(in), optional :: tunits
257 !--------------------------------------------------------------
258
259 call file_create( basename, & ! [IN]
260 title, & ! [IN]
261 h_source, & ! [IN]
262 h_institute, & ! [IN]
263 this%fid, & ! [OUT]
264 fileexisted, & ! [OUT]
265 rankid = myrank, & ! [IN]
266 time_units = tunits, & ! [IN]
267 calendar = calendar ) ! [IN]
268
269 if ( .not. fileexisted ) then
270 call def_axes( this, dtype )
271 this%File_axes_written = .false.
272 end if
273
274 return
275 end subroutine file_base_meshfield_create
276
277 subroutine file_base_meshfield_def_var1( this, & ! (inout)
278 field, desc, vid, dim_type_id, datatype, & ! (in)
279 standard_name, timeinv, nsteps ) ! (in)
280 implicit none
281
282 class(file_base_meshfield), intent(inout) :: this
283 class(meshfieldbase), intent(in) :: field
284 character(len=*), intent(in) :: desc
285 integer, intent(in) :: dim_type_id
286 integer, intent(in) :: vid
287 character(len=*), intent(in) :: datatype
288 character(len=*), optional, intent(in) :: standard_name
289 real(DP), optional, intent(in) :: timeinv
290 integer, optional, intent(in) :: nsteps
291 !--------------------------------------------------------------
292
293 call this%Def_Var( field%varname, field%unit, &
294 desc, vid, dim_type_id, datatype, standard_name, timeinv, nsteps )
295
296 return
297 end subroutine file_base_meshfield_def_var1
298
299 subroutine file_base_meshfield_def_var2( this, & ! (inout)
300 varname, units, desc, vid, dim_type_id, datatype, & ! (in)
301 standard_name, timeinv, nsteps ) ! (in)
302
303 use scale_file, only: &
304 file_opened, &
305 file_def_variable, &
306 file_set_attribute
307 implicit none
308
309 class(file_base_meshfield), intent(inout) :: this
310 character(len=*), intent(in) :: varname
311 character(len=*), intent(in) :: units
312 character(len=*), intent(in) :: desc
313 integer, intent(in) :: dim_type_id
314 integer, intent(in) :: vid
315 character(len=*), intent(in) :: datatype
316 character(len=*), optional, intent(in) :: standard_name
317 real(DP), optional, intent(in) :: timeinv
318 integer, optional, intent(in) :: nsteps
319
320 integer :: i_dtype
321 integer :: ndim
322 character(len=H_MID) :: standard_name_
323 !--------------------------------------------------------------
324
325 i_dtype = get_dtype(datatype)
326
327 if ( present(nsteps) ) then
328 this%write_buf_amount = this%write_buf_amount + this%dimsinfo(dim_type_id)%size * nsteps
329 else
330 this%write_buf_amount = this%write_buf_amount + this%dimsinfo(dim_type_id)%size
331 end if
332 if ( present(standard_name) ) then
333 standard_name_ = standard_name
334 else
335 standard_name_ = ""
336 end if
337
338 ndim = this%dimsinfo(dim_type_id)%ndim
339 if ( present(timeinv) ) then
340 call file_def_variable( this%fid, varname, desc, units, standard_name_, &
341 ndim, this%dimsinfo(dim_type_id)%dims(1:ndim), i_dtype, this%vars_ncid(vid), &
342 time_int=timeinv )
343 else
344 call file_def_variable( this%fid, varname, desc, units, standard_name_, &
345 ndim, this%dimsinfo(dim_type_id)%dims(1:ndim), i_dtype, this%vars_ncid(vid) )
346 end if
347
348 return
349 end subroutine file_base_meshfield_def_var2
350
351 subroutine file_base_meshfield_enddef( this ) ! (inout)
352
353 use scale_file, only: &
354 file_opened, &
355 file_enddef
356 implicit none
357 class(file_base_meshfield), intent(inout) :: this
358
359 integer :: start(3)
360 !--------------------------------------------------------------
361
362 if (this%fid == -1) return
363
364 call file_enddef( this%fid )
365
366 if ( .not. this%File_axes_written ) then
367 start(:) = 1
368 call write_axes( this, start(:) )
369 this%File_axes_written = .true.
370 end if
371
372 return
373 end subroutine file_base_meshfield_enddef
374
375!OCL_SERIAL
376 subroutine file_base_meshfield_write_var1d( this, & ! (inout)
377 vid, field1d, sec_str, sec_end ) ! (in)
378
379 use scale_file, only: &
380 file_opened, &
381 file_write
382 use scale_file_common_meshfield, only: &
384 implicit none
385
386 class(file_base_meshfield), intent(inout) :: this
387 integer, intent(in) :: vid
388 class(meshfield1d), intent(in) :: field1d
389 real(DP), intent(in) :: sec_str
390 real(DP), intent(in) :: sec_end
391
392 real(RP), allocatable :: buf(:)
393 integer :: dims(1)
394 integer :: start(1)
395 !-------------------------------------------------
396
397 if ( this%fid /= -1 ) then
398 start(:) = 1
399 dims(1) = this%dimsinfo(mf1d_dimtype_x)%size
400 allocate( buf(dims(1)) )
401 call file_common_meshfield_put_field1d_cartesbuf( this%mesh1D, field1d, buf(:), &
402 this%force_uniform_grid )
403
404 call file_write( this%vars_ncid(vid), buf(:), & ! (in)
405 sec_str, sec_end, start=start ) ! (in)
406 end if
407
408 return
409 end subroutine file_base_meshfield_write_var1d
410
411!OCL_SERIAL
412 subroutine file_base_meshfield_write_var2d( this, & ! (inout)
413 vid, field2d, sec_str, sec_end ) ! (in)
414
415 use scale_file, only: &
416 file_opened, &
417 file_write
418 use scale_file_common_meshfield, only: &
421 implicit none
422
423 class(file_base_meshfield), intent(inout) :: this
424 integer, intent(in) :: vid
425 class(meshfield2d), intent(in) :: field2d
426 real(DP), intent(in) :: sec_str
427 real(DP), intent(in) :: sec_end
428
429 real(RP), allocatable :: buf(:,:)
430 integer :: dims(2)
431 integer :: start(2)
432 !-------------------------------------------------
433
434 if ( this%fid /= -1 ) then
435 start(:) = 1
436 dims(1) = this%dimsinfo(mf2d_dimtype_x)%size
437 dims(2) = this%dimsinfo(mf2d_dimtype_y)%size
438 allocate( buf(dims(1),dims(2)) )
439 if ( associated(this%mesh2D) ) then
440 call file_common_meshfield_put_field2d_cartesbuf( this%mesh2D, field2d, buf(:,:), &
441 this%force_uniform_grid )
442 else if ( associated(this%meshCS2D) ) then
444 this%meshCS2D, field2d, buf(:,:) )
445 end if
446
447 call file_write( this%vars_ncid(vid), buf(:,:), & ! (in)
448 sec_str, sec_end, start=start ) ! (in)
449 end if
450
451 return
452 end subroutine file_base_meshfield_write_var2d
453
454!OCL_SERIAL
455 subroutine file_base_meshfield_write_var3d( this, & ! (inout)
456 vid, field3d, sec_str, sec_end ) ! (in)
457
458 use scale_file, only: &
459 file_opened, &
460 file_write
461 use scale_file_common_meshfield, only: &
464 use scale_prof
465 implicit none
466
467 class(file_base_meshfield), intent(inout) :: this
468 integer, intent(in) :: vid
469 class(meshfield3d), intent(in) :: field3d
470 real(DP), intent(in) :: sec_str
471 real(DP), intent(in) :: sec_end
472
473 real(RP), allocatable :: buf(:,:,:)
474 integer :: dims(3)
475 integer :: start(3)
476 !-------------------------------------------------
477
478 if ( this%fid /= -1 ) then
479 start(:) = 1
480 dims(1) = this%dimsinfo(mf3d_dimtype_x)%size
481 dims(2) = this%dimsinfo(mf3d_dimtype_y)%size
482 dims(3) = this%dimsinfo(mf3d_dimtype_z)%size
483 allocate( buf(dims(1),dims(2),dims(3)) )
484
485 if ( associated(this%mesh3D) ) then
486 call file_common_meshfield_put_field3d_cartesbuf( this%mesh3D, field3d, buf(:,:,:), &
487 this%force_uniform_grid )
488 else if ( associated(this%meshCS3D) ) then
490 this%meshCS3D, field3d, buf(:,:,:) )
491 end if
492
493 call file_write( this%vars_ncid(vid), buf(:,:,:), & ! (in)
494 sec_str, sec_end, start ) ! (in)
495 end if
496
497 return
498 end subroutine file_base_meshfield_write_var3d
499
500 subroutine file_base_meshfield_get_commoninfo( this, & ! (in)
501 title, source, institution ) ! (out)
502 use scale_file, only: &
503 file_get_attribute
504 implicit none
505
506 class(file_base_meshfield), intent(in) :: this
507 character(len=FILE_HMID), intent(out), optional :: title
508 character(len=FILE_HMID), intent(out), optional :: source
509 character(len=FILE_HMID), intent(out), optional :: institution
510 !-------------------------------------------------
511
512 if ( present(title) ) call file_get_attribute( this%fid, 'global', 'title', title )
513 if ( present(source) ) call file_get_attribute( this%fid, 'global', 'source', source )
514 if ( present(institution) ) call file_get_attribute( this%fid, 'global', 'institution', institution )
515
516 return
517 end subroutine file_base_meshfield_get_commoninfo
518
519 subroutine file_base_meshfield_get_varstepsize( this, varname, & ! (in)
520 len ) ! (out)
521 use scale_file, only: &
522 file_get_stepsize
523 implicit none
524
525 class(file_base_meshfield), intent(in) :: this
526 character(*), intent(in) :: varname
527 integer, intent(out) :: len
528 !-------------------------------------------------
529
530 call file_get_stepsize( this%fid, varname, & ! (in)
531 len ) ! (out)
532
533 return
534 end subroutine file_base_meshfield_get_varstepsize
535
536 subroutine file_base_meshfield_get_datainfo( this, varname, istep, & ! (in)
537 description, units, standard_name, & ! (out)
538 time_start, time_end, time_units, calendar ) ! (out)
539 use scale_file, only: &
540 file_get_datainfo
541 implicit none
542
543 class(file_base_meshfield), intent(in) :: this
544 character(*), intent(in) :: varname
545 integer, intent(in), optional :: istep
546 character(len=FILE_HMID), intent(out), optional :: description
547 character(len=FILE_HSHORT), intent(out), optional :: units
548 character(len=FILE_HMID), intent(out), optional :: standard_name
549 real(DP), intent(out), optional :: time_start
550 real(DP), intent(out), optional :: time_end
551 character(len=FILE_HMID), intent(out), optional :: time_units
552 character(len=FILE_HSHORT), intent(out), optional :: calendar
553 !-------------------------------------------------
554
555 call file_get_datainfo( this%fid, varname, istep=istep, & ! (in)
556 description=description, units=units, standard_name=standard_name, & ! (out)
557 time_start=time_start, time_end=time_end, time_units=time_units, calendar=calendar ) ! (out)
558
559 return
560 end subroutine file_base_meshfield_get_datainfo
561
562!OCL_SERIAL
563 subroutine file_base_meshfield_read_var1d( this, & ! (inout)
564 dim_typeid, varname, & ! (in)
565 field1d, & ! (inout)
566 step, allow_missing ) ! (in)
567
568 use scale_file, only: &
569 file_read
570 use scale_file_common_meshfield, only: &
572
573 implicit none
574
575 class(file_base_meshfield), intent(inout) :: this
576 integer, intent(in) :: dim_typeid
577 character(*), intent(in) :: varname
578 class(meshfield1d), intent(inout) :: field1d
579 integer, intent(in), optional :: step
580 logical, intent(in), optional :: allow_missing
581
582 real(RP), allocatable :: buf(:)
583 integer :: dims(1)
584 integer :: start(1) ! start offset of globale variable
585 !-------------------------------------------------
586
587 if ( this%fid /= -1 ) then
588 start(:) = 1
589 dims(1) = this%dimsinfo(dim_typeid)%size
590 allocate( buf(dims(1)) )
591
592 call file_read( this%fid, varname, & ! (in)
593 buf(:), & ! (out)
594 step=step, allow_missing=allow_missing ) ! (in)
595
596 call file_common_meshfield_set_cartesbuf_field1d( this%mesh1D, buf(:), &
597 field1d )
598 end if
599
600 return
601 end subroutine file_base_meshfield_read_var1d
602
603!OCL_SERIAL
604 subroutine file_base_meshfield_read_var1d_local( this, & ! (inout)
605 dim_typeid, varname, lcmesh, i0_s, & ! (in)
606 val, & ! (out)
607 step, allow_missing ) ! (in)
608
609 use scale_file, only: &
610 file_read
611 use scale_file_common_meshfield, only: &
613
614 implicit none
615
616 class(file_base_meshfield), intent(inout) :: this
617 integer, intent(in) :: dim_typeid
618 character(*), intent(in) :: varname
619 class(localmesh1d), intent(in) :: lcmesh
620 integer, intent(in) :: i0_s
621 real(RP), intent(out) :: val(lcmesh%refElem1D%Np,lcmesh%NeA)
622 integer, intent(in), optional :: step
623 logical, intent(in), optional :: allow_missing
624
625 real(RP), allocatable :: buf(:)
626 integer :: dims(1)
627 integer :: start(1) ! start offset of globale variable
628 !-------------------------------------------------
629
630 if ( this%fid /= -1 ) then
631 start(:) = 1
632 dims(1) = this%dimsinfo(dim_typeid)%size
633 allocate( buf(dims(1)) )
634
635 call file_read( this%fid, varname, & ! (in)
636 buf(:), & ! (out)
637 step=step, allow_missing=allow_missing ) ! (in)
638
640 lcmesh, buf(:), i0_s, &
641 val(:,:) )
642 end if
643
644 return
645 end subroutine file_base_meshfield_read_var1d_local
646
647!OCL_SERIAL
648 subroutine file_base_meshfield_read_var2d( this, & ! (inout)
649 dim_typeid, varname, & ! (in)
650 field2d, & ! (inout)
651 step, allow_missing ) ! (in)
652
653 use scale_file, only: &
654 file_read
655 use scale_file_common_meshfield, only: &
658
659 implicit none
660
661 class(file_base_meshfield), intent(inout) :: this
662 integer, intent(in) :: dim_typeid
663 character(*), intent(in) :: varname
664 class(meshfield2d), intent(inout) :: field2d
665 integer, intent(in), optional :: step
666 logical, intent(in), optional :: allow_missing
667
668 real(RP), allocatable :: buf(:,:)
669 integer :: dims(2)
670 integer :: start(2) ! start offset of globale variable
671 !-------------------------------------------------
672
673 if ( this%fid /= -1 ) then
674 start(:) = 1
675 dims(1) = this%dimsinfo(mf2d_dimtype_x)%size
676 dims(2) = this%dimsinfo(mf2d_dimtype_y)%size
677 allocate( buf(dims(1),dims(2)) )
678
679 call file_read( this%fid, varname, & ! (in)
680 buf(:,:), & ! (out)
681 step=step, allow_missing=allow_missing ) ! (in)
682
683 if ( associated( this%meshCS2D) ) then
685 this%meshCS2D, buf(:,:), &
686 field2d )
687 else if ( associated( this%mesh2D) ) then
688 call file_common_meshfield_set_cartesbuf_field2d( this%mesh2D, buf(:,:), &
689 field2d )
690 end if
691 end if
692
693 return
694 end subroutine file_base_meshfield_read_var2d
695
696!OCL_SERIAL
697 subroutine file_base_meshfield_read_var2d_local( this, & ! (inout)
698 dim_typeid, varname, lcmesh, i0_s, j0_s, & ! (in)
699 val, & ! (out)
700 step, allow_missing ) ! (in)
701
702 use scale_file, only: &
703 file_read
704 use scale_file_common_meshfield, only: &
706
707 implicit none
708
709 class(file_base_meshfield), intent(inout) :: this
710 integer, intent(in) :: dim_typeid
711 character(*), intent(in) :: varname
712 class(localmesh2d), intent(in) :: lcmesh
713 integer, intent(in) :: i0_s, j0_s
714 real(RP), intent(out) :: val(lcmesh%refElem2D%Np,lcmesh%NeA)
715 integer, intent(in), optional :: step
716 logical, intent(in), optional :: allow_missing
717
718 real(RP), allocatable :: buf(:,:)
719 integer :: dims(2)
720 integer :: start(2) ! start offset of globale variable
721 !-------------------------------------------------
722
723 if ( this%fid /= -1 ) then
724 start(:) = 1
725 dims(1) = this%dimsinfo(mf2d_dimtype_x)%size
726 dims(2) = this%dimsinfo(mf2d_dimtype_y)%size
727 allocate( buf(dims(1),dims(2)) )
728
729 call file_read( this%fid, varname, & ! (in)
730 buf(:,:), & ! (out)
731 step=step, allow_missing=allow_missing ) ! (in)
732
734 lcmesh, buf(:,:), i0_s, j0_s, &
735 val(:,:) )
736 end if
737
738 return
739 end subroutine file_base_meshfield_read_var2d_local
740
741!OCL_SERIAL
742 subroutine file_base_meshfield_read_var3d( this, & ! (inout)
743 dim_typeid, varname, & ! (in)
744 field3d, & ! (inout)
745 step, allow_missing ) ! (in)
746
747 use scale_file, only: &
748 file_read
749 use scale_file_common_meshfield, only: &
752
753
754 implicit none
755
756 class(file_base_meshfield), intent(inout) :: this
757 integer, intent(in) :: dim_typeid
758 character(*), intent(in) :: varname
759 class(meshfield3d), intent(inout) :: field3d
760 integer, intent(in), optional :: step
761 logical, intent(in), optional :: allow_missing
762
763 real(RP), allocatable :: buf(:,:,:)
764 integer :: dims(3)
765 integer :: start(3) ! start offset of globale variable
766 !-------------------------------------------------
767
768 if ( this%fid /= -1 ) then
769 start(:) = 1
770 dims(1) = this%dimsinfo(mf3d_dimtype_x)%size
771 dims(2) = this%dimsinfo(mf3d_dimtype_y)%size
772 dims(3) = this%dimsinfo(mf3d_dimtype_z)%size
773 allocate( buf(dims(1),dims(2),dims(3)) )
774
775 call file_read( this%fid, varname, & ! (in)
776 buf(:,:,:), & ! (out)
777 step=step, allow_missing=allow_missing ) ! (in)
778
779 if ( associated(this%meshCS3D) ) then
781 this%meshCS3D, buf(:,:,:), &
782 field3d )
783 else if ( associated(this%mesh3D) ) then
784 call file_common_meshfield_set_cartesbuf_field3d( this%mesh3D, buf(:,:,:), &
785 field3d )
786 end if
787 end if
788
789 return
790 end subroutine file_base_meshfield_read_var3d
791
792!OCL_SERIAL
793 subroutine file_base_meshfield_read_var3d_local( this, & ! (inout)
794 dim_typeid, varname, lcmesh, i0_s, j0_s, k0_s, & ! (in)
795 val, & ! (out)
796 step, allow_missing ) ! (in)
797
798 use scale_file, only: &
799 file_read
800 use scale_file_common_meshfield, only: &
802
803 implicit none
804
805 class(file_base_meshfield), intent(inout) :: this
806 integer, intent(in) :: dim_typeid
807 character(*), intent(in) :: varname
808 class(localmesh3d), intent(in) :: lcmesh
809 integer, intent(in) :: i0_s, j0_s, k0_s
810 real(RP), intent(out) :: val(lcmesh%refElem3D%Np,lcmesh%NeA)
811 integer, intent(in), optional :: step
812 logical, intent(in), optional :: allow_missing
813
814 real(RP), allocatable :: buf(:,:,:)
815 integer :: dims(3)
816 integer :: start(3) ! start offset of globale variable
817 !-------------------------------------------------
818
819 if ( this%fid /= -1 ) then
820 start(:) = 1
821 dims(1) = this%dimsinfo(mf3d_dimtype_x)%size
822 dims(2) = this%dimsinfo(mf3d_dimtype_y)%size
823 dims(3) = this%dimsinfo(mf3d_dimtype_z)%size
824 allocate( buf(dims(1),dims(2),dims(3)) )
825
826 call file_read( this%fid, varname, & ! (in)
827 buf(:,:,:), & ! (out)
828 step=step, allow_missing=allow_missing ) ! (in)
829
831 lcmesh, buf(:,:,:), i0_s, j0_s, k0_s, &
832 val(:,:) )
833 end if
834
835 return
836 end subroutine file_base_meshfield_read_var3d_local
837
838 subroutine file_base_meshfield_close( this ) ! (inout)
839 use scale_file, only: file_close
840
841 implicit none
842 class(file_base_meshfield), intent(inout) :: this
843 !--------------------------------------------------
844
845 if ( this%fid /= -1 ) then
846 call file_close( this%fid ) ! [IN]
847 this%fid = -1
848 end if
849
850 return
851 end subroutine file_base_meshfield_close
852
853
854 subroutine file_base_meshfield_final( this ) ! (inout)
855 implicit none
856 class(file_base_meshfield), intent(inout) :: this
857 !--------------------------------------------------
858
859 if ( allocated(this%vars_ncid) ) deallocate( this%vars_ncid )
860 if ( allocated(this%dimsinfo) ) deallocate( this%dimsinfo )
861 nullify( this%mesh1D, this%mesh2D, this%mesh3D )
862
863 return
864 end subroutine file_base_meshfield_final
865
866 subroutine file_base_meshfield_put_global_attribute_time( &
867 this, date, subsec )
868
869 use scale_file, only: &
870 file_set_attribute, &
871 file_get_cftunits
872 use scale_calendar, only: &
873 calendar_get_name
874
875 implicit none
876
877 class(file_base_meshfield), intent(inout) :: this
878 integer, intent(in) :: date(6)
879 real(DP), intent(in) :: subsec
880
881 character(34) :: tunits
882 character(len=H_SHORT) :: calendar_name
883 !------------------------------------
884
885 call file_set_attribute( this%fid, "global", "Conventions", "CF-1.6" ) ! [IN]
886 call file_set_attribute( this%fid, "global", "grid_name", "hoge" ) ! [IN]
887
888 !- time
889
890 if ( date(1) > 0 ) then
891 call file_get_cftunits( date(:), tunits )
892 call calendar_get_name( calendar_name )
893 else
894 tunits = 'seconds'
895 calendar_name = ''
896 endif
897
898 if ( calendar_name /= "" ) &
899 call file_set_attribute( this%fid, "global", "calendar", calendar_name )
900 call file_set_attribute( this%fid, "global", "time_units", tunits )
901 call file_set_attribute( this%fid, "global", "time_start", (/ subsec /) )
902
903 return
904 end subroutine file_base_meshfield_put_global_attribute_time
905
906 !- private -----------------------------------------
907
908 subroutine def_axes( this, & ! (in)
909 dtype ) ! (in)
910 use scale_const, only: &
911 undef => const_undef
912 use scale_file, only: &
913 file_def_axis, &
914 file_set_attribute, &
915 file_def_associatedcoordinate, &
916 file_add_associatedvariable
917
918 implicit none
919
920 class(file_base_meshfield), intent(in) :: this
921 character(*), intent(in) :: dtype
922 integer :: d
923 integer :: i_dtype
924 !------------
925
926 i_dtype = get_dtype( dtype )
927
928 if ( associated(this%mesh1D) ) then
929 do d=1, 1
930 call file_def_axis( this%fid, &
931 this%dimsinfo(d)%name, this%dimsinfo(d)%desc, this%dimsinfo(d)%unit, &
932 this%dimsinfo(d)%name, i_dtype, this%dimsinfo(d)%size )
933 end do
934 end if
935
936 if ( associated(this%mesh2D) &
937 .or. associated(this%meshCS2D) ) then
938 do d=1, 2
939 call file_def_axis( this%fid, &
940 this%dimsinfo(d)%name, this%dimsinfo(d)%desc, this%dimsinfo(d)%unit, &
941 this%dimsinfo(d)%name, i_dtype, this%dimsinfo(d)%size )
942 end do
943 end if
944
945 if ( associated(this%mesh3D) &
946 .or. associated(this%meshCS3D) ) then
947 do d=1, 3
948 call file_def_axis( this%fid, &
949 this%dimsinfo(d)%name, this%dimsinfo(d)%desc, this%dimsinfo(d)%unit, &
950 this%dimsinfo(d)%name, i_dtype, this%dimsinfo(d)%size )
951 end do
952 end if
953
954 return
955 end subroutine def_axes
956
957 subroutine write_axes( this, & ! (in)
958 start ) ! (in)
959 use scale_const, only: &
960 undef => const_undef
961 use scale_file, only: &
962 file_write_axis, &
963 file_set_attribute
964 use scale_file_common_meshfield, only: &
966 implicit none
967
968 class(file_base_meshfield), intent(in) :: this
969 integer, intent(in) :: start(3)
970
971 real(RP), allocatable :: x(:)
972 real(RP), allocatable :: y(:)
973 real(RP), allocatable :: z(:)
974 !------------
975
976 if ( associated(this%mesh1D) ) then
977 allocate( x(this%dimsinfo(1)%size) )
978 call file_common_meshfield_get_axis( this%mesh1D, this%dimsinfo, x(:), this%force_uniform_grid )
979
980 call file_write_axis( this%fid, this%dimsinfo(1)%name, x(:), start(1:1) )
981 end if
982
983 if ( associated(this%mesh2D) ) then
984 allocate( x(this%dimsinfo(1)%size), y(this%dimsinfo(2)%size) )
985 call file_common_meshfield_get_axis( this%mesh2D, this%dimsinfo, x(:), y(:), this%force_uniform_grid )
986
987 call file_write_axis( this%fid, this%dimsinfo(1)%name, x(:), start(1:1) )
988 call file_write_axis( this%fid, this%dimsinfo(2)%name, y(:), start(2:2) )
989 end if
990
991 if ( associated(this%meshCS2D) ) then
992 allocate( x(this%dimsinfo(1)%size), y(this%dimsinfo(2)%size) )
993 call file_common_meshfield_get_axis( this%meshCS2D, this%dimsinfo, x(:), y(:) )
994
995 call file_write_axis( this%fid, this%dimsinfo(1)%name, x(:), start(1:1) )
996 call file_write_axis( this%fid, this%dimsinfo(2)%name, y(:), start(2:2) )
997 end if
998
999 if ( associated(this%mesh3D) ) then
1000 allocate( x(this%dimsinfo(1)%size), y(this%dimsinfo(2)%size), z(this%dimsinfo(3)%size) )
1001 call file_common_meshfield_get_axis( this%mesh3D, this%dimsinfo, x(:), y(:), z(:), this%force_uniform_grid )
1002
1003 call file_write_axis( this%fid, this%dimsinfo(1)%name, x(:), start(1:1) )
1004 call file_write_axis( this%fid, this%dimsinfo(2)%name, y(:), start(2:2) )
1005 call file_write_axis( this%fid, this%dimsinfo(3)%name, z(:), start(3:3) )
1006 if ( this%dimsinfo(3)%positive_down(1) ) &
1007 call file_set_attribute( this%fid, this%dimsinfo(3)%name, "positive", "down" )
1008 end if
1009
1010 if ( associated(this%meshCS3D) ) then
1011 allocate( x(this%dimsinfo(1)%size), y(this%dimsinfo(2)%size), z(this%dimsinfo(3)%size) )
1012 call file_common_meshfield_get_axis( this%meshCS3D, this%dimsinfo, x(:), y(:), z(:) )
1013
1014 call file_write_axis( this%fid, this%dimsinfo(1)%name, x(:), start(1:1) )
1015 call file_write_axis( this%fid, this%dimsinfo(2)%name, y(:), start(2:2) )
1016 call file_write_axis( this%fid, this%dimsinfo(3)%name, z(:), start(3:3) )
1017 if ( this%dimsinfo(3)%positive_down(1) ) &
1018 call file_set_attribute( this%fid, this%dimsinfo(3)%name, "positive", "down" )
1019 end if
1020
1021 return
1022 end subroutine write_axes
1023
module FElib / Element / Base
subroutine file_base_meshfield_init(this, var_num, mesh1d, mesh2d, meshcubedsphere2d, mesh3d, meshcubedsphere3d, force_uniform_grid)
subroutine, public file_common_meshfield_set_cartesbuf_field1d(mesh1d, buf, field1d)
subroutine, public file_common_meshfield_set_cartesbuf_field2d(mesh2d, buf, field2d)
subroutine, public file_common_meshfield_put_field3d_cubedsphere_cartesbuf(mesh3d, field3d, buf)
subroutine, public file_common_meshfield_put_field2d_cubedsphere_cartesbuf(mesh2d, field2d, buf)
subroutine, public file_common_meshfield_put_field2d_cartesbuf(mesh2d, field2d, buf, force_uniform_grid)
subroutine, public file_common_meshfield_set_cartesbuf_field3d(mesh3d, buf, field3d)
subroutine, public file_common_meshfield_put_field1d_cartesbuf(mesh1d, field1d, buf, force_uniform_grid)
subroutine, public file_common_meshfield_set_cartesbuf_field2d_local(lcmesh, buf, i0_s, j0_s, val)
subroutine, public file_common_meshfield_set_cartesbuf_field3d_local(lcmesh, buf, i0_s, j0_s, k0_s, val)
subroutine, public file_common_meshfield_put_field3d_cartesbuf(mesh3d, field3d, buf, force_uniform_grid)
subroutine, public file_common_meshfield_set_cartesbuf_field1d_local(lcmesh, buf, i0_s, val)
subroutine, public file_common_meshfield_set_cartesbuf_field3d_cubedsphere(mesh3d, buf, field3d)
subroutine, public file_common_meshfield_set_cartesbuf_field2d_cubedsphere(mesh2d, buf, field2d)
integer function, public file_common_meshfield_get_dtype(datatype)
module FElib / Mesh / Local 1D
module FElib / Mesh / Local 2D
module FElib / Mesh / Local 3D
module FElib / Mesh / Base 1D
integer, public meshbase1d_dimtype_num
integer, public meshbase1d_dimtypeid_x
module FElib / Mesh / Base 2D
integer, public meshbase2d_dimtypeid_x
integer, public meshbase2d_dimtype_num
integer, public meshbase2d_dimtypeid_y
module FElib / Mesh / Base 3D
integer, public meshbase3d_dimtypeid_y
integer, public meshbase3d_dimtypeid_z
integer, public meshbase3d_dimtype_num
integer, public meshbase3d_dimtypeid_x
module FElib / Mesh / Cubic 3D domain
module FElib / Mesh / Cubed-sphere 2D domain
module FElib / Mesh / Cubed-sphere 3D domain
module FElib / Mesh / Rectangle 2D domain
module FElib / Data / base
module FElib / Data / base