From 6f4ba00f7131908ef0a27a2400fb51938ca0a46c Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Tue, 13 May 2025 15:24:02 +0200
Subject: [PATCH] Enable output option when no computing command is requested
 and add first option

Closes #121 and #100
---
 src/DynareMain.cc                |  6 ++++--
 src/ExtendedPreprocessorTypes.hh |  1 +
 src/ModFile.cc                   | 18 ++++++++++++++++--
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index 4e9ff55a..f28a7a84 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -56,7 +56,7 @@ usage()
           "[conffile=path_to_config_file] [parallel_follower_open_mode] "
           "[parallel_test] [parallel_use_psexec=true|false]"
        << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] "
-          "[compute_xrefs] [output=second|third] [language=matlab|julia]"
+          "[compute_xrefs] [output=first|second|third] [language=matlab|julia]"
        << " [params_derivs_order=0|1|2] [transform_unary_ops] "
           "[exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
        << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] "
@@ -320,7 +320,9 @@ main(int argc, char** argv)
 
           s.erase(0, 7);
 
-          if (s == "second")
+          if (s == "first")
+            output_mode = OutputType::first;
+          else if (s == "second")
             output_mode = OutputType::second;
           else if (s == "third")
             output_mode = OutputType::third;
diff --git a/src/ExtendedPreprocessorTypes.hh b/src/ExtendedPreprocessorTypes.hh
index 79f9e9a6..dd4d999f 100644
--- a/src/ExtendedPreprocessorTypes.hh
+++ b/src/ExtendedPreprocessorTypes.hh
@@ -24,6 +24,7 @@
 enum class OutputType
 {
   standard, // Default value, infer the derivation order from .mod file only
+  first,    // Output only 1st dynamic derivatives with no other computations
   second,   // Output at least 2nd dynamic derivatives
   third,    // Output at least 3rd dynamic derivatives
 };
diff --git a/src/ModFile.cc b/src/ModFile.cc
index 928ec611..eb2de0b8 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -960,8 +960,22 @@ ModFile::computingPass(bool no_tmp_terms, OutputType output, int params_derivs_o
                                                         no_tmp_terms, block, use_dll);
             }
         }
-      else // No computing task requested, compute derivatives up to 2nd order by default
-        dynamic_model.computingPass(2, 0, global_eval_context, no_tmp_terms, block, use_dll);
+      else // No computing task requested, compute derivatives up to 2nd order by default unless
+           // output=first (preprocessor#100) or third (preprocessor#121) is requested
+        {
+          switch (output)
+            {
+            case OutputType::first:
+              dynamic_model.computingPass(1, 0, global_eval_context, no_tmp_terms, block, use_dll);
+              break;
+            case OutputType::third:
+              dynamic_model.computingPass(3, 0, global_eval_context, no_tmp_terms, block, use_dll);
+              break;
+            default:
+              dynamic_model.computingPass(2, 0, global_eval_context, no_tmp_terms, block, use_dll);
+              break;
+            }
+        }
 
       if (linear)
         {
-- 
GitLab