把这里sys.argv传参改成用namelist的方法 import sys CASEPATH=sys.argv[1] if sys.argv[2] == "GRID": GRIDBASE="#define GRIDBASED" CATCHMENT="#undef CATCHMENT" UNSTRUCTU="#undef UNSTRUCTURED" SINGLEPOI="#undef SinglePoint"
时间: 2023-07-21 14:02:46 浏览: 87
你可以使用namelist的方法来替代sys.argv传参。首先,创建一个namelist文件,例如"input.nml",在文件中定义你需要的参数:
```fortran
¶ms
CASEPATH = 'path/to/case'
GRIDTYPE = 'GRID'
CATCHMENT = .FALSE.
UNSTRUCTURED = .FALSE.
SINGLEPOINT = .FALSE.
/
```
然后,在你的代码中使用一个Fortran读取namelist文件的库(例如f90nml)来读取参数:
```fortran
program your_program
use f90nml
type(params) :: input_params
character(len=256) :: namelist_file
namelist_file = 'input.nml'
read(namelist_file, nml=input_params)
CASEPATH = input_params%CASEPATH
GRIDTYPE = input_params%GRIDTYPE
CATCHMENT = input_params%CATCHMENT
UNSTRUCTURED = input_params%UNSTRUCTURED
SINGLEPOINT = input_params%SINGLEPOINT
! Rest of your code...
end program your_program
```
这样,你就可以通过修改"input.nml"文件来改变参数,而不需要使用命令行参数传递。
阅读全文