Skip to content
Snippets Groups Projects
Commit a7bc5366 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Merge repeated Fortran record copy code.

parent aa7a09f0
No related branches found
No related tags found
No related merge requests found
...@@ -279,6 +279,8 @@ src/stream_cgribex.c -text ...@@ -279,6 +279,8 @@ src/stream_cgribex.c -text
src/stream_cgribex.h -text src/stream_cgribex.h -text
src/stream_ext.c -text src/stream_ext.c -text
src/stream_ext.h -text src/stream_ext.h -text
src/stream_fcommon.c -text
src/stream_fcommon.h -text
src/stream_grb.c -text src/stream_grb.c -text
src/stream_grb.h -text src/stream_grb.h -text
src/stream_gribapi.c -text src/stream_gribapi.c -text
......
...@@ -77,6 +77,8 @@ libcdi_la_SOURCES = \ ...@@ -77,6 +77,8 @@ libcdi_la_SOURCES = \
stream_history.c \ stream_history.c \
stream_ieg.c \ stream_ieg.c \
stream_ieg.h \ stream_ieg.h \
stream_fcommon.c \
stream_fcommon.h \
cdi_int.c \ cdi_int.c \
cdi_int.h \ cdi_int.h \
stream_record.c \ stream_record.c \
......
...@@ -150,10 +150,11 @@ am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \ ...@@ -150,10 +150,11 @@ am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \
institution.lo model.lo namespace.lo serialize.lo \ institution.lo model.lo namespace.lo serialize.lo \
resource_handle.lo servicelib.lo stream_cdf.lo \ resource_handle.lo servicelib.lo stream_cdf.lo \
stream_cgribex.lo stream_ext.lo stream_grb.lo \ stream_cgribex.lo stream_ext.lo stream_grb.lo \
stream_gribapi.lo stream_history.lo stream_ieg.lo cdi_int.lo \ stream_gribapi.lo stream_history.lo stream_ieg.lo \
stream_record.lo stream_srv.lo stream_var.lo table.lo taxis.lo \ stream_fcommon.lo cdi_int.lo stream_record.lo stream_srv.lo \
timebase.lo tsteps.lo util.lo varscan.lo version.lo vlist.lo \ stream_var.lo table.lo taxis.lo timebase.lo tsteps.lo util.lo \
vlist_att.lo vlist_var.lo zaxis.lo stream.lo swap.lo varscan.lo version.lo vlist.lo vlist_att.lo vlist_var.lo \
zaxis.lo stream.lo swap.lo
libcdi_la_OBJECTS = $(am_libcdi_la_OBJECTS) libcdi_la_OBJECTS = $(am_libcdi_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
...@@ -497,6 +498,8 @@ libcdi_la_SOURCES = \ ...@@ -497,6 +498,8 @@ libcdi_la_SOURCES = \
stream_history.c \ stream_history.c \
stream_ieg.c \ stream_ieg.c \
stream_ieg.h \ stream_ieg.h \
stream_fcommon.c \
stream_fcommon.h \
cdi_int.c \ cdi_int.c \
cdi_int.h \ cdi_int.h \
stream_record.c \ stream_record.c \
...@@ -730,6 +733,7 @@ distclean-compile: ...@@ -730,6 +733,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cdf.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cdf.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cgribex.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cgribex.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_ext.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_ext.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_fcommon.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_grb.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_grb.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_gribapi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_gribapi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_history.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_history.Plo@am__quote@
......
...@@ -119,6 +119,7 @@ c="dmemory.c \ ...@@ -119,6 +119,7 @@ c="dmemory.c \
stream_history.c \ stream_history.c \
stream_cgribex.c \ stream_cgribex.c \
stream_gribapi.c \ stream_gribapi.c \
stream_fcommon.c \
stream_grb.c \ stream_grb.c \
stream_srv.c \ stream_srv.c \
stream_ext.c \ stream_ext.c \
...@@ -144,7 +145,7 @@ h="cdi_limits.h resource_handle.h taxis.h dtypes.h file.h service.h extra.h \ ...@@ -144,7 +145,7 @@ h="cdi_limits.h resource_handle.h taxis.h dtypes.h file.h service.h extra.h \
tablepar.h table.h gaussgrid.h grid.h zaxis.h varscan.h binary.h swap.h \ tablepar.h table.h gaussgrid.h grid.h zaxis.h varscan.h binary.h swap.h \
service.h stream_srv.h stream_ext.h stream_ieg.h cdf_int.h \ service.h stream_srv.h stream_ext.h stream_ieg.h cdf_int.h \
cdf.h vlist.h vlist_var.h vlist_att.h model.h institution.h \ cdf.h vlist.h vlist_var.h vlist_att.h model.h institution.h \
resource_unpack.h serialize.h" resource_unpack.h serialize.h stream_fcommon.h"
#cat $h >> ${PROG} #cat $h >> ${PROG}
#cat $c | grep -v '#include' | grep -v '# include' >> ${PROG} #cat $c | grep -v '#include' | grep -v '# include' >> ${PROG}
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "cdi.h" #include "cdi.h"
#include "cdi_int.h" #include "cdi_int.h"
#include "stream_ext.h" #include "stream_ext.h"
#include "stream_fcommon.h"
#include "varscan.h" #include "varscan.h"
#include "datetime.h" #include "datetime.h"
#include "extra.h" #include "extra.h"
...@@ -166,28 +167,7 @@ void extReadRecord(stream_t *streamptr, double *data, int *nmiss) ...@@ -166,28 +167,7 @@ void extReadRecord(stream_t *streamptr, double *data, int *nmiss)
void extCopyRecord(stream_t *streamptr2, stream_t *streamptr1) void extCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
{ {
streamFCopyRecord(streamptr2, streamptr1, "EXTRA");
int fileID1 = streamptr1->fileID;
int fileID2 = streamptr2->fileID;
int tsID = streamptr1->curTsID;
int vrecID = streamptr1->tsteps[tsID].curRecID;
int recID = streamptr1->tsteps[tsID].recIDs[vrecID];
off_t recpos = streamptr1->tsteps[tsID].records[recID].position;
size_t recsize = streamptr1->tsteps[tsID].records[recID].size;
if (fileSetPos(fileID1, recpos, SEEK_SET) != 0)
Error("Cannot seek input file for EXTRA record copy!");
char *buffer = xmalloc(recsize);
if (fileRead(fileID1, buffer, recsize) != recsize)
Error("Failed to read record from EXTRA file for copying!");
if (fileWrite(fileID2, buffer, recsize) != recsize)
Error("Failed to write record to EXTRA file when copying!");
free(buffer);
} }
......
#include <stdlib.h>
#include "dmemory.h"
#include "file.h"
#include "stream_fcommon.h"
void streamFCopyRecord(stream_t *streamptr2, stream_t *streamptr1,
const char *container_name)
{
int fileID1 = streamptr1->fileID;
int fileID2 = streamptr2->fileID;
int tsID = streamptr1->curTsID;
int vrecID = streamptr1->tsteps[tsID].curRecID;
int recID = streamptr1->tsteps[tsID].recIDs[vrecID];
off_t recpos = streamptr1->tsteps[tsID].records[recID].position;
size_t recsize = streamptr1->tsteps[tsID].records[recID].size;
if (fileSetPos(fileID1, recpos, SEEK_SET) != 0)
Error("Cannot seek input file for %s record copy!", container_name);
char *buffer = xmalloc(recsize);
if (fileRead(fileID1, buffer, recsize) != recsize)
Error("Failed to read record from %s file for copying!", container_name);
if (fileWrite(fileID2, buffer, recsize) != recsize)
Error("Failed to write record to %s file when copying!", container_name);
free(buffer);
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
#ifndef STREAM_FCOMMON_H
#define STREAM_FCOMMON_H
#include "cdi_int.h"
void streamFCopyRecord(stream_t *streamptr2, stream_t *streamptr1,
const char *container_name);
#endif
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "varscan.h" #include "varscan.h"
#include "datetime.h" #include "datetime.h"
#include "ieg.h" #include "ieg.h"
#include "stream_fcommon.h"
#include "stream_ieg.h" #include "stream_ieg.h"
#include "vlist.h" #include "vlist.h"
...@@ -527,27 +528,7 @@ void iegDefLevel(int *pdb, int *gdb, double *vct, int zaxisID, int levelID) ...@@ -527,27 +528,7 @@ void iegDefLevel(int *pdb, int *gdb, double *vct, int zaxisID, int levelID)
void iegCopyRecord(stream_t *streamptr2, stream_t *streamptr1) void iegCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
{ {
int fileID1 = streamptr1->fileID; streamFCopyRecord(streamptr2, streamptr1, "IEG");
int fileID2 = streamptr2->fileID;
int tsID = streamptr1->curTsID;
int vrecID = streamptr1->tsteps[tsID].curRecID;
int recID = streamptr1->tsteps[tsID].recIDs[vrecID];
off_t recpos = streamptr1->tsteps[tsID].records[recID].position;
size_t recsize = streamptr1->tsteps[tsID].records[recID].size;
if (fileSetPos(fileID1, recpos, SEEK_SET) != 0)
Error("Cannot seek input file for IEG record copy!");
char *buffer = xmalloc(recsize);
if (fileRead(fileID1, buffer, recsize) != recsize)
Error("Failed to read record from IEG file for copying!");
if (fileWrite(fileID2, buffer, recsize) != recsize)
Error("Failed to write record to IEG file when copying!");
free(buffer);
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "varscan.h" #include "varscan.h"
#include "datetime.h" #include "datetime.h"
#include "service.h" #include "service.h"
#include "stream_fcommon.h"
#include "stream_srv.h" #include "stream_srv.h"
#include "vlist.h" #include "vlist.h"
...@@ -145,27 +146,7 @@ void srvReadRecord(stream_t *streamptr, double *data, int *nmiss) ...@@ -145,27 +146,7 @@ void srvReadRecord(stream_t *streamptr, double *data, int *nmiss)
void srvCopyRecord(stream_t *streamptr2, stream_t *streamptr1) void srvCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
{ {
int fileID1 = streamptr1->fileID; streamFCopyRecord(streamptr2, streamptr1, "SRV");
int fileID2 = streamptr2->fileID;
int tsID = streamptr1->curTsID;
int vrecID = streamptr1->tsteps[tsID].curRecID;
int recID = streamptr1->tsteps[tsID].recIDs[vrecID];
off_t recpos = streamptr1->tsteps[tsID].records[recID].position;
size_t recsize = streamptr1->tsteps[tsID].records[recID].size;
if (fileSetPos(fileID1, recpos, SEEK_SET) != 0)
Error("Cannot seek input file for SRV record copy!");
char *buffer = xmalloc(recsize);
if (fileRead(fileID1, buffer, recsize) != recsize)
Error("Failed to read record from SRV file for copying!");
if (fileWrite(fileID2, buffer, recsize) != recsize)
Error("Failed to write record to SRV file when copying!");
free(buffer);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment