82
Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 EUR 22292 EN

Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

Embed Size (px)

Citation preview

Page 1: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

Technical Specification on the Implementation of a Trajectory Model

S. Potempski and S. Galmarini

2006

EUR 22292 EN

Page 2: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

The mission of the Institute for Environment and Sustainability is to provide scientific and technical support to EU policies for the protection of the environment and to contribute to the EU strategy on sustainable development. European Commission Directorate-General Joint Research Centre Institute for Environment and Sustainability Contact information Dr. S. Galmarini JRC/IES/TAQU/REM TP 441 Joint Research Centre 21020 Ispra Italy [email protected] Tel. +39 0332 785382 Fax. +39 0332 785466

Dr. S. Potempski JRC/IES/TAQU/REM TP 441 Joint Research Centre 21020 Ispra Italy [email protected] Tel. +39 0332 789944 Fax. +39 0332 785466

http://ies.jrc.ec.europa.eu http://www.jrc.ec.europa.eu Legal Notice Neither the European Commission nor any person acting on behalf of the Commission is responsible for the use which might be made of this publication. A great deal of additional information on the European Union is available on the Internet. It can be accessed through the Europa server http://europa.eu.int EUR 22292 EN ISBN 92-79-02886-3 ISSN 1018-5593 Luxembourg: Office for Official Publications of the European Communities © European Communities, 2006 Reproduction is authorised provided the source is acknowledged Printed in Italy

Page 3: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

1

Technical specification on the implementation of a trajectory model

S. Potempski and S. Galmarini

European Commission - DG Joint Research Centre,

Institute for Environment and Sustainability, Transport and Air Quality Unit

IT-21020 Ispra (VA), Italy

2006 EUR 22292 EN

Page 4: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

2

Page 5: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

Table of contents 1. Introduction......................................................................................................................................5

2. The implementation of the FLEXTRA model – overview ..............................................................5

3. The FLEXTRA code........................................................................................................................9

4. Preparation of input data ................................................................................................................10

4.1 Direct editing of input parameters ...........................................................................................10

4.2 Input parameters via Unix shell ...............................................................................................10

4.3 Input parameters via WWW ....................................................................................................11

4.4 Meteorological data preparation ..............................................................................................15

5. Post-processing ..............................................................................................................................16

8. Summary ........................................................................................................................................28

Appendix 1. Input files for FLEXTRA..............................................................................................29

Appendix 2. Unix shell scripts for input ............................................................................................35

Appendix 3. WWW scripts ................................................................................................................41

Appendix 4. Meteorological data preparation scripts ........................................................................47

Appendix 5. Post-processing scripts ..................................................................................................58

Page 6: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

4

Page 7: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

5

1. Introduction The trajectory model FLEXTRA has been implemented as a tool that can be used in different analyses of the situation arisen after accidental release of airborne harmful material. The aim of this report is to give the technical specification of the implementation of a trajectory model FLEXTRA that can be used by the administrator and by the user. Some operational elements are also presented, however another technical report will be devoted to include all the relevant aspects in details. The report is organised as follows: first general structure of the implementation is presented, then pre-processing and post-processing software is fully described. In the appendixes the developed software is included. The application of a trajectory model is presented in a separate report entitled: “Implementation and applications of a trajectory model” by the same authors. 2. The implementation of the FLEXTRA model – overview This section gives an overview of the implementation of the FLEXTRA model, all the technical details are put into the next sections. The FLEXTRA model v. 3.3 has been implemented at IES, JRC under Linux-based platform. The diagram below (Fig. 1) shows implementation done at JRC mainly pre- and post-processing. Some small changes have been also made in the source code to increase flexibility of the model. The pre-processing is related to proper preparation of input data in order to run FLEXTRA simulation. The user can define input data either via interactive script of Unix shell or via simple WWW interface (examples are shown on Figs. 2-4 – depending on chosen options screens can be slightly different – see Figs. 6-9). Once the data are introduced they are converted into proper format of input files via developed Unix scripts (written in Perl language). Another problem is retrieving of needed meteorological data – this can be done in two ways. Firstly it can be achieved via WWW ECMWF site in interactive way. Second possibility is to make it in automatic way. For this purpose additional scripts have been developed namely:

1. To prepare appropriate request to ECMWF system MARS (Meteorological Archival and Retrieval System) and sending it via secure ftp.

2. On ECMWF site background process to proceed with the request and after its completion to send meteorological grib files to JRC site.

3. To combine retrieved grib files from ECMWF into the form expected by the FLEXTRA model (this script is also used after retrieving ECMWF data via WWW).

Once all the input data have been prepared in a proper format FLEXTRA simulation can be initiated. The standard outputs of FLEXTRA are text files. Therefore it has been necessary to develop full post-processing in order to visualize results of simulations on the map and in the form of graphs. The following scripts have been prepared:

1) To make a picture of each individual trajectory on the map and in the form of graph for the height of trajectory (above see level) in a function of time.

2) To make a picture of all trajectories started at the same time on the map and for height as graph.

3) To make a picture of trajectories within one sub-run (i.e. separately for each perturbed i.e. ensemble run) on the map and for height as graph.

4) Finally all trajectories from all sub-runs (again on map and graph for height).

Page 8: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

6

Fig. 1 Diagram of implementation scheme for FLEXTRA model

Page 9: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

7

Fig. 2 FLEXTRA input via WWW – first screen

All the pictures can be available in either jpg or pdf files on the WWW site (examples are shown in the next section). The post-processing has been programmed in Perl script language with the usage of GrADS (Grid Analysis and Display System) package for visualization on the map and Gnuplot for creating graph. The GrADS is a commonly used visualization and analysis tool for meteorological and other environmental data. The package is freely available on the Web site http://grads/iges.org/grads/. The Gnuplot is a de facto standard of open source package for producing two and three dimensional graphs, practically included in all Linux distributions. Both packages are portable and have been implemented on many software and hardware platforms. Additionally each individual trajectory is stored in xml files. These files can be either interactively or automatically transferred (via ftp) to the EURDEP system. This option allows for visualization of trajectories together with available measurement data and takes advantage of the all typical properties of GIS system (like zooming, displaying geographical layers, etc.).

Page 10: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

8

Fig. 3 FLEXTRA input via WWW – second screen

Page 11: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

9

Fig. 4 FLEXTRA input via WWW – third screen NORMAL mode

