nc_varrenameΒΆ
nc_varrename renames a given netCDF variable.
-
ret = nc_varrename(ncid, varid, ssNewName)
Return Value
ret is -1 in case an error occurred.
Parameters
-
ncid
Identifies the netCDF file.
-
varid
varid is the ID of a variable.
-
ssNewName
ssNewName is the new name of the netCDF variable.
// Remove _Mean and _Max from all channel names:
def _nc_modifychannelnames(ssNCName)
{
svRemove = ["_Mean", "_Max"];
ncid = nc_open(ssNCName, NC_WRITE)
if (ncid == -1) {
MessageBoxError("Cannot open file: %s", ssNCName);
return FALSE;
}
svVarNames = NC_GetVarNames(ncid);
svVarNamesNew = svVarNames;
for (i in 1:len(svRemove)) {
idx = strmatchi("*" + svRemove[i], svVarNamesNew)
if (idx[1] != 0) {
svVarNamesNew[idx] = strfindreplace(svVarNamesNew[idx], svRemove[i], "");
}
}
nc_redef(ncid);
for (i in 1:len(svVarNamesNew)) {
if (svVarNames[i] != svVarNamesNew[i]) {
varid = nc_varid(ncid, svVarNames[i]);
if (varid != -1) {
nc_varrename(ncid, varid, svVarNamesNew[i]);
nc_attput(ncid, varid, "title", NC_CHAR, svVarNamesNew[i], TRUE);
ssUnit = nc_attget(ncid, varid, "units");
ssUnit = strfindreplace(ssUnit, "[", "");
ssUnit = strfindreplace(ssUnit, "]", "");
nc_attput(ncid, varid, "long_name", NC_CHAR, ...
NC_long_name(svVarNamesNew[i], ssUnit), TRUE);
}
}
}
nc_endef(ncid);
nc_close(ncid);
return TRUE;
}
See also
id-227457