2013-10-23 107 views
-2

由於不便,我已經重新提交了代碼。 問題:我試圖編寫一個從二進制(.DAT)文件中讀取降水量的程序。它計算每個網格和每個網格的降水值,最大值月份作爲輸出返回。例如,如果6月份的價值最高,那麼我們的產值應該是「Jun」。Fortran 90:在Fortran中將字符分配給真實類型

implicit none 
integer,parameter :: ix=44,iy=27,nyr=12 
integer :: ntot 
real :: v_obs(ix,iy,nyr),TestVal,b(ix,iy,nyr),wet(ix,iy)  
real:: Mon(12),Y(12),missing_obs,missing_mod,missing 
integer :: ii,jj,i,j,k,ik,jk,irec,m,n 
character (130) dir,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec 
data missing_obs/-999000000/ 
data missing/-999./  
open(21,file='C:/Fortran/test-dat.dat',access='direct',recl=ix*iy*nyr,form='unformatted') 
open(23,file='C:/wet-month.dat',access='direct',recl=ix*iy*nyr,form='unformatted') 
irec=1 
Do j=1,nyr 
read(21,rec=irec) ((v_obs(ii,jj,j),ii=1,ix),jj=1,iy) 
ntot=0 
do ik=1,nyr 
ntot=ntot+1 
Y(ik)=v_obs(ii,jj,ik) 
enddo 
if (Y(ik) .eq. missing_obs)then 
wet=-999 
go to 199 
endif 
enddo 
Mon(1)=v_obs(ii,jj,1) 
Mon(2)=v_obs(ii,jj,2) 
Mon(3)=v_obs(ii,jj,3) 
Mon(4)=v_obs(ii,jj,4) 
Mon(5)=v_obs(ii,jj,5) 
Mon(6)=v_obs(ii,jj,6) 
Mon(7)=v_obs(ii,jj,7) 
Mon(8)=v_obs(ii,jj,8) 
Mon(9)=v_obs(ii,jj,9) 
Mon(10)=v_obs(ii,jj,10) 
Mon(11)=v_obs(ii,jj,11) 
Mon(12)=v_obs(ii,jj,12) 
TestVal=MAXVAL(Mon) 
If (TestVal .eq. Mon(1)) then 
wet=jan 
else if (TestVal .eq. Mon(2)) Then 
wet=feb 
else if (TestVal .eq. Mon(3)) Then 
wet=mar 
else if (TestVal .eq. Mon(4)) Then 
wet=apr 
else if (TestVal .eq. Mon(5)) Then 
wet=may 
else if (TestVal .eq. Mon(6)) Then 
wet=jun 
else if (TestVal .eq. Mon(7)) Then 
wet=jul 
else if (TestVal .eq. Mon(8)) Then 
wet=aug 
else if (TestVal .eq. Mon(9)) Then 
wet=sep 
else if (TestVal .eq. Mon(10)) Then 
wet=oct 
else if (TestVal .eq. Mon(11)) Then 
wet=nov 
else if (TestVal .eq. Mon(12)) Then 
wet=dec 
endif 
199  continue 
irec=1 
do k=1,nyr 
write(23,rec=irec)((wet(ii,jj),ii=1,ix),jj=1,iy) 
irec=irec+1 
enddo 
close(21) 
close(22) 
end 

的compliation錯誤說

You cannot assign an expression of type CHARACTER(LEN=130) to a variable of type REAL(KIND=1)" i.e: "wet=jan". 

但我想保存數據,字符每個網格point.Please幫助解決這個錯誤。

+3

請正確格式化(全部)您的代碼,刪除任何註釋掉的代碼並刪除多餘的空白。就我而言,如果你沒有常識讓我變得容易(或更容易),我甚至不會試圖幫助你。而且,如果您希望我查看代碼中的特定行,例如編譯器發現錯誤的行,請清楚標記該行。你真的期望讀者能夠通過計算行數來找到101行嗎? –

+2

好悲傷它更糟。不要縮進代碼的可理解性嗎? –

+0

感謝您的幫助 – user2904211

回答

3

的問題是所有這些線路wet=janwet=feb

當我從你的代碼讀取wetreal,dimension(44,27)janfeb類型爲character(130)。那些是不相容的(正如編譯器所說)。