Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Input Fortran:读取输入_Input_Fortran_Intel Fortran - Fatal编程技术网

Input Fortran:读取输入

Input Fortran:读取输入,input,fortran,intel-fortran,Input,Fortran,Intel Fortran,我正在尝试运行一个非常大的FORTRAN模型,所以我不能给出所有涉及的代码,但我希望我能提供足够的信息,使其有意义。 代码编译良好(使用英特尔2016.0.109编译器、OpenMPI 1.10.2和HDF5 1.8.17) 当我尝试运行它时,它告诉我我的两个输入(称为NZG和NZS)被设置为-999,因此它失败了 > >>>> opspec_grid error! in your namelist! > ---> Reason:

我正在尝试运行一个非常大的FORTRAN模型,所以我不能给出所有涉及的代码,但我希望我能提供足够的信息,使其有意义。 代码编译良好(使用英特尔2016.0.109编译器、OpenMPI 1.10.2和HDF5 1.8.17)

当我尝试运行它时,它告诉我我的两个输入(称为NZG和NZS)被设置为-999,因此它失败了

> >>>>  opspec_grid  error! in your namelist!
>     ---> Reason:      Too few soil layers.  Set it to at least 2. Your nzg is currently set to -999...
>     ---> Reason:      Too few maximum # of snow layers. Set it to at least 1.  Your nzs is currently set to -999.
但是,在输入文件中,它们实际上被指定为

   NL%NZG  = 9
   NL%NZS  = 1
我浏览了所有与这些变量有关的模块,但找不到任何应该偏离轨道的地方。 所以我现在开始想,可能是读取值的方式有问题。输入文件是一个文本文件。变量在读取它们的模块中指定为整数,仅供参考。 我应该检查特殊字符还是什么?我知道Fortran对输入很挑剔

编辑:在跟踪错误的代码序列下方

1) 主模块打开名称列表

write (unit=*,fmt='(a)') 'Reading namelist information'
call read_nl(trim(name_name))
read\nl

subroutine read_nl(namelist_name)
   use ename_coms, only : nl              & ! intent(inout)
                        , init_ename_vars ! ! subroutine

   implicit none
   !----- Arguments. ----------------------------------------------------------------------!
   character(len=*), intent(in) :: namelist_name
   !----- Local variables. ----------------------------------------------------------------!
   logical                      :: fexists
   !----- Name lists. ---------------------------------------------------------------------!
   namelist /ED_NL/ nl
   !---------------------------------------------------------------------------------------!

   !----- Open the namelist file. ---------------------------------------------------------!
   inquire (file=trim(namelist_name),exist=fexists)
   if (.not. fexists) then
      call fatal_error('The namelist file '//trim(namelist_name)//' is missing.'           &
                      ,'read_nl','ed_load_namelist.f90')
   end if

   !----- Initialise the name list with absurd, undefined values. -------------------------!
   call init_ename_vars(nl) 

   !----- Read grid point and options information from the namelist. ----------------------!
   open (unit=10, status='OLD', file=namelist_name)
   read (unit=10, nml=ED_NL)
   close(unit=10)

   return
end subroutine read_nl
2) 然后是关于如何(哪些变量)从名称列表(输入)中读取的细节

我的模拟是
'NOT_HISTORY'
copy_nl('ALL_CASES')
被指定,因此它读取许多名称列表变量,包括变量
'runtype'
,然后在if-else语句中使用

3) 然后
copy\u nl('NOT\u HISTORY')
如下所示,这是定义nzg和nzs的地方

subroutine copy_nl(copy_type)
use grid_coms            , only : time                      & ! intent(out)
                                   , centlon                   & ! intent(out)
                                   , centlat                   & ! intent(out)
                                   , deltax                    & ! intent(out)
                                   , deltay                    & ! intent(out)
                                   , nnxp                      & ! intent(out)
                                   , nnyp                      & ! intent(out)
                                   , nstratx                   & ! intent(out)
                                   , nstraty                   & ! intent(out)
                                   , polelat                   & ! intent(out)
                                   , polelon                   & ! intent(out)
                                   , ngrids                    & ! intent(out)
                                   , timmax                    & ! intent(out)
                                   , time                      & ! intent(out)
                                   , nzg                       & ! intent(out)
                                   , nzs                       ! ! intent(out)