3. The FLEXTRA code The FLEXTRA code is written in Fortran 77 standard with one exception: INCLUDE statement is used for including separate files containing definition of parameters (includepar) and common blocks (includecom). An external library used for reading meteorological grib files ECMWF library called gribex is applied. The library can be freely downloaded from ECMWF site (http://www.ecmwf.int), but it is also included into FLEXTRA 3.3 distribution. The library is a mixture of Fortran and C code and is highly sensitive to platform. For Linux platform there are two versions – one for standard GNU compiler and the second for Portland Group compiler (PGI), which is default for gribex. The library can be tested independently as demo code (grdemo.f) is also included into the package. The tests made on different platform have shown that C and Fortran compilers should be absolutely compatible for proper working – despite of existing standards in Unix environment practically both compilers should be taken from one vendor. The following changes have been made in the source code: 1. In gridcheck.f subroutine all the lines for checking header of grib files have been commented out. The reason was that in case of grib files created on other than actually used architecture first record of header is not recognized correctly (the problem is partially a consequence of existing two standards: little and big endian for binary storing of integer numbers). 2. In files readwind.f and readwind_nests.f two possible codes for reading surface pressure have been introduced. This is a consequence of using different code tables by ECMWF archives (tables: 128 and 162) containing different code for surface pressure (codes: 52 for ERA-40, 134 for operational archive). Caution: in case of lack of surface pressure in grib files the highest level of pressure is taken into simulations by default. 3. In includepar file the following parameters have been changed: - maxpoint – maximum number of trajectory starting/ending points from the value 10 to 50

Page 12: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

10

and in consequence number of possible trajectories (200*maxpoints) have been increased. - maxtime, maxitime – maximum number of time steps and equidistant interpolated time steps respectively from 500, 10000 to 1000, 20000. This allows for longer simulation time. 4. Additionally instead of reading each time elevation (which can be obtained from surface geopotential grib file) the OROGRAPHY file has been prepared on domain covering the whole Europe (-10W to 30E and 30N to 60N with grid steps 0.5x0.5). In case of a need of simulation for different domain geopotential can be included into meteorological grib file (this is an option of the FLEXTRA input: either use geopotential or a fixed orography file). The Fortran code for preparation of OROGRAPHY file from DEM_30M_GLOBAL dataset available in USGS WWW site: http://www.usgs.gov for default grid (-10W to 30E and 30N to 60N with grid steps 0.5x0.5) has been included into the Appendix 1. 4. Preparation of input data 4.1 Direct editing of input parameters The FLEXTRA model needs the following input files:

- pathnames: contains information about location on disk meteorological data files and path for output,

- COMMAND: main input file for different options for trajectories (mode, date/time, ensemble and few more advanced options),

- depending on chosen mode (NORMAL, CET or FLIGHT) one of the file: STARTPOINTS, STARTCET or STARTFLIGHT,

- AVAILABLE: defines in which files meteorological fields are put for consecutive time steps.

Formats of these files are strict – no free format Fortran statements are used in the code for reading input data. In Appendix 1 examples of each file are included. 4.2 Input parameters via Unix shell Instead of direct editing all the needed files input data can be introduced via developed Unix shell scripts. The main internal script prep_inp.pl for preparation of input parameters has been written in Perl language (see Appendix 2). The synopsis of the script is the following: prep_inp.pl mode if_advanced no_ensemble < standard_input where the parameters denote:

- mode is either 1 – NORMAL, 2 – CET, 3 – FLIGHT corresponding to FLEXTRA modes

- if_advanced is either 0 – NO or 1 – YES, depending if the user wants to change advanced options or not. The advanced options are the following:

o interpolation type (ideal - default or linear), o CFL and CFLT parameters corresponding to Courant-Friedrichs-Levy

criterion (default: 5.0, 5.0), o kind of trajectory (3-D - default, on model layer, mixing layer, isobaric,

isentropic), o units of z-coordinate (above see level, above ground - default, hectopascal).

- no_ensemble – number of ensemble trajectories (default: 5, if set to zero no ensemble trajectories will be calculated). Default values for parameters for ensemble trajectories are the following:

o distance in grid units: 0.5 deg

Page 13: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

11

o relative scaled relaxation time: 1.0 o errors in U, V, W wind components: 0.08, 0.08, 0.2.

The script prep_inp.pl reads standard input for parameters’ specification and finally produces the following files:

- sed_fil_com for changing COMMAND template file - sed_fil_star for changing STARPOINTS, STARCET or STARFLIGHT template file - sed_fil_more_xx for changing STARPOINTS or STARFLIGHT template file in case

of more than one source point (xx is the consecutive number of source point). The script prep_inp.pl is called in other Unix shell scripts used both for input data via shell and via WWW site. The input to the script prep_inp.pl must be in agreement with read statements in the script. To achieve that interactive Unix shell prep_inp.sh has been developed (included in the Appendix 2). The Bourne shell prep_inp.sh scripts displays step by step which data should be specified by the user. There is no way of go back, so in case of a mistake the user should start the script again. As soon as all the needed data are given by the user the script creates all input files for FLEXTRA run. The script makes use of files created by prep_inp.pl script and previously prepared template files for all input data files (i.e. COMMAND and STAR* files). On the diagram shown on Fig. 5 flow of information is presented for realization of FLEXTRA input via Unix shell.

Fig. 5 Scheme of input scripts via Unix shell

4.3 Input parameters via WWW The input can be also realized by developed WWW site. The pictures on Figs. 2-4, 6-9 show all the screens for different FLEXTRA modes. The WWW site has been developed in PHP language. The PHP language is the most popular Web-based script language in Unix environment and in particular is included in all Linux distributions (although there is also MS Windows version). The configuration used is the standard one, however this can be improved if additional safety features will be required. No connections to any database or

Page 14: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

12

other external service are required. The Appendix 3 contains full code for PHP script flextra.php. Once the user specifies all the data, in the temporary directory file /tmp/flextra_php.in will be created by PHP with all the needed input data for preparation of input FLEXTRA files.

Fig. 6 FLEXTRA input via WWW – additional sources NORMAL mode

Fig. 7 FLEXTRA input via WWW – third screen CET mode

Page 15: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

13

Fig. 8 FLEXTRA input via WWW – third screen FLIGHT mode

Fig. 9 FLEXTRA input via WWW – additional sources FLIGHT mode

Page 16: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

14

The script for preparation of input data for FLEXTRA run is called prep_inp_php.sh and invokes Perl script prep_inp.pl with created by PHP file flextra_php.in as input. The synopsis is: prep_inp_php.sh mode if_advanced no_ensemble (i.e. like prep_inp.pl) The PHP also creates simple commands that can be used for full automation of the whole input process. They are: 1. /tmp/flextra_php.sh like: ./prep_inp_php.sh 3 1 3 (parameters are defined according to

user input). 2. /tmp/flextra_php_met.sh like: ./prep_met.pl 20030410 013000 0480000 1 for

meteorological data preparation (described in the next section). 3. /tmp/flextra_php_run.sh like: ./FLEXTRA < __in__ > flight_case.out 2>&1 Then the following scheme can be applied to automate the whole process (Fig. 10 shows flow diagram): 1. The user defines parameters via WWW interface. 2. The PHP script creates input file (flextra_php.in) for Unix shell scripts used for data

preparation in appropriate format as well as commands (items 1-3 above) that should be run.

3. The Unix daemon checks whether new file and commands have appeared in /tmp directory. If yes, then first command for input data is run, then the second one for preparation of meteorological data and finally FLEXTRA simulation runs. The daemon removes input files and waits for new ones.

Fig. 10 Scripts and files for FLEXTRA input via WWW and simulation run

Page 17: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

15

The organisation of communication between JRC and ECMWF with the full description of the daemon used for automation of this process will be described in a separated document related to the operational aspects. Similarly all the issues related to safety features of the Web site used for FLEXTRA will be also included there. 4.4 Meteorological data preparation The FLEXTRA model originally has been prepared to use meteorological grib files from the ECMWF. The following data are necessary to run the model:

- multilevel fields: temperature and three components of wind (u, v, w) on model levels (hybrid coordinate system is used in the ECMWF) ,

- surface fields: pressure and geopotential (unless fixed OROGRAPHY file is used). The data are expected to be stored in grib file in such a way that first multilevel fields are written then surface data. For each time step data should be stored in a separate file. List of available meteorological files is included in AVAILABLE file. Locations of meteorological data (grib files) and AVAILABLE file are given in pathnames file. Once the user defines parameters for FLEXTRA run (either via Unix shell or via WWW interface) the Perl script prep_met.pl can be invoked to produce requests for meteorological data in the form used by ECMWF MARS archive (Appendix 4 contains source code of this script). The synopsis of the script is the following: ./prep_met.pl begin_date begin_hour end_date end_hour trajector_length traj_type ecmwf (for example: ./prep_met.pl 20060101 120000 20060102 120000 0480000 1 1 i.e. start date/time:01.01.2006 12:00, end date/time 02.01.2006 12:00, forward trajectories with length 48 hours) The parameters denote: first starting date and time of simulation, last starting date and time of simulation, trajectory length (hours, minutes, seconds) and trajectory type (1 = forward, -1 = backward). The last parameter shows if there is a need to retrieve data from the ECMF. In order to make this request in an automatic way flextra.php script writes in temporary directory shell script flextra_sh_met.sh, which invokes prep_met.pl script with appropriate parameters. The outputs of the meteo preparation script are the following files:

- _retr_ml_ (or _retr6_ml_ for data before September 2002 or from analysis) containing request for multilevel fields,

- _retr_sfc_ (or _retr6_sfc_ for data before September 2002 or from analysis) containing request for surface fields,

- _available_ - list of meteorological grib files for each time step (typically every 3 or 6 hours). The file corresponds to AVAILABLE file.

In case of data before September 2002 files _retr6_ml_ and _retr6_sfc_ containing requests from ERA-40 archive are created. For newer data these files contain requests related to analysis data (hours: 0, 6, 12 and 18) from operational archive. Additionally _retr_ml_ and _retr_sfc_ contain request for forecast data (for hours: 3, 9, 15 and 21). Combaining these two data sets one can have meteorological data every 3 hours (Appendix 4 contains examples of request files). The files (_retr_*) containing requests for MARS archive should be transferred via ftp to ECMWF server, where the background process run job for retrieving data via simple commands like: mars < _retr_ml_ and mars < _retr_sfc_. Standard grid used is defined as follows: -10W to 30E and 30N to 60N with grid steps 0.5x0.5. Once the data are retrieved from MARS archive they are sent automatically via ftp.

Page 18: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

16

However in order to send request files to ECMWF server one must use secure EC-card to generate one-time password. This part demands manual input from the user. On the other hand ftp process from ECMWF to JRC can be fully automated. The other possibility is to get needed meteorological data in a completely interactive way via ECMWF WWW site (http://www.ecmwf.int). The meteorological grib data downloaded from ECMWF site are further processed by the scripts included in Appendix 4 in order to meet FLEXTRA requirements mentioned in the beginning of this section (i.e. separate files for each time step with proper order of meteorological fields). The scripts make use of open source wgrib C program that can be obtained from the web site: http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html. The wgrib program is a widely used, simple and flexible tool for manipulation of grib meteorological data coming from different meteorological centres. The scripts for final preparation of the meteorological data are the following: extract_ml.sh, extract_sfc.sh and extract_ml_sfc_.sh. The first two should be applied to analysis data and the last one to forecast data. In any case first multilevel fields must be processed (example is shown in the Appendix 4). As it was previously mentioned the operational aspects of the automated transfer of meteorological data from ECMWF to JRC with the description of the software used on both sides will be included in the technical report dealing with all the operational elements of the usage of the FLEXTRA model.

5. Post-processing The standard outputs of the FLEXTRA simulations are text files stored in output directory defined in the file pathnames. They are:

- T_label – containing location and height of each trajectory for all time steps (where label is one of the input parameter), if number of ensemble trajectories is greater than zero than corresponding files T_label_U0001, T_label_U0002 and etc. are also produced.

- TI_label – containing the same data but for interpolated for fixed time steps (for example every 3 hours), if number of ensemble trajectories is greater than zero than corresponding files TI_label_U0001, TI_label_U0002 and etc. are also produced.

Therefore in order to visualize output data the following Perl and Unix scripts have been developed: 1. Perl script get_res_new.pl for processing one output file – the synopsis is: ./get_res_new.pl prefix label mode sim_sec_from sim_sec_till < T_output_file The aim of this script is to process standard FLEXTRA output file and prepare script for displaying indivudual trajectories in GrADS (on map) and Gnuplot (graph of height). The parameters denote:

• prefix – prefix used for naming output files • label – corresponds to label defined in input files STAR* • mode – 1=NORMAL, 2=CET, 3=FLIGHT • sim_sec_from, sim_sec_till – only trajectories with length in seconds in the interval

[sim_sec_from, sim_sec_till] are to be processed, if sim_sec_till is not specified value 864000 (=10 days) is taken.

• T_output_file – is the FLEXTRA output file. The script produces the following output files:

• {pref}_{starting_date}{starting_time}_{no_of_traj}.plt – script file for use in the Gnuplot for displaying heights (above see level) of trajectory.

Page 19: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

17

• {pref}_{starting_date}{starting_time}_{no_of_traj}.dat – data file for use in the Gnuplot for displaying heights (above see level) of trajectory (time steps given in seconds).

• {pref}_{starting_date}{starting_time}_{no_of_traj}.tim – data file for use in the Gnuplot for displaying heights (above see level) of trajectory (time steps specified in date/time format).

• {pref}_{starting_date}{starting_time}_{no_of_traj}.gs – script file for use in the GrADS for displaying trajectory on the map.

• {pref}_{starting_date}{starting_time}_{no_of_traj}_._txt_ – text file for use by script collecting results in the GrADS and Gnuplot. It contains information about: length of trajectory, minimum and maximum of geographical longitude and latitude and height, starting date and time, ending date and time.

• {pref}_{starting_date}{starting_time}_{no_of_traj}.xml – file in XML format for sending to the EURDEP system containing geographical coordinates, height and text information of a trajectory.

• {pref}_gra_.ctl – control file for use in GrADS (one for all trajectories from one FLEXTRA output file). This file can be used to initiate GrADS session. It uses prepared earlier files output2.grib and output2.grib.idx for definition of standard grid used (-10W to 30E and 30N to 60N with grid steps 0.5x0.5).

The total number of files is 6x(number of trajectories processed)+1. The convention for naming files is as follows:

• {prefix} corresponds to prefix parameter. • {starting_date}{starting_time} are starting date and time for trajectory in the form

YYYYMMDD and HHMISS respectively. • {no_of_traj} – number of successive trajectory processed from FLEXTRA output file

(it corresponds to successive trajectory started within the specified by the user period: 0=first starting time, 1=second starting time, etc.).

The script get_res_new.pl calculates trajectory data for synoptic hours (i.e. 0, 3, 6, 9, 12, 15, 18 and 21) starting from the closest one, if necessary linear interpolation based on closest time steps is used. For example if the beginning hour of trajectory is 01.30 the output is produced for 01.30, next for the first synoptic hour 03.00 and then for the following ones. The last time step always corresponds to the last simulation time (i.e. to the total trajectory length) – for the presented example, in case of 12 hours trajectory length the last two time steps will be 12.00 and 13.30. 2. Perl script collect_res_new.pl for collecting results from different output files – the synopsis is: ./collect_res_new.pl prefix1 {prefix2} ... The aim of this script is to prepare script for displaying in GrADS and Gnuplot a number of trajectories from different FLEXTRA output files. The parameters prefix1 {prefix2} ... do not denote prefixes used in the previously described script get_res_new.pl for producing output files but simply the beginning of the name of the text file produced by get_res_new.pl. Precisely: the script checks the current directory for files naming {prefix}_txt_._txt_. However the trick is that wildcharacters (using quotation if necessary) can be used in {prefix} parameter. For example command: ./collect_res_new.pl paks\* or ./collect_res_new.pl “paks*” will produce output from all files with the names beginning with word paks. Theoretically even more tricky version is possible like ./collect_res_new.pl “paks1* paks2*” resulting in producing output from all files with the names beginning with words paks1and paks2, however for better clarification command ./collect_res_new.pl paks1\* paks2\* is recommended. This, of course, also means that in order to use collect_res_new.pl script, first

Page 20: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

18

get_res_new.pl script should be applied to all FLEXTRA output files which the user wants to process. The collect_res_new.pl reads text files prepared by the script get_res_new.pl and creates similar files like get_res_new.pl but for visualization of all processed trajectories (not for individual ones). Hence the script generates the following output files:

• _tmp1_gra_.gs – script for GrADS containing header (with title and some settings), • _tmp2_gra_.gs – script for GrADS including scripts for individual trajectories, • _tmp1_gnu_.plt – script for Gnuplot containing header (title, axis description, etc), • _tmp2_gnu_.plt – script for Gnuplot including scripts for individual trajectories, • _out_gnu_.txt – text file for controlling and debugging purposes.

The colors used for successive trajectories are the following: red, green, blue, magenta, cyan and orange. By default trajectories starting at the same time are plotted with the same color. 3. Unix script print_res_gen.sh for preparation of graphics results from different simulation runs. The script uses above mentioned Perl scripts. The synopsis is: ./print_res_gen.sh lab mode sim_time_from sim_time_till postprefix {postprefix} where the peremeters denote: lab – prefix of the label used in FLEXTRA input parameters, mode – 1=NORMAL, 2=CET, 3=FLIGHT, sim_sec_from, sim_sec_till – only trajectories with length in seconds in the interval [sim_sec_from, sim_sec_till] are to be processed; as sim_sec_till can be taken max, which means that sim_sec_till=864000 (10 days), postprefix – postprefix of the label used in FLEXTRA input parameters. For example ./print_res_gen.sh alg 1 0 max 020 050 100 will collect results from the runs labeled: alg020, alg050 and alg100 (which for instance can correspond to simulations of trajectories for different starting heights: 20, 50 and 100m). The script works in the following way:

- First get_res_new.pl script is invoked for all FLEXTRA output files labeled lab*. Using the same example, files T_alg020, T_alg050 and T_alg100 are used as input (and if ensemble option is used also T_alg020_U0001, T_alg020_U0002, etc.). In such a manner all individual trajectories are processed from runs: alg020, alg050 and alg100 and all previously mentioned files are produced (*.gs, *.plt, *.tim. *.dat, *._txt_, *.xml).

- For each created GrADS and Gnuplot scripts (*.gs and *.plt) respective programs are run in non-interactive mode to produce Postscipt files (*_gnu.ps, *_gra.ps for Gnuplot and GrADS respetively). Then via standard Unix/Linux programs ps2pdf, pstopnm and pnmtojpeg Postscript files are converted to pdf, pnm and jpeg formats. The names of the files correspond to names of script files (*.pdf, *.jpg).

- In the second step all trajectories from all runs are collected by usage of collect_res_new.pl script (called with parameter {lab}\* - in the example alg\*). The final files are {lab}_all_gnu.* or {lab}_all_gra.* respectively for Gnuplot and GrADS and again images in the form of pdf and jpg formats are created.

- In the third step collect_res_new.pl script is invoked as many times as needed for visualizing all trajectories from each run (it means that collect_res_new.pl script is called with parameter {lab}{postprefix}\* - in the example alg020\*, alg050\* and alg100\*). Then images are created in the files {lab}{postprefix}_gnu.* or {lab}{postprefix}_gra.*.

- In the last step collect_res_new.pl script is invoked for any time step for visulalization of all trajectories from all runs starting at the same time (script collect_res_new.pl is called with parameter lab\*_xx where xx coresponds to successive number of trajectory (0=first starting time, 1=second starting time, etc).

Page 21: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

19

Similarly as before Gnuplot and GrADS scripts and images are produced in files named: {lab}_t_{xx}_gnu.* and {lab}_t_{xx}_gnu.* respectively (in the example alg_t_0_gnu.*, alg_t_0_gra.*, etc.).

To summarize ./print_res_gen.sh makes use of Perl scripts to produce a number of different pictures:

- Each individual trajectory on the map and in the form of graph for the height of trajectory (above see level) in a function of time.

- All trajectories from all runs on map and graph for height. - For each run all trajectories on the map and for height as graph. - For each time step all trajectories started at the same time on the map and for

height as graph (additional scripts included in the Appendix 5: color_gra.sh and color_gnu.sh are used to distinguish trajectories from different runs by specifying different colors).

Using the same example the following output files will be produced: - alg{020|050|100}_{starting_date_and_time}_xx.* (*=gs, plt, dat, tim, xml or _txt_), - alg{020|050|100}_{starting_date_and_time}_xx_{gnu|gra}.* (*=pdf, jpg, ps, pnm), - alg_all_{gnu|gra}.* (*=gs, plt, pdf, jpg, ps, pnm), - alg{020|050|100}_{gnu|gra}.* (*=gs, plt, pdf, jpg, ps, pnm), - alg_t_xx_{gnu|gra}.* (*=gs, plt, pdf, jpg, ps, pnm) where where xx coresponds to

successive number of trajectories (0=first starting time, 1=second starting time, etc). Thus the number of produced files can be large. For instance suppose that there have been 3 runs made for different starting heigths (let say: alg020, alg050, alg100) within the starting times in the period 30.05.1998 01:00 to 31.05.1998 01.00 with 3 hours as interval between successive trajectories. Then the total number of produced files in the example can be calculated as follows:

- 3 (runs)x9(starting times)x6(files)=162 text files for individual trajectories - 3(runs)x9(starting times)x2(gnu or gra)x4(graphic formats)= 216 graphic files for

individual trajectories - 6 files for all trajectories from all runs - 3(runs)x2(gnu or gra)x6(formats)= 36 files for trajectories from one run - 9(starting times)x2(gnu or gra)x6(formats)= 108 files for same time trajectories from

all runs. This gives in total: 162+216+6+36+108=528 files. In the Appendix 5 the source codes for post-processing Perl and Unix shell scripts are included. On Figs. 11-15 examples of produced images are presented both for single trajetory and for a set of trajectories from different runs. Once all the images are produced Bourne shell script read_d.sh (attached in Appendix 5) can be used to generate automatically WWW pages (in html) to access all the output files produced by FLEXTRA and post-processing scripts. The synopsis is: ./read_d.sh directory – where directory denotes the starting directory for which html files will be produce to access any file in this directory as well as all sub-directories. The script creates html files named directory.html for each sub-directory started from the one specified as argument.

Page 22: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

20

Fig. 11 Example: forward trajectories starting at 1.30 (red) and 2.00 (green) from one run.

Fig. 12 Example: height of forward trajectories starting at 1.30 (red) and 2.00 (green), from one run.

Page 23: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

21

Fig. 13 Algeciras case: backward trajectories from all runs (colors show different start time).

Fig. 14 Example: single backward trajectory.

Page 24: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

22

Fig. 15 Example: height of single trajectory (with elevation)

However print_res_gen.sh prepares also html files and a structure of directories, in which the results of all the processed runs are stored. The final structure of directories is the following: /{lab}_plots --------------/pdf ---------------------- /time ---------------------- /{run1} ---------------------- /{run2} ………………………..... --------------/jpg ---------------------- /time ---------------------- /{run1} ---------------------- /{run2} ………………………..... -------------- /ps ---------------------- /time ---------------------- /{run1} ---------------------- /{run2} ………………………..... --------------/gra --------------/gnu --------------/xml where {lab} is the common label for all runs while {run1}, {run2}, etc, correspond to postprefixes used for run identification. In the directories: pdf/, jpg/ and ps/ files are stored in appropriate formats (pdf, jpg ans ps respectively). In the directory gra/ all files needed by GrADS are put (i.e. control and script files), analoguously in gnu/ directory those ones used by Gnuplot (data and script files). In xml/ directory all xml files that can be used to exchange data are stored. In time/ subdirectories files related to the same starting (or ending time) for all the runs are kept. In the main directory output (containing information normally displayed on the screen during the run) and result text files can be found as well as general plots containing all trajectories from all the runs.

Page 25: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

23

The main html file created is {lab}.html. It contains links to text files, plots with all trajectories and the rest of pdf and jpg files. The other html files created are:

- {lab}_pdf.html – for displaying pdf files - {lab}_jpg.html – for displaying jpg files - {lab}_pdf_{run}_{gra|gnu}.html – for displaying pdf files for each individual trajectory

from specified run - {lab}_jpg_{run}_{gra|gnu}.html – for displaying jpg files for each individual trajectory

from specified run The navigation between html files is built-in . Using the previous example structure of directories would be: /alg_plots --------------/pdf ---------------------- /time ---------------------- /020 ---------------------- /050 ………………………... --------------/jpg ---------------------- /time ---------------------- /020 ---------------------- /050 ………………………... -------------- /ps ---------------------- /time ---------------------- /020 ---------------------- /050 ………………………... --------------/gra --------------/gnu --------------/xml The html files created would be: alg.html – main file, then alg_pdf.html, alg_jpg.html – for pdf/jpg files and finally alg_{pdf|jpg}_{020|050|…}_{gra|gnu}.html. In the three subsequent pictures (Figs. 16-18) examples of html files are shown:

- main Web page for all runs, - Web page for pdf files (for jpg is analoguous one), - Web page for one specified run.

Page 26: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

24

Fig.16 Example of main screen with results

Page 27: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

25

Fig.17 Example of screen with results for pdf files

Page 28: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

26

Fig.18 Example of screen with results for specified screen

The user can also via WWW script flextra_output.php define which runs are to be processed for preparation of graphic results. On Fig2. 19-20 examples of such screens are shown. The user should provide the following information:

- label common for all the runs (typically prefix of the run-id name), - trajectory mode (normal, CET or FLIGHT), - eventually minimal and maximal duration of trajectories (in seconds) – default is all

(i.e. from 0 to max), - id-runs (typically post-prefixes of original run-id).

For example for runs alg020, alg100, alg300 label should be alg and run ids: 020 100 300. As a result in /tmp directory short script flextra_output_php.sh will be created which simply includes invocation of previously described print_res_gen.sh shell script. For example it can be like: ./print_res_gen.sh alg 1 0 max 020 100 300. This can be used for automation of the post-processing.

Page 29: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

27

Fig.19 Screen to specify which runs are to be processed for having plots

Fig.20 Screen to specify which runs are to be processed for having plots

Page 30: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

28

8. Summary In the report we have presented the technical details of the implementation of the trajectory model FLEXTRA (http://zardoz.nilu.no/~andreas/flextra+flexpart.html). The following tools and packages are necessary for the input preparation, FLEXTRA simulation and output postprocessing on Linux based plaftorm:

- Fortran and C compiler (Portland Group PGI compiler is recommended to omit the problems with compatibility http://www.pgroup.com/),

- gribex library from ECMWF (http://www.ecmwf.int/products/data/software/grib.html) for reading meteorological grib files - the library is included into FLEXTRA 3.3 version,

- GrADS (Grid Analysis and Display System) from http://www.iges.org/grads/, - Gnuplot function plotting utility from http://www.gnuplot.info/ included in most Linux

distribution, - wgrib program (free) for manipulating and decoding meteorological grib files from

http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html, - ps2pdf, pstopnm and pnmtojpeg programs for conversion between different graphic

formats are included in any Linux distribiutions, - PHP script language with Apache Web server (or any other Web server which can

use PHP language) – both packages are included in any Linux distribiution, - Perl scripting language included in any Linux distribiutions, and - standard Unix/Linux Bourne shell (in Linux it is typically extended version: bash).

The operational aspects of the implementation will be described in a separate report.

Page 31: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

29

Appendix 1. Input files for FLEXTRA

pathnames ./ ./output/ ./meteo/ ./meteo/AVAILABLE ============================================ Line 1: path where control files "COMMAND" and "RELEASES" are available Line 2: name of directory where output files are generated Line 3: path where meteorological fields are available (mother grid) Line 4: full filename of "AVAILABLE"-file (mother grid) Subsequent lines: Line 2n+3: path where meteorological fields are available (nested grid n) Line 2n+4: full filename of "AVAILABLE"-file (nested grid n) Line below last pathname must be: ============================================

COMMAND ******************************************************************************** * * * Input file for the trajectory model FLEXTRA: Please select your options * * * ******************************************************************************** 1. __________________________________________________ 3X, A50 Paks case LABEL FOR THE MODEL RUN 2. __ 3X, I2 1 DIRECTION 1 FORWARD, -1 BACKWARD TRAJECTORIES 3. _______ 3X, I7 0960000 HHHMISS LENGTH OF AN INDIVIDUAL TRAJECTORY 4. ________ ______ 3X, I8, 1X, I6 19980530 010000 YYYYMMDD HHMISS BEGINNING DATE 5. ________ ______ 3X, I8, 1X, I6 19980530 030000 YYYYMMDD HHMISS ENDING DATE 6. _______ 3X, I7 0003000 HHHMISS TIME INTERVAL BETWEEN STARTING TIMES OF TRAJECTORIES 7. _ _____ 3X, I1, 2X, I5 2 10800 i SSSSS i>0: INTERPOLATED OUTPUT OF TRAJECTORY EVERY SSSSS SECONDS 8. _____ ___.___ _.___ _.___ _.___ _.___ 3X, I5, 2X, F7.3 4(2X,F5.3)

Page 32: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

30

00005 0.000 1.000 0.080 0.080 0.200 NUMBER, DISTANCE (GRID UNITS), TIME CONSTANT (WIND FIELD INTERVAL UNITS) AND INTERPOLATION ERRORS (IN U, V AND W) OF UNCERTAINTY TRAJECT. 9. _ 3X, I1 1 INTERPOLATION 1 = IDEAL INTERPOLATION >1 = LINEAR INTERPOLATION 10. ---.-- 4X, F6.4 5.00 CFL TIMESTEP CRITERION HORIZONTAL AND VERTICAL 11. ---.-- 4X, F6.4 5.00 CFLT TIMESTEP CRITERION TIME GAP BETWEEN INPUT WIND FIELDS 12. - 4X, I1 1 MODE 1 NORMAL MODE, 2 CET MODE, 3 FLIGHT MODE =================================================================== 1. Comment to identify the current model run 2. Direction of trajectories (1 means forward trajectories, -1 backward) 3. Temporal lengths of the trajectories in the format HHHMISS, where HHH is HOUR, MI is MINUTE and SS is SECOND 4. Beginning date and time of trajectory calculation. Must be given in format YYYYMMDD HHMISS, where YYYY is YEAR, MM is MONTH, DD is DAY, HH is HOUR, MI is MINUTE and SS is SECOND. All times are in UTC. 5. Ending date and time of trajectory calculation. Same format as 4. 6. Time interval between two trajectory calculations. Same format as 3. 7. Options for the trajectory output: 0 = original data in irregular time intervals 1 = constant time intervals, interpolated output every SSSSS seconds 2 = 0 plus 1 8. Six parameters have to be inputted. The first is the number of uncertainty trajectories. They are starting in a distance from the starting point of the reference trajectory as given by the second parameter (in grid units). Additionally, random errors may be added at each time step of the trajectory calculation. Using a Langevin equation, they are relaxed with a time constant (in units of the wind field interval, third parameter) specified by the user. These random errors are thought to reflect typical wind errors caused, for instance, by interpolation. The magnitude of these errors (in relative units, relative to the wind velocity) must be specified by the user for the three wind components u, v and w (last three parameters). 9. Kind of interpolation 1 - horizontal interpolation bicubic vertical interpolation polynomial temporal interpolation linear >1 - horizontal interpolation bilinear vertical interpolation linear temporal interpolation linear 10.cfl criterion horizontal/vertical factor by which time step must be shorter than that determined from the CFL criterion, i.e.

Page 33: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

31

delta_t1=delta x/u/cfl delta_t2=delta y/v/cfl delta_t3=delta z/w/cfl delta_t(space) = min(delta_t1,delta_t2,delta_t3) 11. cfl criterion time factor by wich time is shorter than time interval of the wind fields delta_t(time) = delta_T(input wind)/cflt The time step used for trajectory calculation is the minimum of delta_t(space) and delta_t(time) cfl and cflt must not be less than 1! 12. 1 NORMAL mode -> read file STARTPOINTS and calculate a time series of trajectories starting all from the same starting points 2 CET mode -> read file STARTCET and calculate trajectories starting uniformly spaced from a user-defined domain (for a single starting time) 3 FLIGHT mode -> read file STARTFLIGHT and calculate trajectories starting neither uniformly spaced nor with constant time intervals (as needed, for instance, to start trajectories along an aircraft leg) STARPOINTS ********************************************************************** * * * TRAJECTORY MODEL * * DEFINITION OF STARTING/ENDING POINTS * * * * The first 7 characters of the comment are also used as filenames. * * Therefore, they cannot be blank and they must be different for * * each starting point. * * * * Kind of trajectory: 1 = 3 dimensional * * 2 = on model layers * * 3 = mixing layer * * 4 = isobaric * * 5 = isentropic * * * ********************************************************************** * * * Unit of z coordinate: 1 = Meters above sea level * * 2 = Meters above ground * * 3 = Hectopascal * * * * For mixing layer trajectories (kind 3), the z coordinate must be * * given in m.a.g.l. (option 2) * * * ********************************************************************** ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -5.440 ____.____ f9.4 Longitude [DEG] 36.150 ____.____ f9.4 Latitude [DEG]

Page 34: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

32

1 _ 1X,I1 Kind of trajectory (see file header) 2 _ 1X,I1, Unit of z coordinate 1300.0 _____.___ f10.3 z-coordinate (see file header) alg_1300 ________________________________________ character*40 comment ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STARTCET ********************************************************************** * * * TRAJECTORY MODEL * * DEFINITION OF THE CET DOMAIN * * A CET STARTING DOMAIN IS DEFINED BY THE LOWER LEFT AND UPPER RIGHT* * CORNER IN A LATITUDE/LONGITUDE COORDINATE SYSTEM, AND BY A LOWER * * AND UPPER LEVEL. TRAJECTORIES ARE STARTED AT DISTANCES DX, DY AND * * DZ WITHIN THIS DOMAIN. * * * * Kind of trajectory: 1 = 3 dimensional * * 2 = on model layers * * 3 = not allowed in CET mode * * 4 = isobaric * * 5 = isentropic * * * ********************************************************************** * * * Unit of z coordinate: 1 = Meters above sea level * * 2 = Meters above ground * * 3 = Hectopascal * * * * The vertical distance DZ between the trajectories must be * * given in the same units. * * * ********************************************************************** ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -5.000 F Lower left longitude [DEG] -10.000 F Lower left latitude [DEG] 30.000 F Upper right longitude [DEG] 30.000 F Upper right latitude [DEG] 1.000 F DX: Longitudinal distance between trajectories [DEG] 0.500 F DY: Latitudinal distance between trajectories [DEG] 1 I Kind of trajectory (see file header) 2 I Unit of z coordinate 50.0 F Lower z-coordinate (see file header) 550.0 F Upper z-coordinate (see file header) 50.0 F DZ: Vertical interval of trajectories (see file header) 'test' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

STARTFLIGHT ********************************************************************** * TRAJECTORY MODEL * * DEFINITION OF STARTING/ENDING POINTS IN FLIGHT MODE * * This file defines starting points separated non-uniformly in * * space as well as in time. Thus, both starting times AND starting *

Page 35: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

33

* coordinates must be given. * * The starting times must be strictly in temporal order. * * For backward trajectories, the temporal order must be reversed. * * In line #28 of this file, the name of the output file must be * * indicated. Lines #29 and #30 must contain kind of trajectory and * * the unit of the z coordinate to be used. Line #31 is arbitrary, * * then follows a sequence of points. * * Kind of trajectory: 1 = 3 dimensional * * 2 = on model layers * * 3 = mixing layer * * 4 = isobaric * * 5 = isentropic * ********************************************************************** * * * Unit of z coordinate: 1 = Meters above sea level * * 2 = Meters above ground * * 3 = Hectopascal * * * * For mixing layer trajectories (kind 3), the z coordinate must be * * given in m.a.g.l. (option 2) * * * ********************************************************************** 'test' 1 I Kind of trajectory (see file header) 2 I Unit of z coordinate ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 20060104 000000 2I Starting date and time -1.000 F Longitude [DEG] -1.000 F Latitude [DEG] 1.0 F z-coordinate (see file header) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 20060104 000000 2I Starting date and time -20.000 F Longitude [DEG] -20.000 F Latitude [DEG] 1234.0 F z-coordinate (see file header) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 20060104 000000 2I Starting date and time -10.000 F Longitude [DEG] 40.000 F Latitude [DEG] 23.0 F z-coordinate (see file header) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AVAILABLE DATE TIME FILENAME SPECIFICATIONS YYYYMMDD HHMISS -------- ------ ---------- --------- 20030410 120000 2003041012 on disc 20030410 180000 2003041018 on disc 20030411 000000 2003041100 on disc 20030411 060000 2003041106 on disc 20030411 120000 2003041112 on disc 20030411 180000 2003041118 on disc 20030412 000000 2003041200 on disc 20030412 060000 2003041206 on disc 20030412 120000 2003041212 on disc 20030412 180000 2003041218 on disc 20030413 000000 2003041300 on disc 20030413 060000 2003041306 on disc 20030413 120000 2003041312 on disc 20030413 180000 2003041318 on disc 20030414 000000 2003041400 on disc 20030414 060000 2003041406 on disc

Page 36: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

34

20030414 120000 2003041412 on disc 20030414 180000 2003041418 on disc prep_oro.f Fortran program for preparation of OROGRAPHY file from DEM_30M_GLOBAL dataset on default grid (-10W to 30E and 30N to 60N with grid steps 0.5x0.5) program prep_oro integer*2 ioro parameter (nlat=360,nlon=720,length=2*nlon) parameter (latmin=30,latmax=75,lonmin=-15,lonmax=60) dimension ioro(nlat,nlon) open(1,name='DEM_30M_GLOBAL',access='direct',recl=length, + status='old') do i=1,nlat read(1) (ioro(i,j),j=1,nlon) enddo open(2,name='OROGRAPHY_GL') do i=1,nlat write(2,*) (ioro(i,j),j=1,nlon) enddo do i=1,nlat do j=1,nlon if(ioro(i,j) .eq. -9999) ioro(i,j)=0 enddo enddo open(3,name='OROGRAPHY') minrow= 2*(90-latmin)+1 maxrow= 2*(90-latmax)+1 mincol= 2*(lonmin-(-180))+1 maxcol= 2*(lonmax-(-180))+1 do i=minrow,maxrow,-1 write(3,*) (ioro(i,j),j=mincol,maxcol) enddo end

Page 37: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

35

Appendix 2. Unix shell scripts for input 1. Script prep_inp.sh #!/bin/sh rm -f _inp_ touch _inp_ rm -f sed_fil_more_* echo "Please specify description (max. 50 characters)" read desc echo $desc >> _inp_ echo "Please specify mode of trajectories (1=normal 2=CET 3=FLIGHT)" read mode echo "Please type of trajectories: 1 forward, -1 backward" read traj_typ echo $traj_typ >> _inp_ echo "Please specify length of trajectories (HHHMISS)" read traj_len echo $traj_len >> _inp_ echo "Do you want to use advanced options: 1 yes, 0 no ?" read if_advanced if [ "$if_advanced" -eq 1 ] then echo "Please specify interpolation type (1=ideal 2=linear) CFL and CFLT" read traj_inter cfl cflt echo $traj_inter $cfl $cflt >> _inp_ fi echo "Begining date YYYYMMDD and hour HHMISS" read start_date start_hour echo $start_date $start_hour >> _inp_ no_ensemble=0 if [ "$mode" -ne 2 ] then echo "End date (YYYYMMDD) and hour (HHMISS)" read end_date end_hour echo $end_date $end_hour >> _inp_ echo "Time interval between trajectories (HHHMISS)" read tim_inter echo $tim_inter >> _inp_ echo "Please specify number of ensemble trajectories (0=none)" read no_ensemble if [ "$no_ensemble" -gt 0 ] then echo "Then specify distance in deg (0.5) relative relaxation time (1.0) error components for u,v,w (0.08,0.08,0.2)" read dist_deg rel_time u_err v_err w_err echo $dist_deg $rel_time $u_err $v_err $w_err >> _inp_ fi echo "./prep_met.pl $start_date $start_hour $end_date $end_hour $traj_len $traj_typ" > flextra_sh_met.sh fi if [ "$mode" -eq 2 ] then echo $start_date $start_hour >> _inp_ echo 0030000 >> _inp_ echo "./prep_met.pl $start_date $start_hour $start_date $start_hour $traj_len $traj_typ" > flextra_sh_met.sh fi if [ "$if_advanced" -eq 1 ] then

Page 38: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

36

echo "Kind of trajectories: 1=3-D, 2=on model layer, 3=on mixing layer, 4=isobaric, 5=isentropic" echo "Units of z-coordinate: 1=Meters above see, 2=meters above ground, 3=hectopascal)" echo "If kind=3 (mixing layer) => z-coor=2 (m.a.g.l.)" echo "Specify kind of trajectories (1-5) and units of z-coordinate (1-3)" read traj_kind z_coor echo $traj_kind $z_coor >> _inp_ fi if [ "$mode" -eq 3 ] then echo "Label used for run-id & file name extention (12 characters):" read lab echo $lab >> _inp_ fi ans=f if [ "$mode" -eq 1 ] then while [ "$ans" != 'n' ] do echo "Define source location (long.deg lati.deg)" read s_long s_lati echo "Define height of release" read h_rel echo "Label used for run-id & file name extention (12 characters):" read lab if [ "$ans" == 'f' ] then echo $s_long >> _inp_ echo $s_lati >> _inp_ echo $h_rel >> _inp_ echo $lab >> _inp_ else echo $s_long $s_lati $h_rel $lab >> _inp_ fi echo "Do you want to define other sources (y/n)?" read ans done fi if [ "$mode" -eq 2 ] then echo "Define source location lower left (long.deg lati.deg) and upper right (long.deg, lati.deg)" read l_long l_lati r_long r_lati echo $l_long >> _inp_ echo $l_lati >> _inp_ echo $r_long >> _inp_ echo $r_lati >> _inp_ echo "Specify distance in grid coordinates (lon,lat)" read o_dist a_dist echo $o_dist >> _inp_ echo $a_dist >> _inp_ echo "Define low and upper levels of release height and interval in z-coordinates" read low_z upp_z z_int echo $low_z >> _inp_ echo $upp_z >> _inp_ echo $z_int >> _inp_ echo "Label used for run-id & file name extention (12 characters):" read lab echo $lab >> _inp_ fi if [ "$mode" -eq 3 ] then

Page 39: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

37

while [ "$ans" != 'n' ] do echo "Start date of release (or end date for backward trajectories) YYYYMMDD and hour HHMISS" read start_date start_hour echo "Define source location (long.deg lati.deg)" read s_long s_lati echo "Define height of release" read h_rel if [ "$ans" == 'f' ] then echo $start_date >> _inp_ echo $start_hour >> _inp_ echo $s_long >> _inp_ echo $s_lati >> _inp_ echo $h_rel >> _inp_ else echo $start_date $start_hour $s_long $s_lati $h_rel >> _inp_ fi echo "Do you want to define other sources (y/n)?" read ans done fi echo "cat AVAILABLE.head _available_ > meteo/AVAILABLE" > flextra_sh_run.sh echo " ./FLEXTRA < __in__ > $lab.out 2>&1 " >> flextra_sh_run.sh ./prep_inp.pl $mode $if_advanced $no_ensemble < _inp_ sed -f sed_fil_com < COMMAND.template > COMMAND if [ "$mode" -eq 1 ] then sed -f sed_fil_star < STARTPOINTS.template > STARTPOINTS for i in `ls sed_fil_more_*` do sed -f $i < NORMAL.more > STARTPOINTS.more cat STARTPOINTS STARTPOINTS.more > STARTPOINTS.tmp mv STARTPOINTS.tmp STARTPOINTS done fi if [ "$mode" -eq 2 ] then sed -f sed_fil_star < STARTCET.template > STARTCET fi if [ "$mode" -eq 3 ] then sed -f sed_fil_star < STARTFLIGHT.template > STARTFLIGHT for i in `ls sed_fil_more_*` do sed -f $i < FLIGHT.more > STARTFLIGHT.more cat STARTFLIGHT STARTFLIGHT.more > STARTFLIGHT.tmp mv STARTFLIGHT.tmp STARTFLIGHT done fi

Page 40: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

38

2. Script prep_inp.pl

#!/usr/bin/perl use IO::File; if($#ARGV < 2) { print "Usage: $0 mode if_advanced no_ensemble\n"; exit; } $mode=$ARGV[0]; $if_advanced=$ARGV[1]; $no_ensemble=$ARGV[2]; @command=([8,'TEST'],[12,'00'],[16,'HHHMISS'],[20,'YYYYMMDDHHMISS'],[24,'YYYYMMDD HHMISS'],[28,'HHHMISS'],[36, '00000 ddd.ddd t.ttt u.uuu v.vvv w.www'],[52,1] ); @adv_com = ( [40,1],[44,' 5.00'],[48,' 5.00'] ); @adv_traj_nor = ( [33,1],[36,2] ); @adv_traj_cet = ( [33,1],[34,2] ); @adv_traj_fli = ( [29,1],[30,2] ); @st_point = ( [27,'long.deg'],[30,'lati.deg'],[39,'zzzzz.0'],[42,'TEST'] ); @st_fligh=([28,'FLIGHT01'],[32,'YYYYMMDD'],[32,'HHMISS'],[33,'lon.deg'],[34,'lat.deg'],[35,'zzzz.0'] ); @st_cet=([27,'llo.deg'],[28,'lla.deg'],[29,'uro.deg'],[30,'ura.deg'],[31,'od.deg'],[32,'ad.deg'],[35,'low_z.0'],[36,'upp_z.0'],[37,'int_z.0'],[38,'TESTCET'] ); @format_st=(['%8.3f','%8.3f','%7.1f','%s'],['%7.3f','%7.3f','%7.3f','%7.3f','%6.3f','%6.3f','%7.1f','%7.1f','%7.1f','%6s'], ['%8s','','','%7.3f','%7.3f','%6.1f']); @more_nor = ( [1,'long.deg'],[4,'lati.deg'],[13,'zzzzz.0'],[16,'TEST'] ); @more_fli=([1,'YYYYMMDD'],[1,'HHMISS'],[2,'lon.deg'],[3,'lat.deg'],[4,'zzzz.0'] ); @st = ([@st_point,],[@st_cet,],[@st_fligh]); @counts = ( scalar @st_point, scalar @st_cet, scalar @st_fligh); open(SED,"> sed_fil_com") || die "Can't open sed file COMMAND: $!\n"; $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} print SED "$command[0][0]s/$command[0][1]/$_/\n"; $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} if($_ < 0) { print SED "$command[1][0]s/$command[1][1]/-1/\n"; } else { print SED "$command[1][0]s/$command[1][1]/ 1/\n"; } $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} print SED "$command[2][0]s/$command[2][1]/$_/\n"; if ($if_advanced == 1) { $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} @tab=split(/\s+/,$_); print SED "$adv_com[0][0]s/$adv_com[0][1]/$tab[0]/\n"; if($#tab > 0) { $tmp=sprintf("%6.2f",$tab[1]); print SED "$adv_com[1][0]s/$adv_com[1][1]/$tmp/\n"; } if($#tab > 1) { $tmp=sprintf("%6.2f",$tab[2]); print SED "$adv_com[2][0]s/$adv_com[2][1]/$tmp/\n"; } }

Page 41: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

39

$_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} $i=0; @tab=split(/\s+/,$_); print SED "$command[3][0]s/$command[3][1]/$tab[0] $tab[1]/\n"; $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} @tab=split(/\s+/,$_); print SED "$command[4][0]s/$command[4][1]/$tab[0] $tab[1]/\n"; $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} print SED "$command[5][0]s/$command[5][1]/$_/\n"; if($no_ensemble > 0) { $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} @tab=split(/\s+/,$_); $val=sprintf("%05d",$ARGV[2]); for($i=0; $i<5; $i++) { if( $i == 0) { $tmp=sprintf("%7.3f",$tab[$i]); } else {$tmp=sprintf("%5.3f",$tab[$i]);} $val="$val $tmp"; } print SED "$command[6][0]s/$command[6][1]/$val/\n"; } else { print SED "$command[6][0]s/$command[6][1]/00000 000.500 1.000 0.080 0.080 0.200/\n"; } print SED "$command[7][0]s/$command[7][1]/$ARGV[0]/\n"; close SED; open(SEDST,"> sed_fil_star") || die "Can't open sed file START: $!\n"; if($if_advanced == 1) { $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} @tab=split(/\s+/,$_); if($mode == 1) { print SEDST "$adv_traj_nor[0][0]s/$adv_traj_nor[0][1]/$tab[0]/\n"; print SEDST "$adv_traj_nor[1][0]s/$adv_traj_nor[1][1]/$tab[1]/\n"; } if($mode == 2) { print SEDST "$adv_traj_cet[0][0]s/$adv_traj_cet[0][1]/$tab[0]/\n"; print SEDST "$adv_traj_cet[1][0]s/$adv_traj_cet[1][1]/$tab[1]/\n"; } if($mode == 3) { print SEDST "$adv_traj_fli[0][0]s/$adv_traj_fli[0][1]/$tab[0]/\n"; print SEDST "$adv_traj_fli[1][0]s/$adv_traj_fli[1][1]/$tab[1]/\n"; } } $i=0; while($i < $counts[$mode-1]) { $_=<STDIN>; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} if(length($format_st[$mode-1][$i]) > 0) { $tmp=sprintf("$format_st[$mode-1][$i]",$_); print SEDST "$st[$mode-1][$i][0]s/$st[$mode-1][$i][1]/$tmp/\n"; } else { print SEDST "$st[$mode-1][$i][0]s/$st[$mode-1][$i][1]/$_/\n";

Page 42: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

40

} $i++; } close SEDST; $n=0; while(<STDIN>) { open(SEDMOR,"> sed_fil_more_$n") || die "Can't open sed file STARTmore$n: $!\n"; chop if /\n$/; if(/^\s+/) {$_=~ s/\s+(.*)/$1/;} @tab=split(/\s+/,$_); SWITCH: { if ($mode == 1 ) { for($i=0; $i <= $#more_nor; $i++) { if(length($format_st[$mode-1][$i]) > 1) { if($i == $#more_nor) { $tmp1="$tab[$i]"; for($j=$i+1; $j<= $#tab; $j++) { $tmp1=join(' ',$tmp1,$tab[$j]); } $tmp=sprintf("$format_st[$mode-1][$i]",$tmp1); print SEDMOR "$more_nor[$i][0]s/$more_nor[$i][1]/$tmp/\n"; } else { $tmp=sprintf("$format_st[$mode-1][$i]",$tab[$i]); print SEDMOR "$more_nor[$i][0]s/$more_nor[$i][1]/$tmp/\n"; } } else { print SEDMOR "$more_nor[$i][0]s/$more_nor[$i][1]/$tab[$i]/\n"; } } last SWITCH; } if ($mode == 3 ) { for($i=0; $i <= $#more_fli; $i++) { if(length($format_st[$mode-1][$i+1]) > 1) { $tmp=sprintf("$format_st[$mode-1][$i+1]",$tab[$i]); print SEDMOR "$more_fli[$i][0]s/$more_fli[$i][1]/$tmp/\n"; } else { print SEDMOR "$more_fli[$i][0]s/$more_fli[$i][1]/$tab[$i]/\n"; } } last SWITCH; } } close SEDMOR; $n++; }

Page 43: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

41

Appendix 3. WWW scripts

1. Script flextra.php

<? include("web.top"); ?> <? function input1() { echo("<form action=\"http://slawek.jrc.it/flextra/flextra.php?show=2\" method=\"post\">"); echo("Description (max. 50 characters): <Input type=\"text\" size=50 name=\"desc\"><br>"); echo("Trajectory mode: <br>"); echo("<Input type=\"radio\" name=\"mode\" value=\"1\" checked>Normal<br>"); echo("<Input type=\"radio\" name=\"mode\" value=\"2\" >CET (in area: no time series, no ensemble)<br>"); echo("<Input type=\"radio\" name=\"mode\" value=\"3\" >FLIGHT (individual specification of trajectories)<br>"); echo("Type of trajectory: <br>"); echo("<Input type=\"radio\" name=\"typ\" value=\"1\" checked>Forward<br>"); echo("<Input type=\"radio\" name=\"typ\" value=\"-1\">Backward <br>"); echo("Length of trajectory HHHMISS: <input type=\"text\" size=7 name=\"length\" value=\"0480000\" method=\"post\"> <br>"); echo("Begining date and hour: <br>"); echo("YYYYMMDD <Input type=\"text\" size=8 name=\"sdate\"> <br>"); echo("HHMISS <Input type=\"text\" size=6 name=\"shour\" > <br>"); echo("Do you need to retrieve ECMWF meteorological data ? <br>"); echo("<Input type=\"radio\" name=\"ecmwf\" value=\"1\" checked>Yes<br>"); echo("<Input type=\"radio\" name=\"ecmwf\" value=\"0\" >No (I'll use already transferred)<br>"); echo("<input type=\"reset\" value=\"Reset\">"); echo("<input type=\"submit\" value=\"OK\">"); echo("</form>"); } function input2() { $desc=$_POST["desc"]; $mode=$_POST["mode"]; $typ=$_POST["typ"]; $length=$_POST["length"]; $sdate=$_POST["sdate"]; $shour=$_POST["shour"]; $ecmwf=$_POST["ecmwf"]; echo("<form action=\"http://slawek.jrc.it/flextra/flextra.php?show=3&desc=$desc&mode=$mode&typ=$typ&sdate=$sdate&shour=$shour&length=$length&ecmwf=$ecmwf\" method=\"post\">"); if($mode != 2) { echo("End date and hour: <br>"); echo("YYYYMMDD <Input type=\"text\" size=8 name=\"edate\"> <br>"); echo("HHMISS <Input type=\"text\" size=6 name=\"ehour\" > <br>"); echo("Interval time between trajectories: <br>"); echo("HHHMISS <Input type=\"text\" size=7 name=\"interv\" > <br>"); echo("<i> Ensemble options </i><br>"); echo("Number of ensemble trajectories <Input type=\"text\" size=3 value=\"3\" name=\"noens\" > <br>"); echo("Distance in grid units for ensemble <Input type=\"text\" size=5 value=\"0.5\" name=\"dgrid\"><br>"); echo("Relative relaxation time for ensemble <Input type=\"text\" size=5 value=\"1.0\" name=\"rtime\"><br>"); echo("Errors in u,v,w for ensemble <br>"); echo("U: <Input type=\"text\" size=5 value=\"0.08\" name=\"uerr\"><br>"); echo("V: <Input type=\"text\" size=5 value=\"0.08\" name=\"verr\"><br>"); echo("W: <Input type=\"text\" size=5 value=\"0.2\" name=\"werr\"><br>"); } echo("<b><br> Advanced options: <br></b>"); echo("Interpolation type : <br>"); echo("<Input type=\"radio\" name=\"interp\" value=\"1\" checked>Ideal<br>"); echo("<Input type=\"radio\" name=\"interp\" value=\"2\">Linear<br>");

Page 44: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

42

echo("CFL parameters <br>"); echo("CFL: <Input type=\"text\" size=5 value=\"5.0\" name=\"cfl\"><br>"); echo("CFLT: <Input type=\"text\" size=5 value=\"5.0\" name=\"cflt\"><br>"); echo("Kind of trajectory: <br>"); echo("<Input type=\"radio\" name=\"kind\" value=\"1\" checked>3-D <br>"); echo("<Input type=\"radio\" name=\"kind\" value=\"2\">on model layer <br>"); echo("<Input type=\"radio\" name=\"kind\" value=\"3\">mixing layer <br>"); echo("<Input type=\"radio\" name=\"kind\" value=\"4\">isobaric <br>"); echo("<Input type=\"radio\" name=\"kind\" value=\"5\">isentropic<br>"); echo("Units of z-coordinate (for mixing layer trajectory units are always in meters above grond): <br>"); echo("<Input type=\"radio\" name=\"zunit\" value=\"1\">meters above sea level <br>"); echo("<Input type=\"radio\" name=\"zunit\" value=\"2\" checked>meters above ground <br>"); echo("<Input type=\"radio\" name=\"zunit\" value=\"3\">hectopascal <br><br>"); echo("<input type=\"reset\" value=\"Reset\">"); echo("<input type=\"submit\" value=\"OK\">"); echo("</form>"); } function input3() { $desc=$_GET["desc"]; $mode=$_GET["mode"]; $typ=$_GET["typ"]; $length=$_GET["length"]; $sdate=$_GET["sdate"]; $shour=$_GET["shour"]; $ecmwf=$_GET["ecmwf"]; $edate=$_POST["edate"]; $ehour=$_POST["ehour"]; $interv=$_POST["interv"]; $noens=$_POST["noens"]; $dgrid=$_POST["dgrid"]; $rtime=$_POST["rtime"]; $uerr=$_POST["uerr"]; $verr=$_POST["verr"]; $werr=$_POST["werr"]; $interp=$_POST["interp"]; $cfl=$_POST["cfl"]; $cflt=$_POST["cflt"]; $kind=$_POST["kind"]; $zunit=$_POST["zunit"]; echo("<form action=\"http://slawek.jrc.it/flextra/flextra.php?show=4&desc=$desc&mode=$mode&typ=$typ&length=$length&sdate=$sdate&shour=$shour&ecmwf=$ecmwf&edate=$edate&ehour=$ehour&interv=$interv&noens=$noens&dgrid=$dgrid&rtime=$rtime&uerr=$uerr&verr=$verr&werr=$werr&interp=$interp&cfl=$cfl&cflt=$cflt&kind=$kind&zunit=$zunit\" method=\"post\">"); echo(" <b> Source definition </b><br>"); switch($mode) { case 1: // Normal echo("Longitude and latitude: <input type=\"text\" size=6 name=\"slong\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"slat\" method=\"post\"> <br>"); echo("Height: <input type=\"text\" size=5 name=\"height\" method=\"post\"> <br>"); echo("Label used for run-id & file name extention: <input type=\"text\" size=12 name=\"label\" method=\"post\"> <br>"); echo("Number of additional source points: <input type=\"text\" size=3 name=\"nosource\" method=\"post\"> <br>"); break; case 2: // CET echo("Longitude and latitude left down: <input type=\"text\" size=6 name=\"slong1\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"slat1\" method=\"post\"> <br>"); echo("Longitude and latitude right up: <input type=\"text\" size=6 name=\"slong2\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"slat2\" method=\"post\"> <br>"); echo("Distance in grid coordinates (lon,lat): <input type=\"text\" size=6 name=\"odist\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"adist\" method=\"post\"> <br>");

Page 45: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

43

echo("Height low, up, interval: <input type=\"text\" name=\"height1\" method=\"post\"> "); echo(" <input type=\"text\" size=6 name=\"height2\" method=\"post\"> "); echo(" <input type=\"text\" size=6 name=\"hinterv\" method=\"post\"> <br>"); echo("Label used for run-id & file name extention: <input type=\"text\" size=12 name=\"label\" method=\"post\"> <br>"); break; case 3: //FLIGHT echo("Label used for run-id & file name extention: <input type=\"text\" size=12 name=\"label\" method=\"post\"> <br>"); echo("Start date and hour: <br>"); echo("YYYYMMDD <Input type=\"text\" size=8 name=\"sfdate\"> <br>"); echo("HHMISS <Input type=\"text\" size=6 name=\"sfhour\" > <br>"); echo("Longitude and latitude: <input type=\"text\" size=6 name=\"slong\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"slat\" method=\"post\"> <br>"); echo("Height: <input type=\"text\" name=\"height\" method=\"post\"> <br>"); echo("Number of additional source points: <input type=\"text\" size=3 name=\"nosource\" method=\"post\"> <br>"); break; } echo("<input type=\"reset\" value=\"Reset\">"); echo("<input type=\"submit\" value=\"OK\">"); echo("</form>"); } $show=$_GET["show"]; if($show == "") {$show=1;} echo("<h3> FLEXTRA input [$show]</h3><br><br>"); switch ($show) { case 1: // first screen input input1(); break; case 2: input2(); break; case 3: input3(); break; case 4: $mode=$_GET["mode"]; $noens=$_GET["noens"]; $typ=$_GET["typ"]; $sdate=$_GET["sdate"]; $shour=$_GET["shour"]; $ecmwf=$_GET["ecmwf"]; $edate=$_GET["edate"]; $ehour=$_GET["ehour"]; $length=$_GET["length"]; $han=fopen("/tmp/flextra_php.sh","w"); fwrite($han,"./prep_inp_php.sh $mode 1 $noens"); fclose($han); $han=fopen("/tmp/flextra_php_met.sh","w"); if($mode != 2) { fwrite($han,"./prep_met.pl $sdate $shour $edate $ehour $length $typ $ecmwf"); } else { fwrite($han,"./prep_met.pl $sdate $shour $sdate $shour $length $typ $ecmwf"); } fclose($han); $label=$_POST["label"]; $han=fopen("/tmp/flextra_php_run.sh","w"); fwrite($han,"cat AVAILABLE.head _available_ > meteo/AVAILABLE\n"); fwrite($han," ./FLEXTRA < __in__ > out.$label 2>&1 "); fclose($han); $han=fopen("/tmp/flextra_php.in","w"); # echo(" Post: <br>"); # foreach($_POST as $val) { # echo("$val <br>"); # fwrite($han,"$val\n");

Page 46: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

44

# } # echo(" Get: <br>"); # foreach($_GET as $val) { # echo("$val <br>"); # fwrite($han,"$val\n"); # } fwrite($han,$_GET["desc"] . "\n"); fwrite($han,$_GET["typ"] . "\n"); fwrite($han,$_GET["length"] . "\n"); fwrite($han,$_GET["interp"] . " " . $_GET["cfl"] . " " . $_GET["cflt"] . "\n"); fwrite($han,$_GET["sdate"] . " " . $_GET["shour"] . "\n"); if( $mode != 2 ) { fwrite($han,$_GET["edate"] . " " . $_GET["ehour"] . "\n"); fwrite($han,$_GET["interv"] . "\n"); fwrite($han,$_GET["dgrid"] . " " . $_GET["rtime"] . " " . $_GET["uerr"] . " " . $_GET["verr"] . " " . $_GET["werr"] . "\n"); } else { fwrite($han,$_GET["sdate"] . " " . $_GET["shour"] . "\n"); fwrite($han,"0030000\n"); } fwrite($han,$_GET["kind"] . " " . $_GET["zunit"] . "\n"); if($mode == 3) { fwrite($han,$_POST["label"] . "\n"); } if($mode == 1) { fwrite($han,$_POST["slong"] . "\n"); fwrite($han,$_POST["slat"] . "\n"); fwrite($han,$_POST["height"] . "\n"); fwrite($han,$_POST["label"] . "\n"); } if($mode == 2) { fwrite($han,$_POST["slong1"] . "\n"); fwrite($han,$_POST["slat1"] . "\n"); fwrite($han,$_POST["slong2"] . "\n"); fwrite($han,$_POST["slat2"] . "\n"); fwrite($han,$_POST["odist"] . "\n"); fwrite($han,$_POST["adist"] . "\n"); fwrite($han,$_POST["height1"] . "\n"); fwrite($han,$_POST["height2"] . "\n"); fwrite($han,$_POST["hinterv"] . "\n"); fwrite($han,$_POST["label"] . "\n"); } if($mode ==3) { fwrite($han,$_GET["sdate"] . "\n"); fwrite($han,$_GET["shour"] . "\n"); fwrite($han,$_POST["slong"] . "\n"); fwrite($han,$_POST["slat"] . "\n"); fwrite($han,$_POST["height"] . "\n"); } fclose($han); $nosource=$_POST["nosource"]; if(($mode != 2) && ($nosource > 1)) { echo("<form action=\"http://slawek.jrc.it/flextra/flextra.php?show=5&nosource=$nosource&mode=$mode&label=$label\" method=\"post\">"); for($i=1; $i<= $nosource; $i++) { echo("Additional source #: $i <br>"); if($mode == 1) { echo("Longitude and latitude: <input type=\"text\" size=6 name=\"slong$i\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"slat$i\" method=\"post\"> <br>"); echo("Height: <input type=\"text\" size=5 name=\"height$i\" method=\"post\"> <br>"); echo("Label: <input type=\"text\" size=40 name=\"label$i\" method=\"post\"> <br>"); } else { echo("Start date and hour: <br>"); echo("YYYYMMDD <Input type=\"text\" size=8 name=\"sfdate$i\"> <br>"); echo("HHMISS <Input type=\"text\" size=6 name=\"sfhour$i\" > <br>");

Page 47: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

45

echo("Longitude and latitude: <input type=\"text\" size=6 name=\"slong$i\" method=\"post\">"); echo(" <input type=\"text\" size=6 name=\"slat$i\" method=\"post\"> <br>"); echo("Height: <input type=\"text\" name=\"height$i\" method=\"post\"> <br>"); } } echo("<input type=\"reset\" value=\"Reset\">"); echo("<input type=\"submit\" value=\"OK\">"); echo("</form>"); } else { echo("End of input data for FLEXTRA run: data are transferred to shell scripts <br>"); echo("Output file will be: out.{label} <br>"); switch($mode) { case 1: echo("Results will be in the files: T_{label} and TI_{label} <br>"); break; case 2: echo("Results will be in the files: CET_{label} and CETI_{label} <br>"); break; case 3: echo("Results will be in the files: FLIGHT_{label} and FLIGHTI_{label} <br>"); break; default: echo("Error: this screen shouldn't have appeared <br>"); break; } } break; case 5: $han=fopen("/tmp/flextra_php.in","a"); $nosource=$_GET["nosource"]; $mode=$_GET["mode"]; $label=$_GET["label"]; # echo(" mode, #source: $mode $nosource <br>"); for($i=1; $i<= $nosource; $i++) { if($mode == 1) { $slong=$_POST["slong$i"]; $slat =$_POST["slat$i"]; $height=$_POST["height$i"]; $label=$_POST["label$i"]; fwrite($han,"$slong $slat $height $label \n"); # echo("source $i: $slong $slat $height $label \n"); } else { $sfdate=$_POST["sfdate$i"]; $sfhour=$_POST["sfhour$i"]; $slong=$_POST["slong$i"]; $slat =$_POST["slat$i"]; $height=$_POST["height$i"]; fwrite($han,"$sfdate $sfhour $slong $slat $height \n"); } } fclose($han); echo("End of input data for FLEXTRA run: data are transferred to shell scripts <br>"); echo("Output file will be: out.{label} <br>"); switch($mode) { case 1: echo("Results will be in the files: T_$label and TI_$label <br>"); break; case 2: echo("Results will be in the files: CET_$label and CETI_$label <br>"); break; case 3: echo("Results will be in the files: FLIGHT_$label and FLIGHTI_$label <br>"); break; default: echo("Error: this screen shouldn't have appeared <br>"); break; }

Page 48: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

46

echo("Results will be available under the output directory of the current page <br>"); break; default: input1(); break; } ?> <? include("web.bot"); ?>

web.top file

<html> <head> <title>FLEXTRA simulations</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#D8FEF2" >

web.bot file </body> </html>

2. Script prep_inp_php.sh #!/bin/sh mode=$1 if_advanced=$2 no_ensemble=$3 rm -f _inp_ touch _inp_ rm -f sed_fil_more_* cp /tmp/flextra_php.in . ./prep_inp.pl $mode $if_advanced $no_ensemble < flextra_php.in sed -f sed_fil_com < COMMAND.template > COMMAND if [ "$mode" -eq 1 ] then sed -f sed_fil_star < STARTPOINTS.template > STARTPOINTS for i in `ls sed_fil_more_*` do sed -f $i < NORMAL.more > STARTPOINTS.more cat STARTPOINTS STARTPOINTS.more > STARTPOINTS.tmp mv STARTPOINTS.tmp STARTPOINTS done fi if [ "$mode" -eq 2 ] then sed -f sed_fil_star < STARTCET.template > STARTCET fi if [ "$mode" -eq 3 ] then sed -f sed_fil_star < STARTFLIGHT.template > STARTFLIGHT for i in `ls sed_fil_more_*` do sed -f $i < FLIGHT.more > STARTFLIGHT.more cat STARTFLIGHT STARTFLIGHT.more > STARTFLIGHT.tmp mv STARTFLIGHT.tmp STARTFLIGHT done fi

Page 49: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

47

Appendix 4. Meteorological data preparation scripts

1. Script prep_met.pl #!/usr/bin/perl if($#ARGV < 6) { print "Usage: $0 begin_date begin_hour end_date end_hour trajector_length traj_type ecmwf\n"; exit; } $b_year=substr($ARGV[0],0,4); $b_month=substr($ARGV[0],4,2); $b_day=substr($ARGV[0],6,2); $b_hour=substr($ARGV[1],0,2); $b_min=substr($ARGV[1],2,2); $b_sec=substr($ARGV[1],4,2); $e_year=substr($ARGV[2],0,4); $e_month=substr($ARGV[2],4,2); $e_day=substr($ARGV[2],6,2); $e_hour=substr($ARGV[3],0,2); $e_min=substr($ARGV[3],2,2); $e_sec=substr($ARGV[3],4,2); $l_hour=substr($ARGV[4],0,3); $l_min=substr($ARGV[4],3,2); $l_sec=substr($ARGV[4],5,2); $traj_typ=$ARGV[5]; $ecmwf=$ARGV[6]; # Argument no 6 shows if met data are to be retrieved from ECMWF (0=no) @syn_h= (0,3,6,9,12,15,18,21); @months=(31,28,31,30,31,30,31,31,30,31,30,31); $sec_b=$b_hour*3600+$b_min*60+$b_sec; $sec_e=$e_hour*3600+$e_min*60+$e_sec; $sec_l=$l_hour*3600+$l_min*60+$l_sec; #$b_day_0=($b_hour==0 && $b_min==0 && $b_sec==0)?$b_day+1:$b_day+1; $b_day_0=$b_day+1; $e_day_0=$e_day; if($traj_typ >=0) { $sec_e0=$sec_l+$sec_e; $sec_b0=24*3600-$sec_b; } else { $sec_b0=$sec_l+24*3600-$sec_b; $sec_e0=$sec_e; } #print "$sec_b0 $sec_e0\n"; $ee_d=$sec_e0%(24*3600); $no_d_e=($sec_e0-$ee_d)/(24*3600); $ee_h=$ee_d%3600; $no_h_e=($ee_d-$ee_h)/3600; #print "$ee_d $ee_h $no_d_e $no_h_e\n"; if($ee_h > 0 ) { $no_h_e=$no_h_e+1;} #print "$ee_d $ee_h $no_d_e $no_h_e\n"; $bb_d=$sec_b0%(24*3600); $no_d_b=($sec_b0-$bb_d)/(24*3600); $bb_h=$bb_d%3600; $no_h_b=($bb_d-$bb_h)/3600; #print "$bb_d $bb_h $no_d_b $no_h_b\n"; if($bb_h > 0 ) { $no_h_b=$no_h_b+1;} #print "$bb_d $bb_h $no_d_b $no_h_b\n"; $e_day_1=$e_day_0+$no_d_e; $b_day_1=$b_day_0-$no_d_b; #print "$b_day_1\n";

Page 50: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

48

if($no_h_e > 23) { $e_day_1=$e_day_1+1; $no_h_e=$no_h_e%24; } $ind_syn_h=($no_h_e%3 == 0) ? $no_h_e/3 : (3+$no_h_e-$no_h_e%3)/3; $syn_h2=$syn_h[$ind_syn_h]; if($no_h_b > 23) { $b_day_1=$b_day_1-1; $no_h_b=$no_h_b%24; } if($no_h_b > 0) { $b_day_1=$b_day_1-1; $no_h_b=24-$no_h_b; } #print "$b_day_1\n"; $ind_syn_h=($no_h_b%3 == 0) ? $no_h_b/3 : ($no_h_b-$no_h_b%3)/3; $syn_h1=$syn_h[$ind_syn_h]; #print "$b_day_1 $syn_h1 $e_day_1 $syn_h2\n"; if($sec_e0%10800 == 0) { $syn_h2=$syn_h2+3; } if($sec_b0%10800 == 0) { $syn_h1=$syn_h1-3; } if($syn_h2>21) { $syn_h2=0; $e_day_1=$e_day_1+1; } if($syn_h1<0) { $syn_h1=21; $b_day_1=$b_day_1-1; } $start_year=$b_year; $start_month=$b_month; if($b_day_1 <= 0) { $start_month=$start_month-1; if($start_month == 0) { $start_year=$start_year-1; $start_month=12; } $start_day=$months[$start_month-1]+$b_day_1; if($start_year%4 == 0 && $start_month == 2) {$start_day=$start_day+1;} } else { $start_day=$b_day_1; } $end_year=$e_year; $end_month=$e_month; if($end_year%4 ==0 && $end_month==2) {$months[1] = 29;} if($e_day_1 > $months[$end_month-1]) { $end_day=$e_day_1-$months[$end_month-1]; $end_month=$end_month+1; if($end_month == 13) { $end_year=$end_year+1; $end_month=1; } } else { $end_day = $e_day_1; } if(length($start_month) < 2) { $start_month="0$start_month";} if(length($start_day) < 2) { $start_day="0$start_day";} if(length($syn_h1) < 2) { $syn_h1="0$syn_h1";} if(length($end_month) < 2) { $end_month="0$end_month";} if(length($end_day) < 2) { $end_day="0$end_day";} if(length($syn_h2) < 2) { $syn_h2="0$syn_h2";}

Page 51: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

49

print "$start_year$start_month$start_day ${syn_h1}0000\n"; print "$end_year$end_month$end_day ${syn_h2}0000\n"; open(AVA,"> _available_") || die "Can't open _available_ file: $!\n"; $yy=$start_year; $mo=$start_month; $da=$start_day; $hh=$syn_h1; $n=0; $fh=$syn_h1; $retr_ym[0] = "$start_year" . "-$start_month"; $retr_d[0] = $start_day; if($fh%12 == 0) { $retr_t[0] = $fh; } else { while($fh%12 != 0) { $fh=$fh-3 ;} $retr_t[0] = $fh; } $retr_st[0] = $hh - $fh; $first=0; while($yy != $end_year || $mo != $end_month || $da != $end_day || $hh != $syn_h2) { if(length($mo) < 2) { $mo="0$mo";} if(length($da) < 2) { $da="0$da";} if(length($hh) < 2) { $hh="0$hh";} print AVA "$yy$mo$da ${hh}0000 $yy$mo$da$hh on disc\n"; if($first != 0 ) { if($retr_d[$n] == $da) { if($hh == 12) { $n = $n + 1; $retr_ym[$n] = "$yy" . "-$mo"; $retr_d[$n] = $da; $retr_t[$n] = "12"; $retr_st[$n] = "0"; $fh = 12; } else { $s=$hh-$fh; $retr_st[$n] = "$retr_st[$n]/$s"; } } else { $n=$n+1; $retr_ym[$n] = "$yy" . "-$mo"; $retr_d[$n] = $da; $retr_t[$n] = "0"; $retr_st[$n] = "0"; $fh = 0; } } else { $first=1; } $hh=$hh+3; if($hh > 21) { $hh=0; $da=$da+1; if($year%4 == 0) { $months[1] = 29;} if($da > $months[$mo-1]) { $mo=$mo+1; $da=1; } if($mo > 12) { $mo=1; $yy=$yy+1; } } }

Page 52: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

50

if(length($mo) < 2) { $mo="0$mo";} if(length($da) < 2) { $da="0$da";} if(length($hh) < 2) { $hh="0$hh";} print AVA "$yy$mo$da ${hh}0000 $yy$mo$da$hh on disc\n"; close AVA; if($retr_d[$n] == $da) { if($hh == 12) { $n = $n + 1; $retr_ym[$n] = "$yy" . "-$mo"; $retr_d[$n] = $da; $retr_t[$n] = "12"; $retr_st[$n] = "0"; $fh = 12; } else { $s=$hh-$fh; $retr_st[$n] = "$retr_st[$n]/$s"; } } else { $n=$n+1; $retr_ym[$n] = "$yy" . "-$mo"; $retr_d[$n] = $da; $retr_t[$n] = "0"; $retr_st[$n] = "0"; $fh = 0; } if(($start_year > 2002) || ($start_year == 2002 && $start_month > 8)) { $if_new = 1; } else { $if_new = 0; } if(($if_new == 1)) { open(RETR,"> _retr_ml_") || die "Can't open _retr_ml_ file: $!\n"; open(RETRS,"> _retr_sfc_") || die "Can't open _retr_sfc_ file: $!\n"; print RETR "retrieve,\n"; print RETR " class = od,\n"; print RETR " stream = oper,\n"; print RETR " expver = 1,\n"; print RETR " date = $retr_ym[0]" . "-$retr_d[0],\n"; print RETR " time = $retr_t[0],\n"; $_=$retr_st[0]; $_=~ s/0\///; $ss=$_; $_=$ss; $_=~ s/6\///; $ss=$_; print RETR " step = $ss,\n"; print RETR " type = fc,\n"; print RETR " levtype = ml,\n"; print RETR " levelist = 20/to/60,\n"; print RETR " param = 130/131/132/135,\n"; print RETR " grid = 0.5/0.5,\n"; print RETR " area = 75/-15/30/60,\n"; print RETR " use = infrequent,\n"; print RETR " target = \"scratchdir/out_ml_fc3.grb\"\n"; print RETRS "retrieve,\n"; print RETRS " class = od,\n"; print RETRS " stream = oper,\n"; print RETRS " expver = 1,\n"; print RETRS " date = $retr_ym[0]" . "-$retr_d[0],\n"; print RETRS " time = $retr_t[0],\n"; print RETRS " step = $ss,\n"; print RETRS " type = fc,\n"; print RETRS " levtype = sfc,\n"; print RETRS " param = 134,\n";

Page 53: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

51

print RETRS " grid = 0.5/0.5,\n"; print RETRS " area = 75/-15/30/60,\n"; print RETRS " use = infrequent,\n"; print RETRS " target = \"scratchdir/out_sfc_fc3.grb\"\n"; for($i=1; $i <= $n; $i ++ ) { if($retr_st[$i] ne "0" ) { $_=$retr_st[$i]; $_=~ s/0\///; $ss=$_; $_=$ss; $_=~ s/6\///; $ss=$_; print RETR "retrieve,\n"; print RETR " date = $retr_ym[$i]" . "-$retr_d[$i],\n"; print RETR " time = $retr_t[$i],\n"; print RETR " step = $ss,\n"; print RETR " target = \"scratchdir/out_ml_fc3.grb\"\n"; print RETRS "retrieve,\n"; print RETRS " date = $retr_ym[$i]" . "-$retr_d[$i],\n"; print RETRS " time = $retr_t[$i],\n"; print RETRS " step = $ss,\n"; print RETRS " target = \"scratchdir/out_sfc_fc3.grb\"\n"; } } close RETR; close RETRS; } if($syn_h1%6 != 0) { $syn_h1=$syn_h1-3; } if($syn_h2%6 != 0) { $syn_h2=$syn_h2+3; } if(length($syn_h1) < 2) { $syn_h1="0$syn_h1";} if(length($syn_h2) < 2) { $syn_h2="0$syn_h2";} print "6-h start: $start_year$start_month$start_day ${syn_h1}0000\n"; print "6-h end: $end_year$end_month$end_day ${syn_h2}0000\n"; $yy=$start_year; $mo=$start_month; $da=$start_day; $hh=$syn_h1; $first=0; $n=0; if ($if_new == 0) { open(AVA,"> _available_") || die "Can't open _available_ file: $!\n"; } while($yy != $end_year || $mo != $end_month || $da != $end_day || $hh != $syn_h2) { if(length($mo) < 2) { $mo="0$mo";} if(length($da) < 2) { $da="0$da";} if(length($hh) < 2) { $hh="0$hh";} print "$yy$mo$da ${hh}0000\n"; if ($if_new == 0) { print AVA "$yy$mo$da ${hh}0000 $yy$mo$da$hh on disc\n"; } if($first == 0) { $retr_ym[0] = "$yy" . "-$mo"; $retr_d[0] = $da; $retr_t[0] = $hh; $first = 1; } else { if($da == $retr_d[$n]) { $retr_t[$n] = "$retr_t[$n]/$hh"; }

Page 54: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

52

else { $n=$n+1; $retr_ym[$n] = "$yy" . "-$mo"; $retr_d[$n] = $da; $retr_t[$n] = $hh; } } $hh=$hh+6; if($hh > 21) { $hh=0; $da=$da+1; if($year%4 == 0) { $months[1] = 29;} if($da > $months[$mo-1]) { $mo=$mo+1; $da=1; } if($mo > 12) { $mo=1; $yy=$yy+1; } } } if(length($mo) < 2) { $mo="0$mo";} if(length($da) < 2) { $da="0$da";} if(length($hh) < 2) { $hh="0$hh";} print "$yy$mo$da ${hh}0000\n"; if ($if_new == 0) { print AVA "$yy$mo$da ${hh}0000 $yy$mo$da$hh on disc\n"; close AVA; } if($da == $retr_d[$n]) { $retr_t[$n] = "$retr_t[$n]/$hh"; } else { $n=$n+1; $retr_ym[$n] = "$yy" . "-$mo"; $retr_d[$n] = $da; $retr_t[$n] = $hh; } open(RETR,"> _retr6_ml_") || die "Can't open _retr6_ml_ file: $!\n"; open(RETRS,"> _retr6_sfc_") || die "Can't open _retr6_sfc_ file: $!\n"; print RETR "retrieve,\n"; if ($if_new == 0) { print RETR " class = e4,\n"; } else { print RETR " class = od,\n"; } print RETR " stream = oper,\n"; print RETR " expver = 1,\n"; print RETR " date = $retr_ym[0]" . "-$retr_d[0],\n"; if(length($retr_t[0]) == 1) {$retr_t[0] = "0$retr_t[0]";} print RETR " time = $retr_t[0],\n"; print RETR " type = an,\n"; print RETR " levtype = ml,\n"; print RETR " levelist = 20/to/60,\n"; print RETR " param = 130/131/132/135,\n"; print RETR " grid = 0.5/0.5,\n"; print RETR " area = 75/-15/30/60,\n"; print RETR " use = infrequent,\n"; print RETR " target = \"scratchdir/out_ml_fc6.grb\"\n"; print RETRS "retrieve,\n"; if ($if_new == 0) { print RETRS " class = e4,\n"; } else {

Page 55: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

53

print RETRS " class = od,\n"; } print RETRS " stream = oper,\n"; print RETRS " expver = 1,\n"; print RETRS " date = $retr_ym[0]" . "-$retr_d[0],\n"; print RETRS " time = $retr_t[0],\n"; print RETRS " type = an,\n"; print RETRS " levtype = sfc,\n"; if ($if_new == 0) { print RETRS " param = 52,\n"; } else { print RETRS " param = 134,\n"; } print RETRS " grid = 0.5/0.5,\n"; print RETRS " area = 75/-15/30/60,\n"; print RETRS " use = infrequent,\n"; print RETRS " target = \"scratchdir/out_sfc_fc6.grb\"\n"; for($i=1; $i <= $n; $i ++ ) { print RETR "retrieve,\n"; print RETR " date = $retr_ym[$i]" . "-$retr_d[$i],\n"; if(length($retr_t[$i]) == 1) {$retr_t[$i] = "0$retr_t[$i]";} print RETR " time = $retr_t[$i],\n"; print RETR " target = \"scratchdir/out_ml_fc6.grb\"\n"; print RETRS "retrieve,\n"; print RETRS " date = $retr_ym[$i]" . "-$retr_d[$i],\n"; print RETRS " time = $retr_t[$i],\n"; print RETRS " target = \"scratchdir/out_sfc_fc6.grb\"\n"; } close RETR; close RETRS;

2. Examples of request files _retr_ml_ retrieve, class = od, stream = oper, expver = 1, date = 2003-04-10, time = 0, step = 9, type = fc, levtype = ml, levelist = 20/to/60, param = 130/131/132/135, grid = 0.5/0.5, area = 75/-15/30/60, use = infrequent, target = "scratchdir/out_ml_fc3.grb" retrieve, date = 2003-04-10, time = 12, step = 3/9, target = "scratchdir/out_ml_fc3.grb" retrieve, date = 2003-04-11, time = 0, step = 3/9, target = "scratchdir/out_ml_fc3.grb" retrieve, date = 2003-04-11, time = 12, step = 3/9,

Page 56: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

54

target = "scratchdir/out_ml_fc3.grb" retrieve, date = 2003-04-12, time = 0, step = 3/9, target = "scratchdir/out_ml_fc3.grb" _retr_sfc_ retrieve, class = od, stream = oper, expver = 1, date = 2003-04-10, time = 0, step = 9, type = fc, levtype = sfc, param = 134, grid = 0.5/0.5, area = 75/-15/30/60, use = infrequent, target = "scratchdir/out_sfc_fc3.grb" retrieve, date = 2003-04-10, time = 12, step = 3/9, target = "scratchdir/out_sfc_fc3.grb" retrieve, date = 2003-04-11, time = 0, step = 3/9, target = "scratchdir/out_sfc_fc3.grb" retrieve, date = 2003-04-11, time = 12, step = 3/9, target = "scratchdir/out_sfc_fc3.grb" retrieve, date = 2003-04-12, time = 0, step = 3/9, target = "scratchdir/out_sfc_fc3.grb" _retr6_ml_ retrieve, class = od, stream = oper, expver = 1, date = 2003-04-10, time = 06/12/18, type = an, levtype = ml, levelist = 20/to/60, param = 130/131/132/135, grid = 0.5/0.5, area = 75/-15/30/60, use = infrequent, target = "scratchdir/out_ml_fc6.grb" retrieve, date = 2003-04-11, time = 00/06/12/18, target = "scratchdir/out_ml_fc6.grb"

Page 57: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

55

retrieve, date = 2003-04-12, time = 00/06/12, target = "scratchdir/out_ml_fc6.grb" _retr6_sfc_ retrieve, class = od, stream = oper, expver = 1, date = 2003-04-10, time = 06/12/18, type = an, levtype = sfc, param = 134, grid = 0.5/0.5, area = 75/-15/30/60, use = infrequent, target = "scratchdir/out_sfc_fc6.grb" retrieve, date = 2003-04-11, time = 00/06/12/18, target = "scratchdir/out_sfc_fc6.grb" retrieve, date = 2003-04-12, time = 00/06/12, target = "scratchdir/out_sfc_fc6.grb" In case of data from ERA-40 archive parameter class should be set as e4. 3. Scripts for extracting grib data extract_ml.sh #!/bin/sh if [ $# -lt 2 ] then echo "Usage: $0 grib_file 19|20 " echo "i.e. name of grib file and first two digits indicating century either 19 or 20" exit 1 fi name=0 no_of_rec=`wgrib $1| wc -l` i=1 while [ $i -le $no_of_rec ] do wgrib -d $i -grib -o _tmp_.grb $1 nam_tmp=`wgrib _tmp_.grb | awk -F : '{print $3}' | sed s/d=/$2/` if [ $nam_tmp = $name ] then cat _tmp_.grb >> $name else name=$nam_tmp mv _tmp_.grb $name fi i=`expr $i + 1` done extract_sfc.sh #!/bin/sh if [ $# -lt 2 ] then

Page 58: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

56

echo "Usage: $0 grib_file 19|20 " echo "i.e. name of grib file and first two digits indicating century either 19 or 20" exit 1 fi name=0 no_of_rec=`wgrib $1| wc -l` i=1 while [ $i -le $no_of_rec ] do wgrib -d $i -grib -o _tmp_.grb $1 nam_tmp=`wgrib _tmp_.grb | awk -F : '{print $3}' | sed s/d=/$2/` if [ $nam_tmp = $name ] then cat _tmp_.grb >> $name else name=$nam_tmp cat _tmp_.grb >> $name fi i=`expr $i + 1` done extract_ml_sfc.sh #!/bin/sh if [ $# -lt 2 ] then echo "Usage: $0 grib_file 19|20 " echo "i.e. name of grib file and first two digits indicating century either 19 or 20" exit 1 fi name=0 no_of_rec=`wgrib $1| wc -l` i=1 while [ $i -le $no_of_rec ] do wgrib -d $i -grib -o _tmp_.grb $1 nam_tmp1=`wgrib _tmp_.grb | awk -F : '{print $3}' | sed s/d=/$2/` nam_tmp2=`wgrib _tmp_.grb | awk -F : '{print $13}' | awk '{print $1}' | sed s/hr//` hour=`expr $nam_tmp1 % 100` tmp=`expr $nam_tmp1 - $hour` tmp=`expr $tmp / 100` day=`expr $tmp % 100` tmp=`expr $tmp - $day` tmp=`expr $tmp / 100` month=`expr $tmp % 100` tmp=`expr $tmp - $month` year=`expr $tmp / 100` hour=`expr $hour + $nam_tmp2` if [ $hour -ge 24 ] then hour=`expr $hour % 24` day=`expr $day + 1` if [ \( $month -eq 1 \) -o \( $month -eq 3 \) -o \( $month -eq 5 \) -o \( $month -eq 7 \) -o \( $month -eq 8 \) -o \( $month -eq 10 \) ] then if [ $day -gt 31 ] then day=1 month=`expr $month + 1` fi fi if [ $month -eq 12 ]

Page 59: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

57

then if [ $day -gt 31 ] then day=1 month=1 year=`expr $year + 1` fi fi if [ \( $month -eq 4 \) -o \( $month -eq 6 \) -o \( $month -eq 9 \) -o \( $month -eq 11 \) ] then if [ $day -gt 30 ] then day=1 month=`expr $month + 1` fi fi if [ $month -eq 2 ] then yy=`expr $year % 4` if [ \( $day -gt 28 \) -a \( $yy -ne 0 \) ] then day=1 month=3 fi if [ \( $day -gt 29 \) -a \( $yy -eq 0 \) ] then day=1 month=3 fi fi fi if [ $hour -le 9 ] then hour="0$hour" fi if [ $day -le 9 ] then day="0$day" fi if [ $month -le 9 ] then month="0$month" fi nam_tmp=$year$month$day$hour if [ $nam_tmp = $name ] then cat _tmp_.grb >> $name else name=$nam_tmp cat _tmp_.grb >> $name fi i=`expr $i + 1` done 4. Example of usage extracting scripts to data obtained from request files ./extract_ml.sh out_ml_fc6.grb 20 ./extract_ml_sfc.sh out_ml_fc3.grb 20 ./extract_sfc.sh out_sfc_fc6.grb 20 ./extract_ml_sfc.sh out_sfc_fc3.grb 20 The order of commands should be such that first multilevel fields are to be processed. In the example the files named 20{date}{time} will be produced (e.g. 2003041109).

Page 60: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

58

Appendix 5. Post-processing scripts

1. Script get_res_new.pl #!/usr/bin/perl use IO::File; if($#ARGV < 3) { print "Usage: $0 prefix label mode sim_sec_from sim_sec_till \n"; exit; } ($pref,$label,$mode,$sim_sec1,$sim_sec2) = @ARGV; if($mode == 1) {$modes="Normal"}; if($mode == 2) {$modes="CET"}; if($mode == 3) {$modes="Flight"}; if ($#ARGV == 3) { $sim_sec2=864000;} @syn_h= (0,3,6,9,12,15,18,21,24); $_=<STDIN>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } ($n,@rest)=split(/\s+/,$_); print "n=$n\n"; for ($i=2; $i<$n+1; $i++) { $_=<STDIN>; } $no_of_traj = 0; $max_no_points=0; # Colors in [gnuplot, grads]: red, green, blue, magenta, cyan, orange @colors = ( [1,2],[2,3],[3,4],[4,6],[5,5],[7,8] ); # Main loop: reading trajectories and processing LINE: while (<STDIN>) { chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } @tab=split(/\s+/,$_); $no_points=$tab[$#tab]; $t_date=$tab[1]; # if(length($tab[3]) == 5) { # $tab[3]="0" . $tab[3]; # } # if(length($tab[3]) == 1) { # $tab[3]="000000"; # } $nz=length($tab[3]); if($nz < 6) { for($nn=$nz+1; $nn<7; $nn++) { $tab[3]="0" . $tab[3]; } } $t_time=$tab[3]; $s_day=substr($t_date,6,2); $s_month=substr($t_date,4,2); $s_year=substr($t_date,0,4); $s_hour=substr($t_time,0,2); $s_min=substr($t_time,2,2); $s_sec=substr($t_time,4,2); print "$s_day,$s_hour, $s_min\n"; $start_sec=3600*$s_hour+60*$s_min+$s_sec;

Page 61: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

59

$ind_syn_h=($s_hour%3 == 0) ? $s_hour/3 : (3+$s_hour-$s_hour%3)/3; $first_syn_h= $syn_h[$ind_syn_h]; print "$ind_syn_h,$first_syn_h, $start_sec\n"; print "no_of_points: $no_points\n"; $_=<STDIN>; next LINE if ($no_points <= 0); for ($i=0; $i<$no_points; $i++) { $_=<STDIN>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } @tab=split(/\s+/,$_); $sec[$i] = $tab[0]; $long[$i] = $tab[1]; $lat[$i] = $tab[2]; $z[$i] = $tab[5]; $z_oro[$i] = $tab[6]; } $height = $z_oro[0]; if ($sec[1]<0) { $l=$no_points%2; $ll=($no_points-$l)/2; # print "Changing direction: $no_points $l $ll\n"; for($i=0; $i<$ll; $i++) { $tmp = $sec[$i]; $sec[$i] = $sec[$no_points-$i-1]; $sec[$no_points-$i-1] = $tmp; $tmp = $long[$i]; $long[$i] = $long[$no_points-$i-1]; $long[$no_points-$i-1] = $tmp; $tmp = $lat[$i]; $lat[$i] = $lat[$no_points-$i-1]; $lat[$no_points-$i-1] = $tmp; $tmp = $z[$i]; $z[$i] = $z[$no_points-$i-1]; $z[$no_points-$i-1] = $tmp; $tmp = $z_oro[$i]; $z_oro[$i] = $z_oro[$no_points-$i-1]; $z_oro[$no_points-$i-1] = $tmp; } $typ = "backward"; } else { $typ = "forward"; } $last_sec=$sec[$#sec]; $sim_time = $last_sec-$sec[0]; if ( $sim_time < $sim_sec1 || $sim_time > $sim_sec2 ) { print "Simulation time: $sim_time not in the limit, skipping ...\n"; next LINE; } # next LINE if( ($sim_time < $sim_sec1) || ($sim_time > $sim_sec2) ); $tim[0]=$sec[0]; $shif=$first_syn_h*3600-$start_sec; if ($first_syn_h == 24) { $first_syn_h=0; } if($sec[0] < 0 ) { $shif1=10800-$shif; $shif=(-$sec[0]-$shif1)%10800; } $j=0; if($shif > 0 && $shif + $tim[0] <= $last_sec) { $j=1; $tim[1] = $shif + $tim[0]; }

Page 62: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

60

$i=1; while($i*10800+$shif+$tim[0] <= $last_sec) { $tim[$i+$j]=$i*10800+$shif+$tim[0]; $i++; } if($tim[$i+$j-1] != $last_sec) { $tim[$i+$j] = $last_sec; } $zmax=0; $zmin=0; $long_min = 999; $long_max = -999; $lat_min = 999; $lat_max = -999; open(PLT,">${pref}_$t_date${t_time}_$no_of_traj.plt") || die "Can't open plt file: $!\n"; open(DAT,">${pref}_$t_date${t_time}_$no_of_traj.dat") || die "Can't open dat file: $!\n"; open(TIM,">${pref}_$t_date${t_time}_$no_of_traj.tim") || die "Can't open dat file: $!\n"; open(GS,">${pref}_$t_date${t_time}_$no_of_traj.gs") || die "Can't open gs file: $!\n"; open(TXT,">${pref}_$t_date${t_time}_${no_of_traj}_._txt_") || die "Can't open txt file: $!\n"; open(XML,">${pref}_$t_date${t_time}_$no_of_traj.xml") || die "Can't open xml file: $!\n"; $color = $no_of_traj%6; print GS "'set line $colors[$color][1]'\n"; print XML "<trajectory>\n"; print XML "<sdate>$s_year-$s_month-$s_day</sdate>\n"; print XML "<stime>$s_hour:$s_min:$s_sec.000</stime>\n"; print XML "<height>$height</height>\n"; print XML "<label>$label</label>\n"; print XML "<mode>$modes</mode>\n"; if($no_points > $max_no_points) { $max_no_points = $no_points; } $day=$s_day; $month=$s_month; $year=$s_year; $hour=$s_hour; $min=$s_min; if ($tim[0] >=0) { $date_p[0] = "$s_year-$s_month-$s_day"; $time_p[0] = "$s_hour:$s_min:$s_sec.000"; for ($i=1; $i<=$#tim; $i++) { $diff=int(($tim[$i]-$tim[$i-1])/60); $min=$min+$diff; if($min > 60) { $hour=$hour + int($min/60); $min=$min%60; if($hour >= 24) { $hour=$hour-24; $day=$day+1; if($month == 2) { if($year%4 == 0 && $day>29) { $day=1; $month=3; } if($year%4 != 0 && $day>28) { $day=1; $month=3; } }

Page 63: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

61

if($month==1 || $month==3 || $month==5 || $month==7 || $month==8 || $month==10 || $month==12) { if($day>31) { $day=1; $month=$month+1; } } if($month==4 || $month==6 || $month==9|| $month==11) { if($day>30) { $day=1; $month=$month+1; } } } } if($month > 12) { $year=$year+1; $month=1; } if(length($month) == 1) {$month="0$month";} if(length($day) == 1) {$day="0$day";} if(length($min) == 1) {$min="0$min";} if(length($hour) == 1) {$hour="0$hour";} $date_p[$i] = "$year-$month-$day"; $time_p[$i] = "$hour:$min:00.000"; } } else { $date_p[$#tim] = "$s_year-$s_month-$s_day"; $time_p[$#tim] = "$s_hour:$s_min:$s_sec.000"; for ($i=$#tim-1; $i>=0; $i--) { $diff=int(($tim[$i]-$tim[$i+1])/60); $min=$min+$diff; if($min < 0) { $min=-$min; if($min%60 == 0) { $hour=$hour - int($min/60); $min=0; } else { $hour=$hour - int($min/60) -1; $min=(1+int($min/60))*60-$min; } if($hour <0) { $hour=24+$hour; $day=$day-1; if($month == 3) { if($year%4 == 0 && $day==0) { $day=29; $month=2; } if($year%4 != 0 && $day==0) { $day=28; $month=2; } } if($month==1 || $month==2 || $month==4 || $month==6 || $month==8 || $month==9 || $month==11) { if($day==0) { $day=31; $month=$month-1; } } if($month==5 || $month==7 || $month==10|| $month==12) { if($day==0) { $day=30;

Page 64: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

62

$month=$month-1; } } } } if($month <= 0) { $year=$year-1; $month=12; } if(length($month) == 1) {$month="0$month";} if(length($day) == 1) {$day="0$day";} if(length($min) == 1) {$min="0$min";} if(length($hour) == 1) {$hour="0$hour";} $date_p[$i] = "$year-$month-$day"; $time_p[$i] = "$hour:$min:00.000"; } } for ($i=0; $i<=$#tim; $i++) { $long_n[$i] = &interpol($tim[$i],$#sec,@sec,@long); $lat_n[$i] = &interpol($tim[$i],$#sec,@sec,@lat); $z_n[$i] = &interpol($tim[$i],$#sec,@sec,@z); $z_oro_n[$i] = &interpol($tim[$i],$#sec,@sec,@z_oro); print "$tim[$i] $long_n[$i] $lat_n[$i] $z_n[$i] $z_oro_n[$i]\n"; print DAT "$tim[$i] $long_n[$i] $lat_n[$i] $z_n[$i] $z_oro_n[$i]\n"; $yy=substr($date_p[$i],0,4); $mm=substr($date_p[$i],5,2); $dd=substr($date_p[$i],8,2); $hh=substr($time_p[$i],0,2); $mi=substr($time_p[$i],3,2); print TIM "$yy$mm$dd $hh$mi $long_n[$i] $lat_n[$i] $z_n[$i] $z_oro_n[$i]\n"; print XML "<point>\n"; # print XML " <sectime>$tim[$i]</sectime>\n"; print XML " <date_p>$date_p[$i]</date_p>\n"; print XML " <time_p>$time_p[$i]</time_p>\n"; print XML " <longitude>$long_n[$i]</longitude>\n"; print XML " <latitude>$lat_n[$i]</latitude>\n"; print XML " <height_asl>$z_n[$i]</height_asl>\n"; print XML " <height_agl>$z_oro_n[$i]</height_agl>\n"; print XML "</point>\n"; if($z_n[$i] > $zmax) { $zmax=$z_n[$i]; } if($z_n[$i] < $zmin) { $zmin=$z_n[$i]; } if($long_n[$i] > $long_max) { $long_max=$long_n[$i]; } if($long_n[$i] < $long_min) { $long_min=$long_n[$i]; } if($lat_n[$i] > $lat_max) { $lat_max=$lat_n[$i]; } if($lat_n[$i] < $lat_min) { $lat_min=$lat_n[$i]; } } print XML "</trajectory>\n"; close DAT; close TIM; close XML; if($tim[0] >= 0) {

Page 65: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

63

print GS "#'draw title \"Forward trajectory, start date/time:\\ $s_day.$s_month.$s_year $s_hour:$s_min\"'\n"; } else { print GS "#'draw title \"Backward trajectory, end date/time:\\ $s_day.$s_month.$s_year $s_hour:$s_min\"'\n"; } for ($i=0; $i<=$#tim; $i++) { if ($i>0) { print GS "'q ll2xy $long_n[$i-1] $lat_n[$i-1]'\n"; print GS "x_p = subwrd(result,1)\n"; print GS "y_p = subwrd(result,2)\n"; print GS "'q ll2xy $long_n[$i] $lat_n[$i]'\n"; print GS "x = subwrd(result,1)\n"; print GS "y = subwrd(result,2)\n"; print GS "'draw line 'x_p' 'y_p' 'x' 'y\n"; print GS "xm = 0.3*x_p+0.7*x\n"; print GS "ym = 0.3*y_p+0.7*y\n"; print GS "xy = (x-xm)*(x-xm)+(y-ym)*(y-ym)\n"; print GS "'define zz=0.3*sqrt('xy')'\n"; print GS "'d zz'\n"; print GS "z = subwrd(result,4)\n"; print GS "if(x=xm)\n"; print GS "'draw line 'xm-z' 'ym' 'x' 'y\n"; print GS "'draw line 'xm+z' 'ym' 'x' 'y\n"; print GS "else\n"; print GS "m=(y-ym)/(x-xm)\n"; print GS "m1=1+m*m\n"; print GS "'define sq=sqrt('m1')'\n"; print GS "'d sq'\n"; print GS "sqm = subwrd(result,4)\n"; print GS "'draw line 'xm+m*z/sqm' 'ym-z/sqm' 'x' 'y\n"; print GS "'draw line 'xm-m*z/sqm' 'ym+z/sqm' 'x' 'y\n"; print GS "endif\n"; } } close GS; $zz=(int($zmax)-(int($zmax)%1000))+1000; $zmin=$zmin<0 ? -250 : 0; if($tim[0] >= 0) { $xtic="\"$s_hour.$s_min\" $tim[0]"; for($i=1; $i< $#tim; $i++) { $hh=($shif==0) ? $first_syn_h+3*$i : $first_syn_h+3*($i-1); $h_syn=$hh%24; $xtic = "$xtic, \"$h_syn\" $tim[$i]"; } if($shif == 0) { $hh=$first_syn_h+3*$#tim; $h_syn=$hh%24; $xtic = "$xtic, \"$h_syn\" $tim[$#tim]"; } } else { $xtic="\" $s_hour.$s_min\" $tim[$#tim]"; $h_syn = $first_syn_h; for($i=$#tim-1; $i> 0; $i--) { $h_syn= $h_syn-3; if($h_syn<0) {$h_syn=21;} $xtic = "$xtic, \"$h_syn\" $tim[$i]"; } if($shif == 0) { $h_syn = $h_syn-3; if($h_syn<0) {$h_syn=21;} $xtic = "$xtic, \"$h_syn\" $tim[0]";

Page 66: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

64

} } print PLT "set xlabel \"Time \"\n"; print PLT "set ylabel \"Height [m]\"\n"; print PLT "set xrange [$sec[0]:$sec[$#sec]]\n"; print PLT "set yrange [$zmin: $zz]\n"; print PLT "set key off\n"; print PLT "set grid\n"; print PLT "set xtics ($xtic)\n"; if($tim[0] >= 0) { print PLT "set title \"Forward trajectory, height along trajectory, start date/time: $s_day.$s_month.$s_year $s_hour:$s_min\"\n"; } else { print PLT "set title \"Backward trajectory, height along trajectory, end date/time: $s_day.$s_month.$s_year $s_hour:$s_min\"\n"; } print PLT "plot '${pref}_$t_date${t_time}_$no_of_traj.dat' using 1:4 with linespoints linetype $colors[$color][0], \\\n"; print PLT " '${pref}_$t_date${t_time}_$no_of_traj.dat' using 1:(\$4-\$5) with filledcurves x1 linetype 8\n"; print PLT "# pause -1 \"Return to continue\"\n"; close PLT; print TXT "$sec[0] $sec[$#sec]\n"; print TXT "$zmin $zz\n"; print TXT "$long_min $long_max\n"; print TXT "$lat_min $lat_max\n"; print TXT "$s_year $s_month $s_day\n"; print TXT "$s_hour $s_min $s_sec\n"; close TXT; $no_of_traj = $no_of_traj + 1; @tab=(); @sec=(); @long=(); @lat=(); @z=(); @z_oro=(); @tim=(); @long_n=(); @lat_n=(); @z_n=(); @z_oro_n=(); # End of main loop (LINE:) } open(CTL,">${pref}_gra_.ctl") || die "Can't open gs file: $!\n"; print CTL "dset ^output2.grib\n"; print CTL "index ^output2.grib.idx\n"; print CTL "undef -999.0\n"; print CTL "title Trajectory\n"; print CTL "dtype grib 255\n"; print CTL "options yrev\n"; print CTL "ydef 91 linear 30.000000 0.5\n"; print CTL "xdef 151 linear -15.000000 0.500000\n"; print CTL "tdef 20 linear 00Z01aug2002 6hr\n"; print CTL "zdef 41 levels 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20\n"; print CTL "vars 4\n"; print CTL "Thbl 41 130,109,0 ** Temperature K\n"; print CTL "Uhbl 41 131,109,0 ** U-velocity m s**-1\n"; print CTL "Vhbl 41 132,109,0 ** V-velocity m s**-1\n";

