code: def _generic_patch_sources(
      filenames, patch_source_func, source_fnpart, root_dir=None
  ):
      """
      Patch Fortran sources, creating new source files.
  
      Parameters
      ----------
      filenames : list
          List of Fortran source files to patch.
          Files not ending in ``.f`` or ``.f90`` are left unaltered.
      patch_source_func : callable(filename, old_contents) -> new_contents
          Function to apply to file contents, returning new file contents
          as a string.
      source_fnpart : str
          String to append to the modified file basename before extension.
      root_dir : str, optional
          Source root directory. Default: cwd
  
      Returns
      -------
      new_filenames : list
          List of names of the newly created patched sources.
  
      """
      new_filenames = []
  
      if root_dir is None:
          root_dir = os.getcwd()
  
      root_dir = os.path.abspath(root_dir)
      src_dir = os.path.join(root_dir, _get_build_src_dir())
  
      for src in filenames:
          base, ext = os.path.splitext(os.path.basename(src))
  
          if ext not in (".f", ".f90"):
              new_filenames.append(src)
              continue
  
          with open(src, "r") as fsrc:
              text = patch_source_func(src, fsrc.read())
  
          # Generate useful target directory name under src_dir
          src_path = os.path.abspath(os.path.dirname(src))
  
          for basedir in [src_dir, root_dir]:
              if os.path.commonpath([src_path, basedir]) == basedir:
                  rel_path = os.path.relpath(src_path, basedir)
                  break
          else:
              raise ValueError(f"{src!r} not under {root_dir!r}")
  
          dst = os.path.join(
              src_dir, rel_path, base + source_fnpart + ext
          )
          write_file_content(dst, text)
  
          new_filenames.append(dst)
  
      return new_filenames
  
imports: import re
  import os
  import sys
  from distutils.util import get_platform
  import numpy
  from .system_info import combine_dict
label_desc: Use image node_id 13 for calling a global function with example usage: _generic_patch_sources(filenames, patch_source_func, source_fnpart, root_dir) and returns: new_filenames