implicit none
   !----- Arguments. ----------------------------------------------------------------------!
   character(len=*), intent(in) :: copy_type
   !----- Internal variables. -------------------------------------------------------------!
   integer                      :: ifm
   !---------------------------------------------------------------------------------------!

   !---------------------------------------------------------------------------------------!
   !     Here we decide which variables we should copy based on the input variable.        !
   !---------------------------------------------------------------------------------------!
select case (trim(copy_type))
case ('NOT_HISTORY')

  itimea        = nl%itimea
  idatea        = nl%idatea
  imontha       = nl%imontha
  iyeara        = nl%iyeara

  nzg           = nl%nzg
  nzs           = nl%nzs

  slz(1:nzgmax) = nl%slz(1:nzgmax)

  current_time%year  = iyeara
  current_time%month = imontha
  current_time%date  = idatea
  current_time%time  = real(int(real(itimea) * 0.01)) * hr_sec                         &
                     + (real(itimea) * 0.01 - real(int(real(itimea)*0.01)))            &
                     * 100.0 * min_sec
  time               = 0.0d0
请注意,我没有将所有的模块和变量都放在
use
中,否则这篇文章会非常长。 仅供参考,模块
grid\u coms
指定变量的类型。参见下面的相关部分(整个模块是一个变量列表,没有其他内容)

4) 回到主模块,然后调用
ed\u opspec\u grid
检查变量是否合理,这就是问题所在。同样地,使用
use
时,变量在开始时就被初始化了,我在这里不讨论这个问题

subroutine ed_opspec_grid
!---------------------------------------------------------------------------------------!
   !      Check whether soil layers are reasonable, i.e, enough layers, sorted from the !
   ! deepest to the shallowest.                                                            !
   !---------------------------------------------------------------------------------------!
   if (nzg < 2) then
      write (reason,'(a,1x,i4,a)')                                                         &
            'Too few soil layers.  Set it to at least 2. Your nzg is currently set to'     &
           ,nzg,'...'
      call opspec_fatal(reason,'opspec_grid')  
      ifaterr=ifaterr+1        
   elseif (nzg > nzgmax) then 
      write (reason,'(2(a,1x,i5,a))')                                                      &
            'The number of soil layers cannot be greater than ',nzgmax,'.'                 &
           ,' Your nzg is currently set to',nzg,'.'
      call opspec_fatal(reason,'opspec_grid') 
      ifaterr=ifaterr+1 
   end if
   do k=1,nzg
      if (slz(k) > -.001) then
         write (reason,'(a,1x,i4,1x,a,1x,es14.7,a)')                                       &
               'Your soil level #',k,'is not enough below ground. It is currently set to'  &
               ,slz(k),', make it deeper than -0.001...'
         call opspec_fatal(reason,'opspec_grid')  
         ifaterr=ifaterr+1        
      end if
   end do

   do k=1,nzg-1
      if (slz(k)-slz(k+1) > .001) then
         write (reason,'(2(a,1x,i4,1x),a,2x,a,1x,es14.7,1x,a,1x,es14.7,a)')                &
               'Soil layers #',k,'and',k+1,'are not enough apart (i.e. > 0.001).'          &
              ,'They are currently set as ',slz(k),'and',slz(k+1),'...'
         call opspec_fatal(reason,'opspec_grid')  
         ifaterr=ifaterr+1        
      end if
   end do
