diff --git a/.github/workflows/Linux_options.yml b/.github/workflows/Linux_options.yml index 853f803..f5ea5b5 100644 --- a/.github/workflows/Linux_options.yml +++ b/.github/workflows/Linux_options.yml @@ -105,6 +105,22 @@ jobs: make -j2 make install + - name: checkout-g2c + uses: actions/checkout@v4 + with: + repository: NOAA-EMC/NCEPLIBS-g2c + path: g2c + ref: develop + + - name: build-g2c + run: | + cd g2c + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX=~/g2c -DUSE_OpenJPEG=ON -DUSE_Jasper=OFF + make -j2 + make install + - name: checkout uses: actions/checkout@v2 with: @@ -115,6 +131,7 @@ jobs: cd wgrib2 mkdir b cd b - cmake ${{ matrix.config.options }} -DCMAKE_PREFIX_PATH="~/ip" .. + export CFLAGS='-I/home/runner/g2c/include' + cmake ${{ matrix.config.options }} -DCMAKE_PREFIX_PATH="~/ip;~/g2c" .. make VERBOSE=1 ctest --verbose --output-on-failure --rerun-failed diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bdc4ef..55dd0a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,7 @@ endif() # Find required packages to use OpenJPEG message(STATUS "Checking if the user wants to use OpenJPEG...") if(USE_OPENJPEG) -find_package(OpenJPEG REQUIRED) + find_package(g2c 1.9.0 CONFIG REQUIRED) endif() message(STATUS "Checking if the user want to use OpenMP...") diff --git a/spack/package.py b/spack/package.py index 7ddd52a..90bc92a 100644 --- a/spack/package.py +++ b/spack/package.py @@ -177,8 +177,8 @@ def url_for_version(self, version): depends_on("g2c", when="@develop +jasper") depends_on("zlib-api", when="@3.2: +png") depends_on("libpng", when="@3.2: +png") - depends_on("openjpeg", when="@3.2: +openjpeg") - + depends_on("openjpeg", when="@3.2:3.4 +openjpeg") + depends_on("g2c +openjpeg", when="@develop +openjpeg") @when("@:2 ^gmake@4.2:") diff --git a/wgrib2/CMakeLists.txt b/wgrib2/CMakeLists.txt index 6658cbf..878fe63 100644 --- a/wgrib2/CMakeLists.txt +++ b/wgrib2/CMakeLists.txt @@ -22,7 +22,7 @@ Alias.c Ave_test.c Ave_var.c Bbox.c bitstream.c Box_ave.c Check_pdt_size.c Checksum.c Cluster.c cname.c codetable_4_230.c CodeTable.c Code_Values.c Code_Values_JMA.c complex_pk.c Config.c copy.c crc32.c Cress_lola.c Csv.c Csv_long.c cubed_sphere2ll.c -CubeFace2global.c Cyclic.c Data.c decenc_openjpeg.c dec_png_clone.c +CubeFace2global.c Cyclic.c Data.c dec_png_clone.c Dump.c Earth.c Else.c End.c Endif.c Ensemble.c Ens_processing.c Ens_qc.c EOF.c Export_lonlat.c ExtName.c fatal_error.c Fcst_ave.c ffopen.c Fi.c File.c Fix_CFSv2_fcst.c @@ -143,16 +143,11 @@ if(USE_AEC) target_link_libraries(wgrib2_exe PRIVATE ${LIBAEC_LIBRARIES}) endif() -if(USE_JASPER) +if(USE_JASPER OR USE_OPENJPEG) target_link_libraries(obj_lib PUBLIC g2c::g2c) target_link_libraries(wgrib2_exe PRIVATE g2c::g2c) endif() -if(USE_OPENJPEG) - include_directories(${OPENJPEG_INCLUDE_DIRS}) - target_link_libraries(wgrib2_exe PRIVATE ${OPENJPEG_LIBRARIES}) -endif() - target_link_libraries(wgrib2_exe PRIVATE obj_lib) # target_link_libraries(wgrib2_exe PRIVATE wgrib2_lib) diff --git a/wgrib2/jpeg_pk.c b/wgrib2/jpeg_pk.c index cc4661c..d2a6ec8 100644 --- a/wgrib2/jpeg_pk.c +++ b/wgrib2/jpeg_pk.c @@ -7,14 +7,11 @@ #include "wgrib2.h" #include "fnlist.h" -#ifdef USE_JASPER - #include "grib2.h" -#endif - /* 10/2024 Public Domain Wesley Ebisuzaki */ #if defined USE_JASPER || defined USE_OPENJPEG + #include "grib2.h" /* * writes out jpeg2000 compressed grib message */ @@ -31,9 +28,7 @@ int jpeg2000_grib_out(unsigned char **sec, float *data, unsigned int ndata, int i, k, nbits, nbytes; int ltype, ratio, retry; char *outjpc; -#ifdef USE_JASPER unsigned char *cdata, *p; -#endif /* required passed sections */ sec0 = sec[0]; @@ -124,7 +119,6 @@ int jpeg2000_grib_out(unsigned char **sec, float *data, unsigned int ndata, nbytes = (nbits + 7) / 8; if (nbytes > 4) fatal_error_i("jpeg2000_grib_out number of bytes is %d > 4", nbytes); -#ifdef USE_JASPER /* floats -> integers -> bytes */ cdata = (unsigned char *) malloc(nbytes * (size_t) n_defined); @@ -156,9 +150,6 @@ int jpeg2000_grib_out(unsigned char **sec, float *data, unsigned int ndata, } } -// jas_init(); -#endif - ltype = 0; ratio = 1; retry = 0; @@ -166,7 +157,6 @@ int jpeg2000_grib_out(unsigned char **sec, float *data, unsigned int ndata, jpclen = 4*n_defined+200; outjpc = (char *) malloc(jpclen); -#ifdef USE_JASPER i = g2c_enc_jpeg2000(cdata,ix,iy,nbits,ltype,ratio,retry,outjpc,jpclen); // we try to catch following error: "error: too few guard bits (need at least x)" if (i == -3) { @@ -174,10 +164,6 @@ int jpeg2000_grib_out(unsigned char **sec, float *data, unsigned int ndata, i = g2c_enc_jpeg2000(cdata,ix,iy,nbits,ltype,ratio,retry,outjpc,jpclen); } free(cdata); -#endif -#ifdef USE_OPENJPEG - i = enc_jpeg2000_clone_float(data,ix,iy,nbits,ltype,ratio,retry,outjpc,jpclen); -#endif if (i <= 0) fatal_error_i("enc_jpeg error %d", i); } diff --git a/wgrib2/unpk.c b/wgrib2/unpk.c index eae0710..936a62a 100644 --- a/wgrib2/unpk.c +++ b/wgrib2/unpk.c @@ -12,7 +12,7 @@ #include "wgrib2.h" #include "grb2.h" -#ifdef USE_JASPER +#if defined USE_JASPER || defined USE_OPENJPEG #include "grib2.h" #endif @@ -193,7 +193,6 @@ int unpk_grib(unsigned char **sec, float *data) { // decode jpeg2000 -#ifdef USE_JASPER ifld = (int *) malloc(ndata * sizeof(int)); if (ifld == 0) fatal_error("unpk: memory allocation error",""); err = g2c_dec_jpeg2000((char *) sec[7]+5, (size_t) GB2_Sec7_size(sec)-5, ifld); @@ -214,32 +213,6 @@ int unpk_grib(unsigned char **sec, float *data) { } free(ifld); return 0; -#endif -#ifdef USE_OPENJPEG - ifld = (int *) malloc(ndata * sizeof(int)); - if (ifld == 0) fatal_error("unpk: memory allocation error",""); - err = dec_jpeg2000_clone((char *) sec[7]+5, (int) GB2_Sec7_size(sec)-5, ifld); - if (err != 0) fatal_error_i("dec_jpeg2000, error %d",err); - - if (bitmap_flag == 255) { -#pragma omp parallel for private(ii) - for (ii = 0; ii < ndata; ii++) { - data[ii] = ((ifld[ii]*bin_scale)+reference)*dec_scale; - } - } - else if (bitmap_flag == 0 || bitmap_flag == 254) { - mask_pointer = sec[6] + 6; - mask = 0; - kk = 0; - for (ii = 0; ii < ndata; ii++) { - if ((ii & 7) == 0) mask = *mask_pointer++; - data[ii] = (mask & 128) ? ((ifld[kk++]*bin_scale)+reference)*dec_scale : UNDEFINED; - mask <<= 1; - } - } - free(ifld); - return 0; -#endif } #endif diff --git a/wgrib2/wgrib2.h b/wgrib2/wgrib2.h index 95005b1..7deb9d0 100644 --- a/wgrib2/wgrib2.h +++ b/wgrib2/wgrib2.h @@ -503,11 +503,6 @@ int scaling(unsigned char **sec, double *base, int *decimal, int *binary, int *n unsigned char *mk_bms(float *data, unsigned int *ndata); int dec_png_clone(unsigned char *pngbuf,int *width,int *height, unsigned char *cout, int *grib2_bit_depth, unsigned int ndata); -#ifdef USE_OPENJPEG -int dec_jpeg2000_clone(char *injpc, int bufsize, int *outfld); -int enc_jpeg2000_clone_float(float *data, int width, int height, int nbits, - int ltype, int ratio, int retry, char *outjpc, int jpclen); -#endif int ieee_grib_out(unsigned char **sec, float *data, unsigned int ndata, struct seq_file *out); int jpeg_grib_out(unsigned char **sec, float *data, unsigned int ndata, int nx, int ny, int use_scale, int dec_scale, int bin_scale, FILE *out);