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: tsdate.m
    path of file: ./repos/malini/Codes/FC_EC_calculation code/DynamicFC/jplv7/util
    
    the code of the file until where you have to start completion: function [out] = tsdate(beg_yr,beg_mth,freq,nobs)
% PURPOSE: produce a time-series date string for an observation #
%          given beginning year, beginning period and frequency of the data
% ---------------------------------------------------
% USAGE: out = tsdate(beg_yr,beg_period,freq,obsn);
%        or:   tsdate(beg_yr,beg_period,freq,obsn);
%        or:   tsdate(cal_struct,obsn);
% where: beg_yr     = beginning year, e.g., 1974
%        beg_period = beginning period, e.g., 4 for april
%        freq       = 1 for annual, 4 for quarterly 12 for monthly
%        obsn       = the observation #
%        cal_struct = a structure returned by cal()
%     
% e.g., tsdate(1974,1,12,13) would print: Jan75
%       tsdate(1974,1,4,13)  would print: Q1-77
%       tsdate(1974,1,1,13)  would print 1986
%       out = tsdate(1974,1,12,13) would return a string `Jan75'
%       
%       cstr = cal(1974,1,12)
%       tsdate(cstr,13)      would print Jan75
% ---------------------------------------------------
% RETURNS: a string, or: simply displays the date associated
%          with obsn (observation #)
% ---------------------------------------------------
% SEE ALSO: tsplot(), tsprint()
% ---------------------------------------------------

% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jpl@jpl.econ.utoledo.edu

    
function [out] = tsdate(beg_yr,beg_mth,freq,nobs)
% PURPOSE: produce a time-series date string for an observation #
%          given beginning year, beginning period and frequency of the data
% ---------------------------------------------------
% USAGE: out = tsdate(beg_yr,beg_period,freq,obsn);
%        or:   tsdate(beg_yr,beg_period,freq,obsn);
%        or:   tsdate(cal_struct,obsn);
% where: beg_yr     = beginning year, e.g., 1974
%        beg_period = beginning period, e.g., 4 for april
%        freq       = 1 for annual, 4 for quarterly 12 for monthly
%        obsn       = the observation #
%        cal_struct = a structure returned by cal()
%     
% e.g., tsdate(1974,1,12,13) would print: Jan75
%       tsdate(1974,1,4,13)  would print: Q1-77
%       tsdate(1974,1,1,13)  would print 1986
%       out = tsdate(1974,1,12,13) would return a string `Jan75'
%       
%       cstr = cal(1974,1,12)
%       tsdate(cstr,13)      would print Jan75
% ---------------------------------------------------
% RETURNS: a string, or: simply displays the date associated
%          with obsn (observation #)
% ---------------------------------------------------
% SEE ALSO: tsplot(), tsprint()
% ---------------------------------------------------

% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jpl@jpl.econ.utoledo.edu

switch nargin

case 4   % case where a cal() structure is not used
% we need do nothing here

case 2   % case where a cal() structure is used
% error checking
if ~isstruct(beg_yr)
error('tsdate: one of the two inputs must be a structure from cal');
end