How to get a multidimensional post value via typoscript? - typo3

In TYPO3 4.5, how can a value stored in $_POST (in a 2-dimensional array) be accessed via Typoscript?
print_r($_POST) looks like this:
I have tried this:
20 = TEXT
20.data = GP:[tx_powermail_pi1][uid1517]
and also
20.value.data = GP:[tx_powermail_pi1][uid1517]
but it doesn't output anything. How is the correct syntax?

You can use GP:stuff|key like so:
10 = TEXT
10.data = GP:tx_powermail_pi1|uid1517
See: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/2/#id1037388
(search for getText)

Related

dicom header personal information conversion to a .txt file

I have a series of DICOM Images which I want to anonymize, I found few Matlab codes and some programs which do the job, but none of them export a .txt file of removed personal information. I was wondering if there is a function which can also save removed personal information of a DICOM images in .txt format for features uses. Also, I am trying to create a table which shows the corresponding new images ID to their real name.(subjects real name = personal-information-removed image ID)
Any thoughts?
Thanks for considering my request!
I'm guessing you only want to output to your text file the fields that are changed by anonymization (either modified, removed, or added). First, you may want to modify some dicomanon options to reduce the number of changes, in particular passing the arguments 'WritePrivate', true to ensure private extensions are kept.
First, you can perform the anonymization, saving structures of pre- and post-anonymization metadata using dicominfo:
preAnonData = dicominfo('input_file.dcm');
dicomanon('input_file.dcm', 'output_file.dcm', 'WritePrivate', true);
postAnonData = dicominfo('output_file.dcm');
Then you can use fieldnames and setdiff to find fields that are removed or added by anonymization, and add them to the post-anonymization or pre-anonymization data, respectively, with a nan value as a place holder:
preFields = fieldnames(preAnonData);
postFields = fieldnames(postAnonData);
removedFields = setdiff(preFields, postFields);
for iField = 1:numel(removedFields)
postAnonData.(removedFields{iField}) = nan;
end
addedFields = setdiff(postFields, preFields);
for iField = 1:numel(addedFields)
preAnonData.(addedFields{iField}) = nan;
end
It will also be helpful to use orderfields so that both data structures have the same ordering for their field names:
postAnonData = orderfields(postAnonData, preAnonData);
Finally, now that each structure has the same fields in the same order we can use struct2cell to convert their field data to a cell array and use cellfun and isequal to find any fields that have been modified by the anonymization:
allFields = fieldnames(preAnonData);
preAnonCell = struct2cell(preAnonData);
postAnonCell = struct2cell(postAnonData);
index = ~cellfun(#isequal, preAnonCell, postAnonCell);
modFields = allFields(index);
Now you can create a table of the changes like so:
T = table(modFields, preAnonCell(index), postAnonCell(index), ...
'VariableNames', {'Field', 'PreAnon', 'PostAnon'});
And you could use writetable to easily output the table data to a text file:
writetable(T, 'anonymized_data.txt');
Note, however, that if any of the fields in the table contain vectors or structures of data, the formatting of your output file may look a little funky (i.e. lots of columns, most of them empty, except for those few fields).
One way to do this is to store the tags before and after anonymisation and use these to write your text file. In Matlab, dicominfo() will read the tags into a structure:
% Get tags before anonymization
tags_before = dicominfo(file_in);
% Anoymize
dicomanon(file_in, file_out); % Need to set tags values where required
% Get tags after anonymization
tags_after = dicominfo(file_out);
% Do something with the two structures
disp(['Patient ID:', tags_before.PatientID ' -> ' tags_after.PatientID]);
disp(['Date of Birth:', tags_before.PatientBirthDate ' -> ' tags_after.PatientBirthDate]);
disp(['Family Name:', tags_before.PatientName.FamilyName ' -> ' tags_after.PatientName.FamilyName]);
You can then write out the before/after fields into a text file. You'd need to modify dicomanon() to choose your own values for the removed fields, since by default they are set to empty.

Powershell Hashtable values using variable key

I am trying to let a user make a selection and then return a value from a hashtable based on that selection.
My hashtable looks like this:
$choices = #{ 0 = "SelectionA";
1 = "SelectionB";
99 = "SelectionC"}
My selection looks like this:
$selection = Read-Host -Prompt "
Please make a selection
0 - Selection A
1 - Selection B
99 - Selection C "
Then I'm trying to bring back the value based on the selection like this:
$choices.$selection
or
$choices.{$selection}
This isn't working. Is it possible to call a hashtable value using a variable as the key?
Thanks for any help you can offer!
You can use the Get_Item method.
$myChoice = $choices.Get_Item($selection)
You may have to convert the $selection variable into an integer first, since I believe it will come in as a string.
More info on hash tables: https://technet.microsoft.com/en-us/library/ee692803.aspx
The comments above are both correct answers. I'm adding them as answers to close the question.
By PetSerAl:
$choices.[int]$selection
Or by beatcracker:
$choices = #{ '0' = 'SelectionA'}
This is one of the PowerShell's automatic type conversion blindspots. Keys in your hashtable are integers, but Read-Host returns strings.
The simple works in PSVersion 7
$ha=#{0='aa';1='bb'}
$sel=0
$ha.$sel // 'aa'

