rich-iannone / splitr

Use the HYSPLIT model from inside R and do more with it
Other
141 stars 60 forks source link

Issue using hysplit_trajectory on Linux: missing return in SETUP.CFG #40

Closed ajblomberg closed 5 years ago

ajblomberg commented 5 years ago

Hello, and thanks for the great package.

I'm using splitr on a linux platform. When I use the hysplit_trajectory function, I get a blank tibble.

> library(splitr)
> packageVersion("splitr")
[1] ‘0.4.0.9000’
> 
> setwd("/n/scratchlfs/koutrakis_lab/H")
> trajectory <- hysplit_trajectory(lat = 42,
+                                  lon = -80,
+                                  height = 50,
+                                  duration = 24,
+                                  days = "2001-03-12",
+                                  daily_hours = c(0),
+                                  direction = "backward",
+                                  met_type = "narr",
+                                  extended_met = FALSE,
+                                  exec_dir = "/n/scratchlfs/koutrakis_lab/H",
+                                  met_dir = "/n/scratchlfs/koutrakis_lab/H")
> trajectory
# A tibble: 0 x 12
# … with 12 variables: run <int>, receptor <int>, hour_along <int>, traj_dt <dttm>, lat <dbl>,
#   lon <dbl>, height <dbl>, traj_dt_i <dttm>, lat_i <dbl>, lon_i <dbl>, height_i <dbl>,
#   pressure <dbl>

Using the SETUP.CFG file and CONTROL file created by hysplit_trajectory gives the following error:

[ajm806@boslogin04 H]$ /n/home00/ajm806/apps/R/splitr/linux-amd64/hyts_std
 HYSPLIT4 - Initialization
 Last Changed Rev: 742
 Last Changed Date: 2015-04-02 08:54:24 -0400 (Thu, 02 Apr 2015)

At line 345 of file ../source/hymodelt.F (unit = 75, file = 'SETUP.CFG')
Fortran runtime error: End of file

After some troubleshooting, it appears that the SETUP.CFG file needs a return at the end of the file to work (at least in linux). The following code fixed the problem:

> # New function to add line at end of SETUP.CFG file
> write_config_list <- function (config_list, dir) {
+   paste0("&SETUP\n", 
+          paste0(names(config_list)," = ", config_list, ",\n",
+                 collapse = ""),
+          "/\n") %>% 
+     cat(file = file.path(dir, "SETUP.CFG"))
+   print("use new config write function")
+ }
> 
> assignInNamespace("write_config_list", write_config_list, ns="splitr")
> 
> #' Run hysplit_trajectory
> trajectory <- hysplit_trajectory(lat = 42,
+                                  lon = -80,
+                                  height = 50,
+                                  duration = 24,
+                                  days = "2001-03-12",
+                                  daily_hours = c(0),
+                                  direction = "backward",
+                                  met_type = "narr",
+                                  extended_met = FALSE,
+                                  exec_dir = "/n/scratchlfs/koutrakis_lab/H",
+                                  met_dir = "/n/scratchlfs/koutrakis_lab/H")
[1] "use new config write function"
> trajectory
# A tibble: 25 x 12
     run receptor hour_along traj_dt               lat   lon height traj_dt_i           lat_i lon_i
   <int>    <int>      <int> <dttm>              <dbl> <dbl>  <dbl> <dttm>              <dbl> <dbl>
 1     1        1          0 2001-03-12 00:00:00  42   -80     50   2001-03-12 00:00:00    42   -80
 2     1        1         -1 2001-03-11 23:00:00  42.1 -80.1   33.8 2001-03-12 00:00:00    42   -80
 3     1        1         -2 2001-03-11 22:00:00  42.2 -80.3   20.4 2001-03-12 00:00:00    42   -80
 4     1        1         -3 2001-03-11 21:00:00  42.3 -80.4   12.8 2001-03-12 00:00:00    42   -80
rich-iannone commented 5 years ago

Thanks so much for reporting this issue and for all of the troubleshooting work! I will fix this in master shortly.

rich-iannone commented 5 years ago

@ajblomberg This should now be fixed. Please let me know if this is still a problem. Closing this issue for now.