You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: read_hdr.m
    path of file: ./repos/CanlabCore/CanlabCore/Data_extraction
    
    the code of the file until where you have to start completion: function hdr = read_hdr(name,varargin)
% Loads the analyze format header file from a file 'name' 
%
% :Usage:
% ::
%
%    function hdr = read_hdr(name,[opt] datatype)
%
% The function returns a structure defined as 
%
% hdr = struct(...
%      'sizeof_hdr', fread(pFile, 1,'int32'),...
%
%      'pad1', setstr(fread(pFile, 28, 'char')),...
%
%      'extents', fread(pFile, 1,'int32'),...
%
%      'pad2', setstr(fread(pFile, 2, 'char')),...
%
%      'regular',setstr(fread(pFile, 1,'char')), ...
%
%      'pad3', setstr(fread(pFile,1, 'char')),...
%
%      'dims', fread(pFile, 1,'int16'),...
%
%      'xdim', fread(pFile, 1,'int16'),...
%
%      'ydim', fread(pFile, 1,'int16'),...
%
%      'zdim', fread(pFile, 1,'int16'),...
%
%      'tdim', fread(pFile, 1,'int16'),...
%
%      'pad4', setstr(fread(pFile,20, 'char')),...
%
%      'datatype', fread(pFile, 1,'int16'),...

    
function hdr = read_hdr(name,varargin)
% Loads the analyze format header file from a file 'name' 
%
% :Usage:
% ::
%
%    function hdr = read_hdr(name,[opt] datatype)
%
% The function returns a structure defined as 
%
% hdr = struct(...
%      'sizeof_hdr', fread(pFile, 1,'int32'),...
%
%      'pad1', setstr(fread(pFile, 28, 'char')),...
%
%      'extents', fread(pFile, 1,'int32'),...
%
%      'pad2', setstr(fread(pFile, 2, 'char')),...
%
%      'regular',setstr(fread(pFile, 1,'char')), ...
%
%      'pad3', setstr(fread(pFile,1, 'char')),...
%
%      'dims', fread(pFile, 1,'int16'),...
%
%      'xdim', fread(pFile, 1,'int16'),...
%
%      'ydim', fread(pFile, 1,'int16'),...
%
%      'zdim', fread(pFile, 1,'int16'),...
%
%      'tdim', fread(pFile, 1,'int16'),...
%
%      'pad4', setstr(fread(pFile,20, 'char')),...
%
%      'datatype', fread(pFile, 1,'int16'),...
%
%      'bits', fread(pFile, 1,'int16'),...
%
%      'pad5', setstr(fread(pFile, 6, 'char')),...
%
%      'xsize', fread(pFile, 1,'float'),...
%
%      'ysize', fread(pFile, 1,'float'),...
%
%      'zsize', fread(pFile, 1,'float'),...
%
%      'pad6', setstr(fread(pFile, 48, 'char'))...
%
%      'glmax', fread(pFile, 1,'int32'),...
%
%      'glmin', fread(pFile, 1,'int32'),... 
%      'descrip', setstr(fread(pFile, 80,'char')),...
%
%      'aux_file'        , setstr(fread(pFile,24,'char'))',...
%
%      'orient'          , fread(pFile,1,'char'),...
%
%      'origin'          , fread(pFile,5,'int16'),...
%
%      'generated'       , setstr(fread(pFile,10,'char'))',...
%
%      'scannum'         , setstr(fread(pFile,10,'char'))',...
%
%      'patient_id'      , setstr(fread(pFile,10,'char'))',...
%
%      'exp_date'        , setstr(fread(pFile,10,'char'))',...
%
%      'exp_time'        , setstr(fread(pFile,10,'char'))',...
%
%      'hist_un0'        , setstr(fread(pFile,3,'char'))',...
%
%      'views'           , fread(pFile,1,'int32'),...
%
%      'vols_added'      , fread(pFile,1,'int32'),...
%
%      'start_field'     , fread(pFile,1,'int32'),...
%
%      'field_skip'      , fread(pFile,1,'int32'),...
%
%      'omax'            , fread(pFile,1,'int32'),...
%
%      'omin'            , fread(pFile,1,'int32'),...
%
%      'smax'            , fread(pFile,1,'int32'),...
%
%      'smin'            , fread(pFile,1,'int32') );
%
% ..
%    Luis hernandez
%    last edit 12-9-01 by tor wager
%    Unzip .gz files before processing.         Editted 11/7/2023 by Michael Sun, Ph.D.
% ..


global SPM_scale_factor
unzipped=0;

if nargin > 1, 
	dtype = varargin{1};
else
	dtype = 'n';
end