program wheat_area
implicit none
integer m,i
integer,allocatable::alloc_key(:)
real,allocatable::whea(:), whea_h(:),whea_l(:)
real,allocatable::whea_i(:),whea_s(:)
open(10,file="/home/iga_qtong/fortran_xcao/gae_c/spam_p.csv")
open(11,file="/home/iga_qtong/fortran_xcao/gae_c/whout.csv")
m=792305
allocate(alloc_key(m),whea(m),whea_h(m))
allocate(whea_l(m),whea_i(m),whea_s(m))
do i=1,1
read(10,*)
end do
do i=1,m
read(10,*)
write(11,*) (alloc_key(i),whea(i),whea_h(i),whea_l(i),&
whea_i(i),whea_s(i))
end do
close(10)
close(11)
end program wheat_area
program test
implicit none
integer,parameter::nCol = 113
integer i, j
character(80) str(nCol)
character(*),parameter:: strHead(6)=['alloc_key','whea','whea_h','whea_l', 'whea_i','whea_s']
logical L(nCol)
open(11,file='2.csv')
open(10,file='1.csv')
!读取表头
read(10,*) str
!判断需要读取的列
L = .false.
do i = 1, nCol
str(i) = adjustl( str(i) )
if( any(trim(str(i))==strHead) ) then
L(i) = .true.
write(11,"(a,',')",advance='no') trim( str(i) ) !输出新表头
end if
end do
write(11,*)
do
read(10,*,iostat=j) str
if(j/=0) exit
do i =1, nCol
if(.NOT.L(i)) cycle
write(11,'(a,",")',advance='no') trim( str(i) )
end do
write(11,*)
end do
end program test
li913 发表于 2017-4-8 18:23
write的问题,去掉最外层括号就好。[mw_shl_code=fortran,true]program test
implicit none
integer,pa ...
fcode 发表于 2017-4-9 17:32
这本来就是 do 循环呀,加了 cycle 它还是do循环。
cycle 的意思是,放弃本次循环,直接进入下一次循环。 ...
fcode 发表于 2017-4-10 08:10
character(*),parameter:: strHead(6)=['alloc_key','whea','whea_h','whea_l', 'whea_i','whea_s']
改为
program wheat_area
implicit none
integer k,i
integer,parameter::nCol=113
!Define a constant nCol equal to 113
character(80) str(nCol)
character(9),parameter::strHead(6)=['alloc_key,'whea ','whea_h ','whea_l ','whea_i ','whea_s ']
logical (kind=4) L(nCol)
open(10,file="/home/iga_qtong/fortran_xcao/gae_c/spam_p.csv")
open(11,file="/home/iga_qtong/fortran_xcao/gae_c/whout.csv")
read(10,*) str !read the head of table
L= .false. !determin the column to read
do i=1,nCol
str(i)=AdjustL(str(i))
if(any(Trim(str(i))==strHead))then
!if the string equal to the strHead
L(i)= .true.
write(11,"(a,',')",advance='no') Trim(str(i))
end if
end do
fcode 发表于 2017-4-10 08:10
character(*),parameter:: strHead(6)=['alloc_key','whea','whea_h','whea_l', 'whea_i','whea_s']
改为
program wheat_area
implicit none
integer k,i
integer,parameter::nCol=113
!Define a constant nCol equal to 113
character(80) str(nCol)
character(9),parameter::strHead(6)=['alloc_key,'whea ','whea_h ','whea_l ','whea_i ','whea_s ']
logical (kind=4) L(nCol)
open(10,file="/home/iga_qtong/fortran_xcao/gae_c/spam_p.csv")
open(11,file="/home/iga_qtong/fortran_xcao/gae_c/whout.csv")
read(10,*) str !read the head of table
L= .false. !determin the column to read
do i=1,nCol
str(i)=AdjustL(str(i))
if(any(Trim(str(i))==strHead))then
!if the string equal to the strHead
L(i)= .true.
write(11,"(a,',')",advance='no') Trim(str(i))
end if
end do
write(11,*)
do
read(10,*,iostat=k) str
if(k/=0) exit
do i=1,nCol
if(.NOT.L(i)) cycle
write(11,'(a,",")',advance='no') Trim(str(i))
end do
write(11,*)
end do
end program wheat_area
fcode 发表于 2017-4-10 17:20
少了一个引号,请直接复制粘贴我的代码。
fcode 发表于 2017-4-10 21:22
没想到你连复制粘贴都不会
桂圆莲子汤 发表于 2017-4-10 21:51
对不起,之前把空格去掉了,我自己没注意,不好意思,可是这次我是真的复制过去的,还是一样的错误,但是 ...
pasuka 发表于 2017-4-10 22:11
*.f格式最大列数不超过80,把文件后缀名改成*.f90
活学活用,急用先学并不代表本站的视频教程和彭国伦的 ...
program test
implicit none
integer,parameter::nCol = 36
integer i, j
character(80) str(nCol)
character(32),parameter:: strHead(1)=['Province']
!strHead(23)=['Province','City','Stationname','Longitude','Latitude','Publishtime', 'AQI','SO2','NO2','CO','O3','PM10', &
!'PM2_5','SO2_24H_AVG','NO2_24H_AVG','CO_24H_AVG','O3_24H_AVG','PM10_24H_AVG','PM2_5_24H_AVG','O3_8H','O3_8H_24H','PrimaryPollutant','Quality']
logical L(nCol)
open(11,file='F:\GraduateStudent\Data-Data\sichuanpollution.csv')
open(10,file='F:\GraduateStudent\Data-Data\sichuanpollution1.csv')
!读取表头
read(10,*) str
!判断需要读取的列
L = .false.
do i = 1, nCol
str(i) = adjustl( str(i) )
if( any(trim(str(i))==strHead) ) then
L(i) = .true.
write(11,"(a,',')",advance='no') trim( str(i) ) !输出新表头
end if
end do
write(11,*)
do
read(10,*,iostat=j) str
if(j/=0) exit
do i =1, nCol
if(.NOT.L(i)) cycle
write(11,'(a,",")',advance='no') trim( str(i) )
end do
write(11,*)
end do
end program test
山水 发表于 2017-10-7 11:06
[mw_shl_code=fortran,true]program test
implicit none
integer,parameter::nCol = 36
fcode 发表于 2017-4-10 17:20
少了一个引号,请直接复制粘贴我的代码。
program test
implicit none
integer,parameter::nCol = 949
integer i, j
character(10000) str(nCol)
character(*),parameter:: strHead(9)=['date','hour','type','1142A','1143A','1144A','1145A', '1146A','1147A']
logical L(nCol)
open(10,file='E:\shuju\zhandian\20140513-20141231\china_sites_20141201.csv')
open(11,file='E:\shuju\china_sites_20141201.csv')
!读取表头
read(10,*) str
!判断需要读取的列
L = .false.
do i = 1,nCol
str(i) = adjustl( str(i) )
if( any(trim(str(i))==strHead) ) then
L(i) = .true.
write(11,"(a,',')",advance='no') trim( str(i) ) !输出新表头
end if
end do
write(11,*)
do
read(10,*,iostat=j) str
if(j/=0) exit
do i =1, nCol
if(.NOT.L(i)) cycle
write(11,'(a,",")',advance='no') trim( str(i) )
end do
write(11,*)
end do
end program test
捕获.PNG (20.74 KB, 下载次数: 458)
捕获1.PNG (18.17 KB, 下载次数: 514)
li913 发表于 2017-4-8 18:23
write的问题,去掉最外层括号就好。[mw_shl_code=fortran,true]program test
implicit none
integer,pa ...
Rookie 发表于 2022-4-14 16:50
请问第19和28行的 write语句括号中的 format 部分,所用的单引号、双引号,刚好反过来了。这是什么原因 ...
青衣巷 发表于 2022-4-14 17:10
没关系的,Fortran不区分单双引号。
只要间隔开就行了。
比如你用 " 开头,里面就要用 ',例如 "I ' m fc ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |