Fortran Coder

查看: 818|回复: 2

[数值问题] 怎样让字符串相等

[复制链接]

61

帖子

14

主题

0

精华

熟手

F 币
241 元
贡献
181 点
发表于 2018-2-1 01:51:11 | 显示全部楼层 |阅读模式
本帖最后由 wxy 于 2018-2-1 01:54 编辑

74行开始的if循环设置的等式全部不成立 但是73行的打印结果 读取是没问题的 75行一个都没打印出来 不知道是不是哪里语句出问题了
[Fortran] 纯文本查看 复制代码
! A fortran95 program for G95
! By WQY
program main
    implicit none
    integer::i,m
  !  real::lon
    character(len=4)::LO,CL,SILO,CLLO,SACL,SICL,SALO,LOSA,SA
    character(len=4) , allocatable :: type_soil(:)
    character(len=9) , allocatable :: site(:)
    real , allocatable :: lat(:),lon(:),SBDM(:),SLOC(:),SLCL(:),SLHW(:)



    m=46086 !//m 此时的含义为,有多少个数据(而不是有多少行)
    allocate(site(m),lat(m),lon(m),type_soil(m),SBDM(m),SLOC(m),SLCL(m),SLHW(m))
    open(8, File='D:/DNDC/soil.txt')
    do i=1,m
        read(8,"(a9,2x,f5.2,2x,f6.2,2x,a4,2x,f5.3,2x,f4.2,2x,f4.1,2x,f3.1)")&
        &site(i),lat(i),lon(i),type_soil(i),SBDM(i),SLOC(i),SLCL(i),SLHW(i)
      !  write(*,*)type_soil(i)

        !     Open (11, File='D:/DNDC/filename.dat')
        !     do
        !╤ах║нд╪ЧцШ
        !         read(11,*) filename
        ! if(i/=0) exit
        open(7,File='D:/DNDC/double_rice/'//site(i)//'.dnd')

        !  if (filename==site(i))then
        write(7,'(a)')'DNDC_Input_Parameters'
        write(7,'(a)')'----------------------------------------'
        write(7,'(a)')'Site_infomation'
        write(7,'(t1,a,a9)')
        write(7,'(t1,a,a6)')'__Site_name                                                   CN',site(i)(4:9)
        write(7,'(a)')'__Simulated_years                                                    10'
        write(7,'(t1,a,f7.4)')'__Latitude                                                      ',lat(i)
        write(7,'(a)')'__Daily_record                                                        0'
        write(7,'(a)')'__Unit_system                                                         0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'----------------------------------------'
        write(7,'(a)')'Climate_data'
        write(7,'(a)')
        write(7,'(a)')'__Climate_data_type                                                   1'
        write(7,'(a)')'__N_in_rainfall                                                  0.0000'
        write(7,'(a)')'__Air_NH3_concentration                                          0.0600'
        write(7,'(a)')'__Air_CO2_concentration                                        350.0000'
        write(7,'(a)')'__Climate_files                                                      10'
        write(7,'(a,a6)')'1                                                        F:\weather-DNDC\1961\CN',site(i)(4:9)
        write(7,'(a,a6)')'2                                                        F:\weather-DNDC\1962\CN',site(i)(4:9)
        write(7,'(a,a6)')'3                                                        F:\weather-DNDC\1963\CN',site(i)(4:9)
        write(7,'(a,a6)')'4                                                        F:\weather-DNDC\1964\CN',site(i)(4:9)
        write(7,'(a,a6)')'5                                                        F:\weather-DNDC\1965\CN',site(i)(4:9)
        write(7,'(a,a6)')'6                                                        F:\weather-DNDC\1966\CN',site(i)(4:9)
        write(7,'(a,a6)')'7                                                        F:\weather-DNDC\1967\CN',site(i)(4:9)
        write(7,'(a,a6)')'8                                                        F:\weather-DNDC\1968\CN',site(i)(4:9)
        write(7,'(a,a6)')'9                                                        F:\weather-DNDC\1969\CN',site(i)(4:9)
        write(7,'(a,a6)')'10                                                       F:\weather-DNDC\1970\CN',site(i)(4:9)
        write(7,'(a)')'__Climate_file_mode                                                   0'
        write(7,'(a)')'__CO2_increase_rate                                              0.0000'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'__None                                                                0'
        write(7,'(a)')'----------------------------------------'
        write(7,'(a)')'Soil_data'
        write(7,'(a)')
        write(7,'(a)')'__Land_use_ID                                                         2'
         !   print*,type_soil(i)
        if(type_soil(i)==LO)THEN
            print*,type_soil(i)
            write(7,'(a)')'__Soil_texture_ID                                                     5'
        elseif (type_soil(i)==CL)THEN
            write(7,'(a)')'__Soil_texture_ID                                                    11'
        elseif (type_soil(i)==SILO)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     4'
        elseif (type_soil(i)==CLLO)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     8'
        elseif (type_soil(i)==SACL)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     6'
        elseif (type_soil(i)==SICL)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     7'
        elseif (type_soil(i)==SALO)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     3'
        elseif (type_soil(i)==LOSA)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     2'
        elseif (type_soil(i)==SA)THEN
            write(7,'(a)')'__Soil_texture_ID                                                     1'
        else
            write(7,'(a)')'__Soil_texture_ID                                                     6'
        END IF

        !  end if
close(7)
        print*,site(i),' is end'
        ! end do

    end do

    deallocate(site,lat,lon,type_soil,SBDM,SLOC,SLCL,SLHW)
end program main



TIM截图20180201015201.png
回复

使用道具 举报

44

帖子

6

主题

0

精华

专家

超凡脱俗

F 币
317 元
贡献
168 点
发表于 2018-2-1 10:36:42 | 显示全部楼层
一、LO,CL,SILO,CLLO,SACL,SICL,SALO,LOSA,SA 这些变量都没有初始化
二、type_soil读文件第四列,要4个字符,包含空格,空格是不是要trim掉?
天下英雄出我辈,一入江湖岁月催。

鸿图霸业谈笑间,不胜人生一场醉。

61

帖子

14

主题

0

精华

熟手

F 币
241 元
贡献
181 点
 楼主| 发表于 2018-2-1 10:41:19 | 显示全部楼层
Jackdaw 发表于 2018-2-1 10:36
一、LO,CL,SILO,CLLO,SACL,SICL,SALO,LOSA,SA 这些变量都没有初始化啊
二、type_soil读文件第四列,要4个字 ...

嗯嗯 明白了 谢谢
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

QQ|捐赠本站|Archiver|关于我们 About Us|群聊|Fcode

GMT+8, 2018-12-12 15:45

Powered by Discuz! X3.2

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表