dlmwrite in a loop using cell type as the name

I would like to save my filenames by calling my cell names as:
bench(1:15).applicationNames
in which they are like this:
ans =
'mvt'
ans =
'symm'
, etc.
Having tested all kinds of conversions (cellstr, char, sprintf), i can't seems to find the solution for saving my array as bellow in loop:
dlmwrite('result_<bench(a),applicationName>.csv'),[zz' sort(bench(a).norm)],',')
where each bench.application has a name on it as mentioned above.
Use sprintf in place of your first string:
sprintf('result_%s.csv',bench(a).application{:})
Edit: fixed, as it was pointed out to me that bench.application was a cellstring.

converting a string array into a struct

I have a string array with the contents of the row in the following manner.
X ='Xmole(1)=0.0Xmole(2)=1.0rho(1)=2343rho(2)=2343'
Now I need a struct data.Massdensity which should look like this
<data.Massdensity = Xmole(1)=0.0
Xmole(2)=1.0
rho(1)=2343
rho(2)=2343>
I did use cell2struct which will gave me a struct like this
data.Massdensity ='Xmole(1)=0.0Xmole(2)=1.0rho(1)=2343rho(2)=2343'
Is there any way possible I can get the struct like the one above.
I am reading a textfile whose contents look like this
MassDensity{
Xmole(1) = 0.0
Xmole(2) = 1.0
rho(1) = 2343 # [kg/m^3]
rho(2) = 2343 # [kg/m^3]
}
I am using fileread to read this into a single string.
So any better way of doing this
The problem with the intial way you presented your data is that there are no obvious delimiters. Whereas within the original file you have the option (one presumes) of using the line ends as delimiters.
1) Read in as separate strings (may require splitting or reassembly in MATLAB), the individual lines into a cell array. With textscan you can set a range of delimiters and other settings so make full use of the options.
For example:
a = textscan(fid,'%s','Delimiter',...
{'\n','{','}','#'},'CommentStyle','#','MultipleDelimsAsOne',1);
a = a{1}
Ideally you want to end up with:
a{1} = 'Massdensity'
a{2} = 'Xmole(1)=0.0'
...
a{4} = 'rho(2) = 2343'
You may need to do some trimming of whitespace.
2) Create your struct, using dynamic field naming:
data.(a{1})=a(2:end);
data.MassDensity{1}
ans =
Xmole(1) = 0.0

creating an array and append values to it in smarty template

I want to create an array in smarty and do an append functionality in it! Like if I declare a variable in smarty template like {assign var=sizearr value=''} and then i want to append values to this in a loop, and i can access values like {sizearr.0}, how can i do that?
Use append. I'm not sure if this is also available in Smarty 2
{append var='sizearr' value='' index=0}
In smarty3 yould also use a more php-like approach:
{$sizearr[] = 'your value'}
and either loop through the array like
{foreach $sizearr as $value}
{$value#key}: {$value}
{/foreach}
or just hit a specific index:
{$sizearr[2]}
You can use this too:
{$sizearr[] = "Size value"}
Here you can see the full doc (Section Appending an array)
You can simply use the smarty built-in function append :
Now lets take this example:
{assign var="ages" value=[] }
{for $i=1 to 3}
{append var="ages" value=$i }
{/for}
In the above example we didn't specify index parameter in the append function, so the value will be appended at the end of the ages array.
Hope this is helpful for everyone.