957 class(DisNCStructuredType),
intent(inout) :: this
958 integer(I4B) :: var_id
959 character(len=LINELENGTH) :: gmname
960 character(len=LENBIGLINE) :: effective_crs_wkt, derived_wkt
961 character(len=100) :: rotinfo
962 real(DP) :: longitude_of_central_meridian, latitude_of_projection_origin
963 real(DP) :: scale_factor_at_central_meridian, false_easting, false_northing
964 real(DP) :: semi_major_axis, inverse_flattening
965 real(DP) :: standard_parallel_1, standard_parallel_2
966 logical(LGP) :: params_found, is_2sp
968 if (this%wkt /=
'' .or. this%crs_wkt /=
'')
then
969 call nf_verify(nf90_redef(this%ncid), this%nc_fname)
970 call nf_verify(nf90_def_var(this%ncid, this%gridmap_name, nf90_int, &
971 var_id), this%nc_fname)
975 if (this%wkt /=
'')
then
976 call nf_verify(nf90_put_att(this%ncid, var_id,
'wkt', this%wkt), &
980 if (this%crs_wkt /=
'')
then
981 effective_crs_wkt = this%crs_wkt
983 effective_crs_wkt = this%wkt
991 if (this%dis%angrot /= dzero)
then
992 if (this%crs_wkt ==
'')
then
993 write (warnmsg,
'(a)')
'Structured rotated grid with no CRS_WKT &
994 &input: no rotation-positioning information will be written &
995 &to the output CRS; x/y coordinate values will not reflect &
996 &the true rotated position. Applies to file "'// &
997 trim(this%nc_fname)//
'".'
998 call store_warning(warnmsg)
1000 derived_wkt = wrap_rotated_crs(this%crs_wkt, this%dis%xorigin, &
1001 this%dis%yorigin, this%dis%angrot)
1002 if (derived_wkt /=
'')
then
1003 write (rotinfo,
'(a,g0,a,g0,a,g0,a)')
'xorigin=', &
1004 this%dis%xorigin,
', yorigin=', this%dis%yorigin, &
1005 ', angrot=', this%dis%angrot,
' deg'
1006 write (warnmsg,
'(a)')
'Structured rotated grid: wrapped &
1007 &CRS_WKT in a derived CRS to encode grid rotation ('// &
1008 trim(rotinfo)//
'). Applies to file "'// &
1009 trim(this%nc_fname)//
'".'
1010 call store_warning(warnmsg)
1011 effective_crs_wkt = derived_wkt
1013 write (warnmsg,
'(a)')
'Structured rotated grid: CRS_WKT is &
1014 ¬ a recognized WKT2 PROJCRS; no rotation-positioning &
1015 &information will be written to the output CRS; x/y &
1016 &coordinate values will not reflect the true rotated &
1017 &position. Applies to file "'//trim(this%nc_fname)//
'".'
1018 call store_warning(warnmsg)
1022 call nf_verify(nf90_put_att(this%ncid, var_id,
'crs_wkt', &
1023 trim(effective_crs_wkt)), this%nc_fname)
1025 gmname = wkt_to_cf_gridmapping(trim(effective_crs_wkt))
1026 if (gmname /=
'')
then
1027 call nf_verify(nf90_put_att(this%ncid, var_id,
'grid_mapping_name', &
1028 trim(gmname)), this%nc_fname)
1041 if (trim(gmname) ==
'transverse_mercator')
then
1042 call wkt_transverse_mercator_params(trim(effective_crs_wkt), &
1043 longitude_of_central_meridian, &
1044 latitude_of_projection_origin, &
1045 scale_factor_at_central_meridian, &
1046 false_easting, false_northing, &
1047 semi_major_axis, inverse_flattening, &
1049 if (params_found)
then
1050 call nf_verify(nf90_put_att(this%ncid, var_id, &
1051 'longitude_of_central_meridian', &
1052 longitude_of_central_meridian), &
1054 call nf_verify(nf90_put_att(this%ncid, var_id, &
1055 'latitude_of_projection_origin', &
1056 latitude_of_projection_origin), &
1058 call nf_verify(nf90_put_att(this%ncid, var_id, &
1059 'scale_factor_at_central_meridian', &
1060 scale_factor_at_central_meridian), &
1062 call nf_verify(nf90_put_att(this%ncid, var_id,
'false_easting', &
1063 false_easting), this%nc_fname)
1064 call nf_verify(nf90_put_att(this%ncid, var_id,
'false_northing', &
1065 false_northing), this%nc_fname)
1066 call nf_verify(nf90_put_att(this%ncid, var_id,
'semi_major_axis', &
1067 semi_major_axis), this%nc_fname)
1068 call nf_verify(nf90_put_att(this%ncid, var_id,
'inverse_flattening', &
1069 inverse_flattening), this%nc_fname)
1071 write (warnmsg,
'(a)')
'Structured grid: unable to extract CF &
1072 &transverse_mercator grid_mapping parameters from CRS_WKT; &
1073 &some netCDF readers may not correctly position this grid. &
1074 &Applies to file "'//trim(this%nc_fname)//
'".'
1075 call store_warning(warnmsg)
1077 else if (trim(gmname) ==
'lambert_conformal_conic')
then
1078 call wkt_lambert_conformal_conic_params(trim(effective_crs_wkt), &
1079 standard_parallel_1, &
1080 standard_parallel_2, &
1081 longitude_of_central_meridian, &
1082 latitude_of_projection_origin, &
1083 false_easting, false_northing, &
1085 inverse_flattening, is_2sp, &
1087 if (params_found)
then
1088 call nf_verify(nf90_put_att(this%ncid, var_id,
'standard_parallel', &
1089 (/standard_parallel_1, &
1090 standard_parallel_2/)), this%nc_fname)
1091 call nf_verify(nf90_put_att(this%ncid, var_id, &
1092 'longitude_of_central_meridian', &
1093 longitude_of_central_meridian), &
1095 call nf_verify(nf90_put_att(this%ncid, var_id, &
1096 'latitude_of_projection_origin', &
1097 latitude_of_projection_origin), &
1099 call nf_verify(nf90_put_att(this%ncid, var_id,
'false_easting', &
1100 false_easting), this%nc_fname)
1101 call nf_verify(nf90_put_att(this%ncid, var_id,
'false_northing', &
1102 false_northing), this%nc_fname)
1103 call nf_verify(nf90_put_att(this%ncid, var_id,
'semi_major_axis', &
1104 semi_major_axis), this%nc_fname)
1105 call nf_verify(nf90_put_att(this%ncid, var_id,
'inverse_flattening', &
1106 inverse_flattening), this%nc_fname)
1107 else if (.not. is_2sp)
then
1108 write (warnmsg,
'(a)')
'Structured grid: 1SP lambert_conformal_conic &
1109 &variants are not supported for CF grid_mapping parameter &
1110 &extraction (CF has no scale_factor attribute for this method); &
1111 &some netCDF readers may not correctly position this grid. &
1112 &Applies to file "'//trim(this%nc_fname)//
'".'
1113 call store_warning(warnmsg)
1115 write (warnmsg,
'(a)')
'Structured grid: unable to extract CF &
1116 &lambert_conformal_conic grid_mapping parameters from CRS_WKT; &
1117 &some netCDF readers may not correctly position this grid. &
1118 &Applies to file "'//trim(this%nc_fname)//
'".'
1119 call store_warning(warnmsg)
1121 else if (trim(gmname) ==
'albers_conical_equal_area')
then
1122 call wkt_albers_conical_equal_area_params(trim(effective_crs_wkt), &
1123 standard_parallel_1, &
1124 standard_parallel_2, &
1125 longitude_of_central_meridian, &
1126 latitude_of_projection_origin, &
1127 false_easting, false_northing, &
1129 inverse_flattening, &
1131 if (params_found)
then
1132 call nf_verify(nf90_put_att(this%ncid, var_id,
'standard_parallel', &
1133 (/standard_parallel_1, &
1134 standard_parallel_2/)), this%nc_fname)
1135 call nf_verify(nf90_put_att(this%ncid, var_id, &
1136 'longitude_of_central_meridian', &
1137 longitude_of_central_meridian), &
1139 call nf_verify(nf90_put_att(this%ncid, var_id, &
1140 'latitude_of_projection_origin', &
1141 latitude_of_projection_origin), &
1143 call nf_verify(nf90_put_att(this%ncid, var_id,
'false_easting', &
1144 false_easting), this%nc_fname)
1145 call nf_verify(nf90_put_att(this%ncid, var_id,
'false_northing', &
1146 false_northing), this%nc_fname)
1147 call nf_verify(nf90_put_att(this%ncid, var_id,
'semi_major_axis', &
1148 semi_major_axis), this%nc_fname)
1149 call nf_verify(nf90_put_att(this%ncid, var_id,
'inverse_flattening', &
1150 inverse_flattening), this%nc_fname)
1152 write (warnmsg,
'(a)')
'Structured grid: unable to extract CF &
1153 &albers_conical_equal_area grid_mapping parameters from &
1154 &CRS_WKT; some netCDF readers may not correctly position this &
1155 &grid. Applies to file "'//trim(this%nc_fname)//
'".'
1156 call store_warning(warnmsg)
1163 call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
1164 call nf_verify(nf90_put_var(this%ncid, var_id, 1), &