Hello all,
I got hundreds of data files, which contains 2-dimensional (in
latitude-longtude) variables, and each file corresponds to a single time. I
want to do some processing on them and finally write them onto a single nc file
which will have three dimensions (i.e., 2 in space and 1 in time). I wrote the
following subroutine (please refer below) in an interface program to accomplish
it. The fortran executable created out of this codes are run in a time-loop
written in ksh. The "RECORD" variable in the subroutine is a stdin from this
ksh script, where it increments by one for each time.
The program runs without spitting any error, but only writes data for the final
time, and nothing for eralier records / times.
Could somebody please point out whats wrong with my code. Any help would be
greatly appreciated.
Thank you for your time.
Regards,
Vinod.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SUBROUTINE WRITE_NC ( RECORD, FILE_NAME, NXPTS, NYPTS, RAW_BG, COR_BG, BT_COR )
IMPLICIT NONE
CHARACTER ( LEN = 22 ), INTENT(IN) :: FILE_NAME
INTEGER, INTENT (IN) :: RECORD, NXPTS, NYPTS
REAL, INTENT(IN), DIMENSION (NXPTS, NYPTS) :: RAW_BG, COR_BG, BT_COR
INTEGER, PARAMETER :: NDIMS = 3
INTEGER :: NCID, LAT_DIMID, LON_DIMID, TIME_DIMID
INTEGER :: RAWBG_VARID, CORBG_VARID, BTCOR_VARID
INTEGER :: START(NDIMS), COUNT(NDIMS), DIMIDS(NDIMS)
CHARACTER (LEN = *), PARAMETER :: UNITS = "UNITS"
CHARACTER (LEN = *), PARAMETER :: RAWBG_UNITS = "KELVIN"
CHARACTER (LEN = *), PARAMETER :: CORBG_UNITS = "KELVIN"
CHARACTER (LEN = *), PARAMETER :: BTCOR_UNITS = "KELVIN"
!-----------------------------------------------------------
! DEFINE THE OUTPUT NETCDF STRUCTURE
!-----------------------------------------------------------
CALL CHECK ( NF90_CREATE ( FILE_NAME, NF90_CLOBBER, NCID ) )
CALL CHECK ( NF90_DEF_DIM ( NCID, "LONGITUDE", NXPTS, LON_DIMID ) )
CALL CHECK ( NF90_DEF_DIM ( NCID, "LATITUDE", NYPTS, LAT_DIMID ) )
CALL CHECK ( NF90_DEF_DIM ( NCID, "TIME", NF90_UNLIMITED, TIME_DIMID ) )
DIMIDS = (/ LON_DIMID, LAT_DIMID, TIME_DIMID /)
CALL CHECK ( NF90_DEF_VAR ( NCID, "RAW_BG", NF90_REAL, DIMIDS, RAWBG_VARID )
)
CALL CHECK ( NF90_DEF_VAR ( NCID, "COR_BG", NF90_REAL, DIMIDS, CORBG_VARID )
)
CALL CHECK ( NF90_DEF_VAR ( NCID, "BT_COR", NF90_REAL, DIMIDS, BTCOR_VARID )
)
CALL CHECK ( NF90_PUT_ATT ( NCID, RAWBG_VARID, UNITS, RAWBG_UNITS ) )
CALL CHECK ( NF90_PUT_ATT ( NCID, CORBG_VARID, UNITS, CORBG_UNITS ) )
CALL CHECK ( NF90_PUT_ATT ( NCID, BTCOR_VARID, UNITS, BTCOR_UNITS ) )
CALL CHECK ( NF90_ENDDEF ( NCID ) )
!-----------------------------------------------------------
! WRITE THE DATA ARRAY
!-----------------------------------------------------------
CALL CHECK ( NF90_PUT_VAR ( NCID, RAWBG_VARID, RAW_BG, START = (/ 1, 1,
RECORD /), &
COUNT = (/ NXPTS, NYPTS,
1 /) ) )
CALL CHECK ( NF90_PUT_VAR ( NCID, CORBG_VARID, COR_BG, START = (/ 1, 1,
RECORD /), &
COUNT = (/ NXPTS, NYPTS,
1 /) ) )
CALL CHECK ( NF90_PUT_VAR ( NCID, CORBG_VARID, COR_BG, START = (/ 1, 1,
RECORD /), &
COUNT = (/ NXPTS, NYPTS,
1 /) ) )
CALL CHECK ( NF90_PUT_VAR ( NCID, BTCOR_VARID, BT_COR, START = (/ 1, 1,
RECORD /), &
COUNT = (/ NXPTS, NYPTS,
1 /) ) )
CALL CHECK ( NF90_CLOSE(NCID) )
END SUBROUTINE WRITE_NC
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!