More adaptions
authorAnders Henja <anders@baltrad.eu>
Mon, 14 Nov 2011 13:51:03 +0000 (14:51 +0100)
committerAnders Henja <anders@baltrad.eu>
Mon, 14 Nov 2011 13:51:03 +0000 (14:51 +0100)
Makefile
data/Makefile [new file with mode: 0644]
lib/Makefile
lib/beamblockage.c
lib/beamblockage.h
lib/beamblockagemap.c [new file with mode: 0644]
lib/beamblockagemap.h [new file with mode: 0644]
pybeamb/Makefile [new file with mode: 0644]
pybeamb/pybeamblockage.c [new file with mode: 0644]
pybeamb/pybeamblockage.h [new file with mode: 0644]

index 28ae06b..3449fdd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ def.mk:
 build: def.mk
        $(MAKE) -C lib
        $(MAKE) -C pybeamb
+       $(MAKE) -C data
 
 .PHONY:install
 install: def.mk
@@ -59,9 +60,9 @@ clean:
        $(MAKE) -C lib clean
        $(MAKE) -C pybeamb clean
        $(MAKE) -C data clean
-       $(MAKE) -C config clean
-       $(MAKE) -C test/pytest clean
-       $(MAKE) -C doxygen clean
+       #$(MAKE) -C config clean
+       #$(MAKE) -C test/pytest clean
+       #$(MAKE) -C doxygen clean
        
 
 .PHONY:distclean
@@ -69,7 +70,7 @@ distclean:
        $(MAKE) -C lib distclean
        $(MAKE) -C pybeamb distclean
        $(MAKE) -C data distclean
-       $(MAKE) -C doxygen distclean
-       $(MAKE) -C config distclean
-       $(MAKE) -C test/pytest distclean
+       #$(MAKE) -C doxygen distclean
+       #$(MAKE) -C config distclean
+       #$(MAKE) -C test/pytest distclean
        @\rm -f *~ config.log config.status def.mk
diff --git a/data/Makefile b/data/Makefile
new file mode 100644 (file)
index 0000000..f84332e
--- /dev/null
@@ -0,0 +1,64 @@
+###########################################################################
+# Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+#
+# This file is part of beamb.
+#
+# beamb is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# beamb is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public License
+# along with RAVE.  If not, see <http://www.gnu.org/licenses/>.
+# ------------------------------------------------------------------------
+# 
+# beamb make file
+# @file
+# @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
+# @date 2011-11-10
+###########################################################################
+-include ../def.mk
+
+# And the rest of the make file targets
+#
+.PHONY=all
+all: gtopo30
+
+gtopo30: gtopo30.tgz
+       @tar -xvzf gtopo30.tgz
+       @touch gtopo30
+.PHONY=install
+install: gtopo30
+       @mkdir -p ${prefix}/share/beamb/data/gtopo30
+       @cp -f gtopo30/*.* ${prefix}/share/beamb/data/gtopo30/
+               
+.PHONY=clean
+clean:
+       @\rm -f *.o core *~
+
+.PHONY=distclean                
+distclean:     clean
+       @\rm -fr gtopo30
+
+# --------------------------------------------------------------------
+# Rules
+
+# Contains dependency generation as well, so if you are not using
+# gcc, comment out everything until the $(CC) statement.
+
+%.o : %.c
+       @$(MAKECDEPEND); \
+       cp $(DF).d $(DF).P; \
+       sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
+               -e '/^$$/ d' -e 's/$$/ :/' < $(DF).d >> $(DF).P; \
+       \rm -f $(DF).d
+       $(CC) -c $(CFLAGS) $< -o $@
+
+# NOTE! This ensures that the dependencies are setup at the right time so this should not be moved
+-include $(SOURCES:%.c=$(DEPDIR)/%.P)
index 6d04bfc..73b107c 100644 (file)
@@ -46,7 +46,7 @@ endif
 # --------------------------------------------------------------------
 # Fixed definitions
 
-SOURCES= beamblockage.c
+SOURCES= beamblockage.c beamblockagemap.c
                                
 OBJECTS= $(SOURCES:.c=.o)
 
index e4ac9e8..991f1cd 100644 (file)
@@ -25,45 +25,20 @@ along with beamb.  If not, see <http://www.gnu.org/licenses/>.
  * @date 2011-11-10
  */
 #include "beamblockage.h"
+#include "beamblockagemap.h"
 #include "rave_debug.h"
 #include "rave_alloc.h"
 #include "math.h"
 #include <string.h>
-#include "rave_field.h"
-#include "polarnav.h"
 
 /**
  * Represents the beam blockage algorithm
  */
 struct _BeamBlockage_t {
   RAVE_OBJECT_HEAD /** Always on top */
-  char* topodir;   /**< the topo30 directory */
-  PolarNavigator_t* navigator; /**< the navigator */
+  BeamBlockageMap_t* mapper; /**< the topography reader */
 };
 