end subroutine ed_opspec_grid
子程序ed\u opspec\u网格
!---------------------------------------------------------------------------------------!
!      检查土层是否合理,即是否有足够的土层,从!
! 最深最浅!
!---------------------------------------------------------------------------------------!
如果(nzg<2),则
写入(原因,“(a,1x,i4,a)”&
“土层太少。将其设置为至少2。您的nzg当前设置为'&
,nzg,“…”
调用opspec\u fatal(原因为'opspec\u grid')
ifaterr=ifaterr+1
elseif(nzg>nzgmax)然后
写入(原因,“(2(a,1x,i5,a)))&
“土壤层的数量不能大于”,nzgmax“。”&
,'您的nzg当前设置为',nzg'。'
调用opspec\u fatal(原因为'opspec\u grid')
ifaterr=ifaterr+1
如果结束
do k=1,nzg
如果(slz(k)>-.001),那么
写入(原因,“(a,1x,i4,1x,a,1x,es14.7,a)”&
“你的土壤水平面”k“在地下是不够的。它当前设置为'&
,slz(k),',使其深度超过-0.001…'
调用opspec\u fatal(原因为'opspec\u grid')
ifaterr=ifaterr+1
如果结束
结束
Dok=1,nzg-1
如果(slz(k)-slz(k+1)>.001),那么
写入(原因,“(2(a,1x,i4,1x),a,2x,a,1x,es14.7,1x,a,1x,es14.7,a)”&
“土壤层#”,k,“和”,k+1,“距离不够(即>0.001)。”&
,“它们当前设置为',slz(k),'和',slz(k+1),'…”
调用opspec\u fatal(原因为'opspec\u grid')
ifaterr=ifaterr+1
如果结束
结束
结束子程序ed_opspec_网格
请注意,这不是此子例程中的第一次检查。在这一部分之前检查了其他变量(我省略了这些变量),但这是第一条错误消息。这让我觉得,可能部分输入是可读的,而有些是不可读的

最后,让我再次强调,这是一个非常大的项目,我真的无法显示所有的代码,这就是为什么我非常简单地提出了这个问题:Fortran是否有我可能遗漏的任何(文本)输入要求(特殊字符、返回,对于不同的系统可能不同?)。
另外,这段代码被很多研究人员在不同的平台上使用,所以我很怀疑代码本身是否有问题。。。(但如果我错了,请告诉我)。

您没有为我们提供足够的数据来确定问题,因此我将使用姓名列表告诉您我遇到的两个问题:

  • 如果从同一个文件中读取多个(甚至不同)名称列表,则顺序将起作用:如果在文件名称列表
    a
    中,名称列表
    b
    ,但代码先读取
    b
    ,则除非您倒带文件,否则它将找不到
    a

  • 如果数据文件中的名称列表不包含一个或多个值,则这些值将保持不变。很可能在代码中,这些变量被设置为
    -999
    ,以便注意到它们的缺失。因此,请仔细检查数据文件是否正确。查找可能过早结束姓名列表的离群
    /
    字符

  • 总之,为了正确评估正在发生的事情,我们至少需要三件事:

  • 声明块,包括构成此名称列表一部分的所有变量,以及
    namelist/../…,…,…
    规范

  • 名称列表文件中声明此特定名称列表的部分,以及

  • 是否有任何其他名称列表也在同一文件中,以及它们是否在该名称列表之前或之后(在文件和代码中)<
    module grid_coms
      integer :: nzg                            ! Number of soil levels
      integer :: nzs                            ! Number of snow/surface water levels
    end module grid_coms
    
    subroutine ed_opspec_grid
    !---------------------------------------------------------------------------------------!
       !      Check whether soil layers are reasonable, i.e, enough layers, sorted from the !
       ! deepest to the shallowest.                                                            !
       !---------------------------------------------------------------------------------------!
       if (nzg < 2) then
          write (reason,'(a,1x,i4,a)')                                                         &
                'Too few soil layers.  Set it to at least 2. Your nzg is currently set to'     &
               ,nzg,'...'
          call opspec_fatal(reason,'opspec_grid')  
          ifaterr=ifaterr+1        
       elseif (nzg > nzgmax) then 
          write (reason,'(2(a,1x,i5,a))')                                                      &
                'The number of soil layers cannot be greater than ',nzgmax,'.'                 &
               ,' Your nzg is currently set to',nzg,'.'
          call opspec_fatal(reason,'opspec_grid') 
          ifaterr=ifaterr+1 
       end if
       do k=1,nzg
          if (slz(k) > -.001) then
             write (reason,'(a,1x,i4,1x,a,1x,es14.7,a)')                                       &
                   'Your soil level #',k,'is not enough below ground. It is currently set to'  &
                   ,slz(k),', make it deeper than -0.001...'
             call opspec_fatal(reason,'opspec_grid')  
             ifaterr=ifaterr+1        
          end if
       end do
    
       do k=1,nzg-1
          if (slz(k)-slz(k+1) > .001) then
             write (reason,'(2(a,1x,i4,1x),a,2x,a,1x,es14.7,1x,a,1x,es14.7,a)')                &
                   'Soil layers #',k,'and',k+1,'are not enough apart (i.e. > 0.001).'          &
                  ,'They are currently set as ',slz(k),'and',slz(k+1),'...'
             call opspec_fatal(reason,'opspec_grid')  
             ifaterr=ifaterr+1        
          end if
       end do
    end subroutine ed_opspec_grid