Skip to content

Commit d048371

Browse files
committed
Deploying to stdlib-fpm from @ 10f9438 🚀
1 parent 5dd3a7e commit d048371

File tree

2 files changed

+119
-33
lines changed

2 files changed

+119
-33
lines changed

src/stdlib_io_npy_save.f90

Lines changed: 96 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ module subroutine save_npy_rsp_1(filename, array, iostat, iomsg)
123123
end if
124124

125125
if (present(iomsg)) then
126-
iomsg = "Failed to write array to file '"//filename//"'"
126+
if (stat /= 0) then
127+
iomsg = "Failed to write array to file '"//filename//"'"
128+
end if
127129
end if
128130
end subroutine save_npy_rsp_1
129131
!> Save 2-dimensional array in npy format
@@ -156,7 +158,9 @@ module subroutine save_npy_rsp_2(filename, array, iostat, iomsg)
156158
end if
157159

158160
if (present(iomsg)) then
159-
iomsg = "Failed to write array to file '"//filename//"'"
161+
if (stat /= 0) then
162+
iomsg = "Failed to write array to file '"//filename//"'"
163+
end if
160164
end if
161165
end subroutine save_npy_rsp_2
162166
!> Save 3-dimensional array in npy format
@@ -189,7 +193,9 @@ module subroutine save_npy_rsp_3(filename, array, iostat, iomsg)
189193
end if
190194

191195
if (present(iomsg)) then
192-
iomsg = "Failed to write array to file '"//filename//"'"
196+
if (stat /= 0) then
197+
iomsg = "Failed to write array to file '"//filename//"'"
198+
end if
193199
end if
194200
end subroutine save_npy_rsp_3
195201
!> Save 4-dimensional array in npy format
@@ -222,7 +228,9 @@ module subroutine save_npy_rsp_4(filename, array, iostat, iomsg)
222228
end if
223229

224230
if (present(iomsg)) then
225-
iomsg = "Failed to write array to file '"//filename//"'"
231+
if (stat /= 0) then
232+
iomsg = "Failed to write array to file '"//filename//"'"
233+
end if
226234
end if
227235
end subroutine save_npy_rsp_4
228236
!> Save 1-dimensional array in npy format
@@ -255,7 +263,9 @@ module subroutine save_npy_rdp_1(filename, array, iostat, iomsg)
255263
end if
256264

257265
if (present(iomsg)) then
258-
iomsg = "Failed to write array to file '"//filename//"'"
266+
if (stat /= 0) then
267+
iomsg = "Failed to write array to file '"//filename//"'"
268+
end if
259269
end if
260270
end subroutine save_npy_rdp_1
261271
!> Save 2-dimensional array in npy format
@@ -288,7 +298,9 @@ module subroutine save_npy_rdp_2(filename, array, iostat, iomsg)
288298
end if
289299

290300
if (present(iomsg)) then
291-
iomsg = "Failed to write array to file '"//filename//"'"
301+
if (stat /= 0) then
302+
iomsg = "Failed to write array to file '"//filename//"'"
303+
end if
292304
end if
293305
end subroutine save_npy_rdp_2
294306
!> Save 3-dimensional array in npy format
@@ -321,7 +333,9 @@ module subroutine save_npy_rdp_3(filename, array, iostat, iomsg)
321333
end if
322334

323335
if (present(iomsg)) then
324-
iomsg = "Failed to write array to file '"//filename//"'"
336+
if (stat /= 0) then
337+
iomsg = "Failed to write array to file '"//filename//"'"
338+
end if
325339
end if
326340
end subroutine save_npy_rdp_3
327341
!> Save 4-dimensional array in npy format
@@ -354,7 +368,9 @@ module subroutine save_npy_rdp_4(filename, array, iostat, iomsg)
354368
end if
355369

356370
if (present(iomsg)) then
357-
iomsg = "Failed to write array to file '"//filename//"'"
371+
if (stat /= 0) then
372+
iomsg = "Failed to write array to file '"//filename//"'"
373+
end if
358374
end if
359375
end subroutine save_npy_rdp_4
360376
!> Save 1-dimensional array in npy format
@@ -387,7 +403,9 @@ module subroutine save_npy_iint8_1(filename, array, iostat, iomsg)
387403
end if
388404

