Remove spaces between characters of output Batch file - batch-file

I have a batch file that outputs the Wi-Fi adapter MAC address to a text file using the command wmic nic where "name like '%%802%%'" get name,macaddress and there are spaces between characters. I get the same thing for sfc /scannow in a batch file.
The output of the wmic command is:
Hostname: SOME-COMPUTER
A C A d d r e s s N a m e
3 4 : F 6 : B 3 : J 3 : 6 3 : 1 3 B r o a d c o m 8 0 2 . 1 1 n N e t w o r k A d a p t e r
The snippet of output of the sfc scan is:
n 3 0 % c o m p l e t e . V e r i f i c a t i o n 3 1 % c o m p l e t e . V e r i f i c a t i o n 3 1 % c o m p l e t e . V e r i f i c a t i o n 3 2 % c o m p l e t e . V e r i f i c a t i o n 3 2 % c o m p l e t e . V e r i f i c a t i o n 3 3 % c o m p l e t e . V e r i f i c a t i o n 3 3 % c o m p l e t e . V e r i f i c a t i o n 3 4 % c o m p l e t e . V e r i f i c a t i o n 3 4 % c o m p l e t e . V e r i f i c a t i o n 3 5 % c o m p l e t e . V e r i f i c a t i o n 3 5 % c o m p l e t e . V e r i f i c a t i o n 3 5 % c o m p l e t e . V e r i f i c a t i o n 3 6 % c o m p l e t e . V e r i f i c a t i o n 3 6 % c o m p l e t e . V e r i f i c a t i o n 3 7 % c o m p l e t e . V e r i f i c a t i o n 3 7 % c o m p l e t e . V e r i f i c a t i o n 3 8 % c o m p l e t e . V e r i f i c a t i o n 3 8 % c o m p l e t e . V e r i f i c a t i o n 3 9 % c o m p l e t e . V e r i f i c a t i o n 3 9 % c o m p l e t e . V e r i f i c a t i o n 4 0 % c o m p l e t e . V e r i f i c a t i o n 4 0 % c o m p l e t e . V e r i f i c a t i o n 4 1 % c o m p l e t e . V e r i f i c a t i o n 4 1 % c o m p l e t e . V e r i f i c a t i o n 4 2 % c o m p l e t e . V e r i f i c a t i o n 4 2 % c o m p l e t e . V e r i f i c a t i o n 4 2 % c o m p l e t e . V e r i f i c a t i o n 4 3 % c o m p l e t e . V e r i f i c a t i o n 4 3 % c o m p l e t e . V e r i f i c a t i o n 4 4 % c o m p l e t e . V e r i f i c a t i o n 4 4 % c o m p l e t e . V e r i f i c a t i o n 4 5 % c o m p l e t e . V e r i f i c a t i o n 4 5 % c o m p l e t e . V e r i f i c a t i o n 4 6 % c o m p l e t e . V e r i f i c a t i o n 4 6 % c o m p l e t e . V e r i f i c a t i o n 4 7 % c o m p l e t e . V e r i f i c a t i o n 4 7 % c o m p l e t e . V e r i f i c a t i o n 4 8 % c o m p l e t e . V e r i f i c a t i o n 4 8 % c o m p l e t e . V e r i f i c a t i o n 4 9 % c o m p l e t e . V e r i f i c a t i o n 4 9 % c o m p l e t e . V e r i f i c a t i o n 5 0 % c o m p l e t e . V e r i f i c a t i o n 5 0 % c o m p l e t e . V e r i f i c a t i o n 5 0 % c o m p l e t e . V e r i f i c a t i o n 5 1 % c o m p l e t e . V e r i f i c a t i o n 5 1 % c o m p l e t e . V e r i f i c a t i o n 5 2 % c o m p l e t e . V e r i f i c a t i o n 5 2 % c o m p l e t e . V e r i f i c a t i o n 5 3 % c o m p l e t e . V e r i f i c a t i o n 5 3 % c o m p l e t e . V e r i f i c a t i o n 5 4 % c o m p l e t e . V e r i f i c a t i o n 5 4 % c o m p l e t e . V e r i f i c a t i o n 5 5 % c o m p l e t e . V e r i f i c a t i o n 5 5 % c o m p l e t e . V e r i f i c a t i o n 5 6 % c o m p l e t e . V e r i f i c a t i o n 5 6 % c o m p l e t e . V e r i f i c a t i o n 5 7 % c o m p l e t e . V e r i f i c a t i o n 5 7 % c o m p l e t e . V e r i f i c a t i o n 5 7 % c o m p l e t e . V e r i f i c a t i o n 5 8 % c o m p l e t e . V e r i f i c a t i o n 5 8 % c o m p l e t e . V e r i f i c a t i o n 5 9 % c o m p l e t e . V e r i f i c a t i o n 5 9 % c o m p l e t e . V e r i f i c a t i o n 6 0 % c o m p l e t e . V e r i f i c a t i o n 6 0 % c o m p l e t e . V e r i f i c a t i o n 6 1 % c o m p l e t e . V e r i f i c a t i o n 6 1 % c o m p l e t e . V e r i f i c a t i o n 6 2 % c o m p l e t e . V e r i f i c a t i o n 6 2 % c o m p l e t e . V e r i f i c a t i o n 6 3 % c o m p l e t e . V e r i f i c a t i o n 6 3 % c o m p l e t e . V e r i f i c a t i o n 6 4 % c o m p l e t e . V e r i f i c a t i o n 6 4 % c o m p l e t e . V e r i f i c a t i o n 6 4 % c o m p l e t e . V e r i f i c a t i o n 6 5 % c o m p l e t e . V e r i f i c a t i o n 6 5 % c o m p l e t e . V e r i f i c a t i o n 6 6 % c o m p l e t e . V e r i f i c a t i o n 6 6 % c o m p l e t e . V e r i f i c a t i o n 6 7 % c o m p l e t e . V e r i f i c a t i o n 6 7 % c o m p l e t e . V e r i f i c a t i o n 6 8 % c o m p l e t e . V e r i f i c a t i o n 6 8 % c o m p l e t e . V e r i f i c a t i o n 6 9 % c o m p l e t e . V e r i f i c a t i o n 6 9 % c o m p l e t e . V e r i f i c a t i o n 7 0 % c o m p l e t e . V e r i f i c a t i o n 7 0 % c o m p l e t e . V e r i f i c a t i o n 7 1 % c o m p l e t e . V e r i f i c a t i o n 7 1 % c o m p l e t e . V e r i f i c a t i o n 7 1 % c o m p l e t e . V e r i f i c a t i o n 7 2 %
When I run these commands from cmd.exe, the output looks like this:
MACAddress Name
34:F2:B3:A1:83:33 Broadcom 802.11n Network Adapter
I would use PowerShell normally, but that is not what I need here. I would like the output to look like this in the output file.
The output doesn't seem to care if I use setlocal enabledelayedexpansion endlocal, as the output is the same.
Thank you for your help!
EDIT
I created a blank Unicode file ( I have Windows 10 ), and copied it to a new file I used for the output file. Now, the spaces are gone, but for whatever reason, the variable created for the hostname outputs what appears to be Chinese characters:
潈瑳慮敭›䕄䭓佔ⵐ䩒䵔剄⁓਍MACAddress Name
34:F2:B3:A1:83:33 Broadcom 802.11n Network Adapter
The hostname command was used as follows:
for /f "delims= tokens=*" %%i in ('hostname') do (
set "nameHost=%%i"
)
Then, I changed tokens=* to tokens=2 and all of the characters were Chinese. Anyway, a work-around was to add the hostname to the filename instead, which resolves this issue. However, it would be ideal to learn how to have both ANSI and Unicode strings in the same file, without the spaces.
I saw a C++ article about this and the answer was to change the code; therefore, if that it true, I don't have the code for sfc or wmic, so am I SOL there, or is there a way to have both ANSI and Unicode strings in the same file without the spaces between each character?

