43 caller_linenum, point_count, x, y) bind(c,name='pj_init_and_transform')
45 character(c_char) :: from_projection(*)
46 character(c_char) :: to_projection(*)
47 character(c_char) :: caller_name(*)
48 integer(c_int),
value :: caller_linenum
49 integer(c_long),
value :: point_count
50 real(c_double) :: x(*)
51 real(c_double) :: y(*)
58 integer (c_int) :: inx
59 integer (c_int) :: iny
60 integer (c_int) :: inumgridcells
61 integer (c_int) :: idatatype
62 character (len=:),
allocatable :: sproj4_string
63 character (len=:),
allocatable :: sfilename
64 real (c_double) :: rgridcellsize
65 integer (c_int) :: ilengthunits= -99999
66 real (c_double) :: rx0, rx1
67 real (c_double) :: ry0, ry1
69 integer (c_int),
dimension(:,:),
allocatable :: idata
70 real (c_float),
dimension(:,:),
allocatable :: rdata
71 real (c_float),
dimension(:,:),
allocatable :: fdata
72 real (c_double),
dimension(:,:),
allocatable :: dpdata
73 real (c_double),
dimension(:,:),
allocatable :: rx
74 real (c_double),
dimension(:,:),
allocatable :: ry
75 integer (c_int),
dimension(:,:),
allocatable :: imask
85 real (c_double) :: rxll, ryll
86 real (c_double) :: rxul, ryul
87 real (c_double) :: rxlr, rylr
88 real (c_double) :: rxur, ryur
89 character (len=256) :: sproj4_string
94 character(len=45) :: cerrormessagetext
95 integer :: ierrornumber
144 error_message_t(
"geocentric transformation missing z or ellps ", -45), &
147 error_message_t(
"point not within available datum shift grids ", -48), &
170 integer (c_int),
parameter,
private ::
column = 1
171 integer (c_int),
parameter,
private ::
row = 2
183 character (len=*),
intent(in) :: sdirname
187 call logs%write(
"ASCII grids will be written to subdirectory " &
189 ilinesbefore=1, lecho=
true )
213 integer (c_int),
intent(in) :: inx, iny
214 real (c_double),
intent(in) :: rx0, ry0
215 real (c_double),
intent(in) :: rx1, ry1
216 integer (c_int),
intent(in) :: idatatype
220 integer (c_int) :: istat
222 allocate ( pgrd, stat=istat )
223 call assert ( istat == 0, &
224 "Could not allocate pointer to T_GRID object", __file__,__line__ )
226 if (inx <= 0 .or. iny <= 0)
then
227 call logs%write(
"Illegal grid dimensions: ")
235 "INTERNAL PROGRAMMING ERROR? - Illegal grid dimensions specified", __file__,__line__)
238 select case (idatatype)
241 allocate ( pgrd%iData( inx, iny ), stat=istat )
242 call assert (istat == 0, &
243 "Could not allocate integer data", &
248 allocate ( pgrd%rData( inx, iny ), stat=istat )
249 call assert (istat == 0, &
250 "Could not allocate real data", &
255 allocate ( pgrd%dpData( inx, iny ), stat=istat )
256 call assert (istat == 0, &
257 "Could not allocate double-precision data", &
259 pgrd%dpData = 0.0_c_double
262 call assert (
false,
'Internal error -- illegal grid data type' )
265 pgrd%iDataType = idatatype
272 pgrd%rGridCellSize = (pgrd%rX1 - pgrd%rX0) / real(pgrd%iNX, c_double)
273 pgrd%iNumGridCells = inx * iny
275 allocate(pgrd%iMask(inx, iny))
284 integer (c_int),
intent(in) :: inx, iny
285 real (c_double),
intent(in) :: rx0, ry0
286 real (c_double),
intent(in) :: rgridcellsize
287 integer (c_int),
intent(in) :: idatatype
292 integer (c_int) :: istat
294 allocate ( pgrd, stat=istat )
295 call assert ( istat == 0, &
296 "Could not allocate pointer to T_GRID object", __file__,__line__ )
297 call assert ( inx > 0 .and. iny > 0, &
298 "Illegal grid dimensions specified: NX="//
ascharacter(inx) &
301 select case (idatatype)
304 allocate ( pgrd%iData( inx, iny ), stat=istat )
305 call assert (istat == 0, &
306 "Could not allocate integer data", &
308 pgrd%iData = pgrd%iNoDataValue
311 allocate ( pgrd%rData( inx, iny ), stat=istat )
312 call assert (istat == 0, &
313 "Could not allocate real data", &
315 pgrd%rData = pgrd%rNoDataValue
318 allocate ( pgrd%dpData( inx, iny ), stat=istat )
319 call assert (istat == 0, &
320 "Could not allocate double-precision data", &
322 pgrd%dpData = pgrd%dpNoDataValue
325 call assert (
false,
'Internal error -- illegal grid data type' )
328 pgrd%iDataType = idatatype
332 pgrd%rX1 = rx0 + real(inx, c_double) * rgridcellsize
334 pgrd%rY1 = ry0 + real(iny, c_double) * rgridcellsize
335 pgrd%rGridCellSize = rgridcellsize
336 pgrd%iNumGridCells = inx * iny
338 allocate(pgrd%iMask(inx, iny))
370 integer (c_int) :: istat
372 if(
associated(pgrd) )
then
375 deallocate ( pgrd%iData, stat=istat )
376 call assert ( istat == 0,
"Failed to deallocate integer grid" )
378 deallocate ( pgrd%rData, stat=istat )
379 call assert ( istat == 0,
"Failed to deallocate real grid" )
381 deallocate ( pgrd%dpData, stat=istat )
382 call assert ( istat == 0,
"Failed to deallocate double-precision grid" )
395 call assert (
false,
"Internal error -- unknown grid type", &
399 if(
allocated(pgrd%rX) )
then
400 deallocate( pgrd%rX, stat=istat)
401 call assert ( istat == 0,
"Failed to deallocate X-coordinate data structure associated with grid", &
405 if(
allocated(pgrd%rY) )
then
406 deallocate( pgrd%rY, stat=istat)
407 call assert ( istat == 0,
"Failed to deallocate Y-coordinate data structure associated with grid", &
446function grid_read ( sFilename, sFileType, iDataType )
result ( pGrd )
449 character (len=*),
intent(in) :: sfilename
450 character (len=*),
intent(in) :: sfiletype
451 integer (c_int),
intent(in) :: idatatype
457 if ( trim(sfiletype) ==
"ARC_GRID" )
then
459 else if ( trim(sfiletype) ==
"SURFER" )
then
462 call assert(
false,
"Illegal grid file type requested" )
465 pgrd%sFilename = trim(sfilename)
474 character (len=*),
intent(in) :: sfilename
475 character (len=*),
intent(in) :: sfiletype
478 if ( trim(sfiletype) ==
"ARC_GRID" )
then
480 else if ( trim(sfiletype) ==
"SURFER" )
then
483 call assert(
false,
"Illegal grid file type requested" )
486 pgrd%sFilename = trim(sfilename)
518 character (len=*),
intent(in) :: sfilename
519 integer (c_int),
intent(in) :: idatatype
523 character (len=256) :: sinputrecord
524 character (len=256) :: sdirective
525 character (len=256) :: sargument
526 character (len=256) :: snodatavalue
527 integer (c_int) :: istat
528 integer (c_int) :: inx,iny
529 integer (c_int) :: ihdrrecs
530 integer (c_int) :: icol,irow
531 real (c_double) :: rx0,rx1
532 real (c_double) :: ry0,ry1
533 real (c_double) :: rcellsize
534 logical (c_bool) :: lxllcenter, lyllcenter
535 logical :: lfileexists
539 inquire(file=trim(sfilename), exist=lfileexists)
540 call assert( lfileexists,
"The Arc ASCII grid file "//
dquote(sfilename)// &
541 " could not be found.",__file__,__line__)
543 inquire(unit=
lu_grid, opened=lisopen )
544 if (lisopen )
close( unit=
lu_grid )
546 open ( newunit=
lu_grid, iostat=istat, file=trim(sfilename) )
547 call assert( istat == 0, &
548 "Could not open input file " // trim(sfilename) )
556 read ( unit=
lu_grid, fmt=
"(a256)", iostat=istat ) sinputrecord
557 call assert ( istat == 0, &
558 "Could not read input record - file:"//trim(sfilename) )
559 call chomp ( sinputrecord, sdirective )
561 call chomp ( sinputrecord, sargument )
562 if ( sdirective ==
"NCOLS" )
then
563 read ( unit=sargument, fmt=*, iostat=istat ) inx
564 call assert ( istat == 0,
"Could not read NCOLS" )
565 ihdrrecs = ihdrrecs + 1
566 else if ( sdirective ==
"NROWS" )
then
567 read ( unit=sargument, fmt=*, iostat=istat ) iny
568 call assert ( istat == 0,
"Could not read NROWS" )
569 ihdrrecs = ihdrrecs + 1
570 else if ( sdirective ==
"XLLCENTER" )
then
571 read ( unit=sargument, fmt=*, iostat=istat ) rx0
572 call assert ( istat == 0,
"Could not read XLLCENTER" )
574 ihdrrecs = ihdrrecs + 1
575 else if ( sdirective ==
"YLLCENTER" )
then
576 read ( unit=sargument, fmt=*, iostat=istat ) ry0
577 call assert ( istat == 0,
"Could not read YLLCENTER" )
579 ihdrrecs = ihdrrecs + 1
580 else if ( sdirective ==
"XLLCORNER" )
then
581 read ( unit=sargument, fmt=*, iostat=istat ) rx0
582 call assert ( istat == 0,
"Could not read XLLCORNER" )
583 ihdrrecs = ihdrrecs + 1
584 else if ( sdirective ==
"YLLCORNER" )
then
585 read ( unit=sargument, fmt=*, iostat=istat ) ry0
586 call assert ( istat == 0,
"Could not read YLLCORNER" )
587 ihdrrecs = ihdrrecs + 1
588 else if ( sdirective ==
"CELLSIZE" )
then
589 read ( unit=sargument, fmt=*, iostat=istat ) rcellsize
590 call assert ( istat == 0,
"Could not read CELLSIZE" )
591 ihdrrecs = ihdrrecs + 1
592 else if ( sdirective ==
"NODATA_VALUE" )
then
593 snodatavalue = trim(sargument)
594 ihdrrecs = ihdrrecs + 1
597 if ( lxllcenter ) rx0 = rx0 - 0.5_c_double*rcellsize
598 if ( lyllcenter ) ry0 = ry0 - 0.5_c_double*rcellsize
599 rx1 = rx0 + real(inx, c_double) * rcellsize
600 ry1 = ry0 + real(iny, c_double) * rcellsize
602 pgrd =>
grid_create( inx, iny, rx0, ry0, rx1, ry1, idatatype )
604 pgrd%rGridCellSize = rcellsize
606 rewind( unit=
lu_grid, iostat=istat )
607 call assert ( istat == 0,
"Failed to rewind grid file" )
609 read ( unit=
lu_grid, fmt=
"(a256)", iostat=istat ) sinputrecord
610 call assert ( istat == 0, &
611 "Could not read input record - file: "//trim(sfilename))
614 select case ( idatatype )
619 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%iData(:,irow)
620 call assert ( istat == 0, &
621 "Failed to read integer grid data - file: " &
622 //trim(sfilename)//
" row num: "//trim(
ascharacter(irow)), &
625 if(len_trim(snodatavalue) > 0)
then
626 read(unit=snodatavalue, fmt=*, iostat=istat) pgrd%iNoDataValue
627 call assert ( istat == 0, &
628 "Failed to read NODATA value in grid data - file: " &
629 //
dquote(sfilename), __file__,__line__ )
635 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%rData(:,irow)
636 call assert ( istat == 0, &
637 "Failed to read real grid data - file: " &
638 //trim(sfilename)//
" row num: "//trim(
ascharacter(irow)), &
641 if(len_trim(snodatavalue) > 0)
then
642 read(unit=snodatavalue, fmt=*, iostat=istat) pgrd%rNoDataValue
643 call assert ( istat == 0, &
644 "Failed to read NODATA value in grid data - file: " &
645 //trim(sfilename), __file__,__line__ )
651 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%dpData(:,irow)
652 call assert ( istat == 0, &
653 "Failed to read double-precision grid data - file: " &
654 //trim(sfilename)//
" row num: "//trim(
ascharacter(irow)), &
657 if(len_trim(snodatavalue) > 0)
then
658 read(unit=snodatavalue, fmt=*, iostat=istat) pgrd%dpNoDataValue
659 call assert ( istat == 0, &
660 "Failed to read NODATA value in grid data - file: " &
661 //trim(sfilename), __file__,__line__ )
667 "Internal error -- illegal ARC GRID data type", &
677 open ( unit=
lu_grid, iostat=istat )
678 call assert ( istat == 0,
"Failed to close grid file" )
687 character (len=*),
intent(in) :: sFileName
688 type (GENERAL_GRID_T),
pointer :: pGrd
691 character (len=256) :: sInputRecord
692 character (len=256) :: sDirective
693 character (len=256) :: sArgument
694 character (len=256) :: sNoDataValue
695 integer (c_int) :: iStat
696 integer (c_int) :: iNX,iNY
697 integer (c_int) :: iHdrRecs
698 integer (c_int) :: iCol,iRow
699 real (c_double) :: rX0
700 real (c_double) :: rY0
701 real (c_double) :: rCellSize
702 logical (c_bool) :: lXLLCenter, lYLLCenter
703 logical :: lFileExists
708 inquire(file=trim(sfilename), exist=lfileexists, opened=lisopen )
709 call assert( lfileexists,
"The Arc ASCII grid file "//
dquote(sfilename)// &
710 " could not be found.",__file__,__line__)
712 inquire(unit=
lu_grid, opened=lisopen )
713 if (lisopen )
close( unit=
lu_grid )
715 open ( newunit=
lu_grid, iostat=istat, file=trim(sfilename) )
716 call assert( istat == 0, &
717 "Could not open input file " // trim(sfilename) )
725 read ( unit=
lu_grid, fmt=
"(a256)", iostat=istat ) sinputrecord
726 call assert ( istat == 0, &
727 "Could not read input record - file:"//trim(sfilename) )
728 call chomp ( sinputrecord, sdirective )
730 call chomp ( sinputrecord, sargument )
731 if ( sdirective ==
"NCOLS" )
then
732 read ( unit=sargument, fmt=*, iostat=istat ) inx
733 call assert ( istat == 0,
"Could not read NCOLS" )
734 ihdrrecs = ihdrrecs + 1
735 else if ( sdirective ==
"NROWS" )
then
736 read ( unit=sargument, fmt=*, iostat=istat ) iny
737 call assert ( istat == 0,
"Could not read NROWS" )
738 ihdrrecs = ihdrrecs + 1
739 else if ( sdirective ==
"XLLCENTER" )
then
740 read ( unit=sargument, fmt=*, iostat=istat ) rx0
741 call assert ( istat == 0,
"Could not read XLLCENTER" )
743 ihdrrecs = ihdrrecs + 1
744 else if ( sdirective ==
"YLLCENTER" )
then
745 read ( unit=sargument, fmt=*, iostat=istat ) ry0
746 call assert ( istat == 0,
"Could not read YLLCENTER" )
748 ihdrrecs = ihdrrecs + 1
749 else if ( sdirective ==
"XLLCORNER" )
then
750 read ( unit=sargument, fmt=*, iostat=istat ) rx0
751 call assert ( istat == 0,
"Could not read XLLCORNER" )
752 ihdrrecs = ihdrrecs + 1
753 else if ( sdirective ==
"YLLCORNER" )
then
754 read ( unit=sargument, fmt=*, iostat=istat ) ry0
755 call assert ( istat == 0,
"Could not read YLLCORNER" )
756 ihdrrecs = ihdrrecs + 1
757 else if ( sdirective ==
"CELLSIZE" )
then
758 read ( unit=sargument, fmt=*, iostat=istat ) rcellsize
759 call assert ( istat == 0,
"Could not read CELLSIZE" )
760 ihdrrecs = ihdrrecs + 1
761 else if ( sdirective ==
"NODATA_VALUE" )
then
762 snodatavalue = trim(sargument)
763 ihdrrecs = ihdrrecs + 1
768 rewind( unit=
lu_grid, iostat=istat )
769 call assert ( istat == 0,
"Failed to rewind grid file" )
771 read ( unit=
lu_grid, fmt=
"(a256)", iostat=istat ) sinputrecord
772 call assert ( istat == 0, &
773 "Could not read input record - file: "//trim(sfilename))
776 select case ( pgrd%iDataType )
780 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%iData(:,irow)
781 call assert ( istat == 0, &
782 "Failed to read integer grid data - file: " &
783 //trim(sfilename)//
"; row num: "//trim(
ascharacter(irow)) &
784 //
"; line num: "//trim(
ascharacter(irow + ihdrrecs)) &
788 if(len_trim(snodatavalue) > 0)
then
789 read(unit=snodatavalue, fmt=*, iostat=istat) pgrd%iNoDataValue
790 call assert ( istat == 0, &
791 "Failed to read NODATA value in grid data - file: " &
792 //trim(sfilename), __file__,__line__ )
798 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%rData(:,irow)
800 call assert ( istat == 0, &
801 "Failed to read real grid data - file: " &
802 //trim(sfilename)//
"; row num: "//trim(
ascharacter(irow)) &
803 //
"; line num: "//trim(
ascharacter(irow + ihdrrecs)) &
807 if(len_trim(snodatavalue) > 0)
then
808 read(unit=snodatavalue, fmt=*, iostat=istat) pgrd%rNoDataValue
809 call assert ( istat == 0, &
810 "Failed to read NODATA value in grid data - file: " &
811 //trim(sfilename), __file__,__line__ )
816 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%dpData(:,irow)
817 call assert ( istat == 0, &
818 "Failed to read double-precision grid data - file: " &
819 //trim(sfilename)//
"; row num: "//trim(
ascharacter(irow)) &
820 //
"; line num: "//trim(
ascharacter(irow + ihdrrecs)) &
824 if(len_trim(snodatavalue) > 0)
then
825 read(unit=snodatavalue, fmt=*, iostat=istat) pgrd%dpNoDataValue
826 call assert ( istat == 0, &
827 "Failed to read NODATA value in grid data - file: " &
828 //trim(sfilename), __file__,__line__ )
833 "Internal error -- illegal ARC GRID data type", &
842 open ( unit=
lu_grid, iostat=istat )
843 call assert ( istat == 0,
"Failed to close grid file" )
875 character (len=*),
intent(in) :: sfilename
876 integer (c_int),
intent(in) :: idatatype
880 character (len=4) :: ssentinel
881 integer (c_int) :: istat
882 integer (c_int) :: inx,iny
883 integer (c_int) :: irow
884 real (c_double) :: rx0,rx1
885 real (c_double) :: ry0,ry1
886 real (c_float) :: rz0,rz1
887 logical :: lfileexists
890 inquire(file=trim(sfilename), exist=lfileexists)
891 call assert( lfileexists,
"The Surfer ASCII grid file "//
dquote(sfilename)// &
892 " could not be found.",__file__,__line__)
894 inquire(unit=
lu_grid, opened=lisopen )
895 if (lisopen )
close( unit=
lu_grid )
897 open ( newunit=
lu_grid, iostat=istat, file=trim(sfilename) )
898 call assert( istat == 0, &
899 "Could not open input file " // trim(sfilename) )
901 read ( unit=
lu_grid, fmt=*, iostat=istat ) ssentinel
902 call assert ( istat == 0, &
903 "Could not read first record of SURFER grid" )
904 call assert (
LOGICAL(trim(sSentinel) == "DSAA",c_bool), &
905 "This is not a SURFER grid" )
906 read ( unit=
lu_grid, fmt=*, iostat=istat ) inx, iny
907 call assert ( istat == 0, &
908 "Error reading SURFER grid dimensions" )
909 read ( unit=
lu_grid, fmt=*, iostat=istat ) rx0, rx1
910 call assert ( istat == 0, &
911 "Error reading SURFER X limits" )
912 read ( unit=
lu_grid, fmt=*, iostat=istat ) ry0, ry1
913 call assert ( istat == 0, &
914 "Error reading SURFER y limits" )
915 read ( unit=
lu_grid, fmt=*, iostat=istat ) rz0, rz1
916 call assert ( istat == 0, &
917 "Error reading SURFER Z limits" )
919 pgrd =>
grid_create( inx, iny, rx0, ry0, rx1, ry1, idatatype )
920 select case ( idatatype )
923 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%iData(:,irow)
924 call assert ( istat == 0,
"Failed to read integer grid data" )
928 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%rData(:,irow)
929 call assert ( istat == 0,
"Failed to read real grid data" )
933 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%dpData(:,irow)
934 call assert ( istat == 0,
"Failed to read double-precision grid data" )
937 call assert (
false,
"Internal error -- illegal SURFER grid data type" )
940 call assert(inx>0,
"Must have a non-zero number of columns surfer grid file...")
941 call assert(iny>0,
"Must have a non-zero number of rows in a surfer grid file...")
943 pgrd%rGridCellSize = (rx1-rx0)/inx
947 open ( unit=
lu_grid, iostat=istat )
948 call assert ( istat == 0,
"Failed to close grid file" )
957 character (len=*),
intent(in) :: sFileName
958 type (GENERAL_GRID_T),
pointer :: pGrd
961 character (len=4) :: sSentinel
962 integer (c_int) :: iStat
963 integer (c_int) :: iNX,iNY
964 integer (c_int) :: iRow
965 real (c_double) :: rX0,rX1
966 real (c_double) :: rY0,rY1
967 real (c_float) :: rZ0,rZ1
968 logical :: lFileExists
971 inquire(file=trim(sfilename), exist=lfileexists)
972 call assert( lfileexists,
"The Surfer ASCII grid file "//
dquote(sfilename)// &
973 " could not be found.",__file__,__line__)
975 inquire(unit=
lu_grid, opened=lisopen )
976 if (lisopen )
close( unit=
lu_grid )
978 open ( newunit=
lu_grid, iostat=istat, file=trim(sfilename) )
979 call assert( istat == 0, &
980 "Could not open input file " // trim(sfilename) )
982 read ( unit=
lu_grid, fmt=*, iostat=istat ) ssentinel
983 call assert ( istat == 0, &
984 "Could not read first record of SURFER grid" )
985 call assert (
LOGICAL(trim(sSentinel) == "DSAA",c_bool), &
986 "This is not a SURFER grid" )
987 read ( unit=
lu_grid, fmt=*, iostat=istat ) inx, iny
988 call assert ( istat == 0, &
989 "Error reading SURFER grid dimensions" )
990 read ( unit=
lu_grid, fmt=*, iostat=istat ) rx0, rx1
991 call assert ( istat == 0, &
992 "Error reading SURFER X limits" )
993 read ( unit=
lu_grid, fmt=*, iostat=istat ) ry0, ry1
994 call assert ( istat == 0, &
995 "Error reading SURFER y limits" )
996 read ( unit=
lu_grid, fmt=*, iostat=istat ) rz0, rz1
997 call assert ( istat == 0, &
998 "Error reading SURFER Z limits" )
1000 select case ( pgrd%iDataType )
1003 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%iData(:,irow)
1004 call assert ( istat == 0,
"Failed to read integer grid data" )
1008 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%rData(:,irow)
1009 call assert ( istat == 0,
"Failed to read real grid data" )
1013 read ( unit=
lu_grid, fmt=*, iostat=istat ) pgrd%dpData(:,irow)
1014 call assert ( istat == 0,
"Failed to read double-precision grid data" )
1017 call assert (
false,
"Internal error -- illegal SURFER grid data type" )
1020 call assert(inx > 0,
"Must have a non-zero number of grid cells in a surfer grid file...")
1021 call assert(iny > 0,
"Must have a non-zero number of grid cells in a surfer grid file...")
1025 open ( unit=
lu_grid, iostat=istat )
1026 call assert ( istat == 0,
"Failed to close grid file" )
1035 character (len=*),
intent(in) :: sfilename
1037 integer (c_int) :: ioutputformat
1056 character (len=*),
intent(in) :: sfilename
1061 integer (c_int) :: icol,irow
1062 integer (c_int) :: inumcols, inumrows
1063 integer (c_int) :: istat
1064 character(len=256) :: sbuf
1067 inumcols =
size(pgrd%iData,1)
1068 inumrows =
size(pgrd%iData,2)
1070 inumcols =
size(pgrd%rData,1)
1071 inumrows =
size(pgrd%rData,2)
1073 inumcols =
size(pgrd%dpData,1)
1074 inumrows =
size(pgrd%dpData,2)
1076 call assert(
false,
"Internal programming error - Unsupported grid type", &
1081 write(sbuf,fmt=
"(a,a,a)")
'(',trim(
ascharacter(inumcols)),
'(a,1x))'
1084 call assert( istat==0,
"Could not open output file "//
dquote(sfilename), &
1087 write ( unit=
lu_temp, fmt=
"('NCOLS ',i10)", iostat=istat ) inumcols
1088 call assert( istat==0,
"Error writing grid file header", __file__, __line__)
1090 write ( unit=
lu_temp, fmt=
"('NROWS ',i10)", iostat=istat ) inumrows
1091 call assert( istat==0,
"Error writing grid file header", __file__, __line__)
1093 write ( unit=
lu_temp, fmt=
"('XLLCORNER ',f14.3)", iostat=istat ) pgrd%rX0
1094 call assert( istat==0,
"Error writing X limits", __file__, __line__)
1096 write ( unit=
lu_temp, fmt=
"('YLLCORNER ',f14.3)", iostat=istat ) pgrd%rY0
1097 call assert( istat==0,
"Error writing Y limits", __file__, __line__)
1099 write ( unit=
lu_temp, fmt=
"('CELLSIZE ',f14.3)", iostat=istat ) pgrd%rGridCellSize
1100 call assert( istat==0,
"Error writing cell size", __file__, __line__)
1104 write ( unit=
lu_temp, fmt=
"('NODATA_VALUE ',i14)", iostat=istat ) pgrd%iNoDataValue
1105 call assert( istat==0,
"Error writing NODATA value", __file__, __line__)
1107 write( unit=
lu_temp, fmt=trim(sbuf), iostat=istat ) &
1108 (trim(
ascharacter(pgrd%iData(icol,irow) ) ),icol=1,inumcols)
1109 call assert( istat==0,
"Error writing Arc ASCII INTEGER grid data", &
1115 write ( unit=
lu_temp, fmt=
"('NODATA_VALUE ',g0.4)", iostat=istat ) pgrd%rNoDataValue
1116 call assert( istat==0,
"Error writing NODATA value", __file__, __line__)
1118 write( unit=
lu_temp, fmt=trim(sbuf), iostat=istat ) &
1119 (trim(
ascharacter( pgrd%rData(icol,irow), fmt_string=
"g0.5" )),icol=1,inumcols)
1120 call assert( istat==0,
"Error writing Arc ASCII REAL grid data", &
1126 write ( unit=
lu_temp, fmt=
"('NODATA_VALUE ',g0.4)", iostat=istat ) pgrd%dpNoDataValue
1127 call assert( istat==0,
"Error writing NODATA value", __file__, __line__)
1129 write( unit=
lu_temp, fmt=trim(sbuf), iostat=istat ) &
1130 (trim(
ascharacter( pgrd%dpData(icol,irow), fmt_string=
"g0.5" )),icol=1,inumcols)
1131 call assert( istat==0,
"Error writing Arc ASCII REAL grid data", &
1146 character (len=*),
intent(in) :: sfilename
1150 integer (c_int) :: icol,irow
1151 integer (c_int) :: inumcols, inumrows
1152 integer (c_int) :: istat
1153 character(len=256) :: sbuf
1154 real (c_float) :: fhalfcell
1157 inumcols =
size(pgrd%iData,1)
1158 inumrows =
size(pgrd%iData,2)
1160 inumcols =
size(pgrd%rData,1)
1161 inumrows =
size(pgrd%rData,2)
1163 inumcols =
size(pgrd%dpData,1)
1164 inumrows =
size(pgrd%dpData,2)
1166 call assert(
false,
"Internal programming error - Unsupported grid type", &
1170 fhalfcell = real(pgrd%rGridCellSize * 0.5_c_double, c_float)
1173 write(sbuf,fmt=
"(a,a,a)")
'(',trim(
ascharacter(inumcols)),
'(a,1x))'
1176 call assert( istat==0,
"Could not open output file "//
dquote(sfilename), &
1179 write ( unit=
lu_temp, fmt=
"('DSAA')", iostat=istat )
1180 call assert( istat==0,
"Error writing SURFER header", &
1183 write ( unit=
lu_temp, fmt=
"(2i8)", iostat=istat ) inumcols, inumrows
1184 call assert( istat==0,
"Error writing SURFER dimensions", &
1187 write ( unit=
lu_temp, fmt=
"(2f14.3)", iostat=istat ) &
1188 pgrd%rX0 + fhalfcell , pgrd%rX1 - fhalfcell
1189 call assert( istat==0,
"Error writing SURFER X limits", &
1192 write ( unit=
lu_temp, fmt=
"(2f14.3)", iostat=istat ) &
1193 pgrd%rY0 + fhalfcell, pgrd%rY1 - fhalfcell
1194 call assert( istat==0,
"Error writing SURFER Y limits", &
1199 write ( unit=
lu_temp, fmt=
"(2i14)", iostat=istat ) minval(pgrd%iData),maxval(pgrd%iData)
1200 call assert( istat==0,
"Error writing SURFER Z limits", &
1204 do irow=inumrows,1,-1
1205 write( unit=
lu_temp, fmt=trim(sbuf), iostat=istat ) &
1206 (trim(
ascharacter(pgrd%iData(icol,irow) ) ),icol=1,inumcols)
1207 call assert( istat==0,
"Error writing SURFER grid data" , &
1213 write ( unit=
lu_temp, fmt=
"(2f14.3)", iostat=istat ) minval(pgrd%rData),maxval(pgrd%rData)
1214 call assert( istat==0,
"Error writing SURFER Z limits", &
1217 do irow=inumrows,1,-1
1218 write( unit=
lu_temp, fmt=trim(sbuf), iostat=istat ) &
1219 (trim(
ascharacter(pgrd%rData(icol,irow) ) ),icol=1,inumcols)
1220 call assert( istat==0,
"Error writing SURFER grid data" , &
1226 write ( unit=
lu_temp, fmt=
"(2f14.3)", iostat=istat ) minval(pgrd%dpData),maxval(pgrd%dpData)
1227 call assert( istat==0,
"Error writing SURFER Z limits", &
1230 do irow=inumrows,1,-1
1231 write( unit=
lu_temp, fmt=trim(sbuf), iostat=istat ) &
1232 (trim(
ascharacter(pgrd%dpData(icol,irow) ) ),icol=1,inumcols)
1233 call assert( istat==0,
"Error writing SURFER grid data" , &
1270 real (c_float),
intent(in),
optional :: rtolerance
1272 logical (c_bool) :: lconform
1274 real (c_float) :: rtol
1275 real (c_float),
parameter :: rdefault_tolerance = 0.5_c_float
1277 if (
present ( rtolerance ) )
then
1278 rtol = real(rtolerance * ( pgrd1%rX1 - pgrd1%rX0 ), c_float)
1280 rtol = real(rdefault_tolerance * ( pgrd1%rX1 - pgrd1%rX0 ), c_float)
1285 if ( pgrd1%iNX /= pgrd2%iNX )
then
1287 call logs%write(
"Unequal number of columns between grids", iloglevel=
log_all)
1290 if ( pgrd1%iNY /= pgrd2%iNY )
then
1292 call logs%write(
"Unequal number of rows between grids", iloglevel=
log_all)
1295 if( abs( pgrd1%rX0 - pgrd2%rX0 ) > rtol )
then
1296 call logs%write(
"Lower left-hand side X coordinates do not match:", iloglevel=
log_all)
1302 if( abs( pgrd1%rY0 - pgrd2%rY0 ) > rtol )
then
1303 call logs%write(
"Lower left-hand side Y coordinates do not match:", iloglevel=
log_all)
1309 if( abs( pgrd1%rX1 - pgrd2%rX1 ) > rtol )
then
1310 call logs%write(
"Upper right-hand side X coordinates do not match:", iloglevel=
log_all)
1316 if( abs( pgrd1%rY1 - pgrd2%rY1 ) > rtol )
then
1317 call logs%write(
"Upper right-hand side Y coordinates do not match:", iloglevel=
log_all)
1334 real (c_float),
intent(in),
optional :: rtolerance
1336 logical (c_bool) :: lcompletelycover
1338 real (c_float) :: rtol
1339 real (c_float) :: rdefault_tolerance
1341 rdefault_tolerance = real(-pbasegrd%rGridCellSize / 100.0_c_double, c_float)
1344 if (
present ( rtolerance ) )
then
1347 rtol = rdefault_tolerance
1350 if ( (pbasegrd%rX0 - pothergrd%rX0 >= rtol) .and. &
1351 (pbasegrd%rY0 - pothergrd%rY0 >= rtol) .and. &
1352 (pothergrd%rX1 - pbasegrd%rX1 >= rtol) .and. &
1353 (pothergrd%rY1 - pbasegrd%rY1 >= rtol) )
then
1354 lcompletelycover =
true
1356 lcompletelycover =
false
1358 call logs%write(
"Extents of the data grid file "//
dquote(pothergrd%sFilename) &
1359 //
" do not cover the base grid extents.")
1361 call logs%write(
"BASE GRID EXTENTS DATA GRID EXTENTS DIFFERENCE", &
1362 itab=18, ilinesbefore=1)
1365 //
" "//trim(
ascharacter(pbasegrd%rX0 - pothergrd%rX0)) )
1368 //
" "//trim(
ascharacter(pbasegrd%rY0 - pothergrd%rY0)) )
1369 call logs%write(
"X (upper-right): "//trim(
ascharacter(pbasegrd%rX1)) &
1371 //
" "//trim(
ascharacter(pothergrd%rX1 - pbasegrd%rX1)) )
1372 call logs%write(
"Y (upper-right): "//trim(
ascharacter(pbasegrd%rY1)) &
1374 //
" "//trim(
ascharacter(pothergrd%rY1 - pbasegrd%rY1)), ilinesafter=1 )
1427 type ( GENERAL_GRID_T ),
pointer :: pGrd
1428 real (c_float),
intent(in) :: rXval
1429 integer (c_int),
intent(out) :: iBefore,iAfter
1430 real (c_float),
intent(out) :: rFrac
1432 real (c_float) :: rColPosition
1434 rcolposition = real((pgrd%iNX - 1) * (rxval - pgrd%rX0) / (pgrd%rX1 - pgrd%rX0), c_float)
1436 ibefore = floor(rcolposition) + 1
1437 iafter = ibefore + 1
1438 if ( ibefore > pgrd%iNX .or. ibefore < 1)
then
1441 else if ( iafter > pgrd%iNX )
then
1444 rfrac = mod(rcolposition, 1.0_c_float )
1495 type ( GENERAL_GRID_T ),
pointer :: pGrd
1496 real (c_float),
intent(in) :: rYval
1497 integer (c_int),
intent(out) :: iBefore,iAfter
1498 real (c_float),
intent(out) :: rFrac
1500 real (c_float) :: rColPosition
1502 rcolposition = real((pgrd%iNY - 1) * (pgrd%rY1 - ryval) / (pgrd%rY1 - pgrd%rY0), c_float)
1504 ibefore = floor(rcolposition) + 1
1505 iafter = ibefore + 1
1506 if ( ibefore > pgrd%iNY )
then
1509 else if ( ibefore < 1)
then
1512 else if ( iafter > pgrd%iNY )
then
1515 rfrac = mod(rcolposition, 1.0_c_float )
1540 character (len=*) :: sfromproj4, stoproj4
1541 character (kind=c_char, len=len_trim(sFromPROJ4)) :: csfromproj4
1542 character (kind=c_char, len=len_trim(sToPROJ4)) :: cstoproj4
1543 real (c_double),
optional :: rx(:)
1544 real (c_double),
optional :: ry(:)
1547 integer (c_int) :: iretval
1549 if (
present(rx) .and.
present(ry))
then
1561 csfromproj4 = trim(sfromproj4)
1562 cstoproj4 = trim(stoproj4)
1567 if ( ( csfromproj4 .containssimilar.
"latlon" ) &
1568 .or. ( csfromproj4 .containssimilar.
"latlong" ) &
1569 .or. ( csfromproj4 .containssimilar.
"lonlat" ) &
1570 .or. ( csfromproj4 .containssimilar.
"longlat" ) )
then
1578 cstoproj4//c_null_char, &
1579 __file__//c_null_char, &
1581 int(pgrd%iNumGridCells, c_long), pgrd%rX, pgrd%rY)
1588 if( index(string=cstoproj4, substring=
"latlon") > 0 &
1589 .or. index(string=cstoproj4, substring=
"lonlat") > 0 )
then
1597 pgrd%rGridCellSize = ( maxval(pgrd%rX) - minval(pgrd%rX) ) &
1598 / real(pgrd%iNX - 1, c_double)
1600 pgrd%rX0 = minval(pgrd%rX) - pgrd%rGridCellSize / 2.0_c_double
1601 pgrd%rX1 = maxval(pgrd%rX) + pgrd%rGridCellSize / 2.0_c_double
1602 pgrd%rY0 = minval(pgrd%rY) - pgrd%rGridCellSize / 2.0_c_double
1603 pgrd%rY1 = maxval(pgrd%rY) + pgrd%rGridCellSize / 2.0_c_double
1606 pgrd%sPROJ4_string = trim(stoproj4)
1618 type ( GENERAL_GRID_T ),
pointer :: pGrd
1619 character (len=*),
intent(in) :: sFilename
1622 integer (c_int) :: iRunningSum
1623 integer (c_int) :: iRecord
1668 integer (c_int) :: iretval
1669 character (len=*) :: sfromproj4
1670 character (len=*) :: stoproj4
1673 integer (c_int) :: i
1674 logical (c_bool) :: lfound
1675 character (len=256) :: serrormessage
1679 if (iretval /= 0)
then
1681 write(serrormessage,fmt=
"(a,a,a,a,a)") &
1682 "There was an error transforming a grid from this projection:~", &
1683 dquote(sfromproj4),
" to:~", &
1688 serrormessage = serrormessage &
1689 //
"~ PROJ4 Error number "//
ascharacter(iretval)//
" reported.~" &
1690 //
" ==> error description: "//trim(
terrormessage(i)%cErrorMessageText)
1696 call assert(
false, trim(serrormessage), __file__, __line__)
1734 real (c_float),
intent(in) :: rxval,ryval
1736 real (c_float) :: rvalue
1738 integer (c_int) :: ib,jb,ia,ja
1739 real (c_float) :: ylocal,u,v
1743 call assert (ib>0 .and. ia>0 .and. ib <= ubound(pgrd%rData,1) &
1744 .and. ia <= ubound(pgrd%rData,1), &
1745 "Internal programming error: illegal bounds caught~requested column value " &
1747 //
" out of range", __file__, __line__)
1751 if ( ryval < pgrd%rY0 )
then
1752 ylocal = real(pgrd%rY0, c_float)
1753 else if ( ryval > pgrd%rY1 )
then
1754 ylocal = real(pgrd%rY1, c_float)
1765 call assert (jb>0 .and. ja>0 .and. jb <= ubound(pgrd%rData,2) &
1766 .and. ja <= ubound(pgrd%rData,2), &
1767 "Internal programming error: illegal bounds caught~requested row value " &
1769 //
" out of range", __file__, __line__)
1771 rvalue = ( 1.0_c_float -u) * ( 1.0_c_float -v) * pgrd%rData(ib,jb) + &
1772 u * ( 1.0_c_float -v) * pgrd%rData(ib,ja) + &
1773 ( 1.0_c_float -u) * v * pgrd%rData(ia,jb) + &
1774 u * v * pgrd%rData(ia,ja)
1826 real (c_float),
intent(in) :: rxval,rzval,rnodata
1828 real (c_float) :: rvalue
1830 integer (c_int) :: ib,ia,istat,irow
1831 real (c_float) :: u,v,frac,rprev
1832 real (c_float),
dimension(:),
allocatable :: rcol
1835 allocate ( rcol(pgrd%iNY), stat=istat )
1836 call assert(
LOGICAL(istat==0,c_bool), &
1837 "Couldn't allocate temporary array" )
1845 call assert (ib>0 .and. ia>0 .and. ib <= ubound(pgrd%rData,1) &
1846 .and. ia <= ubound(pgrd%rData,1), &
1847 "Internal programming error: requested X value " &
1849 //
" out of range", __file__, __line__)
1851 call assert(ubound(rcol,1) == ubound(pgrd%rData,2), &
1852 "Internal programming error: upper bound of rCol /= upper " &
1853 //
"bound of first array element of pGrd%rData~" &
1854 //
"ubound(rCol)="//trim(
ascharacter(ubound(rcol,1))) &
1855 //
"~ubound(pGrd%rData)="//trim(
ascharacter(ubound(pgrd%rData,1))), &
1861 rcol = u * pgrd%rData(ia,:) + ( 1.0_c_float -u)*pgrd%rData(ib,:)
1865 if ( pgrd%rData(ia, irow) <= rnodata .and. pgrd%rData(ib, irow) <= rnodata )
then
1866 rcol(irow) = rnodata
1867 else if ( pgrd%rData(ib,irow) <= rnodata .and. u>0.9_c_float )
then
1868 rcol(irow) = pgrd%rData(ia,irow)
1869 else if ( pgrd%rData(ia,irow) <= rnodata .and. u<0.1_c_float )
then
1870 rcol(irow) = pgrd%rData(ib,irow)
1871 else if ( pgrd%rData(ia,irow) <= rnodata .or. pgrd%rData(ib,irow) <= rnodata )
then
1872 rcol(irow) = rnodata
1881 if ( rcol(irow) <= rnodata )
then
1882 if ( rprev <= rnodata )
then
1887 v = real(irow-1, c_float) / real(pgrd%iNY-1, c_float)
1888 rvalue = real(( 1.0_c_float -v)*pgrd%rY0 + v*pgrd%rY1, c_float)
1892 if ( rprev <= rnodata )
then
1898 if ( (rcol(irow) - rzval) * (rprev - rzval) < 0.0_c_float )
then
1900 frac = (rzval-rcol(irow-1)) / (rcol(irow)-rcol(irow-1))
1902 v = ( real(irow-2, c_float)+frac ) / real(pgrd%iNY-1, c_float)
1903 rvalue = real(v*pgrd%rY0 + ( 1.0_c_float -v)*pgrd%rY1, c_float)
1905 else if ( rzval < rprev .and. rcol(irow) > rprev )
then
1907 v = real(irow-2, c_float) / real(pgrd%iNY-1, c_float)
1908 rvalue = real(v*pgrd%rY0 + ( 1.0_c_float -v)*pgrd%rY1, c_float)
1910 else if ( rzval > rprev .and. rcol(irow) < rprev )
then
1911 v = real(irow-2, c_float) / real(pgrd%iNY-1, c_float)
1912 rvalue = real(v*pgrd%rY0 + ( 1.0_c_float -v)*pgrd%rY1, c_float)
1914 else if ( irow == pgrd%iNY )
then
1916 rvalue = real(v*pgrd%rY0 + ( 1.0_c_float -v)*pgrd%rY1, c_float)
1955 real (c_float),
intent(in) :: rxval,ryval
1956 real (c_float) :: rvalue
1957 integer (c_int) :: icol,irow
1959 irow = int( pgrd%iNY * (pgrd%rY0 - ryval) / (pgrd%rY0 - pgrd%rY1) ) + 1
1960 if ( irow > pgrd%iNY ) irow = pgrd%iNY
1961 icol = int( pgrd%iNX * (rxval - pgrd%rX0) / (pgrd%rX1 - pgrd%rX0) ) + 1
1962 if ( icol > pgrd%iNX ) icol = pgrd%iNX
1963 rvalue = pgrd%rData(icol,irow)
1973 real (c_double) :: rx
1974 real (c_double) :: ry
1975 logical (c_bool) :: coordinates_fall_inside_grid
1977 coordinates_fall_inside_grid = ( ( rx >= pgrd%rX0 ) .and. ( rx <= pgrd%rX1 ) &
1978 .and. ( ry >= pgrd%rY0 ) .and. ( ry <= pgrd%rY1 ) )
1987 integer (c_int) :: irow
1988 integer (c_int) :: icol
1989 logical (c_bool) :: row_col_falls_inside_grid
1991 row_col_falls_inside_grid = ( ( irow >= 1 ) .and. ( irow <= pgrd%iNY ) &
1992 .and. ( icol >= 1 ) .and. ( icol <= pgrd%iNX ) )
2001 real (c_double) :: rx
2002 integer (c_int) :: icolumnnumber
2006 icolumnnumber = nint(real(pgrd%iNX, c_double) &
2007 * ( rx - pgrd%rX0 ) / (pgrd%rX1 - pgrd%rX0) + 0.5_c_double, c_int)
2034 real (c_double) :: ry
2035 integer (c_int) :: irownumber
2037 irownumber = pgrd%iNY - nint(real(pgrd%iNY, c_double) &
2038 * ( ry - pgrd%rY0 ) / (pgrd%rY1 - pgrd%rY0) - 0.5_c_double, c_int)
2055 real (c_double) :: rx, ry
2056 integer (c_int),
dimension(2) :: icolrow
2059 real (c_float) :: rdist, rmindistance, rdist2
2061 integer (c_int),
save :: ilastcolnum, ilastrownum
2062 integer (c_int) :: istartingcolnum, istartingrownum
2063 integer (c_int) :: irowboundlower, irowboundupper
2064 integer (c_int) :: icolboundlower, icolboundupper
2065 integer (c_int) :: icol, irow
2066 integer (c_int) :: icandidaterow, icandidatecol
2067 logical (c_bool) :: lchanged
2077 if (istartingcolnum > 0 .and. istartingcolnum <= pgrd%iNX &
2078 .and. istartingrownum > 0 .and. istartingrownum <= pgrd%iNY)
then
2079 rdist = real(hypot(pgrd%rX(istartingcolnum,istartingrownum) - rx, &
2080 pgrd%rY(istartingcolnum,istartingrownum) - ry), c_float)
2084 if (ilastcolnum > 0 .and. ilastcolnum <= pgrd%iNX &
2085 .and. ilastrownum > 0 .and. ilastrownum <= pgrd%iNY)
then
2086 rdist2 = real(hypot(pgrd%rX(ilastcolnum,ilastrownum) - rx, &
2087 pgrd%rY(ilastcolnum,ilastrownum) - ry), c_float)
2092 if (rdist > rdist2)
then
2093 icandidaterow = ilastrownum
2094 icandidatecol = ilastcolnum
2096 icandidaterow = istartingrownum
2097 icandidatecol = istartingcolnum
2110 irowboundlower =
clip(
value=icandidaterow - 1, minval=1, maxval=pgrd%iNY)
2111 irowboundupper =
clip(
value=icandidaterow + 1, minval=1, maxval=pgrd%iNY)
2114 icolboundlower =
clip(
value=icandidatecol - 1, minval=1, maxval=pgrd%iNX)
2115 icolboundupper =
clip(
value=icandidatecol + 1, minval=1, maxval=pgrd%iNX)
2119 do irow=irowboundlower,irowboundupper
2120 do icol=icolboundlower,icolboundupper
2122 rdist = real(hypot(pgrd%rX(icol,irow) - rx, pgrd%rY(icol,irow) - ry), c_float)
2124 if (rdist < rmindistance )
then
2126 rmindistance = rdist
2127 icandidatecol = icol
2128 icandidaterow = irow
2140 if (.not. lchanged )
exit
2144 ilastcolnum = icandidatecol
2145 ilastrownum = icandidaterow
2147 icolrow(
column) = icandidatecol
2148 icolrow(
row) = icandidaterow
2152 icolrow(
column) = istartingcolnum
2153 icolrow(
row) = istartingrownum
2161 integer (c_int),
intent(in),
optional :: ivalue
2162 real (c_float),
intent(in),
optional :: fvalue
2164 if (
present( ivalue ) ) pgrd%iNoDataValue = ivalue
2165 if (
present( fvalue ) ) pgrd%rNoDataValue = fvalue
2172 real (c_double) :: rx
2173 integer (c_int) :: icolumnnumber
2175 rx = pgrd%rX0 + pgrd%rGridCellSize * (real(icolumnnumber, c_double) - 0.5_c_double )
2184 real (c_double) :: ry
2185 integer (c_int) :: irownumber
2188 - pgrd%rGridCellSize * (real(irownumber, c_double) - 0.5_c_double )
2198 real (c_double),
optional :: rx(:)
2199 real (c_double),
optional :: ry(:)
2202 integer (c_int) :: icol,irow
2203 integer (c_int) :: istat
2204 integer (c_int) :: nx, ny
2206 if ( .not.
allocated(pgrd%rX) )
then
2208 ALLOCATE (pgrd%rX(pgrd%iNX, pgrd%iNY), stat=istat)
2209 call assert( istat == 0, &
2210 "Could not allocate memory for x-coordinates within grid data structure", &
2214 if ( .not.
allocated(pgrd%rY) )
then
2215 ALLOCATE (pgrd%rY(pgrd%iNX, pgrd%iNY), stat=istat)
2216 call assert( istat == 0, &
2217 "Could not allocate memory for y-coordinates within grid data structure", &
2221 if (
present(rx) .and.
present(ry))
then
2226 call assert( nx == pgrd%iNX, &
2227 "Internal programming error: number of 'X' values does not match number of x values in grid", &
2230 call assert( ny == pgrd%iNY, &
2231 "Internal programming error: number of 'X' values does not match number of x values in grid", &
2236 pgrd%rX(icol, irow) = rx(icol)
2237 pgrd%rY(icol, irow) = ry(irow)
2267 if (
associated( pgrd) )
then
2269 call logs%write(
"---------------------------------------------------")
2270 call logs%write(
"GRID DETAILS:")
2271 call logs%write(
"---------------------------------------------------")
2272 call logs%write(
"file: "//
dquote(pgrd%sFilename) )
2275 call logs%write(
"cellsize: "//trim(
ascharacter(pgrd%rGridCellSize) ) )
2281 call logs%write(
"PROJ4 string: "//
dquote(pgrd%sPROJ4_string) )
2282 call logs%write(
"---------------------------------------------------")
2286 call logs%write(
"---------------------------------------------------")
2287 call logs%write(
" ** grid not allocated ** ")
2288 call logs%write(
"---------------------------------------------------")
2300 integer (c_int),
intent(in) :: icol
2301 integer (c_int),
intent(in) :: irow
2302 integer (c_int) :: ivalue
2305 integer (c_int),
dimension(2) :: icolrow
2306 integer (c_int) :: ispread
2314 rx=real(pgrdto%rX(icol, irow), c_double), &
2315 ry=real(pgrdto%rY(icol, irow), c_double))
2317 if ( icolrow(
column) < 1 .or. icolrow(
column) > pgrdfrom%iNX ) &
2321 if ( icolrow(
row) < 1 .or. icolrow(
row) > pgrdfrom%iNY ) &
2327 ispread = max(1, nint(pgrdto%rGridCellSize / pgrdfrom%rGridCellSize / 2.))
2330 itargetcol=icolrow(
column), &
2331 itargetrow=icolrow(
row), &
2332 inodatavalue=pgrdfrom%iNoDataValue, &
2345 logical (c_bool),
intent(in) :: lusemajorityfilter
2348 integer (c_int) :: icol, irow
2349 integer (c_int),
dimension(2) :: icolrow
2350 integer (c_int) :: ispread
2351 real (c_float) :: fgridcellratio
2358 fgridcellratio = real(pgrdto%rGridCellSize / pgrdfrom%rGridCellSize, c_float)
2361 if ( lusemajorityfilter )
then
2363 call logs%write(
"** Majority filter in use for data from grid file "//
dquote(pgrdfrom%sFilename), lecho=
true )
2365 ispread = max( 1, nint( fgridcellratio / 2.0_c_float ) )
2367 do irow=1,pgrdto%iNY
2368 do icol=1,pgrdto%iNX
2371 rx=real(pgrdto%rX(icol, irow), c_double), &
2372 ry=real(pgrdto%rY(icol, irow), c_double) )
2378 call assert(icolrow(
row) > 0 .and. icolrow(
row) <= pgrdfrom%iNY, &
2379 "Illegal row number supplied: "//trim(
ascharacter(icolrow(
row))), &
2383 itargetcol=icolrow(
column), &
2384 itargetrow=icolrow(
row), &
2385 inodatavalue=pgrdfrom%iNoDataValue, &
2393 do irow=1,pgrdto%iNY
2394 do icol=1,pgrdto%iNX
2397 rx=real(pgrdto%rX(icol, irow), c_double), &
2398 ry=real(pgrdto%rY(icol, irow), c_double))
2404 call assert(icolrow(
row) > 0 .and. icolrow(
row) <= pgrdfrom%iNY, &
2405 "Illegal row number supplied: "//trim(
ascharacter(icolrow(
row))), &
2408 pgrdto%iData(icol,irow) = pgrdfrom%iData( icolrow(
column), icolrow(
row) )
2426 integer (c_int),
dimension(2) :: icolrow
2427 integer (c_int) :: icol, irow
2428 real (c_float),
dimension(3,3) :: rkernel
2440 do irow=1,pgrdto%iNY
2441 do icol=1,pgrdto%iNX
2444 rx=real(pgrdto%rX(icol, irow), c_double), &
2445 ry=real(pgrdto%rY(icol, irow), c_double))
2447 if ( icolrow(
column) < 1 .or. icolrow(
column) > pgrdfrom%iNX) cycle
2448 if ( icolrow(
row) < 1 .or. icolrow(
row) > pgrdfrom%iNY) cycle
2450 pgrdto%rData(icol,irow) = pgrdfrom%rData( icolrow(
column), icolrow(
row) )
2474 iTargetRow, iNoDataValue, iSpread)
result(iRetVal)
2477 integer (c_int) :: itargetcol
2478 integer (c_int) :: itargetrow
2479 integer (c_int) :: inodatavalue
2480 integer (c_int) :: iretval
2481 integer (c_int) :: ispread
2485 integer (c_int),
dimension(625) :: ivalue
2486 integer (c_int),
dimension(625) :: icount
2487 logical (c_bool) :: lmatch
2488 integer (c_int) :: irow
2489 integer (c_int) :: icol
2490 integer (c_int) :: i, ilast, iindex, icellnum
2498 ispread = min(ispread, 12)
2500 do irow=max(1,itargetrow - ispread), min(pgrdfrom%iNY, itargetrow + ispread)
2501 do icol=max(1,itargetcol - ispread), min(pgrdfrom%iNX, itargetcol + ispread)
2503 icellnum = icellnum + 1
2508 if (ivalue(i) == pgrdfrom%iData(icol, irow) )
then
2509 icount(i) = icount(i) + 1
2517 if (.not. lmatch)
then
2519 ivalue(ilast) = pgrdfrom%iData(icol, irow)
2520 icount(ilast) = icount(ilast) + 1
2527 iindex = maxloc(icount, dim=1)
2528 iretval = ivalue(iindex)
2533 iTargetRow, rKernel, rNoDataValue)
result(rRetVal)
2536 integer (c_int) :: inx
2537 integer (c_int) :: iny
2538 integer (c_int) :: itargetcol
2539 integer (c_int) :: itargetrow
2540 real (c_float),
dimension(:,:) :: rkernel
2541 real (c_float),
optional :: rnodatavalue
2542 real (c_float) :: rretval
2545 integer (c_int) :: irowmin, irowmax
2546 integer (c_int) :: icolmin, icolmax
2547 integer (c_int) :: ikernelsize
2548 integer (c_int) :: iincvalue
2549 integer (c_int) :: icol, irow, irownum, icolnum
2550 real (c_float) :: rkernelsum
2555 ikernelsize =
size(rkernel, dim=1)
2556 iincvalue = (ikernelsize - 1) / 2
2558 inx = ubound(pgrdfrom%rData,1)
2559 iny = ubound(pgrdfrom%rData,2)
2561 irowmin = max(1,itargetrow - iincvalue)
2562 irowmax = min(iny, itargetrow + iincvalue)
2564 icolmin = max(1,itargetcol - iincvalue)
2565 icolmax = min(iny, itargetcol + iincvalue)
2567 if( (irowmax - irowmin + 1) /= ikernelsize &
2568 .or. (icolmax - icolmin + 1) /= ikernelsize )
then
2574 rretval = pgrdfrom%rData(itargetcol, itargetrow)
2578 do icol=0,ikernelsize-1
2579 do irow=0,ikernelsize-1
2581 irownum = irow + irowmin
2582 icolnum = icol + icolmin
2584 if (irownum > iny .or. icolnum > inx)
then
2588 rretval = rretval + pgrdfrom%rData(icolnum,irownum) * rkernel(icol+1, irow+1)
2589 rkernelsum = rkernelsum + rkernel(icol+1, irow+1)
2594 if (rkernelsum > 0.) rretval = rretval / rkernelsum
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public true
real(c_float), parameter, public rzero
integer(c_int), parameter datatype_real
logical(c_bool), parameter, public false
real(c_double), parameter, public degrees_to_radians
real(c_float), parameter, public rbigval
integer(c_int), parameter datatype_int
real(c_double), parameter, public radians_to_degrees
integer(c_int), parameter datatype_double
subroutine, public die(smessage, smodule, iline, shints, scalledby, icalledbyline)
Provides support for input and output of gridded ASCII data, as well as for creation and destruction ...
type(general_grid_t) function, pointer, public grid_createcomplete(inx, iny, rx0, ry0, rx1, ry1, idatatype)
Creates a grid of a specified type.
integer(c_int) function, public grid_getgridcolnum(pgrd, rx)
logical(c_bool) function, public grid_coordinatesfallinsidegrid(pgrd, rx, ry)
type(error_message_t), dimension(49) terrormessage
subroutine, public grid_populatexy(pgrd, rx, ry)
real(c_float), parameter, public grid_nodata_real
real(c_float) function grid_searchcolumn(pgrd, rxval, rzval, rnodata)
character(len=256) output_grid_directory_name
logical(c_bool) function, public grid_completelycover(pbasegrd, pothergrd, rtolerance)
integer(c_int), parameter eight_cells
integer(c_int), parameter, public grid_active_cell
type(general_grid_t) function, pointer, public grid_read(sfilename, sfiletype, idatatype)
real(c_float) function grid_lookupreal(pgrd, rxval, ryval)
integer(c_int), parameter four_cells
real(c_float) function grid_convolve_sgl(pgrdfrom, itargetcol, itargetrow, rkernel, rnodatavalue)
subroutine, public grid_writegrid(sfilename, pgrd, ioutputformat)
real(c_float), parameter nc_fill_float
subroutine, public grid_dumpgridextent(pgrd)
integer(c_int) function, public grid_getgridrownum(pgrd, ry)
type(general_grid_t) function, pointer grid_readarcgrid_fn(sfilename, idatatype)
type(general_grid_t) function, pointer, public grid_createsimple(inx, iny, rx0, ry0, rgridcellsize, idatatype)
integer(c_int), parameter, public grid_datatype_int
subroutine, public grid_destroy(pgrd)
subroutine, public grid_writearcgrid(sfilename, pgrd)
integer(c_int), parameter, private row
subroutine grid_lookuprow(pgrd, ryval, ibefore, iafter, rfrac)
real(c_double), parameter, public grid_nodata_double
subroutine, public grid_set_nodata_value(pgrd, ivalue, fvalue)
subroutine grid_lookupcolumn(pgrd, rxval, ibefore, iafter, rfrac)
integer(c_int) function grid_gridtopoint_int(pgrdfrom, pgrdto, icol, irow)
subroutine, public grid_gridtogrid_int(pgrdfrom, pgrdto, lusemajorityfilter)
integer(c_int) function, dimension(2) grid_getgridcolrownum(pgrd, rx, ry)
logical(c_bool) function, public grid_rowcolfallsinsidegrid(pgrd, irow, icol)
integer(c_int), parameter, public grid_nodata_int
integer(c_int), parameter, public grid_datatype_real
subroutine, public grid_readexisting(sfilename, sfiletype, pgrd)
integer(c_int), parameter, public output_arc
real(c_float) function, public grid_interpolate(pgrd, rxval, ryval)
integer(c_int), parameter, private column
integer(c_int), parameter, public output_surfer
subroutine grid_readsurfergrid_sub(sfilename, pgrd)
integer(c_int), parameter nc_fill_int
real(c_double), parameter nc_fill_double
subroutine, public grid_gridtogrid_sgl(pgrdfrom, pgrdto)
real(c_double) function, public grid_getgridy(pgrd, irownumber)
subroutine, public grid_writesurfergrid(sfilename, pgrd)
subroutine grid_checkintegergridvalues(pgrd, sfilename)
logical(c_bool) function, public grid_conform(pgrd1, pgrd2, rtolerance)
subroutine, public grid_checkforproj4error(iretval, sfromproj4, stoproj4)
subroutine, public grid_set_output_directory_name(sdirname)
subroutine, public grid_transform(pgrd, sfromproj4, stoproj4, rx, ry)
Call PROJ4 to transform coordinates.
real(c_double) function, public grid_getgridx(pgrd, icolumnnumber)
type(general_grid_t) function, pointer grid_readsurfergrid_fn(sfilename, idatatype)
integer(c_int), parameter, public grid_datatype_double
subroutine grid_readarcgrid_sub(sfilename, pgrd)
integer(c_int) function grid_majorityfilter_int(pgrdfrom, itargetcol, itargetrow, inodatavalue, ispread)
type(logfile_t), public logs
interface to C code that provides a simplified entry point to PROJ4 capabilities: it has been modifie...