@@ -1767,7 +1767,7 @@ int putget_read_vars_nt(int ncid, int *varid, PIO_Offset *start, PIO_Offset *cou
17671767 * @returns 0 for success, error code otherwise.
17681768 */
17691769int create_putget_file (int iosysid , int access , int unlim , int flavor , int * dim_len ,
1770- int * varid , const char * filename , int * ncidp )
1770+ int * varid , const char * filename , int * ncidp , int * tsvarid )
17711771{
17721772 int dimids [NDIM ]; /* The dimension IDs. */
17731773 int num_vars = NUM_CLASSIC_TYPES + 1 ;
@@ -1786,7 +1786,9 @@ int create_putget_file(int iosysid, int access, int unlim, int flavor, int *dim_
17861786 return ret ;
17871787
17881788 /* Are we using unlimited dimension? */
1789- if (!unlim )
1789+ if (unlim )
1790+ dim_len [0 ] = NC_UNLIMITED ;
1791+ else
17901792 dim_len [0 ] = NUM_TIMESTEPS ;
17911793
17921794 /* Define netCDF dimensions and variable. */
@@ -1812,7 +1814,14 @@ int create_putget_file(int iosysid, int access, int unlim, int flavor, int *dim_
18121814 if ((ret = PIOc_def_var (ncid , var_name , my_type , NDIM , dimids , & varid [v ])))
18131815 return ret ;
18141816 }
1815-
1817+ if (unlim ){
1818+ /* create an additional variable with only the unlimdim dimension */
1819+ if ((ret = PIOc_def_var (ncid , "timestep" , PIO_INT , 1 , dimids , tsvarid )))
1820+ {
1821+ printf ("Defined a timestep variable %d\n" , ret );
1822+ return ret ;
1823+ }
1824+ }
18161825 /* For the first access, also test attributes. */
18171826 if (access == 0 )
18181827 if ((ret = test_write_atts (ncid , varid , flavor )))
@@ -1908,7 +1917,8 @@ int test_putget(int iosysid, int num_flavors, int *flavor, int my_rank,
19081917 MPI_Comm test_comm )
19091918{
19101919 int dim_len [NDIM ] = {NC_UNLIMITED , X_DIM_LEN , Y_DIM_LEN };
1911-
1920+ int tsvarid ;
1921+
19121922#define NUM_ACCESS 8
19131923 for (int unlim = 0 ; unlim < 2 ; unlim ++ )
19141924 for (int access = 0 ; access < NUM_ACCESS ; access ++ )
@@ -1931,15 +1941,15 @@ int test_putget(int iosysid, int num_flavors, int *flavor, int my_rank,
19311941
19321942 /* Create test file with dims and vars defined. */
19331943 if ((ret = create_putget_file (iosysid , access , unlim , flavor [fmt ], dim_len , varid ,
1934- filename , & ncid )))
1944+ filename , & ncid , & tsvarid )))
19351945 return ret ;
19361946
19371947 /* Write some data. */
19381948 PIO_Offset index [NDIM ] = {0 , 0 , 0 };
19391949 PIO_Offset start [NDIM ] = {0 , 0 , 0 };
19401950 PIO_Offset count [NDIM ] = {1 , X_DIM_LEN , Y_DIM_LEN };
19411951 PIO_Offset stride [NDIM ] = {1 , 1 , 1 };
1942-
1952+ PIO_Offset index1d = 0 ;
19431953 switch (access )
19441954 {
19451955 case 0 :
@@ -2003,7 +2013,21 @@ int test_putget(int iosysid, int num_flavors, int *flavor, int my_rank,
20032013 /* Check contents of the file. */
20042014 if ((ret = check_file (access , ncid , varid , flavor [fmt ], index , start , count , stride , unlim )))
20052015 return ret ;
2006-
2016+ if (unlim > 0 ) {
2017+ /* try advancing the file */
2018+ index1d = 0 ;
2019+ if ((ret = PIOc_put_var1_int (ncid , tsvarid , & index1d , dim_len )))
2020+ {
2021+ printf ("extend file time test %d\n" ,ret );
2022+ return ret ;
2023+ }
2024+ index1d = 1 ;
2025+ if ((ret = PIOc_put_var1_int (ncid , tsvarid , & index1d , dim_len + 1 )))
2026+ {
2027+ printf ("extend file time test %d\n" ,ret );
2028+ return ret ;
2029+ }
2030+ }
20072031 /* Close the netCDF file. */
20082032 if ((ret = PIOc_closefile (ncid )))
20092033 ERR (ret );
0 commit comments