From 1d974e88b4478157f5da771e74508613ef9eb6e2 Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Fri, 7 Mar 2025 18:06:03 +0100
Subject: [PATCH] Moved functionality of getting deployment info into
 tcv_get_deployment_info

---
 matlab/TCV_IMAS/tcv_get_deploymentinfo.m | 79 +++++++++++++-----------
 matlab/TCV_IMAS/tcv_get_ids_bolometer.m  |  7 +--
 2 files changed, 44 insertions(+), 42 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv_get_deploymentinfo.m b/matlab/TCV_IMAS/tcv_get_deploymentinfo.m
index 576b97c..0222db1 100644
--- a/matlab/TCV_IMAS/tcv_get_deploymentinfo.m
+++ b/matlab/TCV_IMAS/tcv_get_deploymentinfo.m
@@ -11,45 +11,50 @@ function info = tcv_get_deploymentinfo(filepath)
     
     % Initialize output struct
     info = struct();
-    info.repository=fileparts(filepath);
-    
-    % Check if file exists
-    if exist(filepath, 'file') ~= 2
-        error('File does not exist: %s', filepath);
-    end
-    
-    % Open file for reading
-    fid = fopen(filepath, 'r');
-    if fid == -1
-        error('Could not open file: %s', filepath);
-    end
-    
-    % Read file line by line
-    while ~feof(fid)
-        line = fgetl(fid);
-        if ischar(line)
-            tokens = regexp(line, '^(\w+):\s(.+)$', 'tokens');
-            if ~isempty(tokens)
-                key = tokens{1}{1};
-                value = strtrim(tokens{1}{2});
-                
-                % Store relevant fields in the struct
-                switch key
-                    case 'DEPLOYMENT_DATE'
-                        info.deployment_date = value;
-                    case 'GIT_TAG'
-                        info.git_tag = value;
-                    case 'GIT_COMMIT'
-                        info.git_commit = value;
-                    case 'GIT_TAG_DATE'
-                        info.git_tag_date = value;
-                    case 'GITLAB_PROJECT_URL'
-                        info.gitlab_project_url = value;
+    try
+        filepath=fullfile(fileparts(which(filepath)),'.this-deployment.info');
+        info.repository=fileparts(filepath);
+            
+        % Check if file exists
+        if exist(filepath, 'file') ~= 2
+            error('File does not exist: %s', filepath);
+        end
+        
+        % Open file for reading
+        fid = fopen(filepath, 'r');
+        if fid == -1
+            error('Could not open file: %s', filepath);
+        end
+        
+        % Read file line by line
+        while ~feof(fid)
+            line = fgetl(fid);
+            if ischar(line)
+                tokens = regexp(line, '^(\w+):\s(.+)$', 'tokens');
+                if ~isempty(tokens)
+                    key = tokens{1}{1};
+                    value = strtrim(tokens{1}{2});
+                    
+                    % Store relevant fields in the struct
+                    switch key
+                        case 'DEPLOYMENT_DATE'
+                            info.deployment_date = value;
+                        case 'GIT_TAG'
+                            info.git_tag = value;
+                        case 'GIT_COMMIT'
+                            info.git_commit = value;
+                        case 'GIT_TAG_DATE'
+                            info.git_tag_date = value;
+                        case 'GITLAB_PROJECT_URL'
+                            info.gitlab_project_url = value;
+                    end
                 end
             end
         end
+        
+        % Close the file
+        fclose(fid);
+    catch
+        warning('Failed to read .deployment at filepath: %s',filepath);
     end
-    
-    % Close the file
-    fclose(fid);
 end
diff --git a/matlab/TCV_IMAS/tcv_get_ids_bolometer.m b/matlab/TCV_IMAS/tcv_get_ids_bolometer.m
index 38b695f..58819c5 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_bolometer.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_bolometer.m
@@ -30,9 +30,7 @@ ids_bolometer_description = struct();
 
 % Load the bolometer geometry
 bolo_geom=bolou_load_geometry();
-bolo_geom_gitinfo= ...
-    tcv_get_deploymentinfo(fullfile(fileparts(which('bolou_load_geometry')), ...
-    '.this-deployment.info'));
+bolo_geom_gitinfo= tcv_get_deploymentinfo('bolou_load_geometry');
 
 params_eff.data_request='\tcv_shot::top.results.bolo_u.intensity';
 params_eff.trialindx=1;
@@ -146,8 +144,7 @@ if status
   
   %% Code legacy for rc_gti_prep
   ids_bolometer.code.name = 'rc_gti_prep';
-  rc_gti_prep_gitinfo= ...
-    tcv_get_deploymentinfo(fullfile(fileparts(which(ids_bolometer.code.name)),'.this-deployment.info'));
+  rc_gti_prep_gitinfo= tcv_get_deploymentinfo(ids_bolometer.code.name);
   ids_bolometer.code.description = ...
     'rc_gti_prep, RADCAM gitlab repo, calls GTI to generate emissivity profiles with liuqe.';
   ids_bolometer.code.commit=rc_gti_prep_gitinfo.git_commit;
-- 
GitLab