parquet_maml_base.f90 Source File


Source Code

!===========================================
! This file is automatically generated! Do not edit it directly!
! Instead, edit the MAML files under schemas/ and run generate_parquet_maml.sh to regenerate this file.
! Generator script: parquet-fortran/tools/generate_parquet_maml.sh
!===========================================
!> Base-library MAML fixtures: embeds every .maml file under schemas/ bundled
!> with this library as a compiled-in string array, addressable by filename via
!> get_parquet_maml, plus the shared parquet_maml_file type and its
!> add_col_qc/set_col_qc qc-maml builders.
module parquet_maml_base
    implicit none
    private

    !> One schema field the base MAML declares but a user-supplied MAML omits;
    !> populated by parquet_validate_user_maml, one entry per missing field.
    type, public :: parquet_maml_missing_column
        character(len=:), allocatable :: name      !! The name of the field [required].
        character(len=:), allocatable :: unit      !! The unit of measurement for the field.
        character(len=:), allocatable :: info      !! A short description of the field.
        character(len=:), allocatable :: ucd       !! Unified Content Descriptor for IVOA (can have many).
        character(len=:), allocatable :: data_type !! The data type of the field [required]; base token
        !! only for a temporal column (unit/utc are in time_unit/is_utc).
        integer :: time_unit = 0 !! time/timestamp stored unit (a parquet_unit_* selector; 0 if not temporal).
        logical :: is_utc = .false. !! timestamp UTC-adjusted flag.
        integer :: array_size = 1 !! Maximum length of character strings.
        integer :: col_size = 1   !! The number of elements in the vector column.
    end type parquet_maml_missing_column

    !> One col_map: entry: `- <internal_name>: <output_name>`, i.e. the field
    !> declared as `output_name` in this MAML fields: actually corresponds to
    !> the internal/canonical column named `internal_name`.
    type, public :: parquet_maml_col_map_entry
        character(len=:), allocatable :: internal_name !! Canonical (internal) column name.
        character(len=:), allocatable :: output_name   !! Renamed name as declared in fields:.
    end type parquet_maml_col_map_entry

    !> One embedded or user-supplied MAML file: its raw source lines plus, once
    !> parsed/validated, the columns missing relative to the base schema and any
    !> col_map: renames it declares. add_col_qc/set_col_qc build a qc-maml
    !> incrementally (see parquet_maml_base_add_col_qc.f90).
    type, public :: parquet_maml_file
        logical :: user_maml = .false. !! true if this is a user defined MAML file
        character(len=:), allocatable :: name !! This MAML file name (embedded fixture name or path).
        character(len=:), allocatable :: lines(:) !! Raw MAML source, one array element per line.
        !> Columns present in the base MAML but missing from this (user) MAML;
        !> populated by parquet_validate_user_maml, consumed by parquet_read_maml.
        type(parquet_maml_missing_column), allocatable :: missing_columns(:)
        !> Parsed col_map: section (see parquet_maml_col_map_entry): exposes the
        !> renames this MAML declares, for inspection; populated by
        !> parquet_validate_user_maml. Renames are applied automatically whenever
        !> this MAML lines are parsed, independent of whether this is set.
        type(parquet_maml_col_map_entry), allocatable :: col_map(:)
    contains
        procedure :: add_col_qc => parquet_maml_add_col_qc !! Appends one qc: field entry.
        procedure :: set_col_qc => parquet_maml_set_col_qc !! In-place form; parses the name into its argument.
    end type parquet_maml_file

    interface
        !> Appends one qc: field entry to this MAML from a compact
        !> "col, min, max, miss" string. col_name (optional) returns the
        !> parsed column name. Implemented in the submodule
        !> src/parquet_maml_base_add_col_qc.f90.
        module subroutine parquet_maml_add_col_qc(self, qc_input, col_name)
            class(parquet_maml_file), intent(inout) :: self !! qc-maml being built; gains a fields: entry.
            character(len=*), intent(in) :: qc_input !! compact "col, min, max, miss" string.
            character(len=:), allocatable, intent(out), optional :: col_name !! parsed column name.
        end subroutine parquet_maml_add_col_qc
        !> In-place form of add_col_qc: appends the same qc: field entry. `col_name` is
        !> `intent(inout)`: it holds the compact "col, min, max, miss" string on entry and
        !> the parsed column name on exit, so a caller reuses one variable
        !> (call maml%set_col_qc(col)) instead of naming a separate input and output.
        module subroutine parquet_maml_set_col_qc(self, col_name)
            class(parquet_maml_file), intent(inout) :: self !! qc-maml being built; gains a fields: entry.
            character(len=:), allocatable, intent(inout) :: col_name !! compact "col, min, max, miss" string on
            !! entry; parsed column name on exit.
        end subroutine parquet_maml_set_col_qc
    end interface

    public :: get_parquet_maml
    public :: parquet_maml_maml_example
    public :: parquet_maml_maml_example2
    public :: parquet_maml_maml_example3

