Thardy
Technical User
- Oct 29, 2011
- 13
Dear all,
I am trying to read and write data from a lookup table(binary file LUT) based on geographical coordinates from binary files "LON"(longitude) and "LAT"(latitude). The program is running but does not provide real values after the firt reading(0.013231), i.e. the remaining values are 0.00...
I think from line 36 ("get LUT data") of the program below, the reading is problematic. Also in the line "if(ABS(latit(x,y)-(knt-1)*DIF_LATG+90.0", I can not use "latit" in replacement of "latit(x,y)" as there would be a compiler error asking for a scaler.
I am surely missing something. Any help will be appreciated:
program LUT
implicit none
integer*4:: lat, lon,x,y
INTEGER, PARAMETER :: NBYTE_G=4 !byte of albedo data
INTEGER, PARAMETER :: NLONG_G=2880, NLAT_G=1441 !size of albed data
REAL, PARAMETER :: DIF_LONGG=0.125, DIF_LATG=0.125 !size of each pixel of albedo data
REAL*4 :: gal
REAL(KIND=NBYTE_G), ALLOCATABLE :: galraw,
REAL(KIND=4)::latit(1236,1656),longit(1236,1656)
REAL(KIND=4)::longdi(1236,1656)
INTEGER :: iost, knt, knt2
INTEGER :: ilat, ilong
INTEGER :: inlon, inlat
integer, parameter ::irec1=1236*1656*4
C-------
open(10,FILE='LON',FORM='UNFORMATTED',
& ACCESS='DIRECT',RECL=irec1)
read(10, rec=1) longit
open(20,FILE='LAT',FORM='UNFORMATTED',
& ACCESS='DIRECT',RECL=irec1)
read(20, rec=1) latit
allocate(galraw(NLAT_G, NLONG_G))
open(30,FILE='LUT',FORM='UNFORMATTED',STATUS='OLD'
& ,ACCESS='DIRECT',ACTION='READ',RECL=NLONG_G*4)
do knt=1, NLAT_G
read(30,REC=knt) (galraw(knt,knt2)
& , knt2=1, NLONG_G)
C---------open output files
open(40,FILE='out1',FORM='UNFORMATTED',STATUS='UNKNOWN'
& ,ACCESS='DIRECT',ACTION='WRITE',RECL=irec1)
open(50,FILE='out2',FORM='FORMATTED')
C----------- get LUT data
if(ABS(latit(x,y)-(knt-1)*DIF_LATG+90.0)
& .le. DIF_LATG*0.5) then
ilat=knt
exit
endif
enddo
do knt=1, NLONG_G
longdi(x,y)=(knt-1)*DIF_LONGG
if(longit(x,y) .gt. 0) then
if(longdi(x,y) .gt. 180.0) then
longdi(x,y)=longdi(x,y)-360.0
endif
else if(longit(x,y) .lt. 0.0) then
if(longdi(x,y) .ge. 180.0) then
longdi(x,y)=longdi(x,y)-360.0
endif
endif
if(ABS(longit(x,y)-longdi(x,y)) .le. DIF_LATG*0.5) then
ilong=knt
exit
endif
end do
gal=galraw(ilat, ilong)
write(40,rec=1) gal
write(50,'(1236F12.6)') gal
deallocate(galraw)
stop
End program LUT
I am trying to read and write data from a lookup table(binary file LUT) based on geographical coordinates from binary files "LON"(longitude) and "LAT"(latitude). The program is running but does not provide real values after the firt reading(0.013231), i.e. the remaining values are 0.00...
I think from line 36 ("get LUT data") of the program below, the reading is problematic. Also in the line "if(ABS(latit(x,y)-(knt-1)*DIF_LATG+90.0", I can not use "latit" in replacement of "latit(x,y)" as there would be a compiler error asking for a scaler.
I am surely missing something. Any help will be appreciated:
program LUT
implicit none
integer*4:: lat, lon,x,y
INTEGER, PARAMETER :: NBYTE_G=4 !byte of albedo data
INTEGER, PARAMETER :: NLONG_G=2880, NLAT_G=1441 !size of albed data
REAL, PARAMETER :: DIF_LONGG=0.125, DIF_LATG=0.125 !size of each pixel of albedo data
REAL*4 :: gal
REAL(KIND=NBYTE_G), ALLOCATABLE :: galraw,
REAL(KIND=4)::latit(1236,1656),longit(1236,1656)
REAL(KIND=4)::longdi(1236,1656)
INTEGER :: iost, knt, knt2
INTEGER :: ilat, ilong
INTEGER :: inlon, inlat
integer, parameter ::irec1=1236*1656*4
C-------
open(10,FILE='LON',FORM='UNFORMATTED',
& ACCESS='DIRECT',RECL=irec1)
read(10, rec=1) longit
open(20,FILE='LAT',FORM='UNFORMATTED',
& ACCESS='DIRECT',RECL=irec1)
read(20, rec=1) latit
allocate(galraw(NLAT_G, NLONG_G))
open(30,FILE='LUT',FORM='UNFORMATTED',STATUS='OLD'
& ,ACCESS='DIRECT',ACTION='READ',RECL=NLONG_G*4)
do knt=1, NLAT_G
read(30,REC=knt) (galraw(knt,knt2)
& , knt2=1, NLONG_G)
C---------open output files
open(40,FILE='out1',FORM='UNFORMATTED',STATUS='UNKNOWN'
& ,ACCESS='DIRECT',ACTION='WRITE',RECL=irec1)
open(50,FILE='out2',FORM='FORMATTED')
C----------- get LUT data
if(ABS(latit(x,y)-(knt-1)*DIF_LATG+90.0)
& .le. DIF_LATG*0.5) then
ilat=knt
exit
endif
enddo
do knt=1, NLONG_G
longdi(x,y)=(knt-1)*DIF_LONGG
if(longit(x,y) .gt. 0) then
if(longdi(x,y) .gt. 180.0) then
longdi(x,y)=longdi(x,y)-360.0
endif
else if(longit(x,y) .lt. 0.0) then
if(longdi(x,y) .ge. 180.0) then
longdi(x,y)=longdi(x,y)-360.0
endif
endif
if(ABS(longit(x,y)-longdi(x,y)) .le. DIF_LATG*0.5) then
ilong=knt
exit
endif
end do
gal=galraw(ilat, ilong)
write(40,rec=1) gal
write(50,'(1236F12.6)') gal
deallocate(galraw)
stop
End program LUT