Page 67: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

65

print CTL "Whbl 41 135,109,0 ** Vertical velocity Pa s**-1\n"; print CTL "ENDVARS\n"; close CTL; print "Max no of points: $max_no_points\n" ; #open(TXT,">output_tmp2.txt") || die "Can't open txt file: $!\n"; #print TXT "$max_no_points\n" ; #close TXT; #system "cat output_tmp2.txt output_tmp.txt > output_.txt"; sub find_interv { my ($point,@arr) = @_; my $f=0, $l=$#arr; my $m=($f+$l+($f+$l)%2)/2; if ($point < $arr[0]) { return -1; } if ($point > $arr[$#arr]) { return -1; } while($l-$f != 1) { if($point < $arr[$m]) { $l = $m; } else { if($point > $arr[$m]) { $f = $m; } else { return $m; } } $m=($f+$l+($f+$l)%2)/2; } return $f; } sub int_interv { my ($p,$p1,$p2) = @_; return ($p-$p1)/($p2-$p1); } sub interpol { my ($p,$n,@arr) = @_; my $i, $alf; $i = &find_interv($p,@arr[0..$n]); $alf = &int_interv($p,$arr[$i],$arr[$i+1]); return (1-$alf)*$arr[$n+$i+1]+$alf*$arr[$n+$i+2]; } 2. Script collect_res_new.pl #!/usr/bin/perl use IO::File; if($#ARGV < 0) { print "Usage: $0 prefix1 {prefix2} ...\n"; } open(GN2,"> _tmp2_gnu_.plt") || die "Can't open gnu2 file $!\n"; open(GS2,"> _tmp2_gra_.gs") || die "Can't open gs2 file $!\n"; (@pref) = @ARGV; $n=0; $xmin = 0; $xmax = 0; $zmin = 0;

Page 68: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

66

$zmax = 0; $long_min = 999; $long_max = -999; $lat_min = 999; $lat_max = -999; $first=1; # Colors in [gnuplot, grads]: red, green, blue, magenta, cyan, orange @colors = ( [1,2],[2,3],[3,4],[4,6],[5,5],[7,8] ); foreach (@pref) { (@tab_pref)=split(/\s+/,$_); foreach (@tab_pref) { if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } $comm=$_ . "_._txt_"; $prefix=$_; system "ls $comm > _tmp_"; open(FIL,"< _tmp_") || die "Can't open tmp file $!\n"; while (<FIL>) { chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } $fil=$_; $_=~ s/\S+\d{14,14}\w(\d+).*/$1/; $no_of_traj=$_; $color=$no_of_traj%6; open(TXT,"< $fil") || die "Can't open txt file $!\n"; while (<TXT>) { chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } ($x1,$x2)=split(/\s+/,$_); $_=<TXT>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } ($z1,$z2)=split(/\s+/,$_); $_=<TXT>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } ($long1,$long2)=split(/\s+/,$_); $_=<TXT>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } ($lat1,$lat2)=split(/\s+/,$_); $_=<TXT>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; } ($t_year,$t_month,$t_day)=split(/\s+/,$_); $_=<TXT>; chop if /\n$/; if(/^\s+/) { $_=~ s/\s+(.*)/$1/; }

Page 69: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

67

($t_hour,$t_min,$t_sec)=split(/\s+/,$_); if($z2 > $zmax) { $zmax=$z2; } if($z1 < $zmin) { $zmin=$z1; } if($x2 > $xmax) { $xmax=$x2; } if($x1 < $xmin) { $xmin=$x1; } if($long2 > $long_max) { $long_max=$long2; } if($long1 < $long_min) { $long_min=$long1; } if($lat2 > $lat_max) { $lat_max=$lat2; } if($lat1 < $lat_min) { $lat_min=$lat1; } if($no_of_traj == 0) { $s_year=$t_year; $s_month=$t_month; $s_day=$t_day; $s_hour=$t_hour; $s_min=$t_min; } $e_year=$t_year; $e_month=$t_month; $e_day=$t_day; $e_hour=$t_hour; $e_min=$t_min; $n++; $len=length $fil; $fl=substr($fil,0,$len-7) . '.tim'; if ($first == 1) { print GN2 "plot '$fl' using 1:5 with linespoints linetype $colors[$color][0], \\\n"; $first=0; } else { print GN2 " '$fl' using 1:5 with linespoints linetype $colors[$color][0], \\\n"; } $fl_gr=$fl; $len=length $fl; $fl= substr($fl,0,$len-3) . 'gs'; print GS2 "'run $fl'\n"; } close TXT; } close FIL; } } if($s_day == "") { $s_year=$e_year; $s_month=$e_month; $s_day=$e_day; $s_hour=$e_hour;

Page 70: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

68

$s_min=$e_min; } print GN2 " '$fl_gr' using 1:5 with linespoints linetype $colors[$color][0] \n"; #print GN2 " '$fl_gr' using 1:(\$5-\$6) with filledcurves x1 linetype 8 \n"; open(TXT,">out_gnu_.txt") || die "Can't open txt file: $!\n"; print TXT "$n\n"; print TXT "$xmin $xmax\n"; print TXT "$zmin $zmax\n"; print TXT "$long_min $long_max\n"; print TXT "$lat_min $lat_max\n"; $long_l = int($long_min)-int($long_min)%5; $long_r = int($long_max)-int($long_max)%5+5; $lat_d = int($lat_min)-int($lat_min)%5; $lat_u = int($lat_max)-int($lat_max)%5+5; if($long_min-$long_l < 1.5) { $long_l = $long_l - 2;} if($long_r-$long_max < 1.5) { $long_r = $long_r + 2;} if($lat_min-$lat_d < 1.5) { $lat_d = $lat_d - 2;} if($lat_u-$lat_max < 1.5) { $lat_u = $lat_u + 2;} open(GS1,"> _tmp1_gra_.gs") || die "Can't open gs1 file $!\n"; open(GN1,"> _tmp1_gnu_.plt") || die "Can't open gnu1 file $!\n"; print GS1 "'set lon $long_l $long_r'\n"; print GS1 "'set lat $lat_d $lat_u'\n"; print GN1 "set xlabel \"Time \"\n"; print GN1 "set ylabel \"Height [m]\"\n"; #print GN1 "set xrange [$xmin:$xmax]\n"; print GN1 "set xdata time\n"; print GN1 "set format x \"%H:%M\"\n"; print GN1 "set yrange [$zmin:$zmax]\n"; print GN1 "set key off\n"; print GN1 "set grid\n"; print GN1 "set timefmt \"%Y%m%d %H%M\"\n"; print GN1 "set xtics 21600\n"; if($xmin >= 0) { print GN1 "set title \"Forward trajectory, height along trajectory, $s_day.$s_month.$s_year $s_hour:$s_min - $e_day.$e_month.$e_year $e_hour:$e_min\"\n"; print GS1 "'draw title \"Forward trajectory, date/time \\ $s_day.$s_month.$s_year $s_hour:$s_min - $e_day.$e_month.$e_year $e_hour:$e_min\"'\n"; } else { print GN1 "set title \"Backward trajectory, height along trajectory, $s_day.$s_month.$s_year $s_hour:$s_min - $e_day.$e_month.$e_year $e_hour:$e_min\"\n"; print GS1 "'draw title \"Backward trajectory, date/time \\ $s_day.$s_month.$s_year $s_hour:$s_min - $e_day.$e_month.$e_year $e_hour:$e_min\"'\n"; } close GS1; close GS2; close GN1; close GN2; 3. Script print_res_gen.sh #!/bin/sh print_pic() { rm -f _gnu_.plt touch _gnu_.plt

Page 71: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

69

echo "set terminal postscript color landscape" > _gnu_.plt cat _tmp1_gnu_.plt _tmp2_gnu_.plt >> _gnu_.plt echo "#pause -1 \"Return to continue\"" >> _gnu_.plt gnuplot _gnu_.plt > _gnu_.ps ps2pdf _gnu_.ps _gnu_.pdf pstopnm < _gnu_.ps > _gnu_.pnm pnmtojpeg < _gnu_.pnm > _gnu_.jpg rm -f _gra_.gs touch _gra_.gs echo "'set grads off'" >> _gra_.gs echo "'set mpdset hires'" >> _gra_.gs echo "'open output2.ctl'" >> _gra_.gs head -n 2 _tmp1_gra_.gs >> _gra_.gs echo "'draw map'" >> _gra_.gs awk -f awk_gra _tmp1_gra_.gs >> _gra_.gs cat _tmp2_gra_.gs >> _gra_.gs echo "'d lon'" >> _gra_.gs echo "'d lat'" >> _gra_.gs echo "'enable print _gra_.prn'" >> _gra_.gs echo "'print'" >> _gra_.gs echo "'disable print'" >> _gra_.gs echo "'quit'" >> _gra_.gs gradsc -bpc _gra_.gs gxps -c -i _gra_.prn -o _gra_.ps ps2pdf _gra_.ps _gra_.pdf pstopnm < _gra_.ps > _gra_.pnm pnmtojpeg < _gra_.pnm > _gra_.jpg } if [ $# -lt 5 ] then echo "Usage: $0 lab mode sim_time_from sim_time_till postprefix {postprefix} " echo "for example $0 alg 1 0 max 020 050 100 will collect results from alg020 alg050 alg100 runs" echo "if sim_time_till=max then sim_till_time=864000 (10 days)" exit 1 fi lab=$1 mode=$2 sim_sec1=$3 sim_sec2=$4 postprefix=$5 colors[0]=red colors[1]=green colors[2]=blue colors[3]=magenta colors[4]=cyan colors[5]=orange if [ $sim_sec2 == "max" ] then sim_sec2=864000 fi if [ $mode -eq 1 ] then modestr=T_ modestri=TI_ fi if [ $mode -eq 2 ] then modestr=CET_ modestri=CETI_

Page 72: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

70

fi if [ $mode -eq 3 ] then modestr=FLIGHT_ modestri=FLIGHTI_ fi echo "Simulation time from $sim_sec1 to $sim_sec2" for i in `ls ${modestr}${lab}*` do if [ $mode -eq 1 ] then val=${i:2} fi if [ $mode -eq 2 ] then val=${i:4} fi if [ $mode -eq 3 ] then val=${i:7} fi echo "Processing for run: $i" echo " ./get_res_new.pl $i $lab $mode $sim_sec1 $sim_sec2 < $i" ./get_res_new.pl $val $lab $mode $sim_sec1 $sim_sec2 < $i done echo "Collecting everything in one ... " ./collect_res_new.pl $lab\* print_pic mv _gnu_.ps ${lab}_all_gnu.ps mv _gnu_.pdf ${lab}_all_gnu.pdf mv _gnu_.jpg ${lab}_all_gnu.jpg mv _gnu_.plt ${lab}_all_gnu.plt2 mv _gra_.ps ${lab}_all_gra.ps mv _gra_.pdf ${lab}_all_gra.pdf mv _gra_.jpg ${lab}_all_gra.jpg mv _gra_.gs ${lab}_all_gra.gs2 echo "Producing single pictures for all runs ..." for i in `ls $lab*.plt` do rm -f _gnu_.plt bas=`basename $i .plt` echo "set terminal postscript color landscape" > _gnu_.plt cat $i >> _gnu_.plt gnuplot _gnu_.plt > ${bas}_gnu.ps ps2pdf ${bas}_gnu.ps ${bas}_gnu.pdf pstopnm < ${bas}_gnu.ps > _gnu_.pnm pnmtojpeg < _gnu_.pnm > ${bas}_gnu.jpg done for i in `ls $lab*.gs` do rm -f _gra_.gs bas=`basename $i .gs` echo "'set grads off'" > _gra_.gs echo "'set mpdset hires'" >> _gra_.gs echo "'open output2.ctl'" >> _gra_.gs head -n 2 _tmp1_gra_.gs >> _gra_.gs echo "'draw map'" >> _gra_.gs sed -f sed_gra $i > _gra_tmp.gs echo "'run _gra_tmp.gs'" >> _gra_.gs echo "'d lon'" >> _gra_.gs echo "'d lat'" >> _gra_.gs

Page 73: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

71

echo "'enable print _gra_.prn'" >> _gra_.gs echo "'print'" >> _gra_.gs echo "'disable print'" >> _gra_.gs echo "'quit'" >> _gra_.gs gradsc -bpc _gra_.gs gxps -c -i _gra_.prn -o ${bas}_gra.ps ps2pdf ${bas}_gra.ps ${bas}_gra.pdf pstopnm < ${bas}_gra.ps > _gra_.pnm pnmtojpeg < _gra_.pnm > ${bas}_gra.jpg done mv ${lab}_all_gnu.plt2 ${lab}_all_gnu.plt mv ${lab}_all_gra.gs2 ${lab}_all_gra.gs echo "Collecting all trajectories from the same run ..." shift 4 nruns=0 while [ ! "$1" = "" ] do k="$1" ./collect_res_new.pl ${lab}${k}\* runs[$nruns]=$k nruns=`expr $nruns + 1` print_pic mv _gnu_.ps ${lab}${k}_gnu.ps mv _gnu_.pdf ${lab}${k}_gnu.pdf mv _gnu_.jpg ${lab}${k}_gnu.jpg mv _gnu_.plt ${lab}${k}_gnu.plt mv _gra_.ps ${lab}${k}_gra.ps mv _gra_.pdf ${lab}${k}_gra.pdf mv _gra_.jpg ${lab}${k}_gra.jpg mv _gra_.gs ${lab}${k}_gra.gs shift done ntr=0 echo "Colors for trajectories are linked to starting times:" > legend if [ \( $mode -eq 1 \) -o \( $mode -eq 3 \) ] then echo "Collecting same time ensemble trajectories from different runs ..." k=0 mnr=0 ntr=`ls -l ${lab}${postprefix}_[0-9]*_._txt_ | wc -l` while [ $k -lt $ntr ] do echo "Time $k ..." ./collect_res_new.pl ${lab}\*_$k ./color_gnu.sh $lab $postprefix $k ./color_gra.sh $lab $postprefix $k print_pic mv _gnu_.ps ${lab}_t_${k}_gnu.ps mv _gnu_.pdf ${lab}_t_${k}_gnu.pdf mv _gnu_.jpg ${lab}_t_${k}_gnu.jpg mv _gnu_.plt ${lab}_t_${k}_gnu.plt mv _gra_.ps ${lab}_t_${k}_gra.ps mv _gra_.pdf ${lab}_t_${k}_gra.pdf mv _gra_.jpg ${lab}_t_${k}_gra.jpg mv _gra_.gs ${lab}_t_${k}_gra.gs s[$k]=`awk '{if(NR==10) print $0}' _tmp1_gnu_.plt | awk -F \ '{print $8 " " $9}'` echo "Time $k: ${s[$k]} ${colors[$mnr]}" >> legend k=`expr $k + 1` mnr=`expr $mnr + 1`

Page 74: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

72

if [ $mnr -gt 5 ] then mnr=0 fi done fi rm -rf col_gs.tar tar cvf col_gs.tar *.col rm -rf *.col rm -rf _txt_.tar tar cvf _txt_.tar *._txt_ rm -rf *._txt_ for i in `ls $lab*.gs` do sed -f sed_gra $i > _gra_tmp.gs mv _gra_tmp.gs $i done mkdir ${lab}_plots mkdir ${lab}_plots/pdf mkdir ${lab}_plots/pdf/time mkdir ${lab}_plots/jpg mkdir ${lab}_plots/jpg/time mkdir ${lab}_plots/ps mkdir ${lab}_plots/ps/time mkdir ${lab}_plots/gnu mkdir ${lab}_plots/gra mkdir ${lab}_plots/xml nr=0 while [ $nr -lt $nruns ] do mkdir ${lab}_plots/pdf/${runs[$nr]} mkdir ${lab}_plots/jpg/${runs[$nr]} mkdir ${lab}_plots/ps/${runs[$nr]} nr=`expr $nr + 1` done mv _txt_.tar ${lab}_plots/ mv col_gs.tar ${lab}_plots/ ./move_files.sh $modestr$lab\* ${lab}_plots ./move_files.sh $modestri$lab\* ${lab}_plots ./move_files.sh $lab\*_all_\* ${lab}_plots ./move_files.sh $lab\*_t_\*.pdf ${lab}_plots/pdf/time ./move_files.sh $lab\*_t_\*.ps ${lab}_plots/ps/time ./move_files.sh $lab\*_t_\*.jpg ${lab}_plots/jpg/time ./move_files.sh $lab\*_t_\*gnu.plt ${lab}_plots/gnu ./move_files.sh $lab\*_t_\*gra.gs ${lab}_plots/gra echo "<h3>Common plots from all $lab runs:<br></h3>" > $lab.html echo "<a href=\"${lab}_all_gra.pdf\"> Trajectories on map - pdf file </a><br>" >> $lab.html echo "<a href=\"${lab}_all_gnu.pdf\"> Height of trajectories - pdf file </a><br>" >> $lab.html echo "<a href=\"${lab}_all_gra.jpg\"> Trajectories on map - jpg file </a><br>" >> $lab.html echo "<a href=\"${lab}_all_gnu.jpg\"> Height of trajectories - jpg file </a><br>" >> $lab.html echo "<h3>Graph results from $lab runs:<br></h3>" >> $lab.html echo "<a href=\"pdf/${lab}_pdf.html\"> All the plots in pdf files </a><br>" >> $lab.html echo "<a href=\"jpg/${lab}_jpg.html\"> All the plots in jpg files </a><br>" >> $lab.html echo "Colors for same time trajectories are linked to the runs:" >> legend echo "<h3>Text results from all runs</h3><br>" >> $lab.html for i in `ls ${lab}_plots/$modestr$lab*` do bas=`basename $i`

Page 75: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

73

echo "<a href=\"$bas\"> $bas </a><br>" >> $lab.html done echo "<h3>Output text files for all processed runs:</h3><br>" >> $lab.html echo "<h3>Plots in pdf files</h3><br>" > ${lab}_plots/pdf/${lab}_pdf.html echo "<h3>Plots in jpg files</h3><br>" > ${lab}_plots/jpg/${lab}_jpg.html nr=0 mnr=0 while [ $nr -lt $nruns ] do ./move_files.sh $lab${runs[$nr]}\*.xml ${lab}_plots/xml ./move_files.sh $lab${runs[$nr]}\*.gs ${lab}_plots/gra ./move_files.sh $lab${runs[$nr]}\*.ctl ${lab}_plots/gra ./move_files.sh $lab${runs[$nr]}\*.dat ${lab}_plots/gnu ./move_files.sh $lab${runs[$nr]}\*.plt ${lab}_plots/gnu ./move_files.sh $lab${runs[$nr]}\*.tim ${lab}_plots/gnu ./move_files.sh $lab${runs[$nr]}\*.pdf ${lab}_plots/pdf/${runs[$nr]} ./move_files.sh $lab${runs[$nr]}\*.jpg ${lab}_plots/jpg/${runs[$nr]} ./move_files.sh $lab${runs[$nr]}\*.ps ${lab}_plots/ps/${runs[$nr]} echo "$lab${runs[$nr]}: ${colors[$mnr]}" >> legend if [ -e ../out.$lab${runs[$nr]} ] then echo "<a href=\"out.$lab${runs[$nr]}\"> $lab${runs[$nr]} </a><br>" >> $lab.html mv ../out.$lab${runs[$nr]} ${lab}_plots/ fi echo "<a href=\"${runs[$nr]}/$lab${runs[$nr]}_gra.pdf\"> Map plots for run $lab${runs[$nr]}<br> </a>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<a href=\"${runs[$nr]}/$lab${runs[$nr]}_gra.jpg\"> Map plots for run $lab${runs[$nr]}<br> </a>" >> ${lab}_plots/jpg/${lab}_jpg.html echo "<a href=\"${runs[$nr]}/$lab${runs[$nr]}_gnu.pdf\"> Height plots for run $lab${runs[$nr]}<br> </a>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<a href=\"${runs[$nr]}/$lab${runs[$nr]}_gnu.jpg\"> Height plots for run $lab${runs[$nr]}<br> </a>" >> ${lab}_plots/jpg/${lab}_jpg.html nr=`expr $nr + 1` mnr=`expr $mnr + 1` if [ $mnr -gt 5 ] then mnr=0 fi done echo "<h3>Same time trajectories for all processed runs:</h3><br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<h3>Same time trajectories for all processed runs:</h3><br>" >> ${lab}_plots/jpg/${lab}_jpg.html k=0 while [ $k -lt $ntr ] do echo "<a href=\"time/${lab}_t_${k}_gra.pdf\"> Map plots for time $k: ${s[$k]} </a> <br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<a href=\"time/${lab}_t_${k}_gnu.pdf\"> Height plots for time $k: ${s[$k]} </a> <br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<a href=\"time/${lab}_t_${k}_gra.jpg\"> Map plots for time $k: ${s[$k]} </a> <br>" >> ${lab}_plots/jpg/${lab}_jpg.html echo "<a href=\"time/${lab}_t_${k}_gnu.jpg\"> Height plots for time $k: ${s[$k]} </a> <br>" >> ${lab}_plots/jpg/${lab}_jpg.html k=`expr $k + 1` done echo "<h3>Individual trajectories: </h3><br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<h3>Individual trajectories: </h3><br>" >> ${lab}_plots/jpg/${lab}_jpg.html nr=0 while [ $nr -lt $nruns ] do

Page 76: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

74

echo "<a href=\"${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html\">Plots for run ${runs[$nr]} </a> <br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<a href=\"${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html\">Plots for run ${runs[$nr]} </a> <br>" >> ${lab}_plots/jpg/${lab}_jpg.html echo "<h3>Plots for run ${runs[$nr]}</h3> " > ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html echo "<h3>Plots for run ${runs[$nr]}</h3> " > ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html echo "All trajectories: <br>" >> ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html echo "<a href=\"$lab${runs[$nr]}_gra.pdf\"> Map - all trajectories </a><br>" >> ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html echo "<a href=\"$lab${runs[$nr]}_gnu.pdf\"> Height - all trajectories </a><br>" >> ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html echo "All trajectories: <br>" >> ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html echo "<a href=\"$lab${runs[$nr]}_gra.jpg\"> Map - all trajectories </a><br>" >> ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html echo "<a href=\"$lab${runs[$nr]}_gnu.jpg\"> Height - all trajectories </a><br>" >> ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html echo "<br>Individual trajectories: <br>" >> ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html echo "<br>Individual trajectories: <br>" >> ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html for i in `ls ${lab}_plots/pdf/${runs[$nr]}/$lab${runs[$nr]}_[0-9]*gra*` do bas=`basename $i` echo "<a href=\"$bas\"> Map: $bas </a><br>" >> ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html done for i in `ls ${lab}_plots/pdf/${runs[$nr]}/$lab${runs[$nr]}_[0-9]*gnu*` do bas=`basename $i` echo "<a href=\"$bas\"> Height: $bas </a><br>" >> ${lab}_plots/pdf/${runs[$nr]}/${lab}_pdf_${runs[$nr]}.html done for i in `ls ${lab}_plots/jpg/${runs[$nr]}/$lab${runs[$nr]}_[0-9]*gra*` do bas=`basename $i` echo "<a href=\"$bas\"> Map: $bas </a><br>" >> ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html done for i in `ls ${lab}_plots/jpg/${runs[$nr]}/$lab${runs[$nr]}_[0-9]*gnu*` do bas=`basename $i` echo "<a href=\"$bas\"> Height: $bas </a><br>" >> ${lab}_plots/jpg/${runs[$nr]}/${lab}_jpg_${runs[$nr]}.html done nr=`expr $nr + 1` done echo "<br>Legend:<br>" >> $lab.html echo "<br>Legend:<br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<br>Legend:<br>" >> ${lab}_plots/jpg/${lab}_jpg.html echo "<br>" >> $lab.html awk '{print $0 " <br>"}' legend >> $lab.html echo "<br>" >> ${lab}_plots/pdf/${lab}_pdf.html echo "<br>" >> ${lab}_plots/jpg/${lab}_jpg.html awk '{print $0 " <br>"}' legend >> ${lab}_plots/pdf/${lab}_pdf.html awk '{print $0 " <br>"}' legend >> ${lab}_plots/jpg/${lab}_jpg.html mv legend ${lab}_plots/ mv $lab.html ${lab}_plots/ color_gra.sh #!/bin/sh

Page 77: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

75

if [ $# -lt 3 ] then echo "Usage: $0 lab postprefix time_step" echo "Script changes colors in _tmp2_gra_.gs file created for lab such that" echo " different runs have different colors. Used for same time trajectories" exit 1 fi nlin=`ls -l $1$2_*[0-9]*_$3.gs | wc -l` ntot=`cat _tmp2_gra_.gs | wc -l` #echo "nlin=$nlin" #echo "ntot=$ntot" n=1 col[1]=2 col[2]=3 col[3]=4 col[4]=6 col[5]=5 col[6]=8 c=0 cp _tmp2_gra_.gs _tmp3_gra_.gs while [ $n -lt $ntot ] do # echo "n=$n" c=`expr $c + 1` if [ $c -gt 6 ] then c=1 fi k=1 m=$n while [ $k -le $nlin ] do # echo "k=$k" echo "{if(NR==$m) print \$0}" > _awkf_ fil=`awk -f _awkf_ _tmp2_gra_.gs | awk -f awkf2 | awk -F \' -f awkf1` echo "1s/set line [0-9]/set line ${col[$c]}/" > _sed_gra_ sed -f _sed_gra_ $fil > $fil.col k=`expr $k + 1` m=`expr $m + 1` done n=`expr $n + $nlin` done sed -e s/.gs/.gs.col/ _tmp2_gra_.gs > _tmp3_gra_.gs cp _tmp3_gra_.gs _tmp2_gra_.gs color_gnu.sh #!/bin/sh if [ $# -lt 3 ] then echo "Usage: $0 lab postprefix time_step" echo "Script changes colors in _tmp2_gnu_.plt file created for lab such that" echo " different runs have different colors. Used for same time trajectories" exit 1 fi nlin=`ls -l $1$2_*[0-9]*_$3.plt | wc -l` ntot=`cat _tmp2_gnu_.plt | wc -l` ntot=`expr $ntot - 1` n=1 col[1]=1 col[2]=2 col[3]=3 col[4]=4 col[5]=5 col[6]=7

Page 78: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

76

c=0 while [ $n -lt $ntot ] do c=`expr $c + 1` if [ $c -gt 6 ] then c=1 fi m=`expr $n + $nlin - 1` echo "$n,${m}s/linetype [0-9],/linetype ${col[$c]},/" > _sed_gnu_ sed -f _sed_gnu_ _tmp2_gnu_.plt > _tmp3_gnu_.plt n=`expr $m + 1` cp _tmp3_gnu_.plt _tmp2_gnu_.plt done n=`expr $ntot + 1` echo "${n}s/linetype [0-9]/linetype ${col[$c]}/" > _sed_gnu_ sed -f _sed_gnu_ _tmp2_gnu_.plt > _tmp3_gnu_.plt cp _tmp3_gnu_.plt _tmp2_gnu_.plt move_files #!/bin/sh for i in `ls $1` do bas=`basename $i` mv $i $2/$bas done awk_gra {if(NR==3) print $0 } awkf1 {print $1} awkf2 {print $2} sed_gra 2s/#'draw/'draw/ sed_gra2all 2s/'draw/#'draw/ 4. Script read_d.sh #!/bin/sh read_d() { rm -f out rm -f dir for j in `ls` do if [ -d $j ] then p=`pwd` b=`basename $p` echo "<a href=\"$b/$j.html\"> $j </a><br>" >> dir cd $j read_d fi if [ -f $j ] then p=`pwd` b=`basename $p`

Page 79: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

77

echo "<a href=\"$b/$j\"> $j </a><br>" >> out fi done cd .. } prepar_d() { for j in `ls` do if [ -d $j ] then echo "--------------------------------<br>" >> $j/dir cat /var/www/html/flextra/web.top $j/dir $j/out /var/www/html/flextra/web.bot > $j.html cd $j prepar_d fi done cd .. } if [ $# -lt 1 ] then echo "Usage: $0 path" echo "for example $0 /var/www/html" exit 1 fi cd $1 read_d cd $1 prepar_d cd $1 b=`basename $1` echo "--------------------------------<br>" >> dir cat /var/www/html/flextra/web.top dir out /var/www/html/flextra/web.bot > ../$b.html 5. Script flextra_output.php <? include("web.top"); ?> <? function input1() { echo("<form action=\"http://slawek.jrc.it/flextra/flextra_output.php?show=2\" method=\"post\">"); echo("Please provide information which runs should be processed: <br>"); echo("(if the id-runs to be processed are: alg020 alg100 alg300 then specify <b>alg</b> as a label and <i>020 100 300</i> as runs-id <br>"); echo("Caution: names are case sensitive. <br>"); echo("Label - common id for all runs (e.g. name prefix): <Input type=\"text\" size=10 name=\"label\"><br>"); echo("Trajectory mode: <br>"); echo("<Input type=\"radio\" name=\"mode\" value=\"1\" checked>Normal<br>"); echo("<Input type=\"radio\" name=\"mode\" value=\"2\" >CET (in area: no time series, no ensemble)<br>"); echo("<Input type=\"radio\" name=\"mode\" value=\"3\" >FLIGHT (individual specification of trajectories)<br>"); echo("Minimal duration of trajectory [seconds]: <input type=\"text\" size=7 name=\"min\" value=\"0\"> <br>"); echo("Maximal duration of trajectory [seconds], max=no limitation: <Input type=\"text\" size=8 name=\"max\" value=\"max\"> <br>"); echo("Number of runs to be processed <Input type=\"text\" size=6 name=\"nruns\" > <br>"); echo("<input type=\"reset\" value=\"Reset\">");

Page 80: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

78

echo("<input type=\"submit\" value=\"OK\">"); echo("</form>"); } function input2() { $label=$_POST["label"]; $mode=$_POST["mode"]; $min=$_POST["min"]; $max=$_POST["max"]; $nruns=$_POST["nruns"]; echo("<form action=\"http://slawek.jrc.it/flextra/flextra_output.php?show=3&label=$label&mode=$mode&min=$min&max=$max&nruns=$nruns\" method=\"post\">"); echo("Number of runs: $i <br>"); echo("Post-prefixes of label runs <br>"); echo("(if the id-runs to be processed are: alg020 alg100 alg300 then specify <b>alg</b> as a label and <i>020 100 300</i> as runs-id <br>"); echo("Caution: names are case sensitive. <br>"); for($i=1; $i<= $nruns; $i++) { echo("Run-id: <input type=\"text\" size=10 name=\"run$i\" method=\"post\"> <br>"); } echo("<input type=\"reset\" value=\"Reset\">"); echo("<input type=\"submit\" value=\"OK\">"); echo("</form>"); } $show=$_GET["show"]; if($show == "") {$show=1;} echo("<h3> FLEXTRA output [$show]</h3><br><br>"); switch ($show) { case 1: // first screen input input1(); break; case 2: input2(); break; case 3: $mode=$_GET["mode"]; $nruns=$_GET["nruns"]; $min=$_GET["min"]; $max=$_GET["max"]; $label=$_GET["label"]; $s= " ./print_res_gen.sh $label $mode $min $max "; for($i=1; $i <= $nruns; $i++) { $run=$_POST["run$i"]; $s = $s . " $run"; } $han=fopen("/tmp/flextra_output_php.sh","w"); fwrite($han,"$s"); fclose($han); echo("Results will be available under the page $label" ."_plots/$label.html <br>"); break; default: input1(); break; } ?> <? include("web.bot"); ?>

Page 81: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

79

European Commission

EUR 22292 EN – DG Joint Research Centre, Institute for Environment and Sustainability Title: Technical Specification on the Implementation of a Trajectory Model Authors: S. Potemski, S. Galmarini Luxembourg: Office for Official Publications of the European Communities 2006 – 76 pp. – 21 x 29.7 cm EUR-Scientific and Technical Research series; ISSN 1018-5593 ISBN 92-79-02886-3

Abstract The trajectory model FLEXTRA has been implemented as a tool that can be used in different analyses

of the situation arisen after accidental release of airborne harmful material. This report gives the reader

the technical specification of the implementation of a trajectory model FLEXTRA that can be used by

the administrator and by the user. Some aspects of operational elements are also presented. The

report contains description of general structure and in details pre-processing and post-processing

utilities. In the appendixes developed software is included.

Page 82: Technical Specification on the Implementation of a Trajectory … · Technical Specification on the Implementation of a Trajectory Model S. Potempski and S. Galmarini 2006 ... All

80

Mission of the JRC The mission of the Joint Research Centre is to provide customer-driven scientific and technical support for the conception, development, implementation and monitoring of EU policies. As a service of the European Commission, the JRC functions as a reference centre of science and technology for the Union. Close to the policy-making process, it serves the common interest of the Member States, while being independent of special interests, whether private or national.

LB-N

A-22292-EN

-C