- 积分
- 10823
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-10-27
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2018-2-27 13:13:41
|
显示全部楼层
还是需要,那我手动粘贴主程序和grid22bin.bat吧
program grib2bin
use date_pack
use IFPORT
implicit none
! Variables
INTEGER, PARAMETER :: NLEVEL=21
character(len=4), dimension(NLEVEL) ,parameter :: levels=(/"1000", "975", "950", "925", "900", "850", "800", "750", "700", "650" &
, "600", "550", "500", "450", "400", "350", "300", "250", "200", "150", "100"/)
REAL, DIMENSION(0:359,-90:90,NLEVEL) :: hgt, tmp, rh, vvel, absv, ugrd, vgrd, td, q, thse
real, dimension(0:359,-90:90) :: ugrd10, vgrd10, tmp2, rh2, spfh2, prmsl
CHARACTER(LEN=80) :: pathIn, pathOut, fileIn, fileOut, filePara, fileName, cmdLine
character(len=80) :: line, subline
character(len=80), dimension(400) :: lines
integer :: pos, m, n, mm, nn, k, i, j, nTime,status
integer, dimension(NLEVEL) :: hgtr, tmpr, rhr, vvelr, absvr, ugrdr, vgrdr
integer :: ugrd10r, vgrd10r, tmp2r, rh2r, spfh2r, prmslr
INTEGER :: lon1, lon2, lat1, lat2
character (len=19) :: sDate, curDate, eDate
INTEGER(4) errnum
lon1=0; lon2=180 !表示从东经0度到180度。
lat1=0; lat2=90 !表示从北纬0度到90度。
! Body of grib2bin
sDate="2013-01-01 00:00:00"
eDate="2013-01-01 18:00:00"
pathIn="I:\FNL2\"
pathOut="I:\grid\"
curDate = sDate
nTime=1
do while(curDate<=eDate)
print *, ntime,curDate
fileName="fnl_"//curDate(1:4)//curDate(6:7)//curDate(9:10)//"_"//curDate(12:13)//"_00"
cmdLine=trim(pathIn)//" "//trim(pathOut)//" "//trim(fileName)
status =RUNQQ("C:\Users\Administrator\grib22bin.bat",cmdLine)
print *, nTime, curDate,trim(fileName)
!Read in the records in filelists
filePara=trim(pathOut)//trim(fileName)//".txt"
open(1, file=filePara, status="old")
pos=0
lines=""
do while( .not. eof(1))
read(1,"(A80)")line
pos=pos+1
lines(pos)=line
end do
close(1)
! get the record no.
do m=1, pos
do n=1, NLEVEL
!HGT postions
subline=":HGT:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
hgtr(n)=m
!print *,"HGT", n, m
end if
!TMP postions
subline=":TMP:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
tmpr(n)=m
!print *, "TMP", n, m
end if
!RH postions
subline=":RH:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
rhr(n)=m
!print *, "RH", n, m
end if
!VVEL postions
subline=":VVEL:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
vvelr(n)=m
!print *, "VVEL", n, m
end if
!ABSV postions
subline=":ABSV:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
absvr(n)=m
!print *, "ABSV", n, m
end if
!UGRD postions
subline=":UGRD:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
ugrdr(n)=m
!print *, "UGRD", n, m
end if
!VGRD postions
subline=":VGRD:"// trim(levels(n)) //" mb:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
vgrdr(n)=m
!print *, "VGRD", n, m
end if
end do
!UGRD 10m postions
subline=":UGRD:10 m above ground:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
ugrd10r=m
!print *, "UGRD10", m
end if
!VGRD 10m postions
subline=":VGRD:10 m above ground:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
vgrd10r=m
!print *, "VGRD10", m
end if
!TMP 2m postions
subline=":TMP:surface:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
tmp2r=m
!print *, "TMP2", m
end if
!RH 2m postions
subline=":RH:2 m above ground:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
rh2r=m
!print *, "RH2", m
end if
!SPFH 2m postions
subline=":SPFH:2 m above ground:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
spfh2r=m
!print *, "SPFH2", m
end if
!PRMSL 2m postions
subline=":PRMSL:mean sea level:"
if ( INDEX(trim(lines(m)),trim(subline)) > 0 ) then
prmslr=m
!print *, "PRMSL", m
end if
end do
!read from
fileIn=trim(pathOut)//trim(fileName)//".bin"
OPEN(1,FILE=fileIn,FORM='binary', ACCESS='direct',RECL=4*360*181)
DO k=1, NLEVEL
READ(1,REC=hgtr(k))((hgt(i,j,k),i=0,359), j=90,-90,-1)
END DO
DO k=1, NLEVEL
READ(1,REC=tmpr(k))((tmp(i,j,k),i=0,359), j=90,-90,-1)
END DO
DO k=1, NLEVEL
READ(1,REC=rhr(k))((rh(i,j,k),i=0,359), j=90,-90,-1)
END DO
DO k=1, NLEVEL
READ(1,REC=vvelr(k))((vvel(i,j,k),i=0,359), j=90,-90,-1)
END DO
DO k=1, NLEVEL
READ(1,REC=absvr(k))((absv(i,j,k),i=0,359), j=90,-90,-1)
END DO
DO k=1, NLEVEL
READ(1,REC=ugrdr(k))((ugrd(i,j,k),i=0,359), j=90,-90,-1)
END DO
DO k=1, NLEVEL
READ(1,REC=vgrdr(k))((vgrd(i,j,k),i=0,359), j=90,-90,-1)
END DO
READ(1,REC=ugrd10r)((ugrd10(i,j),i=0,359), j=90,-90,-1)
READ(1,REC=vgrd10r)((vgrd10(i,j),i=0,359), j=90,-90,-1)
READ(1,REC=tmp2r)((tmp2(i,j),i=0,359), j=90,-90,-1)
READ(1,REC=rh2r)((rh2(i,j),i=0,359), j=90,-90,-1)
READ(1,REC=spfh2r)((spfh2(i,j),i=0,359), j=90,-90,-1)
READ(1,REC=prmslr)((prmsl(i,j),i=0,359), j=90,-90,-1)
close(1)
!write to the grads file
fileOut = trim(pathOut) //fileName(5:12)//fileName(14:15)//".gad"
OPEN(2,FILE=fileOut,FORM='binary')
DO k=1, NLEVEL
WRITE(2)((hgt(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
DO k=1, NLEVEL
WRITE(2)((tmp(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
DO k=1, NLEVEL
WRITE(2)((rh(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
DO k=1, NLEVEL
WRITE(2)((vvel(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
DO k=1, NLEVEL
WRITE(2)((absv(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
DO k=1, NLEVEL
WRITE(2)((ugrd(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
DO k=1, NLEVEL
WRITE(2)((vgrd(i,j,k),i=lon1,lon2), j=lat1,lat2)
END DO
WRITE(2)((ugrd10(i,j),i=lon1,lon2), j=lat1,lat2)
WRITE(2)((vgrd10(i,j),i=lon1,lon2), j=lat1,lat2)
WRITE(2)((tmp2(i,j),i=lon1,lon2), j=lat1,lat2)
WRITE(2)((rh2(i,j),i=lon1,lon2), j=lat1,lat2)
WRITE(2)((spfh2(i,j),i=lon1,lon2), j=lat1,lat2)
WRITE(2)((prmsl(i,j),i=lon1,lon2), j=lat1,lat2)
close(2)
call geth_newdate( curDate, sDate, (nTime) * 6 * 3600)
nTime=nTime+1
end do
pause
end program grib2bin
|
|