672
675
676 class(Disv2dType) :: this
677 integer(I4B), dimension(:), intent(in) :: icelltype
678
679 integer(I4B) :: iunit, i, ntxt, version
680 integer(I4B), parameter :: lentxt = 100
681 character(len=50) :: txthdr
682 character(len=lentxt) :: txt
683 character(len=LINELENGTH) :: fname
684 character(len=LENBIGLINE) :: crs
685 logical(LGP) :: found_crs
686
687 character(len=*), parameter :: fmtgrdsave = &
688 "(4X,'BINARY GRID INFORMATION WILL BE WRITTEN TO:', &
689 &/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
690
691
692 version = 1
693 ntxt = 18
694
695 call mem_set_value(crs, 'CRS', this%input_mempath, found_crs)
696
697
698 if (found_crs) then
699 ntxt = ntxt + 1
700 version = 2
701 end if
702
703
704 fname = trim(this%output_fname)
705 iunit = getunit()
706 write (this%iout, fmtgrdsave) iunit, trim(adjustl(fname))
707 call openfile(iunit, this%iout, trim(adjustl(fname)), 'DATA(BINARY)', &
709
710
711 write (txthdr, '(a)') 'GRID DISV2D'
712 txthdr(50:50) = new_line('a')
713 write (iunit) txthdr
714 write (txthdr, '(a, i0)') 'VERSION ', version
715 txthdr(50:50) = new_line('a')
716 write (iunit) txthdr
717 write (txthdr, '(a, i0)') 'NTXT ', ntxt
718 txthdr(50:50) = new_line('a')
719 write (iunit) txthdr
720 write (txthdr, '(a, i0)') 'LENTXT ', lentxt
721 txthdr(50:50) = new_line('a')
722 write (iunit) txthdr
723
724
725 write (txt, '(3a, i0)') 'NCELLS ', 'INTEGER ', 'NDIM 0 # ', this%nodesuser
726 txt(lentxt:lentxt) = new_line('a')
727 write (iunit) txt
728 write (txt, '(3a, i0)') 'NODES ', 'INTEGER ', 'NDIM 0 # ', this%nodes
729 txt(lentxt:lentxt) = new_line('a')
730 write (iunit) txt
731 write (txt, '(3a, i0)') 'NVERT ', 'INTEGER ', 'NDIM 0 # ', this%nvert
732 txt(lentxt:lentxt) = new_line('a')
733 write (iunit) txt
734 write (txt, '(3a, i0)') 'NJAVERT ', 'INTEGER ', 'NDIM 0 # ', size(this%javert)
735 txt(lentxt:lentxt) = new_line('a')
736 write (iunit) txt
737 write (txt, '(3a, i0)') 'NJA ', 'INTEGER ', 'NDIM 0 # ', this%con%nja
738 txt(lentxt:lentxt) = new_line('a')
739 write (iunit) txt
740 write (txt, '(3a, 1pg25.15e3)') &
741 'XORIGIN ', 'DOUBLE ', 'NDIM 0 # ', this%xorigin
742 txt(lentxt:lentxt) = new_line('a')
743 write (iunit) txt
744 write (txt, '(3a, 1pg25.15e3)') &
745 'YORIGIN ', 'DOUBLE ', 'NDIM 0 # ', this%yorigin
746 txt(lentxt:lentxt) = new_line('a')
747 write (iunit) txt
748 write (txt, '(3a, 1pg25.15e3)') 'ANGROT ', 'DOUBLE ', 'NDIM 0 # ', this%angrot
749 txt(lentxt:lentxt) = new_line('a')
750 write (iunit) txt
751 write (txt, '(3a, i0)') 'BOTM ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
752 txt(lentxt:lentxt) = new_line('a')
753 write (iunit) txt
754 write (txt, '(3a, i0)') 'VERTICES ', 'DOUBLE ', 'NDIM 2 2 ', this%nvert
755 txt(lentxt:lentxt) = new_line('a')
756 write (iunit) txt
757 write (txt, '(3a, i0)') 'CELLX ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
758 txt(lentxt:lentxt) = new_line('a')
759 write (iunit) txt
760 write (txt, '(3a, i0)') 'CELLY ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
761 txt(lentxt:lentxt) = new_line('a')
762 write (iunit) txt
763 write (txt, '(3a, i0)') 'IAVERT ', 'INTEGER ', 'NDIM 1 ', this%nodesuser + 1
764 txt(lentxt:lentxt) = new_line('a')
765 write (iunit) txt
766 write (txt, '(3a, i0)') 'JAVERT ', 'INTEGER ', 'NDIM 1 ', size(this%javert)
767 txt(lentxt:lentxt) = new_line('a')
768 write (iunit) txt
769 write (txt, '(3a, i0)') 'IA ', 'INTEGER ', 'NDIM 1 ', this%nodesuser + 1
770 txt(lentxt:lentxt) = new_line('a')
771 write (iunit) txt
772 write (txt, '(3a, i0)') 'JA ', 'INTEGER ', 'NDIM 1 ', size(this%con%jausr)
773 txt(lentxt:lentxt) = new_line('a')
774 write (iunit) txt
775 write (txt, '(3a, i0)') 'IDOMAIN ', 'INTEGER ', 'NDIM 1 ', this%nodesuser
776 txt(lentxt:lentxt) = new_line('a')
777 write (iunit) txt
778 write (txt, '(3a, i0)') 'ICELLTYPE ', 'INTEGER ', 'NDIM 1 ', this%nodesuser
779 txt(lentxt:lentxt) = new_line('a')
780 write (iunit) txt
781
782
783 if (version == 2) then
784 if (found_crs) then
785 write (txt, '(3a, i0)') 'CRS ', 'CHARACTER ', 'NDIM 1 ', &
786 len_trim(crs)
787 txt(lentxt:lentxt) = new_line('a')
788 write (iunit) txt
789 end if
790 end if
791
792
793 write (iunit) this%nodesuser
794 write (iunit) this%nodes
795 write (iunit) this%nvert
796 write (iunit) size(this%javert)
797 write (iunit) this%nja
798 write (iunit) this%xorigin
799 write (iunit) this%yorigin
800 write (iunit) this%angrot
801 write (iunit) this%bottom
802 write (iunit) this%vertices
803 write (iunit) (this%cellxy(1, i), i=1, this%nodesuser)
804 write (iunit) (this%cellxy(2, i), i=1, this%nodesuser)
805 write (iunit) this%iavert
806 write (iunit) this%javert
807 write (iunit) this%con%iausr
808 write (iunit) this%con%jausr
809 write (iunit) this%idomain
810 write (iunit) icelltype
811
812
813 if (version == 2) then
814 if (found_crs) write (iunit) trim(crs)
815 end if
816
817
818 close (iunit)
819
integer(i4b), parameter lenbigline
maximum length of a big line