@@ -28,7 +28,7 @@ int NetCDFAddMetadata (const int fileid,const int time_dimid,
2828int NetCDFAddMetadata2D (const int fileid,const int time_dimid,int nbasins_dimid,string shortname,string longname,string units);
2929void WriteNetCDFGlobalAttributes (const int out_ncid,const optStruct &Options,const string descript);
3030void AddSingleValueToNetCDF (const int out_ncid,const string &label,const size_t time_index,const double &value);
31- void WriteNetCDFBasinList (const int ncid,const int varid,const CModel* pModel,bool is_res,const optStruct &Options);
31+ void WriteNetCDFBasinList (const int ncid,const int varid,const int varid_name, const CModel* pModel,bool is_res,const optStruct &Options);
3232// ////////////////////////////////////////////////////////////////
3333// / \brief returns true if specified observation time series is the flow series for subbasin SBID
3434// / \param pObs [in] observation time series
@@ -1935,7 +1935,8 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
19351935 int dimids1[ndims1]; // array which will contain all dimension ids for a variable
19361936 int ncid, varid_pre; // When we create netCDF variables and dimensions, we get back an ID for each one.
19371937 int time_dimid, varid_time; // dimension ID (holds number of time steps) and variable ID (holds time values) for time
1938- int nSim, nbasins_dimid, varid_bsim; // # of sub-basins with simulated outflow, dimension ID, and
1938+ int nSim, nbasins_dimid, varid_bsim,varid_bsim2;
1939+ // // # of sub-basins with simulated outflow, dimension ID, and
19391940 // // variable to write basin IDs for simulated outflows
19401941 int varid_qsim; // variable ID for simulated outflows
19411942 int varid_qobs; // variable ID for observed outflows
@@ -2010,12 +2011,22 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
20102011 // (c) create variable and set attributes for"basin_name"
20112012 dimids1[0 ] = nbasins_dimid;
20122013 retval = nc_def_var (_HYDRO_ncid, " basin_name" , NC_STRING, ndims1, dimids1, &varid_bsim); HandleNetCDFErrors (retval);
2013- tmp =" Name/ ID of sub-basins with simulated outflows" ;
2014+ tmp =" ID of sub-basins with simulated outflows" ;
20142015 tmp2=" timeseries_id" ;
20152016 tmp3=" 1" ;
20162017 retval = nc_put_att_text (_HYDRO_ncid, varid_bsim, " long_name" , tmp.length (), tmp.c_str ()); HandleNetCDFErrors (retval);
20172018 retval = nc_put_att_text (_HYDRO_ncid, varid_bsim, " cf_role" , tmp2.length (),tmp2.c_str ()); HandleNetCDFErrors (retval);
20182019 retval = nc_put_att_text (_HYDRO_ncid, varid_bsim, " units" , tmp3.length (),tmp3.c_str ()); HandleNetCDFErrors (retval);
2020+
2021+ // (d) create variable and set attributes for"basin_fullname"
2022+ dimids1[0 ] = nbasins_dimid;
2023+ retval = nc_def_var (_HYDRO_ncid, " basin_fullname" , NC_STRING, ndims1, dimids1, &varid_bsim2); HandleNetCDFErrors (retval);
2024+ tmp =" Name of sub-basins with simulated outflows" ;
2025+ tmp2=" timeseries_id" ;
2026+ tmp3=" 1" ;
2027+ retval = nc_put_att_text (_HYDRO_ncid, varid_bsim2, " long_name" , tmp.length (), tmp.c_str ()); HandleNetCDFErrors (retval);
2028+ retval = nc_put_att_text (_HYDRO_ncid, varid_bsim2, " cf_role" , tmp2.length (),tmp2.c_str ()); HandleNetCDFErrors (retval);
2029+ retval = nc_put_att_text (_HYDRO_ncid, varid_bsim2, " units" , tmp3.length (),tmp3.c_str ()); HandleNetCDFErrors (retval);
20192030
20202031 varid_qsim= NetCDFAddMetadata2D (_HYDRO_ncid, time_dimid,nbasins_dimid," q_sim" ," Simulated outflows" ," m**3 s**-1" );
20212032 varid_qobs= NetCDFAddMetadata2D (_HYDRO_ncid, time_dimid,nbasins_dimid," q_obs" ," Observed outflows" ," m**3 s**-1" );
@@ -2033,7 +2044,7 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
20332044
20342045 // (a) write gauged basin names/IDs to variable "basin_name"
20352046 if (nSim>0 ){
2036- WriteNetCDFBasinList (_HYDRO_ncid,varid_bsim,this ,false ,Options);
2047+ WriteNetCDFBasinList (_HYDRO_ncid,varid_bsim,varid_bsim2, this ,false ,Options);
20372048 }
20382049
20392050 // ====================================================================
@@ -2084,13 +2095,24 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
20842095 // (c) create variable and set attributes for"basin_name"
20852096 dimids1[0 ] = nbasins_dimid;
20862097 retval = nc_def_var (_RESSTAGE_ncid," basin_name" ,NC_STRING,ndims1,dimids1,&varid_bsim); HandleNetCDFErrors (retval);
2087- tmp =" Name/ ID of sub-basins with simulated outflows " ;
2098+ tmp =" subbasin ID of reservoirs with simulated stage " ;
20882099 tmp2=" timeseries_id" ;
20892100 tmp3=" 1" ;
20902101 retval = nc_put_att_text (_RESSTAGE_ncid,varid_bsim," long_name" , tmp.length (), tmp.c_str ()); HandleNetCDFErrors (retval);
20912102 retval = nc_put_att_text (_RESSTAGE_ncid,varid_bsim," cf_role" , tmp2.length (),tmp2.c_str ()); HandleNetCDFErrors (retval);
20922103 retval = nc_put_att_text (_RESSTAGE_ncid,varid_bsim," units" , tmp3.length (),tmp3.c_str ()); HandleNetCDFErrors (retval);
20932104
2105+ // (d) create variable and set attributes for"basin_fullname"
2106+ dimids1[0 ] = nbasins_dimid;
2107+ retval = nc_def_var (_RESSTAGE_ncid, " basin_fullname" , NC_STRING, ndims1, dimids1, &varid_bsim2); HandleNetCDFErrors (retval);
2108+ tmp =" subbasin name of reservoirs with simulated stage" ;
2109+ tmp2=" timeseries_id" ;
2110+ tmp3=" 1" ;
2111+ retval = nc_put_att_text (_RESSTAGE_ncid, varid_bsim2, " long_name" , tmp.length (), tmp.c_str ()); HandleNetCDFErrors (retval);
2112+ retval = nc_put_att_text (_RESSTAGE_ncid, varid_bsim2, " cf_role" , tmp2.length (),tmp2.c_str ()); HandleNetCDFErrors (retval);
2113+ retval = nc_put_att_text (_RESSTAGE_ncid, varid_bsim2, " units" , tmp3.length (),tmp3.c_str ()); HandleNetCDFErrors (retval);
2114+
2115+
20942116 varid_qsim= NetCDFAddMetadata2D (_RESSTAGE_ncid,time_dimid,nbasins_dimid," h_sim" ," Simulated stage" ," m" );
20952117 varid_qobs= NetCDFAddMetadata2D (_RESSTAGE_ncid,time_dimid,nbasins_dimid," h_obs" ," Observed stage" ," m" );
20962118
@@ -2102,7 +2124,7 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
21022124 // write values to NetCDF
21032125 // (a) write gauged reservoir basin names/IDs to variable "basin_name"
21042126 if (nSim>0 ){
2105- WriteNetCDFBasinList (_RESSTAGE_ncid,varid_bsim,this ,true ,Options);
2127+ WriteNetCDFBasinList (_RESSTAGE_ncid,varid_bsim,varid_bsim2, this ,true ,Options);
21062128 }
21072129 }
21082130
@@ -2246,13 +2268,23 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
22462268 // (c) create variable and set attributes for"basin_name"
22472269 dimids1[0 ] = nbasins_dimid;
22482270 retval = nc_def_var (_RESMB_ncid," basin_name" ,NC_STRING,ndims1,dimids1,&varid_bsim); HandleNetCDFErrors (retval);
2249- tmp =" Name/ ID of sub-basins with simulated outflows " ;
2271+ tmp =" subbasin ID of reservoirs with simulated stage " ;
22502272 tmp2=" timeseries_id" ;
22512273 tmp3=" 1" ;
22522274 retval = nc_put_att_text (_RESMB_ncid,varid_bsim," long_name" , tmp.length (), tmp.c_str ()); HandleNetCDFErrors (retval);
22532275 retval = nc_put_att_text (_RESMB_ncid,varid_bsim," cf_role" , tmp2.length (),tmp2.c_str ()); HandleNetCDFErrors (retval);
22542276 retval = nc_put_att_text (_RESMB_ncid,varid_bsim," units" , tmp3.length (),tmp3.c_str ()); HandleNetCDFErrors (retval);
22552277
2278+ // (d) create variable and set attributes for"basin_fullname"
2279+ dimids1[0 ] = nbasins_dimid;
2280+ retval = nc_def_var (_RESMB_ncid, " basin_fullname" , NC_STRING, ndims1, dimids1, &varid_bsim2); HandleNetCDFErrors (retval);
2281+ tmp =" subbasin name of reservoirs with simulated stage" ;
2282+ tmp2=" timeseries_id" ;
2283+ tmp3=" 1" ;
2284+ retval = nc_put_att_text (_RESMB_ncid, varid_bsim2, " long_name" , tmp.length (), tmp.c_str ()); HandleNetCDFErrors (retval);
2285+ retval = nc_put_att_text (_RESMB_ncid, varid_bsim2, " cf_role" , tmp2.length (),tmp2.c_str ()); HandleNetCDFErrors (retval);
2286+ retval = nc_put_att_text (_RESMB_ncid, varid_bsim2, " units" , tmp3.length (),tmp3.c_str ()); HandleNetCDFErrors (retval);
2287+
22562288 varid= NetCDFAddMetadata2D (_RESMB_ncid,time_dimid,nbasins_dimid," stage" , " stage" , " m" );
22572289 varid= NetCDFAddMetadata2D (_RESMB_ncid,time_dimid,nbasins_dimid," area" , " area" , " m2" );
22582290 varid= NetCDFAddMetadata2D (_RESMB_ncid,time_dimid,nbasins_dimid," inflow" , " inflow" , " m3" );
@@ -2275,7 +2307,7 @@ void CModel::WriteNetcdfStandardHeaders(const optStruct &Options)
22752307 // write values to NetCDF
22762308 // (a) write gauged reservoir basin names/IDs to variable "basin_name"
22772309 if (nSim>0 ){
2278- WriteNetCDFBasinList (_RESMB_ncid,varid_bsim,this ,true ,Options);
2310+ WriteNetCDFBasinList (_RESMB_ncid,varid_bsim,varid_bsim2, this ,true ,Options);
22792311 }
22802312 }
22812313#endif // end compilation if NetCDF library is available
@@ -3011,27 +3043,30 @@ void AddSingleValueToNetCDF(const int out_ncid,const string &shortname,const siz
30113043// / \brief writes list of Basin IDs to NetCDF file
30123044// / used for hydrographs.nc, reservoirstages.nc, pollutographs.nc
30133045// / \param ncid [in] NetCDF file identifier
3014- // / \param varid [in] ID of existing basin attribute
3046+ // / \param varid [in] netCDF ID of existing basin ID attribute
3047+ // / \param varid_name [in] netCDF ID of existing basin name attribute
30153048// / \param is_res [in] true if this is a reservoir file and only reservoir basins should be included
30163049//
3017- void WriteNetCDFBasinList (const int ncid,const int varid,const CModel* pModel,bool is_res,const optStruct& Options)
3050+ void WriteNetCDFBasinList (const int ncid,const int varid,const int varid_name, const CModel* pModel,bool is_res,const optStruct& Options)
30183051{
30193052#ifdef _RVNETCDF_
30203053 int ibasin = 0 ;
30213054 int retval;
30223055 size_t start[1 ],count[1 ]; // determines where and how much will be written to NetCDF
3023- char * current_basin_name[1 ]; // current name of basin
3056+ char * current_basin_name[1 ]; // current name or ID of basin
30243057 current_basin_name[0 ]=new char [200 ];
30253058 for (int p=0 ;p<pModel->GetNumSubBasins ();p++) {
30263059 if (pModel->GetSubBasin (p)->IsGauged () && (pModel->GetSubBasin (p)->IsEnabled ())) {
30273060 if (!( (is_res) && (pModel->GetSubBasin (p)->GetReservoir ()==NULL ))){
3028- string bname;
3029- if ((pModel-> GetSubBasin (p)-> GetName ()== " " ) || (Options. deltaresFEWS )) { bname = to_string (pModel->GetSubBasin (p)->GetID ()); }
3030- else { bname = pModel->GetSubBasin (p)->GetName (); }
3061+ string bID, bname;
3062+ bID = to_string (pModel->GetSubBasin (p)->GetID ());
3063+ bname = pModel->GetSubBasin (p)->GetName ();
30313064 start[0 ] = ibasin;
30323065 count[0 ] = 1 ;
3033- strcpy (current_basin_name[0 ],bname .c_str ());
3066+ strcpy (current_basin_name[0 ],bID .c_str ());
30343067 retval = nc_put_vara_string (ncid,varid,start,count,(const char **)current_basin_name); HandleNetCDFErrors (retval);
3068+ strcpy (current_basin_name[0 ],bname.c_str ());
3069+ retval = nc_put_vara_string (ncid,varid_name,start,count,(const char **)current_basin_name); HandleNetCDFErrors (retval);
30353070 ibasin++;
30363071 }
30373072 }
0 commit comments