-/**
- * Converts a radian to a degree
- */
-#define RAD2DEG(rad) (rad*180.0/M_PI)
-
-/**
- * Converts a degree into a radian
- */
-#define DEG2RAD(deg) (deg*M_PI/180.0)
-
-/**
- * Internally used struct when reading header info from a TOPO30-file
- */
-typedef struct _map_info {
-  double ulxmap; /**< ulxmap */
-  double ulymap; /**< ulymap */
-  int nbits;     /**< nbits */
-  int nrows;     /**< nrows */
-  int ncols;     /**< ncols */
-  double xdim;   /**< xdim */
-  double ydim;   /**< ydim */
-} map_info;
-
 /*@{ Private functions */
 /**
  * Constructor.
@@ -71,16 +46,15 @@ typedef struct _map_info {
 static int BeamBlockage_constructor(RaveCoreObject* obj)
 {
   BeamBlockage_t* self = (BeamBlockage_t*)obj;
-  self->topodir = NULL;
-  self->navigator = RAVE_OBJECT_NEW(&PolarNavigator_TYPE);
+  self->mapper = RAVE_OBJECT_NEW(&BeamBlockageMap_TYPE);
 
-  if (self->navigator == NULL) {
+  if (self->mapper == NULL) {
          goto error;
   }
 
   return 1;
 error:
-  RAVE_OBJECT_RELEASE(self->navigator);
+  RAVE_OBJECT_RELEASE(self->mapper);
   return 0;
 }
 
@@ -91,8 +65,7 @@ error:
 static void BeamBlockage_destructor(RaveCoreObject* obj)
 {
   BeamBlockage_t* self = (BeamBlockage_t*)obj;
-  RAVE_FREE(self->topodir);
-  RAVE_OBJECT_RELEASE(self->navigator);
+  RAVE_OBJECT_RELEASE(self->mapper);
 }
 
 /**
@@ -102,253 +75,29 @@ static int BeamBlockage_copyconstructor(RaveCoreObject* obj, RaveCoreObject* src
 {
   BeamBlockage_t* this = (BeamBlockage_t*)obj;
   BeamBlockage_t* src = (BeamBlockage_t*)srcobj;
-  this->topodir = NULL;
-  this->navigator = RAVE_OBJECT_CLONE(src->navigator);
-  if (!BeamBlockage_setTopo30Directory(this, BeamBlockage_getTopo30Directory(src)) ||
-      this->navigator == NULL) {
+  this->mapper = RAVE_OBJECT_CLONE(src->mapper);
+  if (this->mapper == NULL) {
     goto error;
   }
   return 1;
 error:
-  RAVE_FREE(this->topodir);
-  RAVE_OBJECT_RELEASE(this->navigator);
+  RAVE_OBJECT_RELEASE(this->mapper);
   return 0;
 }
 
-/**
- * Reads the gropo30 header file and populates the info struct
- * @param[in] self - self
- * @param[in] filename - the gtopo file
- * @param[in] info - the structure
- */
-static int BeamBlockageInternal_readTopographyHeader(BeamBlockage_t* self, const char* filename, map_info* info)
-{
-  /* Declaration of variables */
-  char fname[1024];
-  char* s = NULL;
-  char line[100];
-  char token[64];
-  double f;
-  FILE* fp = NULL;
-  int result = 0;
-
-  RAVE_ASSERT((self != NULL), "self == NULL");
-  RAVE_ASSERT((info != NULL), "info == NULL");
-
-  memset(info, 0, sizeof(map_info));
-
-  if (filename == NULL) {
-    goto done;
-  }
-
-  if (self->topodir != NULL) {
-    sprintf(fname, "%s/%s.HDR", self->topodir, filename);
-  } else {
-    sprintf(fname, "%s.HDF", filename);
-  }
-
-  fp = fopen(fname, "r");
-  if (fp == NULL) {
-    RAVE_ERROR1("Failed to open %s for reading", fname);
-    goto done;
-  }
-
-  while (fgets(line, sizeof(line), fp) > 0) {
-    if (sscanf(line, "%s %lf", token, &f) == 2) {
-      if (strcmp(token, "NROWS") == 0) {
-        info->nrows = (int)f;
-      } else if (strcmp(token, "NCOLS") == 0) {
-        info->ncols = (int)f;
-      } else if (strcmp(token, "NBITS") == 0) {
-        info->nbits = (int)f;
-      } else if (strcmp(token, "ULXMAP") == 0) {
-        info->ulxmap = f;
-      } else if (strcmp(token, "ULYMAP") == 0) {
-        info->ulymap = f;
-      } else if (strcmp(token, "XDIM") == 0) {
-        info->xdim = f;
-      } else if (strcmp(token, "YDIM") == 0) {
-        info->ydim = f;
-      }
-    }
-  }
-
-  result = 1;
-done:
-  if (fp != NULL) {
-    fclose(fp);
-  }
-  return result;
-}
-
-static RaveField_t* BeamBlockageInternal_readData(BeamBlockage_t* self, const char* filename, map_info* info)
-{
-  FILE *fp = NULL;
-  char fname[1024];
-  char* *tmp = NULL;
-  RaveField_t *result=NULL, *field = NULL;
-  long x, y;
-  long nitems = 0;
-
-  RAVE_ASSERT((self != NULL), "self == NULL");
-  RAVE_ASSERT((info != NULL), "info == NULL");
-
-  if (filename == NULL) {
-    goto done;
-  }
-
-  if (self->topodir != NULL) {
-    sprintf(fname, "%s/%s.DEM", self->topodir, filename);
-  } else {
-    sprintf(fname, "%s.DEM", filename);
-  }
-
-  nitems = info->ncols * info->nrows;
-
-  tmp = RAVE_MALLOC(sizeof(short)*nitems);
-  if (tmp == NULL) {
-    goto done;
-  }
-
-  fp = fopen(fname, "rb");
-  if (fp == NULL) {
-    goto done;
-  }
-
-  if (fread(tmp, sizeof(short), nitems, fp) != nitems) {
-    RAVE_WARNING0("Could not read correct number of items");
-  }
-
-  field = RAVE_OBJECT_NEW(&RaveField_TYPE);
-  if (field == NULL || !RaveField_createData(field, info->ncols, info->nrows, RaveDataType_SHORT)) {
-    goto done;
-  }
-
-  for (x = 0; x < info->ncols; x++) {
-    for (y = 0; y < info->nrows; y++) {
-      RaveField_setValue(field, x, y, ntohs(tmp[y*info->ncols + x]));
-    }
-  }
-
-  result = RAVE_OBJECT_COPY(field);
-done:
-  RAVE_FREE(tmp);
-  RAVE_OBJECT_RELEASE(field);
-  if (fp != NULL) {
-    fclose(fp);
-  }
-  return result;
-}
-
-/**
- * Find out which maps are needed to cover given area
- * @param[in] lat - latitude of radar in degrees
- * @param[in] lon - longitude of radar in degrees
- * @param[in] d - maximum range of radar in meters
- * @returns flag corresponding to map to be read
- */
-static RaveField_t* BeamBlockageInternal_readTopography(BeamBlockage_t* self, double lat, double lon, double d)
-{
-  double lat_e, lon_e, lat_w, lon_w, lat_n, lat_s;
-  double earthRadius = 0.0;
-  RaveField_t *field = NULL, *result = NULL;
-  map_info minfo;
-
-  RAVE_ASSERT((self != NULL), "self == NULL");
-  earthRadius = PolarNavigator_getEarthRadius(self->navigator, lat);
-
-  /* Find out which map is needed
-     see http://www.movable-type.co.uk/scripts/latlong.html */
-  lat_e = asin(sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(M_PI/2.));
-  lon_e = lon + atan2( sin(M_PI/2.) * sin(d/earthRadius) * cos(lat), \
-          cos(d/earthRadius) - sin(lat) * sin(lat_e) );
-  lat_w = asin( sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(3.*M_PI/2.) );
-  lon_w = lon + atan2( sin(3.*M_PI/2.) * sin(d/earthRadius) * cos(lat), \
-          cos(d/earthRadius) - sin(lat) * sin(lat_w) );
-  lat_n = asin( sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(0.) );
-  lat_s = asin( sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(M_PI) );
-
-  if (RAD2DEG(lat_n) > 80.0 || RAD2DEG(lat_s) < 40.0 || RAD2DEG(lon_w) < -20.0 || RAD2DEG(lon_e) > 60.0) {
-    RAVE_ERROR0("Topography maps does not cover requested area");
-    goto done;
-  } else if (RAD2DEG(lon_e) <= 20.0) {
-    // Read W020N90
-    if (!BeamBlockageInternal_readTopographyHeader(self, "W020N90", &minfo)) {
-      goto done;
-    }
-    if ((field = BeamBlockageInternal_readData(self, "W020N90", &minfo)) == NULL) {
-      goto done;
-    }
-  } else if (RAD2DEG(lon_w) > 20.0) {
-    // Read E020N90
-    if (!BeamBlockageInternal_readTopographyHeader(self, "E020N90", &minfo)) {
-      goto done;
-    }
-    if ((field = BeamBlockageInternal_readData(self, "E020N90", &minfo)) == NULL) {
-      goto done;
-    }
-  } else {
-    // Read both
-    map_info minfo2;
-    RaveField_t *field2 = NULL;
-
-    if (!BeamBlockageInternal_readTopographyHeader(self, "W020N90", &minfo) ||
-        !BeamBlockageInternal_readTopographyHeader(self, "E020N90", &minfo2)) {
-      goto done;
-    }
-
-    field = BeamBlockageInternal_readData(self, "W020N90", &minfo);
-    field2 = BeamBlockageInternal_readData(self, "E020N90", &minfo2);
-
-    if (field == NULL || field2 == NULL) {
-      RAVE_OBJECT_RELEASE(field);
-      RAVE_OBJECT_RELEASE(field2);
-      goto done;
-    }
-
-#ifdef KALLE
-    /* Check that number of rows and spacing are the same */
-    if(map1->nrows == map2->nrows && map1->xdim == map2-> xdim \
-        && map1->ydim == map2-> ydim && map1->nbits == map2->nbits)
-    {
-#endif
-  }
-
-done:
-  RAVE_OBJECT_RELEASE(field);
-  return NULL;
-}
-
+/*@} End of Private functions */
 
 /*@{ Interface functions */
 int BeamBlockage_setTopo30Directory(BeamBlockage_t* self, const char* topodirectory)
 {
-  char* tmp = NULL;
-  int result = 0;
-
   RAVE_ASSERT((self != NULL), "self == NULL");
-
-  if (topodirectory != NULL) {
-    tmp = RAVE_STRDUP(topodirectory);
-    if (tmp == NULL) {
-      RAVE_ERROR0("Failed to duplicate string");
-      goto done;
-    }
-  }
-
-  RAVE_FREE(self->topodir);
-  self->topodir = tmp;
-  tmp = NULL; // Not responsible for memory any longer
-  result = 1;
-done:
-  RAVE_FREE(tmp);
-  return result;
+  return BeamBlockageMap_setTopo30Directory(self->mapper, topodirectory);
 }
 
 const char* BeamBlockage_getTopo30Directory(BeamBlockage_t* self)
 {
   RAVE_ASSERT((self != NULL), "self == NULL");
-  return (const char*)self->topodir;
+  return (const char*)BeamBlockageMap_getTopo30Directory(self->mapper);
 }
 
 /*@} End of Interface functions */
index 056fd09..bd3132c 100644 (file)
@@ -53,6 +53,4 @@ int BeamBlockage_setTopo30Directory(BeamBlockage_t* self, const char* topodirect
  */
 const char* BeamBlockage_getTopo30Directory(BeamBlockage_t* self);
 
-
-
 #endif /* BEAMBLOCKAGE_H */
diff --git a/lib/beamblockagemap.c b/lib/beamblockagemap.c
new file mode 100644 (file)
index 0000000..1d9ffae
--- /dev/null
@@ -0,0 +1,364 @@
+/* --------------------------------------------------------------------
+Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+
+This file is part of beam blockage (beamb).
+
+beamb is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+beamb is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with beamb.  If not, see <http://www.gnu.org/licenses/>.
+------------------------------------------------------------------------*/
+/**
+ * Beam-blockage topography map reading functionallity
+ * @file
+ * @author Anders Henja (SMHI)
+ * @date 2011-11-14
+ */
+#include "beamblockagemap.h"
+#include "rave_debug.h"
+#include "rave_alloc.h"
+#include "math.h"
+#include <string.h>
+#include "rave_field.h"
+#include "polarnav.h"
+#include <stdio.h>
+#include <arpa/inet.h>
+
+/**
+ * Represents the beam blockage algorithm
+ */
+struct _BeamBlockageMap_t {
+  RAVE_OBJECT_HEAD /** Always on top */
+  char* topodir;   /**< the topo30 directory */
+  PolarNavigator_t* navigator; /**< the navigator */
+};
+
+/**
+ * Converts a radian to a degree
+ */
+#define RAD2DEG(rad) (rad*180.0/M_PI)
+
+/**
+ * Converts a degree into a radian
+ */
+#define DEG2RAD(deg) (deg*M_PI/180.0)
+
+/**
+ * Internally used struct when reading header info from a TOPO30-file
+ */
+typedef struct _map_info {
+  double ulxmap; /**< ulxmap */
+  double ulymap; /**< ulymap */
+  int nbits;     /**< nbits */
+  int nrows;     /**< nrows */
+  int ncols;     /**< ncols */
+  double xdim;   /**< xdim */
+  double ydim;   /**< ydim */
+} map_info;
+
+/*@{ Private functions */
+/**
+ * Constructor.
+ */
+static int BeamBlockageMap_constructor(RaveCoreObject* obj)
+{
+  BeamBlockageMap_t* self = (BeamBlockageMap_t*)obj;
+  self->topodir = NULL;
+  self->navigator = RAVE_OBJECT_NEW(&PolarNavigator_TYPE);
+
+  if (self->navigator == NULL) {
+    goto error;
+  }
+
+  return 1;
+error:
+  RAVE_OBJECT_RELEASE(self->navigator);
+  return 0;
+}
+
+/**
+ * Destroys the polar navigator
+ * @param[in] polnav - the polar navigator to destroy
+ */
+static void BeamBlockageMap_destructor(RaveCoreObject* obj)
+{
+  BeamBlockageMap_t* self = (BeamBlockageMap_t*)obj;
+  RAVE_FREE(self->topodir);
+  RAVE_OBJECT_RELEASE(self->navigator);
+}
+
+/**
+ * Copy constructor
+ */
+static int BeamBlockageMap_copyconstructor(RaveCoreObject* obj, RaveCoreObject* srcobj)
+{
+  BeamBlockageMap_t* this = (BeamBlockageMap_t*)obj;
+  BeamBlockageMap_t* src = (BeamBlockageMap_t*)srcobj;
+  this->topodir = NULL;
+  this->navigator = RAVE_OBJECT_CLONE(src->navigator);
+  if (!BeamBlockageMap_setTopo30Directory(this, BeamBlockageMap_getTopo30Directory(src)) ||
+      this->navigator == NULL) {
+    goto error;
+  }
+  return 1;
+error:
+  RAVE_FREE(this->topodir);
+  RAVE_OBJECT_RELEASE(this->navigator);
+  return 0;
+}
+
+/**
+ * Reads the gropo30 header file and populates the info struct
+ * @param[in] self - self
+ * @param[in] filename - the gtopo file
+ * @param[in] info - the structure
+ */
+static int BeamBlockageMapInternal_readTopographyHeader(BeamBlockageMap_t* self, const char* filename, map_info* info)
+{
+  /* Declaration of variables */
+  char fname[1024];
+  char line[100];
+  char token[64];
+  double f;
+  FILE* fp = NULL;
+  int result = 0;
+
+  RAVE_ASSERT((self != NULL), "self == NULL");
+  RAVE_ASSERT((info != NULL), "info == NULL");
+
+  memset(info, 0, sizeof(map_info));
+
+  if (filename == NULL) {
+    goto done;
+  }
+
+  if (self->topodir != NULL) {
+    sprintf(fname, "%s/%s.HDR", self->topodir, filename);
+  } else {
+    sprintf(fname, "%s.HDF", filename);
+  }
+
+  fp = fopen(fname, "r");
+  if (fp == NULL) {
+    RAVE_ERROR1("Failed to open %s for reading", fname);
+    goto done;
+  }
+
+  while (fgets(line, sizeof(line), fp) > 0) {
+    if (sscanf(line, "%s %lf", token, &f) == 2) {
+      if (strcmp(token, "NROWS") == 0) {
+        info->nrows = (int)f;
+      } else if (strcmp(token, "NCOLS") == 0) {
+        info->ncols = (int)f;
+      } else if (strcmp(token, "NBITS") == 0) {
+        info->nbits = (int)f;
+      } else if (strcmp(token, "ULXMAP") == 0) {
+        info->ulxmap = f;
+      } else if (strcmp(token, "ULYMAP") == 0) {
+        info->ulymap = f;
+      } else if (strcmp(token, "XDIM") == 0) {
+        info->xdim = f;
+      } else if (strcmp(token, "YDIM") == 0) {
+        info->ydim = f;
+      }
+    }
+  }
+
+  result = 1;
+done:
+  if (fp != NULL) {
+    fclose(fp);
+  }
+  return result;
+}
+
+static RaveField_t* BeamBlockageMapInternal_readData(BeamBlockageMap_t* self, const char* filename, map_info* info)
+{
+  FILE *fp = NULL;
+  char fname[1024];
+  short *tmp = NULL;
+  RaveField_t *result=NULL, *field = NULL;
+  long x, y;
+  long nitems = 0;
+
+  RAVE_ASSERT((self != NULL), "self == NULL");
+  RAVE_ASSERT((info != NULL), "info == NULL");
+
+  if (filename == NULL) {
+    goto done;
+  }
+
+  if (self->topodir != NULL) {
+    sprintf(fname, "%s/%s.DEM", self->topodir, filename);
+  } else {
+    sprintf(fname, "%s.DEM", filename);
+  }
+
+  nitems = info->ncols * info->nrows;
+
+  tmp = RAVE_MALLOC(sizeof(short)*nitems);
+  if (tmp == NULL) {
+    goto done;
+  }
+
+  fp = fopen(fname, "rb");
+  if (fp == NULL) {
+    goto done;
+  }
+
+  if (fread(tmp, sizeof(short), nitems, fp) != nitems) {
+    RAVE_WARNING0("Could not read correct number of items");
+  }
+
+  field = RAVE_OBJECT_NEW(&RaveField_TYPE);
+  if (field == NULL || !RaveField_createData(field, info->ncols, info->nrows, RaveDataType_SHORT)) {
+    goto done;
+  }
+
+  for (x = 0; x < info->ncols; x++) {
+    for (y = 0; y < info->nrows; y++) {
+      RaveField_setValue(field, x, y, (double)ntohs((short)(tmp[y*info->ncols + x])));
+    }
+  }
+
+  result = RAVE_OBJECT_COPY(field);
+done:
+  RAVE_FREE(tmp);
+  RAVE_OBJECT_RELEASE(field);
+  if (fp != NULL) {
+    fclose(fp);
+  }
+  return result;
+}
+
+/**
+ * Find out which maps are needed to cover given area
+ * @param[in] lat - latitude of radar in degrees
+ * @param[in] lon - longitude of radar in degrees
+ * @param[in] d - maximum range of radar in meters
+ * @returns flag corresponding to map to be read
+ */
+RaveField_t* BeamBlockageMap_readTopography(BeamBlockageMap_t* self, double lat, double lon, double d)
+{
+  double lat_e, lon_e, lat_w, lon_w, lat_n, lat_s;
+  double earthRadius = 0.0;
+  RaveField_t *field = NULL, *result = NULL;
+  map_info minfo;
+
+  RAVE_ASSERT((self != NULL), "self == NULL");
+  earthRadius = PolarNavigator_getEarthRadius(self->navigator, lat);
+
+  /* Find out which map is needed
+     see http://www.movable-type.co.uk/scripts/latlong.html */
+  lat_e = asin(sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(M_PI/2.));
+  lon_e = lon + atan2( sin(M_PI/2.) * sin(d/earthRadius) * cos(lat), \
+          cos(d/earthRadius) - sin(lat) * sin(lat_e) );
+  lat_w = asin( sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(3.*M_PI/2.) );
+  lon_w = lon + atan2( sin(3.*M_PI/2.) * sin(d/earthRadius) * cos(lat), \
+          cos(d/earthRadius) - sin(lat) * sin(lat_w) );
+  lat_n = asin( sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(0.) );
+  lat_s = asin( sin(lat) * cos(d/earthRadius) + cos(lat) * sin(d/earthRadius) * cos(M_PI) );
+
+  if (RAD2DEG(lat_n) > 80.0 || RAD2DEG(lat_s) < 40.0 || RAD2DEG(lon_w) < -20.0 || RAD2DEG(lon_e) > 60.0) {
+    RAVE_ERROR0("Topography maps does not cover requested area");
+    goto done;
+  } else if (RAD2DEG(lon_e) <= 20.0) {
+    // Read W020N90
+    if (!BeamBlockageMapInternal_readTopographyHeader(self, "W020N90", &minfo)) {
+      goto done;
+    }
+    if ((field = BeamBlockageMapInternal_readData(self, "W020N90", &minfo)) == NULL) {
+      goto done;
+    }
+  } else if (RAD2DEG(lon_w) > 20.0) {
+    // Read E020N90
+    if (!BeamBlockageMapInternal_readTopographyHeader(self, "E020N90", &minfo)) {
+      goto done;
+    }
+    if ((field = BeamBlockageMapInternal_readData(self, "E020N90", &minfo)) == NULL) {
+      goto done;
+    }
+  } else {
+    // Read both
+    map_info minfo2;
+    map_info minfo3;
+    RaveField_t *field2 = NULL;
+    RaveField_t *field3 = NULL;
+
+    if (!BeamBlockageMapInternal_readTopographyHeader(self, "W020N90", &minfo2) ||
+        !BeamBlockageMapInternal_readTopographyHeader(self, "E020N90", &minfo3)) {
+      goto done;
+    }
+
+    field2 = BeamBlockageMapInternal_readData(self, "W020N90", &minfo2);
+    field3 = BeamBlockageMapInternal_readData(self, "E020N90", &minfo3);
+
+    if (field2 != NULL && field3 != NULL) {
+      field = RaveField_concatX(field2, field3);
+    }
+
+    memcpy(&minfo, &minfo2, sizeof(map_info));
+    minfo.ncols += minfo3.ncols;
+
+    RAVE_OBJECT_RELEASE(field2);
+    RAVE_OBJECT_RELEASE(field3);
+  }
+
+  if (field != NULL) {
+    // TODO: Add attributes to field
+  }
+
+  result = RAVE_OBJECT_COPY(field);
+done:
+  RAVE_OBJECT_RELEASE(field);
+  return result;
+}
+
+/*@{ Interface functions */
+int BeamBlockageMap_setTopo30Directory(BeamBlockageMap_t* self, const char* topodirectory)
+{
+  char* tmp = NULL;
+  int result = 0;
+
+  RAVE_ASSERT((self != NULL), "self == NULL");
+
+  if (topodirectory != NULL) {
+    tmp = RAVE_STRDUP(topodirectory);
+    if (tmp == NULL) {
+      RAVE_ERROR0("Failed to duplicate string");
+      goto done;
+    }
+  }
+
+  RAVE_FREE(self->topodir);
+  self->topodir = tmp;
+  tmp = NULL; // Not responsible for memory any longer
+  result = 1;
+done:
+  RAVE_FREE(tmp);
+  return result;
+}
+
+const char* BeamBlockageMap_getTopo30Directory(BeamBlockageMap_t* self)
+{
+  RAVE_ASSERT((self != NULL), "self == NULL");
+  return (const char*)self->topodir;
+}
+
+/*@} End of Interface functions */
+
+RaveCoreObjectType BeamBlockageMap_TYPE = {
+    "BeamBlockageMap",
+    sizeof(BeamBlockageMap_t),
+    BeamBlockageMap_constructor,
+    BeamBlockageMap_destructor,
+    BeamBlockageMap_copyconstructor
+};
diff --git a/lib/beamblockagemap.h b/lib/beamblockagemap.h
new file mode 100644 (file)
index 0000000..4a25043
--- /dev/null
@@ -0,0 +1,64 @@
+/* --------------------------------------------------------------------
+Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+
+This file is part of beam blockage (beamb).
+
+beamb is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+beamb is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with beamb.  If not, see <http://www.gnu.org/licenses/>.
+------------------------------------------------------------------------*/
+/**
+ * Beam-blockage topography map reading functionallity
+ * @file
+ * @author Anders Henja (SMHI)
+ * @date 2011-11-14
+ */
+#ifndef BEAMBLOCKAGEMAP_H
+#define BEAMBLOCKAGEMAP_H
+#include "rave_object.h"
+#include "rave_field.h"
+
+/**
+ * Defines a beam blockage object
+ */
+typedef struct _BeamBlockageMap_t BeamBlockageMap_t;
+
+/**
+ * Type definition to use when creating a rave object.
+ */
+extern RaveCoreObjectType BeamBlockageMap_TYPE;
+
+/**
+ * Sets the topo30 directory.
+ * @param[in] self - self
+ * @param[in] topodirectory - the topo directory
+ * @return 1 on success otherwise 0
+ */
+int BeamBlockageMap_setTopo30Directory(BeamBlockageMap_t* self, const char* topodirectory);
+
+/**
+ * Returns the topo30 directory
+ * @param[in] self - self
+ * @return the topo30 directory
+ */
+const char* BeamBlockageMap_getTopo30Directory(BeamBlockageMap_t* self);
+
+/**
+ * Find out which maps are needed to cover given area
+ * @param[in] lat - latitude of radar in radians
+ * @param[in] lon - longitude of radar in radians
+ * @param[in] d - maximum range of radar in meters
+ * @returns flag corresponding to map to be read
+ */
+RaveField_t* BeamBlockageMap_readTopography(BeamBlockageMap_t* self, double lat, double lon, double d);
+
+#endif /* BEAMBLOCKAGEMAP_H */
diff --git a/pybeamb/Makefile b/pybeamb/Makefile
new file mode 100644 (file)
index 0000000..97922c4
--- /dev/null
@@ -0,0 +1,104 @@
+###########################################################################
+# Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+#
+# This file is part of beamb.
+#
+# beamb is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# beamb is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public License
+# along with beamb.  If not, see <http://www.gnu.org/licenses/>.
+# ------------------------------------------------------------------------
+# 
+# beamb make file
+# @file
+# @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
+# @date 2011-11-14
+###########################################################################
+-include ../def.mk
+
+# beamb specific c flags
+#
+CFLAGS= $(SHARED_FLAG) $(CCOPTS) $(DEFS) -I../lib -I. $(PYTHON_INCLUDE_FLAG)\
+                       $(NUMPY_INCLUDE_FLAG) $(RAVE_INCLUDE_FLAG) $(RAVE_INCLUDE_FLAG)/python \
+                       $(HLHDF_INCLUDE_FLAG) $(ZLIB_INCDIR) $(HDF5_INCDIR) $(PROJ_INCLUDE_FLAG)
+
+# Linker flags
+#
+LDFLAGS= -L../lib -L. $(RAVE_LIB_FLAG) $(HLHDF_LIBRARY_FLAG) $(ZLIB_LIBDIR) \
+                       $(HDF5_LIBDIR) $(PROJ_LIB_FLAG) 
+
+# We need to ensure that raves expat requirements are managed
+EXPAT_LIBRARY=
+ifeq ($(EXPAT_SUPPRESSED), no)
+CPPFLAGS+= $(EXPAT_INCLUDE_DIR) -DRAVE_XML_SUPPORTED
+CFLAGS+= $(EXPAT_INCLUDE_DIR) -DRAVE_XML_SUPPORTED
+LDFLAGS+= $(EXPAT_LIB_DIR)
+EXPAT_LIBRARY=-lexpat
+endif
+
+LIBRARIES=-lhlhdf -lproj  $(EXPAT_LIBRARY) -lravetransform -lravepyapi -lbeamb
+
+# --------------------------------------------------------------------
+# Fixed definitions
+
+BEAMBLOCKAGE_SOURCE= pybeamblockage.c
+BEAMBLOCKAGE_OBJECTS= $(BEAMBLOCKAGE_SOURCE:.c=.o)
+BEAMBLOCKAGE_TARGET= _beamblockage.so
+
+MAKECDEPEND=$(CC) -MM $(CFLAGS) -MT '$(@D)/$(@F)' -o $(DF).d $<
+
+DEPDIR=.dep
+DF=$(DEPDIR)/$(*F)
+
+# Ensures that the .dep directory exists
+.PHONY=$(DEPDIR)
+$(DEPDIR):
+       +@[ -d $@ ] || mkdir -p $@
+
+# And the rest of the make file targets
+#
+.PHONY=all
+all:           $(BEAMBLOCKAGE_TARGET)
+
+$(BEAMBLOCKAGE_TARGET): $(DEPDIR) $(BEAMBLOCKAGE_OBJECTS) ../lib/libbeamb.so
+       $(LDSHARED) -o $@ $(BEAMBLOCKAGE_OBJECTS) $(LDFLAGS) $(LIBRARIES)
+
+.PHONY=install
+install:
+       @mkdir -p ${prefix}/share/beamb/pybeamb
+       @cp -v -f $(BEAMBLOCKAGE_TARGET) ${prefix}/share/beamb/pybeamb
+       @cp -v -f *.py ${prefix}/share/beamb/pybeamb
+       @echo "$(prefix)/share/beamb/pybeamb" > "$(SITEPACK_PYTHON)/pybeamb.pth"
+
+.PHONY=clean
+clean:
+       @\rm -f *.o core *~
+       @\rm -fr $(DEPDIR)
+
+.PHONY=distclean                
+distclean:     clean
+       @\rm -f $(BEAMBLOCKAGE_TARGET)
+
+# --------------------------------------------------------------------
+# Rules
+
+# Contains dependency generation as well, so if you are not using
+# gcc, comment out everything until the $(CC) statement.
+%.o : %.c
+       @$(MAKECDEPEND); \
+       cp $(DF).d $(DF).P; \
+       sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
+               -e '/^$$/ d' -e 's/$$/ :/' < $(DF).d >> $(DF).P; \
+       \rm -f $(DF).d
+       $(CC) -c $(CFLAGS) $< -o $@
+
+# NOTE! This ensures that the dependencies are setup at the right time so this should not be moved
+-include $(BEAMBLOCKAGE_SOURCE:%.c=$(DEPDIR)/%.P)
\ No newline at end of file
diff --git a/pybeamb/pybeamblockage.c b/pybeamb/pybeamblockage.c
new file mode 100644 (file)
index 0000000..f2c4b36
--- /dev/null
@@ -0,0 +1,253 @@
+/* --------------------------------------------------------------------
+Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+
+This file is part of beamb.
+
+beamb is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+beamb is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with beamb.  If not, see <http://www.gnu.org/licenses/>.
+------------------------------------------------------------------------*/
+/**
+ * Python API to the beam blockage functions
+ * @file
+ * @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
+ * @date 2011-11-14
+ */
+#include "Python.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+
+#define PYBEAMBLOCKAGE_MODULE   /**< to get correct part in pybeamblockage */
+#include "pybeamblockage.h"
+
+#include "pyrave_debug.h"
+#include "rave_alloc.h"
+
+/**
+ * Debug this module
+ */
+PYRAVE_DEBUG_MODULE("_beamblockage");
+
+/**
+ * Sets a python exception and goto tag
+ */
+#define raiseException_gotoTag(tag, type, msg) \
+{PyErr_SetString(type, msg); goto tag;}
+
+/**
+ * Sets python exception and returns NULL
+ */
+#define raiseException_returnNULL(type, msg) \
+{PyErr_SetString(type, msg); return NULL;}
+
+/**
+ * Error object for reporting errors to the python interpreeter
+ */
+static PyObject *ErrorObject;
+
+/// --------------------------------------------------------------------
+/// BeamBlockage
+/// --------------------------------------------------------------------
+/*@{ BeamBlockage */
+/**
+ * Returns the native BeamBlockage_t instance.
+ * @param[in] beamb - the python beam blockage instance
+ * @returns the native BeamBlockage_t instance.
+ */
+static BeamBlockage_t*
+PyBeamBlockage_GetNative(PyBeamBlockage* beamb)
+{
+  RAVE_ASSERT((beamb != NULL), "beamb == NULL");
+  return RAVE_OBJECT_COPY(beamb->beamb);
+}
+
+/**
+ * Creates a python beam blockage from a native beam blockage or will create an
+ * initial native beam blockage if p is NULL.
+ * @param[in] p - the native beam blockage (or NULL)
+ * @param[in] beamb- the beam blockage (only used if p != NULL)
+ * @returns the python beam blockage.
+ */
+static PyBeamBlockage* PyBeamBlockage_New(BeamBlockage_t* p)
+{
+  PyBeamBlockage* result = NULL;
+  BeamBlockage_t* cp = NULL;
+
+  if (p == NULL) {
+    cp = RAVE_OBJECT_NEW(&BeamBlockage_TYPE);
+    if (cp == NULL) {
+      RAVE_CRITICAL0("Failed to allocate memory for beam blockage.");
+      raiseException_returnNULL(PyExc_MemoryError, "Failed to allocate memory for beam blockage.");
+    }
+  } else {
+    cp = RAVE_OBJECT_COPY(p);
+    result = RAVE_OBJECT_GETBINDING(p); // If p already have a binding, then this should only be increfed.
+    if (result != NULL) {
+      Py_INCREF(result);
+    }
+  }
+
+  if (result == NULL) {
+    result = PyObject_NEW(PyBeamBlockage, &PyBeamBlockage_Type);
+    if (result != NULL) {
+      PYRAVE_DEBUG_OBJECT_CREATED;
+      result->beamb = RAVE_OBJECT_COPY(cp);
+      RAVE_OBJECT_BIND(result->beamb, result);
+    } else {
+      RAVE_CRITICAL0("Failed to create PyBeamBlockage instance");
+      raiseException_gotoTag(done, PyExc_MemoryError, "Failed to allocate memory for beam blockage.");
+    }
+  }
+done:
+  RAVE_OBJECT_RELEASE(cp);
+  return result;
+}
+
+/**
+ * Deallocates the beam blockage
+ * @param[in] obj the object to deallocate.
+ */
+static void _pybeamblockage_dealloc(PyBeamBlockage* obj)
+{
+  /*Nothing yet*/
+  if (obj == NULL) {
+    return;
+  }
+  PYRAVE_DEBUG_OBJECT_DESTROYED;
+  RAVE_OBJECT_UNBIND(obj->beamb, obj);
+  RAVE_OBJECT_RELEASE(obj->beamb);
+  PyObject_Del(obj);
+}
+
+/**
+ * Creates a new instance of the beam blockage
+ * @param[in] self this instance.
+ * @param[in] args arguments for creation or a beam blockage
+ * @return the object on success, otherwise NULL
+ */
+static PyObject* _pybeamblockage_new(PyObject* self, PyObject* args)
+{
+  if (!PyArg_ParseTuple(args, "")) {
+    return NULL;
+  }
+  return (PyObject*)PyBeamBlockage_New(NULL);
+}
+
+/**
+ * All methods a ropo generator can have
+ */
+static struct PyMethodDef _pybeamblockage_methods[] =
+{
+  {NULL, NULL} /* sentinel */
+};
+
+/**
+ * Returns the specified attribute in the beam blockage
+ */
+static PyObject* _pybeamblockage_getattr(PyBeamBlockage* self, char* name)
+{
+  PyObject* res = NULL;
+
+  res = Py_FindMethod(_pybeamblockage_methods, (PyObject*) self, name);
+  if (res)
+    return res;
+
+  PyErr_Clear();
+  PyErr_SetString(PyExc_AttributeError, name);
+  return NULL;
+}
+
+/**
+ * Returns the specified attribute in the polar volume
+ */
+static int _pybeamblockage_setattr(PyBeamBlockage* self, char* name, PyObject* val)
+{
+  int result = -1;
+  if (name == NULL) {
+    goto done;
+  }
+
+  raiseException_gotoTag(done, PyExc_AttributeError, name);
+
+  result = 0;
+done:
+  return result;
+}
+
+/*@} End of Fmi Image */
+
+/// --------------------------------------------------------------------
+/// Type definitions
+/// --------------------------------------------------------------------
+/*@{ Type definitions */
+PyTypeObject PyBeamBlockage_Type =
+{
+  PyObject_HEAD_INIT(NULL)0, /*ob_size*/
+  "BeamBlockageCore", /*tp_name*/
+  sizeof(PyBeamBlockage), /*tp_size*/
+  0, /*tp_itemsize*/
+  /* methods */
+  (destructor)_pybeamblockage_dealloc, /*tp_dealloc*/
+  0, /*tp_print*/
+  (getattrfunc)_pybeamblockage_getattr, /*tp_getattr*/
+  (setattrfunc)_pybeamblockage_setattr, /*tp_setattr*/
+  0, /*tp_compare*/
+  0, /*tp_repr*/
+  0, /*tp_as_number */
+  0,
+  0, /*tp_as_mapping */
+  0 /*tp_hash*/
+};
+/*@} End of Type definitions */
+
+/*@{ Functions */
+
+/*@} End of Functions */
+
+/*@{ Module setup */
+static PyMethodDef functions[] = {
+  {"new", (PyCFunction)_pybeamblockage_new, 1},
+  {NULL,NULL} /*Sentinel*/
+};
+
+PyMODINIT_FUNC
+init_beamblockage(void)
+{
+  PyObject *module=NULL,*dictionary=NULL;
+  static void *PyBeamBlockage_API[PyBeamBlockage_API_pointers];
+  PyObject *c_api_object = NULL;
+  PyBeamBlockage_Type.ob_type = &PyType_Type;
+
+  module = Py_InitModule("_beamblockage", functions);
+  if (module == NULL) {
+    return;
+  }
+  PyBeamBlockage_API[PyBeamBlockage_Type_NUM] = (void*)&PyBeamBlockage_Type;
+  PyBeamBlockage_API[PyBeamBlockage_GetNative_NUM] = (void *)PyBeamBlockage_GetNative;
+  PyBeamBlockage_API[PyBeamBlockage_New_NUM] = (void*)PyBeamBlockage_New;
+
+  c_api_object = PyCObject_FromVoidPtr((void *)PyBeamBlockage_API, NULL);
+
+  if (c_api_object != NULL) {
+    PyModule_AddObject(module, "_C_API", c_api_object);
+  }
+
+  dictionary = PyModule_GetDict(module);
+  ErrorObject = PyString_FromString("_beamblockage.error");
+
+  if (ErrorObject == NULL || PyDict_SetItemString(dictionary, "error", ErrorObject) != 0) {
+    Py_FatalError("Can't define _beamblockage.error");
+  }
+  PYRAVE_DEBUG_INITIALIZE;
+}
+/*@} End of Module setup */
diff --git a/pybeamb/pybeamblockage.h b/pybeamb/pybeamblockage.h
new file mode 100644 (file)
index 0000000..877cb8b
--- /dev/null
@@ -0,0 +1,118 @@
+/* --------------------------------------------------------------------
+Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+
+This file is part of beamb.
+
+beamb is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+beamb is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with beamb.  If not, see <http://www.gnu.org/licenses/>.
+------------------------------------------------------------------------*/
+/**
+ * Python version of the beam blockage
+ * @file
+ * @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
+ * @date 2011-11-14
+ */
+#ifndef PYBEAMBLOCKAGE_H
+#define PYBEAMBLOCKAGE_H
+#include "beamblockage.h"
+
+/**
+ * The beam blockage
+ */
+typedef struct {
+   PyObject_HEAD /*Always have to be on top*/
+   BeamBlockage_t* beamb;  /**< the native object */
+} PyBeamBlockage;
+
+#define PyBeamBlockage_Type_NUM 0                              /**< index of type */
+
+#define PyBeamBlockage_GetNative_NUM 1                         /**< index of GetNative*/
+#define PyBeamBlockage_GetNative_RETURN BeamBlockage_t*         /**< return type for GetNative */
+#define PyBeamBlockage_GetNative_PROTO (PyBeamBlockage*)        /**< arguments for GetNative */
+
+#define PyBeamBlockage_New_NUM 2                               /**< index of New */
+#define PyBeamBlockage_New_RETURN PyBeamBlockage*              /**< return type for New */
+#define PyBeamBlockage_New_PROTO (BeamBlockage_t*)             /**< arguments for New */
+
+#define PyBeamBlockage_API_pointers 3                          /**< number of type and function pointers */
+
+#ifdef PYBEAMBLOCKAGE_MODULE
+/** Forward declaration of type */
+extern PyTypeObject PyBeamBlockage_Type;
+
+/** Checks if the object is a PyBeamBlockage or not */
+#define PyBeamBlockage_Check(op) ((op)->ob_type == &PyBeamBlockage_Type)
+
+/** Forward declaration of PyBeamBlockage_GetNative */
+static PyBeamBlockage_GetNative_RETURN PyBeamBlockage_GetNative PyBeamBlockage_GetNative_PROTO;
+
+/** Forward declaration of PyRopoGenerator_New */
+static PyBeamBlockage_New_RETURN PyBeamBlockage_New PyBeamBlockage_New_PROTO;
+
+#else
+/** Pointers to types and functions */
+static void **PyBeamBlockage_API;
+
+/**
+ * Returns a pointer to the internal beam blockage, remember to release the reference
+ * when done with the object. (RAVE_OBJECT_RELEASE).
+ */
+#define PyBeamBlockage_GetNative \
+  (*(PyBeamBlockage_GetNative_RETURN (*)PyBeamBlockage_GetNative_PROTO) PyBeamBlockage_API[PyBeamBlockage_GetNative_NUM])
+
+/**
+ * Creates a new beam blockage instance. Release this object with Py_DECREF. If a BeamBlockage_t instance is
+ * provided and this instance already is bound to a python instance, this instance will be increfed and
+ * returned.
+ * @param[in] beamb - the BeamBlockage_t instance.
+ * @returns the PyBeamBlockage instance.
+ */
+#define PyBeamBlockage_New \
+  (*(PyBeamBlockage_New_RETURN (*)PyBeamBlockage_New_PROTO) PyBeamBlockage_API[PyBeamBlockage_New_NUM])
+
+/**
+ * Checks if the object is a python beam blockage instance
+ */
+#define PyBeamBlockage_Check(op) \
+   ((op)->ob_type == (PyTypeObject *)PyBeamBlockage_API[PyBeamBlockage_Type_NUM])
+
+/**
+ * Imports the PyBeamBlockage module (like import _beamblockage in python).
+ */
+static int
+import_beamblockage(void)
+{
+  PyObject *module;
+  PyObject *c_api_object;
+
+  module = PyImport_ImportModule("_beamblockage");
+  if (module == NULL) {
+    return -1;
+  }
+
+  c_api_object = PyObject_GetAttrString(module, "_C_API");
+  if (c_api_object == NULL) {
+    Py_DECREF(module);
+    return -1;
+  }
+  if (PyCObject_Check(c_api_object)) {
+    PyBeamBlockage_API = (void **)PyCObject_AsVoidPtr(c_api_object);
+  }
+  Py_DECREF(c_api_object);
+  Py_DECREF(module);
+  return 0;
+}
+
+#endif
+
+#endif /* PYBEAMBLOCKAGE_H */