979 class(DisNCStructuredType), intent(inout) :: this
980 integer(I4B) :: var_id
981 character(len=LINELENGTH) :: gmname
982 character(len=LENBIGLINE) :: effective_crs_wkt, derived_wkt
983 character(len=100) :: rotinfo
984 real(DP) :: longitude_of_central_meridian, latitude_of_projection_origin
985 real(DP) :: scale_factor_at_central_meridian, false_easting, false_northing
986 real(DP) :: semi_major_axis, inverse_flattening
987 real(DP) :: standard_parallel_1, standard_parallel_2
988 logical(LGP) :: params_found, is_2sp
989
990 if (this%wkt /= '' .or. this%crs_wkt /= '') then
991 call nf_verify(nf90_redef(this%ncid), this%nc_fname)
992 call nf_verify(nf90_def_var(this%ncid, this%gridmap_name, nf90_int, &
993 var_id), this%nc_fname)
994
995
996
997 if (this%wkt /= '') then
998 call nf_verify(nf90_put_att(this%ncid, var_id, 'wkt', this%wkt), &
999 this%nc_fname)
1000 end if
1001
1002 if (this%crs_wkt /= '') then
1003 effective_crs_wkt = this%crs_wkt
1004 else
1005 effective_crs_wkt = this%wkt
1006 end if
1007
1008
1009
1010
1011
1012
1013 if (this%dis%angrot /= dzero) then
1014 if (this%crs_wkt == '') then
1015 write (warnmsg, '(a)') 'Structured rotated grid with no CRS_WKT &
1016 &input: no rotation-positioning information will be written &
1017 &to the output CRS; x/y coordinate values will not reflect &
1018 &the true rotated position. Applies to file "'// &
1019 trim(this%nc_fname)//'".'
1020 call store_warning(warnmsg)
1021 else
1022 derived_wkt = wrap_rotated_crs(this%crs_wkt, this%dis%xorigin, &
1023 this%dis%yorigin, this%dis%angrot)
1024 if (derived_wkt /= '') then
1025 write (rotinfo, '(a,g0,a,g0,a,g0,a)') 'xorigin=', &
1026 this%dis%xorigin, ', yorigin=', this%dis%yorigin, &
1027 ', angrot=', this%dis%angrot, ' deg'
1028 write (warnmsg, '(a)') 'Structured rotated grid: wrapped &
1029 &CRS_WKT in a derived CRS to encode grid rotation ('// &
1030 trim(rotinfo)//'). Applies to file "'// &
1031 trim(this%nc_fname)//'".'
1032 call store_warning(warnmsg)
1033 effective_crs_wkt = derived_wkt
1034 else
1035 write (warnmsg, '(a)') 'Structured rotated grid: CRS_WKT is &
1036 ¬ a recognized WKT2 PROJCRS; no rotation-positioning &
1037 &information will be written to the output CRS; x/y &
1038 &coordinate values will not reflect the true rotated &
1039 &position. Applies to file "'//trim(this%nc_fname)//'".'
1040 call store_warning(warnmsg)
1041 end if
1042 end if
1043 end if
1044 call nf_verify(nf90_put_att(this%ncid, var_id, 'crs_wkt', &
1045 trim(effective_crs_wkt)), this%nc_fname)
1046
1047 gmname = wkt_to_cf_gridmapping(trim(effective_crs_wkt))
1048 if (gmname /= '') then
1049 call nf_verify(nf90_put_att(this%ncid, var_id, 'grid_mapping_name', &
1050 trim(gmname)), this%nc_fname)
1051 end if
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063 if (trim(gmname) == 'transverse_mercator') then
1064 call wkt_transverse_mercator_params(trim(effective_crs_wkt), &
1065 longitude_of_central_meridian, &
1066 latitude_of_projection_origin, &
1067 scale_factor_at_central_meridian, &
1068 false_easting, false_northing, &
1069 semi_major_axis, inverse_flattening, &
1070 params_found)
1071 if (params_found) then
1072 call nf_verify(nf90_put_att(this%ncid, var_id, &
1073 'longitude_of_central_meridian', &
1074 longitude_of_central_meridian), &
1075 this%nc_fname)
1076 call nf_verify(nf90_put_att(this%ncid, var_id, &
1077 'latitude_of_projection_origin', &
1078 latitude_of_projection_origin), &
1079 this%nc_fname)
1080 call nf_verify(nf90_put_att(this%ncid, var_id, &
1081 'scale_factor_at_central_meridian', &
1082 scale_factor_at_central_meridian), &
1083 this%nc_fname)
1084 call nf_verify(nf90_put_att(this%ncid, var_id, 'false_easting', &
1085 false_easting), this%nc_fname)
1086 call nf_verify(nf90_put_att(this%ncid, var_id, 'false_northing', &
1087 false_northing), this%nc_fname)
1088 call nf_verify(nf90_put_att(this%ncid, var_id, 'semi_major_axis', &
1089 semi_major_axis), this%nc_fname)
1090 call nf_verify(nf90_put_att(this%ncid, var_id, 'inverse_flattening', &
1091 inverse_flattening), this%nc_fname)
1092 else
1093 write (warnmsg, '(a)') 'Structured grid: unable to extract CF &
1094 &transverse_mercator grid_mapping parameters from CRS_WKT; &
1095 &some netCDF readers may not correctly position this grid. &
1096 &Applies to file "'//trim(this%nc_fname)//'".'
1097 call store_warning(warnmsg)
1098 end if
1099 else if (trim(gmname) == 'lambert_conformal_conic') then
1100 call wkt_lambert_conformal_conic_params(trim(effective_crs_wkt), &
1101 standard_parallel_1, &
1102 standard_parallel_2, &
1103 longitude_of_central_meridian, &
1104 latitude_of_projection_origin, &
1105 false_easting, false_northing, &
1106 semi_major_axis, &
1107 inverse_flattening, is_2sp, &
1108 params_found)
1109 if (params_found) then
1110 call nf_verify(nf90_put_att(this%ncid, var_id, 'standard_parallel', &
1111 (/standard_parallel_1, &
1112 standard_parallel_2/)), this%nc_fname)
1113 call nf_verify(nf90_put_att(this%ncid, var_id, &
1114 'longitude_of_central_meridian', &
1115 longitude_of_central_meridian), &
1116 this%nc_fname)
1117 call nf_verify(nf90_put_att(this%ncid, var_id, &
1118 'latitude_of_projection_origin', &
1119 latitude_of_projection_origin), &
1120 this%nc_fname)
1121 call nf_verify(nf90_put_att(this%ncid, var_id, 'false_easting', &
1122 false_easting), this%nc_fname)
1123 call nf_verify(nf90_put_att(this%ncid, var_id, 'false_northing', &
1124 false_northing), this%nc_fname)
1125 call nf_verify(nf90_put_att(this%ncid, var_id, 'semi_major_axis', &
1126 semi_major_axis), this%nc_fname)
1127 call nf_verify(nf90_put_att(this%ncid, var_id, 'inverse_flattening', &
1128 inverse_flattening), this%nc_fname)
1129 else if (.not. is_2sp) then
1130 write (warnmsg, '(a)') 'Structured grid: 1SP lambert_conformal_conic &
1131 &variants are not supported for CF grid_mapping parameter &
1132 &extraction (CF has no scale_factor attribute for this method); &
1133 &some netCDF readers may not correctly position this grid. &
1134 &Applies to file "'//trim(this%nc_fname)//'".'
1135 call store_warning(warnmsg)
1136 else
1137 write (warnmsg, '(a)') 'Structured grid: unable to extract CF &
1138 &lambert_conformal_conic grid_mapping parameters from CRS_WKT; &
1139 &some netCDF readers may not correctly position this grid. &
1140 &Applies to file "'//trim(this%nc_fname)//'".'
1141 call store_warning(warnmsg)
1142 end if
1143 else if (trim(gmname) == 'albers_conical_equal_area') then
1144 call wkt_albers_conical_equal_area_params(trim(effective_crs_wkt), &
1145 standard_parallel_1, &
1146 standard_parallel_2, &
1147 longitude_of_central_meridian, &
1148 latitude_of_projection_origin, &
1149 false_easting, false_northing, &
1150 semi_major_axis, &
1151 inverse_flattening, &
1152 params_found)
1153 if (params_found) then
1154 call nf_verify(nf90_put_att(this%ncid, var_id, 'standard_parallel', &
1155 (/standard_parallel_1, &
1156 standard_parallel_2/)), this%nc_fname)
1157 call nf_verify(nf90_put_att(this%ncid, var_id, &
1158 'longitude_of_central_meridian', &
1159 longitude_of_central_meridian), &
1160 this%nc_fname)
1161 call nf_verify(nf90_put_att(this%ncid, var_id, &
1162 'latitude_of_projection_origin', &
1163 latitude_of_projection_origin), &
1164 this%nc_fname)
1165 call nf_verify(nf90_put_att(this%ncid, var_id, 'false_easting', &
1166 false_easting), this%nc_fname)
1167 call nf_verify(nf90_put_att(this%ncid, var_id, 'false_northing', &
1168 false_northing), this%nc_fname)
1169 call nf_verify(nf90_put_att(this%ncid, var_id, 'semi_major_axis', &
1170 semi_major_axis), this%nc_fname)
1171 call nf_verify(nf90_put_att(this%ncid, var_id, 'inverse_flattening', &
1172 inverse_flattening), this%nc_fname)
1173 else
1174 write (warnmsg, '(a)') 'Structured grid: unable to extract CF &
1175 &albers_conical_equal_area grid_mapping parameters from &
1176 &CRS_WKT; some netCDF readers may not correctly position this &
1177 &grid. Applies to file "'//trim(this%nc_fname)//'".'
1178 call store_warning(warnmsg)
1179 end if
1180 end if
1181
1182
1183
1184
1185 call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
1186 call nf_verify(nf90_put_var(this%ncid, var_id, 1), &
1187 this%nc_fname)
1188 end if