.. highlightlang:: us .. index:: nc_from_obj .. _nc_from_obj: nc_from_obj =========== .. us.tag nc_from_obj NOTREADYENGLISH nc.tools New5147 :ref:`nc_from_obj` creates a netCDF file from a special structured UniScript object. .. function:: bool = nc_from_obj(obj, ssNCFilename) .. us.return **Return Value** *bool* is TRUE (1) if the function was successful and otherwise FALSE (0). .. us.params **Parameters** .. uparam:: obj *obj* is an object that contains the channel data and the following elements: ``globals``, ``channel_info`` and ``order``. ``globals`` is an optional object containing elements saved as global attributes in the nc file. ``channel_info`` is an optional object containing channel attributes. The optional element ``order`` sets the order of the channels in the netCDF file. .. uparam:: ssNCFilename *ssNCFilename* is the complete file name of the new netCDF file. .. us.comment **Comment** The function saves the channels in the netCDF file with the data type ``double`` or ``char``. If the element *channel_info* contains the element *datatype* it will be used to define the data type in the NC file. Example ``o.channel_info["speed"].datatype = "real4"`` will create a channel of type NC_FLOAT in the NC file. See also :ref:`format-description-for-csv,-text-and-excel-files--datatype`. The element ``order`` is optional. If the element exists, it must contain all channels. ``order[1]`` contains the first channel, ``order[2]`` the second and so forth. .. us.example **Example** :: ssNCFileName = GetUserDirectory() + "test.nc"; nc_from_obj([. x = [1,2,3], y = [4,5,2]], ssNCFileName); NC_Edit(ssNCFileName); .. us.example **Example** :: def test() { ssNCFileName = GetUserDirectory() + "test.nc"; x = linspace(0,2*PI*100, 1e6); y = sin(x); o = [. x = x, y = y, order = [. 1 = "y", 2 = "x"], globals = [. Comment = "Simple Test" ], channel_info = [. x = [. units = "Nm", a = 1], y = [. units = "kg", b = 2]] ]; nc_from_obj(o, ssNCFileName); NC_Edit(ssNCFileName); return o; } o = test() .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2013.11 - Channel attribute datatype will be used to specify the channel type in the NC file. * - 5.14.7 - New. .. seealso:: :ref:`overview-netcdf-files`, :ref:`nc_to_obj`, :ref:`NC_Edit` :sub:`id-54330`