Commit 09f9c899 authored by Marco Govoni's avatar Marco Govoni
Browse files

Merge branch 'json-test' into 'develop'

Json test

See merge request west-devel/West!12
parents e673db1f 346fc3fe
# Makefile for Json-test
include ../../../make.inc
# location of needed modules
MODFLAGS= $(MOD_FLAG)../Json \
$(MOD_FLAG).
IFLAGS=
JSONTEST_OBJS = \
test.o
JSON_OBJS = ../Json/libjson.a
TLDEPS= bindir mods libs pw
#all : title tldeps wstat.x
all : title test.x
test.x : $(JSONTEST_OBJS) $(LIBOBJS)
$(LD) $(LDFLAGS) -o test.x \
$(JSONTEST_OBJS) $(JSON_OBJS) $(LIBOBJS) $(LIBS)
- ./test.x
- python check.py
clean :
- /bin/rm -f *.x *.o *.a *~ *_tmp.f90 *.d *.mod *.i *.L *.json
title :
@echo " "
@echo "##############"
@echo "# JSON test ##"
@echo "##############"
@echo " "
include make.depend
from __future__ import print_function
import json
with open('input_file.json',"r") as file:
idata = json.load(file)
with open('output_file.json',"r") as file:
odata = json.load(file)
assert( idata == odata )
print("Test passed.")
bar.o : ../../Modules/io_global.o
bar.o : ../../Modules/kind.o
bar.o : io_push.o
destroy_pw_arrays.o : ../../Modules/becmod.o
destroy_pw_arrays.o : ../../Modules/constants.o
destroy_pw_arrays.o : ../../Modules/control_flags.o
destroy_pw_arrays.o : ../../Modules/fft_base.o
destroy_pw_arrays.o : ../../Modules/funct.o
destroy_pw_arrays.o : ../../Modules/io_files.o
destroy_pw_arrays.o : ../../Modules/io_global.o
destroy_pw_arrays.o : ../../Modules/kind.o
destroy_pw_arrays.o : ../../Modules/mp.o
destroy_pw_arrays.o : ../../Modules/mp_global.o
destroy_pw_arrays.o : ../../Modules/noncol.o
destroy_pw_arrays.o : ../../Modules/uspp.o
destroy_pw_arrays.o : ../../Modules/wavefunctions.o
destroy_pw_arrays.o : ../../PW/src/buffers.o
destroy_pw_arrays.o : ../../PW/src/newd.o
destroy_pw_arrays.o : ../../PW/src/pwcom.o
destroy_pw_arrays.o : ../../PW/src/scf_mod.o
do_setup.o : ../../Modules/cell_base.o
do_setup.o : ../../Modules/constants.o
do_setup.o : ../../Modules/control_flags.o
do_setup.o : ../../Modules/io_global.o
do_setup.o : ../../Modules/kind.o
do_setup.o : ../../Modules/mp.o
do_setup.o : ../../Modules/mp_global.o
do_setup.o : ../../Modules/noncol.o
do_setup.o : ../../PW/src/pwcom.o
do_setup.o : io_push.o
get_alpha_pv.o : ../../Modules/kind.o
get_alpha_pv.o : ../../Modules/mp.o
get_alpha_pv.o : ../../Modules/mp_global.o
get_alpha_pv.o : ../../PW/src/pwcom.o
get_nbndval.o : ../../Modules/constants.o
get_nbndval.o : ../../Modules/io_global.o
get_nbndval.o : ../../Modules/kind.o
get_nbndval.o : ../../Modules/noncol.o
get_nbndval.o : ../../PW/src/pwcom.o
human_readable_time.o : ../../Modules/kind.o
init_pw_arrays.o : ../../Modules/becmod.o
init_pw_arrays.o : ../../Modules/constants.o
init_pw_arrays.o : ../../Modules/control_flags.o
init_pw_arrays.o : ../../Modules/fft_base.o
init_pw_arrays.o : ../../Modules/funct.o
init_pw_arrays.o : ../../Modules/io_files.o
init_pw_arrays.o : ../../Modules/io_global.o
init_pw_arrays.o : ../../Modules/kind.o
init_pw_arrays.o : ../../Modules/mp.o
init_pw_arrays.o : ../../Modules/mp_global.o
init_pw_arrays.o : ../../Modules/noncol.o
init_pw_arrays.o : ../../Modules/uspp.o
init_pw_arrays.o : ../../Modules/wavefunctions.o
init_pw_arrays.o : ../../PW/src/buffers.o
init_pw_arrays.o : ../../PW/src/newd.o
init_pw_arrays.o : ../../PW/src/pwcom.o
init_pw_arrays.o : ../../PW/src/scf_mod.o
io_push.o : ../../Modules/io_global.o
io_push.o : ../../Modules/kind.o
linear_algebra_kernel.o : ../../Modules/kind.o
set_iks_l2g.o : ../../Modules/kind.o
set_iks_l2g.o : ../../Modules/mp.o
set_iks_l2g.o : ../../Modules/mp_global.o
set_iks_l2g.o : ../../PW/src/pwcom.o
set_iks_l2g.o : ../../West/Modules/westcom.o
set_isz.o : ../../Modules/cell_base.o
set_isz.o : ../../Modules/constants.o
set_isz.o : ../../Modules/kind.o
set_isz.o : ../../West/Modules/westcom.o
PROGRAM test
USE json_module, ONLY : json_file
INTEGER, PARAMETER :: DP = selected_real_kind(14,200)
TYPE(json_file) :: json
INTEGER :: i
INTEGER :: iiarg, nargs
INTEGER :: numsp
LOGICAL :: found
CHARACTER(LEN=512) :: input_file
CHARACTER(LEN=:),ALLOCATABLE :: cval
REAL(DP) :: rval
INTEGER :: ival
INTEGER,ALLOCATABLE :: ivec(:)
REAL(DP),ALLOCATABLE :: rvec(:)
LOGICAL :: lval
!
INTEGER :: iunit
INTEGER :: i0, i0_
!
CHARACTER(LEN=512),PARAMETER :: ifile="input_file.json"
CHARACTER(LEN=512),PARAMETER :: ofile="output_file.json"
!
! INIT INPUT FILE
!
OPEN( NEWUNIT=iunit, FILE=TRIM(ifile) )
WRITE( iunit, * ) '{ "test" : { "i0" : 100} }'
CLOSE( iunit )
!
! INIT OUTPUT FILE
!
OPEN( NEWUNIT=iunit, FILE=TRIM(ofile) )
WRITE( iunit, * ) '{}'
CLOSE( iunit )
!
! READ
!
CALL json%initialize()
CALL json%load_file(filename = TRIM(ifile))
CALL json%get('test.i0', i0, found)
i0_ = 0
IF( found ) i0_ = i0
CALL json%destroy()
!
! WRITE
!
CALL json%initialize()
CALL json%load_file(filename = TRIM(ofile))
CALL json%add('test.i0', i0_)
!
OPEN( NEWUNIT=iunit, FILE=TRIM(ofile) )
CALL json%print_file( iunit )
CLOSE( iunit )
CALL json%destroy()
END PROGRAM
......@@ -4,6 +4,8 @@ default: all
all: title json_do base64_do
test: json_test_do
json_do:
if test -d Json ; then \
( cd Json ; if test "$(MAKE)" = "" ; then make $(MFLAGS) all; \
......@@ -14,7 +16,12 @@ base64_do:
( cd Base64 ; if test "$(MAKE)" = "" ; then make $(MFLAGS) all; \
else $(MAKE) $(MFLAGS) all ; fi ) ; fi
clean: json_undo base64_undo
json_test_do:
if test -d Json-test ; then \
( cd Json-test ; if test "$(MAKE)" = "" ; then make $(MFLAGS) all; \
else $(MAKE) $(MFLAGS) all ; fi ) ; fi
clean: json_undo base64_undo json_test_undo
json_undo:
if test -d Json ; then \
......@@ -26,6 +33,11 @@ base64_undo:
( cd Base64 ; if test "$(MAKE)" = "" ; then make clean ; \
else $(MAKE) clean ; fi ) ; fi
json_test_undo:
if test -d Json-test ; then \
( cd Json-test ; if test "$(MAKE)" = "" ; then make clean ; \
else $(MAKE) clean ; fi ) ; fi
distclean: clean
title :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment