-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a2e344
commit e801bcd
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | (C) 2008-2024 Potsdam Institute for Climate Impact Research (PIK) | ||
# | authors, and contributors see CITATION.cff file. This file is part | ||
# | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of | ||
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | MAgPIE License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
|
||
# -------------------------------------------------------------- | ||
# description: Convert all .mz files to NetCDF (.nc) for a magpie directory | ||
# comparison script: FALSE | ||
# --------------------------------------------------------------- | ||
|
||
# Version 1.00 - Michael Crawford | ||
# 1.00: first working version | ||
|
||
library(gms) | ||
library(magclass) | ||
|
||
############################# BASIC CONFIGURATION ####################################### | ||
if (!exists("source_include")) { | ||
|
||
title <- NULL | ||
outputdir <- NULL | ||
|
||
# Define arguments that can be read from command line | ||
readArgs("outputdir", "title") | ||
|
||
} | ||
######################################################################################### | ||
|
||
message("Converting all .mz outputs to .nc for output directory: ", outputdir) | ||
|
||
mzFiles <- list.files(path = outputdir, pattern = "0\\.5(_share)?\\.mz$", full.names = TRUE) | ||
|
||
lapply(X = mzFiles, FUN = function(x) { | ||
tryCatch({ | ||
magObj <- magclass::read.magpie(x) | ||
newName <- sub("\\.[^.]+$", "", x) | ||
write.magpie(x = magObj, file_name = paste0(newName, ".nc"), file_folder = outputdir, append = FALSE) | ||
}, error = function(e) { | ||
message("Error processing file: ", x, " - ", e$message) | ||
}) | ||
}) |