550
553
554 class(DisType) :: this
555 integer(I4B), dimension(:), intent(in) :: icelltype
556
557 integer(I4B) :: iunit, ntxt, ncpl, version
558 integer(I4B), parameter :: lentxt = 100
559 character(len=50) :: txthdr
560 character(len=lentxt) :: txt
561 character(len=LINELENGTH) :: fname
562 character(len=LENBIGLINE) :: crs
563 logical(LGP) :: found_crs
564 character(len=*), parameter :: fmtgrdsave = &
565 "(4X,'BINARY GRID INFORMATION WILL BE WRITTEN TO:', &
566 &/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
567
568
569 version = 1
570 ntxt = 16
571 ncpl = this%nrow * this%ncol
572
573 call mem_set_value(crs, 'CRS', this%input_mempath, found_crs)
574
575
576 if (found_crs) then
577 ntxt = ntxt + 1
578 version = 2
579 end if
580
581
582 fname = trim(this%output_fname)
583 iunit = getunit()
584 write (this%iout, fmtgrdsave) iunit, trim(adjustl(fname))
585 call openfile(iunit, this%iout, trim(adjustl(fname)), 'DATA(BINARY)', &
587
588
589 write (txthdr, '(a)') 'GRID DIS'
590 txthdr(50:50) = new_line('a')
591 write (iunit) txthdr
592 write (txthdr, '(a, i0)') 'VERSION ', version
593 txthdr(50:50) = new_line('a')
594 write (iunit) txthdr
595 write (txthdr, '(a, i0)') 'NTXT ', ntxt
596 txthdr(50:50) = new_line('a')
597 write (iunit) txthdr
598 write (txthdr, '(a, i0)') 'LENTXT ', lentxt
599 txthdr(50:50) = new_line('a')
600 write (iunit) txthdr
601
602
603 write (txt, '(3a, i0)') 'NCELLS ', 'INTEGER ', 'NDIM 0 # ', this%nodesuser
604 txt(lentxt:lentxt) = new_line('a')
605 write (iunit) txt
606 write (txt, '(3a, i0)') 'NLAY ', 'INTEGER ', 'NDIM 0 # ', this%nlay
607 txt(lentxt:lentxt) = new_line('a')
608 write (iunit) txt
609 write (txt, '(3a, i0)') 'NROW ', 'INTEGER ', 'NDIM 0 # ', this%nrow
610 txt(lentxt:lentxt) = new_line('a')
611 write (iunit) txt
612 write (txt, '(3a, i0)') 'NCOL ', 'INTEGER ', 'NDIM 0 # ', this%ncol
613 txt(lentxt:lentxt) = new_line('a')
614 write (iunit) txt
615 write (txt, '(3a, i0)') 'NJA ', 'INTEGER ', 'NDIM 0 # ', this%nja
616 txt(lentxt:lentxt) = new_line('a')
617 write (iunit) txt
618 write (txt, '(3a, 1pg24.15)') 'XORIGIN ', 'DOUBLE ', 'NDIM 0 # ', this%xorigin
619 txt(lentxt:lentxt) = new_line('a')
620 write (iunit) txt
621 write (txt, '(3a, 1pg24.15)') 'YORIGIN ', 'DOUBLE ', 'NDIM 0 # ', this%yorigin
622 txt(lentxt:lentxt) = new_line('a')
623 write (iunit) txt
624 write (txt, '(3a, 1pg24.15)') 'ANGROT ', 'DOUBLE ', 'NDIM 0 # ', this%angrot
625 txt(lentxt:lentxt) = new_line('a')
626 write (iunit) txt
627 write (txt, '(3a, i0)') 'DELR ', 'DOUBLE ', 'NDIM 1 ', this%ncol
628 txt(lentxt:lentxt) = new_line('a')
629 write (iunit) txt
630 write (txt, '(3a, i0)') 'DELC ', 'DOUBLE ', 'NDIM 1 ', this%nrow
631 txt(lentxt:lentxt) = new_line('a')
632 write (iunit) txt
633 write (txt, '(3a, i0)') 'TOP ', 'DOUBLE ', 'NDIM 1 ', ncpl
634 txt(lentxt:lentxt) = new_line('a')
635 write (iunit) txt
636 write (txt, '(3a, i0)') 'BOTM ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
637 txt(lentxt:lentxt) = new_line('a')
638 write (iunit) txt
639 write (txt, '(3a, i0)') 'IA ', 'INTEGER ', 'NDIM 1 ', this%nodesuser + 1
640 txt(lentxt:lentxt) = new_line('a')
641 write (iunit) txt
642 write (txt, '(3a, i0)') 'JA ', 'INTEGER ', 'NDIM 1 ', size(this%con%jausr)
643 txt(lentxt:lentxt) = new_line('a')
644 write (iunit) txt
645 write (txt, '(3a, i0)') 'IDOMAIN ', 'INTEGER ', 'NDIM 1 ', this%nodesuser
646 txt(lentxt:lentxt) = new_line('a')
647 write (iunit) txt
648 write (txt, '(3a, i0)') 'ICELLTYPE ', 'INTEGER ', 'NDIM 1 ', this%nodesuser
649 txt(lentxt:lentxt) = new_line('a')
650 write (iunit) txt
651
652
653 if (version == 2) then
654 if (found_crs) then
655 write (txt, '(3a, i0)') 'CRS ', 'CHARACTER ', 'NDIM 1 ', &
656 len_trim(crs)
657 txt(lentxt:lentxt) = new_line('a')
658 write (iunit) txt
659 end if
660 end if
661
662
663 write (iunit) this%nodesuser
664 write (iunit) this%nlay
665 write (iunit) this%nrow
666 write (iunit) this%ncol
667 write (iunit) this%nja
668 write (iunit) this%xorigin
669 write (iunit) this%yorigin
670 write (iunit) this%angrot
671 write (iunit) this%delr
672 write (iunit) this%delc
673 write (iunit) this%top2d
674 write (iunit) this%bot3d
675 write (iunit) this%con%iausr
676 write (iunit) this%con%jausr
677 write (iunit) this%idomain
678 write (iunit) icelltype
679
680
681 if (version == 2) then
682 if (found_crs) write (iunit) trim(crs)
683 end if
684
685
686 close (iunit)
687
integer(i4b), parameter lenbigline
maximum length of a big line