Skip to content

Commit

Permalink
Use automatic time variable name for dynamic forcing (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyprienBosserelle authored Feb 15, 2024
1 parent 3310a3b commit 36da1e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/Read_netcdf.cu
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ void readgridncsize(const std::string ncfilestr, const std::string varstr, std::
//size_t start[] = { 0 };
//size_t count[] = { (size_t)nt };
//status = nc_get_vara_double(ncid, varid, start, count, ttempvar);
status = readnctime2(ncid, reftime, nt, ttempvar);

status = readnctime2(ncid, coordname, reftime, nt, ttempvar);

to = ttempvar[0];
tmax= ttempvar[nt-1];
Expand Down Expand Up @@ -426,7 +427,7 @@ int readnctime(std::string filename, double * &time)
return status;
}

int readnctime2(int ncid,std::string refdate,size_t nt, double*& time)
int readnctime2(int ncid,char * timecoordname,std::string refdate,size_t nt, double*& time)
{

int status, varid;
Expand All @@ -453,13 +454,13 @@ int readnctime2(int ncid,std::string refdate,size_t nt, double*& time)
/// //varstr = "time";
///}

// Warning this could be more robust by taking the unlimited dimention if time does not exist!
std::string Varname = "time";
// Warning this could be more robust by taking the unlimited dimension if time does not exist!
//std::string Varname = "time";

///status = nc_open(ncfilestr.c_str(), 0, &ncid);
///if (status != NC_NOERR) handle_ncerror(status);

status = nc_inq_varid(ncid, Varname.c_str(), &varid);
status = nc_inq_varid(ncid, timecoordname, &varid);
if (status != NC_NOERR) handle_ncerror(status);

// inquire unit of time
Expand Down
2 changes: 1 addition & 1 deletion src/Read_netcdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template<class T> void readgridncsize(T& Imap);

int readvarinfo(std::string filename, std::string Varname, size_t *&ddimU);
int readnctime(std::string filename, double * &time);
int readnctime2(int ncid, std::string refdate, size_t nt, double*& time);
int readnctime2(int ncid,char* timecoordname, std::string refdate, size_t nt, double*& time);
template <class T> int readncslev1(std::string filename, std::string varstr, size_t indx, size_t indy, size_t indt, bool checkhh, double eps, T * &zsa);
template <class T> int readvardata(std::string filename, std::string Varname, int step, T*& vardata, bool flipx, bool flipy);
//template <class T> int readhotstartfile(Param XParam, int * leftblk, int *rightblk, int * topblk, int* botblk, double * blockxo, double * blockyo, T * &zs, T * &zb, T * &hh, T *&uu, T * &vv);
Expand Down

0 comments on commit 36da1e4

Please sign in to comment.