@@ -21,6 +21,10 @@ module bspline_oo_module
2121
2222 private
2323
24+ integer ,parameter :: int_size = storage_size(1 ) ! ! size of a default integer [bits]
25+ integer ,parameter :: logical_size = storage_size(.true. ) ! ! size of a default logical [bits]
26+ integer ,parameter :: real_size = storage_size(1.0_wp ) ! ! size of a real(wp) [bits]
27+
2428 type,public ,abstract :: bspline_class
2529 ! ! Base class for the b-spline types
2630 private
@@ -31,17 +35,27 @@ module bspline_oo_module
3135 private
3236 procedure ,non_overridable :: destroy_base ! ! destructor for the abstract type
3337 procedure (destroy_func),deferred,public :: destroy ! ! destructor
38+ procedure (size_func),deferred,public :: size_of ! ! size of the structure in bits
3439 procedure ,public ,non_overridable :: status_ok ! ! returns true if the last `iflag` status code was `=0`.
3540 procedure ,public ,non_overridable :: status_message = > get_bspline_status_message ! ! retrieve the last status message
3641 procedure ,public ,non_overridable :: clear_flag = > clear_bspline_flag ! ! to reset the `iflag` saved in the class.
3742 end type bspline_class
3843
3944 abstract interface
45+
4046 pure subroutine destroy_func (me ) ! ! interface for bspline destructor routines
4147 import :: bspline_class
4248 implicit none
4349 class(bspline_class),intent (inout ) :: me
4450 end subroutine destroy_func
51+
52+ pure function size_func (me ) result(s) ! ! interface for size routines
53+ import :: bspline_class
54+ implicit none
55+ class(bspline_class),intent (in ) :: me
56+ integer :: s ! ! size of the structure in bits
57+ end function size_func
58+
4559 end interface
4660
4761 type,extends(bspline_class),public :: bspline_1d
@@ -58,6 +72,7 @@ end subroutine destroy_func
5872 procedure :: initialize_1d_specify_knots
5973 procedure ,public :: evaluate = > evaluate_1d
6074 procedure ,public :: destroy = > destroy_1d
75+ procedure ,public :: size_of = > size_1d
6176 final :: finalize_1d
6277 end type bspline_1d
6378
@@ -80,6 +95,7 @@ end subroutine destroy_func
8095 procedure :: initialize_2d_specify_knots
8196 procedure ,public :: evaluate = > evaluate_2d
8297 procedure ,public :: destroy = > destroy_2d
98+ procedure ,public :: size_of = > size_2d
8399 final :: finalize_2d
84100 end type bspline_2d
85101
@@ -107,6 +123,7 @@ end subroutine destroy_func
107123 procedure :: initialize_3d_specify_knots
108124 procedure ,public :: evaluate = > evaluate_3d
109125 procedure ,public :: destroy = > destroy_3d
126+ procedure ,public :: size_of = > size_3d
110127 final :: finalize_3d
111128 end type bspline_3d
112129
@@ -139,6 +156,7 @@ end subroutine destroy_func
139156 procedure :: initialize_4d_specify_knots
140157 procedure ,public :: evaluate = > evaluate_4d
141158 procedure ,public :: destroy = > destroy_4d
159+ procedure ,public :: size_of = > size_4d
142160 final :: finalize_4d
143161 end type bspline_4d
144162
@@ -176,6 +194,7 @@ end subroutine destroy_func
176194 procedure :: initialize_5d_specify_knots
177195 procedure ,public :: evaluate = > evaluate_5d
178196 procedure ,public :: destroy = > destroy_5d
197+ procedure ,public :: size_of = > size_5d
179198 final :: finalize_5d
180199 end type bspline_5d
181200
@@ -218,6 +237,7 @@ end subroutine destroy_func
218237 procedure :: initialize_6d_specify_knots
219238 procedure ,public :: evaluate = > evaluate_6d
220239 procedure ,public :: destroy = > destroy_6d
240+ procedure ,public :: size_of = > size_6d
221241 final :: finalize_6d
222242 end type bspline_6d
223243
@@ -329,6 +349,150 @@ pure function get_bspline_status_message(me,iflag) result(msg)
329349 end function get_bspline_status_message
330350! *****************************************************************************************
331351
352+ ! *****************************************************************************************
353+ ! >
354+ ! Actual size of a [[bspline_1d]] structure in bits.
355+
356+ pure function size_1d (me ) result(s)
357+
358+ implicit none
359+
360+ class(bspline_1d),intent (in ) :: me
361+ integer :: s ! ! size of the structure in bits
362+
363+ s = 2 * int_size + logical_size + 2 * int_size
364+
365+ if (allocated (me% bcoef)) s = s + real_size* size (me% bcoef)
366+ if (allocated (me% tx)) s = s + real_size* size (me% tx)
367+
368+ end function size_1d
369+ ! *****************************************************************************************
370+
371+ ! *****************************************************************************************
372+ ! >
373+ ! Actual size of a [[bspline_2d]] structure in bits.
374+
375+ pure function size_2d (me ) result(s)
376+
377+ implicit none
378+
379+ class(bspline_2d),intent (in ) :: me
380+ integer :: s ! ! size of the structure in bits
381+
382+ s = 2 * int_size + logical_size + 6 * int_size
383+
384+ if (allocated (me% bcoef)) s = s + real_size* size (me% bcoef,1 )* &
385+ size (me% bcoef,2 )
386+ if (allocated (me% tx)) s = s + real_size* size (me% tx)
387+ if (allocated (me% ty)) s = s + real_size* size (me% ty)
388+
389+ end function size_2d
390+ ! *****************************************************************************************
391+
392+ ! *****************************************************************************************
393+ ! >
394+ ! Actual size of a [[bspline_3d]] structure in bits.
395+
396+ pure function size_3d (me ) result(s)
397+
398+ implicit none
399+
400+ class(bspline_3d),intent (in ) :: me
401+ integer :: s ! ! size of the structure in bits
402+
403+ s = 2 * int_size + logical_size + 10 * int_size
404+
405+ if (allocated (me% bcoef)) s = s + real_size* size (me% bcoef,1 )* &
406+ size (me% bcoef,2 )* &
407+ size (me% bcoef,3 )
408+ if (allocated (me% tx)) s = s + real_size* size (me% tx)
409+ if (allocated (me% ty)) s = s + real_size* size (me% ty)
410+ if (allocated (me% tz)) s = s + real_size* size (me% tz)
411+
412+ end function size_3d
413+ ! *****************************************************************************************
414+
415+ ! *****************************************************************************************
416+ ! >
417+ ! Actual size of a [[bspline_4d]] structure in bits.
418+
419+ pure function size_4d (me ) result(s)
420+
421+ implicit none
422+
423+ class(bspline_4d),intent (in ) :: me
424+ integer :: s ! ! size of the structure in bits
425+
426+ s = 2 * int_size + logical_size + 14 * int_size
427+
428+ if (allocated (me% bcoef)) s = s + real_size* size (me% bcoef,1 )* &
429+ size (me% bcoef,2 )* &
430+ size (me% bcoef,3 )* &
431+ size (me% bcoef,4 )
432+ if (allocated (me% tx)) s = s + real_size* size (me% tx)
433+ if (allocated (me% ty)) s = s + real_size* size (me% ty)
434+ if (allocated (me% tz)) s = s + real_size* size (me% tz)
435+ if (allocated (me% tq)) s = s + real_size* size (me% tq)
436+
437+ end function size_4d
438+ ! *****************************************************************************************
439+
440+ ! *****************************************************************************************
441+ ! >
442+ ! Actual size of a [[bspline_5d]] structure in bits.
443+
444+ pure function size_5d (me ) result(s)
445+
446+ implicit none
447+
448+ class(bspline_5d),intent (in ) :: me
449+ integer :: s ! ! size of the structure in bits
450+
451+ s = 2 * int_size + logical_size + 18 * int_size
452+
453+ if (allocated (me% bcoef)) s = s + real_size* size (me% bcoef,1 )* &
454+ size (me% bcoef,2 )* &
455+ size (me% bcoef,3 )* &
456+ size (me% bcoef,4 )* &
457+ size (me% bcoef,5 )
458+ if (allocated (me% tx)) s = s + real_size* size (me% tx)
459+ if (allocated (me% ty)) s = s + real_size* size (me% ty)
460+ if (allocated (me% tz)) s = s + real_size* size (me% tz)
461+ if (allocated (me% tq)) s = s + real_size* size (me% tq)
462+ if (allocated (me% tr)) s = s + real_size* size (me% tr)
463+
464+ end function size_5d
465+ ! *****************************************************************************************
466+
467+ ! *****************************************************************************************
468+ ! >
469+ ! Actual size of a [[bspline_6d]] structure in bits.
470+
471+ pure function size_6d (me ) result(s)
472+
473+ implicit none
474+
475+ class(bspline_6d),intent (in ) :: me
476+ integer :: s ! ! size of the structure in bits
477+
478+ s = 2 * int_size + logical_size + 22 * int_size
479+
480+ if (allocated (me% bcoef)) s = s + real_size* size (me% bcoef,1 )* &
481+ size (me% bcoef,2 )* &
482+ size (me% bcoef,3 )* &
483+ size (me% bcoef,4 )* &
484+ size (me% bcoef,5 )* &
485+ size (me% bcoef,6 )
486+ if (allocated (me% tx)) s = s + real_size* size (me% tx)
487+ if (allocated (me% ty)) s = s + real_size* size (me% ty)
488+ if (allocated (me% tz)) s = s + real_size* size (me% tz)
489+ if (allocated (me% tq)) s = s + real_size* size (me% tq)
490+ if (allocated (me% tr)) s = s + real_size* size (me% tr)
491+ if (allocated (me% ts)) s = s + real_size* size (me% ts)
492+
493+ end function size_6d
494+ ! *****************************************************************************************
495+
332496! *****************************************************************************************
333497! >
334498! Destructor for contents of the base [[bspline_class]] class.
0 commit comments