I have a written a MATLAB program that creates custom MATLAB functions on the fly and launches them in other MATLAB instances using unix command. I use this program for automatizing fMRI neuroimaging analyses (using SPM8 for MATLAB), and everything works fine. However, MATLAB imposes a function name length maximum of 63 characters (namelengthmax). As I need to save two different timestamps in each function name together with the name of the function that created it (I have several different functions that create these new functions that are used for multithreaded fMRI analysis), 63 characters is quite limiting for filenames like:
atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15.m
In this example atf means ‘analysis thread function’ (to separate it from other files with similar filenames), the first timestamp identifies the run (a global timestamp, it this case 5th of July 2012 at 18:01:02), then there’s a string specify_1st_level that identifies the function (in this case specify_1st_level.m) that created this new ‘analysis thread function’, and then the second time stamp identifies this specific new ‘analysis thread function’ from other new ‘analysis thread functions’ created to be run in other threads (and for different analysis subjects, or for different analyses) and that are run simultaneously.
My problem is the character limit of 63 characters for function names.
I’m aware that I could write my timestamps without underscores (_), or compress them, and I can make my function names shorter (eg. specify_1st_level.m -> sp1st.m), and also I could divide my functions created on the fly in different subfolders also created on the fly named eg. with global timestamps. Edit: Or I could even create a hash of the entire function name and use the hash as a function name instead of the human-readable string presented above.
However, I plan to add more data in the names of ‘analysis thread functions’ (one or more hash values of different analysis parameter sets used in this run to identify identical analyses of different times). If possible, I would like to keep it nice and simple (human-readable function names help in debugging of ‘analysis thread functions’ created on the fly).
So, is there any way to extend namelengthmax ? I’m running MATLAB R2012a in Linux. I’m also happy to hear any other ways to solve this issue.
Answering to my own question: After thinking it some more, I found a way to embed as much information as I want into a MATLAB function name and still keep it readable for humans. First, I’ll compute SHA1 hash of my function filename: SHA1 hash of
atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15.misE545831A 0002C73B CA095F11 25FC5C51 35B82451(here presented with spaces for clarity).Then my function name will be
[ 'atf_', sha1hashString, '.m' ], for this example that’ll beatf_E545831A0002C73BCA095F1125FC5C5135B82451.m, so the function name length will be 44 characters, that’s no problem at all. This solves the limitation of 63 characters, but I also need a way to be able to find my functions using regular bash commands.So I’ll create a copy of that function file, concatenating the hash to the end of the original function name, so it becames
atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_E545831A0002C73BCA095F1125FC5C5135B82451.m. Then I can find the correct function easily in bash usinglsorfind(for debugging purposes), check the hash from the end of the filename and set breakpoint in MATLAB debugger in the function that will be called from MATLAB (eg.atf_E545831A0002C73BCA095F1125FC5C5135B82451.m) and use MATLAB debugger without problems.This is the most practical solution I can think of and it makes possible to add hashes of analysis parameter sets into the function name too: I’ll just compute the SHA1 hash of the analysis parameter set (let’s assume that the SHA1 hash of the parameter set is
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D, and concatenated with original function name it’ll beatf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D.m. Then I’ll compute a new SHA1 hash of this original function name extended with the SHA1 hash of the analysis parameter sets: SHA1 hash ofatf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D.misA81F0083 38868103 F1A0DB69 010279D5 5DB3751E. Then I’ll create two identical functions, one for MATLAB and one for my debugging purposes, and they will be namedatf_A81F008338868103F1A0DB69010279D55DB3751E.mandatf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D_A81F008338868103F1A0DB69010279D55DB3751E.m. And it’s even possible to have several SHA1 hashes of different parameters sets in the same function name this way, eg. one defining the subjects to be included, other defining the data handling parameters etc., then concatenate both or all of them to the filename, and then compute SHA1 hash and write two identical functions as above.