389405
if (present(iomsg)) then
390-
iomsg = "Failed to write array to file '"//filename//"'"
406+
if (stat /= 0) then
407+
iomsg = "Failed to write array to file '"//filename//"'"
408+
end if
391409
end if
392410
end subroutine save_npy_iint8_1
393411
!> Save 2-dimensional array in npy format
@@ -420,7 +438,9 @@ module subroutine save_npy_iint8_2(filename, array, iostat, iomsg)
420438
end if
421439

422440
if (present(iomsg)) then
423-
iomsg = "Failed to write array to file '"//filename//"'"
441+
if (stat /= 0) then
442+
iomsg = "Failed to write array to file '"//filename//"'"
443+
end if
424444
end if
425445
end subroutine save_npy_iint8_2
426446
!> Save 3-dimensional array in npy format
@@ -453,7 +473,9 @@ module subroutine save_npy_iint8_3(filename, array, iostat, iomsg)
453473
end if
454474

455475
if (present(iomsg)) then
456-
iomsg = "Failed to write array to file '"//filename//"'"
476+
if (stat /= 0) then
477+
iomsg = "Failed to write array to file '"//filename//"'"
478+
end if
457479
end if
458480
end subroutine save_npy_iint8_3
459481
!> Save 4-dimensional array in npy format
@@ -486,7 +508,9 @@ module subroutine save_npy_iint8_4(filename, array, iostat, iomsg)
486508
end if
487509

488510
if (present(iomsg)) then
489-
iomsg = "Failed to write array to file '"//filename//"'"
511+
if (stat /= 0) then
512+
iomsg = "Failed to write array to file '"//filename//"'"
513+
end if
490514
end if
491515
end subroutine save_npy_iint8_4
492516
!> Save 1-dimensional array in npy format
@@ -519,7 +543,9 @@ module subroutine save_npy_iint16_1(filename, array, iostat, iomsg)
519543
end if
520544

521545
if (present(iomsg)) then
522-
iomsg = "Failed to write array to file '"//filename//"'"
546+
if (stat /= 0) then
547+
iomsg = "Failed to write array to file '"//filename//"'"
548+
end if
523549
end if
524550
end subroutine save_npy_iint16_1
525551
!> Save 2-dimensional array in npy format
@@ -552,7 +578,9 @@ module subroutine save_npy_iint16_2(filename, array, iostat, iomsg)
552578
end if
553579

554580
if (present(iomsg)) then
555-
iomsg = "Failed to write array to file '"//filename//"'"
581+
if (stat /= 0) then
582+
iomsg = "Failed to write array to file '"//filename//"'"
583+
end if
556584
end if
557585
end subroutine save_npy_iint16_2
558586
!> Save 3-dimensional array in npy format
@@ -585,7 +613,9 @@ module subroutine save_npy_iint16_3(filename, array, iostat, iomsg)
585613
end if
586614

587615
if (present(iomsg)) then
588-
iomsg = "Failed to write array to file '"//filename//"'"
616+
if (stat /= 0) then
617+
iomsg = "Failed to write array to file '"//filename//"'"
618+
end if
589619
end if
590620
end subroutine save_npy_iint16_3
591621
!> Save 4-dimensional array in npy format
@@ -618,7 +648,9 @@ module subroutine save_npy_iint16_4(filename, array, iostat, iomsg)
618648
end if
619649

620650
if (present(iomsg)) then
621-
iomsg = "Failed to write array to file '"//filename//"'"
651+
if (stat /= 0) then
652+
iomsg = "Failed to write array to file '"//filename//"'"
653+
end if
622654
end if
623655
end subroutine save_npy_iint16_4
624656
!> Save 1-dimensional array in npy format
@@ -651,7 +683,9 @@ module subroutine save_npy_iint32_1(filename, array, iostat, iomsg)
651683
end if
652684

653685
if (present(iomsg)) then
654-
iomsg = "Failed to write array to file '"//filename//"'"
686+
if (stat /= 0) then
687+
iomsg = "Failed to write array to file '"//filename//"'"
688+
end if
655689
end if
656690
end subroutine save_npy_iint32_1
657691
!> Save 2-dimensional array in npy format
@@ -684,7 +718,9 @@ module subroutine save_npy_iint32_2(filename, array, iostat, iomsg)
684718
end if
685719

