1 !/*------------------------------------------------------------------------------
4 !* Forecast Systems Laboratory
10 !* ADVANCED COMPUTING BRANCH
11 !* SMS/NNT Version: 2.0.0
13 !* This software and its documentation are in the public domain and
14 !* are furnished "as is". The United States government, its
15 !* instrumentalities, officers, employees, and agents make no
16 !* warranty, express or implied, as to the usefulness of the software
17 !* and documentation for any purpose. They assume no
18 !* responsibility (1) for the use of the software and documentation;
19 !* or (2) to provide technical support to users.
21 !* Permission to use, copy, modify, and distribute this software is
22 !* hereby granted, provided that this disclaimer notice appears in
23 !* all copies. All modifications to this software must be clearly
24 !* documented, and are solely the responsibility of the agent making
25 !* the modification. If significant modifications or enhancements
26 !* are made to this software, the SMS Development team
27 !* (sms-info@fsl.noaa.gov) should be notified.
29 !*----------------------------------------------------------------------------
32 ! Author: Jacques Middlecoff jacquesm@fsl.noaa.gov
33 !* Date: October 6, 2000
35 !*----------------------------------------------------------------------------
40 integer , parameter :: FATAL = 1
41 integer , parameter :: WARN = 1
42 integer , parameter :: WrfDataHandleMax = 99
43 integer , parameter :: MaxDims = 2000 ! = NF_MAX_VARS
44 integer , parameter :: MaxVars = 2000
45 integer , parameter :: MaxTimes = 9000000
46 integer , parameter :: DateStrLen = 19
47 integer , parameter :: VarNameLen = 31
48 integer , parameter :: NO_DIM = 0
49 integer , parameter :: NVarDims = 4
50 integer , parameter :: NMDVarDims = 2
51 character (8) , parameter :: NO_NAME = 'NULL'
52 character (DateStrLen) , parameter :: ZeroDate = '0000-00-00-00:00:00'
54 #include "wrf_io_flags.h"
56 character (256) :: msg
57 logical :: WrfIOnotInitialized = .true.
59 type :: wrf_data_handle
60 character (255) :: FileName
66 character (5) :: TimesName
68 integer :: CurrentTime !Only used for read
69 integer :: NumberTimes !Only used for read
70 character (DateStrLen), pointer :: Times(:)
72 integer , pointer :: DimLengths(:)
73 integer , pointer :: DimIDs(:)
74 character (31) , pointer :: DimNames(:)
76 character (9) :: DimUnlimName
77 integer , dimension(NVarDims) :: DimID
78 integer , dimension(NVarDims) :: Dimension
79 integer , pointer :: MDVarIDs(:)
80 integer , pointer :: MDVarDimLens(:)
81 character (80) , pointer :: MDVarNames(:)
82 integer , pointer :: VarIDs(:)
83 integer , pointer :: VarDimLens(:,:)
84 character (VarNameLen), pointer :: VarNames(:)
85 integer :: CurrentVariable !Only used for read
87 ! first_operation is set to .TRUE. when a new handle is allocated
88 ! or when open-for-write or open-for-read are committed. It is set
89 ! to .FALSE. when the first field is read or written.
90 logical :: first_operation
91 end type wrf_data_handle
92 type(wrf_data_handle),target :: WrfDataHandles(WrfDataHandleMax)
93 end module wrf_data_pnc
95 module ext_pnc_support_routines
102 integer(KIND=MPI_OFFSET_KIND) function i2offset(i)
106 end function i2offset
108 subroutine allocHandle(DataHandle,DH,Comm,Status)
110 include 'wrf_status_codes.h'
111 integer ,intent(out) :: DataHandle
112 type(wrf_data_handle),pointer :: DH
113 integer ,intent(IN) :: Comm
114 integer ,intent(out) :: Status
118 do i=1,WrfDataHandleMax
119 if(WrfDataHandles(i)%Free) then
120 DH => WrfDataHandles(i)
122 allocate(DH%Times(MaxTimes), STAT=stat)
124 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
125 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
126 call wrf_debug ( FATAL , msg)
129 allocate(DH%DimLengths(MaxDims), STAT=stat)
131 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
132 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
133 call wrf_debug ( FATAL , msg)
136 allocate(DH%DimIDs(MaxDims), STAT=stat)
138 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
139 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
140 call wrf_debug ( FATAL , msg)
143 allocate(DH%DimNames(MaxDims), STAT=stat)
145 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
146 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
147 call wrf_debug ( FATAL , msg)
150 allocate(DH%MDVarIDs(MaxVars), STAT=stat)
152 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
153 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
154 call wrf_debug ( FATAL , msg)
157 allocate(DH%MDVarDimLens(MaxVars), STAT=stat)
159 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
160 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
161 call wrf_debug ( FATAL , msg)
164 allocate(DH%MDVarNames(MaxVars), STAT=stat)
166 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
167 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
168 call wrf_debug ( FATAL , msg)
171 allocate(DH%VarIDs(MaxVars), STAT=stat)
173 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
174 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
175 call wrf_debug ( FATAL , msg)
178 allocate(DH%VarDimLens(NVarDims-1,MaxVars), STAT=stat)
180 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
181 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
182 call wrf_debug ( FATAL , msg)
185 allocate(DH%VarNames(MaxVars), STAT=stat)
187 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
188 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
189 call wrf_debug ( FATAL , msg)
194 if(i==WrfDataHandleMax) then
195 Status = WRF_WARN_TOO_MANY_FILES
196 write(msg,*) 'Warning TOO MANY FILES in ',__FILE__,', line', __LINE__
197 call wrf_debug ( WARN , TRIM(msg))
198 write(msg,*) 'Did you call ext_pnc_ioinit?'
199 call wrf_debug ( WARN , TRIM(msg))
206 DH%first_operation = .TRUE.
208 end subroutine allocHandle
210 subroutine deallocHandle(DataHandle, Status)
212 include 'wrf_status_codes.h'
213 integer ,intent(in) :: DataHandle
214 integer ,intent(out) :: Status
215 type(wrf_data_handle),pointer :: DH
219 IF ( DataHandle .GE. 1 .AND. DataHandle .LE. WrfDataHandleMax ) THEN
220 if(.NOT. WrfDataHandles(DataHandle)%Free) then
221 DH => WrfDataHandles(DataHandle)
222 deallocate(DH%Times, STAT=stat)
224 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
225 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
226 call wrf_debug ( FATAL , msg)
229 deallocate(DH%DimLengths, STAT=stat)
231 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
232 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
233 call wrf_debug ( FATAL , msg)
236 deallocate(DH%DimIDs, STAT=stat)
238 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
239 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
240 call wrf_debug ( FATAL , msg)
243 deallocate(DH%DimNames, STAT=stat)
245 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
246 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
247 call wrf_debug ( FATAL , msg)
250 deallocate(DH%MDVarIDs, STAT=stat)
252 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
253 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
254 call wrf_debug ( FATAL , msg)
257 deallocate(DH%MDVarDimLens, STAT=stat)
259 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
260 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
261 call wrf_debug ( FATAL , msg)
264 deallocate(DH%MDVarNames, STAT=stat)
266 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
267 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
268 call wrf_debug ( FATAL , msg)
271 deallocate(DH%VarIDs, STAT=stat)
273 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
274 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
275 call wrf_debug ( FATAL , msg)
278 deallocate(DH%VarDimLens, STAT=stat)
280 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
281 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
282 call wrf_debug ( FATAL , msg)
285 deallocate(DH%VarNames, STAT=stat)
287 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
288 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
289 call wrf_debug ( FATAL , msg)
296 end subroutine deallocHandle
298 subroutine GetDH(DataHandle,DH,Status)
300 include 'wrf_status_codes.h'
301 integer ,intent(in) :: DataHandle
302 type(wrf_data_handle) ,pointer :: DH
303 integer ,intent(out) :: Status
305 if(DataHandle < 1 .or. DataHandle > WrfDataHandleMax) then
306 Status = WRF_WARN_BAD_DATA_HANDLE
309 DH => WrfDataHandles(DataHandle)
311 Status = WRF_WARN_BAD_DATA_HANDLE
318 subroutine DateCheck(Date,Status)
320 include 'wrf_status_codes.h'
321 character*(*) ,intent(in) :: Date
322 integer ,intent(out) :: Status
324 if(len(Date) /= DateStrLen) then
325 Status = WRF_WARN_DATESTR_BAD_LENGTH
330 end subroutine DateCheck
332 subroutine GetName(Element,Var,Name,Status)
334 include 'wrf_status_codes.h'
335 character*(*) ,intent(in) :: Element
336 character*(*) ,intent(in) :: Var
337 character*(*) ,intent(out) :: Name
338 integer ,intent(out) :: Status
339 character (VarNameLen) :: VarName
342 integer, parameter :: upper_to_lower =IACHAR('a')-IACHAR('A')
345 Name = 'MD___'//trim(Element)//VarName
348 if('A'<=c .and. c <='Z') Name(i:i)=achar(iachar(c)+upper_to_lower)
349 if(c=='-'.or.c==':') Name(i:i)='_'
353 end subroutine GetName
355 subroutine GetTimeIndex(IO,DataHandle,DateStr,TimeIndex,Status)
357 include 'wrf_status_codes.h'
358 # include "pnetcdf.inc"
359 character (*) ,intent(in) :: IO
360 integer ,intent(in) :: DataHandle
361 character*(*) ,intent(in) :: DateStr
362 integer ,intent(out) :: TimeIndex
363 integer ,intent(out) :: Status
364 type(wrf_data_handle) ,pointer :: DH
365 integer(KIND=MPI_OFFSET_KIND) :: VStart(2)
366 integer(KIND=MPI_OFFSET_KIND) :: VCount(2)
370 DH => WrfDataHandles(DataHandle)
371 call DateCheck(DateStr,Status)
372 if(Status /= WRF_NO_ERR) then
373 Status = WRF_WARN_DATESTR_ERROR
374 write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
375 call wrf_debug ( WARN , TRIM(msg))
378 if(IO == 'write') then
379 TimeIndex = DH%TimeIndex
380 if(TimeIndex <= 0) then
382 elseif(DateStr == DH%Times(TimeIndex)) then
386 TimeIndex = TimeIndex +1
387 if(TimeIndex > MaxTimes) then
388 Status = WRF_WARN_TIME_EOF
389 write(msg,*) 'Warning TIME EOF in ',__FILE__,', line', __LINE__
390 call wrf_debug ( WARN , TRIM(msg))
394 DH%TimeIndex = TimeIndex
395 DH%Times(TimeIndex) = DateStr
397 VStart(2) = TimeIndex
398 VCount(1) = DateStrLen
400 stat = NFMPI_PUT_VARA_TEXT_ALL(DH%NCID,DH%TimesVarID,VStart,VCount,DateStr)
401 call netcdf_err(stat,Status)
402 if(Status /= WRF_NO_ERR) then
403 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
404 call wrf_debug ( WARN , TRIM(msg))
409 if(DH%Times(i)==DateStr) then
415 Status = WRF_WARN_TIME_NF
416 write(msg,*) 'Warning TIME ',DateStr,' NOT FOUND in ',__FILE__,', line', __LINE__
417 call wrf_debug ( WARN , TRIM(msg))
423 end subroutine GetTimeIndex
425 subroutine GetDim(MemoryOrder,NDim,Status)
426 include 'wrf_status_codes.h'
427 character*(*) ,intent(in) :: MemoryOrder
428 integer ,intent(out) :: NDim
429 integer ,intent(out) :: Status
430 character*3 :: MemOrd
432 call LowerCase(MemoryOrder,MemOrd)
434 case ('xyz','xzy','yxz','yzx','zxy','zyx','xsz','xez','ysz','yez')
436 case ('xy','yx','xs','xe','ys','ye')
440 case ('0') ! NDim=0 for scalars. TBH: 20060502
443 print *, 'memory order = ',MemOrd,' ',MemoryOrder
444 Status = WRF_WARN_BAD_MEMORYORDER
449 end subroutine GetDim
451 subroutine GetIndices(NDim,Start,End,i1,i2,j1,j2,k1,k2)
452 integer ,intent(in) :: NDim
453 integer ,dimension(*),intent(in) :: Start,End
454 integer ,intent(out) :: i1,i2,j1,j2,k1,k2
462 if(NDim == 0) return ! NDim=0 for scalars. TBH: 20060502
472 end subroutine GetIndices
474 subroutine ExtOrder(MemoryOrder,Vector,Status)
476 include 'wrf_status_codes.h'
477 character*(*) ,intent(in) :: MemoryOrder
478 integer,dimension(*) ,intent(inout) :: Vector
479 integer ,intent(out) :: Status
481 integer,dimension(NVarDims) :: temp
482 character*3 :: MemOrd
484 call GetDim(MemoryOrder,NDim,Status)
485 temp(1:NDim) = Vector(1:NDim)
486 call LowerCase(MemoryOrder,MemOrd)
489 case ('xyz','xsz','xez','ysz','yez','xy','xs','xe','ys','ye','z','c')
492 continue ! NDim=0 for scalars. TBH: 20060502
514 Status = WRF_WARN_BAD_MEMORYORDER
519 end subroutine ExtOrder
521 subroutine ExtOrderStr(MemoryOrder,Vector,ROVector,Status)
523 include 'wrf_status_codes.h'
524 character*(*) ,intent(in) :: MemoryOrder
525 character*(*),dimension(*) ,intent(in) :: Vector
526 character(80),dimension(NVarDims),intent(out) :: ROVector
527 integer ,intent(out) :: Status
529 character*3 :: MemOrd
531 call GetDim(MemoryOrder,NDim,Status)
532 ROVector(1:NDim) = Vector(1:NDim)
533 call LowerCase(MemoryOrder,MemOrd)
536 case ('xyz','xsz','xez','ysz','yez','xy','xs','xe','ys','ye','z','c')
539 continue ! NDim=0 for scalars. TBH: 20060502
541 ROVector(2) = Vector(3)
542 ROVector(3) = Vector(2)
544 ROVector(1) = Vector(2)
545 ROVector(2) = Vector(1)
547 ROVector(1) = Vector(3)
548 ROVector(2) = Vector(1)
549 ROVector(3) = Vector(2)
551 ROVector(1) = Vector(2)
552 ROVector(2) = Vector(3)
553 ROVector(3) = Vector(1)
555 ROVector(1) = Vector(3)
556 ROVector(3) = Vector(1)
558 ROVector(1) = Vector(2)
559 ROVector(2) = Vector(1)
561 Status = WRF_WARN_BAD_MEMORYORDER
566 end subroutine ExtOrderStr
569 subroutine LowerCase(MemoryOrder,MemOrd)
570 character*(*) ,intent(in) :: MemoryOrder
571 character*(*) ,intent(out) :: MemOrd
573 integer ,parameter :: upper_to_lower =IACHAR('a')-IACHAR('A')
578 MemOrd(1:N) = MemoryOrder(1:N)
581 if('A'<=c .and. c <='Z') MemOrd(i:i)=achar(iachar(c)+upper_to_lower)
584 end subroutine LowerCase
586 subroutine UpperCase(MemoryOrder,MemOrd)
587 character*(*) ,intent(in) :: MemoryOrder
588 character*(*) ,intent(out) :: MemOrd
590 integer ,parameter :: lower_to_upper =IACHAR('A')-IACHAR('a')
595 MemOrd(1:N) = MemoryOrder(1:N)
598 if('a'<=c .and. c <='z') MemOrd(i:i)=achar(iachar(c)+lower_to_upper)
601 end subroutine UpperCase
603 subroutine netcdf_err(err,Status)
605 include 'wrf_status_codes.h'
606 # include "pnetcdf.inc"
607 integer ,intent(in) :: err
608 integer ,intent(out) :: Status
609 character(len=80) :: errmsg
612 if( err==NF_NOERR )then
615 errmsg = NFMPI_STRERROR(err)
616 write(msg,*) 'NetCDF error: ',errmsg
617 call wrf_debug ( WARN , TRIM(msg))
618 Status = WRF_WARN_NETCDF
621 end subroutine netcdf_err
623 subroutine FieldIO(IO,DataHandle,DateStr,Starts,Length,MemoryOrder &
624 ,FieldType,NCID,VarID,XField,Status)
626 include 'wrf_status_codes.h'
627 # include "pnetcdf.inc"
628 character (*) ,intent(in) :: IO
629 integer ,intent(in) :: DataHandle
630 character*(*) ,intent(in) :: DateStr
631 integer,dimension(NVarDims),intent(in) :: Starts
632 integer,dimension(NVarDims),intent(in) :: Length
633 character*(*) ,intent(in) :: MemoryOrder
634 integer ,intent(in) :: FieldType
635 integer ,intent(in) :: NCID
636 integer ,intent(in) :: VarID
637 integer,dimension(*) ,intent(inout) :: XField
638 integer ,intent(out) :: Status
641 integer,dimension(NVarDims) :: VStart
642 integer,dimension(NVarDims) :: VCount
644 call GetTimeIndex(IO,DataHandle,DateStr,TimeIndex,Status)
645 if(Status /= WRF_NO_ERR) then
646 write(msg,*) 'Warning in ',__FILE__,', line', __LINE__
647 call wrf_debug ( WARN , TRIM(msg))
648 write(msg,*) ' Bad time index for DateStr = ',DateStr
649 call wrf_debug ( WARN , TRIM(msg))
652 call GetDim(MemoryOrder,NDim,Status)
655 !jm for parallel netcef VStart(1:NDim) = 1
656 VStart(1:NDim) = Starts(1:NDim)
657 VCount(1:NDim) = Length(1:NDim)
658 VStart(NDim+1) = TimeIndex
660 select case (FieldType)
662 call ext_pnc_RealFieldIO (IO,NCID,VarID,VStart,VCount,XField,Status)
664 call ext_pnc_DoubleFieldIO (IO,NCID,VarID,VStart,VCount,XField,Status)
666 call ext_pnc_IntFieldIO (IO,NCID,VarID,VStart,VCount,XField,Status)
668 call ext_pnc_LogicalFieldIO (IO,NCID,VarID,VStart,VCount,XField,Status)
669 if(Status /= WRF_NO_ERR) return
671 !for wrf_complex, double_complex
672 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
673 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
674 call wrf_debug ( WARN , TRIM(msg))
678 end subroutine FieldIO
680 subroutine Transpose(IO,MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
681 ,XField,x1,x2,y1,y2,z1,z2 &
683 character*(*) ,intent(in) :: IO
684 character*(*) ,intent(in) :: MemoryOrder
685 integer ,intent(in) :: l1,l2,m1,m2,n1,n2
686 integer ,intent(in) :: di
687 integer ,intent(in) :: x1,x2,y1,y2,z1,z2
688 integer ,intent(in) :: i1,i2,j1,j2,k1,k2
689 integer ,intent(inout) :: Field(di,l1:l2,m1:m2,n1:n2)
690 !jm 010827 integer ,intent(inout) :: XField(di,x1:x2,y1:y2,z1:z2)
691 integer ,intent(inout) :: XField(di,(i2-i1+1)*(j2-j1+1)*(k2-k1+1))
692 character*3 :: MemOrd
694 integer ,parameter :: MaxUpperCase=IACHAR('Z')
695 integer :: i,j,k,ix,jx,kx
697 call LowerCase(MemoryOrder,MemOrd)
700 !#define XDEX(A,B,C) A-A ## 1+1+(A ## 2-A ## 1+1)*((B-B ## 1)+(C-C ## 1)*(B ## 2-B ## 1+1))
701 ! define(`XDEX',($1-``$1''1+1+(``$1''2-``$1''1+1)*(($2-``$2''1)+($3-``$3''1)*(``$2''2-``$2''1+1))))
705 #define DFIELD XField(1:di,XDEX(i,k,j))
706 #include "transpose.code"
707 case ('xyz','xsz','xez','ysz','yez','xy','xs','xe','ys','ye','z','c','0')
709 #define DFIELD XField(1:di,XDEX(i,j,k))
710 #include "transpose.code"
713 #define DFIELD XField(1:di,XDEX(j,i,k))
714 #include "transpose.code"
717 #define DFIELD XField(1:di,XDEX(k,i,j))
718 #include "transpose.code"
721 #define DFIELD XField(1:di,XDEX(j,k,i))
722 #include "transpose.code"
725 #define DFIELD XField(1:di,XDEX(k,j,i))
726 #include "transpose.code"
729 #define DFIELD XField(1:di,XDEX(j,i,k))
730 #include "transpose.code"
733 end subroutine Transpose
735 subroutine reorder (MemoryOrder,MemO)
736 character*(*) ,intent(in) :: MemoryOrder
737 character*3 ,intent(out) :: MemO
738 character*3 :: MemOrd
739 integer :: N,i,i1,i2,i3
742 N = len_trim(MemoryOrder)
744 call lowercase(MemoryOrder,MemOrd)
745 ! never invert the boundary codes
746 select case ( MemOrd )
747 case ( 'xsz','xez','ysz','yez' )
755 if(ichar(MemOrd(i:i)) < ichar(MemOrd(i1:i1))) I1 = i
756 if(ichar(MemOrd(i:i)) > ichar(MemOrd(i3:i3))) I3 = i
763 MemO(1:1) = MemoryOrder(i1:i1)
764 MemO(2:2) = MemoryOrder(i2:i2)
765 if(N == 3) MemO(3:3) = MemoryOrder(i3:i3)
766 if(MemOrd(i1:i1) == 's' .or. MemOrd(i1:i1) == 'e') then
767 MemO(1:N-1) = MemO(2:N)
768 MemO(N:N ) = MemoryOrder(i1:i1)
771 end subroutine reorder
773 ! Returns .TRUE. iff it is OK to write time-independent domain metadata to the
774 ! file referenced by DataHandle. If DataHandle is invalid, .FALSE. is
776 LOGICAL FUNCTION ncd_ok_to_put_dom_ti( DataHandle )
778 include 'wrf_status_codes.h'
779 INTEGER, INTENT(IN) :: DataHandle
780 CHARACTER*80 :: fname
783 LOGICAL :: dryrun, first_output, retval
784 call ext_pnc_inquire_filename( DataHandle, fname, filestate, Status )
785 IF ( Status /= WRF_NO_ERR ) THEN
786 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
788 call wrf_debug ( WARN , TRIM(msg) )
791 dryrun = ( filestate .EQ. WRF_FILE_OPENED_NOT_COMMITTED )
792 first_output = ncd_is_first_operation( DataHandle )
793 ! retval = .NOT. dryrun .AND. first_output
796 ncd_ok_to_put_dom_ti = retval
798 END FUNCTION ncd_ok_to_put_dom_ti
800 ! Returns .TRUE. iff it is OK to read time-independent domain metadata from the
801 ! file referenced by DataHandle. If DataHandle is invalid, .FALSE. is
803 LOGICAL FUNCTION ncd_ok_to_get_dom_ti( DataHandle )
805 include 'wrf_status_codes.h'
806 INTEGER, INTENT(IN) :: DataHandle
807 CHARACTER*80 :: fname
810 LOGICAL :: dryrun, retval
811 call ext_pnc_inquire_filename( DataHandle, fname, filestate, Status )
812 IF ( Status /= WRF_NO_ERR ) THEN
813 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
815 call wrf_debug ( WARN , TRIM(msg) )
818 dryrun = ( filestate .EQ. WRF_FILE_OPENED_NOT_COMMITTED )
819 retval = .NOT. dryrun
821 ncd_ok_to_get_dom_ti = retval
823 END FUNCTION ncd_ok_to_get_dom_ti
825 ! Returns .TRUE. iff nothing has been read from or written to the file
826 ! referenced by DataHandle. If DataHandle is invalid, .FALSE. is returned.
827 LOGICAL FUNCTION ncd_is_first_operation( DataHandle )
829 INCLUDE 'wrf_status_codes.h'
830 INTEGER, INTENT(IN) :: DataHandle
831 TYPE(wrf_data_handle) ,POINTER :: DH
834 CALL GetDH( DataHandle, DH, Status )
835 IF ( Status /= WRF_NO_ERR ) THEN
836 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
838 call wrf_debug ( WARN , TRIM(msg) )
841 retval = DH%first_operation
843 ncd_is_first_operation = retval
845 END FUNCTION ncd_is_first_operation
847 end module ext_pnc_support_routines
849 subroutine ext_pnc_open_for_read(DatasetName, Comm1, Comm2, SysDepInfo, DataHandle, Status)
851 use ext_pnc_support_routines
853 include 'wrf_status_codes.h'
854 # include "pnetcdf.inc"
855 character *(*), INTENT(IN) :: DatasetName
856 integer , INTENT(IN) :: Comm1, Comm2
857 character *(*), INTENT(IN) :: SysDepInfo
858 integer , INTENT(OUT) :: DataHandle
859 integer , INTENT(OUT) :: Status
860 DataHandle = 0 ! dummy setting to quiet warning message
861 CALL ext_pnc_open_for_read_begin( DatasetName, Comm1, Comm2, SysDepInfo, DataHandle, Status )
862 IF ( Status .EQ. WRF_NO_ERR ) THEN
863 CALL ext_pnc_open_for_read_commit( DataHandle, Status )
866 end subroutine ext_pnc_open_for_read
868 !ends training phase; switches internal flag to enable input
869 !must be paired with call to ext_pnc_open_for_read_begin
870 subroutine ext_pnc_open_for_read_commit(DataHandle, Status)
872 use ext_pnc_support_routines
874 include 'wrf_status_codes.h'
875 # include "pnetcdf.inc"
876 integer, intent(in) :: DataHandle
877 integer, intent(out) :: Status
878 type(wrf_data_handle) ,pointer :: DH
880 if(WrfIOnotInitialized) then
881 Status = WRF_IO_NOT_INITIALIZED
882 write(msg,*) 'ext_pnc_ioinit was not called ',__FILE__,', line', __LINE__
883 call wrf_debug ( FATAL , msg)
886 call GetDH(DataHandle,DH,Status)
887 if(Status /= WRF_NO_ERR) then
888 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
889 call wrf_debug ( WARN , TRIM(msg))
892 DH%FileStatus = WRF_FILE_OPENED_FOR_READ
893 DH%first_operation = .TRUE.
896 end subroutine ext_pnc_open_for_read_commit
898 subroutine ext_pnc_open_for_read_begin( FileName, Comm, IOComm, SysDepInfo, DataHandle, Status)
900 use ext_pnc_support_routines
902 include 'wrf_status_codes.h'
903 # include "pnetcdf.inc"
904 character*(*) ,intent(IN) :: FileName
905 integer ,intent(IN) :: Comm
906 integer ,intent(IN) :: IOComm
907 character*(*) ,intent(in) :: SysDepInfo
908 integer ,intent(out) :: DataHandle
909 integer ,intent(out) :: Status
910 type(wrf_data_handle) ,pointer :: DH
913 integer ,allocatable :: Buffer(:)
918 integer(KIND=MPI_OFFSET_KIND) :: VStart(2)
919 integer(KIND=MPI_OFFSET_KIND) :: VLen(2)
920 integer :: TotalNumVars
923 character (NF_MAX_NAME) :: Name
925 if(WrfIOnotInitialized) then
926 Status = WRF_IO_NOT_INITIALIZED
927 write(msg,*) 'ext_pnc_ioinit was not called ',__FILE__,', line', __LINE__
928 call wrf_debug ( FATAL , msg)
931 call allocHandle(DataHandle,DH,Comm,Status)
932 if(Status /= WRF_NO_ERR) then
933 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
934 call wrf_debug ( WARN , TRIM(msg))
937 stat = NFMPI_OPEN(Comm, FileName, NF_NOWRITE, MPI_INFO_NULL, DH%NCID)
938 call netcdf_err(stat,Status)
939 if(Status /= WRF_NO_ERR) then
940 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
941 call wrf_debug ( WARN , TRIM(msg))
944 stat = NFMPI_INQ_VARID(DH%NCID,DH%TimesName,VarID)
945 call netcdf_err(stat,Status)
946 if(Status /= WRF_NO_ERR) then
947 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
948 call wrf_debug ( WARN , TRIM(msg))
951 stat = NFMPI_INQ_VAR(DH%NCID,VarID,DH%TimesName, XType, StoredDim, DimIDs, NAtts)
952 call netcdf_err(stat,Status)
953 if(Status /= WRF_NO_ERR) then
954 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
955 call wrf_debug ( WARN , TRIM(msg))
958 if(XType/=NF_CHAR) then
959 Status = WRF_WARN_TYPE_MISMATCH
960 write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
961 call wrf_debug ( WARN , TRIM(msg))
964 stat = NFMPI_INQ_DIMLEN(DH%NCID,DimIDs(1),VLen(1))
965 call netcdf_err(stat,Status)
966 if(Status /= WRF_NO_ERR) then
967 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
968 call wrf_debug ( WARN , TRIM(msg))
971 if(VLen(1) /= DateStrLen) then
972 Status = WRF_WARN_DATESTR_BAD_LENGTH
973 write(msg,*) 'Warning DATESTR BAD LENGTH in ',__FILE__,', line', __LINE__
974 call wrf_debug ( WARN , TRIM(msg))
977 stat = NFMPI_INQ_DIMLEN(DH%NCID,DimIDs(2),VLen(2))
978 call netcdf_err(stat,Status)
979 if(Status /= WRF_NO_ERR) then
980 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
981 call wrf_debug ( WARN , TRIM(msg))
984 if(VLen(2) > MaxTimes) then
985 Status = WRF_ERR_FATAL_TOO_MANY_TIMES
986 write(msg,*) 'Fatal TOO MANY TIME VALUES in ',__FILE__,', line', __LINE__
987 call wrf_debug ( FATAL , TRIM(msg))
992 stat = NFMPI_GET_VARA_TEXT_ALL(DH%NCID,VarID,VStart,VLen,DH%Times)
993 call netcdf_err(stat,Status)
994 if(Status /= WRF_NO_ERR) then
995 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
996 call wrf_debug ( WARN , TRIM(msg))
999 stat = NFMPI_INQ_NVARS(DH%NCID,TotalNumVars)
1000 call netcdf_err(stat,Status)
1001 if(Status /= WRF_NO_ERR) then
1002 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1003 call wrf_debug ( WARN , TRIM(msg))
1008 stat = NFMPI_INQ_VARNAME(DH%NCID,i,Name)
1009 call netcdf_err(stat,Status)
1010 if(Status /= WRF_NO_ERR) then
1011 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1012 call wrf_debug ( WARN , TRIM(msg))
1014 elseif(Name(1:5) /= 'md___' .and. Name /= DH%TimesName) then
1016 DH%VarNames(NumVars) = Name
1017 DH%VarIDs(NumVars) = i
1020 DH%NumVars = NumVars
1021 DH%NumberTimes = VLen(2)
1022 DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
1023 DH%FileName = FileName
1024 DH%CurrentVariable = 0
1026 DH%TimesVarID = VarID
1029 end subroutine ext_pnc_open_for_read_begin
1031 subroutine ext_pnc_open_for_update( FileName, Comm, IOComm, SysDepInfo, DataHandle, Status)
1033 use ext_pnc_support_routines
1035 include 'wrf_status_codes.h'
1036 # include "pnetcdf.inc"
1037 character*(*) ,intent(IN) :: FileName
1038 integer ,intent(IN) :: Comm
1039 integer ,intent(IN) :: IOComm
1040 character*(*) ,intent(in) :: SysDepInfo
1041 integer ,intent(out) :: DataHandle
1042 integer ,intent(out) :: Status
1043 type(wrf_data_handle) ,pointer :: DH
1046 integer ,allocatable :: Buffer(:)
1048 integer :: StoredDim
1050 integer :: DimIDs(2)
1051 integer :: VStart(2)
1053 integer :: TotalNumVars
1056 character (NF_MAX_NAME) :: Name
1058 if(WrfIOnotInitialized) then
1059 Status = WRF_IO_NOT_INITIALIZED
1060 write(msg,*) 'ext_pnc_ioinit was not called ',__FILE__,', line', __LINE__
1061 call wrf_debug ( FATAL , msg)
1064 call allocHandle(DataHandle,DH,Comm,Status)
1065 if(Status /= WRF_NO_ERR) then
1066 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
1067 call wrf_debug ( WARN , TRIM(msg))
1070 stat = NFMPI_OPEN(Comm, FileName, NF_WRITE, MPI_INFO_NULL, DH%NCID)
1071 call netcdf_err(stat,Status)
1072 if(Status /= WRF_NO_ERR) then
1073 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1074 call wrf_debug ( WARN , TRIM(msg))
1077 stat = NFMPI_INQ_VARID(DH%NCID,DH%TimesName,VarID)
1078 call netcdf_err(stat,Status)
1079 if(Status /= WRF_NO_ERR) then
1080 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1081 call wrf_debug ( WARN , TRIM(msg))
1084 stat = NFMPI_INQ_VAR(DH%NCID,VarID,DH%TimesName, XType, StoredDim, DimIDs, NAtts)
1085 call netcdf_err(stat,Status)
1086 if(Status /= WRF_NO_ERR) then
1087 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1088 call wrf_debug ( WARN , TRIM(msg))
1091 if(XType/=NF_CHAR) then
1092 Status = WRF_WARN_TYPE_MISMATCH
1093 write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
1094 call wrf_debug ( WARN , TRIM(msg))
1097 stat = NFMPI_INQ_DIMLEN(DH%NCID,DimIDs(1),VLen(1))
1098 call netcdf_err(stat,Status)
1099 if(Status /= WRF_NO_ERR) then
1100 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1101 call wrf_debug ( WARN , TRIM(msg))
1104 if(VLen(1) /= DateStrLen) then
1105 Status = WRF_WARN_DATESTR_BAD_LENGTH
1106 write(msg,*) 'Warning DATESTR BAD LENGTH in ',__FILE__,', line', __LINE__
1107 call wrf_debug ( WARN , TRIM(msg))
1110 stat = NFMPI_INQ_DIMLEN(DH%NCID,DimIDs(2),VLen(2))
1111 call netcdf_err(stat,Status)
1112 if(Status /= WRF_NO_ERR) then
1113 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1114 call wrf_debug ( WARN , TRIM(msg))
1117 if(VLen(2) > MaxTimes) then
1118 Status = WRF_ERR_FATAL_TOO_MANY_TIMES
1119 write(msg,*) 'Fatal TOO MANY TIME VALUES in ',__FILE__,', line', __LINE__
1120 call wrf_debug ( FATAL , TRIM(msg))
1125 stat = NFMPI_GET_VARA_TEXT_ALL(DH%NCID,VarID,VStart,VLen,DH%Times)
1126 call netcdf_err(stat,Status)
1127 if(Status /= WRF_NO_ERR) then
1128 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1129 call wrf_debug ( WARN , TRIM(msg))
1132 stat = NFMPI_INQ_NVARS(DH%NCID,TotalNumVars)
1133 call netcdf_err(stat,Status)
1134 if(Status /= WRF_NO_ERR) then
1135 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1136 call wrf_debug ( WARN , TRIM(msg))
1141 stat = NFMPI_INQ_VARNAME(DH%NCID,i,Name)
1142 call netcdf_err(stat,Status)
1143 if(Status /= WRF_NO_ERR) then
1144 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1145 call wrf_debug ( WARN , TRIM(msg))
1147 elseif(Name(1:5) /= 'md___' .and. Name /= DH%TimesName) then
1149 DH%VarNames(NumVars) = Name
1150 DH%VarIDs(NumVars) = i
1153 DH%NumVars = NumVars
1154 DH%NumberTimes = VLen(2)
1155 DH%FileStatus = WRF_FILE_OPENED_FOR_UPDATE
1156 DH%FileName = FileName
1157 DH%CurrentVariable = 0
1159 DH%TimesVarID = VarID
1162 end subroutine ext_pnc_open_for_update
1165 SUBROUTINE ext_pnc_open_for_write_begin(FileName,Comm,IOComm,SysDepInfo,DataHandle,Status)
1167 use ext_pnc_support_routines
1169 include 'wrf_status_codes.h'
1170 # include "pnetcdf.inc"
1171 character*(*) ,intent(in) :: FileName
1172 integer ,intent(in) :: Comm
1173 integer ,intent(in) :: IOComm
1174 character*(*) ,intent(in) :: SysDepInfo
1175 integer ,intent(out) :: DataHandle
1176 integer ,intent(out) :: Status
1177 type(wrf_data_handle),pointer :: DH
1180 character (7) :: Buffer
1181 integer :: VDimIDs(2)
1183 if(WrfIOnotInitialized) then
1184 Status = WRF_IO_NOT_INITIALIZED
1185 write(msg,*) 'ext_pnc_open_for_write_begin: ext_pnc_ioinit was not called ',__FILE__,', line', __LINE__
1186 call wrf_debug ( FATAL , msg)
1189 call allocHandle(DataHandle,DH,Comm,Status)
1190 if(Status /= WRF_NO_ERR) then
1191 write(msg,*) 'Fatal ALLOCATION ERROR in ext_pnc_open_for_write_begin ',__FILE__,', line', __LINE__
1192 call wrf_debug ( FATAL , TRIM(msg))
1197 ! stat = NFMPI_CREATE(Comm, FileName, NF_CLOBBER, MPI_INFO_NULL, DH%NCID)
1198 stat = NFMPI_CREATE(Comm, FileName, IOR(NF_CLOBBER, NF_64BIT_OFFSET), MPI_INFO_NULL, DH%NCID)
1199 call netcdf_err(stat,Status)
1200 if(Status /= WRF_NO_ERR) then
1201 write(msg,*) 'NetCDF error in ext_pnc_open_for_write_begin ',__FILE__,', line', __LINE__
1202 call wrf_debug ( WARN , TRIM(msg))
1205 DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
1206 DH%FileName = FileName
1207 stat = NFMPI_DEF_DIM(DH%NCID,DH%DimUnlimName,i2offset(NF_UNLIMITED),DH%DimUnlimID)
1208 call netcdf_err(stat,Status)
1209 if(Status /= WRF_NO_ERR) then
1210 write(msg,*) 'NetCDF error in ext_pnc_open_for_write_begin ',__FILE__,', line', __LINE__
1211 call wrf_debug ( WARN , TRIM(msg))
1214 DH%VarNames (1:MaxVars) = NO_NAME
1215 DH%MDVarNames(1:MaxVars) = NO_NAME
1217 write(Buffer,FMT="('DIM',i4.4)") i
1218 DH%DimNames (i) = Buffer
1219 DH%DimLengths(i) = NO_DIM
1221 DH%DimNames(1) = 'DateStrLen'
1222 stat = NFMPI_DEF_DIM(DH%NCID,DH%DimNames(1),i2offset(DateStrLen),DH%DimIDs(1))
1223 call netcdf_err(stat,Status)
1224 if(Status /= WRF_NO_ERR) then
1225 write(msg,*) 'NetCDF error in ext_pnc_open_for_write_begin ',__FILE__,', line', __LINE__
1226 call wrf_debug ( WARN , TRIM(msg))
1229 VDimIDs(1) = DH%DimIDs(1)
1230 VDimIDs(2) = DH%DimUnlimID
1231 stat = NFMPI_DEF_VAR(DH%NCID,DH%TimesName,NF_CHAR,2,VDimIDs,DH%TimesVarID)
1232 call netcdf_err(stat,Status)
1233 if(Status /= WRF_NO_ERR) then
1234 write(msg,*) 'NetCDF error in ext_pnc_open_for_write_begin ',__FILE__,', line', __LINE__
1235 call wrf_debug ( WARN , TRIM(msg))
1238 DH%DimLengths(1) = DateStrLen
1240 end subroutine ext_pnc_open_for_write_begin
1243 !opens a file for writing or coupler datastream for sending messages.
1244 !no training phase for this version of the open stmt.
1245 subroutine ext_pnc_open_for_write (DatasetName, Comm1, Comm2, &
1246 SysDepInfo, DataHandle, Status)
1248 use ext_pnc_support_routines
1250 include 'wrf_status_codes.h'
1251 # include "pnetcdf.inc"
1252 character *(*), intent(in) ::DatasetName
1253 integer , intent(in) ::Comm1, Comm2
1254 character *(*), intent(in) ::SysDepInfo
1255 integer , intent(out) :: DataHandle
1256 integer , intent(out) :: Status
1257 Status=WRF_WARN_NOOP
1258 DataHandle = 0 ! dummy setting to quiet warning message
1260 end subroutine ext_pnc_open_for_write
1262 SUBROUTINE ext_pnc_open_for_write_commit(DataHandle, Status)
1264 use ext_pnc_support_routines
1266 include 'wrf_status_codes.h'
1267 # include "pnetcdf.inc"
1268 integer ,intent(in) :: DataHandle
1269 integer ,intent(out) :: Status
1270 type(wrf_data_handle),pointer :: DH
1274 if(WrfIOnotInitialized) then
1275 Status = WRF_IO_NOT_INITIALIZED
1276 write(msg,*) 'ext_pnc_open_for_write_commit: ext_pnc_ioinit was not called ',__FILE__,', line', __LINE__
1277 call wrf_debug ( FATAL , msg)
1280 call GetDH(DataHandle,DH,Status)
1281 if(Status /= WRF_NO_ERR) then
1282 write(msg,*) 'Warning Status = ',Status,' in ext_pnc_open_for_write_commit ',__FILE__,', line', __LINE__
1283 call wrf_debug ( WARN , TRIM(msg))
1286 stat = NFMPI_ENDDEF(DH%NCID)
1287 call netcdf_err(stat,Status)
1288 if(Status /= WRF_NO_ERR) then
1289 write(msg,*) 'NetCDF error in ext_pnc_open_for_write_commit ',__FILE__,', line', __LINE__
1290 call wrf_debug ( WARN , TRIM(msg))
1293 DH%FileStatus = WRF_FILE_OPENED_FOR_WRITE
1294 DH%first_operation = .TRUE.
1296 end subroutine ext_pnc_open_for_write_commit
1298 subroutine ext_pnc_ioclose(DataHandle, Status)
1300 use ext_pnc_support_routines
1302 include 'wrf_status_codes.h'
1303 # include "pnetcdf.inc"
1304 integer ,intent(in) :: DataHandle
1305 integer ,intent(out) :: Status
1306 type(wrf_data_handle),pointer :: DH
1309 call GetDH(DataHandle,DH,Status)
1310 if(Status /= WRF_NO_ERR) then
1311 write(msg,*) 'Warning Status = ',Status,' in ext_pnc_ioclose ',__FILE__,', line', __LINE__
1312 call wrf_debug ( WARN , TRIM(msg))
1315 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1316 Status = WRF_WARN_FILE_NOT_OPENED
1317 write(msg,*) 'Warning FILE NOT OPENED in ext_pnc_ioclose ',__FILE__,', line', __LINE__
1318 call wrf_debug ( WARN , TRIM(msg))
1319 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1320 Status = WRF_WARN_DRYRUN_CLOSE
1321 write(msg,*) 'Warning TRY TO CLOSE DRYRUN in ext_pnc_ioclose ',__FILE__,', line', __LINE__
1322 call wrf_debug ( WARN , TRIM(msg))
1323 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1325 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1327 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
1330 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1331 write(msg,*) 'Fatal error BAD FILE STATUS in ext_pnc_ioclose ',__FILE__,', line', __LINE__
1332 call wrf_debug ( FATAL , TRIM(msg))
1336 stat = NFMPI_CLOSE(DH%NCID)
1337 call netcdf_err(stat,Status)
1338 if(Status /= WRF_NO_ERR) then
1339 write(msg,*) 'NetCDF error in ext_pnc_ioclose ',__FILE__,', line', __LINE__
1340 call wrf_debug ( WARN , TRIM(msg))
1343 CALL deallocHandle( DataHandle, Status )
1346 end subroutine ext_pnc_ioclose
1348 subroutine ext_pnc_iosync( DataHandle, Status)
1350 use ext_pnc_support_routines
1352 include 'wrf_status_codes.h'
1353 # include "pnetcdf.inc"
1354 integer ,intent(in) :: DataHandle
1355 integer ,intent(out) :: Status
1356 type(wrf_data_handle),pointer :: DH
1359 call GetDH(DataHandle,DH,Status)
1360 if(Status /= WRF_NO_ERR) then
1361 write(msg,*) 'Warning Status = ',Status,' in ext_pnc_iosync ',__FILE__,', line', __LINE__
1362 call wrf_debug ( WARN , TRIM(msg))
1365 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1366 Status = WRF_WARN_FILE_NOT_OPENED
1367 write(msg,*) 'Warning FILE NOT OPENED in ext_pnc_iosync ',__FILE__,', line', __LINE__
1368 call wrf_debug ( WARN , TRIM(msg))
1369 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1370 Status = WRF_WARN_FILE_NOT_COMMITTED
1371 write(msg,*) 'Warning FILE NOT COMMITTED in ext_pnc_iosync ',__FILE__,', line', __LINE__
1372 call wrf_debug ( WARN , TRIM(msg))
1373 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1375 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1378 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1379 write(msg,*) 'Fatal error BAD FILE STATUS in ext_pnc_iosync ',__FILE__,', line', __LINE__
1380 call wrf_debug ( FATAL , TRIM(msg))
1383 stat = NFMPI_SYNC(DH%NCID)
1384 call netcdf_err(stat,Status)
1385 if(Status /= WRF_NO_ERR) then
1386 write(msg,*) 'NetCDF error in ext_pnc_iosync ',__FILE__,', line', __LINE__
1387 call wrf_debug ( WARN , TRIM(msg))
1391 end subroutine ext_pnc_iosync
1395 subroutine ext_pnc_redef( DataHandle, Status)
1397 use ext_pnc_support_routines
1399 include 'wrf_status_codes.h'
1400 # include "pnetcdf.inc"
1401 integer ,intent(in) :: DataHandle
1402 integer ,intent(out) :: Status
1403 type(wrf_data_handle),pointer :: DH
1406 call GetDH(DataHandle,DH,Status)
1407 if(Status /= WRF_NO_ERR) then
1408 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
1409 call wrf_debug ( WARN , TRIM(msg))
1412 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1413 Status = WRF_WARN_FILE_NOT_OPENED
1414 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
1415 call wrf_debug ( WARN , TRIM(msg))
1416 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1417 Status = WRF_WARN_FILE_NOT_COMMITTED
1418 write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
1419 call wrf_debug ( WARN , TRIM(msg))
1420 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1422 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1423 Status = WRF_WARN_FILE_OPEN_FOR_READ
1424 write(msg,*) 'Warning FILE OPEN FOR READ in ',__FILE__,', line', __LINE__
1425 call wrf_debug ( WARN , TRIM(msg))
1427 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1428 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
1429 call wrf_debug ( FATAL , TRIM(msg))
1432 stat = NFMPI_REDEF(DH%NCID)
1433 call netcdf_err(stat,Status)
1434 if(Status /= WRF_NO_ERR) then
1435 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1436 call wrf_debug ( WARN , TRIM(msg))
1439 DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
1441 end subroutine ext_pnc_redef
1443 subroutine ext_pnc_enddef( DataHandle, Status)
1445 use ext_pnc_support_routines
1447 include 'wrf_status_codes.h'
1448 # include "pnetcdf.inc"
1449 integer ,intent(in) :: DataHandle
1450 integer ,intent(out) :: Status
1451 type(wrf_data_handle),pointer :: DH
1454 call GetDH(DataHandle,DH,Status)
1455 if(Status /= WRF_NO_ERR) then
1456 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
1457 call wrf_debug ( WARN , TRIM(msg))
1460 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1461 Status = WRF_WARN_FILE_NOT_OPENED
1462 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
1463 call wrf_debug ( WARN , TRIM(msg))
1464 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1465 Status = WRF_WARN_FILE_NOT_COMMITTED
1466 write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
1467 call wrf_debug ( WARN , TRIM(msg))
1468 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1470 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1471 Status = WRF_WARN_FILE_OPEN_FOR_READ
1472 write(msg,*) 'Warning FILE OPEN FOR READ in ',__FILE__,', line', __LINE__
1473 call wrf_debug ( WARN , TRIM(msg))
1475 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1476 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
1477 call wrf_debug ( FATAL , TRIM(msg))
1480 stat = NFMPI_ENDDEF(DH%NCID)
1481 call netcdf_err(stat,Status)
1482 if(Status /= WRF_NO_ERR) then
1483 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
1484 call wrf_debug ( WARN , TRIM(msg))
1487 DH%FileStatus = WRF_FILE_OPENED_FOR_WRITE
1489 end subroutine ext_pnc_enddef
1491 subroutine ext_pnc_ioinit(SysDepInfo, Status)
1494 include 'wrf_status_codes.h'
1495 CHARACTER*(*), INTENT(IN) :: SysDepInfo
1496 INTEGER ,INTENT(INOUT) :: Status
1498 WrfIOnotInitialized = .false.
1499 WrfDataHandles(1:WrfDataHandleMax)%Free = .true.
1500 WrfDataHandles(1:WrfDataHandleMax)%TimesName = 'Times'
1501 WrfDataHandles(1:WrfDataHandleMax)%DimUnlimName = 'Time'
1502 WrfDataHandles(1:WrfDataHandleMax)%FileStatus = WRF_FILE_NOT_OPENED
1505 end subroutine ext_pnc_ioinit
1508 subroutine ext_pnc_inquiry (Inquiry, Result, Status)
1511 include 'wrf_status_codes.h'
1512 character *(*), INTENT(IN) :: Inquiry
1513 character *(*), INTENT(OUT) :: Result
1514 integer ,INTENT(INOUT) :: Status
1515 SELECT CASE (Inquiry)
1516 CASE ("RANDOM_WRITE","RANDOM_READ","SEQUENTIAL_WRITE","SEQUENTIAL_READ")
1518 CASE ("OPEN_READ","OPEN_COMMIT_WRITE")
1520 CASE ("OPEN_WRITE","OPEN_COMMIT_READ","PARALLEL_IO")
1522 CASE ("SELF_DESCRIBING","SUPPORT_METADATA","SUPPORT_3D_FIELDS")
1527 Result = 'No Result for that inquiry!'
1531 end subroutine ext_pnc_inquiry
1536 subroutine ext_pnc_ioexit(Status)
1538 use ext_pnc_support_routines
1540 include 'wrf_status_codes.h'
1541 # include "pnetcdf.inc"
1542 integer , INTENT(INOUT) ::Status
1544 type(wrf_data_handle),pointer :: DH
1547 if(WrfIOnotInitialized) then
1548 Status = WRF_IO_NOT_INITIALIZED
1549 write(msg,*) 'ext_pnc_ioinit was not called ',__FILE__,', line', __LINE__
1550 call wrf_debug ( FATAL , msg)
1553 do i=1,WrfDataHandleMax
1554 CALL deallocHandle( i , stat )
1557 end subroutine ext_pnc_ioexit
1559 subroutine ext_pnc_get_dom_ti_real(DataHandle,Element,Data,Count,OutCount,Status)
1560 #define ROUTINE_TYPE 'REAL'
1561 #define TYPE_DATA real,intent(out) :: Data(*)
1562 #define TYPE_COUNT integer,intent(in) :: Count
1563 #define TYPE_OUTCOUNT integer,intent(out) :: OutCOunt
1564 #define TYPE_BUFFER real,allocatable :: Buffer(:)
1565 #define NF_TYPE NF_FLOAT
1566 #define NF_ROUTINE NFMPI_GET_ATT_REAL
1567 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))
1568 #include "ext_pnc_get_dom_ti.code"
1569 end subroutine ext_pnc_get_dom_ti_real
1571 subroutine ext_pnc_get_dom_ti_integer(DataHandle,Element,Data,Count,OutCount,Status)
1578 #define ROUTINE_TYPE 'INTEGER'
1579 #define TYPE_DATA integer,intent(out) :: Data(*)
1580 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
1581 #define NF_TYPE NF_INT
1582 #define NF_ROUTINE NFMPI_GET_ATT_INT
1583 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))
1584 #include "ext_pnc_get_dom_ti.code"
1585 end subroutine ext_pnc_get_dom_ti_integer
1587 subroutine ext_pnc_get_dom_ti_double(DataHandle,Element,Data,Count,OutCount,Status)
1594 #define ROUTINE_TYPE 'DOUBLE'
1595 #define TYPE_DATA real*8,intent(out) :: Data(*)
1596 #define TYPE_BUFFER real*8,allocatable :: Buffer(:)
1597 #define NF_TYPE NF_DOUBLE
1598 #define NF_ROUTINE NFMPI_GET_ATT_DOUBLE
1599 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))
1600 #include "ext_pnc_get_dom_ti.code"
1601 end subroutine ext_pnc_get_dom_ti_double
1603 subroutine ext_pnc_get_dom_ti_logical(DataHandle,Element,Data,Count,OutCount,Status)
1610 #define ROUTINE_TYPE 'LOGICAL'
1611 #define TYPE_DATA logical,intent(out) :: Data(*)
1612 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
1613 #define NF_TYPE NF_INT
1614 #define NF_ROUTINE NFMPI_GET_ATT_INT
1615 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))==1
1616 #include "ext_pnc_get_dom_ti.code"
1617 end subroutine ext_pnc_get_dom_ti_logical
1619 subroutine ext_pnc_get_dom_ti_char(DataHandle,Element,Data,Status)
1623 #undef TYPE_OUTCOUNT
1626 #define ROUTINE_TYPE 'CHAR'
1627 #define TYPE_DATA character*(*),intent(out) :: Data
1629 #define TYPE_OUTCOUNT
1631 #define NF_TYPE NF_CHAR
1633 #include "ext_pnc_get_dom_ti.code"
1635 end subroutine ext_pnc_get_dom_ti_char
1637 subroutine ext_pnc_put_dom_ti_real(DataHandle,Element,Data,Count,Status)
1644 #define ROUTINE_TYPE 'REAL'
1645 #define TYPE_DATA real ,intent(in) :: Data(*)
1646 #define TYPE_COUNT integer,intent(in) :: Count
1647 #define NF_ROUTINE NFMPI_PUT_ATT_REAL
1648 #define ARGS NF_FLOAT,i2offset(Count),Data
1649 #include "ext_pnc_put_dom_ti.code"
1650 end subroutine ext_pnc_put_dom_ti_real
1652 subroutine ext_pnc_put_dom_ti_integer(DataHandle,Element,Data,Count,Status)
1659 #define ROUTINE_TYPE 'INTEGER'
1660 #define TYPE_DATA integer,intent(in) :: Data(*)
1661 #define TYPE_COUNT integer,intent(in) :: Count
1662 #define NF_ROUTINE NFMPI_PUT_ATT_INT
1663 #define ARGS NF_INT,i2offset(Count),Data
1664 #include "ext_pnc_put_dom_ti.code"
1665 end subroutine ext_pnc_put_dom_ti_integer
1667 subroutine ext_pnc_put_dom_ti_double(DataHandle,Element,Data,Count,Status)
1674 #define ROUTINE_TYPE 'DOUBLE'
1675 #define TYPE_DATA real*8 ,intent(in) :: Data(*)
1676 #define TYPE_COUNT integer,intent(in) :: Count
1677 #define NF_ROUTINE NFMPI_PUT_ATT_DOUBLE
1678 #define ARGS NF_DOUBLE,i2offset(Count),Data
1679 #include "ext_pnc_put_dom_ti.code"
1680 end subroutine ext_pnc_put_dom_ti_double
1682 subroutine ext_pnc_put_dom_ti_logical(DataHandle,Element,Data,Count,Status)
1688 #define ROUTINE_TYPE 'LOGICAL'
1689 #define TYPE_DATA logical,intent(in) :: Data(*)
1690 #define TYPE_COUNT integer,intent(in) :: Count
1691 #define NF_ROUTINE NFMPI_PUT_ATT_INT
1692 #define ARGS NF_INT,i2offset(Count),Buffer
1694 #include "ext_pnc_put_dom_ti.code"
1695 end subroutine ext_pnc_put_dom_ti_logical
1697 subroutine ext_pnc_put_dom_ti_char(DataHandle,Element,Data,Status)
1704 #define ROUTINE_TYPE 'CHAR'
1705 #define TYPE_DATA character*(*),intent(in) :: Data
1706 #define TYPE_COUNT integer,parameter :: Count=1
1707 #define NF_ROUTINE NFMPI_PUT_ATT_TEXT
1708 #define ARGS i2offset(len_trim(Data)),Data
1709 #include "ext_pnc_put_dom_ti.code"
1710 end subroutine ext_pnc_put_dom_ti_char
1712 subroutine ext_pnc_put_var_ti_real(DataHandle,Element,Var,Data,Count,Status)
1719 #define ROUTINE_TYPE 'REAL'
1720 #define TYPE_DATA real ,intent(in) :: Data(*)
1721 #define TYPE_COUNT integer ,intent(in) :: Count
1722 #define NF_ROUTINE NFMPI_PUT_ATT_REAL
1723 #define ARGS NF_FLOAT,i2offset(Count),Data
1724 #include "ext_pnc_put_var_ti.code"
1725 end subroutine ext_pnc_put_var_ti_real
1727 subroutine ext_pnc_put_var_td_real(DataHandle,Element,DateStr,Var,Data,Count,Status)
1736 #define ROUTINE_TYPE 'REAL'
1737 #define TYPE_DATA real ,intent(in) :: Data(*)
1738 #define TYPE_COUNT integer ,intent(in) :: Count
1739 #define NF_ROUTINE NFMPI_PUT_VARA_REAL_ALL
1740 #define NF_TYPE NF_FLOAT
1741 #define LENGTH Count
1743 #include "ext_pnc_put_var_td.code"
1744 end subroutine ext_pnc_put_var_td_real
1746 subroutine ext_pnc_put_var_ti_double(DataHandle,Element,Var,Data,Count,Status)
1753 #define ROUTINE_TYPE 'DOUBLE'
1754 #define TYPE_DATA real*8 ,intent(in) :: Data(*)
1755 #define TYPE_COUNT integer ,intent(in) :: Count
1756 #define NF_ROUTINE NFMPI_PUT_ATT_DOUBLE
1757 #define ARGS NF_DOUBLE,i2offset(Count),Data
1758 #include "ext_pnc_put_var_ti.code"
1759 end subroutine ext_pnc_put_var_ti_double
1761 subroutine ext_pnc_put_var_td_double(DataHandle,Element,DateStr,Var,Data,Count,Status)
1770 #define ROUTINE_TYPE 'DOUBLE'
1771 #define TYPE_DATA real*8,intent(in) :: Data(*)
1772 #define TYPE_COUNT integer ,intent(in) :: Count
1773 #define NF_ROUTINE NFMPI_PUT_VARA_DOUBLE_ALL
1774 #define NF_TYPE NF_DOUBLE
1775 #define LENGTH Count
1777 #include "ext_pnc_put_var_td.code"
1778 end subroutine ext_pnc_put_var_td_double
1780 subroutine ext_pnc_put_var_ti_integer(DataHandle,Element,Var,Data,Count,Status)
1787 #define ROUTINE_TYPE 'INTEGER'
1788 #define TYPE_DATA integer ,intent(in) :: Data(*)
1789 #define TYPE_COUNT integer ,intent(in) :: Count
1790 #define NF_ROUTINE NFMPI_PUT_ATT_INT
1791 #define ARGS NF_INT,i2offset(Count),Data
1792 #include "ext_pnc_put_var_ti.code"
1793 end subroutine ext_pnc_put_var_ti_integer
1795 subroutine ext_pnc_put_var_td_integer(DataHandle,Element,DateStr,Var,Data,Count,Status)
1804 #define ROUTINE_TYPE 'INTEGER'
1805 #define TYPE_DATA integer ,intent(in) :: Data(*)
1806 #define TYPE_COUNT integer ,intent(in) :: Count
1807 #define NF_ROUTINE NFMPI_PUT_VARA_INT_ALL
1808 #define NF_TYPE NF_INT
1809 #define LENGTH Count
1811 #include "ext_pnc_put_var_td.code"
1812 end subroutine ext_pnc_put_var_td_integer
1814 subroutine ext_pnc_put_var_ti_logical(DataHandle,Element,Var,Data,Count,Status)
1820 #define ROUTINE_TYPE 'LOGICAL'
1821 #define TYPE_DATA logical ,intent(in) :: Data(*)
1822 #define TYPE_COUNT integer ,intent(in) :: Count
1823 #define NF_ROUTINE NFMPI_PUT_ATT_INT
1825 #define ARGS NF_INT,i2offset(Count),Buffer
1826 #include "ext_pnc_put_var_ti.code"
1827 end subroutine ext_pnc_put_var_ti_logical
1829 subroutine ext_pnc_put_var_td_logical(DataHandle,Element,DateStr,Var,Data,Count,Status)
1837 #define ROUTINE_TYPE 'LOGICAL'
1838 #define TYPE_DATA logical ,intent(in) :: Data(*)
1839 #define TYPE_COUNT integer ,intent(in) :: Count
1840 #define NF_ROUTINE NFMPI_PUT_VARA_INT_ALL
1841 #define NF_TYPE NF_INT
1843 #define LENGTH Count
1845 #include "ext_pnc_put_var_td.code"
1846 end subroutine ext_pnc_put_var_td_logical
1848 subroutine ext_pnc_put_var_ti_char(DataHandle,Element,Var,Data,Status)
1855 #define ROUTINE_TYPE 'CHAR'
1856 #define TYPE_DATA character*(*) ,intent(in) :: Data
1858 #define NF_ROUTINE NFMPI_PUT_ATT_TEXT
1859 #define ARGS i2offset(len_trim(Data)),trim(Data)
1861 #include "ext_pnc_put_var_ti.code"
1863 end subroutine ext_pnc_put_var_ti_char
1865 subroutine ext_pnc_put_var_td_char(DataHandle,Element,DateStr,Var,Data,Status)
1874 #define ROUTINE_TYPE 'CHAR'
1875 #define TYPE_DATA character*(*) ,intent(in) :: Data
1877 #define NF_ROUTINE NFMPI_PUT_VARA_TEXT_ALL
1878 #define NF_TYPE NF_CHAR
1879 #define LENGTH len(Data)
1880 #include "ext_pnc_put_var_td.code"
1881 end subroutine ext_pnc_put_var_td_char
1883 subroutine ext_pnc_get_var_ti_real(DataHandle,Element,Var,Data,Count,OutCount,Status)
1888 #undef TYPE_OUTCOUNT
1892 #define ROUTINE_TYPE 'REAL'
1893 #define TYPE_DATA real ,intent(out) :: Data(*)
1894 #define TYPE_BUFFER real ,allocatable :: Buffer(:)
1895 #define TYPE_COUNT integer,intent(in) :: Count
1896 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1897 #define NF_TYPE NF_FLOAT
1898 #define NF_ROUTINE NFMPI_GET_ATT_REAL
1899 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))
1900 #include "ext_pnc_get_var_ti.code"
1901 end subroutine ext_pnc_get_var_ti_real
1903 subroutine ext_pnc_get_var_td_real(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
1908 #undef TYPE_OUTCOUNT
1913 #define ROUTINE_TYPE 'REAL'
1914 #define TYPE_DATA real ,intent(out) :: Data(*)
1915 #define TYPE_BUFFER real
1916 #define TYPE_COUNT integer,intent(in) :: Count
1917 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1918 #define NF_TYPE NF_FLOAT
1919 #define NF_ROUTINE NFMPI_GET_VARA_REAL_ALL
1920 #define LENGTH min(Count,Len1)
1921 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))
1922 #include "ext_pnc_get_var_td.code"
1923 end subroutine ext_pnc_get_var_td_real
1925 subroutine ext_pnc_get_var_ti_double(DataHandle,Element,Var,Data,Count,OutCount,Status)
1930 #undef TYPE_OUTCOUNT
1934 #define ROUTINE_TYPE 'DOUBLE'
1935 #define TYPE_DATA real*8 ,intent(out) :: Data(*)
1936 #define TYPE_BUFFER real*8 ,allocatable :: Buffer(:)
1937 #define TYPE_COUNT integer,intent(in) :: Count
1938 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1939 #define NF_TYPE NF_DOUBLE
1940 #define NF_ROUTINE NFMPI_GET_ATT_DOUBLE
1941 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))
1942 #include "ext_pnc_get_var_ti.code"
1943 end subroutine ext_pnc_get_var_ti_double
1945 subroutine ext_pnc_get_var_td_double(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
1950 #undef TYPE_OUTCOUNT
1955 #define ROUTINE_TYPE 'DOUBLE'
1956 #define TYPE_DATA real*8 ,intent(out) :: Data(*)
1957 #define TYPE_BUFFER real*8
1958 #define TYPE_COUNT integer,intent(in) :: Count
1959 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1960 #define NF_TYPE NF_DOUBLE
1961 #define NF_ROUTINE NFMPI_GET_VARA_DOUBLE_ALL
1962 #define LENGTH min(Count,Len1)
1963 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))
1964 #include "ext_pnc_get_var_td.code"
1965 end subroutine ext_pnc_get_var_td_double
1967 subroutine ext_pnc_get_var_ti_integer(DataHandle,Element,Var,Data,Count,OutCount,Status)
1972 #undef TYPE_OUTCOUNT
1976 #define ROUTINE_TYPE 'INTEGER'
1977 #define TYPE_DATA integer,intent(out) :: Data(*)
1978 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
1979 #define TYPE_COUNT integer,intent(in) :: Count
1980 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1981 #define NF_TYPE NF_INT
1982 #define NF_ROUTINE NFMPI_GET_ATT_INT
1983 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))
1984 #include "ext_pnc_get_var_ti.code"
1985 end subroutine ext_pnc_get_var_ti_integer
1987 subroutine ext_pnc_get_var_td_integer(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
1992 #undef TYPE_OUTCOUNT
1997 #define ROUTINE_TYPE 'INTEGER'
1998 #define TYPE_DATA integer,intent(out) :: Data(*)
1999 #define TYPE_BUFFER integer
2000 #define TYPE_COUNT integer,intent(in) :: Count
2001 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2002 #define NF_TYPE NF_INT
2003 #define NF_ROUTINE NFMPI_GET_VARA_INT_ALL
2004 #define LENGTH min(Count,Len1)
2005 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))
2006 #include "ext_pnc_get_var_td.code"
2007 end subroutine ext_pnc_get_var_td_integer
2009 subroutine ext_pnc_get_var_ti_logical(DataHandle,Element,Var,Data,Count,OutCount,Status)
2014 #undef TYPE_OUTCOUNT
2018 #define ROUTINE_TYPE 'LOGICAL'
2019 #define TYPE_DATA logical,intent(out) :: Data(*)
2020 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
2021 #define TYPE_COUNT integer,intent(in) :: Count
2022 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2023 #define NF_TYPE NF_INT
2024 #define NF_ROUTINE NFMPI_GET_ATT_INT
2025 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))==1
2026 #include "ext_pnc_get_var_ti.code"
2027 end subroutine ext_pnc_get_var_ti_logical
2029 subroutine ext_pnc_get_var_td_logical(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
2034 #undef TYPE_OUTCOUNT
2039 #define ROUTINE_TYPE 'LOGICAL'
2040 #define TYPE_DATA logical,intent(out) :: Data(*)
2041 #define TYPE_BUFFER integer
2042 #define TYPE_COUNT integer,intent(in) :: Count
2043 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2044 #define NF_TYPE NF_INT
2045 #define NF_ROUTINE NFMPI_GET_VARA_INT_ALL
2046 #define LENGTH min(Count,Len1)
2047 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))==1
2048 #include "ext_pnc_get_var_td.code"
2049 end subroutine ext_pnc_get_var_td_logical
2051 subroutine ext_pnc_get_var_ti_char(DataHandle,Element,Var,Data,Status)
2056 #undef TYPE_OUTCOUNT
2060 #define ROUTINE_TYPE 'CHAR'
2061 #define TYPE_DATA character*(*) ,intent(out) :: Data
2063 #define TYPE_COUNT integer :: Count = 1
2064 #define TYPE_OUTCOUNT
2065 #define NF_TYPE NF_CHAR
2066 #define NF_ROUTINE NFMPI_GET_ATT_TEXT
2069 #include "ext_pnc_get_var_ti.code"
2071 end subroutine ext_pnc_get_var_ti_char
2073 subroutine ext_pnc_get_var_td_char(DataHandle,Element,DateStr,Var,Data,Status)
2078 #undef TYPE_OUTCOUNT
2082 #define ROUTINE_TYPE 'CHAR'
2083 #define TYPE_DATA character*(*) ,intent(out) :: Data
2084 #define TYPE_BUFFER character (80)
2085 #define TYPE_COUNT integer :: Count = 1
2086 #define TYPE_OUTCOUNT
2087 #define NF_TYPE NF_CHAR
2088 #define NF_ROUTINE NFMPI_GET_VARA_TEXT_ALL
2091 #include "ext_pnc_get_var_td.code"
2093 end subroutine ext_pnc_get_var_td_char
2095 subroutine ext_pnc_put_dom_td_real(DataHandle,Element,DateStr,Data,Count,Status)
2096 integer ,intent(in) :: DataHandle
2097 character*(*) ,intent(in) :: Element
2098 character*(*) ,intent(in) :: DateStr
2099 real ,intent(in) :: Data(*)
2100 integer ,intent(in) :: Count
2101 integer ,intent(out) :: Status
2103 call ext_pnc_put_var_td_real(DataHandle,Element,DateStr, &
2104 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2106 end subroutine ext_pnc_put_dom_td_real
2108 subroutine ext_pnc_put_dom_td_integer(DataHandle,Element,DateStr,Data,Count,Status)
2109 integer ,intent(in) :: DataHandle
2110 character*(*) ,intent(in) :: Element
2111 character*(*) ,intent(in) :: DateStr
2112 integer ,intent(in) :: Data(*)
2113 integer ,intent(in) :: Count
2114 integer ,intent(out) :: Status
2116 call ext_pnc_put_var_td_integer(DataHandle,Element,DateStr, &
2117 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2119 end subroutine ext_pnc_put_dom_td_integer
2121 subroutine ext_pnc_put_dom_td_double(DataHandle,Element,DateStr,Data,Count,Status)
2122 integer ,intent(in) :: DataHandle
2123 character*(*) ,intent(in) :: Element
2124 character*(*) ,intent(in) :: DateStr
2125 real*8 ,intent(in) :: Data(*)
2126 integer ,intent(in) :: Count
2127 integer ,intent(out) :: Status
2129 call ext_pnc_put_var_td_double(DataHandle,Element,DateStr, &
2130 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2132 end subroutine ext_pnc_put_dom_td_double
2134 subroutine ext_pnc_put_dom_td_logical(DataHandle,Element,DateStr,Data,Count,Status)
2135 integer ,intent(in) :: DataHandle
2136 character*(*) ,intent(in) :: Element
2137 character*(*) ,intent(in) :: DateStr
2138 logical ,intent(in) :: Data(*)
2139 integer ,intent(in) :: Count
2140 integer ,intent(out) :: Status
2142 call ext_pnc_put_var_td_logical(DataHandle,Element,DateStr, &
2143 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2145 end subroutine ext_pnc_put_dom_td_logical
2147 subroutine ext_pnc_put_dom_td_char(DataHandle,Element,DateStr,Data,Status)
2148 integer ,intent(in) :: DataHandle
2149 character*(*) ,intent(in) :: Element
2150 character*(*) ,intent(in) :: DateStr
2151 character*(*) ,intent(in) :: Data
2152 integer ,intent(out) :: Status
2154 call ext_pnc_put_var_td_char(DataHandle,Element,DateStr, &
2155 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Status)
2157 end subroutine ext_pnc_put_dom_td_char
2159 subroutine ext_pnc_get_dom_td_real(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2160 integer ,intent(in) :: DataHandle
2161 character*(*) ,intent(in) :: Element
2162 character*(*) ,intent(in) :: DateStr
2163 real ,intent(out) :: Data(*)
2164 integer ,intent(in) :: Count
2165 integer ,intent(out) :: OutCount
2166 integer ,intent(out) :: Status
2167 call ext_pnc_get_var_td_real(DataHandle,Element,DateStr, &
2168 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2170 end subroutine ext_pnc_get_dom_td_real
2172 subroutine ext_pnc_get_dom_td_integer(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2173 integer ,intent(in) :: DataHandle
2174 character*(*) ,intent(in) :: Element
2175 character*(*) ,intent(in) :: DateStr
2176 integer ,intent(out) :: Data(*)
2177 integer ,intent(in) :: Count
2178 integer ,intent(out) :: OutCount
2179 integer ,intent(out) :: Status
2180 call ext_pnc_get_var_td_integer(DataHandle,Element,DateStr, &
2181 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2183 end subroutine ext_pnc_get_dom_td_integer
2185 subroutine ext_pnc_get_dom_td_double(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2186 integer ,intent(in) :: DataHandle
2187 character*(*) ,intent(in) :: Element
2188 character*(*) ,intent(in) :: DateStr
2189 real*8 ,intent(out) :: Data(*)
2190 integer ,intent(in) :: Count
2191 integer ,intent(out) :: OutCount
2192 integer ,intent(out) :: Status
2193 call ext_pnc_get_var_td_double(DataHandle,Element,DateStr, &
2194 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2196 end subroutine ext_pnc_get_dom_td_double
2198 subroutine ext_pnc_get_dom_td_logical(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2199 integer ,intent(in) :: DataHandle
2200 character*(*) ,intent(in) :: Element
2201 character*(*) ,intent(in) :: DateStr
2202 logical ,intent(out) :: Data(*)
2203 integer ,intent(in) :: Count
2204 integer ,intent(out) :: OutCount
2205 integer ,intent(out) :: Status
2206 call ext_pnc_get_var_td_logical(DataHandle,Element,DateStr, &
2207 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2209 end subroutine ext_pnc_get_dom_td_logical
2211 subroutine ext_pnc_get_dom_td_char(DataHandle,Element,DateStr,Data,Status)
2212 integer ,intent(in) :: DataHandle
2213 character*(*) ,intent(in) :: Element
2214 character*(*) ,intent(in) :: DateStr
2215 character*(*) ,intent(out) :: Data
2216 integer ,intent(out) :: Status
2217 call ext_pnc_get_var_td_char(DataHandle,Element,DateStr, &
2218 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Status)
2220 end subroutine ext_pnc_get_dom_td_char
2223 subroutine ext_pnc_write_field(DataHandle,DateStr,Var,Field,FieldType,Comm, &
2224 IOComm, DomainDesc, MemoryOrdIn, Stagger, DimNames, &
2225 DomainStart,DomainEnd,MemoryStart,MemoryEnd,PatchStart,PatchEnd,Status)
2227 use ext_pnc_support_routines
2229 include 'wrf_status_codes.h'
2230 # include "pnetcdf.inc"
2231 integer ,intent(in) :: DataHandle
2232 character*(*) ,intent(in) :: DateStr
2233 character*(*) ,intent(in) :: Var
2234 integer ,intent(inout) :: Field(*)
2235 integer ,intent(in) :: FieldType
2236 integer ,intent(inout) :: Comm
2237 integer ,intent(inout) :: IOComm
2238 integer ,intent(in) :: DomainDesc
2239 character*(*) ,intent(in) :: MemoryOrdIn
2240 character*(*) ,intent(in) :: Stagger ! Dummy for now
2241 character*(*) ,dimension(*) ,intent(in) :: DimNames
2242 integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
2243 integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
2244 integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
2245 integer ,intent(out) :: Status
2246 character (3) :: MemoryOrder
2247 type(wrf_data_handle) ,pointer :: DH
2250 character (VarNameLen) :: VarName
2251 character (3) :: MemO
2252 character (3) :: UCMemO
2254 integer ,dimension(NVarDims) :: Length_global
2255 integer ,dimension(NVarDims) :: Length
2256 integer ,dimension(NVarDims) :: VDimIDs
2257 character(80),dimension(NVarDims) :: RODimNames
2258 integer ,dimension(NVarDims) :: StoredStart
2259 integer ,dimension(:,:,:,:),allocatable :: XField
2263 integer :: i1,i2,j1,j2,k1,k2
2264 integer :: x1,x2,y1,y2,z1,z2
2265 integer :: l1,l2,m1,m2,n1,n2
2268 character (80) :: NullName
2271 MemoryOrder = trim(adjustl(MemoryOrdIn))
2273 call GetDim(MemoryOrder,NDim,Status)
2274 if(Status /= WRF_NO_ERR) then
2275 write(msg,*) 'Warning BAD MEMORY ORDER |',MemoryOrder,'| in ',__FILE__,', line', __LINE__
2276 call wrf_debug ( WARN , TRIM(msg))
2279 call DateCheck(DateStr,Status)
2280 if(Status /= WRF_NO_ERR) then
2281 write(msg,*) 'Warning DATE STRING ERROR |',DateStr,'| in ',__FILE__,', line', __LINE__
2282 call wrf_debug ( WARN , TRIM(msg))
2286 call GetDH(DataHandle,DH,Status)
2287 if(Status /= WRF_NO_ERR) then
2288 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2289 call wrf_debug ( WARN , TRIM(msg))
2294 write(msg,*)'ext_pnc_write_field: called for ',TRIM(Var)
2295 CALL wrf_debug( 100, msg )
2298 Length(1:NDim) = PatchEnd(1:NDim)-PatchStart(1:NDim)+1
2299 Length_global(1:NDim) = DomainEnd(1:NDim)-DomainStart(1:NDim)+1
2302 call ExtOrder(MemoryOrder,Length,Status)
2303 call ExtOrder(MemoryOrder,Length_global,Status)
2305 call ExtOrderStr(MemoryOrder,DimNames,RODimNames,Status)
2307 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2308 Status = WRF_WARN_FILE_NOT_OPENED
2309 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2310 call wrf_debug ( WARN , TRIM(msg))
2311 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
2312 Status = WRF_WARN_WRITE_RONLY_FILE
2313 write(msg,*) 'Warning WRITE READ ONLY FILE in ',__FILE__,', line', __LINE__
2314 call wrf_debug ( WARN , TRIM(msg))
2315 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2317 if(DH%VarNames(NVar) == VarName ) then
2318 Status = WRF_WARN_2DRYRUNS_1VARIABLE
2319 write(msg,*) 'Warning 2 DRYRUNS 1 VARIABLE in ',__FILE__,', line', __LINE__
2320 call wrf_debug ( WARN , TRIM(msg))
2322 elseif(DH%VarNames(NVar) == NO_NAME) then
2323 DH%VarNames(NVar) = VarName
2326 elseif(NVar == MaxVars) then
2327 Status = WRF_WARN_TOO_MANY_VARIABLES
2328 write(msg,*) 'Warning TOO MANY VARIABLES in ',__FILE__,', line', __LINE__
2329 call wrf_debug ( WARN , TRIM(msg))
2334 if(RODimNames(j) == NullName .or. RODimNames(j) == '') then
2336 if(DH%DimLengths(i) == Length_global(j)) then
2338 elseif(DH%DimLengths(i) == NO_DIM) then
2339 stat = NFMPI_DEF_DIM(NCID,DH%DimNames(i),i2offset(Length_global(j)),DH%DimIDs(i))
2340 call netcdf_err(stat,Status)
2341 if(Status /= WRF_NO_ERR) then
2342 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
2343 call wrf_debug ( WARN , TRIM(msg))
2346 DH%DimLengths(i) = Length_global(j)
2348 elseif(i == MaxDims) then
2349 Status = WRF_WARN_TOO_MANY_DIMS
2350 write(msg,*) 'Warning TOO MANY DIMENSIONS in ',__FILE__,', line', __LINE__
2351 call wrf_debug ( WARN , TRIM(msg))
2355 else !look for input name and check if already defined
2358 if (DH%DimNames(i) == RODimNames(j)) then
2359 if (DH%DimLengths(i) == Length_global(j)) then
2363 Status = WRF_WARN_DIMNAME_REDEFINED
2364 write(msg,*) 'Warning DIM ',i,', NAME ',TRIM(DH%DimNames(i)),' REDIFINED by var ', &
2365 TRIM(Var),' ',DH%DimLengths(i),Length_global(j) ,' in ', __FILE__ ,' line', __LINE__
2366 call wrf_debug ( WARN , TRIM(msg))
2373 if (DH%DimLengths(i) == NO_DIM) then
2374 DH%DimNames(i) = RODimNames(j)
2375 stat = NFMPI_DEF_DIM(NCID,DH%DimNames(i),i2offset(Length_global(j)),DH%DimIDs(i))
2376 call netcdf_err(stat,Status)
2377 if(Status /= WRF_NO_ERR) then
2378 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
2379 call wrf_debug ( WARN , TRIM(msg))
2382 DH%DimLengths(i) = Length_global(j)
2384 elseif(i == MaxDims) then
2385 Status = WRF_WARN_TOO_MANY_DIMS
2386 write(msg,*) 'Warning TOO MANY DIMENSIONS in ',__FILE__,', line', __LINE__
2387 call wrf_debug ( WARN , TRIM(msg))
2393 VDimIDs(j) = DH%DimIDs(i)
2394 DH%VarDimLens(j,NVar) = Length_global(j)
2396 VDimIDs(NDim+1) = DH%DimUnlimID
2397 select case (FieldType)
2407 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
2408 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
2409 call wrf_debug ( WARN , TRIM(msg))
2414 stat = NFMPI_DEF_VAR(NCID,VarName,XType,NDim+1,VDimIDs,VarID)
2415 call netcdf_err(stat,Status)
2416 if(Status /= WRF_NO_ERR) then
2417 write(msg,*) 'ext_pnc_write_field: NetCDF error for ',TRIM(VarName),' in ',__FILE__,', line', __LINE__
2418 call wrf_debug ( WARN , TRIM(msg))
2421 DH%VarIDs(NVar) = VarID
2422 stat = NFMPI_PUT_ATT_INT(NCID,VarID,'FieldType',NF_INT,i2offset(1),FieldType)
2423 call netcdf_err(stat,Status)
2424 if(Status /= WRF_NO_ERR) then
2425 write(msg,*) 'ext_pnc_write_field: NetCDF error in ',__FILE__,', line', __LINE__
2426 call wrf_debug ( WARN , TRIM(msg))
2429 call reorder(MemoryOrder,MemO)
2430 call uppercase(MemO,UCMemO)
2431 stat = NFMPI_PUT_ATT_TEXT(NCID,VarID,'MemoryOrder',i2offset(3),UCMemO)
2432 call netcdf_err(stat,Status)
2433 if(Status /= WRF_NO_ERR) then
2434 write(msg,*) 'ext_pnc_write_field: NetCDF error in ',__FILE__,', line', __LINE__
2435 call wrf_debug ( WARN , TRIM(msg))
2438 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
2439 do NVar=1,DH%NumVars
2440 if(DH%VarNames(NVar) == VarName) then
2442 elseif(NVar == DH%NumVars) then
2443 Status = WRF_WARN_VAR_NF
2444 write(msg,*) 'Warning VARIABLE NOT FOUND in ',__FILE__,', line', __LINE__
2445 call wrf_debug ( WARN , TRIM(msg))
2449 VarID = DH%VarIDs(NVar)
2451 if(Length_global(j) /= DH%VarDimLens(j,NVar) .AND. DH%FileStatus /= WRF_FILE_OPENED_FOR_UPDATE ) then
2452 Status = WRF_WARN_WRTLEN_NE_DRRUNLEN
2453 write(msg,*) 'Warning LENGTH != DRY RUN LENGTH for |', &
2454 VarName,'| dim ',j,' in ',__FILE__,', line', __LINE__
2455 call wrf_debug ( WARN , TRIM(msg))
2456 write(msg,*) ' LENGTH ',Length_global(j),' DRY RUN LENGTH ',DH%VarDimLens(j,NVar)
2457 call wrf_debug ( WARN , TRIM(msg))
2459 !jm 061024 elseif(PatchStart(j) < MemoryStart(j)) then
2460 !jm elseif(DomainStart(j) < MemoryStart(j)) then
2461 elseif(PatchStart(j) < MemoryStart(j)) then
2462 Status = WRF_WARN_DIMENSION_ERROR
2463 write(msg,*) 'Warning DIMENSION ERROR for |',VarName, &
2464 '| in ',__FILE__,', line', __LINE__
2465 call wrf_debug ( WARN , TRIM(msg))
2470 call GetIndices(NDim,MemoryStart,MemoryEnd,l1,l2,m1,m2,n1,n2)
2471 call GetIndices(NDim,StoredStart,Length ,x1,x2,y1,y2,z1,z2)
2472 call GetIndices(NDim,PatchStart, PatchEnd ,i1,i2,j1,j2,k1,k2)
2474 if(FieldType == WRF_DOUBLE) di=2
2475 allocate(XField(di,x1:x2,y1:y2,z1:z2), STAT=stat)
2477 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
2478 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
2479 call wrf_debug ( FATAL , TRIM(msg))
2482 call Transpose('write',MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
2483 ,XField,x1,x2,y1,y2,z1,z2 &
2484 ,i1,i2,j1,j2,k1,k2 )
2485 StoredStart(1:NDim) = PatchStart(1:NDim)
2486 call ExtOrder(MemoryOrder,StoredStart,Status)
2487 call FieldIO('write',DataHandle,DateStr,StoredStart,Length,MemoryOrder, &
2488 FieldType,NCID,VarID,XField,Status)
2489 if(Status /= WRF_NO_ERR) then
2490 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2491 call wrf_debug ( WARN , TRIM(msg))
2494 deallocate(XField, STAT=stat)
2496 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
2497 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
2498 call wrf_debug ( FATAL , TRIM(msg))
2502 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2503 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2504 call wrf_debug ( FATAL , TRIM(msg))
2506 DH%first_operation = .FALSE.
2508 end subroutine ext_pnc_write_field
2510 subroutine ext_pnc_read_field(DataHandle,DateStr,Var,Field,FieldType,Comm, &
2511 IOComm, DomainDesc, MemoryOrdIn, Stagger, DimNames, &
2512 DomainStart,DomainEnd,MemoryStart,MemoryEnd,PatchStart,PatchEnd,Status)
2514 use ext_pnc_support_routines
2516 include 'wrf_status_codes.h'
2517 # include "pnetcdf.inc"
2518 integer ,intent(in) :: DataHandle
2519 character*(*) ,intent(in) :: DateStr
2520 character*(*) ,intent(in) :: Var
2521 integer ,intent(out) :: Field(*)
2522 integer ,intent(in) :: FieldType
2523 integer ,intent(inout) :: Comm
2524 integer ,intent(inout) :: IOComm
2525 integer ,intent(in) :: DomainDesc
2526 character*(*) ,intent(in) :: MemoryOrdIn
2527 character*(*) ,intent(in) :: Stagger ! Dummy for now
2528 character*(*) , dimension (*) ,intent(in) :: DimNames
2529 integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
2530 integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
2531 integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
2532 integer ,intent(out) :: Status
2533 character (3) :: MemoryOrder
2534 character (NF_MAX_NAME) :: dimname
2535 type(wrf_data_handle) ,pointer :: DH
2538 character (VarNameLen) :: VarName
2540 integer ,dimension(NVarDims) :: VCount
2541 integer ,dimension(NVarDims) :: VStart
2542 integer ,dimension(NVarDims) :: Length
2543 integer ,dimension(NVarDims) :: VDimIDs
2544 integer ,dimension(NVarDims) :: MemS
2545 integer ,dimension(NVarDims) :: MemE
2546 integer ,dimension(NVarDims) :: StoredStart
2547 integer ,dimension(NVarDims) :: StoredLen
2548 integer(KIND=MPI_OFFSET_KIND) ,dimension(NVarDims) :: StoredLen_okind
2549 integer ,dimension(:,:,:,:) ,allocatable :: XField
2552 integer :: i1,i2,j1,j2,k1,k2
2553 integer :: x1,x2,y1,y2,z1,z2
2554 integer :: l1,l2,m1,m2,n1,n2
2555 character (VarNameLen) :: Name
2557 integer :: StoredDim
2559 integer(KIND=MPI_OFFSET_KIND) :: Len
2564 MemoryOrder = trim(adjustl(MemoryOrdIn))
2565 call GetDim(MemoryOrder,NDim,Status)
2566 if(Status /= WRF_NO_ERR) then
2567 write(msg,*) 'Warning BAD MEMORY ORDER |',TRIM(MemoryOrder),'| for |', &
2568 TRIM(Var),'| in ext_pnc_read_field ',__FILE__,', line', __LINE__
2569 call wrf_debug ( WARN , TRIM(msg))
2572 call DateCheck(DateStr,Status)
2573 if(Status /= WRF_NO_ERR) then
2574 write(msg,*) 'Warning DATE STRING ERROR |',TRIM(DateStr),'| for |',TRIM(Var), &
2575 '| in ext_pnc_read_field ',__FILE__,', line', __LINE__
2576 call wrf_debug ( WARN , TRIM(msg))
2580 call GetDH(DataHandle,DH,Status)
2581 if(Status /= WRF_NO_ERR) then
2582 write(msg,*) 'Warning Status = ',Status,' in ext_pnc_read_field ',__FILE__,', line', __LINE__
2583 call wrf_debug ( WARN , TRIM(msg))
2586 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2587 Status = WRF_WARN_FILE_NOT_OPENED
2588 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2589 call wrf_debug ( WARN , TRIM(msg))
2590 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2591 ! jm it is okay to have a dry run read. means read is called between ofrb and ofrc. Just return.
2592 ! Status = WRF_WARN_DRYRUN_READ
2593 ! write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2594 ! call wrf_debug ( WARN , TRIM(msg))
2597 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2598 Status = WRF_WARN_READ_WONLY_FILE
2599 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2600 call wrf_debug ( WARN , TRIM(msg))
2601 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE ) then
2604 Length(1:NDim) = PatchEnd(1:NDim)-PatchStart(1:NDim)+1
2605 StoredStart(1:NDim) = PatchStart(1:NDim)
2607 call ExtOrder(MemoryOrder,Length,Status)
2609 stat = NFMPI_INQ_VARID(NCID,VarName,VarID)
2610 call netcdf_err(stat,Status)
2611 if(Status /= WRF_NO_ERR) then
2612 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__,' Varname ',Varname
2613 call wrf_debug ( WARN , TRIM(msg))
2616 stat = NFMPI_INQ_VAR(NCID,VarID,Name,XType,StoredDim,VDimIDs,NAtts)
2617 call netcdf_err(stat,Status)
2618 if(Status /= WRF_NO_ERR) then
2619 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
2620 call wrf_debug ( WARN , TRIM(msg))
2623 stat = NFMPI_GET_ATT_INT(NCID,VarID,'FieldType',FType)
2624 call netcdf_err(stat,Status)
2625 if(Status /= WRF_NO_ERR) then
2626 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
2627 call wrf_debug ( WARN , TRIM(msg))
2630 ! allow coercion between double and single prec real
2631 !jm if(FieldType /= Ftype) then
2632 if( (FieldType == WRF_REAL .OR. FieldType == WRF_DOUBLE) ) then
2633 if ( .NOT. (Ftype == WRF_REAL .OR. Ftype == WRF_DOUBLE )) then
2634 Status = WRF_WARN_TYPE_MISMATCH
2635 write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
2636 call wrf_debug ( WARN , TRIM(msg))
2639 else if(FieldType /= Ftype) then
2640 Status = WRF_WARN_TYPE_MISMATCH
2641 write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
2642 call wrf_debug ( WARN , TRIM(msg))
2645 select case (FieldType)
2647 ! allow coercion between double and single prec real
2648 if(.NOT. (XType == NF_FLOAT .OR. XType == NF_DOUBLE) ) then
2649 Status = WRF_WARN_TYPE_MISMATCH
2650 write(msg,*) 'Warning REAL TYPE MISMATCH in ',__FILE__,', line', __LINE__
2653 ! allow coercion between double and single prec real
2654 if(.NOT. (XType == NF_FLOAT .OR. XType == NF_DOUBLE) ) then
2655 Status = WRF_WARN_TYPE_MISMATCH
2656 write(msg,*) 'Warning DOUBLE TYPE MISMATCH in ',__FILE__,', line', __LINE__
2659 if(XType /= NF_INT) then
2660 Status = WRF_WARN_TYPE_MISMATCH
2661 write(msg,*) 'Warning INTEGER TYPE MISMATCH in ',__FILE__,', line', __LINE__
2664 if(XType /= NF_INT) then
2665 Status = WRF_WARN_TYPE_MISMATCH
2666 write(msg,*) 'Warning LOGICAL TYPE MISMATCH in ',__FILE__,', line', __LINE__
2669 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
2670 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
2672 if(Status /= WRF_NO_ERR) then
2673 call wrf_debug ( WARN , TRIM(msg))
2676 ! NDim=0 for scalars. Handle read of old NDim=1 files. TBH: 20060502
2677 IF ( ( NDim == 0 ) .AND. ( StoredDim == 2 ) ) THEN
2678 stat = NFMPI_INQ_DIMNAME(NCID,VDimIDs(1),dimname)
2679 call netcdf_err(stat,Status)
2680 if(Status /= WRF_NO_ERR) then
2681 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
2682 call wrf_debug ( WARN , TRIM(msg))
2685 IF ( dimname(1:10) == 'ext_scalar' ) THEN
2690 if(StoredDim /= NDim+1) then
2691 Status = WRF_ERR_FATAL_BAD_VARIABLE_DIM
2692 write(msg,*) 'Fatal error BAD VARIABLE DIMENSION in ext_pnc_read_field ',TRIM(Var),TRIM(DateStr)
2693 call wrf_debug ( FATAL , msg)
2694 write(msg,*) ' StoredDim ', StoredDim, ' .NE. NDim+1 ', NDim+1
2695 call wrf_debug ( FATAL , msg)
2699 stat = NFMPI_INQ_DIMLEN(NCID,VDimIDs(j),StoredLen_okind(j))
2700 call netcdf_err(stat,Status)
2701 if(Status /= WRF_NO_ERR) then
2702 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
2703 call wrf_debug ( WARN , TRIM(msg))
2706 StoredLen(j) = StoredLen_okind(j)
2707 if(Length(j) > StoredLen(j)) then
2708 Status = WRF_WARN_READ_PAST_EOF
2709 write(msg,*) 'Warning READ PAST EOF in ext_pnc_read_field of ',TRIM(Var),Length(j),'>',StoredLen(j)
2710 call wrf_debug ( WARN , TRIM(msg))
2712 elseif(Length(j) <= 0) then
2713 Status = WRF_WARN_ZERO_LENGTH_READ
2714 write(msg,*) 'Warning ZERO LENGTH READ in ',__FILE__,', line', __LINE__
2715 call wrf_debug ( WARN , TRIM(msg))
2717 elseif(DomainStart(j) < MemoryStart(j)) then
2718 Status = WRF_WARN_DIMENSION_ERROR
2719 write(msg,*) 'Warning dim ',j,' DomainStart (',DomainStart(j), &
2720 ') < MemoryStart (',MemoryStart(j),') in ',__FILE__,', line', __LINE__
2721 call wrf_debug ( WARN , TRIM(msg))
2727 call GetIndices(NDim,MemoryStart,MemoryEnd,l1,l2,m1,m2,n1,n2)
2728 call GetIndices(NDim,StoredStart,Length,x1,x2,y1,y2,z1,z2)
2729 !jm call GetIndices(NDim,DomainStart,DomainEnd,i1,i2,j1,j2,k1,k2)
2730 call GetIndices(NDim,PatchStart,PatchEnd,i1,i2,j1,j2,k1,k2)
2732 StoredStart(1:NDim) = PatchStart(1:NDim)
2733 call ExtOrder(MemoryOrder,StoredStart,Status)
2736 if(FieldType == WRF_DOUBLE) di=2
2737 allocate(XField(di,x1:x2,y1:y2,z1:z2), STAT=stat)
2739 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
2740 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
2741 call wrf_debug ( FATAL , msg)
2744 call FieldIO('read',DataHandle,DateStr,StoredStart,Length,MemoryOrder, &
2745 FieldType,NCID,VarID,XField,Status)
2746 if(Status /= WRF_NO_ERR) then
2747 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2748 call wrf_debug ( WARN , TRIM(msg))
2751 call Transpose('read',MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
2752 ,XField,x1,x2,y1,y2,z1,z2 &
2753 ,i1,i2,j1,j2,k1,k2 )
2754 deallocate(XField, STAT=stat)
2756 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
2757 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
2758 call wrf_debug ( FATAL , msg)
2762 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2763 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2764 call wrf_debug ( FATAL , msg)
2766 DH%first_operation = .FALSE.
2768 end subroutine ext_pnc_read_field
2770 subroutine ext_pnc_inquire_opened( DataHandle, FileName , FileStatus, Status )
2772 use ext_pnc_support_routines
2774 include 'wrf_status_codes.h'
2775 integer ,intent(in) :: DataHandle
2776 character*(*) ,intent(in) :: FileName
2777 integer ,intent(out) :: FileStatus
2778 integer ,intent(out) :: Status
2779 type(wrf_data_handle) ,pointer :: DH
2781 call GetDH(DataHandle,DH,Status)
2782 if(Status /= WRF_NO_ERR) then
2783 FileStatus = WRF_FILE_NOT_OPENED
2786 if(FileName /= DH%FileName) then
2787 FileStatus = WRF_FILE_NOT_OPENED
2789 FileStatus = DH%FileStatus
2793 end subroutine ext_pnc_inquire_opened
2795 subroutine ext_pnc_inquire_filename( Datahandle, FileName, FileStatus, Status )
2797 use ext_pnc_support_routines
2799 include 'wrf_status_codes.h'
2800 integer ,intent(in) :: DataHandle
2801 character*(*) ,intent(out) :: FileName
2802 integer ,intent(out) :: FileStatus
2803 integer ,intent(out) :: Status
2804 type(wrf_data_handle) ,pointer :: DH
2805 FileStatus = WRF_FILE_NOT_OPENED
2806 call GetDH(DataHandle,DH,Status)
2807 if(Status /= WRF_NO_ERR) then
2808 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2809 call wrf_debug ( WARN , TRIM(msg))
2812 FileName = DH%FileName
2813 FileStatus = DH%FileStatus
2816 end subroutine ext_pnc_inquire_filename
2818 subroutine ext_pnc_set_time(DataHandle, DateStr, Status)
2820 use ext_pnc_support_routines
2822 include 'wrf_status_codes.h'
2823 integer ,intent(in) :: DataHandle
2824 character*(*) ,intent(in) :: DateStr
2825 integer ,intent(out) :: Status
2826 type(wrf_data_handle) ,pointer :: DH
2829 call DateCheck(DateStr,Status)
2830 if(Status /= WRF_NO_ERR) then
2831 write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
2832 call wrf_debug ( WARN , TRIM(msg))
2835 call GetDH(DataHandle,DH,Status)
2836 if(Status /= WRF_NO_ERR) then
2837 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2838 call wrf_debug ( WARN , TRIM(msg))
2841 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2842 Status = WRF_WARN_FILE_NOT_OPENED
2843 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2844 call wrf_debug ( WARN , TRIM(msg))
2845 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2846 Status = WRF_WARN_FILE_NOT_COMMITTED
2847 write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
2848 call wrf_debug ( WARN , TRIM(msg))
2849 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2850 Status = WRF_WARN_READ_WONLY_FILE
2851 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2852 call wrf_debug ( WARN , TRIM(msg))
2853 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
2855 if(DH%Times(i)==DateStr) then
2859 if(i==MaxTimes) then
2860 Status = WRF_WARN_TIME_NF
2864 DH%CurrentVariable = 0
2867 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2868 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2869 call wrf_debug ( FATAL , msg)
2872 end subroutine ext_pnc_set_time
2874 subroutine ext_pnc_get_next_time(DataHandle, DateStr, Status)
2876 use ext_pnc_support_routines
2878 include 'wrf_status_codes.h'
2879 integer ,intent(in) :: DataHandle
2880 character*(*) ,intent(out) :: DateStr
2881 integer ,intent(out) :: Status
2882 type(wrf_data_handle) ,pointer :: DH
2884 call GetDH(DataHandle,DH,Status)
2885 if(Status /= WRF_NO_ERR) then
2886 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2887 call wrf_debug ( WARN , TRIM(msg))
2890 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2891 Status = WRF_WARN_FILE_NOT_OPENED
2892 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2893 call wrf_debug ( WARN , TRIM(msg))
2894 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2895 Status = WRF_WARN_DRYRUN_READ
2896 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2897 call wrf_debug ( WARN , TRIM(msg))
2898 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2899 Status = WRF_WARN_READ_WONLY_FILE
2900 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2901 call wrf_debug ( WARN , TRIM(msg))
2902 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE ) then
2903 if(DH%CurrentTime >= DH%NumberTimes) then
2904 write(msg,*) 'Warning ext_pnc_get_next_time: DH%CurrentTime >= DH%NumberTimes ',DH%CurrentTime,DH%NumberTimes
2905 call wrf_debug ( WARN , TRIM(msg))
2906 Status = WRF_WARN_TIME_EOF
2909 DH%CurrentTime = DH%CurrentTime +1
2910 DateStr = DH%Times(DH%CurrentTime)
2911 DH%CurrentVariable = 0
2914 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2915 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2916 call wrf_debug ( FATAL , msg)
2919 end subroutine ext_pnc_get_next_time
2921 subroutine ext_pnc_get_previous_time(DataHandle, DateStr, Status)
2923 use ext_pnc_support_routines
2925 include 'wrf_status_codes.h'
2926 integer ,intent(in) :: DataHandle
2927 character*(*) ,intent(out) :: DateStr
2928 integer ,intent(out) :: Status
2929 type(wrf_data_handle) ,pointer :: DH
2931 call GetDH(DataHandle,DH,Status)
2932 if(Status /= WRF_NO_ERR) then
2933 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2934 call wrf_debug ( WARN , TRIM(msg))
2937 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2938 Status = WRF_WARN_FILE_NOT_OPENED
2939 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2940 call wrf_debug ( WARN , TRIM(msg))
2941 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2942 Status = WRF_WARN_DRYRUN_READ
2943 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2944 call wrf_debug ( WARN , TRIM(msg))
2945 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2946 Status = WRF_WARN_READ_WONLY_FILE
2947 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2948 call wrf_debug ( WARN , TRIM(msg))
2949 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
2950 if(DH%CurrentTime.GT.0) then
2951 DH%CurrentTime = DH%CurrentTime -1
2953 DateStr = DH%Times(DH%CurrentTime)
2954 DH%CurrentVariable = 0
2957 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2958 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2959 call wrf_debug ( FATAL , msg)
2962 end subroutine ext_pnc_get_previous_time
2964 subroutine ext_pnc_get_next_var(DataHandle, VarName, Status)
2966 use ext_pnc_support_routines
2968 include 'wrf_status_codes.h'
2969 # include "pnetcdf.inc"
2970 integer ,intent(in) :: DataHandle
2971 character*(*) ,intent(out) :: VarName
2972 integer ,intent(out) :: Status
2973 type(wrf_data_handle) ,pointer :: DH
2975 character (80) :: Name
2977 call GetDH(DataHandle,DH,Status)
2978 if(Status /= WRF_NO_ERR) then
2979 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2980 call wrf_debug ( WARN , TRIM(msg))
2983 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2984 Status = WRF_WARN_FILE_NOT_OPENED
2985 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2986 call wrf_debug ( WARN , TRIM(msg))
2987 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2988 Status = WRF_WARN_DRYRUN_READ
2989 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2990 call wrf_debug ( WARN , TRIM(msg))
2991 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2992 Status = WRF_WARN_READ_WONLY_FILE
2993 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2994 call wrf_debug ( WARN , TRIM(msg))
2995 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
2997 DH%CurrentVariable = DH%CurrentVariable +1
2998 if(DH%CurrentVariable > DH%NumVars) then
2999 Status = WRF_WARN_VAR_EOF
3002 VarName = DH%VarNames(DH%CurrentVariable)
3005 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
3006 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
3007 call wrf_debug ( FATAL , msg)
3010 end subroutine ext_pnc_get_next_var
3012 subroutine ext_pnc_end_of_frame(DataHandle, Status)
3014 use ext_pnc_support_routines
3016 # include "pnetcdf.inc"
3017 include 'wrf_status_codes.h'
3018 integer ,intent(in) :: DataHandle
3019 integer ,intent(out) :: Status
3020 type(wrf_data_handle) ,pointer :: DH
3022 call GetDH(DataHandle,DH,Status)
3024 end subroutine ext_pnc_end_of_frame
3026 ! NOTE: For scalar variables NDim is set to zero and DomainStart and
3027 ! NOTE: DomainEnd are left unmodified.
3028 subroutine ext_pnc_get_var_info(DataHandle,Name,NDim,MemoryOrder,Stagger,DomainStart,DomainEnd,WrfType,Status)
3030 use ext_pnc_support_routines
3032 # include "pnetcdf.inc"
3033 include 'wrf_status_codes.h'
3034 integer ,intent(in) :: DataHandle
3035 character*(*) ,intent(in) :: Name
3036 integer ,intent(out) :: NDim
3037 character*(*) ,intent(out) :: MemoryOrder
3038 character*(*) :: Stagger ! Dummy for now
3039 integer ,dimension(*) ,intent(out) :: DomainStart, DomainEnd
3040 integer ,intent(out) :: WrfType
3041 integer ,intent(out) :: Status
3042 type(wrf_data_handle) ,pointer :: DH
3044 integer ,dimension(NVarDims) :: VDimIDs
3049 call GetDH(DataHandle,DH,Status)
3050 if(Status /= WRF_NO_ERR) then
3051 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
3052 call wrf_debug ( WARN , TRIM(msg))
3055 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
3056 Status = WRF_WARN_FILE_NOT_OPENED
3057 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
3058 call wrf_debug ( WARN , TRIM(msg))
3060 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
3061 Status = WRF_WARN_DRYRUN_READ
3062 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
3063 call wrf_debug ( WARN , TRIM(msg))
3065 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
3066 Status = WRF_WARN_READ_WONLY_FILE
3067 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
3068 call wrf_debug ( WARN , TRIM(msg))
3070 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
3071 stat = NFMPI_INQ_VARID(DH%NCID,Name,VarID)
3072 call netcdf_err(stat,Status)
3073 if(Status /= WRF_NO_ERR) then
3074 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
3075 call wrf_debug ( WARN , TRIM(msg))
3078 stat = NFMPI_INQ_VARTYPE(DH%NCID,VarID,XType)
3079 call netcdf_err(stat,Status)
3080 if(Status /= WRF_NO_ERR) then
3081 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
3082 call wrf_debug ( WARN , TRIM(msg))
3085 stat = NFMPI_GET_ATT_INT(DH%NCID,VarID,'FieldType',WrfType)
3086 call netcdf_err(stat,Status)
3087 if(Status /= WRF_NO_ERR) then
3088 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
3089 call wrf_debug ( WARN , TRIM(msg))
3094 Status = WRF_WARN_BAD_DATA_TYPE
3095 write(msg,*) 'Warning BYTE IS BAD DATA TYPE in ',__FILE__,', line', __LINE__
3096 call wrf_debug ( WARN , TRIM(msg))
3099 Status = WRF_WARN_BAD_DATA_TYPE
3100 write(msg,*) 'Warning CHAR IS BAD DATA TYPE in ',__FILE__,', line', __LINE__
3101 call wrf_debug ( WARN , TRIM(msg))
3104 Status = WRF_WARN_BAD_DATA_TYPE
3105 write(msg,*) 'Warning SHORT IS BAD DATA TYPE in ',__FILE__,', line', __LINE__
3106 call wrf_debug ( WARN , TRIM(msg))
3109 if(WrfType /= WRF_INTEGER .and. WrfType /= WRF_LOGICAL) then
3110 Status = WRF_WARN_BAD_DATA_TYPE
3111 write(msg,*) 'Warning BAD DATA TYPE in ',__FILE__,', line', __LINE__
3112 call wrf_debug ( WARN , TRIM(msg))
3116 if(WrfType /= WRF_REAL) then
3117 Status = WRF_WARN_BAD_DATA_TYPE
3118 write(msg,*) 'Warning BAD DATA TYPE in ',__FILE__,', line', __LINE__
3119 call wrf_debug ( WARN , TRIM(msg))
3123 if(WrfType /= WRF_DOUBLE) then
3124 Status = WRF_WARN_BAD_DATA_TYPE
3125 write(msg,*) 'Warning BAD DATA TYPE in ',__FILE__,', line', __LINE__
3126 call wrf_debug ( WARN , TRIM(msg))
3130 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
3131 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
3132 call wrf_debug ( WARN , TRIM(msg))
3136 stat = NFMPI_GET_ATT_TEXT(DH%NCID,VarID,'MemoryOrder',MemoryOrder)
3137 call netcdf_err(stat,Status)
3138 if(Status /= WRF_NO_ERR) then
3139 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
3140 call wrf_debug ( WARN , TRIM(msg))
3143 call GetDim(MemoryOrder,NDim,Status)
3144 if(Status /= WRF_NO_ERR) then
3145 write(msg,*) 'Warning BAD MEMORY ORDER ',TRIM(MemoryOrder),' in ',__FILE__,', line', __LINE__
3146 call wrf_debug ( WARN , TRIM(msg))
3149 stat = NFMPI_INQ_VARDIMID(DH%NCID,VarID,VDimIDs)
3150 call netcdf_err(stat,Status)
3151 if(Status /= WRF_NO_ERR) then
3152 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
3153 call wrf_debug ( WARN , TRIM(msg))
3158 stat = NFMPI_INQ_DIMLEN(DH%NCID,VDimIDs(j),DomainEnd(j))
3159 call netcdf_err(stat,Status)
3160 if(Status /= WRF_NO_ERR) then
3161 write(msg,*) 'NetCDF error in ',__FILE__,', line', __LINE__
3162 call wrf_debug ( WARN , TRIM(msg))
3167 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
3168 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
3169 call wrf_debug ( FATAL , msg)
3172 end subroutine ext_pnc_get_var_info
3174 subroutine ext_pnc_warning_str( Code, ReturnString, Status)
3176 use ext_pnc_support_routines
3178 # include "pnetcdf.inc"
3179 include 'wrf_status_codes.h'
3181 integer , intent(in) ::Code
3182 character *(*), intent(out) :: ReturnString
3183 integer, intent(out) ::Status
3187 ReturnString='No error'
3191 ReturnString= 'File not found (or file is incomplete)'
3195 ReturnString='Metadata not found'
3199 ReturnString= 'Timestamp not found'
3203 ReturnString= 'No more timestamps'
3207 ReturnString= 'Variable not found'
3211 ReturnString= 'No more variables for the current time'
3215 ReturnString= 'Too many open files'
3219 ReturnString= 'Data type mismatch'
3223 ReturnString= 'Attempt to write read-only file'
3227 ReturnString= 'Attempt to read write-only file'
3231 ReturnString= 'Attempt to access unopened file'
3235 ReturnString= 'Attempt to do 2 trainings for 1 variable'
3239 ReturnString= 'Attempt to read past EOF'
3243 ReturnString= 'Bad data handle'
3247 ReturnString= 'Write length not equal to training length'
3251 ReturnString= 'More dimensions requested than training'
3255 ReturnString= 'Attempt to read more data than exists'
3259 ReturnString= 'Input dimensions inconsistent'
3263 ReturnString= 'Input MemoryOrder not recognized'
3267 ReturnString= 'A dimension name with 2 different lengths'
3271 ReturnString= 'String longer than provided storage'
3275 ReturnString= 'Function not supportable'
3279 ReturnString= 'Package implements this routine as NOOP'
3283 !netcdf-specific warning messages
3285 ReturnString= 'Bad data type'
3289 ReturnString= 'File not committed'
3293 ReturnString= 'File is opened for reading'
3297 ReturnString= 'Attempt to write metadata after open commit'
3301 ReturnString= 'I/O not initialized'
3305 ReturnString= 'Too many variables requested'
3309 ReturnString= 'Attempt to close file during a dry run'
3313 ReturnString= 'Date string not 19 characters in length'
3317 ReturnString= 'Attempt to read zero length words'
3321 ReturnString= 'Data type not found'
3325 ReturnString= 'Badly formatted date string'
3329 ReturnString= 'Attempt at read during a dry run'
3333 ReturnString= 'Attempt to get zero words'
3337 ReturnString= 'Attempt to put zero length words'
3341 ReturnString= 'NetCDF error'
3345 ReturnString= 'Requested length <= 1'
3349 ReturnString= 'More data available than requested'
3353 ReturnString= 'New date less than previous date'
3358 ReturnString= 'This warning code is not supported or handled directly by WRF and NetCDF. &
3359 & Might be an erroneous number, or specific to an i/o package other than NetCDF; you may need &
3360 & to be calling a package-specific routine to return a message for this warning code.'
3365 end subroutine ext_pnc_warning_str
3368 !returns message string for all WRF and netCDF warning/error status codes
3369 !Other i/o packages must provide their own routines to return their own status messages
3370 subroutine ext_pnc_error_str( Code, ReturnString, Status)
3372 use ext_pnc_support_routines
3374 # include "pnetcdf.inc"
3375 include 'wrf_status_codes.h'
3377 integer , intent(in) ::Code
3378 character *(*), intent(out) :: ReturnString
3379 integer, intent(out) ::Status
3383 ReturnString= 'Allocation Error'
3387 ReturnString= 'Deallocation Error'
3391 ReturnString= 'Bad File Status'
3395 ReturnString= 'Variable on disk is not 3D'
3399 ReturnString= 'Metadata on disk is not 1D'
3403 ReturnString= 'Time dimension too small'
3407 ReturnString= 'This error code is not supported or handled directly by WRF and NetCDF. &
3408 & Might be an erroneous number, or specific to an i/o package other than NetCDF; you may need &
3409 & to be calling a package-specific routine to return a message for this error code.'
3414 end subroutine ext_pnc_error_str