Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

ini2struct.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function Struct = ini2struct(FileName)
  2. % Parses .ini file
  3. % Returns a structure with section names and keys as fields.
  4. %
  5. % Based on init2struct.m by Andriy Nych
  6. % 2014/02/01
  7. genvarname = @matlab.lang.makeValidName;
  8. f = fopen(FileName,'r'); % open file
  9. while ~feof(f) % and read until it ends
  10. s = strtrim(fgetl(f)); % remove leading/trailing spaces
  11. if isempty(s) || s(1)==';' || s(1)=='#' % skip empty & comments lines
  12. continue
  13. end
  14. if s(1)=='[' % section header
  15. Section = genvarname(strtok(s(2:end), ']'));
  16. Struct.(Section) = []; % create field
  17. continue
  18. end
  19. [Key,Val] = strtok(s, '='); % Key = Value ; comment
  20. Val = strtrim(Val(2:end)); % remove spaces after =
  21. if isempty(Val) || Val(1)==';' || Val(1)=='#' % empty entry
  22. Val = [];
  23. elseif Val(1)=='"' % double-quoted string
  24. Val = strtok(Val, '"');
  25. elseif Val(1)=='''' % single-quoted string
  26. Val = strtok(Val, '''');
  27. else
  28. Val = strtok(Val, ';'); % remove inline comment
  29. Val = strtok(Val, '#'); % remove inline comment
  30. Val = strtrim(Val); % remove spaces before comment
  31. [val, status] = str2num(Val); %#ok<ST2NM>
  32. if status, Val = val; end % convert string to number(s)
  33. end
  34. if ~exist('Section', 'var') % No section found before
  35. Struct.(genvarname(Key)) = Val;
  36. else % Section found before, fill it
  37. Struct.(Section).(genvarname(Key)) = Val;
  38. end
  39. end
  40. fclose(f);