849
853
854 class(Disv1dType) :: this
855 integer(I4B), dimension(:), intent(in) :: icelltype
856
857 integer(I4B) :: i, iunit, ntxt, version
858 integer(I4B), parameter :: lentxt = 100
859 character(len=50) :: txthdr
860 character(len=lentxt) :: txt
861 character(len=LINELENGTH) :: fname
862 character(len=LENBIGLINE) :: crs
863 logical(LGP) :: found_crs
864 character(len=*), parameter :: fmtgrdsave = &
865 "(4X,'BINARY GRID INFORMATION WILL BE WRITTEN TO:', &
866 &/,6X,'UNIT NUMBER: ', I0,/,6X, 'FILE NAME: ', A)"
867
868
869 version = 1
870 ntxt = 10
871 if (this%nvert > 0) ntxt = ntxt + 5
872
873 call mem_set_value(crs, 'CRS', this%input_mempath, found_crs)
874
875
876 if (found_crs) then
877 ntxt = ntxt + 1
878 version = 2
879 end if
880
881
882 fname = trim(this%output_fname)
884 write (this%iout, fmtgrdsave) iunit, trim(adjustl(fname))
885 call openfile(iunit, this%iout, trim(adjustl(fname)),
'DATA(BINARY)', &
887
888
889 write (txthdr, '(a)') 'GRID DISV1D'
890 txthdr(50:50) = new_line('a')
891 write (iunit) txthdr
892 write (txthdr, '(a, i0)') 'VERSION ', version
893 txthdr(50:50) = new_line('a')
894 write (iunit) txthdr
895 write (txthdr, '(a, i0)') 'NTXT ', ntxt
896 txthdr(50:50) = new_line('a')
897 write (iunit) txthdr
898 write (txthdr, '(a, i0)') 'LENTXT ', lentxt
899 txthdr(50:50) = new_line('a')
900 write (iunit) txthdr
901
902
903 write (txt, '(3a, i0)') 'NCELLS ', 'INTEGER ', 'NDIM 0 # ', this%nodesuser
904 txt(lentxt:lentxt) = new_line('a')
905 write (iunit) txt
906 write (txt, '(3a, i0)') 'NJA ', 'INTEGER ', 'NDIM 0 # ', this%con%nja
907 txt(lentxt:lentxt) = new_line('a')
908 write (iunit) txt
909 write (txt, '(3a, 1pg24.15)') 'XORIGIN ', 'DOUBLE ', 'NDIM 0 # ', this%xorigin
910 txt(lentxt:lentxt) = new_line('a')
911 write (iunit) txt
912 write (txt, '(3a, 1pg24.15)') 'YORIGIN ', 'DOUBLE ', 'NDIM 0 # ', this%yorigin
913 txt(lentxt:lentxt) = new_line('a')
914 write (iunit) txt
915 write (txt, '(3a, 1pg24.15)') 'ANGROT ', 'DOUBLE ', 'NDIM 0 # ', this%angrot
916 txt(lentxt:lentxt) = new_line('a')
917 write (iunit) txt
918 write (txt, '(3a, i0)') 'BOTM ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
919 txt(lentxt:lentxt) = new_line('a')
920 write (iunit) txt
921 write (txt, '(3a, i0)') 'IA ', 'INTEGER ', 'NDIM 1 ', this%nodesuser + 1
922 txt(lentxt:lentxt) = new_line('a')
923 write (iunit) txt
924 write (txt, '(3a, i0)') 'JA ', 'INTEGER ', 'NDIM 1 ', this%con%nja
925 txt(lentxt:lentxt) = new_line('a')
926 write (iunit) txt
927 write (txt, '(3a, i0)') 'ICELLTYPE ', 'INTEGER ', 'NDIM 1 ', this%nodesuser
928 txt(lentxt:lentxt) = new_line('a')
929 write (iunit) txt
930 write (txt, '(3a, i0)') 'IDOMAIN ', 'INTEGER ', 'NDIM 1 ', this%nodesuser
931 txt(lentxt:lentxt) = new_line('a')
932 write (iunit) txt
933
934
935 if (this%nvert > 0) then
936 write (txt, '(3a, i0)') 'VERTICES ', 'DOUBLE ', 'NDIM 2 2 ', this%nvert
937 txt(lentxt:lentxt) = new_line('a')
938 write (iunit) txt
939 write (txt, '(3a, i0)') 'CELLX ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
940 txt(lentxt:lentxt) = new_line('a')
941 write (iunit) txt
942 write (txt, '(3a, i0)') 'CELLY ', 'DOUBLE ', 'NDIM 1 ', this%nodesuser
943 txt(lentxt:lentxt) = new_line('a')
944 write (iunit) txt
945 write (txt, '(3a, i0)') 'IAVERT ', 'INTEGER ', 'NDIM 1 ', this%nodesuser + 1
946 txt(lentxt:lentxt) = new_line('a')
947 write (iunit) txt
948 write (txt, '(3a, i0)') 'JAVERT ', 'INTEGER ', 'NDIM 1 ', size(this%javert)
949 txt(lentxt:lentxt) = new_line('a')
950 write (iunit) txt
951 end if
952
953
954 if (version == 2) then
955 if (found_crs) then
956 write (txt, '(3a, i0)') 'CRS ', 'CHARACTER ', 'NDIM 1 ', &
957 len_trim(crs)
958 txt(lentxt:lentxt) = new_line('a')
959 write (iunit) txt
960 end if
961 end if
962
963
964 write (iunit) this%nodesuser
965 write (iunit) this%nja
966 write (iunit) this%xorigin
967 write (iunit) this%yorigin
968 write (iunit) this%angrot
969 write (iunit) this%bottom
970 write (iunit) this%con%iausr
971 write (iunit) this%con%jausr
972 write (iunit) icelltype
973 write (iunit) this%idomain
974
975
976 if (this%nvert > 0) then
977 write (iunit) this%vertices
978 write (iunit) (this%cellxy(1, i), i=1, this%nodesuser)
979 write (iunit) (this%cellxy(2, i), i=1, this%nodesuser)
980 write (iunit) this%iavert
981 write (iunit) this%javert
982 end if
983
984
985 if (version == 2) then
986 if (found_crs) write (iunit) trim(crs)
987 end if
988
989
990 close (iunit)
integer(i4b), parameter lenbigline
maximum length of a big line