diff --git a/matlab/TCV_IMAS/tcv_get_ids_dataset_description.m b/matlab/TCV_IMAS/tcv_get_ids_dataset_description.m new file mode 100644 index 0000000000000000000000000000000000000000..3efe0d0dbe68badb56790f841fa86ed24438db8e --- /dev/null +++ b/matlab/TCV_IMAS/tcv_get_ids_dataset_description.m @@ -0,0 +1,90 @@ +function [ids_dataset_description,ids_dataset_description_description] = ... + tcv_get_ids_dataset_description(shot, ids_dataset_description_empty, gdat_params,varargin) +% +% [ids_dataset_description,ids_dataset_description_description] = ... +% tcv_get_ids_dataset_description(shot, ids_dataset_description_empty,varargin); +% +% Get the TCV IMAS dataset_description data +% +% ids_dataset_description_empty should at least be the empty dataset_description ids structure +% in input +% +% gdat_params: gdat_data.gdat_params to get all params passed from original +% call, in particular error_bar options +% +% Date: 24/04/25 +% Author: L. Simons + +% Initialise structure with default ids_properties +% shot=70777; gdat_params=[]; varargin={}; +% aa=gdat([],'ids','source','dataset_description'); ids_dataset_description_empty=aa.dataset_description; +if exist('gdat_params') + [ids_dataset_description, ~] = tcv_ids_headpart(shot, ids_dataset_description_empty, ... + 'dataset_description','homogeneous_time',1,'gdat_params',gdat_params, ... + varargin{:}); +else + [ids_dataset_description, ~] = tcv_ids_headpart(shot,ids_dataset_description_empty,'dataset_description','homogeneous_time',0,varargin{:}); +end + +ids_dataset_description_description = struct(); + +% homogenous_time=2 , only static and constant information +ids_dataset_description.ids_properties.homogeneous_time=2; + +% Get username +username = getenv('USERNAME'); % Works on Windows +if isempty(username) + username = getenv('USER'); % Works on Unix/Linux/Mac +end + +% Define uri +backend='mdsplus'; +run=1; +imas_version_number=getenv('IMAS_VERSION'); +version=num2str(imas_version_number(1)); +uri = sprintf('imas:%s?user=%s;shot=%d;run=%d;database=%s;version=%s', ... + backend, username, shot, run, database,version); +ids_dataset_description.uri=uri; + +% Define type +% FIXME: Not sure what the condition should be here... To be discussed +if strcmp(gdat_params.data_request,'ids') + ids_dataset_description.type.name='experimental'; + ids_dataset_description.type.index=1; + ids_dataset_description.type.description='Data coming from an experiment'; +else + ids_dataset_description.type.name='simulation'; + ids_dataset_description.type.index=2; + ids_dataset_description.type.description='Data coming from a simulation'; +end + +% Define data_entry +ids_dataset_description.machine='tcv'; +ids_dataset_description.pulse=shot; + +% Attempt to fill information about pulse time +% FIXME: How to get pulse_time_end? Simply = pulse_time_begin + X seconds? +[pulse_time_begin,pulse_time_begin_epoch,pulse_time_begin_epoch_ns]= ... + get_mds_node_info('\VSYSTEM:TIMERS.VALUES',shot); +ids_dataset_description.pulse_time_begin=pulse_time_begin; +ids_dataset_description.pulse_time_begin_epoch.seconds=pulse_time_begin_epoch; +ids_dataset_description.pulse_time_begin_epoch.nanoseconds=pulse_time_begin_epoch_ns; +% ids_dataset_description.pulse_time_end_epoch.seconds= +% ids_dataset_description.pulse_time_end_epoch.nanoseconds= +% ids_dataset_description.pulse_processing_time_begin=node_time + + +%% Simulation metadata +% FIXME: How do we hope to get this information? +% ids_dataset_description.simulation.comment_before=? +% ids_dataset_description.simulation.comment_after=? +% ids_dataset_description.simulation.time_begin=? +% ids_dataset_description.simulation.time_step=? +% ids_dataset_description.simulation.time_end=? +% ids_dataset_description.simulation.time_restart=? +% ids_dataset_description.simulation.time_current=? +% ids_dataset_description.simulation.time_begun=? +% ids_dataset_description.simulation.time_ended=? +% ids_dataset_description.simulation.time_workflow=? + +end diff --git a/matlab/get_mds_node_info.m b/matlab/get_mds_node_info.m new file mode 100644 index 0000000000000000000000000000000000000000..b832deb3f20a99abc98aea89fd75ea3c678b7a26 --- /dev/null +++ b/matlab/get_mds_node_info.m @@ -0,0 +1,49 @@ +function [node_time, node_epoch_time, node_epoch_time_ns, node_owner] = get_mds_node_info(node_str, shot) +% [node_time, node_epoch_time, node_owner] = +% get_mds_node_info(node_str, shot) +% +% Retrieves insertion time and owner of a node in MDSplus +% +% Inputs: +% node_str - String, path to the MDSplus node +% (e.g. '\\RESULTS::CXRS_001:TI') +% shot - Numeric, Shot number to open +% +% Outputs: +% node_time - Numeric, Time the node data was inserted +% node_owner - String, (Optional) Owner info of the node +% +% Date: 20/09/24 +% Author: L. Simons + + % Open the shot + mdsopen('tcv_shot',shot); + + try + % Time inserted + tdi_time = sprintf('times(getnci("%s","TIME_INSERTED"))', node_str); + mds_node_time = mdsvalue(tdi_time); + % Convert the timestamp (returned as a string) to MATLAB datetime + dt = datetime(mds_node_time, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss.SSSSSS', 'TimeZone', 'UTC'); + % Format it to ISO 8601 with Zulu (UTC) time + time_str = datestr(dt, 'yyyy-mm-ddTHH:MM:SS'); + node_time = [time_str 'Z']; + % Convert to Unix Epoch time (seconds since Jan 1, 1970 UTC) + node_epoch_time = posixtime(datetime(mds_node_time, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss.SSSSSS', 'TimeZone', 'UTC')); + node_epoch_time_ns=mod(second(dt),1)*1e9; + + % Owner + tdi_owner = sprintf('owner_ascii("%s")', node_str); + node_owner = mdsvalue(tdi_owner); + + catch + warning('Failed to read time of node, returning empty strings..'); + node_time=''; + node_owner=''; + mdsclose; + end + + % Always close MDS connection + mdsclose; + +end \ No newline at end of file