1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
|
program tests_write
use etsf_io_low_level
implicit none
integer :: nArg, iargc
character(len = 256) :: path
nArg = iargc()
if (nArg > 0) then
call getarg(1, path)
else
write(path, "(A)") "."
end if
call tests_write_create(trim(path))
call tests_write_modify(trim(path))
call tests_write_dim(trim(path))
call tests_write_att_integer(trim(path))
call tests_write_att_real(trim(path))
call tests_write_att_double(trim(path))
call tests_write_att_character(trim(path))
call tests_def_var(trim(path))
call tests_write_var_integer(trim(path))
call tests_write_var_double(trim(path))
call tests_write_var_character(trim(path))
call tests_copy_all_att(trim(path))
contains
subroutine tests_write_status(name, lstat, error)
character(len = *), intent(in) :: name
logical, intent(in) :: lstat
type(etsf_io_low_error), intent(in) :: error
if (lstat) then
write(*, "(A,A,A,A)") "== ", name, repeat(" ", 68 - len(name)), "OK =="
else
write(*, "(A,A,A,A)") "== ", name, repeat(" ", 68 - len(name)), "Failed =="
call etsf_io_low_error_handle(error)
end if
end subroutine tests_write_status
subroutine tests_write_create(path)
character(len = *), intent(in) :: path
integer :: ncid, s
logical :: lstat
type(etsf_io_low_error) :: error
character(len = 80) :: title
character(len = 1024) :: history
write(*,*)
write(*,*) "Testing etsf_io_low_open_create()..."
! We test an IO error, trying to write in a hardly existing place on the disk.
call etsf_io_low_open_create(ncid, "/pouet/pouet.nc", 1.3, lstat, error_data = error)
call tests_write_status("argument filename: no write access", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_IO .and. error%target_type_id == ERROR_TYPE_OWR), error)
! We create the file with a minimal header, we will test it later.
call etsf_io_low_open_create(ncid, "open_create_t01.nc", 1.3, lstat, error_data = error)
call tests_write_status("argument filename: creation, minimal header", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We test the opening of this minimal file.
call etsf_io_low_open_read(ncid, "open_create_t01.nc", lstat, error_data = error)
call tests_write_status(" | opening test", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We create a new file with a complete header, we will test it later.
call etsf_io_low_open_create(ncid, "open_create_t02.nc", 2.0, lstat, &
& title = "Testing header", history = "Testing suite", &
& error_data = error)
call tests_write_status("argument filename: creation, full header", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We test the opening of this minimal file.
call etsf_io_low_open_read(ncid, "open_create_t02.nc", lstat, error_data = error)
call tests_write_status(" | opening test", lstat, error)
! We test the two fields title and history.
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "title", 80, title, &
& lstat, error_data = error)
call tests_write_status(" | reading title", lstat, error)
if (trim(title) /= "Testing header") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value title", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "history", 1024, history, &
& lstat, error_data = error)
call tests_write_status(" | reading history", lstat, error)
if (trim(history) /= "Testing suite") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value history", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_create
subroutine tests_write_modify(path)
character(len = *), intent(in) :: path
integer :: ncid, s
logical :: lstat
type(etsf_io_low_error) :: error
character(len = 80) :: title
character(len = 1024) :: history
write(*,*)
write(*,*) "Testing etsf_io_low_open_modify()..."
! We test an IO error, trying to modify a none existing file.
call etsf_io_low_open_modify(ncid, "pouet.nc", lstat, error_data = error)
call tests_write_status("argument filename: wrong filename", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_IO .and. error%target_type_id == ERROR_TYPE_OWR), error)
! We try to open a no valid file.
call etsf_io_low_open_modify(ncid, "tests_write", lstat, error_data = error)
call tests_write_status("argument filename: wrong file type", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_IO .and. error%target_type_id == ERROR_TYPE_OWR), error)
! We try to open a file without header.
call etsf_io_low_open_modify(ncid, path//"/open_read_t01.nc", lstat, error_data = error)
call tests_write_status("argument filename: NetCDF without header", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ .and. error%target_type_id == ERROR_TYPE_ATT), error)
! We open a file without header modification.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, error_data = error)
call tests_write_status("argument filename: NetCDF without header modification", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We open a file with header modification: title creation.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, &
& title = "Testing title" , error_data = error)
call tests_write_status("argument filename: NetCDF with title creation", lstat, error)
! We test the title.
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "title", 80, title, &
& lstat, error_data = error)
call tests_write_status(" | reading title", lstat, error)
if (trim(title) /= "Testing title") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value title", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We open a file with header modification: title modification.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, &
& title = "Modifying title" , error_data = error)
call tests_write_status("argument filename: NetCDF with title modification", lstat, error)
! We test the title.
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "title", 80, title, &
& lstat, error_data = error)
call tests_write_status(" | reading title", lstat, error)
if (trim(title) /= "Modifying title") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value title", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We open a file with header modification: history creation.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, &
& history = "Testing history" , error_data = error)
call tests_write_status("argument filename: NetCDF with history creation", lstat, error)
! We test the title.
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "history", 1024, history, &
& lstat, error_data = error)
call tests_write_status(" | reading history", lstat, error)
if (trim(history) /= "Testing history") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value history", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
! We open a file with header modification: history appending.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, &
& history = "Modifying history" , error_data = error)
call tests_write_status("argument filename: NetCDF with history updating", lstat, error)
! We test the title.
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "history", 1024, history, &
& lstat, error_data = error)
call tests_write_status(" | reading history", lstat, error)
if (trim(history) /= "Testing history"//char(10)//"Modifying history") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value: '"//trim(history)//"'"
lstat = .false.
end if
call tests_write_status(" | value history", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_modify
subroutine tests_write_dim(path)
character(len = *), intent(in) :: path
logical :: lstat
integer :: ncid, value
type(etsf_io_low_error) :: error
write(*,*)
write(*,*) "Testing etsf_io_low_write_dim()..."
! We test an IO error, trying to write a dim in a none existing file.
call etsf_io_low_write_dim(0, "pouet", 5, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_DEF .and. error%target_type_id == ERROR_TYPE_DIM), error)
! We open a file to write in.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, error_data = error)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
! We test the writing action
call etsf_io_low_write_dim(ncid, "number_of_atoms", 4, lstat, error_data = error)
call tests_write_status("argument dimname: write a new value", lstat, error)
! We test we can read and fetch the right value
call etsf_io_low_read_dim(ncid, "number_of_atoms", value, lstat, error_data = error)
call tests_write_status(" | reading dimension", lstat, error)
if (value /= 4) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%target_name = "number_of_atoms"
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking value", lstat, error)
! We test the writing action with a bad value
call etsf_io_low_write_dim(ncid, "character_string_length", -80, lstat, error_data = error)
call tests_write_status("argument value: wrong negative value", (.not. lstat), error)
! We test the over-writing action
call etsf_io_low_write_dim(ncid, "character_string_length", 80, lstat, error_data = error)
if (.not. lstat) then
write(*,*) "Abort, can't add a dimension"
return
end if
call etsf_io_low_write_dim(ncid, "character_string_length", 1, lstat, error_data = error)
call tests_write_status("argument dimname: overwriting (should fail)", (.not. lstat), error)
call etsf_io_low_write_dim(ncid, "character_string_length", 80, lstat, error_data = error)
call tests_write_status("argument dimname: overwriting (same value)", lstat, error)
! We test we can read and fetch the right value
call etsf_io_low_read_dim(ncid, "character_string_length", value, lstat, error_data = error)
call tests_write_status(" | reading dimension", lstat, error)
if (value /= 80) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking value", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_dim
subroutine tests_write_att_integer(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid, var(3)
logical :: lstat
type(etsf_io_low_error) :: error
write(*,*)
write(*,*) "Testing etsf_io_low_write_att_integer()..."
call etsf_io_low_write_att(0, etsf_io_low_global_att, "test_att_integer", &
& 2, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat), error)
call etsf_io_low_open_modify(ncid, "open_create_t02.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_integer", &
& 2, lstat, error_data = error)
call tests_write_status("argument att: good value (0D)", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_integer", &
& var(1), lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 2)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_integer_1D", &
& (/ 2, 3, 4 /), lstat, error_data = error)
call tests_write_status("argument att: good value (1D)", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_integer_1D", &
& 3, var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 2 .and. var(2) == 3 .and. var(3) == 4)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_att_integer
subroutine tests_write_att_real(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid
real :: var(3)
logical :: lstat
type(etsf_io_low_error) :: error
write(*,*)
write(*,*) "Testing etsf_io_low_write_att_real()..."
call etsf_io_low_write_att(0, etsf_io_low_global_att, "test_att_real", &
& 2., lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat), error)
call etsf_io_low_open_modify(ncid, "open_create_t02.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_real", &
& 2., lstat, error_data = error)
call tests_write_status("argument att: good value (0D)", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_real", &
& var(1), lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 2.)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_real_1D", &
& (/ 2., 3., 4. /), lstat, error_data = error)
call tests_write_status("argument att: good value (1D)", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_real_1D", &
& 3, var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 2. .and. var(2) == 3. .and. var(3) == 4.)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_att_real
subroutine tests_write_att_double(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid
double precision :: var(3)
logical :: lstat
type(etsf_io_low_error) :: error
write(*,*)
write(*,*) "Testing etsf_io_low_write_att_double()..."
call etsf_io_low_write_att(0, etsf_io_low_global_att, "test_att_double", &
& 2.d0, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat), error)
call etsf_io_low_open_modify(ncid, "open_create_t02.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_double", &
& 2.d0, lstat, error_data = error)
call tests_write_status("argument att: good value (0D)", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_double", &
& var(1), lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 2.d0)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_double_1D", &
& (/ 2.d0, 3.d0, 4.d0 /), lstat, error_data = error)
call tests_write_status("argument att: good value (1D)", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_double_1D", &
& 3, var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 2.d0 .and. var(2) == 3.d0 .and. var(3) == 4.d0)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_att_double
subroutine tests_write_att_character(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid
character(len = 80) :: var
logical :: lstat
type(etsf_io_low_error) :: error
write(*,*)
write(*,*) "Testing etsf_io_low_write_att_character()..."
call etsf_io_low_write_att(0, etsf_io_low_global_att, "test_att_character", &
& "toto", lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat), error)
call etsf_io_low_open_modify(ncid, "open_create_t02.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_write_att(ncid, etsf_io_low_global_att, "test_att_character", &
& "toto", lstat, error_data = error)
call tests_write_status("argument att: good value", lstat, error)
call etsf_io_low_read_att(ncid, etsf_io_low_global_att, "test_att_character", &
& 80, var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (trim(var) == "toto")) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_att_character
subroutine tests_def_var(path)
character(len = *), intent(in) :: path
logical :: lstat
integer :: ncid, value, ncvarid, vardims(1)
type(etsf_io_low_error) :: error
type(etsf_io_low_var_infos) :: infos
write(*,*)
write(*,*) "Testing etsf_io_low_def_var()..."
! We test an IO error, trying to write a dim in a none existing file.
call etsf_io_low_def_var(0, "pouet", NF90_INT, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_DEF .and. error%target_type_id == ERROR_TYPE_VAR), error)
! We open a file to write in.
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat, error_data = error)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
! We add a single value as variable, but wrong type
call etsf_io_low_def_var(ncid, "number_of_electrons", -2, lstat, error_data = error)
call tests_write_status("single value: wrong type", (.not. lstat), error)
! We add a single variable
call etsf_io_low_def_var(ncid, "number_of_electrons", NF90_INT, lstat, error_data = error)
call tests_write_status("single value: adding a new variable", lstat, error)
! We add single variable, but overwriting is not allowed.
call etsf_io_low_def_var(ncid, "number_of_electrons", NF90_DOUBLE, lstat, error_data = error)
call tests_write_status("single value: overwriting (should fail)", (.not. lstat), error)
! We add single variable, overwriting, with the same definition.
call etsf_io_low_def_var(ncid, "number_of_electrons", NF90_INT, lstat, error_data = error)
call tests_write_status("single value: overwriting (matching definition)", lstat, error)
! We check the definition.
call etsf_io_low_read_var_infos(ncid, "number_of_electrons", infos, lstat, error_data = error)
call tests_write_status("single value: read definition", lstat, error)
if (.not. (infos%nctype == etsf_io_low_integer .and. infos%ncshape == 0)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_VAR
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | check definition", lstat, error)
! We add an array as variable, but wrong type
call etsf_io_low_def_var(ncid, "atom_species", -2, lstat, error_data = error)
call tests_write_status("1D array: wrong type", (.not. lstat), error)
! We add a single variable, but unknown dimension
call etsf_io_low_def_var(ncid, "atom_species", NF90_INT, (/ "pouet" /), &
& lstat, error_data = error)
call tests_write_status("1D array: wrong dimension", (.not. lstat), error)
! We add a single variable
call etsf_io_low_def_var(ncid, "atom_species", NF90_INT, (/ "number_of_atoms" /), &
& lstat, error_data = error)
call tests_write_status("1D array: adding a new variable", lstat, error)
! We add single variable, but overwriting is not allowed.
call etsf_io_low_def_var(ncid, "atom_species", NF90_INT, lstat, error_data = error)
call tests_write_status("1D array: overwriting (should fail)", (.not. lstat), error)
! We add single variable, overwriting, with the same definition.
call etsf_io_low_def_var(ncid, "atom_species", NF90_INT, (/ "number_of_atoms" /), &
& lstat, error_data = error)
call tests_write_status("1D array: overwriting (matching definition)", lstat, error)
! We check the definition.
call etsf_io_low_read_var_infos(ncid, "atom_species", infos, lstat, error_data = error)
call tests_write_status("1D array: read definition", lstat, error)
if (.not. (infos%nctype == etsf_io_low_integer .and. &
& infos%ncshape == 1 .and. infos%ncdims(1) == 4)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_VAR
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | check definition", lstat, error)
! We add a 2D integer array for future testing.
call etsf_io_low_def_var(ncid, "test_integer_2d", NF90_INT, &
& (/ "number_of_atoms", "number_of_atoms" /), &
& lstat, error_data = error)
call tests_write_status("2D array: adding a new variable", lstat, error)
! We add a string as variable
call etsf_io_low_def_var(ncid, "exchange_functional", NF90_CHAR, &
& (/ "character_string_length" /), lstat, error_data = error)
call tests_write_status("string: adding a new variable", lstat, error)
! We check the definition.
call etsf_io_low_read_var_infos(ncid, "exchange_functional", infos, lstat, error_data = error)
call tests_write_status("string: read definition", lstat, error)
if (.not. (infos%nctype == etsf_io_low_character .and. &
& infos%ncshape == 1 .and. infos%ncdims(1) == 80)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_VAR
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | check definition", lstat, error)
call etsf_io_low_write_dim(ncid, "number_of_reduced_dimensions", 3, lstat, error_data = error)
! We add a 2D array as variable
call etsf_io_low_def_var(ncid, "reduced_atom_positions", NF90_DOUBLE, &
& (/ pad("number_of_reduced_dimensions"), pad("number_of_atoms") /), &
& lstat, error_data = error)
call tests_write_status("2D array: adding a new variable", lstat, error)
! We check the definition.
call etsf_io_low_read_var_infos(ncid, "reduced_atom_positions", infos, lstat, error_data = error)
call tests_write_status("2D array: read definition", lstat, error)
if (.not. (infos%nctype == etsf_io_low_double .and. &
& infos%ncshape == 2 .and. infos%ncdims(1) == 3 .and. &
& infos%ncdims(2) == 4)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_VAR
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | check definition", lstat, error)
! We add a 4D array for future testing.
call etsf_io_low_def_var(ncid, "density", NF90_DOUBLE, &
& (/ "number_of_reduced_dimensions", "number_of_reduced_dimensions", &
& "number_of_reduced_dimensions", "number_of_atoms " /), &
& lstat, error_data = error)
call tests_write_status("4D array: adding a new variable", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_def_var
subroutine tests_write_var_integer(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid
integer, target :: var(4), var2d(2, 2)
character(len = 4) :: varc
logical :: lstat
type(etsf_io_low_error) :: error
type(etsf_io_low_var_integer) :: var_gen
write(*,*)
write(*,*) "Testing etsf_io_low_write_var_integer()..."
call etsf_io_low_write_var(0, "atom_species", var, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ), error)
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_set_write_mode(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't switch to data mode"
return
end if
call etsf_io_low_write_var(ncid, "pouet", var, lstat, error_data = error)
call tests_write_status("argument varname: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ .and. error%target_type_id == ERROR_TYPE_VID), &
& error)
call etsf_io_low_write_var(ncid, "atom_species", varc, 4, lstat, error_data = error)
call tests_write_status("argument var: wrong type", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_SPEC .and. error%target_type_id == ERROR_TYPE_VAR), &
& error)
call etsf_io_low_write_var(ncid, "atom_species", var(1:3), lstat, error_data = error)
call tests_write_status("argument var: wrong dimensions", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_SPEC .and. error%target_type_id == ERROR_TYPE_ARG), &
& error)
call etsf_io_low_write_var(ncid, "number_of_electrons", 12, lstat, error_data = error)
call tests_write_status("argument var: good value (0D)", lstat, error)
call etsf_io_low_read_var(ncid, "number_of_electrons", var(1), lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 12)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
var(:) = (/ 1, 2, 3, 4 /)
call etsf_io_low_write_var(ncid, "atom_species", var, lstat, error_data = error)
call tests_write_status("argument var: good value (1D)", lstat, error)
call etsf_io_low_read_var(ncid, "atom_species", var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 1 .and. var(2) == 2 .and. var(3) == 3 .and. var(4) == 4)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
var2d = reshape((/ 4, 5, 6, 7 /), (/ 2, 2/))
call etsf_io_low_write_var(ncid, "atom_species", var2d(1:1, :), &
& lstat, error_data = error)
call tests_write_status("argument var: wrong matching (2D <-> 1D)", (.not. lstat), error)
call etsf_io_low_write_var(ncid, "atom_species", var2d, &
& lstat, error_data = error)
call tests_write_status("argument var: good matching (2D <-> 1D)", lstat, error)
call etsf_io_low_read_var(ncid, "atom_species", var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 4 .and. var(2) == 5 .and. var(3) == 6 .and. var(4) == 7)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
var = (/ 7, 5, 3, 9 /)
call etsf_io_low_write_var(ncid, "test_integer_2d", var, &
& lstat, start = (/ 1, 2, 3 /), count = (/ 0, 1, 1 /), &
& error_data = error)
call tests_write_status("argument sub: wrong size", (.not. lstat), error)
call etsf_io_low_write_var(ncid, "test_integer_2d", var, &
& lstat, start = (/ 1, 6 /), count = (/ 0, 1 /), error_data = error)
call tests_write_status("argument sub: out-of-bounds", (.not. lstat), error)
call etsf_io_low_write_var(ncid, "test_integer_2d", var(1:3), &
& lstat, start = (/ 1, 2 /), count = (/ 0, 1 /), error_data = error)
call tests_write_status("argument sub: wrong dimensions", (.not. lstat), error)
call etsf_io_low_write_var(ncid, "test_integer_2d", var, &
& lstat, start = (/ 1, 2 /), count = (/ 0, 1 /), error_data = error)
call tests_write_status("argument sub: good dimensions", lstat, error)
call etsf_io_low_read_var(ncid, "test_integer_2d", var, lstat, &
& start = (/ 1, 2 /), count = (/ 0, 1 /), error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 7 .and. var(2) == 5 .and. var(3) == 3 .and. var(4) == 9)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
var = (/ 1, 2, 3, 4 /)
var_gen%data1D => var
call etsf_io_low_write_var(ncid, "atom_species", var_gen, lstat, error_data = error)
call tests_write_status("argument var: generic pointer (1D)", lstat, error)
var(:) = 0
call etsf_io_low_read_var(ncid, "atom_species", var_gen, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1) == 1 .and. var(2) == 2 .and. var(3) == 3 .and. var(4) == 4)) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't close file"
return
end if
write(*,*)
end subroutine tests_write_var_integer
subroutine tests_write_var_double(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid, i
double precision, target :: var(3, 4), bigvar(12), density(27)
character(len = 3) :: varc(4)
logical :: lstat
type(etsf_io_low_error) :: error
type(etsf_io_low_var_double) :: var_gen
write(*,*)
write(*,*) "Testing etsf_io_low_write_var_double()..."
call etsf_io_low_write_var(0, "reduced_atom_positions", var, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ), error)
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_set_write_mode(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't switch to data mode"
return
end if
call etsf_io_low_write_var(ncid, "pouet", var, lstat, error_data = error)
call tests_write_status("argument varname: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ .and. error%target_type_id == ERROR_TYPE_VID), &
& error)
call etsf_io_low_write_var(ncid, "reduced_atom_positions", varc, 3, lstat, error_data = error)
call tests_write_status("argument var: wrong type", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_SPEC .and. error%target_type_id == ERROR_TYPE_VAR), &
& error)
call etsf_io_low_write_var(ncid, "reduced_atom_positions", var(:, 1:3), lstat, error_data = error)
call tests_write_status("argument var: wrong dimensions", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_SPEC .and. error%target_type_id == ERROR_TYPE_ARG), &
& error)
var = reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 /), (/ 3, 4 /))
call etsf_io_low_write_var(ncid, "reduced_atom_positions", var, lstat, error_data = error)
call tests_write_status("argument var: good value (2D)", lstat, error)
call etsf_io_low_read_var(ncid, "reduced_atom_positions", var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1, 1) == 1 .and. var(2, 1) == 2 .and. var(3, 1) == 3 .and. &
& var(1, 2) == 4 .and. var(2, 2) == 5 .and. var(3, 2) == 6 .and. &
& var(1, 3) == 7 .and. var(2, 3) == 8 .and. var(3, 3) == 9 .and. &
& var(1, 4) == 10 .and. var(2, 4) == 11 .and. var(3, 4) == 12) ) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
bigvar = (/ 1d0, 2d0, 3d0, 4d0, 5d0, 6d0, 7d0, 8d0, 9d0, 10d0, 11d0, 0.5d0 /)
call etsf_io_low_write_var(ncid, "reduced_atom_positions", bigvar(1:10), &
& lstat, error_data = error)
call tests_write_status("argument var: wrong matching (2D <-> 1D)", (.not. lstat), error)
call etsf_io_low_write_var(ncid, "reduced_atom_positions", bigvar, &
& lstat, error_data = error)
call tests_write_status("argument var: good matching (2D <-> 1D)", lstat, error)
call etsf_io_low_read_var(ncid, "reduced_atom_positions", var, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1, 1) == 1 .and. var(2, 1) == 2 .and. var(3, 1) == 3 .and. &
& var(1, 2) == 4 .and. var(2, 2) == 5 .and. var(3, 2) == 6 .and. &
& var(1, 3) == 7 .and. var(2, 3) == 8 .and. var(3, 3) == 9 .and. &
& var(1, 4) == 10 .and. var(2, 4) == 11 .and. var(3, 4) == 0.5d0) ) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
density = (/ (-real(i) / 2.d0, i = 1, 27) /)
call etsf_io_low_write_var(ncid, "density", density, &
& lstat, start = (/ 1, 1, 1, 2 /), count = (/ 0, 0, 0, 1 /), &
& error_data = error)
call tests_write_status("argument var + sub: good matching (3D <-> 1D)", lstat, error)
call etsf_io_low_read_var(ncid, "density", density, lstat, &
& start = (/ 1, 1, 1, 2 /), count = (/ 0, 0, 0, 1 /), &
& error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (density(1) == -0.5d0 .and. density(2) == -1.d0 .and. density(3) == -1.5d0) ) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
var = reshape((/ (real(i) / 2.d0, i = 1, 12) /), (/ 3, 4 /))
var_gen%data2D => var
call etsf_io_low_write_var(ncid, "reduced_atom_positions", var_gen, lstat, error_data = error)
call tests_write_status("argument var: generic pointer (2D)", lstat, error)
var(:, :) = 0.d0
call etsf_io_low_read_var(ncid, "reduced_atom_positions", var_gen, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
if (.not. (var(1, 1) == 0.5d0 .and. var(2, 1) == 1.d0 .and. var(3, 1) == 1.5d0 .and. &
& var(1, 2) == 2.d0 .and. var(2, 2) == 2.5d0 .and. var(3, 2) == 3.d0 .and. &
& var(1, 3) == 3.5d0 .and. var(2, 3) == 4.d0 .and. var(3, 3) == 4.5d0 .and. &
& var(1, 4) == 5.d0 .and. var(2, 4) == 5.5d0 .and. var(3, 4) == 6.d0) ) then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
write(*,*)
end subroutine tests_write_var_double
subroutine tests_write_var_character(path)
character(len = *), intent(in) :: path
integer :: ncid, ncvarid, pos
character(len = 80) :: var
integer :: vari(80)
logical :: lstat
type(etsf_io_low_error) :: error
write(*,*)
write(*,*) "Testing etsf_io_low_write_var_character()..."
call etsf_io_low_write_var(0, "exchange_functional", var, 80, lstat, error_data = error)
call tests_write_status("argument ncid: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ), error)
call etsf_io_low_open_modify(ncid, "open_create_t01.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file"
return
end if
call etsf_io_low_set_write_mode(ncid, lstat)
if (.not. lstat) then
write(*,*) "Abort, can't switch to data mode"
return
end if
call etsf_io_low_write_var(ncid, "pouet", var, 80, lstat, error_data = error)
call tests_write_status("argument varname: wrong value", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_INQ .and. error%target_type_id == ERROR_TYPE_VID), &
& error)
call etsf_io_low_write_var(ncid, "exchange_functional", vari, lstat, error_data = error)
call tests_write_status("argument var: wrong type", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_SPEC .and. error%target_type_id == ERROR_TYPE_VAR), &
& error)
call etsf_io_low_write_var(ncid, "exchange_functional", var(1:50), 50, lstat, error_data = error)
call tests_write_status("argument var: wrong dimensions", (.not. lstat .and. &
& error%access_mode_id == ERROR_MODE_SPEC .and. error%target_type_id == ERROR_TYPE_ARG), &
& error)
write(var, "(A)") "This is a wonderful functional"
call etsf_io_low_write_var(ncid, "exchange_functional", var, 80, lstat, error_data = error)
call tests_write_status("argument var: good value (one string)", lstat, error)
call etsf_io_low_read_var(ncid, "exchange_functional", var, 80, lstat, error_data = error)
call tests_write_status(" | reading variable", lstat, error)
pos = index(var, char(0))
if (pos > 0) then
var(pos:len(var)) = repeat(" ", len(var) - pos + 1)
end if
if (trim(var) /= "This is a wonderful functional") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | checking values", lstat, error)
call etsf_io_low_close(ncid, lstat)
write(*,*)
end subroutine tests_write_var_character
subroutine tests_copy_all_att(path)
character(len = *), intent(in) :: path
integer :: ncid_from, ncid_to, ncvarid_from, ncvarid_to1, ncvarid_to2
logical :: lstat
type(etsf_io_low_error) :: error
type(etsf_io_low_var_infos) :: var_infos
character(len = 80) :: title
write(*,*)
write(*,*) "Testing etsf_io_low_copy_all_att()..."
call etsf_io_low_copy_all_att(0, 0, 0, 0, lstat, error_data = error)
call tests_write_status("argument ncid_from: wrong value", (.not. lstat), error)
call etsf_io_low_open_read(ncid_from, path//"/check_var_t01.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file from"
return
end if
call etsf_io_low_copy_all_att(ncid_from, 0, 0, 0, lstat, error_data = error)
call tests_write_status("argument ncid_to: wrong value", (.not. lstat), error)
call etsf_io_low_open_modify(ncid_to, "open_create_t01.nc", lstat)
if (.not. lstat) then
write(*,*) "Abort, can't open file to"
return
end if
call etsf_io_low_copy_all_att(ncid_from, ncid_to, -1, 0, lstat, error_data = error)
call tests_write_status("argument ncvarid_from: wrong value", (.not. lstat), error)
call etsf_io_low_copy_all_att(ncid_from, ncid_to, etsf_io_low_global_att, &
& -1, lstat, error_data = error)
call tests_write_status("argument ncvarid_to: wrong value", (.not. lstat), error)
call etsf_io_low_copy_all_att(ncid_from, ncid_to, etsf_io_low_global_att, &
& etsf_io_low_global_att, lstat, error_data = error)
call tests_write_status("global attribute: valid copy", lstat, error)
call etsf_io_low_read_att(ncid_to, etsf_io_low_global_att, "title", 80, title, &
& lstat, error_data = error)
call tests_write_status(" | reading title", lstat, error)
if (trim(title) /= "Silane molecule generated by ncgen.") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value title", lstat, error)
call etsf_io_low_read_var_infos(ncid_from, "atom_species_names", var_infos, lstat, &
& error_data = error)
if (.not. lstat) then
write(*,*) "Abort, can't find variable 'atom_species_names'"
return
end if
ncvarid_from = var_infos%ncid
call etsf_io_low_read_var_infos(ncid_to, "exchange_functional", var_infos, lstat, &
& error_data = error)
if (.not. lstat) then
write(*,*) "Abort, can't find variable 'exchange_functional'"
return
end if
ncvarid_to1 = var_infos%ncid
call etsf_io_low_read_var_infos(ncid_to, "number_of_electrons", var_infos, lstat, &
& error_data = error)
if (.not. lstat) then
write(*,*) "Abort, can't find variable 'number_of_electrons'"
return
end if
ncvarid_to2 = var_infos%ncid
call etsf_io_low_copy_all_att(ncid_from, ncid_to, etsf_io_low_global_att, &
& ncvarid_to2, lstat, error_data = error)
call tests_write_status("global attribute to variable: valid copy", lstat, error)
call etsf_io_low_read_att(ncid_to, etsf_io_low_global_att, "title", 80, title, &
& lstat, error_data = error)
call tests_write_status(" | reading title", lstat, error)
if (trim(title) /= "Silane molecule generated by ncgen.") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value title", lstat, error)
call etsf_io_low_copy_all_att(ncid_from, ncid_to, ncvarid_from, &
& ncvarid_to1, lstat, error_data = error)
call tests_write_status("variable attribute to variable: valid copy", lstat, error)
call etsf_io_low_read_att(ncid_to, ncvarid_to1, "units", 80, title, &
& lstat, error_data = error)
call tests_write_status(" | reading attribute", lstat, error)
if (trim(title) /= "pouet") then
error%access_mode_id = ERROR_MODE_SPEC
error%target_type_id = ERROR_TYPE_ATT
error%error_message = "wrong value"
lstat = .false.
end if
call tests_write_status(" | value units", lstat, error)
call etsf_io_low_close(ncid_from, lstat)
call etsf_io_low_close(ncid_to, lstat)
write(*,*)
end subroutine tests_copy_all_att
end program tests_write
|