Skip to content

Commit

Permalink
#2394 Removed the bits field from ALL_TYPES.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Jan 7, 2025
1 parent ecb0571 commit 8debe33
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 108 deletions.
6 changes: 6 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ all:
$(MAKE) -C read_only all
$(MAKE) -C value_range_check all

allclean:
$(MAKE) -C extract clean
$(MAKE) -C profiling clean
$(MAKE) -C read_only clean
$(MAKE) -C value_range_check clean

%.f90: %.jinja process.py
$$($(PSYDATA_LIB_DIR)/get_python.sh) $(PSYDATA_LIB_DIR)/process.py $< > $*.f90

Expand Down
22 changes: 9 additions & 13 deletions lib/extract/compare_variables_mod.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined -%}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Character", "character(*)", 8),
("Long", "real(kind=int64)", 64),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Character", "character(*)" ),
("Long", "real(kind=int64)" ),
("Int", "integer(kind=int32)") ] %}
{% endif -%}


Expand Down Expand Up @@ -99,7 +95,7 @@ module compare_variables_mod
{# ------------------------------------------------------------------------- #}
interface compare
{% set all_compares=[] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
module procedure compare_scalar_{{name}}
{% for dim in ALL_DIMS %}
module procedure compare_array_{{dim}}d{{name}}
Expand Down Expand Up @@ -158,7 +154,7 @@ contains
end subroutine compare_summary
! -------------------------------------------------------------------------
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
{# Logical needs EQV for its tests #}
{% if name == "Logical" %}
{% set EQUAL = ".EQV." -%}
Expand Down Expand Up @@ -311,6 +307,6 @@ contains
end subroutine Compare_array_{{dim}}d{{name}}
{% endfor -%} {# for dim in ALL_DIMS #}
{%- endfor -%} {# for name, type, bits in ALL_TYPES #}
{%- endfor -%} {# for name, type in ALL_TYPES #}
end module compare_variables_mod
22 changes: 9 additions & 13 deletions lib/extract/netcdf/extract_netcdf_base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined -%}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Character", "character(*)", 32),
("Long", "real(kind=int64)", 64),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Character", "character(*)" ),
("Long", "real(kind=int64)" ),
("Int", "integer(kind=int32)") ] %}
{% endif -%}


Expand Down Expand Up @@ -119,7 +115,7 @@ module extract_netcdf_base_mod
{# ------------------------------------------------------------------------- -#}
{% set all_declares=[] -%}
{% set all_provides=[] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
procedure :: DeclareScalar{{name}}
procedure :: WriteScalar{{name}}
{{- all_declares.append("DeclareScalar"~name) or "" -}}
Expand Down Expand Up @@ -318,7 +314,7 @@ contains
"Int": "NF90_INT"} -%}

{% set indent=" " %}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
{% set NETCDF_TYPE = NCDF_TYPE_MAPPING[name] %}
! -------------------------------------------------------------------------
!> @brief This subroutine declares a scalar {{type}} value.
Expand Down Expand Up @@ -506,6 +502,6 @@ contains

{% endfor -%} {# for dim in ALL_DIMS #}

{%- endfor -%} {# for name, type, bits in ALL_TYPES #}
{%- endfor -%} {# for name, type in ALL_TYPES #}

end module extract_netcdf_base_mod
22 changes: 9 additions & 13 deletions lib/extract/netcdf/read_kernel_data_mod.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined -%}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Char", "character(*)", 8),
("Logical","integer(kind=real32)",32),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Char", "character(*)" ),
("Logical","integer(kind=real32)"),
("Int", "integer(kind=int32)" ) ] %}
{% endif -%}


Expand Down Expand Up @@ -99,7 +95,7 @@ module read_kernel_data_mod
{# Collect and declare the various procedures for the same generic interface -#}
{# ------------------------------------------------------------------------- -#}
{% set all_reads=[] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
procedure :: ReadScalar{{name}}
{{- all_reads.append("ReadScalar"~name) or "" }}
{% for dim in ALL_DIMS %}
Expand Down Expand Up @@ -197,7 +193,7 @@ contains
"Logical":"NF90_INT",
"Int": "NF90_INT"} -%}

{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
{% set NETCDF_TYPE = NCDF_TYPE_MAPPING[name] %}

! -------------------------------------------------------------------------
Expand Down Expand Up @@ -329,6 +325,6 @@ contains

{% endfor -%} {# for dim in ALL_DIMS #}

{%- endfor -%} {# for name, type, bits in ALL_TYPES #}
{%- endfor -%} {# for name, type in ALL_TYPES #}

end module read_kernel_data_mod
22 changes: 9 additions & 13 deletions lib/extract/standalone/extract_standalone_base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined -%}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Character", "character(*)", 8),
("Long", "real(kind=int64)", 64),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Character", "character(*)" ),
("Long", "real(kind=int64)" ),
("Int", "integer(kind=int32)") ] %}
{% endif -%}


Expand Down Expand Up @@ -112,7 +108,7 @@ module extract_standalone_base_mod
{# ------------------------------------------------------------------------- -#}
{% set all_declares=[] -%}
{% set all_provides=[] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
procedure :: WriteScalar{{name}}
{{- all_provides.append("WriteScalar"~name) or "" }}
{% for dim in ALL_DIMS %}
Expand Down Expand Up @@ -215,7 +211,7 @@ contains

end subroutine PostEnd

{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
! -------------------------------------------------------------------------
!> @brief This subroutine writes the value of a scalar {{type}}
!! variable to the file. It takes the variable id from the
Expand Down Expand Up @@ -275,6 +271,6 @@ contains

{% endfor -%} {# for dim in ALL_DIMS #}

{%- endfor -%} {# for name, type, bits in ALL_TYPES #}
{%- endfor -%} {# for name, type in ALL_TYPES #}

end module extract_standalone_base_mod
22 changes: 9 additions & 13 deletions lib/extract/standalone/read_kernel_data_mod.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined -%}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Char", "character(*)", 8),
("Logical","integer(kind=real32)",32),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Char", "character(*)" ),
("Logical","integer(kind=real32)"),
("Int", "integer(kind=int32)" ) ] %}
{% endif -%}


Expand Down Expand Up @@ -102,7 +98,7 @@ module read_kernel_data_mod
{# Collect and declare the various procedures for the same generic interface -#}
{# ------------------------------------------------------------------------- -#}
{% set all_reads=[] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
procedure :: ReadScalar{{name}}
{{- all_reads.append("ReadScalar"~name) or "" }}
{% for dim in ALL_DIMS %}
Expand Down Expand Up @@ -168,7 +164,7 @@ contains

end subroutine OpenReadFileName

{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}

! -------------------------------------------------------------------------
!> @brief This subroutine reads the value of a scalar {{type}}
Expand Down Expand Up @@ -264,6 +260,6 @@ contains

{% endfor -%} {# for dim in ALL_DIMS #}

{%- endfor -%} {# for name, type, bits in ALL_TYPES #}
{%- endfor -%} {# for name, type in ALL_TYPES #}

end module read_kernel_data_mod
12 changes: 6 additions & 6 deletions lib/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@
# ---------------------------------------------------------
# This is a mapping from the command line option name
# to the tuple that is required for the jinja templates:
TYPE_DATA = {"real": ("Real", "real(kind=real32)", 32),
"double": ("Double", "real(kind=real64)", 64),
"int": ("Int", "integer(kind=int32)", 32),
"char": ("Char", "character(*)", 8),
"logical": ("Logical", "Logical(kind=4)", 4),
"long": ("Long", "integer(kind=int64)", 64)}
TYPE_DATA = {"real": ("Real", "real(kind=real32)"),
"double": ("Double", "real(kind=real64)"),
"int": ("Int", "integer(kind=int32)"),
"char": ("Char", "character(*)"),
"logical": ("Logical", "Logical(kind=4)"),
"long": ("Long", "integer(kind=int64)")}

# ---------------------------------------------------------
# Check type information:
Expand Down
16 changes: 6 additions & 10 deletions lib/psy_data_base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Int", "integer(kind=int32)") ] %}
{% endif %}

! -----------------------------------------------------------------------------
Expand Down Expand Up @@ -110,7 +106,7 @@ module psy_data_base_mod
{# ------------------------------------------------------------- -#}
{% set all_declares=[] -%}
{% set all_provides=[] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
procedure :: DeclareScalar{{name}}
procedure :: ProvideScalar{{name}}
{{- all_declares.append("DeclareScalar"~name) or "" -}}
Expand Down Expand Up @@ -316,7 +312,7 @@ contains
! =========================================================================
! Jinja created code:
! =========================================================================
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
! -------------------------------------------------------------------------
!> @brief This subroutine declares a scalar {{type}} value. This
!! implementation only increases the next index, and prints
Expand Down
4 changes: 2 additions & 2 deletions lib/read_only/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ F90FLAGS ?=
PSYDATA_LIB_DIR ?= ./..
# -----------------------------------------------------------------------------

# The read-only verification library is implemented for int, real and
# double scalars and 2-dimension arrays
# The read-only verification library is implemented for int, logical,
# characters, real, and double precision scalars and 1 to 4 dimensional arrays
PROCESS_ARGS = -prefix=read_only_verify_ -types=char,int,logical,real,double \
-dims=1,2,3,4
PROCESS = $$($(PSYDATA_LIB_DIR)/get_python.sh) $(PSYDATA_LIB_DIR)/process.py
Expand Down
32 changes: 21 additions & 11 deletions lib/read_only/read_only_base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@

{# The types that are supported. The first entry of each tuple
is the name used when naming subroutines and in user messages.
The second entry is the Fortran declaration. The third entry
is the number of bits. There is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mould) function leaves undefined bits
when mould is larger than value.) #}
The second entry is the Fortran declaration. #}

{% if ALL_TYPES is not defined %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)", 64),
("Real", "real(kind=real32)", 32),
("Int", "integer(kind=int32)", 32) ] %}
{% set ALL_TYPES = [ ("Double", "real(kind=real64)" ),
("Real", "real(kind=real32)" ),
("Int", "integer(kind=int32)") ] %}
{% endif %}

! -----------------------------------------------------------------------------
Expand Down Expand Up @@ -117,7 +113,7 @@ module read_only_base_mod
{# Collect the various procedures for the same generic interface -#}
{# ------------------------------------------------------------- -#}
{% set all_provides=[] -%}
{%- for name, type, bits in ALL_TYPES %}
{%- for name, type in ALL_TYPES %}
procedure :: ProvideScalar{{name}}
{{- all_provides.append("ProvideScalar"~name) or "" }}
{% for dim in ALL_DIMS %}
Expand Down Expand Up @@ -145,7 +141,7 @@ module read_only_base_mod
{# Create a generic interface for all ComputeChecksum functions #}
{# ------------------------------------------------------------ #}
{% set all_compute = [] -%}
{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
{% for dim in ALL_DIMS %}
{{- all_compute.append("ComputeChecksum"~dim~"d"~name) or "" -}}
{% endfor %}
Expand Down Expand Up @@ -265,7 +261,21 @@ contains
LFRic which uses ComputeChecksum1dDouble)
#}

{% for name, type, bits in ALL_TYPES %}
{% for name, type in ALL_TYPES %}
{# We need the number of bits since there is slightly different code
required for 32 and 64 bit values (due to the fact that the
Fortran transfer(value, mold) function leaves undefined bits
when mold is larger than value. #}
{% if name in ["Real", "Int", "Logical"] %}
{% set bits = 32 %}
{% elif name in ["Double", "Long"] %}
{% set bits = 64 %}
{% elif name in ["Char"] %}
{% set bits = 8 %}
{% else %}
ERROR - UNSUPPORTED BIT SIZE for {{name}}!
{% endif %}


! =========================================================================
! Implementation for all {{type}} types
Expand Down
Loading

0 comments on commit 8debe33

Please sign in to comment.