wmic nic where "name like '%%802%%'" get name,macaddress|more
should provide you with an ANSI version - the problem there is Unicode-output from WMIC.

Related

Response to Remote access to Unet Agents for GNURadio

I was wondering what did the Unetstack agent expect as a response to a TCP connection which is established to the modem at ip:port ?
I was trying to connect to the the modem using the TCP connection through the GNURadio pdu socket. The connection was established but i think after handshaking, it was automatically terminated. Did it expect something ?I am planning to send custom messages to modem using this APIs.
Here is what i have done so far.
I opened a TCP connection using Socket PDU block using below flow graph.
I used unet audio SDOAM to test:
jay#jay-MS-7885:~/Desktop/unet-3.2.0$ bin/unet -c audio
Modem web: http://localhost:8080/
> iface
tcp://10.0.3.1:1100, tcp://192.168.0.14:1100, tcp://192.168.0.165:1100 [API]
ws://10.0.3.1:8080/ws, ws://192.168.0.14:8080/ws, ws://192.168.0.165:8080/ws [API]
unetsh: console://- [GroovyScriptEngine]
websh: ws://127.0.1.1:8080/fjage/shell/ws [GroovyScriptEngine]
It looks like the connection was established and on GNURadio side in command prompt i got normal JSON response from modem. And Just after that connection was automatically closed. Did it expect something ?
Executing: /usr/bin/python3 -u /home/jay/Desktop/Jay/UnetstackPython.py
******* MESSAGE DEBUG PRINT ********
Send
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a l i v e " : t r u e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " 0 9 f 5 3 2 0 0 - e 2 9 1 - 4 8 2 6 - 8 9 6 b - c 5 d 1 6 5 8 9 f 8 d 5 " , " i n R e p l y T o " : " 3 5 5 8 f e c 9 4 e e 7 b e e 1 a 5 0 f 5 6 6 1 d e 6 f c 4 b d " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " a u t o " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " 4 b d 5 6 f 0 7 - d a c 2 - 4 7 2 9 - 8 2 7 6 - b 4 4 1 8 6 d 3 1 6 a a " , " i n R e p l y T o " : " 8 7 7 9 5 2 4 c 4 5 d 8 9 f 1 e 4 6 3 b e 9 8 e 6 4 d 6 0 c e a " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " t c p : / / 1 0 . 0 . 3 . 1 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 1 1 0 0 [ A P I ] \ n w s : / / 1 0 . 0 . 3 . 1 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 8 0 8 0 / w s [ A P I ] \ n t c p : / / / 1 0 . 0 . 3 . 1 : 1 1 0 0 / / 1 0 . 0 . 3 . 1 . 3 5 9 5 6 [ A P I ] \ n u n e t s h : c o n s o l e : / / - [ G r o o v y S c r i p t E n g i n e ] \ n w e b s h : w s : / / 1 2 7 . 0 . 1 . 1 : 8 0 8 0 / f j a g e / s h e l l / w s [ G r o o v y S c r i p t E n g i n e ] " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . p a r a m . P a r a m e t e r R s p " , " d a t a " : { " i n d e x " : - 1 , " v a l u e s " : n u l l , " p a r a m " : " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " , " v a l u e " : - 8 4 2 . 1 , " r e a d o n l y " : [ " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " ] , " m s g I D " : " c 4 6 8 b 2 8 c - 9 3 8 5 - 4 9 a 3 - 9 c 2 8 - a 8 6 5 e d 7 e 9 8 b c " , " p e r f " : " I N F O R M " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " p h y " , " i n R e p l y T o " : " f 9 0 a 8 1 f 2 4 4 6 6 5 2 4 8 5 c a 7 3 1 b 0 7 a 5 6 1 e 9 3 " , " s e n t A t " : 1 6 1 5 4 2 0 6 8 6 4 3 0 } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " e 2 1 2 4 c 9 c - 0 b 2 9 - 4 c 4 3 - 8 c 2 c - b 8 a d 2 3 8 c 4 1 8 a " , " i n R e p l y T o " : " 2 e 6 9 3 c b d 2 4 1 9 b 8 7 c b f a 9 c b 7 8 f 5 d 8 8 0 b f " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " a u t o " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . G e n e r i c M e s s a g e " , " d a t a " : { " m s g I D " : " 1 e f f b 6 8 6 - a 0 5 a - 4 3 a d - a 5 a e - d 7 2 2 d 5 3 4 b b 1 9 " , " i n R e p l y T o " : " d 7 d e c 5 e b 6 a 2 3 d 6 8 3 d 6 8 2 7 3 6 2 c 8 4 d 0 2 8 f " , " p e r f " : " A G R E E " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " w e b s h " , " a n s " : " t c p : / / 1 0 . 0 . 3 . 1 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 1 1 0 0 , t c p : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 1 1 0 0 [ A P I ] \ n w s : / / 1 0 . 0 . 3 . 1 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 4 : 8 0 8 0 / w s , w s : / / 1 9 2 . 1 6 8 . 0 . 1 6 5 : 8 0 8 0 / w s [ A P I ] \ n t c p : / / / 1 0 . 0 . 3 . 1 : 1 1 0 0 / / 1 0 . 0 . 3 . 1 . 3 5 9 5 6 [ A P I ] \ n u n e t s h : c o n s o l e : / / - [ G r o o v y S c r i p t E n g i n e ] \ n w e b s h : w s : / / 1 2 7 . 0 . 1 . 1 : 8 0 8 0 / f j a g e / s h e l l / w s [ G r o o v y S c r i p t E n g i n e ] " } } , " r e l a y " : f a l s e }
])
************************************
******* MESSAGE DEBUG PRINT ********
(() . #[{ " a c t i o n " : " s e n d " , " m e s s a g e " : { " c l a z z " : " o r g . a r l . f j a g e . p a r a m . P a r a m e t e r R s p " , " d a t a " : { " i n d e x " : - 1 , " v a l u e s " : n u l l , " p a r a m " : " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " , " v a l u e " : - I n f i n i t y , " r e a d o n l y " : [ " o r g . a r l . y o d a . M o d e m P a r a m . n o i s e " ] , " m s g I D " : " f a b 5 e 8 4 8 - 4 6 7 6 - 4 1 4 9 - b 6 2 8 - 7 b b 5 a 4 8 2 a 0 f e " , " p e r f " : " I N F O R M " , " r e c i p i e n t " : " W e b G W - c e a 1 9 a 9 d 3 7 f b e b 0 8 " , " s e n d e r " : " p h y " , " i n R e p l y T o " : " a d a 8 d 2 7 1 2 3 6 e 8 d 5 6 0 f 1 7 d 2 9 7 9 e 5 0 2 0 7 4 " , " s e n t A t " : 1 6 1 5 4 2 0 6 8 9 4 3 1 } } , " r e l a y " : f a l s e }
])
************************************
terminate called after throwing an instance of 'boost::system::system_error'
what(): End of file
>>> Done (return code -6)
I am trying to send this JSON message but the connection was closed before even i do anything.
Is there specific JSON response needed by unetstack to keep the connection active ?
The JSON protocol used by UnetStack is from fjåge. The full specification of the protocol can be found here: https://fjage.readthedocs.io/en/latest/protocol.html
The protocol expects an acknowledgement to the {"alive": true} JSON message within a short timeout (5 seconds). If it receives no acknowledgement, it will close the connection, assuming that the connecting party is not responsive. The correct acknowledgement is a {"alive": true} sent back to confirm that the connection is indeed alive.
The above handshake is designed to cater for other transports such as RS232 where a disconnection can only be detected by communicating over the connection.