contains

    !> Returns the named embedded .maml fixture from schemas/ as a raw parquet_maml_file
    !> (unparsed lines only); error stops on an unknown name. A fixture is matched
    !> by its filename, with or without the .maml extension; one held in a
    !> subdirectory is also matched by its full relative path.
    function get_parquet_maml(name) result(maml)
        character(len=*), intent(in) :: name !! embedded fixture name, with or without .maml.
        type(parquet_maml_file) :: maml !! the matching MAML, unparsed (raw lines only).

        select case (trim(name))
        case ("maml_example.maml")
            maml = parquet_maml_maml_example()
        case ("maml_example")
            maml = parquet_maml_maml_example()
        case ("maml_example2.maml")
            maml = parquet_maml_maml_example2()
        case ("maml_example2")
            maml = parquet_maml_maml_example2()
        case ("maml_example3.maml")
            maml = parquet_maml_maml_example3()
        case ("maml_example3")
            maml = parquet_maml_maml_example3()
        case default
            error stop "get_parquet_maml: unknown internal MAML file: " // trim(name)
        end select
    end function get_parquet_maml

    !> Returns the embedded maml_example.maml MAML fixture, unparsed (raw lines only).
    function parquet_maml_maml_example() result(maml)
        type(parquet_maml_file) :: maml !! the maml_example.maml MAML, unparsed.

        maml%name = "maml_example.maml"
        allocate(character(len=104) :: maml%lines(91))
        maml%lines(1) = "dataset: input_data"
        maml%lines(2) = "table: input_table"
        maml%lines(3) = "author: Dave Smith <dave_smith_is_not_here@gmail.com>"
        maml%lines(4) = "coauthors:"
        maml%lines(5) = "- Joe Bloggs <joe_bloggs_is_not_here@gmail.com>"
        maml%lines(6) = "- Jane Doe <jane_doe_is_not_here@gmail.com>"
        maml%lines(7) = "DOIs:"
        maml%lines(8) = "- DOI: 10.1093/mnras/sty440"
        maml%lines(9) = "  type: paper"
        maml%lines(10) = "- DOI: 10.5281/zenodo.10059903"
        maml%lines(11) = "  type: software"
        maml%lines(12) = &
            "description: Just an example. Probably do not write tonnes here. A few sentences is usually about ri" // &
            "ght."
        maml%lines(13) = "comments:"
        maml%lines(14) = "- This is an example. Remember comments are lists."
        maml%lines(15) = "- Another comment."
        maml%lines(16) = "- zeropoint: 1.00"
        maml%lines(17) = "license: Copyright [Private]"
        maml%lines(18) = "keyarray:"
        maml%lines(19) = "- key: test_scalar"
        maml%lines(20) = "  value: 8.1"
        maml%lines(21) = "  comment: something"
        maml%lines(22) = "- key: test_string"
        maml%lines(23) = "  value: Fun times"
        maml%lines(24) = "  comment: something else"
        maml%lines(25) = "- key: test_vector"
        maml%lines(26) = "  value: [1.8, 2, 5]"
        maml%lines(27) = "  comment: something extra"
        maml%lines(28) = "fields:"
        maml%lines(29) = "- name: id0"
        maml%lines(30) = "  unit: unitless"
        maml%lines(31) = "  info: ID field."
        maml%lines(32) = "  ucd: meta.id;meta.main"
        maml%lines(33) = "  data_type: int32"
        maml%lines(34) = "- name: idarr"
        maml%lines(35) = "  unit: unitless"
        maml%lines(36) = "  info: ID field."
        maml%lines(37) = "  ucd: meta.id;meta.main"
        maml%lines(38) = "  data_type: int64"
        maml%lines(39) = "  col_size: 2"
        maml%lines(40) = "- name: name"
        maml%lines(41) = "  unit: unitless"
        maml%lines(42) = "  info: Name of the object."
        maml%lines(43) = "  ucd:"
        maml%lines(44) = "  - meta.id"
        maml%lines(45) = "  - meta.main"
        maml%lines(46) = "  data_type: string"
        maml%lines(47) = "  array_size: 18"
        maml%lines(48) = "- name: name_arr"
        maml%lines(49) = "  info: Name of the object."
        maml%lines(50) = "  data_type: string"
        maml%lines(51) = "  array_size: 8"
        maml%lines(52) = "  col_size: 3"
        maml%lines(53) = "- name: idlong"
        maml%lines(54) = "  unit: count"
        maml%lines(55) = "  info: Long ID field."
        maml%lines(56) = "  ucd: meta.id"
        maml%lines(57) = "  data_type: int64"
        maml%lines(58) = "- name: value"
        maml%lines(59) = "  unit: m/s"
        maml%lines(60) = "  info: Value of the object."
        maml%lines(61) = "  ucd: phys.veloc;phys.speed"
        maml%lines(62) = "  data_type: float32"
        maml%lines(63) = "- name: value_64"
        maml%lines(64) = "  unit: m/s"
        maml%lines(65) = "  info: Second value of the object."
        maml%lines(66) = "  ucd: phys.veloc;phys.speed"
        maml%lines(67) = "  data_type: float64"
        maml%lines(68) = "- name: arr"
        maml%lines(69) = "  unit: unitless"
        maml%lines(70) = "  info: Array of values."
        maml%lines(71) = "  ucd: "
        maml%lines(72) = "  data_type: float32"
        maml%lines(73) = "  col_size: 5"
        maml%lines(74) = "- name: arrlong"
        maml%lines(75) = "  unit: unitless"
        maml%lines(76) = "  info: Array of values."
        maml%lines(77) = "  data_type: float64"
        maml%lines(78) = "  col_size: 5"
        maml%lines(79) = "- name: val"
        maml%lines(80) = "  info: Value of the object."
        maml%lines(81) = "  data_type: float32"
        maml%lines(82) = "- name: iarr"
        maml%lines(83) = "  info: Array of values."
        maml%lines(84) = "  data_type: int32"
        maml%lines(85) = "  col_size: 3"
        maml%lines(86) = "- name: myflag"
        maml%lines(87) = "  data_type: boolean"
        maml%lines(88) = "- name: flag_array"
        maml%lines(89) = "  info: Flag for the object."
        maml%lines(90) = "  data_type: boolean"
        maml%lines(91) = "  col_size: 6"
    end function parquet_maml_maml_example
    !> Returns the embedded maml_example2.maml MAML fixture, unparsed (raw lines only).
    function parquet_maml_maml_example2() result(maml)
        type(parquet_maml_file) :: maml !! the maml_example2.maml MAML, unparsed.

        maml%name = "maml_example2.maml"
        allocate(character(len=104) :: maml%lines(83))
        maml%lines(1) = "survey: The Big Survey"
        maml%lines(2) = "dataset: input_data"
        maml%lines(3) = "table: input_table"
        maml%lines(4) = "version: 1.3"
        maml%lines(5) = "date: '2025-09-01'"
        maml%lines(6) = "author: Dave Smith <dave_smith_is_not_here@gmail.com>"
        maml%lines(7) = "coauthors:"
        maml%lines(8) = "- Joe Bloggs <joe_bloggs_is_not_here@gmail.com>"
        maml%lines(9) = "- Jane Doe <jane_doe_is_not_here@gmail.com>"
        maml%lines(10) = "DOIs:"
        maml%lines(11) = "- DOI: 10.1093/mnras/sty440"
        maml%lines(12) = "  type: paper"
        maml%lines(13) = "- DOI: 10.5281/zenodo.10059903"
        maml%lines(14) = "  type: software"
        maml%lines(15) = "depends:"
        maml%lines(16) = "- survey: The Medium Survey"
        maml%lines(17) = "  dataset: SpecZ"
        maml%lines(18) = "  table: Spec_field_01"
        maml%lines(19) = "  version: 3.7"
        maml%lines(20) = "- survey: The Tiny Survey"
        maml%lines(21) = "  dataset: Stars"
        maml%lines(22) = "  table: Phot_South"
        maml%lines(23) = "  version: 2"
        maml%lines(24) = &
            "description: Just an example. Probably do not write tonnes here. A few sentences is usually about ri" // &
            "ght."
        maml%lines(25) = "comments:"
        maml%lines(26) = "- Optional comment or interesting fact"
        maml%lines(27) = "- '...'"
        maml%lines(28) = "license: Copyright [Private]"
        maml%lines(29) = "keywords:"
        maml%lines(30) = "- Optional keyword tag"
        maml%lines(31) = "- TopCat"
        maml%lines(32) = "MAML_version: 1.2"
        maml%lines(33) = "keyarray:"
        maml%lines(34) = "- key: test_url"
        maml%lines(35) = "  value: //example.com/data #new"
        maml%lines(36) = "  comment: something: and else"
        maml%lines(37) = "- key: test_url2"
        maml%lines(38) = "  value: http://example.com/data :#new"
        maml%lines(39) = "  comment: something: and else"
        maml%lines(40) = "extra:"
        maml%lines(41) = "  anything:"
        maml%lines(42) = "    I:"
        maml%lines(43) = "      like: 1.3"
        maml%lines(44) = "fields:"
        maml%lines(45) = "- name: id"
        maml%lines(46) = "  ucd:"
        maml%lines(47) = "  - meta.id"
        maml%lines(48) = "  - meta.main"
        maml%lines(49) = "  info: ID field."
        maml%lines(50) = "  data_type: int32"
        maml%lines(51) = "  qc:"
        maml%lines(52) = "    min: 1"
        maml%lines(53) = "    max: 1000"
        maml%lines(54) = "    miss: 'Null'"
        maml%lines(55) = "- name: name"
        maml%lines(56) = "  unit: unitless"
        maml%lines(57) = "  ucd: meta.id;meta.main"
        maml%lines(58) = "  info: Name of the object."
        maml%lines(59) = "  data_type: string"
        maml%lines(60) = "  array_size: 24"
        maml%lines(61) = "- name: RA"
        maml%lines(62) = "  unit: deg"
        maml%lines(63) = "  info: Right ascension (J2000)"
        maml%lines(64) = "  ucd: pos.eq.ra"
        maml%lines(65) = "  data_type: float64"
        maml%lines(66) = "  array_size:"
        maml%lines(67) = "  col_size:"
        maml%lines(68) = "  qc:"
        maml%lines(69) = "    min: '>= 0'"
        maml%lines(70) = "    max: '< 360'"
        maml%lines(71) = "    miss: 'Null'"
        maml%lines(72) = "- name: Dec"
        maml%lines(73) = "  unit: deg"
        maml%lines(74) = "  info: Declination (J2000)"
        maml%lines(75) = "  ucd:"
        maml%lines(76) = "  - pos.eq.dec"
        maml%lines(77) = "  data_type: float64"
        maml%lines(78) = "  array_size:"
        maml%lines(79) = "  col_size:"
        maml%lines(80) = "  qc:"
        maml%lines(81) = "    min: -90"
        maml%lines(82) = "    max: 90"
        maml%lines(83) = "    miss: 'Null'"
    end function parquet_maml_maml_example2
    !> Returns the embedded maml_example3.maml MAML fixture, unparsed (raw lines only).
    function parquet_maml_maml_example3() result(maml)
        type(parquet_maml_file) :: maml !! the maml_example3.maml MAML, unparsed.

        maml%name = "maml_example3.maml"
        allocate(character(len=53) :: maml%lines(48))
        maml%lines(1) = "survey: The Big Survey"
        maml%lines(2) = "dataset: input_data"
        maml%lines(3) = "table: input_table"
        maml%lines(4) = "version: 1.3"
        maml%lines(5) = "date: '2025-09-01'"
        maml%lines(6) = "author: Dave Smith <dave_smith_is_not_here@gmail.com>"
        maml%lines(7) = "description: Just an example."
        maml%lines(8) = "MAML_version: 1.2"
        maml%lines(9) = "extra:"
        maml%lines(10) = "  whatever: ei midagi"
        maml%lines(11) = "  col_map:"
        maml%lines(12) = "  - id: uberid"
        maml%lines(13) = "  - RA: ra_J2000"
        maml%lines(14) = "  yet_another: testing"
        maml%lines(15) = "fields:"
        maml%lines(16) = "- name: uberid"
        maml%lines(17) = "  ucd:"
        maml%lines(18) = "  - meta.id"
        maml%lines(19) = "  - meta.main"
        maml%lines(20) = "  info: ID field."
        maml%lines(21) = "  data_type: int32"
        maml%lines(22) = "  qc:"
        maml%lines(23) = "    min: 1"
        maml%lines(24) = "    max: 1000"
        maml%lines(25) = "    miss: 'Null'"
        maml%lines(26) = "- name: ra_J2000"
        maml%lines(27) = "  unit: deg"
        maml%lines(28) = "  info: Right ascension (J2000)"
        maml%lines(29) = "  ucd: pos.eq.ra"
        maml%lines(30) = "  data_type: float64"
        maml%lines(31) = "  array_size:"
        maml%lines(32) = "  col_size:"
        maml%lines(33) = "  qc:"
        maml%lines(34) = "    min: '>= 0'"
        maml%lines(35) = "    max: '< 360'"
        maml%lines(36) = "    miss: 'Null'"
        maml%lines(37) = "- name: Dec"
        maml%lines(38) = "  unit: deg"
        maml%lines(39) = "  info: Declination (J2000)"
        maml%lines(40) = "  ucd:"
        maml%lines(41) = "  - pos.eq.dec"
        maml%lines(42) = "  data_type: float64"
        maml%lines(43) = "  array_size:"
        maml%lines(44) = "  col_size:"
        maml%lines(45) = "  qc:"
        maml%lines(46) = "    min: -90"
        maml%lines(47) = "    max: 90"
        maml%lines(48) = "    miss: 'Null'"
    end function parquet_maml_maml_example3

end module parquet_maml_base ! GCOVR_EXCL_LINE