Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
edd41f72
Commit
edd41f72
authored
Feb 08, 2019
by
Uwe Schulzweida
Browse files
Added function cdfDefineCoordinates().
parent
fd75ad55
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cdf_write.c
View file @
edd41f72
...
...
@@ -383,6 +383,94 @@ void cdfAppendCoordinates(int fileID, int ncvarid, char coordinates[CDI_MAX_NAME
}
}
static
void
cdfDefineCoordinates
(
const
stream_t
*
streamptr
,
int
fileID
,
int
ncvarid
,
int
nczvarID
,
int
gridtype
,
int
gridID
,
int
gridindex
,
int
xid
,
int
yid
,
size_t
gridsize
,
char
axis
[
5
],
size_t
iax
)
{
char
coordinates
[
CDI_MAX_NAME
];
coordinates
[
0
]
=
0
;
if
(
nczvarID
!=
CDI_UNDEFID
)
cdfAppendCoordinates
(
fileID
,
nczvarID
,
coordinates
);
if
(
gridtype
!=
GRID_GENERIC
&&
gridtype
!=
GRID_LONLAT
&&
gridtype
!=
GRID_GAUSSIAN
&&
gridtype
!=
GRID_PROJECTION
&&
gridtype
!=
GRID_CURVILINEAR
&&
gridtype
!=
GRID_CHARXY
)
{
const
size_t
len
=
strlen
(
gridNamePtr
(
gridtype
));
if
(
len
>
0
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"CDI_grid_type"
,
len
,
gridNamePtr
(
gridtype
));
}
char
gmapvarname
[
CDI_MAX_NAME
];
gmapvarname
[
0
]
=
0
;
cdf_get_gmapvarname
(
gridID
,
gmapvarname
);
if
(
gmapvarname
[
0
]
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"grid_mapping"
,
strlen
(
gmapvarname
),
gmapvarname
);
if
(
gridtype
==
GRID_TRAJECTORY
)
{
cdf_put_att_text
(
fileID
,
ncvarid
,
"coordinates"
,
9
,
"tlon tlat"
);
}
else
if
(
gridtype
==
GRID_LONLAT
&&
xid
==
CDI_UNDEFID
&&
yid
==
CDI_UNDEFID
&&
gridsize
==
1
)
{
const
int
ncxvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_X
];
const
int
ncyvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_Y
];
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
}
else
if
(
gridtype
==
GRID_UNSTRUCTURED
||
gridtype
==
GRID_CURVILINEAR
)
{
char
cellarea
[
CDI_MAX_NAME
]
=
"area: "
;
const
int
ncxvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_X
];
const
int
ncyvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_Y
];
const
int
ncavarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_A
];
// CMOR order: coordinates = "lat lon"
if
(
cdiCoordinatesLonLat
)
{
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
}
else
{
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
}
if
(
ncavarID
!=
CDI_UNDEFID
)
{
size_t
len
=
strlen
(
cellarea
);
cdf_inq_varname
(
fileID
,
ncavarID
,
cellarea
+
len
);
len
=
strlen
(
cellarea
);
cdf_put_att_text
(
fileID
,
ncvarid
,
"cell_measures"
,
len
,
cellarea
);
}
if
(
gridtype
==
GRID_UNSTRUCTURED
)
{
int
position
=
gridInqPosition
(
gridID
);
if
(
position
>
0
)
cdf_put_att_int
(
fileID
,
ncvarid
,
"number_of_grid_in_reference"
,
NC_INT
,
1
,
&
position
);
}
}
else
if
(
gridtype
==
GRID_SPECTRAL
||
gridtype
==
GRID_FOURIER
)
{
axis
[
iax
++
]
=
'-'
;
axis
[
iax
++
]
=
'-'
;
cdf_put_att_text
(
fileID
,
ncvarid
,
"axis"
,
iax
,
axis
);
int
gridTruncation
=
gridInqTrunc
(
gridID
);
cdf_put_att_int
(
fileID
,
ncvarid
,
"truncation"
,
NC_INT
,
1
,
&
gridTruncation
);
}
else
if
(
gridtype
==
GRID_CHARXY
)
{
if
(
gridInqXIsc
(
gridID
)
)
{
const
int
ncxvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_X
];
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
}
else
if
(
gridInqYIsc
(
gridID
)
)
{
const
int
ncyvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_Y
];
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
}
}
size_t
len
=
strlen
(
coordinates
);
if
(
len
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"coordinates"
,
len
,
coordinates
);
}
static
int
cdfDefVar
(
stream_t
*
streamptr
,
int
varID
)
{
...
...
@@ -430,6 +518,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
if
(
yid
!=
CDI_UNDEFID
)
cdf_inq_dimlen
(
fileID
,
yid
,
&
ysize
);
}
const
int
zaxistype
=
zaxisInqType
(
zaxisID
);
const
int
zaxisindex
=
vlistZaxisIndex
(
vlistID
,
zaxisID
);
const
int
zid
=
streamptr
->
zaxisID
[
zaxisindex
];
bool
zaxis_is_scalar
=
false
;
...
...
@@ -602,93 +691,9 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdf_put_att_int
(
fileID
,
ncvarid
,
"table"
,
NC_INT
,
1
,
&
tablenum
);
}
char
coordinates
[
CDI_MAX_NAME
];
coordinates
[
0
]
=
0
;
if
(
zaxis_is_scalar
||
zaxisInqType
(
zaxisID
)
==
ZAXIS_CHAR
)
{
const
int
nczvarID
=
streamptr
->
nczvarID
[
zaxisindex
];
cdfAppendCoordinates
(
fileID
,
nczvarID
,
coordinates
);
}
const
int
nczvarID
=
(
zaxis_is_scalar
||
zaxistype
==
ZAXIS_CHAR
)
?
streamptr
->
nczvarID
[
zaxisindex
]
:
CDI_UNDEFID
;
if
(
gridtype
!=
GRID_GENERIC
&&
gridtype
!=
GRID_LONLAT
&&
gridtype
!=
GRID_GAUSSIAN
&&
gridtype
!=
GRID_PROJECTION
&&
gridtype
!=
GRID_CURVILINEAR
&&
gridtype
!=
GRID_CHARXY
)
{
const
size_t
len
=
strlen
(
gridNamePtr
(
gridtype
));
if
(
len
>
0
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"CDI_grid_type"
,
len
,
gridNamePtr
(
gridtype
));
}
char
gmapvarname
[
CDI_MAX_NAME
];
gmapvarname
[
0
]
=
0
;
cdf_get_gmapvarname
(
gridID
,
gmapvarname
);
if
(
gmapvarname
[
0
]
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"grid_mapping"
,
strlen
(
gmapvarname
),
gmapvarname
);
if
(
gridtype
==
GRID_TRAJECTORY
)
{
cdf_put_att_text
(
fileID
,
ncvarid
,
"coordinates"
,
9
,
"tlon tlat"
);
}
else
if
(
gridtype
==
GRID_LONLAT
&&
xid
==
CDI_UNDEFID
&&
yid
==
CDI_UNDEFID
&&
gridsize
==
1
)
{
const
int
ncxvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_X
];
const
int
ncyvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_Y
];
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
}
else
if
(
gridtype
==
GRID_UNSTRUCTURED
||
gridtype
==
GRID_CURVILINEAR
)
{
char
cellarea
[
CDI_MAX_NAME
]
=
"area: "
;
const
int
ncxvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_X
];
const
int
ncyvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_Y
];
const
int
ncavarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_A
];
// CMOR order: coordinates = "lat lon"
if
(
cdiCoordinatesLonLat
)
{
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
}
else
{
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
}
if
(
ncavarID
!=
CDI_UNDEFID
)
{
size_t
len
=
strlen
(
cellarea
);
cdf_inq_varname
(
fileID
,
ncavarID
,
cellarea
+
len
);
len
=
strlen
(
cellarea
);
cdf_put_att_text
(
fileID
,
ncvarid
,
"cell_measures"
,
len
,
cellarea
);
}
if
(
gridtype
==
GRID_UNSTRUCTURED
)
{
int
position
=
gridInqPosition
(
gridID
);
if
(
position
>
0
)
cdf_put_att_int
(
fileID
,
ncvarid
,
"number_of_grid_in_reference"
,
NC_INT
,
1
,
&
position
);
}
}
else
if
(
gridtype
==
GRID_SPECTRAL
||
gridtype
==
GRID_FOURIER
)
{
const
int
gridTruncation
=
gridInqTrunc
(
gridID
);
axis
[
iax
++
]
=
'-'
;
axis
[
iax
++
]
=
'-'
;
cdf_put_att_text
(
fileID
,
ncvarid
,
"axis"
,
iax
,
axis
);
cdf_put_att_int
(
fileID
,
ncvarid
,
"truncation"
,
NC_INT
,
1
,
&
gridTruncation
);
}
else
if
(
gridtype
==
GRID_CHARXY
)
{
if
(
gridInqXIsc
(
gridID
)
)
{
const
int
ncxvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_X
];
cdfAppendCoordinates
(
fileID
,
ncxvarID
,
coordinates
);
}
else
if
(
gridInqYIsc
(
gridID
)
)
{
const
int
ncyvarID
=
streamptr
->
ncgrid
[
gridindex
].
ncIDs
[
CDF_VARID_Y
];
cdfAppendCoordinates
(
fileID
,
ncyvarID
,
coordinates
);
}
}
size_t
len
=
strlen
(
coordinates
);
if
(
len
)
cdf_put_att_text
(
fileID
,
ncvarid
,
"coordinates"
,
len
,
coordinates
);
cdfDefineCoordinates
(
streamptr
,
fileID
,
ncvarid
,
nczvarID
,
gridtype
,
gridID
,
gridindex
,
xid
,
yid
,
gridsize
,
axis
,
iax
);
cdfDefVarPacking
(
streamptr
,
ncvarid
,
xtype
,
vlistID
,
varID
);
...
...
@@ -706,17 +711,17 @@ int cdfDefVar(stream_t *streamptr, int varID)
if
(
zid
==
-
1
)
{
if
(
zaxis
InqType
(
zaxisID
)
==
ZAXIS_CLOUD_BASE
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_CLOUD_TOP
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_ISOTHERM_ZERO
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_TOA
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_SEA_BOTTOM
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_LAKE_BOTTOM
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_SEDIMENT_BOTTOM
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_SEDIMENT_BOTTOM_TA
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_SEDIMENT_BOTTOM_TW
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_MIX_LAYER
||
zaxis
InqType
(
zaxisID
)
==
ZAXIS_ATMOSPHERE
)
if
(
zaxis
type
==
ZAXIS_CLOUD_BASE
||
zaxis
type
==
ZAXIS_CLOUD_TOP
||
zaxis
type
==
ZAXIS_ISOTHERM_ZERO
||
zaxis
type
==
ZAXIS_TOA
||
zaxis
type
==
ZAXIS_SEA_BOTTOM
||
zaxis
type
==
ZAXIS_LAKE_BOTTOM
||
zaxis
type
==
ZAXIS_SEDIMENT_BOTTOM
||
zaxis
type
==
ZAXIS_SEDIMENT_BOTTOM_TA
||
zaxis
type
==
ZAXIS_SEDIMENT_BOTTOM_TW
||
zaxis
type
==
ZAXIS_MIX_LAYER
||
zaxis
type
==
ZAXIS_ATMOSPHERE
)
{
zaxisInqName
(
zaxisID
,
varname
);
cdf_put_att_text
(
fileID
,
ncvarid
,
"level_type"
,
strlen
(
varname
),
varname
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment