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.

KTNEVComments.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. %
  2. % KTNEVComments
  3. %
  4. % This is a class that deals with comments saved in a NEV file. The user
  5. % can read the comments, get their timestamp information and even add
  6. % comments to the NEV file and then save it as a new file.
  7. %
  8. %
  9. % addComment: Allows the user to add a new comment to the
  10. % file at a given timestamp.
  11. %
  12. % displayComments: Displays all the comments in the NEV with their
  13. % corresponding timestamps.
  14. %
  15. % 'report': Will show a summary report if user passes this
  16. % argument.
  17. % DEFAULT: will not show report.
  18. %
  19. % getCommentText: Displays the text of comments.
  20. %
  21. % getCommentTimestamps: Displays the timestamp of comments, in samples.
  22. %
  23. % getCommentTimestampsSec: Displays the timestamp of comments, in seconds.
  24. %
  25. % EXAMPLE:
  26. %
  27. % To run, use "myVariable = KTNEVComments;". Then use
  28. % "myVariable.METHODNAME" to call the various differnet methods. Type
  29. % "myVariable." and then hit enter to see the available methods.
  30. %
  31. % myComments = KTNEVComments;
  32. % myComments.DisplayComments;
  33. %
  34. % Kian Torab
  35. % ktorab@blackrockmicro.com
  36. % Blackrock Microsystems
  37. % Version 1.0.1.0
  38. %
  39. classdef KTNEVComments
  40. properties (Hidden)
  41. NEV
  42. end
  43. methods (Hidden)
  44. function obj = KTNEVComments
  45. %% Open the NEV file
  46. obj.NEV = openNEV('read', 'nomat');
  47. end
  48. function rawNEV = getRawNEV(obj)
  49. FIDr = fopen([obj.NEV.MetaTags.FilePath '/' obj.NEV.MetaTags.Filename '.NEV'], 'r+', 'ieee-le');
  50. % Loading the NEV file
  51. rawNEV = fread(FIDr)';
  52. fclose(FIDr);
  53. end
  54. function rawData = getRawData(obj)
  55. FID = fopen([obj.NEV.MetaTags.FilePath '/' obj.NEV.MetaTags.Filename '.NEV'], 'r+', 'ieee-le');
  56. fseek(FID, obj.NEV.MetaTags.HeaderOffset, 'bof');
  57. rawData = fread(FID, [obj.NEV.MetaTags.PacketBytes obj.NEV.MetaTags.PacketCount], '104*uint8=>uint8', 0);
  58. end
  59. function packetIndices = getPacketIDIndices(obj)
  60. rawData = obj.getRawData;
  61. PacketID = rawData(5:6,:);
  62. packetIndices = typecast(PacketID(:), 'uint16').';
  63. end
  64. function packetIndices = getPacketIDIndicesForPacketID(obj, packetID)
  65. PacketIDs = obj.getPacketIDIndices;
  66. packetIndices = find(PacketIDs==packetID);
  67. end
  68. function timestampIndices = getTimestampIndices(obj)
  69. rawData = obj.getRawData;
  70. Timestamp = rawData(1:4,:);
  71. timestampIndices = typecast(Timestamp(:), 'uint32').';
  72. end
  73. end
  74. methods
  75. function displayComments(obj)
  76. fprintf('\n\n Timestamp Timestamp Seconds Text\n');
  77. for commentIDX = 1:length(obj.NEV.Data.Comments.TimeStamp)
  78. fprintf('%11d %17.4f %s\n', obj.NEV.Data.Comments.TimeStamp(commentIDX), ...
  79. obj.NEV.Data.Comments.TimeStampSec(commentIDX), ...
  80. obj.NEV.Data.Comments.Text(commentIDX,:));
  81. end
  82. end
  83. function output = getCommentTimestamps(obj)
  84. output = obj.NEV.Data.Comments.TimeStamp;
  85. end
  86. function output = getCommentTimestampsSec(obj)
  87. output = obj.NEV.Data.Comments.TimeStampSec;
  88. end
  89. function output = getCommentText(obj)
  90. output = obj.NEV.Data.Comments.Text;
  91. end
  92. function addComment(obj)
  93. FIDw = fopen([obj.NEV.MetaTags.FilePath '/' obj.NEV.MetaTags.Filename '-commented.nev'], 'w+', 'ieee-le');
  94. % Getting the comment info
  95. timestamp = input('What timestamp? ');
  96. color = input('What is the color code (hit enter if not sure)? ');
  97. if isempty(color)
  98. color = 0;
  99. end
  100. charSet = input('What is the character set (hit enter if not sure)? ');
  101. if isempty(charSet)
  102. charSet = 0;
  103. end
  104. text = input('Comment: ','s');
  105. text(end+1:92) = zeros(1,obj.NEV.MetaTags.PacketBytes-12-length(text));
  106. % Reading the RawNEV
  107. rawData = obj.getRawNEV;
  108. rawData = [rawData typecast(uint32(timestamp), 'uint8')...
  109. typecast(uint16(65535), 'uint8')...
  110. typecast(uint8(charSet), 'uint8')...
  111. typecast(uint8(0), 'uint8')...
  112. typecast(uint32(color), 'uint8')...
  113. typecast(uint8(text), 'uint8')];
  114. % Writing file
  115. fwrite(FIDw, rawData, 'uint8');
  116. fclose(FIDw);
  117. clear rawData;
  118. end
  119. end
  120. end