Skip to content

Commit 78394ba

Browse files
committed
minor changes to examples
1 parent 9e9ce7c commit 78394ba

File tree

2 files changed

+44
-51
lines changed

2 files changed

+44
-51
lines changed

files/test1.json

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22

3-
"VERSION_VARS": {
4-
"INPUTDECK_VERSION": 176,
5-
"COP_SVN_REPOSITORY": "COPERNICUS_NASA",
6-
"COP_SVN_REVISION": 7191
3+
"version": {
4+
"major": 2,
5+
"minor": 2,
6+
"patch": 1,
7+
"string": "2.2.1",
8+
"svn": 7191
79
},
8-
"SPICE_VARS": [
9-
"..\\support_files\\generic_kernels\\fk\\satellites\\moon_080317.tf.pc",
10-
"..\\support_files\\generic_kernels\\lsk\\naif0010.tls.pc",
11-
"..\\support_files\\generic_kernels\\pck\\pck00010.tpc.pc",
10+
"files": [
11+
"..\\path\\to\\files\\file1.txt",
12+
"..\\path\\to\\files\\file2.txt",
13+
"..\\path\\to\\files\\file3.txt",
1214
"test \uXXXX \uABCD \uABCD\uABCDtest",
1315
" test test test"
1416
],
@@ -21,29 +23,20 @@
2123
},
2224

2325
"empty_string": "",
24-
25-
"GLOBAL_VARS": {
26-
"MISSION_SEGMENTS": 37,
27-
"CURRENT_SEGMENT": 23,
28-
"MISSION_INFO": "",
29-
"SOLUTION_METHOD": "SNOPTA",
30-
"GLOBAL_INTEGRATOR": 0,
31-
"OUTPUT_TEXT_FORMAT": 2
32-
},
3326

34-
"SEGMENT_VARS": [
27+
"data": [
3528
{
36-
"SEG_NUMBER": 1,
29+
"number": 1,
3730
"tf1": true,
3831
"tf2": false,
39-
"SEG_NAME": "DRO",
32+
"name": "Horatio",
4033
"array": ["1","2","3"]
4134
},
4235
{
43-
"SEG_NUMBER": 2,
44-
"blah1": 33,
45-
"blah2": 2.333e2,
46-
"SEG_NAME": "MECO"
36+
"number": 2,
37+
"integer": 33,
38+
"real": 2.333e2,
39+
"name": "Nelson"
4740
}
4841
]
4942

src/json_example.f90

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ subroutine test_2()
257257

258258
!config structure:
259259
call json_value_create(inp) !an object
260-
call to_object(inp,'INPUTS')
260+
call to_object(inp,'inputs')
261261
call json_value_add(p, inp)
262262

263263
!trajectory structure:
264264
call json_value_create(traj) !an array
265-
call to_array(traj,'TRAJECTORY')
265+
call to_array(traj,'trajectory')
266266
call json_value_add(p, traj)
267267

268268
write(*,*) ''
@@ -274,8 +274,8 @@ subroutine test_2()
274274
call json_value_add(inp, 't0', 0.1_wp)
275275
call json_value_add(inp, 'tf', 1.1_wp)
276276
call json_value_add(inp, 'x0', 9999.000_wp)
277-
call json_value_add(inp, 'current_segment', 1)
278-
call json_value_add(inp, 'segment_groups', [2,4,99])
277+
call json_value_add(inp, 'integer_scalar', 1)
278+
call json_value_add(inp, 'integer_array', [2,4,99])
279279
call json_value_add(inp, 'names', ['aaa','bbb','ccc'])
280280
call json_value_add(inp, 'logical_scalar', .true.)
281281
call json_value_add(inp, 'logical_vector', [.true., .false., .true.])
@@ -326,7 +326,7 @@ subroutine add_variables_to_input(me, variable, units, frame, center, rdata)
326326

327327
!create the object before data can be added:
328328
call json_value_create(var)
329-
call to_object(var,'VARIABLE')
329+
call to_object(var,'') !name does not matter
330330

331331
!variable info:
332332
call json_value_add(var, 'VARIABLE',trim(variable))
@@ -482,67 +482,67 @@ subroutine test_1()
482482
write(*,*) 'get some data from the file...'
483483

484484
write(*,*) ''
485-
call json%get('VERSION_VARS.COP_SVN_REVISION', ival)
485+
call json%get('version.svn', ival)
486486
if (json_failed()) then
487487
call print_error_message()
488488
else
489-
write(*,*) 'VERSION_VARS.COP_SVN_REVISION = ',ival
489+
write(*,*) 'version.svn = ',ival
490490
end if
491491

492492
write(*,*) ''
493-
call json%get('SEGMENT_VARS(1).array(2)', cval)
493+
call json%get('data(1).array(2)', cval)
494494
if (json_failed()) then
495495
call print_error_message()
496496
else
497-
write(*,'(1x,A)') 'SEGMENT_VARS(1).array(2) = '//trim(cval)
497+
write(*,'(1x,A)') 'data(1).array(2) = '//trim(cval)
498498
end if
499499

500500
write(*,*) ''
501-
call json%get('SPICE_VARS(1)', cval)
501+
call json%get('files(1)', cval)
502502
if (json_failed()) then
503503
call print_error_message()
504504
else
505-
write(*,'(1x,A)') 'SPICE_VARS(1) = '//trim(cval)
505+
write(*,'(1x,A)') 'files(1) = '//trim(cval)
506506
end if
507507

508508
write(*,*) ''
509-
call json%get('SPICE_VARS(2)', cval)
509+
call json%get('files(2)', cval)
510510
if (json_failed()) then
511511
call print_error_message()
512512
else
513-
write(*,'(1x,A)') 'SPICE_VARS(2) = '//trim(cval)
513+
write(*,'(1x,A)') 'files(2) = '//trim(cval)
514514
end if
515515

516516
write(*,*) ''
517-
call json%get('SPICE_VARS(3)', cval)
517+
call json%get('files(3)', cval)
518518
if (json_failed()) then
519519
call print_error_message()
520520
else
521-
write(*,*) 'SPICE_VARS(3) = '//trim(cval)
521+
write(*,*) 'files(3) = '//trim(cval)
522522
end if
523523

524524
write(*,*) ''
525-
call json%get('SEGMENT_VARS(2).blah2', rval)
525+
call json%get('data(2).real', rval)
526526
if (json_failed()) then
527527
call print_error_message()
528528
else
529-
write(*,*) 'SEGMENT_VARS(2).blah2 = ',rval
529+
write(*,*) 'data(2).real = ',rval
530530
end if
531531

532532
write(*,*) ''
533-
call json%get('SPICE_VARS[4]', cval) !has hex characters
533+
call json%get('files[4]', cval) !has hex characters
534534
if (json_failed()) then
535535
call print_error_message()
536536
else
537-
write(*,'(1x,A)') 'SPICE_VARS[4] = '//trim(cval)
537+
write(*,'(1x,A)') 'files[4] = '//trim(cval)
538538
end if
539539

540540
write(*,*) ''
541-
call json%get('SPICE_VARS[5]', cval) !string with spaces and no escape characters
541+
call json%get('files[5]', cval) !string with spaces and no escape characters
542542
if (json_failed()) then
543543
call print_error_message()
544544
else
545-
write(*,'(1x,A)') 'SPICE_VARS[5] = '//trim(cval)
545+
write(*,'(1x,A)') 'files[5] = '//trim(cval)
546546
end if
547547

548548
!
@@ -551,19 +551,19 @@ subroutine test_1()
551551
!
552552

553553
write(*,*) ''
554-
call json%get('SPICE_VARS[10]', cval, found) !value that isn't there
554+
call json%get('files[10]', cval, found) !value that isn't there
555555
if (.not. found) then
556-
write(*,*) 'SPICE_VARS[10] not in file.'
556+
write(*,*) 'files[10] not in file.'
557557
else
558-
write(*,'(1x,A)') 'SPICE_VARS[10] = '//trim(cval)
558+
write(*,'(1x,A)') 'files[10] = '//trim(cval)
559559
end if
560560

561561
write(*,*) ''
562-
call json%get('VERSION_VARS.blah', ival, found) !value that isn't there
562+
call json%get('version.blah', ival, found) !value that isn't there
563563
if (.not. found) then
564-
write(*,*) 'VERSION_VARS.blah not in file.'
564+
write(*,*) 'version.blah not in file.'
565565
else
566-
write(*,*) 'VERSION_VARS.blah = ',ival
566+
write(*,*) 'version.blah = ',ival
567567
end if
568568

569569
end if

0 commit comments

Comments
 (0)