You call:
> CALL CHECK ( NF90_CREATE ( FILE_NAME, NF90_CLOBBER, NCID ) )
each time the subroutine is called, not just the first time. Therefore the
file gets recreated each iteration, so only the final time will have data.
-Roy
On Feb 24, 2013, at 6:47 PM, Vinod Kumar <V.Kumar2@xxxxxxxxxx> wrote:
> 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
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit:
> http://www.unidata.ucar.edu/mailing_lists/
**********************
"The contents of this message do not reflect any position of the U.S.
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097
e-mail: Roy.Mendelssohn@xxxxxxxx (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/
"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.