Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
9044bfa8
Commit
9044bfa8
authored
1 year ago
by
Oliver Heidmann
Committed by
Uwe Schulzweida
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
class rework Tocomplex.cc
parent
2bcdc6cf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!96
Develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tocomplex.cc
+116
-82
116 additions, 82 deletions
src/Tocomplex.cc
with
116 additions
and
82 deletions
src/Tocomplex.cc
+
116
−
82
View file @
9044bfa8
...
...
@@ -10,94 +10,128 @@
#include
"process_int.h"
#include
"cdo_default_values.h"
// Namespace CdoDefault
void
*
Tocomplex
(
void
*
process
)
class
ModuleTocomplex
{
cdo_initialize
(
process
);
auto
RETOCOMPLEX
=
cdo_operator_add
(
"retocomplex"
,
0
,
0
,
nullptr
);
auto
IMTOCOMPLEX
=
cdo_operator_add
(
"imtocomplex"
,
0
,
0
,
nullptr
);
auto
operatorID
=
cdo_operator_id
();
operator_check_argc
(
0
);
auto
streamID1
=
cdo_open_read
(
0
);
CdoStreamID
streamID1
;
int
taxisID1
;
auto
vlistID1
=
cdo_stream_inq_vlist
(
streamID1
);
auto
vlistID2
=
vlistDuplicate
(
vlistID1
);
CdoStreamID
streamID2
;
int
taxisID2
;
int
vlistID2
;
auto
nvars
=
vlistNvars
(
vlistID2
);
for
(
int
varID
=
0
;
varID
<
nvars
;
++
varID
)
{
auto
datatype
=
vlistInqVarDatatype
(
vlistID2
,
varID
);
datatype
=
(
datatype
==
CDI_DATATYPE_FLT64
)
?
CDI_DATATYPE_CPX64
:
CDI_DATATYPE_CPX32
;
vlistDefVarDatatype
(
vlistID2
,
varID
,
datatype
);
}
int
operatorID
;
auto
taxisID1
=
vlistInqTaxis
(
vlistID1
);
auto
taxisID2
=
taxisDuplicate
(
taxisID1
);
vlistDefTaxis
(
vlistID2
,
taxisID2
);
// if (CdoDefault::FileType != CDI_FILETYPE_EXT) cdo_abort("Complex numbers need EXTRA format; used CDO option -f ext!");
auto
streamID2
=
cdo_open_write
(
1
);
cdo_def_vlist
(
streamID2
,
vlistID2
);
VarList
varList1
;
Varray
<
double
>
array1
,
array2
;
int
RETOCOMPLEX
,
IMTOCOMPLEX
;
public:
void
init
(
void
*
process
)
{
cdo_initialize
(
process
);
RETOCOMPLEX
=
cdo_operator_add
(
"retocomplex"
,
0
,
0
,
nullptr
);
IMTOCOMPLEX
=
cdo_operator_add
(
"imtocomplex"
,
0
,
0
,
nullptr
);
operatorID
=
cdo_operator_id
();
operator_check_argc
(
0
);
streamID1
=
cdo_open_read
(
0
);
auto
vlistID1
=
cdo_stream_inq_vlist
(
streamID1
);
vlistID2
=
vlistDuplicate
(
vlistID1
);
auto
nvars
=
vlistNvars
(
vlistID2
);
for
(
int
varID
=
0
;
varID
<
nvars
;
++
varID
)
{
auto
datatype
=
vlistInqVarDatatype
(
vlistID2
,
varID
);
datatype
=
(
datatype
==
CDI_DATATYPE_FLT64
)
?
CDI_DATATYPE_CPX64
:
CDI_DATATYPE_CPX32
;
vlistDefVarDatatype
(
vlistID2
,
varID
,
datatype
);
}
taxisID1
=
vlistInqTaxis
(
vlistID1
);
taxisID2
=
taxisDuplicate
(
taxisID1
);
vlistDefTaxis
(
vlistID2
,
taxisID2
);
// if (CdoDefault::FileType != CDI_FILETYPE_EXT) cdo_abort("Complex numbers need EXTRA format; used CDO option -f ext!");
streamID2
=
cdo_open_write
(
1
);
cdo_def_vlist
(
streamID2
,
vlistID2
);
auto
gridsizemax
=
vlistGridsizeMax
(
vlistID1
);
array1
=
Varray
<
double
>
(
gridsizemax
);
array2
=
Varray
<
double
>
(
2
*
gridsizemax
);
varListInit
(
varList1
,
vlistID1
);
}
void
run
()
{
int
tsID
=
0
;
int
tsID2
=
0
;
while
(
true
)
{
auto
nrecs
=
cdo_stream_inq_timestep
(
streamID1
,
tsID
);
if
(
nrecs
==
0
)
break
;
cdo_taxis_copy_timestep
(
taxisID2
,
taxisID1
);
cdo_def_timestep
(
streamID2
,
tsID2
++
);
for
(
int
recID
=
0
;
recID
<
nrecs
;
++
recID
)
{
size_t
nmiss
;
int
varID
,
levelID
;
cdo_inq_record
(
streamID1
,
&
varID
,
&
levelID
);
cdo_def_record
(
streamID2
,
varID
,
levelID
);
cdo_read_record
(
streamID1
,
array1
.
data
(),
&
nmiss
);
auto
gridsize
=
varList1
[
varID
].
gridsize
;
if
(
operatorID
==
RETOCOMPLEX
)
{
for
(
size_t
i
=
0
;
i
<
gridsize
;
++
i
)
{
array2
[
2
*
i
]
=
array1
[
i
];
array2
[
2
*
i
+
1
]
=
0
;
}
}
else
if
(
operatorID
==
IMTOCOMPLEX
)
{
for
(
size_t
i
=
0
;
i
<
gridsize
;
++
i
)
{
array2
[
2
*
i
]
=
0
;
array2
[
2
*
i
+
1
]
=
array1
[
i
];
}
}
cdo_write_record
(
streamID2
,
array2
.
data
(),
nmiss
);
}
tsID
++
;
}
}
void
close
()
{
cdo_stream_close
(
streamID2
);
cdo_stream_close
(
streamID1
);
vlistDestroy
(
vlistID2
);
cdo_finish
();
}
};
auto
gridsizemax
=
vlistGridsizeMax
(
vlistID1
);
Varray
<
double
>
array1
(
gridsizemax
),
array2
(
2
*
gridsizemax
);
void
*
Tocomplex
(
void
*
process
)
{
ModuleTocomplex
tocomplex
;
VarList
varList1
;
varListInit
(
varList1
,
vlistID1
);
int
tsID
=
0
;
int
tsID2
=
0
;
while
(
true
)
{
auto
nrecs
=
cdo_stream_inq_timestep
(
streamID1
,
tsID
);
if
(
nrecs
==
0
)
break
;
cdo_taxis_copy_timestep
(
taxisID2
,
taxisID1
);
cdo_def_timestep
(
streamID2
,
tsID2
++
);
for
(
int
recID
=
0
;
recID
<
nrecs
;
++
recID
)
{
size_t
nmiss
;
int
varID
,
levelID
;
cdo_inq_record
(
streamID1
,
&
varID
,
&
levelID
);
cdo_def_record
(
streamID2
,
varID
,
levelID
);
cdo_read_record
(
streamID1
,
array1
.
data
(),
&
nmiss
);
auto
gridsize
=
varList1
[
varID
].
gridsize
;
if
(
operatorID
==
RETOCOMPLEX
)
{
for
(
size_t
i
=
0
;
i
<
gridsize
;
++
i
)
{
array2
[
2
*
i
]
=
array1
[
i
];
array2
[
2
*
i
+
1
]
=
0
;
}
}
else
if
(
operatorID
==
IMTOCOMPLEX
)
{
for
(
size_t
i
=
0
;
i
<
gridsize
;
++
i
)
{
array2
[
2
*
i
]
=
0
;
array2
[
2
*
i
+
1
]
=
array1
[
i
];
}
}
cdo_write_record
(
streamID2
,
array2
.
data
(),
nmiss
);
}
tsID
++
;
}
cdo_stream_close
(
streamID2
);
cdo_stream_close
(
streamID1
);
vlistDestroy
(
vlistID2
);
cdo_finish
();
tocomplex
.
init
(
process
);
tocomplex
.
run
();
tocomplex
.
close
();
return
nullptr
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment