Showing posts with label Guide. Show all posts
Showing posts with label Guide. Show all posts

Thursday, April 30, 2026

Research Note #33 - Instalasi WRF-Chem 4.7.1 + KPP di HPC BRIN (Mahameru)

Kinetic PreProcessor (KPP) adalah tool untuk menerjemahkan reaksi kimia kompleks ke dalam kode program (misal Fortran atau C) dan umumnya digunakan pada pemodelan kimia atmosfer, termasuk WRF-Chem. Dengan sekian banyaknya pilihan opsi mekanisme kimia yang dapat digunakan pada WRF-Chem, KPP membantu developer untuk mengaplikasikan skema kimia kompleks yang mereka bangun tanpa harus 'mengganggu' kode program WRF-Chem itu sendiri. Beberapa mekanisme kimia yang menerapkan reaksi kimia kompleks, misalnya untuk simulasi fase gas pada secondary aerosol, antara lain: MOZART, MOZCART, RADM, MOSAIC dll. Dengan kata lain, bila ingin menggunakan mekanisme-mekanisme tersebut untuk simulasi, WRF-Chem yang digunakan wajib hukumnya dikompilasi dengan dukungan KPP.

Tulisan ini berasumsi bahwa environment yang digunakan adalah HPC BRIN, dengan bash shell, gcc 12.2.0 dan pembaca telah mengetahui dasar-dasar kompilasi WRF-Chem ver. 4.7.1 (misal, sudah memiliki library-library yang dibutuhkan, seperti NetCDF, MPICH dll). Bila belum, silakan membaca tulisan berikut: https://sketsa-langit.blogspot.com/2025/10/research-note-29-instalasi-wrf-chem-di.html.

Berikut langkah-langkah kompilasi WRF-Chem dengan KPP pada HPC BRIN. 

Temukan path library flex di sistem. Library flex ini akan digunakan untuk kompilasi KPP:

module load gcc flex
module show flex

------------------------------------------------------------------------------------------------------------------------------------------------------------
   /mgpfs/shared/apps/mod/library/flex/2.6.4:
------------------------------------------------------------------------------------------------------------------------------------------------------------
load("gcc/12.2.0")
whatis("flex 2.6.4 - The fast lexical analyzer generator")
setenv("FLEXHOME","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0")
prepend_path("PATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/bin")
prepend_path("CPATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/include")
prepend_path("INCLUDE_PATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/include")
prepend_path("INCLUDE_LIBRARY_PATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/include")
prepend_path("LIBRARY_PATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/lib")
prepend_path("LD_LIBRARY_PATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/lib")
prepend_path("INFOPATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/share/info")
prepend_path("MANPATH","/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/share/man")


Deklarasikan WRF_CHEM, WRF_KPP dan FLEX_LIB_DIR di environment bash:

export WRF_CHEM=1
export WRF_KPP=1
export FLEX_LIB_DIR=/mgpfs/shared/apps/app/flex/2.6.4/GCC/12.2.0/lib

Masuk ke interactive-node HPC karena proses kompilasi ini akan memakan memori sistem yang besar. Proses kompilasi pada login-node hampir bisa dipastikan akan gagal (akan di-kill oleh sistem).

srun --partition=interactive --pty /bin/bash

Setelah masuk ke interactive-node, masuk ke direktori WRF dan jalankan konfigurasi kompilasi wrf.

./clean -aa
./configure

Pilih 34 (dmpar) untuk GCC compiler. Untuk nesting, pilih 1 (basic).

Pastikan proses konfigurasi berjalan lancar, tanpa ada pesan masalah pada compiler. Bila ada masalah, bereskan dulu masalah compiler, lalu lakukan konfigurasi ulang. Bila tak ada masalah, buka dan edit file configure.wrf.

Hilangkan 'time' pada deklarasi fortran compile 'FC':

FC = time $(DM_FC)  menjadi  FC = $(DM_FC)

Simpan file dan keluar dari configure.wrf. Selanjutnya, pada direktori WRF, buka dan edit file scan.h dan scan.y yang terdapat pada direktori chem/KPP/kpp/kpp-2.1/src/

Pada file scan.h (dan scan.y), temukan kode baris void yyerror( char * str ) ; pada baris ke-101 (390 pada scan.y), dan ubah menjadi void yyerror( const char * str ) ;. Simpan perubahan dan keluar dari kedua file tersebut.

Buka file compile_wkc pada direktori chem/KPP dan ubahlah baris kode pada baris 121:

 $WKC_HOME/util/wkc/tuv_kpp FIRST ../../inc/

menjadi:

 $WKC_HOME/util/wkc/tuv_kpp FIRST ../../../../inc/

Simpan perubahan dan keluar dari file. Sekarang anda bisa melakukan kompilasi wrf.

./compile -j 2 em_real >& compile.log

Proses kompilasi akan memakan waktu kurang lebih 30 menit - 1 jam. Pastikan tidak ada Error yang tercatat pada file compile.log dan file-file exe berhasil dibuat.

--->                  Executables successfully built                  <---

-rwxr-xr-x 1 ardh003 researcher 63915712 Apr 30 10:35 main/ndown.exe
-rwxr-xr-x 1 ardh003 researcher 64055224 Apr 30 10:35 main/real.exe
-rwxr-xr-x 1 ardh003 researcher 57765544 Apr 30 10:35 main/tc.exe
-rwxr-xr-x 1 ardh003 researcher 85490080 Apr 30 10:29 main/wrf.exe

==========================================================================

Tuesday, January 7, 2020

Research Note #26 - Filtering Data and Making Standard Deviation using Google Earth Engine

So, there are two main objectives of this script: display data based on a certain threshold value (in this case, reflectance < 1000) and make a standard deviation from the results. The Data used in this example was Sentinel-2 MSI Level 2A, in the period between November 1 - 15, 2019. Cloud masking was utilized at the beginning of the script to choose granules which were clear from clouds.

// Create a geometry representing the analysis region.
var daerah = ee.Geometry.Rectangle([72.611536, 28.354144, 78.807625, 32.630466]); 

/**
 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
 */
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0)

 // Choose pixels with reflectance < 1000
      .and(image.lt(1000))
      );

  return image.updateMask(mask).divide(10000);
}

// Map the function over the analysis region and period
// Load Sentinel-2 TOA reflectance data.
var datasentinel = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2019-11-01', '2019-11-15')
                  .filterBounds(daerah)
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
                  .map(maskS2clouds)
                  ;

// Get the standard Deviation.
var hasil = datasentinel.reduce(ee.Reducer.stdDev());

// Define the plot parameter, use the standard deviation of Band 4 only  
var stdevVis = {
  min: 0,
  max: 0.005,
  bands: ['B4_stdDev'],
  palette: ['0000FF', '00FFFF', '00FF00', 'FFFF00', 'FF0000']
};

// Add the plot layer on the map
Map.addLayer(hasil, stdevVis, 'Std Deviation');
Map.setCenter(75.7095805, 30.492305, 14);

And the result will be like this:


You may seen some pixels with very high standard deviation values (shown in red, cyan or anything else other than blue). To 'clean-up' these pixels, we can add another filter to the standard deviation results. For example to show the values no higher than 0.000001:

// Get the standard Deviation.
var hasil = datasentinel.reduce(ee.Reducer.stdDev());
var hi_stddev = hasil.lt(0.000001);
var hasil = hasil.updateMask(hi_stddev);

The result will be like this:


Finally, we can overlay the base Google Map using the result by choosing the Satellite map (button on the right corner of the map).


Wednesday, November 6, 2019

Research Note #25 - Reading a Text File Line-by-Line with Fortran

Again, this is actually a very simple task which I usually deal with ... and forget, most of the time! That's why this post exists. The following is a basic Fortran code to enable you reading the contents of a text file, line-by-line. 

As an example, let's make a text file (named 'list.txt') containing a list of files with their complete paths on Linux:

$ ls ../gcom-c/aerosol/0524/pl/* > list.txt
$ cat list.txt

../gcom-c/aerosol/0524/pl/GC1SG1_20190901D01D_T0524_L2SG_ARPLK_1001.h5
../gcom-c/aerosol/0524/pl/GC1SG1_20190902D01D_T0524_L2SG_ARPLK_1001.h5
../gcom-c/aerosol/0524/pl/GC1SG1_20190903D01D_T0524_L2SG_ARPLK_1001.h5
../gcom-c/aerosol/0524/pl/GC1SG1_20190904D01D_T0524_L2SG_ARPLK_1001.h5

Now, this is the Fortran code to read file 'list.txt':

PROGRAM READTEXT
IMPLICIT NONE
CHARACTER(LEN=8) :: listfile
CHARACTER(LEN=70) :: filecontents
INTEGER :: io

listfile="list.txt"

OPEN(10, FILE=listfile, FORM="FORMATTED", STATUS="OLD",&
        ACTION="READ")

DO
   READ(10,"(A70)",IOSTAT=io) filecontents
   IF (io/=0) EXIT
   PRINT *, filecontents
END DO
CLOSE(10)

END PROGRAM READTEXT

How it works?

The program will open file 'list.txt', then read the first line of the file and put the (string) contents into variable 'filecontents'. It will then print the contents of variable onto the screen. Since there's a DO.. END DO statement, this process will repeat, with the next line being read, replacing the contents of variable 'filecontents'. This looping process will end once there are no more lines found in the file, invoking IOSTAT to a value other than 0 (0 means no I/O error occurred, other values mean there are I/O errors), then program will exit. That's all!

Some important notices:
  • The absence of 'DO ... END DO' will make the program only reads the first line of the file.
  • The absence of 'IF (io/=0) EXIT' will make the program runs endlessly, with the last line of the file kept being showed on the screen.
  • If the output format is not determined (for example, FMT=* instead of A70), the program will not correctly show the file's contents. The (character) length of this format should be same or more than the one at variable declaration. Why 70? Because in this case, the full path of file list (in one line) has 70 characters. 

Tuesday, November 5, 2019

Research Note #24 - Showing GCOM-C/SLGI Dataset Header/Metadata

One of the most important things to do while working with binary satellite data is checking the header/metadata of the dataset. By doing so, you could know the dimensions, parameters, variables and attributes of the data which will be needed for analysis (with program, script, etc.). These are three methods to show the GCOM-C/SLGI dataset header and attributes. I made this post because I always forget the quickest way to do it and ended up wasting too much time just for knowing some attributes of the data.

1. Using HDF View
This is definitely the quickest way and the most convenient way to check the headers and attributes of HDF data file. It works perfectly with MODIS as well as GCOM-C/SLGI. Just open the HDF file, and browse into the dataset directories. Simple!


2. Using h5dump
Works in similar fashion with ncdump. Just type the command and you're good to go. Not so convenient for non-Linux user.

Example:
h5dump -H <filename> --> Show header contents of a datafile
h5dump -a /Image_data/LST/Slope <filename> --> Show the contents of attribute 'Slope' (scaling factor) of dataset 'LST' of a datafile



3. Using SGLI Tool
This is by far the most not-convenient way to see the headers. Not only it's slow and taking so much of system resources, it also shows the header only (no attributes). To see the header, open a HDF file and go to Menu->View->Meta Data


Friday, June 14, 2019

Research Note #22 - Reading GCOM-C 250m-Res HDF5 Data with Fortran

There were not so many references about 'simple' ways to open and read HDF5 data file with Fortran as well as compiling the codes. I said 'simple', because there are actually manuals and tutorials about that purpose, however, most of them were too complicated and refer to other sub-references, thus blah .. blah ... it takes too much time, especially if you just simply want to open, read and compile a HDF dataset. Here, I posted a very basic way to access HDF5 data, using very minimal Fortran code. Before starting, here's the convention:
  • I used Linux OS. 
  • I used Fortran 90 for programming.
  • HDF5 (ver 1.8.17) libraries has been already installed in my system as module.
  • I used JAXA's GCOM-C NDVI Monthly statistics (Level-2 data) with 250m spatial resolution with Sinusoidal/EQA projection. This data contains 4800x4800 pixels. For exemplary purpose, I renamed it to "ndvi.h5".
So, the following is a very basic example of Fortran code to open and read HDF5 data:

PROGRAM HDF5test

   USE HDF5
   IMPLICIT NONE

   INTEGER :: hdferr, i, j
   INTEGER(HID_T) :: fileid, dset
   CHARACTER(LEN=7), PARAMETER :: filename = "ndvi.h5"
   CHARACTER(LEN=19), PARAMETER :: dataset = "Image_data/NDVI_AVE"
   INTEGER, PARAMETER :: xdim = 4800
   INTEGER, PARAMETER :: ydim = 4800
   INTEGER, DIMENSION(1:xdim, 1:ydim) :: ndvi_ave
   INTEGER(HSIZE_T), DIMENSION(1:2) :: dims = (/xdim, ydim/)
   
   CALL h5open_f(hdferr)
   CALL h5fopen_f(filename, H5F_ACC_RDONLY_F, fileid, hdferr)
   CALL h5dopen_f(fileid, dataset, dset, hdferr)
   CALL h5dread_f(dset, H5T_NATIVE_INTEGER, ndvi_ave, dims, hdferr)

    DO j = 1, ydim
      DO i = 1, xdim
         print *, ndvi_ave(i,j)
      ENDDO
   ENDDO

  CALL h5dclose_f(dset, hdferr)
  CALL h5fclose_f(fileid, hdferr)
  CALL h5close_f(hdferr)

END PROGRAM HDFtest

The most important lines are:
  • CALL h5open_f(hdferr)This function initializes HDF5 library for Fortran uses. Returns 0 (to hdferr variable) if it's successful, and -1 if it's failed.
  • CALL h5fopen_f(filename, H5F_ACC_RDONLY_F, fileid, hdferr). This function opens an existing HDF5 file. In this example, I just want to read it, hence H5F_ACC_RDONLY_F was used as argument. This function will return integers for file identifier and status to fileid and hdferr variables, respectively.
  • CALL h5dopen_f(fileid, dataset, dset, hdferr). This function opens an existing dataset in the opened file. Take notice that it needs file identifier (from h5fopen_f), dataset name, dataset identifier and status (as previous functions).
  • CALL h5dread_f(dset, H5T_NATIVE_INTEGER, ndvi_ave, dims, hdferr). This function reads raw data from dataset of the file, into a buffer. The buffer means a space in the computer memory, this could be a variable or array. Take notice that it need dataset identifier (from h5dopen_f), memory data type (Native integer), buffer, dimension (to store buffer dimension) and as always, status (hdferr).
To make it simple, the program will firstly initialize HDF5 library, opens an existing HDF5 datafile, opens a dataset from that file (a file could consist of many datasets), read the raw data from the dataset, put the data into an array buffer, then prints the contents of the buffer into the screen. Finally, it closes the dataset, closes the file and ultimately deactivates HDF5 library (flush and cleans the memory). That's all.

Another important thing is variable declaration. HID_T and HSIZE_T are parameters for predefined datatype used by HDF5 library. So, don't be confused with them (for details, just read: https://support.hdfgroup.org/HDF5/doc/fortran/index.html).

Finally, save and give the codes a name (for example: test.f90). To compile the code, just use this command on (bash) shell:

$ h5fc -o test.exe test.f90

It's just similar with a normal Fortran compiler command. If you don't specify a name for the output, a file named 'a.out' will be generated by the compiler.

Monday, March 18, 2019

Gunpla #46 - Exceed Gundam Head Vol.1 Review


I am not a fan of gashapon toys, but this one is an exception. Exceed have been successful with its previously released Zaku head (I even have two of them on my desk), and this year, they made it again. This time though, it's not Zaku, but Gundam, the protagonist of the franchise. The first volume of Gundam head have been released in January 2019 in Japan, and consists of three kinds of head: 'granddaddy' RX-78-2, FA-78-1 Full Armor Gundam, and RX-78-3 G3, with price of 500 Yen for each head. It became a big hit when it was released, and the toys were quickly sold out. Now, it is so rare, you won't likely find it, even in Akihabara except at very few hobby stores or auction sites.

Unopened head in their 'helmet'
Construction wise, it is pretty simple and not so different with the Zaku head. Each had was encased in a kind 'helmet' along with the manual. The manual itself is in Japanese, but quite self-explanatory and easy to understand.


The manual
The head will be revealed after opening the helmet case, where v-fin, forehead, and chin parts are stuffed inside it.


The main parts of the head

By opening the side vents hatch (which is the main gimmick of this kit), we can pull the forehead and back sensor out. The v-fin could be constructed and attached on the forehead, as well as the chin parts. Take caution when opening the plastic bag of v-fin parts since they are quite fragile.



Last step, connect the head to the neck which is made by using the base of helmet. The color of the neck might be inaccurate but the head looks totally cool!





As mentioned above, the only gimmick of this kit is the side vent hatch which could be opened. Other than that, nothing special could be done with it. Of course, there are possibilities for customization eg, installing LED inside the head etc. Nevertheless, for a 500 Yen gashapon toy, this kit is highly detailed, with lots of panel lines over it. As previously released Zaku head, each Gundam head has a marking on it. Panel-lining the head should be easy using Tamiya Panel Lines Accent (TPLA) or even Gundam Marker. Anyway, the ones who use TPLA should be aware because its excessive use could melt the plastics as well as the paint (on forehead or chin).

The verdict, this kit is a nice addition for those who love gashapon toys, and of course, Gundam. I'm truly looking forward to see the Vol.2. I wonder how Exceed will make Gundam head from different universe such as Wing or Seed series :-)

Wednesday, March 13, 2019

Research Note #21 - Compiling Fortran Script for NetCDF Data Processing

NetCDF data is become more and more important for my research, thus it's necessary to work with it with my own program, in Fortran (F90). The compilation anyway, a little bit tricky and slightly different with ordinary Fortran compilation. Here are the simple steps to compile it, using Intel Fortran compiler:

1. Make sure NetCDF module has been installed and declared in the system path.

The path for NetCDF module is : $NETCDF/include

If the path has not yet existed, make a soft link of the module file to current directory:

ln -sf $NETCDF/include/netcdf.mod

2. Compile the Fortran code to make an object file

Let's say the code file name is 'test.f90', then execute:

$ ifort -c test.f90 -I$NETCDF/include

Or, if the path of NetCDF module has existed, just simply:

$ ifort -c test.f90

Make sure no problems occur.

3. Finally, link the object file to an executable file:

$ ifort -o test.exe test.o -I$NETCDF/include -L$NETCDF/lib -lnetcdff -lnetcdf

Same as step 2, if the module path has existed:

$ ifort -o test.exe test.o -L$NETCDF/lib -lnetcdff -lnetcdf

If everything's OK, then an exe file will be created in the current directory. The most important thing, don forget to include '-lnetcdff', because since release 4.1.3, the Fortran library is no longer combined with C library. One hint is by checking if there are file named 'libnetcdff' in the $NETCDF/lib directory. If they are there, the argument '-lnetcdff' should be added in the compile command. 

Monday, March 4, 2019

Gunpla #42 - HGUC Jegan Type-D (Escort Type) Review


I love Jegan. It's definitely one of the best, and probably the most diverse grunts in Gundam universe, alongside Zaku and GM series. Anyway, the Jegan I would like to talk about this time is the most recent variant which made cameo in MS Gundam Narrative (NT) OVA, the Jegan Type-D (or D-type?) Escort type (let's call it Escort Jegan from now). The kit was finally released as a p-bandai exclusive in January 2019, two months after the movie screening in Japan. As cool as it might look like, this mobile suit ironically didn't have much action time after got blasted by the (outdated) Dijeh in the movie. But who cares? It still the Jegan, and Jegan is always cool!!

Upper Torso
It may look obvious that HGUC Escort Jegan is basically a retooled version of HGUC Jegan ECOAS type which I've reviewed in the past, thus, I would not talk much about stuffs such as articulation because they are basically the same kit. Of course, there are new stuffs (and sadly, missing stuffs) with this kit.

With everything it brought with
To start, let's talk about the new stuffs. This Jegan gets a brand new COOL head which has never been seen in any previous Jegans. It looks very similar with Jesta, or rather Gernsback from Full Metal Panic. Another new stuffs is the new COOL chest armor. In contrast with Jegan ECOAS chest armor which was quite 'meh' IMHO, the new armor has more details with the 'rib-bones' patterns. This new armor looks like a kevlar vest and it makes Escort Jegan has more robust chest than any Jegans. Finally, this kit comes with a brand new COOL short-machine gun. These COOL new stuffs make this kit looks more militaristic than ever.


As with Jegan ECOAS type, Jegan Escort also gets Jegan beam rifle, a shield, a bazooka, 3 hands (2 standards, 1 right trigger), 2 beam saber effects (long and short) with additions of extra spare parts to make other Jegan heads (normal, Type-D and ECOAS), as well as ECOAS chest armor, waists, crotches and a 'runner handler'. With all new stuffs, this Jegan is basically an upgraded version of Jegan ECOAS type.




Now, let's talk about the bad stuff about this Jegan. Firstly, no marking stickers as the ECOAS version. I don't know why, but the latest HGUC kits I bought (Sinanju Stein, Gustav Karl and this Jegan) don't include marking stickers at all. That's pretty lame. Another bad thing is (as always) foil sticker for part separation, and there are lots of them for the chest armor, and waist section of the kit. Eventually, I chose for not using any foils and just painted the part with grey color. For the lacks of marking, I finally used custom water slide decals to add more details with the kit. The articulation of Jegan Escort is definitely same with ECOAS type. Good thing is the (left) hand could grab the gun handle for making a natural pose as seen in the movie.


The verdict, this Jegan is a nice addition to HGUC line, especially for Jegan. It's totally cool, comes with new parts, and with price lower than 2000 yen, it's well worth the money. Should you buy it? If you're a Jegan's fan, you should not miss it.

-----------------

RGM-89D-ESC Jegan Type-D (Escort Type)

Pros:
  • New parts for head, chest armor and gun
  • Comes with many extra parts (as Jegan ECOAS type)
Cons:
  • No marking stickers
  • Lots of foils. Paints needed for better end results.

Thursday, February 7, 2019

Research Note #20 - Preparing Emission Data with PREP-CHEM-SRC and CONVERT_EMISS for WRF-Chem

It took quite a while before I could post this, mainly because everything becomes more and more complicated. The deeper I dig into WRF-Chem, the more complex the problems are. Successfully compiling PREP_CHEM_SRC didn't make things easier as more questions keep coming into my mind about how the system actually works, thanks to the oblivious manual. Well, at least the emission data could be prepared and seems to be simulated in the model now.

Here are the steps to prepare emission data for WRF-Chem using PREP-CHEM-SRC and CONVERT_EMISS utilities.

1. Download and Link the Emission Data
Download the latest emission data from this link. It was in the same directory with PREP-CHEM-SRC source codes. Extract the data inside any desired directory and it is recommended to make a soft link to the location to avoid long-directory listing in the input namelist file which will be explained soon. Locate the softlink in the same directory with the PREP-CHEM-SRC utility (and its namelist input file), and name it 'datain' (the name is actually up to you). 

$ mkdir wrf/EMISSION
$ cd wrf/EMISSION
$ tar -xzvf global_emissions_v3_24aug2015.tar.gz
$ cd PREP-CHEM-SRC-1.5/bin
$ ln -sf ../../Global_emissions_v3/ datain

The directory should similar like this (after executing ls command):

[c24223@ofp05 bin]$ ls -alh
total 3.9M
drwxr-s--- 4 c24223 gi55 4.0K Feb  7 19:06 .
drwxr-s--- 8 c24223 gi55 4.0K Aug 25  2015 ..
drwxr-s--- 3 c24223 gi55  12K Jan 31 20:24 build
lrwxrwxrwx 1 c24223 gi55   26 Jan 31 20:24 datain -> ../../Global_emissions_v3/
-rw-r----- 1 c24223 gi55 6.0K Feb  6 20:38 prep_chem_sources.inp
-rwxr-x--- 1 c24223 gi55 3.9M Jan 31 20:22 prep_chem_sources_RADM_WRF_FIM_.exe
drwxr-s--- 6 c24223 gi55 4.0K Apr 30  2015 .svn

2. Configure using Namelist Input File
This step is really important to determine what kind of emission data, map projections, grid configuration, output format etc. used by the utility. These configurations are stored inside namelist input file: prep_chem_sources.inp

Ideally, we could run the utility without any changes to namelist file, but unfortunately, it is not the case this time. The main contents of the file contain paths of emission data from step #1, and it seems the developers didn't update it according the latest path in the data. Therefore, you MUST re-check and confirm the path inside the namelist file by your own, otherwise you will get errors while executing the utility.

A sample of 'working' configuration for my case could be download here

Some important points are before using the namelist file above:
  • The emission dataset used this post is published does not contain MEGAN emission data.
  • I didn't use bbem/bbem plumerise and volcanic emission data.
  • The map projection used in my simulation is mercator/ii. 
  • For more detailed information about the configurations in the namelist file, read this guide (it is much better than the original emission guide of WRF-Chem).
3. Execute prep_chem_src utility
This step is quite straight forward, except that some nasty things could happen during the process. 

$ ./prep_chem_sources_RADM_WRF_FIM_.exe

You could just sit down nicely until the utility finishes preparing the emission data. Anyway, if you find that the utility crashes midway with some scary segmentation fault messages, you should check the compilation of it. One possible cause is, the compiler option used while compiling the utility. For more detail, check the previous post about installing prep_chem_src utility.

Another possible reason is the program overloads the memory because of compilation or grid settings in the namelist file, causing crash. If it's the case, execute 'ulimit -s unlimited' and try again.

Anyway, if the program successfully works, you will see files similar like the following in the directory:

-rw-r----- 1 c24223 gi55  27M Feb  7 20:03 matrixfire-T-2018-01-01-000000-g1-ab.bin
-rw-r----- 1 c24223 gi55  35M Feb  7 20:03 matrixfire-T-2018-01-01-000000-g1-bb.bin
-rw-r----- 1 c24223 gi55 6.5K Feb  7 20:02 matrixfire-T-2018-01-01-000000-g1.ctl
-rw-r----- 1 c24223 gi55 168M Feb  7 20:03 matrixfire-T-2018-01-01-000000-g1-gocartBG.bin
-rw-r----- 1 c24223 gi55  70M Feb  7 20:03 matrixfire-T-2018-01-01-000000-g1.gra
-rw-r----- 1 c24223 gi55  71M Feb  7 20:03 matrixfire-T-2018-01-01-000000-g1.vfm

So, here are some explanations for the files:
  • g1-ab.bin file is anthropogenic emission data (+ biogenic emission data, if you use it) for WRF-Chem
  • g1-bb.bin file is biomass burning (+ plume rise, if you use it) emission data for WRF-Chem
  • g1-gocartBG.bin is GOCART background emission data for WRF-Chem
  • g1.gra and g1.vfm are binary files in GrADS format to visualize the emission data
  • g1.ctl is GrADS control/descriptor file
You can now check the emission data using GrADS (don't forget to add 'options big_endian' into the descriptor file).

 --- To be continued --- 


Monday, December 24, 2018

Research Note #19 - Installing prep_chem_sources Utility for WRF-Chem

This has been probably one of the trickiest installations I've ever experienced, thanks to the lack of necessary library, limited references and bug in the source code. 

In order to install (or rather, compile) prep_chem_sources tool (I'll call it PCS from now on), HDF5, NetCDF and ZLIB libraries are necessary. Since NetCDF and ZLIB have been already available from previous WRF installation, one should only care about HDF5. Be advised though, HDF5 library of Oakforest super computer module was not compatible with the installation script. Thus, newly fresh HDF5 library is necessary (latest version might be compatible, thus keep checking updates of the super computer).

1. HDF5 Library Installation
Download the latest version from HDF group website. For this case, the version used is HDF5-1.10.4. Extract the file in a directory and execute installation script. Since PCS needs ZLIB and Fortran library, do not forget to mention them during the configuration.

$ ./configure --prefix=/work/gi55/c24223/libs/hdf5 --enable-fortran --enable-cxx --with-zlib=/work/gi55/c24223/libs/grib2
$ ./make
$ ./make check
$ ./make install

Make sure no errors occurred during the installation. After installing HDF5, put its path and LD_LIBRARY_PATH in the .bash_profile and re-load the file.

export HDF5=$PACSLIB/hdf5
export PATH=$HDF5/bin:$PATH

export LD_LIBRARY_PATH= ... :/work/gi55/c24223/libs/hdf5/lib

2. Download PCS tool
Download the tool from this ftp site directory: ftp://aftp.fsl.noaa.gov/divisions/taq/global_emissions

By the time this note was written, the latest version of PCS tool is ver. 1.5. Extract the tools inside any desired directory. Once extracted, there will a directory PREP-CHEM-SRC-1.5 with several sub-directories such as: /bin, /src, /extra etc.

3. Edit  convert_edgar_to_RELACS_REAC.f90 Script
This step should be done, otherwise PCS installation will fail with following messages:

convert_edgar_to_RELACS_REAC.f90(17): error #6405: The same named entity from different modules and/or program units cannot be referenced. [CO]
,CO &
-----------------------------^
convert_edgar_to_RELACS_REAC.f90(20): error #6405: The same named entity from different modules and/or program units cannot be referenced. [CH4]
,CH4 &
-----------------------------^
convert_edgar_to_RELACS_REAC.f90(21): error #6405: The same named entity from different modules and/or program units cannot be referenced. [SO2]
,SO2 &
-----------------------------^
compilation aborted for convert_edgar_to_RELACS_REAC.f90 (code 1)

make: *** [convert_edgar_to_RELACS_REAC.o] Error 1

The cause of this error is ironically simple: the absence of remark symbol ('!') in front of the 9th line of script convert_edgar_to_RELACS_REAC.f90 in the /src sub-directory:

8 subroutine convert_edgar_to_relacs_reac(isp,iespc,ident,spc_name_dummy)  !kml
9 use chem1_list
10 !use chem1_list, only : alke, bio,ora2,aro,ket,alka,ald

Thus, edit the script by adding '!' symbol in front of the said line using vi or other text editor.

4. Edit include.mk.intel.wrf Option Script and Compile PCS
This step is briefly explained on emission guide of WRF-Chem, however no further explanation about the script options available since it will strictly depend on the machine/system architecture. Anyway, one useful hint is: use the same options with WRF-Chem installation used, which are stored inside file configure.wrf inside /WRFV3 sub-directory.

Go to /bin/build sub-directory of PCS, and edit include.mk.intel.wrf option script (since the compiler used is intel compiler). Change these settings as follows:

update 2019/01/31:
Changed F_OPTS because the "longer" version caused crash during execution of utility for GOCART background data.

NETCDF=/work/gi55/c24223/libs/netcdf
HDF5=/work/gi55/c24223/libs/hdf5
HDF5_LIB=-L$(HDF5)/lib -lhdf5hl_fortran -lhdf5_fortran -lhdf5_hl -lhdf5 -L/work/gi55/c24223/libs/grib2/lib -lz -ldl

F_COMP=mpif90 -f90=ifort
C_COMP=mpicc -cc=icc -DMPI2_SUPPORT
LOADER=$(F_COMP)
C_LOADER=$(C_COMP) -DFSEEKO64_OK
F_OPTS=-fpp -D$(CHEM) -O3 -convert big_endian
C_OPTS= -O2

LOADER_OPTS= -O2

Save the script and compile PCS (for GOCART chem option):

$ make OPT=intel.wrf CHEM=RADM_WRF_FIM

If everything's going well, an executable prep_chem_sources_RADM_WRF_FIM_.exe will be created in /bin sub-directory. Check with ldd command to make sure there are no missing shared library links of the executable.

$ ldd prep_chem_sources_RADM_WRF_FIM_.exe
        linux-vdso.so.1 =>  (0x00007ffc35bbe000)
        libnetcdff.so.6 => /work/gi55/c24223/libs/netcdf/lib/libnetcdff.so.6 (0x00007ff8b2825000)
        libnetcdf.so.11 => /work/gi55/c24223/libs/netcdf/lib/libnetcdf.so.11 (0x00007ff8b23cf000)
        libhdf5hl_fortran.so.100 => /work/gi55/c24223/libs/hdf5/lib/libhdf5hl_fortran.so.100 (0x00007ff8b21a8000)
        libhdf5_fortran.so.100 => /work/gi55/c24223/libs/hdf5/lib/libhdf5_fortran.so.100 (0x00007ff8b1f45000)
        libhdf5_hl.so.100 => /work/gi55/c24223/libs/hdf5/lib/libhdf5_hl.so.100 (0x00007ff8b1d1c000)
        libhdf5.so.103 => /work/gi55/c24223/libs/hdf5/lib/libhdf5.so.103 (0x00007ff8b1679000)
        libz.so.1 => /work/gi55/c24223/libs/grib2/lib/libz.so.1 (0x00007ff8b145a000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007ff8b1237000)
        libmpifort.so.12 => /home/opt/local/cores/intel/impi/2018.1.163/intel64/lib/libmpifort.so.12 (0x00007ff8b0e8d000)
        libmpi.so.12 => /home/opt/local/cores/intel/impi/2018.1.163/intel64/lib/libmpi.so.12 (0x00007ff8b0208000)
        librt.so.1 => /lib64/librt.so.1 (0x00007ff8b0000000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff8afde3000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff8afae1000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff8af71e000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff8af507000)
        libhdf5_hl.so.10 => /work/opt/local/apps/intel/2017.1.132/hdf5/1.8.17/lib/libhdf5_hl.so.10 (0x00007ff8af2db000)
        libhdf5.so.10 => /work/opt/local/apps/intel/2017.1.132/hdf5/1.8.17/lib/libhdf5.so.10 (0x00007ff8aebb3000)
        libifport.so.5 => /home/opt/local/cores/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64/libifport.so.5 (0x00007ff8ae984000)
        libifcoremt.so.5 => /home/opt/local/cores/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64/libifcoremt.so.5 (0x00007ff8ae5f0000)
        libimf.so => /home/opt/local/cores/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64/libimf.so (0x00007ff8ae061000)
        libsvml.so => /home/opt/local/cores/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64/libsvml.so (0x00007ff8ac9ae000)
        libintlc.so.5 => /home/opt/local/cores/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64/libintlc.so.5 (0x00007ff8ac740000)
        libirng.so => /home/opt/local/cores/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64/libirng.so (0x00007ff8ac3cc000)
        /lib64/ld-linux-x86-64.so.2 (0x00005572db0f7000)