用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill fortran-namelist命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | fortran-namelist |
| description | Reading and modifying Fortran namelist configuration files for scientific models |
Fortran namelists are human-readable configuration files used by many scientific models. They use §ion syntax and key=value pairs. Parsing requires careful handling of Fortran syntax quirks.
§ion_name
parameter1 = value1
parameter2 = value2, value3, value4
array_param = 1, 2, 3, 4, 5
/
Key features:
&name and //!)import f90nml
# Read entire namelist
nml = f90nml.read('/path/to/config.nml')
# Access values
kw = nml['light']['Kw']
coef_mix = nml['mixing']['coef_mix_hyp']
# Modify values
nml['light']['Kw'] = 0.35
nml['mixing']['wind_factor'] = 1.1
# Write back
nml.write('/path/to/config.nml', force=True)
pip install f90nml
For simple changes without additional dependencies:
import re
def read_nml_parameter(nml_file, section, param):
"""Extract single parameter value from namelist"""
with open(nml_file, 'r') as f:
content = f.read()
# Pattern: find section, then parameter
pattern = (r'&' + section + r'.*?' +
r'(\s+' + param + r'\s*=\s*)' +
r'([^,\n/]+)')
match = re.search(pattern, content, re.DOTALL)
if match:
value_str = match.group(2).strip()
try:
return float(value_str)
except ValueError:
return value_str
return None
def update_nml_parameter(nml_file, section, param, value):
"""Update a parameter in namelist"""
with open(nml_file, 'r') as f:
content = f.read()
# Pattern to find and replace parameter in section
pattern = (r'(&' + section + r'.*?)' +
r'(\s+' + param + r'\s*=\s*)' +
r'([^,\n/]+)')
replacement = r'\g<1>\g<2>' + str(value)
new_content = re.sub(pattern, replacement, content,
count=1, flags=re.DOTALL)
(nml_file, ) f:
f.write(new_content)
Fortran namelists support array values:
&init_profiles
the_depths = 0, 1, 2, 3, 4, 5
the_temps = 5.1, 5.1, 5.0, 4.9, 4.8, 4.7
/
import f90nml
nml = f90nml.read('glm3.nml')
depths = nml['init_profiles']['the_depths'] # List
temps = nml['init_profiles']['the_temps'] # List
print(depths[0]) # 0
print(temps[5]) # 4.7
Arrays should not be modified for this task, but if needed:
# Only modify if changing array values entirely
nml['init_profiles']['the_depths'] = [0, 1, 2, 3, 4, 5, 6]
nml['init_profiles']['the_temps'] = [5.1, 5.1, 5.0, 4.9, 4.8, 4.7, 4.6]
cp glm3.nml glm3.nml.bakimport f90nml
# Read original
nml = f90nml.read('glm3.nml')
print(f"Original Kw: {nml['light']['Kw']}")
# Modify
nml['light']['Kw'] = 0.35
nml.write('glm3.nml', force=True)
# Verify change persisted
nml2 = f90nml.read('glm3.nml')
assert nml2['light']['Kw'] == 0.35
print("Verification passed!")
[...] in Python, Fortran has = with commas