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.

nex_cont.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function [adfreq, n, ts, fn, d] = nex_cont(filename, varname)
  2. % nex_cont(filename, varname): Read continuous variable from a .nex file
  3. %
  4. % [adfreq, n, ts, fn, d] = nex_cont(filename, varname)
  5. %
  6. % INPUT:
  7. % filename - if empty string, will use File Open dialog
  8. % varname - variable name
  9. %
  10. % continuous (a/d) data come in fragments. Each fragment has a timestamp
  11. % and a number of a/d data points. The timestamp corresponds to
  12. % the time of recording of the first a/d value in this fragment.
  13. % All the data values stored in the vector d.
  14. % OUTPUT:
  15. % n - total number of data points
  16. % ts - array of fragment timestamps (one timestamp for fragment, in seconds)
  17. % fn - number of data points in each fragment
  18. % d - array of a/d values (in millivolts)
  19. n = 0;
  20. adfreq = 0;
  21. ts = 0;
  22. fn = 0;
  23. d = 0;
  24. if(nargin ~= 2)
  25. disp('2 input arguments are required')
  26. return
  27. end
  28. if(ischar(filename) == 0)
  29. disp('input arguments should be character arrays')
  30. return
  31. end
  32. if(ischar(varname) == 0)
  33. disp('input arguments should be character arrays')
  34. return
  35. end
  36. if(isempty(filename))
  37. [fname, pathname] = uigetfile('*.nex', 'Select a Nex file');
  38. filename = strcat(pathname, fname);
  39. end
  40. fid = fopen(filename, 'r');
  41. if(fid == 0)
  42. return
  43. end
  44. disp(strcat('file = ', filename));
  45. magic = fread(fid, 1, 'int32');
  46. version = fread(fid, 1, 'int32');
  47. comment = fread(fid, 256, 'char');
  48. freq = fread(fid, 1, 'double');
  49. tbeg = fread(fid, 1, 'int32');
  50. tend = fread(fid, 1, 'int32');
  51. nvar = fread(fid, 1, 'int32');
  52. fseek(fid, 260, 'cof');
  53. name = zeros(1, 64);
  54. found = 0;
  55. for i=1:nvar
  56. type = fread(fid, 1, 'int32');
  57. var_version = fread(fid, 1, 'int32');
  58. name = fread(fid, [1 64], 'char');
  59. offset = fread(fid, 1, 'int32');
  60. nf = fread(fid, 1, 'int32');
  61. dummy = fread(fid, 32, 'char');
  62. adfreq = fread(fid, 1, 'double');
  63. adtomv = fread(fid, 1, 'double');
  64. n = fread(fid, 1, 'int32');
  65. name = char(name);
  66. name = deblank(name);
  67. k = strcmp(name, deblank(varname));
  68. if(k == 1)
  69. if type ~= 5
  70. disp(sprintf('%s is not a continuous variable', deblank(varname)));
  71. return;
  72. end
  73. found = 1;
  74. fseek(fid, offset, 'bof');
  75. ts = fread(fid, [1 nf], 'int32');
  76. fn = fread(fid, [1 nf], 'int32');
  77. d = fread(fid, [1 n], 'int16');
  78. break
  79. end
  80. dummy = fread(fid, 76, 'char');
  81. end
  82. fclose(fid);
  83. if found == 0
  84. disp('did not find variable in the file');
  85. else
  86. ts = ts/freq;
  87. d = d*adtomv;
  88. fn(nf+1) = n;
  89. fn = diff(fn);
  90. disp(strcat('number of data points = ', num2str(n)));
  91. end