- 积分
- 17505
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-6-7
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2015-11-21 19:58:07
|
显示全部楼层
本帖最后由 洗雨 于 2015-11-21 20:35 编辑
! read ibtracs data--basin style IBtracs数据的csv格式读取
character*200:: path
character*200:: filename
character*3000 :: fline
integer :: L,Nv
integer:: i,j,iv
character*30,allocatable :: fvar(:)
integer :: NUM
path='J:\sst\IBTracks\csv\'
filename=TRIM(path)//'Basin.NI.ibtracs_all.v03r07.csv'
! + open file
open(unit=11,file=TRIM(fname),status='old')
! + open over
! + read head information
read(11,*)
read(11,'(A3000)')fline
read(11,*)
! + read variations
L=LEN_TRIM(fline)
Nv=1
do i=1,L
if ( fline(i:i).eq.',' ) Nv=Nv+1
enddo
!write(*,*)'Nv=',Nv
allocate(fvar(Nv))
call cal_sub(fline,Nv,fvar)
deallocate(fvar)
! + read data
NUM=0 !TC number
data(seq(i,1),i=1,5) / 65, 66, 67, 68, 69/ ! - jtwc_wp
data(seq(i,2),i=1,5) /120,121,122,123,124/ ! - hko
data(seq(i,3),i=1,5) /110,111,112,113,114/ ! - tokyo
data(seq(i,4),i=1,5) / 85, 86, 87, 88, 89/ ! - cma
!
! + SUBROUTINES
!
subroutine cal_sub(fline,Nv,fvar)
implicit none
character*3000 :: fline
integer :: Nv
character*30 :: fvar(Nv)
integer :: i,j,iv,L
L=LEN_TRIM(fline)
iv=1
j=1
do i=1,L
if ( fline(i:i).eq.',' ) then
fvar(iv)=fline(j:i-1)
iv=iv+1
j=i+1
endif
enddo
if ( iv.ne.Nv ) write(*,*) 'ERROR'
fvar(iv)=fline(j:L)
return
end
subroutine read_ibtracs(fname,year,NUM,NREC,TCNAME,DAT,INF)
implicit none
character*300 :: fname
integer :: year
logical :: flag
character*3000 :: fline
integer :: L,Nv
integer :: i,j,iv
character*30,allocatable :: fvar(:)
integer :: yr,id,id0
character*30 :: name
integer :: dat0(4)
real :: inf0(5,4)
integer :: seq(5,4)
integer,parameter :: TCMax=100,RECMax=300
integer :: NUM
integer :: NREC(TCMax)
character*30 :: TCNAME(TCMax)
integer :: DAT(4,RECMax,TCMax)
real :: INF(5,RECMax,TCMax,4)
! + FILE
inquire(file=TRIM(fname),exist=flag)
if ( .not.flag ) then
write(*,*) TRIM(fname),' does not exist!'
STOP
endif
! + READ HEAD INFORMATION
open(unit=31,file=TRIM(fname),status='old',action='read')
read(31,*)
read(31,'(A3000)') fline
read(31,*)
! + VARIABLES
L=LEN_TRIM(fline)
Nv=1
do i=1,L
if ( fline(i:i).eq.',' ) Nv=Nv+1
enddo
!write(*,*) 'Nv= ',Nv
allocate(fvar(Nv))
!iv=1
!j=1
!do i=1,L
! if ( fline(i:i).eq.',' ) then
! fvar(iv)=fline(j:i-1)
! iv=iv+1
! j=i+1
! endif
!enddo
!if ( iv.ne.Nv ) write(*,*) 'ERROR'
!fvar(iv)=fline(j:L)
call cal_sub(fline,Nv,fvar)
!open(unit=41,file='var_list.txt',status='unknown',action='write')
!do iv=1,Nv
! L=LEN_TRIM(fvar(iv))
! write(41,'(I3.3,3X,A<L>)') iv,TRIM(fvar(iv))
!enddo
!close(41)
deallocate(fvar)
! + READ DATA
NUM=0
id0=0
data(seq(i,1),i=1,5) / 65, 66, 67, 68, 69/ ! - jtwc_wp
data(seq(i,2),i=1,5) /120,121,122,123,124/ ! - hko
data(seq(i,3),i=1,5) /110,111,112,113,114/ ! - tokyo
data(seq(i,4),i=1,5) / 85, 86, 87, 88, 89/ ! - cma
do while ( .not.EOF(31) )
read(31,'(A3000)') fline
allocate(fvar(Nv))
call cal_sub(fline,Nv,fvar)
read(fvar(2),*) yr ! - Season
read(fvar(3),*) id ! - Num
name=fvar(6) ! - Name
L=LEN_TRIM(fvar(7)) ! - ISO_time
if ( L.ne.19 ) write(*,*) 'ERROR ISO-TIME'
read(fvar(7)(1:L),'(I4,1X,I2,1X,I2,1X,I2,6X)') (dat0(i),i=1,4)
do j=1,4
do i=1,5
read(fvar(seq(i,j)),*) inf0(i,j) ! - lat, lon, grade, wind, pres
enddo
enddo
if ( yr.eq.year ) then
if ( id.ne.id0 ) then
NUM=NUM+1
id0=id
NREC(NUM)=0
TCNAME(NUM)=name
endif
if ( MOD(dat0(4),6).eq.0 ) then
NREC(NUM)=NREC(NUM)+1
do i=1,4
DAT(i,NREC(NUM),NUM)=dat0(i)
enddo
do j=1,4
do i=1,5
INF(i,NREC(NUM),NUM,j)=inf0(i,j)
enddo
enddo
endif
endif
deallocate(fvar)
enddo
close(31)
return
end
!
! + SUBROUTINES
!
subroutine cal_sub(fline,Nv,fvar)
implicit none
character*3000 :: fline
integer :: Nv
character*30 :: fvar(Nv)
integer :: i,j,iv,L
L=LEN_TRIM(fline)
iv=1
j=1
do i=1,L
if ( fline(i:i).eq.',' ) then
fvar(iv)=fline(j:i-1)
iv=iv+1
j=i+1
endif
enddo
if ( iv.ne.Nv ) write(*,*) 'ERROR'
fvar(iv)=fline(j:L)
return
end
|
|