Join four columns into one according to each row

A B C D
E F G H
I J K L
M N O P
If I chose to join the columns I would ={A1:A;B1:B;C1:C;D1:D} but it would look like this:
A
E
I
M
B
F
J
N
... and so on
I would like it to look like this:
A
B
C
D
E
F
G
... and so on
How to proceed in this case?
Note: It may happen that some of the columns are not complete in data, some may have more values than the others, but I still want to continue following this same pattern. Example:
A B D
E G H
I J K L
M N O P
Result:
A
B
D
E
G
H
... and so on
use:
=TRANSPOSE(QUERY(TRANSPOSE(A:D),, 9^9))
then:
=TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A:D),,9^9)),,9^9), " "))

SaveToFile and then open it formating text weird

Okay so I am writing a program that imports a database to an text file Via (SaveToFile command) .But when I open the file normally it gives me.
TG! ¶’ò?²Ï# ª _þX g Ò­cöëÏ°ã ª ? Á<Ž¶ëmÐö ª _þX
| ¾"µÈó\Î­å ª Dw= ÿÿ† ÿÿ" I Á<Ž¶ëmÐö ª _þX 2 . " C l i e n t s " C l i e n t s + ð I D I D
ÿ Z ÿÿÿÿC ð S u r e n a m e S u r e n a m e ‚ ÿ ÿ j ÿÿC ð P a s s w o r d P a s s w o r d
ÿ z ÿÿ3 ð N a m e N a m e ‚ ÿ ÿ j ÿÿK ð
M o n e y P a i d
M o n e y P a i d ÿ z ÿÿK ð
M o n e y O w e d
M o n e y O w e d ÿ z ÿÿ[ ð O n c e O f f C l i e n t O n c e O f f C l i e n t ÿ ÿ Z ÿÿC ð P h o n e I D P h o n e I D
ÿ z ÿÿÿ a w e a w e Ó–I
Here is my code:
procedure TfrmRawDATA.btnStoreFeedClick(Sender: TObject);
var
StoreFeed : string;
StoreFeedFile: TextFile;
data : string;
begin
begin
if (FileExists('C:\Users\ASROCK\Desktop\IT-PAT 2014\PAT Fase 3\StoreFeedFile.txt')) then
begin
DeleteFile('C:\Users\ASROCK\Desktop\IT-PAT 2014\PAT Fase 3\StoreFeedFile.txt');
ShowMessage('Save file deleted!');
end
else
AssignFile(StoreFeedFile,'Test.txt');
FileSetAttr('C:\Users\ASROCK\Desktop\IT-PAT 2014\PAT Fase 3\StoreFeedFile.txt', faReadOnly);
dmMJCPlus.tblClients.SaveToFile('C:\Users\ASROCK\Desktop\IT-PAT 2014\PAT Fase 3\StoreFeedFile.txt');
end;
end;
I just wanna know how to set like the file type or something so it doesn't give me that text.
The default saving format for ADO table/query and ClientDataSet is binary. You have the option of using XML though. You need to specify it in the call to SaveToFile:
ClientDataSet.SaveToFile('...', dfXML);
or
ADOTable.SaveToFile('...', pfXML);
Having a file extension of '.xml' should achieve the same, looking at the source, though it would seem it didn't turn out to be the case for you (as you seem to have tried it in the comments).
pfXML/dfXML are defined in 'adodb.pas' and 'dbclient.pas' respectively.

How to load a sliding diagonal vector from data stored column-wise with SSE

The sliding diagonal vector contains 16 elements, each one an 8-bit unsigned integer.
Without SSE and a bit simplified it would have looked like this in C:
int width=1000000; // a big number
uint8_t matrix[width][16];
fill_matrix_with_interesting_values(&matrix);
for (int i=0; i < width - 16; ++i) {
uint8_t diagonal_vector[16];
for (int j=0; j<16; ++j) {
diagonal_vector[j] = matrix[i+j][j];
}
do_something(&diagonal_vector);
}
but in my case I can only load column-wise (vertically) from the matrix with the _mm_load_si128 intrinsics function. The sliding diagonal vector is moving horizontally so I need to load 16 column vectors in advance and use one element from each of those column vectors to create the diagonal vector.
Is it possible to make a fast low-memory implementation for this with SSE?
Update Nov 14 2016: Providing some more details. In my case I read single-letter codes from a text file in FASTA format. Each letter represents a certain amino acid. Each amino acid has a specific column vector associated with it. That column vector is looked up from a constant table (a BLOSUM matrix). In C code it would look like this
while (uint8_t c = read_next_letter_from_file()) {
column_vector = lookup_from_const_table(c)
uint8_t diagonal_vector[16];
... rearrange the values from the latest column
vectors into the diagonal_vector ...
do_something(&diagonal_vector)
}
The implementation I will present only needs one column load per iteration. First we initialize some variables
const __m128i mask1=_mm_set_epi8(0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255);
const __m128i mask2=_mm_set_epi8(0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255);
const __m128i mask3=_mm_set_epi8(0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255);
const __m128i mask4=_mm_set_epi8(0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255);
__m128i v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15;
Then for each step the variable v_column_load is loaded with the next column.
v15 = v_column_load;
v7 = _mm_blendv_epi8(v7,v15,mask1);
v3 = _mm_blendv_epi8(v3,v7,mask2);
v1 = _mm_blendv_epi8(v1,v3,mask3);
v0 = _mm_blendv_epi8(v0,v1,mask4);
v_diagonal = v0;
In the next step the variable name numbers in v0, v1, v3, v7, v15 are incremented by 1 and adjusted to be in the range 0 to 15. In other words: newnumber = ( oldnumber + 1 ) modulo 16.
v0 = v_column_load;
v8 = _mm_blendv_epi8(v8,v0,mask1);
v4 = _mm_blendv_epi8(v4,v8,mask2);
v2 = _mm_blendv_epi8(v2,v4,mask3);
v1 = _mm_blendv_epi8(v1,v2,mask4);
v_diagonal = v1;
After 16 iterations the v_diagonal will start to contain the correct diagonal values.
Looking at mask1,mask2, mask3, mask4, we see a pattern that can be used to generalize this algorithm for other vector lengths (2^n).
For instance, for vector length 8, we would only need 3 masks and the iteration steps would look like this:
v7 = a a a a a a a a
v6 =
v5 =
v4 =
v3 = a a a a
v2 =
v1 = a a
v0 = a
v0 = b b b b b b b b
v7 = a a a a a a a a
v6 =
v5 =
v4 = b b b b
v3 = a a a a
v2 = b b
v1 = a b
v1 = c c c c c c c c
v0 = b b b b b b b b
v7 = a a a a a a a a
v6 =
v5 = c c c c
v4 = b b b b
v3 = a a c c
v2 = a b c
v2 = d d d d d d d d
v1 = c c c c c c c c
v0 = b b b b b b b b
v7 = a a a a a a a a
v6 = d d d d
v5 = c c c c
v4 = b b d d
v3 = a a c d
v3 = e e e e e e e e
v2 = d d d d d d d d
v1 = c c c c c c c c
v0 = b b b b b b b b
v7 = a a a a e e e e
v6 = d d d d
v5 = a a c c e e
v4 = a b b d a
v4 = f f f f f f f f
v3 = e e e e e e e e
v2 = d d d d d d d d
v1 = c c c c c c c c
v0 = b b b b f f f f
v7 = a a a a e e e e
v6 = b b d d f f
v5 = a b c d e f
v5 = g g g g g g g g
v4 = f f f f f f f f
v3 = e e e e e e e e
v2 = d d d d d d d d
v1 = c c c c g g g g
v0 = b b b b f f f f
v7 = a a c c e e g g
v6 = a b c d e f g
v6 = h h h h h h h h
v5 = g g g g g g g g
v4 = f f f f f f f f
v3 = e e e e e e e e
v2 = d d d d h h h h
v1 = c c c c g g g g
v0 = b b d d f f h h
v7 = a b c d e f g h <-- this vector now contains the diagonal
v7 = i i i i i i i i
v6 = h h h h h h h h
v5 = g g g g g g g g
v4 = f f f f f f f f
v3 = e e e e i i i i
v2 = d d d d h h h h
v1 = c c e e g g i i
v0 = b c d e f g h i <-- this vector now contains the diagonal
v0 = j j j j j j j j
v7 = i i i i i i i i
v6 = h h h h h h h h
v5 = g g g g g g g g
v4 = f f f f j j j j
v3 = e e e e i i i i
v2 = d d f f h h j j
v1 = c d e f g h i j <-- this vector now contains the diagonal
Sidenote: I discovered this way of loading a diagonal vector when I was working on an implementation of the Smith-Waterman algorithm. Some more information can be found on the old SourceForge project web page.

C reading csv file

I'm running into a problem I haven't encountered before and am baffled... for some reason when I try to read a CSV file char by char but it seems like spaces are somehow getting placed there... and what's weirder is the fact that no space chars exist anywhere. I will give an example...
char *readgd(const char *fname)
{
char *gddata, *tmp;
FILE *fp;
int buff = 1024, c = 0, ch;
if(!(fp = fopen(fname, "r")))
{
printf("\nError! Could not open %s!", fname);
return 0x00;
}
if(!(gddata = malloc(buff)))
{
fclose(fp);
printf("\nError! Memory allocation failed!");
return 0x00;
}
while(ch != EOF)
{
c++;
ch = fgetc(fp);
if(buff <= c)
{
buff += buff;
if(!(tmp = realloc(gddata, buff)))
{
free(gddata);
fclose(fp);
printf("\nError! Memory allocation failed!");
}
gddata = tmp;
}
gddata[c - 1] = ch;
if(gddata[c - 1] != ' ') printf("%c", gddata[c - 1]); //no spaces?
}
if(!(tmp = realloc(gddata, c + 1)))
{
free(gddata);
fclose(fp);
printf("\nError! Memory allocation failed!");
}
gddata = tmp;
gddata[c] = 0x00;
fclose(fp);
return gddata;
}
with the following CSV snippet:
:Tagname,Area,SecurityGroup,Container,ContainedName,ShortDesc,ExecutionRelativeOrder,ExecutionRelatedObject,UDAs,Extensions,CmdData,Address_ACbHAlmCfg,Address_ACbHWarnCfg,Address_ACbLAlmCfg,Address_ACbLWarnCfg,Address_ACbTfCfg,Address_ACrHAlmDb,Address_ACrHAlmSp,Address_ACrHAlmTmrSp,Address_ACrHWarnDb,Address_ACrHWarnSp,Address_ACrHWarnTmrSp,Address_ACrLAlmDb,Address_ACrLAlmSp,Address_ACrLAlmTmrSp,Address_ACrLWarnDb,Address_ACrLWarnSp,Address_ACrLWarnTmrSp,Address_ACrTfTmrSp,Address_bHalm,Address_bHWarn,Address_bLAlm,Address_bLwarn,Address_bMode,Address_bTfAlm,Address_rCCmd,Address_rVal,
outputs this onto the console:
 
■: T a g n a m e , A r e a , S e c u r i t y G r o u p , C o n t a i n e r , C
o n t a i n e d N a m e , S h o r t D e s c , E x e c u t i o n R e l a t i v e
O r d e r , E x e c u t i o n R e l a t e d O b j e c t , U D A s , E x t e n s
i o n s , C m d D a t a , A d d r e s s _ A C b H A l m C f g , A d d r e s s _
A C b H W a r n C f g , A d d r e s s _ A C b L A l m C f g , A d d r e s s _ A
C b L W a r n C f g , A d d r e s s _ A C b T f C f g , A d d r e s s _ A C r H
A l m D b , A d d r e s s _ A C r H A l m S p , A d d r e s s _ A C r H A l m T
m r S p , A d d r e s s _ A C r H W a r n D b , A d d r e s s _ A C r H W a r n
S p , A d d r e s s _ A C r H W a r n T m r S p , A d d r e s s _ A C r L A l m
D b , A d d r e s s _ A C r L A l m S p , A d d r e s s _ A C r L A l m T m r S
p , A d d r e s s _ A C r L W a r n D b , A d d r e s s _ A C r L W a r n S p ,
A d d r e s s _ A C r L W a r n T m r S p , A d d r e s s _ A C r T f T m r S p
, A d d r e s s _ b H a l m , A d d r e s s _ b H W a r n , A d d r e s s _ b L
A l m , A d d r e s s _ b L w a r n , A d d r e s s _ b M o d e , A d d r e s s
_ b T f A l m , A d d r e s s _ r C C m d , A d d r e s s _ r V a l ,
I am very confused as to where these spaces are coming from. Any help would be greatly appreciated.
Are you sure the CSV is not encoded with UTF-16 (using two bytes per character)?
This is the most likely reason you'd see spaces between otherwise valid ASCII characters, so try verifying the encoding first.

Resources