get_molecule_name Function

public function get_molecule_name(filename) result(name)

Extract molecule name from filename Example: “output_multi_structure_molecule_1.json” -> “molecule_1”

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

Return Value character(len=256)


Called by

proc~~get_molecule_name~~CalledByGraph proc~get_molecule_name get_molecule_name proc~read_json_content read_json_content proc~read_json_content->proc~get_molecule_name proc~merge_multi_molecule_json merge_multi_molecule_json proc~merge_multi_molecule_json->proc~read_json_content proc~run_multi_molecule_calculations run_multi_molecule_calculations proc~run_multi_molecule_calculations->proc~merge_multi_molecule_json program~main main program~main->proc~run_multi_molecule_calculations

Variables

Type Visibility Attributes Name Initial
integer, private :: end_pos
integer, private :: start_pos

Source Code

   function get_molecule_name(filename) result(name)
      !! Extract molecule name from filename
      !! Example: "output_multi_structure_molecule_1.json" -> "molecule_1"
      character(len=*), intent(in) :: filename
      character(len=256) :: name
      integer :: start_pos, end_pos

      ! Find "_molecule_" or similar pattern
      start_pos = index(filename, '_molecule_')
      if (start_pos == 0) start_pos = index(filename, '_mol_')

      if (start_pos > 0) then
         start_pos = start_pos + 1  ! Skip leading underscore
         end_pos = index(filename, '.json') - 1
         if (end_pos > start_pos) then
            name = filename(start_pos:end_pos)
         else
            name = "unknown"
         end if
      else
         name = "unknown"
      end if
   end function get_molecule_name