登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 银魈 于 2018-5-13 22:04 编辑
短期气候的上机实习,只有中间 “处理数据 从hh到h的转换,再从h到f的转换”是我自己写的,但是总显示有如图错误,问老师也没查出来哪儿错了,求大佬指点!NCEP/NCAR 1948-2008年1月的500 hPa月平均高度场资料,资料范围为(900S-900N,00-3600E),网格距为2.50×2.50,纬向格点数为144,经向格点数为73。资料为GRD格式,资料从南到北、自西向东排列,每月为一个记录,按年逐月排放 PROGRAM EOF
PARAMETER(M=61,N=41*21,MNH=61,KS=1,KV=8,KVT=8,pi=3.1415926)
DIMENSION F(N,M),A(MNH,MNH),S(MNH,MNH),ER(MNH,4),DF(N),V(MNH),AVF(N),EGVT(N,KVT),ECOF(M,KVT)
dimension hh(144,73,12,61),h(41,21,61)
open(10,file='d:\copy2\hgt500.grd',form='binary') !改变数据路径
open(20,file='d:\copy2\egvt.grd',form='binary') !改变数据路径
open(30,file='d:\copy2\t.grd',form='binary') !改变数据路径
open(16,file='d:\copy2\eof.txt') !改变数据路径
do it=1,61
do k=1,12
do j=1,73
do i=1,144
read(10)hh(i,j,k,it)
enddo;enddo;enddo;enddo
write(*,*)'read data ok'
!______________处理数据 从hh到h的转换,再从h到f的转换_____________
do it=1,61
do j=1,21
do i=1,41
h(i,j,it)=hh(i+16,j+44,1,it)
enddo
enddo
enddo
k=1
do i=1,41
do j=1,21
do it=1,61
f(k,it)=h(i,j,it)
enddo
k=k+1
enddo
enddo
!_____________________________________________
CALL TRANSF(N,M,F,AVF,DF,KS)
write(*,*)'ok program 1'
CALL FORMA(N,M,MNH,F,A)
write(*,*)'ok program 2'
CALL JCB(MNH,A,S,0.00001)
write(*,*)'ok program 3'
CALL ARRANG(KV,MNH,A,ER,S)
write(*,*)'ok program 4'
CALL TCOEFF(KVT,KV,N,M,MNH,S,F,V,ER)
write(*,*)'ok program 5'
CALL OUTER(KV,ER,MNH)
write(*,*)'ok program 6'
CALL OUTVT(KVT,N,M,MNH,S,F,EGVT,ECOF)
write(*,*)'ok program 7'
do j=1,m
do i=1,kvt
write(30)ecof(j,i)
enddo;enddo
do it=1,kvt
do j=1,n
write(20)egvt(j,it)
enddo;enddo
write(*,*)'ok 8'
END
SUBROUTINE TRANSF(N,M,F,AVF,DF,KS)
DIMENSION F(N,M),AVF(N),DF(N)
DO 5 I=1,N
AVF(I)=0.0
5 DF(I)=0.0
IF(KS) 30,10,10
10 DO 14 I=1,N
DO 12 J=1,M
12 AVF(I)=AVF(I)+F(I,J)
AVF(I)=AVF(I)/M
DO 14 J=1,M
F(I,J)=F(I,J)-AVF(I)
14 CONTINUE
IF(KS.EQ.0) THEN
RETURN
ELSE
DO 24 I=1,N
DO 22 J=1,M
22 DF(I)=DF(I)+F(I,J)*F(I,J)
DF(I)=SQRT(DF(I)/M)
DO 24 J=1,M
F(I,J)=F(I,J)/DF(I)
24 CONTINUE
ENDIF
30 CONTINUE
RETURN
END
SUBROUTINE FORMA(N,M,MNH,F,A)
DIMENSION F(N,M),A(MNH,MNH)
IF(M-N) 40,50,50
40 DO 44 I=1,MNH
DO 44 J=I,MNH
A(I,J)=0.0
DO 42 IS=1,N
42 A(I,J)=A(I,J)+F(IS,I)*F(IS,J)
A(J,I)=A(I,J)
44 CONTINUE
RETURN
50 DO 54 I=1,MNH
DO 54 J=I,MNH
A(I,J)=0.0
DO 52 JS=1,M
52 A(I,J)=A(I,J)+F(I,JS)*F(J,JS)
A(J,I)=A(I,J)
54 CONTINUE
RETURN
END
SUBROUTINE JCB(N,A,S,EPS)
DIMENSION A(N,N),S(N,N)
DO 30 I=1,N
DO 30 J=1,I
IF(I-J) 20,10,20
10 S(I,J)=1.
GO TO 30
20 S(I,J)=0.
S(J,I)=0.
30 CONTINUE
G=0.
DO 40 I=2,N
I1=I-1
DO 40 J=1,I1
40 G=G+2.*A(I,J)*A(I,J)
S1=SQRT(G)
S2=EPS/FLOAT(N)*S1
S3=S1
L=0
50 S3=S3/FLOAT(N)
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ER(I,3)=ER(I,1)/TR
ER(I,4)=ER(I,2)/TR
230 CONTINUE
WRITE(*,250) TR
250 FORMAT(/5X,'TOTAL SQUARE ERROR=',F20.5)
RETURN
END
SUBROUTINE TCOEFF(KVT,KV,N,M,MNH,S,F,V,ER)
DIMENSION S(MNH,MNH),F(N,M),V(MNH),ER(MNH,4)
IF(N.LE.M) THEN
DO 390 J=1,M
DO 370 I=1,N
V(I)=F(I,J)
F(I,J)=0.
370 CONTINUE
DO 380 IS=1,KVT
DO 380 I=1,N
380 F(IS,J)=F(IS,J)+V(I)*S(I,IS)
390 CONTINUE
ELSE
DO 410 I=1,N
DO 400 J=1,M
V(J)=F(I,J)
F(I,J)=0.
400 CONTINUE
DO 410 JS=1,KVT
DO 410 J=1,M
F(I,JS)=F(I,JS)+V(J)*S(J,JS)
410 CONTINUE
DO 430 JS=1,KVT
DO 420 J=1,M
S(J,JS)=S(J,JS)*SQRT(ER(JS,1))
420 CONTINUE
DO 430 I=1,N
F(I,JS)=F(I,JS)/SQRT(ER(JS,1))
430 CONTINUE
ENDIF
RETURN
END
SUBROUTINE OUTER(KV,ER,MNH)
DIMENSION ER(MNH,4)
WRITE(16,510)
510 FORMAT(/10X,'EIGENVALUE AND ANALYSIS ERROR')
WRITE(16,520)
520 FORMAT(10X,1HH,8X,5HLAMDA,10X,6HSLAMDA,11X,2HPH,12X,3HSPH)
WRITE(16,530) (IS,(ER(IS,J),J=1,4),IS=1,KV)
530 FORMAT(1X,I10,4F15.5)
WRITE(16,540)
540 FORMAT(//)
RETURN
END
SUBROUTINE OUTVT(KVT,N,M,MNH,S,F,EGVT,ECOF)
DIMENSION F(N,M),S(MNH,MNH),EGVT(N,KVT),ECOF(M,KVT)
WRITE(16,560)
560 FORMAT(10X,'STANDARD EIGENVECTORS')
WRITE(16,570) (IS,IS=1,KVT)
570 FORMAT(3X,10i7)
DO 550 I=1,N
IF(M.GE.N) THEN
WRITE(16,580) I,(S(I,JS),JS=1,KVT)
580 FORMAT(1X,I3,10F7.3,/)
DO 11 JS=1,KVT
EGVT(I,JS)=S(I,JS)
11 CONTINUE
ELSE
WRITE(16,590) I,(F(I,JS),JS=1,KVT)
590 FORMAT(1X,I5,10F7.3)
DO 12 JS=1,KVT
EGVT(I,JS)=F(I,JS)
12 CONTINUE
ENDIF
550 CONTINUE
WRITE(16,590) I,(F(I,JS),JS=1,KVT)
WRITE(20)((F(I,JS),i=1,n),JS=1,KVT)
WRITE(16,720)
720 FORMAT(//)
WRITE(16,610)
610 FORMAT(10X,'TIME-COEFFICENT SERIES OF S. E.')
WRITE(16,620) (IS,IS=1,KVT)
620 FORMAT(3X,5i12)
DO 600 J=1,M
IF(M.GE.N) THEN
WRITE(16,630) J,(f(is,j),is=1,kvt)
630 FORMAT(1X,I3,5F12.3)
DO 13 IS=1,KVT
ECOF(J,IS)=F(IS,J)
13 CONTINUE
ELSE
WRITE(16,640) J,(S(J,IS),IS=1,KVT)
640 FORMAT(1X,I3,10F12.3)
DO 14 IS=1,KVT
ECOF(J,IS)=S(J,IS)
14 CONTINUE
ENDIF
600 CONTINUE
WRITE(30)((S(J,IS),j=1,m),IS=1,KVT)
RETURN
END
|