.. highlightlang:: us .. index:: Channel-Interpolation .. index:: Interpolation .. index:: MDF .. index:: INCA .. index:: NC_Interpolation .. _nc_interpolation: NC_Interpolation ================ .. us.tag NC_Interpolation ENGLISH nc.tools New5151 :ref:`NC_Interpolation` creates a new NC file with interpolated data. The function can be used to change the sampling rate (frequency resolution). MDF/Inca files with multiple time channels can be interpolated onto a common time channel. .. function:: bool = NC_Interpolation(ssNCFile, ssNewNCName, ssTimeName) bool = NC_Interpolation(ssNCFile, ssNewNCName, ssTimeName, svChannelList) bool = NC_Interpolation(ssNCFile, ssNewNCName, ssTimeName, svChannelList, rvTimeDef) bool = NC_Interpolation(ncid, ssNewNCName, ssTimeName) bool = NC_Interpolation(ncid, ssNewNCName, ssTimeName, svChannelList) bool = NC_Interpolation(ncid, ssNewNCName, ssTimeName, svChannelList, rvTimeDef) .. us.return **Return Value** Is TRUE (1), if the file could be created and otherwise FALSE (0). .. us.params **Parameters** .. uparam:: ssNCFile *ssNCFile* is the name of an NC file with the source data. .. uparam:: ncid *ncid* is the handle of an NC file, returned by :ref:`nc_create` or :ref:`nc_open`. .. uparam:: ssNewNCName *ssNewNCName* is the output NC file name for the resulte file. .. uparam:: ssTimeName Is the name of a time channel in the source file. If the parameter *rvTimeDef* is not specified, the data will be interpolated to this channel. .. uparam:: svChannelList *svChannelList* is a vector with channel names. If an empty string is given, all channels will be interpolated. .. uparam:: rvTimeDef Is a real vector with one or three elements. If the parameter contains one value only, it is the time increment, for example 0.01 seconds (100 Hz). If the vector contains three values, the first element is the start time, the second element the end time and the third element the time increment. Example: ``[0,10,0.1]`` create a time channel form 0 to 10 with an increment of 0.1 seconds (10 Hz). .. us.comment **Comment** Only channels with at least 2 data points will be interpolated. For MDF data files the group name can be ignored. No extrapolation. Missing values will be set to `missing`. A linear interpolation is executed. *Bit Channels* To disable linear interpolation for certain channels, the channel names can be added to a ini file. In the ini file the interpolation type can be set for each channel (see comment in the following example). The file must be saved in the user directory of UniPlot. The file name is `` Bit_Channel_Interpolation.ini``. *String Channels* String channels can be interpolated and UniPlot uses the following rule: the interpolated channel take the original channel value until the interpolated time channel is equal or above to an existing time point in the original time channel. Example: .. code-block:: none - Original file at 1Hz Time String Channel 0 A 1 B 2 C - Interpolated file at 2Hz Time String Channel 0 A 0.5 A 1 B 1.5 B 2 C Example file: .. code-block:: ini ; Used be NC_Interpolation, NC_SycchronizeTime, NC_TimeInterpolation ; Channelname = interpolation type (nType) ; nType == 1: prev ; Previous neighbor interpolation. The interpolated value at a query point is ; the value at the previous sample grid point. ; nType == 2: nearest (default) ; Nearest neighbor interpolation. The interpolated value at a query point is the ; value at the nearest sample grid point. ; nType == 3: next ; Next neighbor interpolation. The interpolated value at a query point is the ; value at the next sample grid point. [Interpolation] Bit_Kanal1 = 1 Bit.Channel2 = 2 vKwz1 = 1 .. us.example **Example** :: def TestInterpolation() { ssDatFile = "u:/nc_daten2/080226_P5736R3_Startversuch.dat" ssNCFile = auto_ImportData(ssDatFile); ssNewTimeName = "time" svChannel = ["AirCtl_dvolIndAir_r32_ETKC_1", "PthSet_trqInrSet_ETKC_1", "AirCtl_mDesVal_ETKC_1"] // Erzeuge neuen Namen: svPath = SplitPath(ssNCFile); ssOutputName = svPath[1] + svPath[2] + svPath[3] + "_interpol" + svPath[4]; NC_Interpolation(ssNCFile, ssOutputName, ssNewTimeName, svChannel); // Time wie erste Kanal //NC_Interpolation (ssNCFile, ssOutputName, ssNewTimeName, svChannel, [0.01]) // Delta 0.1s von Range 1. Kanal //NC_Interpolation (ssNCFile, ssOutputName, ssNewTimeName, svChannel, [0,12,0.01]) // Time von 0s bis 12s in 0.01s } The following example reads MDF files and interpolates the data to the time of the first channel found in the channel list svSearchName. The data is exported as a Excel XLSX file:: RegisterCommand("File: MDF-Export", "_MDF_To_Excel", "MDF->Excel...", "", "", "MSExcel.BMP"); UserBar_Add("_MDF_To_Excel"); def _MDF_Find_TimeChannel(ncid, svSearch) { nSearch = len(svSearch); for (i in 1:nSearch) { VaridTime = _NC_get_time_channel_id(ncid, svSearch[i]); if (VaridTime != -1) { return VaridTime; } } return -1; } def _MDF_To_Excel() { // Channelname for interpolation. // The time is used from the first found defined channel svSearchName = ["Input_2", "time1", "time2"]; WriteProfileInt("Settings", "MDF_StripDeviceName", 1) WriteProfileInt("Settings", "MDF_StripGroupName", 1) ssDir = GetProfileString("settings", "last_mdf_to_excel_dir"); svFiles = GetOpenFileName_Data(ssDir, TRUE, TRUE, FALSE); if (svFiles[1] == "") { return; } smPath = SplitPath(svFiles); WriteProfileString("settings", "last_mdf_to_excel_dir", smPath[1;1] + smPath[1;2]); nFiles = len(svFiles); for (i in 1:nFiles) { ssNCName = auto_ImportData(svFiles[i]); ncid = nc_open(ssNCName, NC_NOWRITE); if (ncid == -1) { MessageBoxError("Cannot open file: %s", ssNCName); continue; } if (_QV_IsVS100(ncid) == FALSE) { nc_close(ncid); continue; } varid = _MDF_Find_TimeChannel(ncid, svSearchName); if (varid == -1) { // USe first time channel dimid = 0; nVars = nc_inquire_nvars(ncid); if (nVars <= 0) { nc_close(ncid); continue; } rvVarid = _QV_FindGroupChannelsVS100(ncid, nVars, dimid); if (rvVarid[1] == -1) { Event_Error(_s("MDF LoadDataset", "Cannot find Time Channel")); } varid = rvVarid[1]; } ssTimeName = nc_varinq_name(ncid, varid); ssNewNCName = sum(smPath[i; 1,2, 3]) + "_tran.nc2"; ncid2 = NC_TimeInterpolation(ncid, ssNewNCName, ssTimeName); nc_close(ncid); if (ncid2 == -1) { Event_Error("MDF-Export", "Failed to create file"); continue; } nc_close(ncid2); obj = [.] ssType = "XLSX-NOHEADER" // "XLSX"; // obj.ssOutDir = "d:/"; obj.ssMissing = "missing"; // obj.bOverwrite = TRUE; // obj.svChannel = ["Lst", "EngPwr", "Speed", "PME"]; NC_ExportData(ssNewNCName, "XLSX-NOHEADER", obj); } } .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2022.4 - String channels are interpolated. * - R2022.4 - _nc_enum information is kept during interpolation. * - 5.15.1 - New. .. seealso:: :ref:`overview-netcdf-files`, :ref:`nc_create`, :ref:`nc_open`, :ref:`fileexport-data`, :ref:`auto_ImportData`, :ref:`NC_ExportData` :sub:`id-540769`