diff --git a/matlab/dynare.m b/matlab/dynare.m
index 034ec06745cef22bbec94c0d7eae582e530bd4d3..84b7efca4f993cb380bf9952bce926abef6f9a4c 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -82,6 +82,7 @@ end
 % Testing if file have extension
 % If no extension default .mod is added
 if isempty(strfind(fname,'.'))
+    fnamelength = length(fname);
     fname1 = [fname '.dyn'];
     d = dir(fname1);
     if length(d) == 0
@@ -94,8 +95,13 @@ else
             && ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN')
         error('DYNARE: argument must be a filename with .mod or .dyn extension')
     end;
+    fnamelength = length(fname) - 4;
 end;
 
+if fnamelength + length('_set_auxiliary_variables') > namelengthmax()
+    error('The name of your MOD file is too long, please shorten it')
+end
+
 % Workaround for a strange bug with Octave: if there is any call to exist(fname)
 % before the call to the preprocessor, then Octave will use the old copy of
 % the .m instead of the newly generated one. Deleting the .m beforehand
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8b3baccfd20857769a3a2c03f6c93f5999478907..b19c4651c4efa126c58c90689511054dcf23e341 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,12 +100,12 @@ MODFILES = \
 	dsge-var/simul_hybrid.mod \
 	dsge-var/dsgevar_forward_calibrated_lambda.mod \
 	dsge-var/dsgevar_forward_estimated_lambda.mod \
-	external_function/example1_1st_and_2nd_deriv_functions_provided.mod \
-	external_function/example1_1st_and_2nd_deriv_functions_provided_dll.mod \
-	external_function/example1_1st_deriv_function_provided.mod \
-	external_function/example1_1st_deriv_function_provided_dll.mod \
-	external_function/example1_no_deriv_functions_provided.mod \
-	external_function/example1_no_deriv_functions_provided_dll.mod \
+	external_function/first_and_2nd_deriv_fcns_provided.mod \
+	external_function/first_and_2nd_deriv_fcns_provided_dll.mod \
+	external_function/first_deriv_fcn_provided.mod \
+	external_function/first_deriv_fcn_provided_dll.mod \
+	external_function/no_deriv_fcns_provided.mod \
+	external_function/no_deriv_fcns_provided_dll.mod \
 	seeds.mod \
 	identification/kim/kim2.mod \
 	identification/as2007/as2007.mod \
diff --git a/tests/external_function/example1_1st_and_2nd_deriv_functions_provided.mod b/tests/external_function/first_and_2nd_deriv_fcns_provided.mod
similarity index 100%
rename from tests/external_function/example1_1st_and_2nd_deriv_functions_provided.mod
rename to tests/external_function/first_and_2nd_deriv_fcns_provided.mod
diff --git a/tests/external_function/example1_1st_and_2nd_deriv_functions_provided_dll.mod b/tests/external_function/first_and_2nd_deriv_fcns_provided_dll.mod
similarity index 100%
rename from tests/external_function/example1_1st_and_2nd_deriv_functions_provided_dll.mod
rename to tests/external_function/first_and_2nd_deriv_fcns_provided_dll.mod
diff --git a/tests/external_function/example1_1st_deriv_function_provided.mod b/tests/external_function/first_deriv_fcn_provided.mod
similarity index 100%
rename from tests/external_function/example1_1st_deriv_function_provided.mod
rename to tests/external_function/first_deriv_fcn_provided.mod
diff --git a/tests/external_function/example1_1st_deriv_function_provided_dll.mod b/tests/external_function/first_deriv_fcn_provided_dll.mod
similarity index 100%
rename from tests/external_function/example1_1st_deriv_function_provided_dll.mod
rename to tests/external_function/first_deriv_fcn_provided_dll.mod
diff --git a/tests/external_function/example1_no_deriv_functions_provided.mod b/tests/external_function/no_deriv_fcns_provided.mod
similarity index 100%
rename from tests/external_function/example1_no_deriv_functions_provided.mod
rename to tests/external_function/no_deriv_fcns_provided.mod
diff --git a/tests/external_function/example1_no_deriv_functions_provided_dll.mod b/tests/external_function/no_deriv_fcns_provided_dll.mod
similarity index 100%
rename from tests/external_function/example1_no_deriv_functions_provided_dll.mod
rename to tests/external_function/no_deriv_fcns_provided_dll.mod