.. highlightlang:: us .. _nc_varrename: nc_varrename ============ .. index:: nc_varrename .. us.tag nc_varrename ENGLISH NC_Var New320 :ref:`nc_varrename` renames a given netCDF variable. .. function:: ret = nc_varrename(ncid, varid, ssNewName) .. us.return **Return Value** *ret* is -1 in case an error occurred. .. us.params **Parameters** .. uparam:: ncid Identifies the netCDF file. .. uparam:: varid *varid* is the ID of a variable. .. uparam:: 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; } .. seealso:: :ref:`overview-netcdf-files`, :ref:`nc_create` :sub:`id-227457`