686720
if (present(iomsg)) then
687-
iomsg = "Failed to write array to file '"//filename//"'"
721+
if (stat /= 0) then
722+
iomsg = "Failed to write array to file '"//filename//"'"
723+
end if
688724
end if
689725
end subroutine save_npy_iint32_2
690726
!> Save 3-dimensional array in npy format
@@ -717,7 +753,9 @@ module subroutine save_npy_iint32_3(filename, array, iostat, iomsg)
717753
end if
718754

719755
if (present(iomsg)) then
720-
iomsg = "Failed to write array to file '"//filename//"'"
756+
if (stat /= 0) then
757+
iomsg = "Failed to write array to file '"//filename//"'"
758+
end if
721759
end if
722760
end subroutine save_npy_iint32_3
723761
!> Save 4-dimensional array in npy format
@@ -750,7 +788,9 @@ module subroutine save_npy_iint32_4(filename, array, iostat, iomsg)
750788
end if
751789

752790
if (present(iomsg)) then
753-
iomsg = "Failed to write array to file '"//filename//"'"
791+
if (stat /= 0) then
792+
iomsg = "Failed to write array to file '"//filename//"'"
793+
end if
754794
end if
755795
end subroutine save_npy_iint32_4
756796
!> Save 1-dimensional array in npy format
@@ -783,7 +823,9 @@ module subroutine save_npy_iint64_1(filename, array, iostat, iomsg)
783823
end if
784824

785825
if (present(iomsg)) then
786-
iomsg = "Failed to write array to file '"//filename//"'"
826+
if (stat /= 0) then
827+
iomsg = "Failed to write array to file '"//filename//"'"
828+
end if
787829
end if
788830
end subroutine save_npy_iint64_1
789831
!> Save 2-dimensional array in npy format
@@ -816,7 +858,9 @@ module subroutine save_npy_iint64_2(filename, array, iostat, iomsg)
816858
end if
817859

818860
if (present(iomsg)) then
819-
iomsg = "Failed to write array to file '"//filename//"'"
861+
if (stat /= 0) then
862+
iomsg = "Failed to write array to file '"//filename//"'"
863+
end if
820864
end if
821865
end subroutine save_npy_iint64_2
822866
!> Save 3-dimensional array in npy format
@@ -849,7 +893,9 @@ module subroutine save_npy_iint64_3(filename, array, iostat, iomsg)
849893
end if
850894

851895
if (present(iomsg)) then
852-
iomsg = "Failed to write array to file '"//filename//"'"
896+
if (stat /= 0) then
897+
iomsg = "Failed to write array to file '"//filename//"'"
898+
end if
853899
end if
854900
end subroutine save_npy_iint64_3
855901
!> Save 4-dimensional array in npy format
@@ -882,7 +928,9 @@ module subroutine save_npy_iint64_4(filename, array, iostat, iomsg)
882928
end if
883929

884930
if (present(iomsg)) then
885-
iomsg = "Failed to write array to file '"//filename//"'"
931+
if (stat /= 0) then
932+
iomsg = "Failed to write array to file '"//filename//"'"
933+
end if
886934
end if
887935
end subroutine save_npy_iint64_4
888936
!> Save 1-dimensional array in npy format
@@ -915,7 +963,9 @@ module subroutine save_npy_csp_1(filename, array, iostat, iomsg)
915963
end if
916964

917965
if (present(iomsg)) then
918-
iomsg = "Failed to write array to file '"//filename//"'"
966+
if (stat /= 0) then
967+
iomsg = "Failed to write array to file '"//filename//"'"
968+
end if
919969
end if
920970
end subroutine save_npy_csp_1
921971
!> Save 2-dimensional array in npy format
@@ -948,7 +998,9 @@ module subroutine save_npy_csp_2(filename, array, iostat, iomsg)
948998
end if
949999

9501000
if (present(iomsg)) then
951-
iomsg = "Failed to write array to file '"//filename//"'"
1001+
if (stat /= 0) then
1002+
iomsg = "Failed to write array to file '"//filename//"'"
1003+
end if
9521004
end if
9531005
end subroutine save_npy_csp_2
9541006
!> Save 3-dimensional array in npy format
@@ -981,7 +1033,9 @@ module subroutine save_npy_csp_3(filename, array, iostat, iomsg)
9811033
end if
9821034

