@@ -105,6 +105,10 @@ module mpas_io
105
105
module procedure MPAS_io_get_var_char1d
106
106
end interface MPAS_io_get_var
107
107
108
+ interface put_att_pio
109
+ module procedure put_att_generic_pio
110
+ end interface put_att_pio
111
+
108
112
interface MPAS_io_put_var
109
113
module procedure MPAS_io_put_var_int0d
110
114
module procedure MPAS_io_put_var_int1d
@@ -5338,12 +5342,29 @@ subroutine MPAS_io_put_att_int0d(handle, attName, attValue, fieldname, syncVal,
5338
5342
end if
5339
5343
5340
5344
#ifdef MPAS_PIO_SUPPORT
5341
- pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValueLocal)
5345
+ ! if (handle % preexisting_file) then
5346
+ ! pio_ierr = PIO_redef(handle % pio_file)
5347
+ ! if (pio_ierr /= PIO_noerr) then
5348
+ ! io_global_err = pio_ierr
5349
+ ! return
5350
+ ! end if
5351
+ ! end if
5352
+
5353
+ call put_att_pio(handle, varid, attName, attValueLocal, ierr= ierr)
5354
+ !pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValueLocal)
5342
5355
if (pio_ierr /= PIO_noerr) then
5343
5356
io_global_err = pio_ierr
5344
5357
if (present (ierr)) ierr = MPAS_IO_ERR_BACKEND
5345
5358
return
5346
5359
end if
5360
+
5361
+ ! if (handle % preexisting_file) then
5362
+ ! pio_ierr = PIO_enddef(handle % pio_file)
5363
+ ! if (pio_ierr /= PIO_noerr) then
5364
+ ! io_global_err = pio_ierr
5365
+ ! return
5366
+ ! end if
5367
+ ! end if
5347
5368
#endif
5348
5369
5349
5370
#ifdef MPAS_SMIOL_SUPPORT
@@ -5685,11 +5706,22 @@ subroutine MPAS_io_put_att_real0d(handle, attName, attValue, fieldname, syncVal,
5685
5706
end if
5686
5707
end if
5687
5708
5709
+ #ifdef MPAS_PIO_SUPPORT
5710
+ ! if (handle % preexisting_file) then
5711
+ ! pio_ierr = PIO_redef(handle % pio_file)
5712
+ ! if (pio_ierr /= PIO_noerr) then
5713
+ ! io_global_err = pio_ierr
5714
+ ! return
5715
+ ! end if
5716
+ ! end if
5717
+ #endif
5718
+
5688
5719
if ((new_attlist_node % attHandle % precision == MPAS_IO_SINGLE_PRECISION) .and. &
5689
5720
(MPAS_IO_NATIVE_PRECISION /= MPAS_IO_SINGLE_PRECISION)) then
5690
5721
singleVal = real (attValueLocal,R4 KIND)
5691
5722
#ifdef MPAS_PIO_SUPPORT
5692
- pio_ierr = PIO_put_att(handle % pio_file, varid, attName, singleVal)
5723
+ call put_att_pio(handle, varid, attName, singleVal, ierr= ierr)
5724
+ !pio_ierr = PIO_put_att(handle % pio_file, varid, attName, singleVal)
5693
5725
#endif
5694
5726
5695
5727
#ifdef MPAS_SMIOL_SUPPORT
@@ -5703,7 +5735,8 @@ subroutine MPAS_io_put_att_real0d(handle, attName, attValue, fieldname, syncVal,
5703
5735
(MPAS_IO_NATIVE_PRECISION /= MPAS_IO_DOUBLE_PRECISION)) then
5704
5736
doubleVal = real (attValueLocal,R8 KIND)
5705
5737
#ifdef MPAS_PIO_SUPPORT
5706
- pio_ierr = PIO_put_att(handle % pio_file, varid, attName, doubleVal)
5738
+ call put_att_pio(handle, varid, attName, doubleVal, ierr= ierr)
5739
+ !pio_ierr = PIO_put_att(handle % pio_file, varid, attName, doubleVal)
5707
5740
#endif
5708
5741
5709
5742
#ifdef MPAS_SMIOL_SUPPORT
@@ -5715,7 +5748,8 @@ subroutine MPAS_io_put_att_real0d(handle, attName, attValue, fieldname, syncVal,
5715
5748
#endif
5716
5749
else
5717
5750
#ifdef MPAS_PIO_SUPPORT
5718
- pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValueLocal)
5751
+ call put_att_pio(handle, varid, attName, attValueLocal, ierr= ierr)
5752
+ !pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValueLocal)
5719
5753
#endif
5720
5754
5721
5755
#ifdef MPAS_SMIOL_SUPPORT
@@ -5733,6 +5767,14 @@ subroutine MPAS_io_put_att_real0d(handle, attName, attValue, fieldname, syncVal,
5733
5767
if (present (ierr)) ierr = MPAS_IO_ERR_BACKEND
5734
5768
return
5735
5769
end if
5770
+
5771
+ ! if (handle % preexisting_file) then
5772
+ ! pio_ierr = PIO_enddef(handle % pio_file)
5773
+ ! if (pio_ierr /= PIO_noerr) then
5774
+ ! io_global_err = pio_ierr
5775
+ ! return
5776
+ ! end if
5777
+ ! end if
5736
5778
#endif
5737
5779
#ifdef MPAS_SMIOL_SUPPORT
5738
5780
if (local_ierr /= SMIOL_SUCCESS) then
@@ -5949,6 +5991,74 @@ subroutine MPAS_io_put_att_real1d(handle, attName, attValue, fieldname, syncVal,
5949
5991
5950
5992
end subroutine MPAS_io_put_att_real1d
5951
5993
5994
+ subroutine put_att_generic_pio (handle , varid , attName , attValue , ierr )
5995
+ type (MPAS_IO_Handle_type), intent (inout ) :: handle
5996
+ integer , intent (in ) :: varid
5997
+ character (len=* ), intent (in ) :: attName
5998
+ class(* ), intent (in ) :: attValue
5999
+ integer , optional :: ierr
6000
+
6001
+ select type(attValue)
6002
+ type is (integer )
6003
+ call mpas_log_write(' Calling PIO_put_att for integer attribute ' // trim (attname))
6004
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6005
+ type is (real (kind= R4 KIND))
6006
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6007
+ call mpas_log_write(' Calling PIO_put_att for real(kind=R4KIND attribute ' // trim (attname))
6008
+ type is (real (kind= R8 KIND))
6009
+ call mpas_log_write(' Calling PIO_put_att for real(kind=R8KIND attribute ' // trim (attname))
6010
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6011
+ type is (character (len=* ))
6012
+ call mpas_log_write(' Calling PIO_put_att for text attribute ' // trim (attname))
6013
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6014
+ end select
6015
+ if (pio_ierr /= PIO_noerr) then
6016
+
6017
+ io_global_err = pio_ierr
6018
+ if (present (ierr)) ierr = MPAS_IO_ERR_BACKEND
6019
+
6020
+ if (handle % preexisting_file .and. .not. handle % data_mode) then
6021
+ call mpas_log_write(' Calling PIO_redef' )
6022
+ pio_ierr = PIO_redef(handle % pio_file)
6023
+ if (pio_ierr /= PIO_noerr) then
6024
+ io_global_err = pio_ierr
6025
+ return
6026
+ end if
6027
+ call mpas_log_write(' Successfully called PIO_redef' )
6028
+ select type(attValue)
6029
+ type is (integer )
6030
+ call mpas_log_write(' Calling PIO_put_att for integer attribute ' // trim (attname))
6031
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6032
+ type is (real (kind= R4 KIND))
6033
+ call mpas_log_write(' Calling PIO_put_att for real(kind=R4KIND attribute ' // trim (attname))
6034
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6035
+ type is (real (kind= R8 KIND))
6036
+ call mpas_log_write(' Calling PIO_put_att for real(kind=R8KIND attribute ' // trim (attname))
6037
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6038
+ type is (character (len=* ))
6039
+ call mpas_log_write(' Calling PIO_put_att for text attribute ' // trim (attname))
6040
+ pio_ierr = PIO_put_att(handle % pio_file, varid, attName, attValue)
6041
+ end select
6042
+ if (pio_ierr /= PIO_noerr) then
6043
+ io_global_err = pio_ierr
6044
+ return
6045
+ end if
6046
+
6047
+ call mpas_log_write(' Calling PIO_enddef' )
6048
+ pio_ierr = PIO_enddef(handle % pio_file)
6049
+ if (pio_ierr /= PIO_noerr) then
6050
+ io_global_err = pio_ierr
6051
+ return
6052
+ end if
6053
+ call mpas_log_write(' Successfully called PIO_enddef' )
6054
+
6055
+ if (present (ierr)) ierr = MPAS_IO_NOERR
6056
+ end if
6057
+ return
6058
+ end if
6059
+ end subroutine
6060
+
6061
+
5952
6062
5953
6063
subroutine MPAS_io_put_att_text (handle , attName , attValue , fieldname , syncVal , ierr )
5954
6064
@@ -6100,43 +6210,7 @@ subroutine MPAS_io_put_att_text(handle, attName, attValue, fieldname, syncVal, i
6100
6210
end if
6101
6211
6102
6212
#ifdef MPAS_PIO_SUPPORT
6103
- pio_ierr = PIO_put_att(handle % pio_file, varid, attName, trim (attValueLocal))
6104
- if (pio_ierr /= PIO_noerr) then
6105
-
6106
- io_global_err = pio_ierr
6107
- if (present (ierr)) ierr = MPAS_IO_ERR_BACKEND
6108
-
6109
- !
6110
- ! If we are working with a pre- existing file and the text attribute is larger than in the file, we need
6111
- ! to enter define mode before writing the attribute. Note the PIO_redef documentation:
6112
- ! ' Entering and leaving netcdf define mode causes a file sync operation to occur,
6113
- ! these operations can be very expensive in parallel systems.'
6114
- !
6115
- if (handle % preexisting_file .and. .not. handle % data_mode) then
6116
- pio_ierr = PIO_redef(handle % pio_file)
6117
- if (pio_ierr /= PIO_noerr) then
6118
- io_global_err = pio_ierr
6119
- return
6120
- end if
6121
-
6122
- pio_ierr = PIO_put_att(handle % pio_file, varid, attName, trim (attValueLocal))
6123
- if (pio_ierr /= PIO_noerr) then
6124
- io_global_err = pio_ierr
6125
- return
6126
- end if
6127
-
6128
- pio_ierr = PIO_enddef(handle % pio_file)
6129
- if (pio_ierr /= PIO_noerr) then
6130
- io_global_err = pio_ierr
6131
- return
6132
- end if
6133
-
6134
- if (present (ierr)) ierr = MPAS_IO_NOERR
6135
-
6136
- end if
6137
-
6138
- return
6139
- end if
6213
+ call put_att_pio(handle, varid, attName, attValueLocal, ierr= ierr)
6140
6214
#endif
6141
6215
6142
6216
#ifdef MPAS_SMIOL_SUPPORT
0 commit comments