Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
west-public
West
Commits
16f88821
Commit
16f88821
authored
Jul 11, 2017
by
Govoni
Browse files
Added base64 to pdep_io.
parent
b0010996
Changes
14
Hide whitespace changes
Inline
Side-by-side
IO_kernel/Makefile
View file @
16f88821
...
...
@@ -6,6 +6,7 @@ include ../../make.inc
MODFLAGS
=
$(MOD_FLAG)
../../iotk/src
$(MOD_FLAG)
../../Modules
$(MOD_FLAG)
../../LAXlib
\
$(MOD_FLAG)
../../FFTXlib
$(MOD_FLAG)
../../PW/src
\
$(MOD_FLAG)
../Libraries/Json
\
$(MOD_FLAG)
../Libraries/Base64
\
$(MOD_FLAG)
../Modules
\
$(MOD_FLAG)
../Tools
\
$(MOD_FLAG)
../FFT_kernel
\
...
...
@@ -27,7 +28,7 @@ wfreq_io.o \
wfreq_restart.o
PWOBJS
=
../../PW/src/libpw.a
QEMODS
=
../../Modules/libqemod.a ../../FFTXlib/libqefft.a ../../LAXlib/libqela.a ../Libraries/Json/libjson.a
QEMODS
=
../../Modules/libqemod.a ../../FFTXlib/libqefft.a ../../LAXlib/libqela.a ../Libraries/Json/libjson.a
../Libraries/Base64/libbase64.a
TLDEPS
=
bindir mods libs pw
...
...
IO_kernel/pdep_io.f90
View file @
16f88821
...
...
@@ -15,10 +15,12 @@ MODULE pdep_io
!----------------------------------------------------------------------------
!
USE
iotk_module
USE
kinds
,
ONLY
:
DP
USE
mp_global
,
ONLY
:
me_bgrp
,
root_bgrp
,
nproc_bgrp
,
intra_bgrp_comm
,
my_pool_id
,
my_bgrp_id
,
inter_bgrp_comm
,
inter_pool_comm
USE
westcom
,
ONLY
:
npwq0
,
npwq0_g
,
npwq0x
USE
gvect
,
ONLY
:
ig_l2g
USE
kinds
,
ONLY
:
DP
USE
mp_global
,
ONLY
:
me_bgrp
,
root_bgrp
,
nproc_bgrp
,
intra_bgrp_comm
,
my_pool_id
,
my_bgrp_id
,
inter_bgrp_comm
,
inter_pool_comm
USE
westcom
,
ONLY
:
npwq0
,
npwq0_g
,
npwq0x
USE
gvect
,
ONLY
:
ig_l2g
USE
json_module
,
ONLY
:
json_file
USE
base64_module
!
IMPLICIT
NONE
!
...
...
@@ -40,10 +42,12 @@ MODULE pdep_io
CHARACTER
(
*
),
INTENT
(
IN
)
::
fname
COMPLEX
(
DP
),
INTENT
(
IN
)
::
pdepg
(
npwq0x
)
!
!
Scratch
!
Workspace
!
COMPLEX
(
DP
),
ALLOCATABLE
::
tmp_vec
(:)
INTEGER
::
iun
,
ierr
CHARACTER
(
LEN
=
:),
ALLOCATABLE
::
charbase64
INTEGER
::
nbytes
,
ndim
,
iunit
!
!
IF
(
my_pool_id
.NE.
0
)
RETURN
...
...
@@ -62,14 +66,33 @@ MODULE pdep_io
!
! ... open XML descriptor
!
CALL
iotk_free_unit
(
iun
,
ierr
)
CALL
iotk_open_write
(
iun
,
FILE
=
TRIM
(
fname
),
BINARY
=
.TRUE.
)
CALL
iotk_write_begin
(
iun
,
'PDEP_GSPACE'
)
C
ALL
iotk_write_dat
(
iun
,
"ndim"
,
npwq0_g
)
CALL
iotk_write_dat
(
iun
,
"pdep"
,
tmp_vec
(
1
:
n
pwq0_g
)
)
CALL
iotk_write_end
(
iun
,
'PDEP_GSPACE'
)
ndim
=
npwq0_g
nbytes
=
SIZEOF
(
tmp_vec
(
1
))
*
ndim
!
CALL
get_lenbase64( nbytes, lenbase64
)
ALL
OCATE
(
CHARACTER
(
LEN
=
lenbase64
(
nbytes
))
::
charbase64
)
!IF (lbigendian) CALL base64_bytesswap_complex(nbytes,
tmp_vec(1:n
dim)
)
CALL
base64_encode_complex
(
tmp_vec
(
1
:
ndim
),
ndim
,
charbase64
)
!
CALL
iotk_close_write
(
iun
)
OPEN
(
NEWUNIT
=
iunit
,
FILE
=
TRIM
(
fname
)
)
IF
(
isbigendian
()
)
THEN
WRITE
(
iunit
,
'(a,i0,a)'
)
'{ "ndim" : '
,
ndim
,
', "isbigendian" : true, "kind" : "complex", "array" :'
ELSE
WRITE
(
iunit
,
'(a,i0,a)'
)
'{ "ndim" : '
,
ndim
,
', "isbigendian" : false, "kind" : "complex", "array" :'
ENDIF
WRITE
(
iunit
,
'(a)'
)
'"'
//
charbase64
//
'"'
WRITE
(
iunit
,
'(a)'
)
'}'
CLOSE
(
iunit
)
!
DEALLOCATE
(
charbase64
)
!
!CALL iotk_free_unit( iun, ierr )
!CALL iotk_open_write( iun, FILE = TRIM(fname), BINARY = .TRUE.)
!CALL iotk_write_begin( iun, 'PDEP_GSPACE' )
!CALL iotk_write_dat( iun, "ndim" , npwq0_g )
!CALL iotk_write_dat( iun, "pdep" , tmp_vec(1:npwq0_g) )
!CALL iotk_write_end( iun, 'PDEP_GSPACE' )
!
!CALL iotk_close_write( iun )
!
END
IF
!
...
...
@@ -88,36 +111,59 @@ MODULE pdep_io
USE
mp_wave
,
ONLY
:
splitwf
USE
mp
,
ONLY
:
mp_bcast
USE
mp_global
,
ONLY
:
intra_bgrp_comm
USE
base64_module
!
! I/O
!
CHARACTER
(
*
),
INTENT
(
IN
)
::
fname
COMPLEX
(
DP
),
INTENT
(
OUT
)
::
pdepg
(
npwq0x
)
!
!
Scratch
!
Workspace
!
TYPE
(
json_file
)
::
json
COMPLEX
(
DP
),
ALLOCATABLE
::
tmp_vec
(:)
INTEGER
::
iun
,
ierr
,
ig
CHARACTER
(
LEN
=
:),
ALLOCATABLE
::
charbase64
INTEGER
::
nbytes
,
ndim
,
iunit
LOGICAL
::
found
,
isbe
!
! Resume all components
!
ALLOCATE
(
tmp_vec
(
npwq0_g
)
)
tmp_vec
=
0._DP
pdepg
=
0._DP
!
IF
(
my_pool_id
==
0.
AND
.
my_bgrp_id
==
0
)
THEN
!
! ONLY ROOT W/IN BGRP READS
!
ndim
=
npwq0_g
nbytes
=
SIZEOF
(
tmp_vec
(
1
))
*
ndim
!CALL get_lenbase64( nbytes, lenbase64 )
!ALLOCATE(CHARACTER(LEN=lenbase64) :: charbase64)
!
IF
(
me_bgrp
==
root_bgrp
)
THEN
!
CALL
json
%
initialize
()
CALL
json
%
load_file
(
filename
=
TRIM
(
fname
)
)
!
CALL
json
%
get
(
'isbigendian'
,
isbe
,
found
)
CALL
json
%
get
(
'array'
,
charbase64
,
found
)
!
! ... open XML descriptor
!
CALL
iotk_free_unit
(
iun
,
ierr
)
CALL
iotk_open_read
(
iun
,
FILE
=
TRIM
(
fname
),
BINARY
=
.TRUE.
,
IERR
=
ierr
)
CALL
iotk_scan_begin
(
iun
,
'PDEP_GSPACE'
)
CALL
iotk_scan_dat
(
iun
,
"pdep"
,
tmp_vec
(
1
:
npwq0_g
)
)
CALL
iotk_scan_end
(
iun
,
'PDEP_GSPACE'
)
CALL
iotk_close_read
(
iun
)
!CALL iotk_free_unit( iun, ierr )
!CALL iotk_open_read( iun, FILE = TRIM(fname), BINARY = .TRUE., IERR = ierr)
!CALL iotk_scan_begin( iun, 'PDEP_GSPACE' )
!CALL iotk_scan_dat( iun, "pdep" , tmp_vec(1:npwq0_g) )
!CALL iotk_scan_end( iun, 'PDEP_GSPACE' )
!CALL iotk_close_read( iun )
!
CALL
json
%
destroy
()
!
CALL
base64_decode_complex
(
charbase64
,
ndim
,
tmp_vec
(
1
:
ndim
))
IF
(
isbigendian
()
.NEQV.
isbe
)
CALL
base64_byteswap_complex
(
nbytes
,
tmp_vec
(
1
:
ndim
))
DEALLOCATE
(
charbase64
)
!
END
IF
!
...
...
Libraries/Base64/Base64.C
deleted
100644 → 0
View file @
b0010996
/*
Copyright (C) 2015-2016 M. Govoni
This file is distributed under the terms of the
GNU General Public License. See the file `License'
in the root directory of the present distribution,
or http://www.gnu.org/copyleft/gpl.txt .
This file is part of WEST.
Contributors to this file:
Huihuo Zheng
*/
#include <iostream>
#include "Base64Transcoder.h"
#include <complex>
#include "Base64.h"
using
namespace
std
;
void
Base64
::
encode
(
double
*
a
,
int
n
,
char
*
b
)
{
int
nb
=
sizeof
(
double
)
*
n
;
bt
.
encode
(
nb
,
(
unsigned
char
*
)
&
a
[
0
],
b
);
}
void
Base64
::
encode
(
complex
<
double
>
*
a
,
int
n
,
char
*
b
)
{
int
nb
=
sizeof
(
complex
<
double
>
)
*
n
;
bt
.
encode
(
nb
,
(
unsigned
char
*
)
&
a
[
0
],
b
);
}
void
Base64
::
decode
(
char
*
b
,
int
n
,
double
*
a
)
{
int
nb
=
bt
.
nchars
(
sizeof
(
double
)
*
n
);
bt
.
decode
(
nb
,
b
,
(
unsigned
char
*
)
&
a
[
0
]);
}
void
Base64
::
decode
(
char
*
b
,
int
n
,
complex
<
double
>
*
a
)
{
int
nb
=
bt
.
nchars
(
sizeof
(
complex
<
double
>
)
*
n
);
bt
.
decode
(
nb
,
b
,
(
unsigned
char
*
)
&
a
[
0
]);
}
void
Base64
::
byteswap_double
(
int
n
,
double
*
const
x
)
{
bt
.
byteswap_double
(
n
,
x
);
}
void
Base64
::
byteswap_complex
(
int
n
,
complex
<
double
>*
const
x
)
{
bt
.
byteswap_double
(
n
*
2
,
(
double
*
)
x
);
}
extern
"C"
{
#include "Base64.h"
Base64
*
Base64__new
()
{
return
new
Base64
();
}
void
Base64__encode_double
(
Base64
*
This
,
double
*
a
,
int
n
,
char
*
to
)
{
This
->
encode
(
a
,
n
,
to
);
}
void
Base64__encode_complex
(
Base64
*
This
,
complex
<
double
>
*
a
,
int
n
,
char
*
to
)
{
This
->
encode
(
a
,
n
,
to
);
}
void
Base64__decode_double
(
Base64
*
This
,
char
*
from
,
int
n
,
double
*
a
)
{
This
->
decode
(
from
,
n
,
a
);
}
void
Base64__decode_complex
(
Base64
*
This
,
char
*
from
,
int
n
,
complex
<
double
>
*
a
)
{
This
->
decode
(
from
,
n
,
a
);
}
void
Base64__byteswap_double
(
Base64
*
This
,
int
n
,
double
*
x
)
{
This
->
byteswap_double
(
n
,
x
);
}
void
Base64__byteswap_complex
(
Base64
*
This
,
int
n
,
complex
<
double
>
*
x
)
{
This
->
byteswap_complex
(
n
,
x
);
}
}
Libraries/Base64/Base64.h
deleted
100644 → 0
View file @
b0010996
/*
Copyright (C) 2015-2016 M. Govoni
This file is distributed under the terms of the
GNU General Public License. See the file `License'
in the root directory of the present distribution,
or http://www.gnu.org/copyleft/gpl.txt .
This file is part of WEST.
Contributors to this file:
Huihuo Zheng
*/
#ifndef BASE64__H__
#define BASE64__H__
#include <iostream>
#include "Base64Transcoder.h"
#include <complex>
using
namespace
std
;
class
Base64
{
Base64Transcoder
bt
;
public:
void
encode
(
double
*
a
,
int
n
,
char
*
b
);
void
decode
(
char
*
b
,
int
n
,
double
*
);
void
encode
(
complex
<
double
>
*
a
,
int
n
,
char
*
b
);
void
decode
(
char
*
b
,
int
n
,
complex
<
double
>
*
);
void
byteswap_double
(
int
n
,
double
*
const
);
void
byteswap_complex
(
int
n
,
complex
<
double
>*
const
);
};
#endif
Libraries/Base64/Base64Module.f90
View file @
16f88821
...
...
@@ -11,75 +11,77 @@
! Huihuo Zheng
!
!-------------------------------------------------------------------
module
B
ase64_module
module
b
ase64_module
!-------------------------------------------------------------------
!
USE
,
INTRINSIC
::
ISO_C_Binding
,
ONLY
:
C_DOUBLE
,
C_DOUBLE_COMPLEX
,
C_CHAR
,
C_SIGNED_CHAR
,
C_PTR
,
C_NULL_PTR
,
C_INT
!
IMPLICIT
NONE
!
TYPE
Base64_type
TYPE
(
C_PTR
)
::
object
=
C_NULL_PTR
END
TYPE
Base64_type
SAVE
!
INTEGER
::
ICHAR
LOGICAL
,
PARAMETER
::
lbigendian
=
(
ICHAR
(
TRANSFER
(
1
,
'a'
)
)
==
0
)
!
INTERFACE
!
FUNCTION
C_Base64__new
()
RESULT
(
this
)
BIND
(
C
,
NAME
=
"Base64__new"
)
IMPORT
TYPE
(
C_PTR
)
::
this
END
FUNCTION
C_Base64__new
!
FUNCTION
C_Base64__delete
(
this
)
BIND
(
C
,
NAME
=
"Base64__delete"
)
SUBROUTINE
base64_init
()
BIND
(
C
,
NAME
=
"b64init"
)
IMPORT
TYPE
(
C_PTR
),
VALUE
::
this
END
FUNCTION
C_Base64__delete
END
SUBROUTINE
!
SUBROUTINE
C_B
ase64_
_
encode_double
(
this
,
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"
Base64__
encode_double"
)
SUBROUTINE
b
ase64_encode_double
(
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"encode_double"
)
IMPORT
INTEGER
(
C_INT
),
VALUE
,
INTENT
(
IN
)
::
n
REAL
(
C_DOUBLE
),
INTENT
(
IN
)
::
from
(
*
)
CHARACTER
(
C_CHAR
),
INTENT
(
OUT
)
::
to
(
*
)
TYPE
(
C_PTR
),
VALUE
::
this
END
SUBROUTINE
C_Base64__encode_double
END
SUBROUTINE
!
SUBROUTINE
C_B
ase64_
_
decode_double
(
this
,
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"
Base64__
decode_double"
)
SUBROUTINE
b
ase64_decode_double
(
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"decode_double"
)
IMPORT
INTEGER
(
C_int
),
VALUE
,
INTENT
(
IN
)
::
n
REAL
(
C_DOUBLE
),
INTENT
(
IN
)
::
to
(
*
)
CHARACTER
(
C_CHAR
),
INTENT
(
OUT
)
::
from
(
*
)
TYPE
(
C_PTR
),
VALUE
::
this
END
SUBROUTINE
C_Base64__decode_double
END
SUBROUTINE
!
SUBROUTINE
C_B
ase64_
_
encode_complex
(
this
,
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"
Base64__
encode_complex"
)
SUBROUTINE
b
ase64_encode_complex
(
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"encode_complex"
)
IMPORT
INTEGER
(
C_INT
),
VALUE
,
INTENT
(
IN
)
::
n
COMPLEX
(
C_DOUBLE_COMPLEX
),
INTENT
(
IN
)
::
from
(
*
)
CHARACTER
(
C_CHAR
),
INTENT
(
OUT
)
::
to
(
*
)
TYPE
(
C_PTR
),
VALUE
::
this
END
SUBROUTINE
C_Base64__encode_complex
END
SUBROUTINE
!
SUBROUTINE
C_B
ase64_
_
decode_complex
(
this
,
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"
Base64__
decode_complex"
)
SUBROUTINE
b
ase64_decode_complex
(
from
,
n
,
to
)
BIND
(
C
,
NAME
=
"decode_complex"
)
IMPORT
INTEGER
(
C_INT
),
VALUE
,
INTENT
(
IN
)
::
n
COMPLEX
(
C_DOUBLE_COMPLEX
),
INTENT
(
IN
)
::
to
(
*
)
CHARACTER
(
C_CHAR
),
INTENT
(
OUT
)
::
from
(
*
)
TYPE
(
C_PTR
),
VALUE
::
this
END
SUBROUTINE
C_Base64__decode_complex
END
SUBROUTINE
!
SUBROUTINE
C_B
ase64_
_
byteswap_complex
(
this
,
n
,
to
)
BIND
(
C
,
NAME
=
"
Base64__
byteswap_complex"
)
SUBROUTINE
b
ase64_byteswap_complex
(
n
,
to
)
BIND
(
C
,
NAME
=
"byteswap_complex"
)
IMPORT
INTEGER
(
C_INT
),
VALUE
,
INTENT
(
IN
)
::
n
COMPLEX
(
C_DOUBLE_COMPLEX
),
INTENT
(
INOUT
)
::
to
(
*
)
TYPE
(
C_PTR
),
VALUE
::
this
END
SUBROUTINE
C_Base64__byteswap_complex
END
SUBROUTINE
!
SUBROUTINE
C_B
ase64_
_
byteswap_double
(
this
,
n
,
to
)
BIND
(
C
,
NAME
=
"
Base64__
byteswap_double"
)
SUBROUTINE
b
ase64_byteswap_double
(
n
,
to
)
BIND
(
C
,
NAME
=
"byteswap_double"
)
IMPORT
INTEGER
(
C_INT
),
VALUE
,
INTENT
(
IN
)
::
n
REAL
(
C_DOUBLE
),
INTENT
(
INOUT
)
::
to
(
*
)
TYPE
(
C_PTR
),
VALUE
::
this
END
SUBROUTINE
C_Base64__byteswap_double
END
SUBROUTINE
!
END
INTERFACE
!
CONTAINS
!
INTEGER
FUNCTION
lenbase64
(
nbytes
)
IMPLICIT
NONE
INTEGER
,
INTENT
(
IN
)
::
nbytes
lenbase64
=
(
(
nbytes
+
2
)
/
3
)
*
4
END
FUNCTION
!
LOGICAL
FUNCTION
isbigendian
(
)
IMPLICIT
NONE
isbigendian
=
lbigendian
END
FUNCTION
!
END
MODULE
Libraries/Base64/Base64Transcoder.h
deleted
100644 → 0
View file @
b0010996
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// Base64Transcoder.h
//
////////////////////////////////////////////////////////////////////////////////
// $Id: Base64Transcoder.h,v 1.7 2008-09-08 15:56:18 fgygi Exp $
#ifndef BASE64TRANSCODER_H
#define BASE64TRANSCODER_H
#include <iostream>
#include <cstdio>
#include <string>
typedef
unsigned
char
byte
;
class
Base64Transcoder
{
char
etable
[
64
];
// encode table
byte
dtable
[
256
];
// decode table
public:
Base64Transcoder
();
int
encode
(
int
nbytes
,
const
byte
*
const
from
,
char
*
const
to
);
int
decode
(
int
nchars
,
const
char
*
const
from
,
byte
*
const
to
);
void
byteswap_double
(
size_t
n
,
double
*
const
x
);
void
byteswap_int
(
size_t
n
,
int
*
const
x
);
int
print
(
int
nchars
,
const
char
*
const
buf
,
std
::
ostream
&
o
);
int
print
(
const
std
::
string
buf
,
std
::
ostream
&
o
);
int
print
(
int
nchars
,
const
char
*
const
buf
,
FILE
*
outfile
);
int
print
(
const
std
::
string
buf
,
FILE
*
outfile
);
// number of chars needed to encode nbytes bytes
int
nchars
(
int
nbytes
)
{
return
4
*
(
(
nbytes
+
2
)
/
3
);
}
// number of bytes needed to decode nchars chars
int
nbytes
(
int
nchars
)
{
return
3
*
(
nchars
/
4
);
}
};
#endif
Libraries/Base64/Makefile
View file @
16f88821
...
...
@@ -7,20 +7,11 @@ MODFLAGS= $(MOD_FLAG).
IFLAGS
=
BASE64_OBJS
=
\
Base64.o
\
Base64Transcoder.o
\
Base64Module.o
cbase64.o
\
base64module.o
.SUFFIXES
:
.o .c .f .f90 .C
.C.o
:
$(CC)
$(CFLAGS)
-c
$<
-lsdtc
++
#all : title tldeps libbase64.a
all
:
title libbase64.a
#tldeps:
# test -n "$(TLDEPS)" && ( cd ../.. ; $(MAKE) $(MFLAGS) $(TLDEPS) || exit 1) || :
libbase64.a
:
$(BASE64_OBJS)
$(AR)
$(ARFLAGS)
$@
$?
$(RANLIB)
$@
...
...
Libraries/Base64/
B
ase64
Transcoder.C
→
Libraries/Base64/
cb
ase64
.c
View file @
16f88821
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// Base64Transcoder.C
//
////////////////////////////////////////////////////////////////////////////////
#include "Base64Transcoder.h"
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring> // memcpy
#include <cassert>
using
namespace
std
;
////////////////////////////////////////////////////////////////////////////////
Base64Transcoder
::
Base64Transcoder
()
{
// initialize encoding/decoding tables
for
(
int
i
=
0
;
i
<
26
;
i
++
)
{
/*
! Copyright (C) 2015-2016 M. Govoni
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST. It is created based on Base64Transcoder.C in Qbox
!
! Contributors to this file:
! Huihuo Zheng
*/
#include "cbase64.h"
void
b64init
()
{
int
i
;
/// this is to initialized the encode and decode tables
for
(
i
=
0
;
i
<
26
;
i
++
)
{
etable
[
i
]
=
'A'
+
i
;
etable
[
26
+
i
]
=
'a'
+
i
;
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
i
=
0
;
i
<
10
;
i
++
)
{
etable
[
52
+
i
]
=
'0'
+
i
;
}
etable
[
62
]
=
'+'
;
etable
[
63
]
=
'/'
;
for
(
int
i
=
0
;
i
<
255
;
i
++
)
{
for
(
i
=
0
;
i
<
255
;
i
++
)
{
dtable
[
i
]
=
0x80
;
}
for
(
int
i
=
'A'
;
i
<=
'Z'
;
i
++
)
{
for
(
i
=
'A'
;
i
<=
'Z'
;
i
++
)
{
dtable
[
i
]
=
0
+
(
i
-
'A'
);
}
for
(
int
i
=
'a'
;
i
<=
'z'
;
i
++
)
{
for
(
i
=
'a'
;
i
<=
'z'
;
i
++
)
{
dtable
[
i
]
=
26
+
(
i
-
'a'
);
}
for
(
int
i
=
'0'
;
i
<=
'9'
;
i
++
)
{
for
(
i
=
'0'
;
i
<=
'9'
;
i
++
)
{
dtable
[
i
]
=
52
+
(
i
-
'0'
);
}
dtable
[
'+'
]
=
62
;
...
...
@@ -62,9 +43,7 @@ Base64Transcoder::Base64Transcoder()
dtable
[
'='
]
=
0
;
}
////////////////////////////////////////////////////////////////////////////////
int
Base64Transcoder
::
encode
(
int
nbytes
,
const
byte
*
const
from
,
char
*
const
to
)
{
int
encode
(
int
nbytes
,
const
byte
*
const
from
,
char
*
const
to
)
{
const
byte
*
fptr
=
from
;
char
*
tptr
=
to
;
...
...
@@ -105,15 +84,12 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to)
*
tptr
++
=
'='
;
*
tptr
++
=
'='
;
}
return
0
;
}
////////////////////////////////////////////////////////////////////////////////
int
Base64Transcoder
::
decode
(
const
int
nchars
,
const
char
*
const
from
,
byte
*
const
to
)
int
decode
(
int
nchars
,
const
char
*
const
from
,
byte
*
const
to
)
{
// Decode Base64 chars in array "from" into bytes in array "to"
// Decode Base64 chars in array "from" into bytes in array "to"
// White space and new lines are skipped
// extra characters at end that do not form a valid group of 4 chars are
// ignored.
...
...
@@ -236,114 +212,15 @@ int Base64Transcoder::decode(const int nchars, const char* const from,
return
tptr
-
to
;
}
////////////////////////////////////////////////////////////////////////////////
void
Base64Transcoder
::
byteswap_double
(
size_t
n
,
double
*
const
x
)
{
void
byteswap_double
(
int
n
,
double
*
const
x
)
{
if
(
n
==
0
)
return
;
unsigned
char
*
c
=
(
unsigned
char
*
)
x
;
while
(
n
--
>
0
)
{
unsigned
char
tmp
;
tmp
=
c
[
7
];
c
[
7
]
=
c
[
0
];
c
[
0
]
=
tmp
;
tmp
=
c
[
6
];
c
[
6
]
=
c
[
1
];
c
[
1
]
=
tmp
;
tmp
=
c
[
5
];
c
[
5
]
=
c
[
2
];
c
[
2
]
=
tmp
;
tmp
=
c
[
4
];
c
[
4
]
=
c
[
3
];
c
[
3
]
=
tmp
;
while
(
n
--
>
0
)
{
unsigned
char
tmp
;
tmp
=
c
[
7
];
c
[
7
]
=
c
[
0
];
c
[
0
]
=
tmp
;
tmp
=
c
[
6
];
c
[
6
]
=
c
[
1
];
c
[
1
]
=
tmp
;
tmp
=
c
[
5
];
c
[
5
]
=
c
[
2
];
c
[
2
]
=
tmp
;
tmp
=
c
[
4
];
c
[
4
]
=
c
[
3
];
c
[
3
]
=
tmp
;
c
+=
8
;
}
}
////////////////////////////////////////////////////////////////////////////////
void
Base64Transcoder
::
byteswap_int
(
size_t
n
,
int
*
const
x
)
{
if
(
n
==
0
)
return
;
unsigned
char
*
c
=
(
unsigned
char
*
)
x
;
while
(
n
--
>
0
)