9831035
if (present(iomsg)) then
984-
iomsg = "Failed to write array to file '"//filename//"'"
1036+
if (stat /= 0) then
1037+
iomsg = "Failed to write array to file '"//filename//"'"
1038+
end if
9851039
end if
9861040
end subroutine save_npy_csp_3
9871041
!> Save 4-dimensional array in npy format
@@ -1014,7 +1068,9 @@ module subroutine save_npy_csp_4(filename, array, iostat, iomsg)
10141068
end if
10151069

10161070
if (present(iomsg)) then
1017-
iomsg = "Failed to write array to file '"//filename//"'"
1071+
if (stat /= 0) then
1072+
iomsg = "Failed to write array to file '"//filename//"'"
1073+
end if
10181074
end if
10191075
end subroutine save_npy_csp_4
10201076
!> Save 1-dimensional array in npy format
@@ -1047,7 +1103,9 @@ module subroutine save_npy_cdp_1(filename, array, iostat, iomsg)
10471103
end if
10481104

10491105
if (present(iomsg)) then
1050-
iomsg = "Failed to write array to file '"//filename//"'"
1106+
if (stat /= 0) then
1107+
iomsg = "Failed to write array to file '"//filename//"'"
1108+
end if
10511109
end if
10521110
end subroutine save_npy_cdp_1
10531111
!> Save 2-dimensional array in npy format
@@ -1080,7 +1138,9 @@ module subroutine save_npy_cdp_2(filename, array, iostat, iomsg)
10801138
end if
10811139

10821140
if (present(iomsg)) then
1083-
iomsg = "Failed to write array to file '"//filename//"'"
1141+
if (stat /= 0) then
1142+
iomsg = "Failed to write array to file '"//filename//"'"
1143+
end if
10841144
end if
10851145
end subroutine save_npy_cdp_2
10861146
!> Save 3-dimensional array in npy format
@@ -1113,7 +1173,9 @@ module subroutine save_npy_cdp_3(filename, array, iostat, iomsg)
11131173
end if
11141174

11151175
if (present(iomsg)) then
1116-
iomsg = "Failed to write array to file '"//filename//"'"
1176+
if (stat /= 0) then
1177+
iomsg = "Failed to write array to file '"//filename//"'"
1178+
end if
11171179
end if
11181180
end subroutine save_npy_cdp_3
11191181
!> Save 4-dimensional array in npy format
@@ -1146,7 +1208,9 @@ module subroutine save_npy_cdp_4(filename, array, iostat, iomsg)
11461208
end if
11471209

11481210
if (present(iomsg)) then
1149-
iomsg = "Failed to write array to file '"//filename//"'"
1211+
if (stat /= 0) then
1212+
iomsg = "Failed to write array to file '"//filename//"'"
1213+
end if
11501214
end if
11511215
end subroutine save_npy_cdp_4
11521216

test/test_npy.f90

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ subroutine collect_npy(testsuite)
3434
new_unittest("duplicate-descr", test_duplicate_descr, should_fail=.true.), &
3535
new_unittest("missing-descr", test_missing_descr, should_fail=.true.), &
3636
new_unittest("missing-fortran_order", test_missing_fortran_order, should_fail=.true.), &
37-
new_unittest("missing-shape", test_missing_shape, should_fail=.true.) &
37+
new_unittest("missing-shape", test_missing_shape, should_fail=.true.), &
38+
new_unittest("iomsg-deallocated", test_iomsg_deallocated) &
3839
]
3940
end subroutine collect_npy
4041

@@ -619,6 +620,27 @@ subroutine test_missing_shape(error)
619620
call check(error, stat, msg)
620621
end subroutine test_missing_shape
621622

623+
subroutine test_iomsg_deallocated(error)
624+
!> Error handling
625+
type(error_type), allocatable, intent(out) :: error
626+
627+
integer :: stat
628+
character(len=:), allocatable :: msg
629+
630+
character(len=*), parameter :: filename = ".test-iomsg-deallocated.npy"
631+
real(sp), allocatable :: input(:, :), output(:, :)
632+
633+
msg = "This message should be deallocated."
634+
635+
allocate(input(12, 5))
636+
call random_number(input)
637+
call save_npy(filename, input, stat, msg)
638+
call delete_file(filename)
639+
640+
call check(error,.not. allocated(msg), "Message wrongly allocated.")
641+
642+
end subroutine
643+
622644
subroutine delete_file(filename)
623645
character(len=*), intent(in) :: filename
624646

0 commit comments

Comments
 (0)