Browse Source

Autodetect format by output file extension in the tsc action

interpolate
Michael Uleysky 1 year ago
parent
commit
e25f843e7e
  1. 5
      actions/actiontsc.h
  2. 1
      include/ParseArgs.h
  3. 7
      src/ParseArgs.cpp

5
actions/actiontsc.h

@ -50,12 +50,12 @@ template<class D> MString ActionTSC::DoAction(const CLArgs& args, D& ds)
if(!data) return "Can't read data"; if(!data) return "Can't read data";
if(!data.Unit().Exist()) michlib::errmessage("Unknown measurement unit!"); if(!data.Unit().Exist()) michlib::errmessage("Unknown measurement unit!");
MString outfmt = args.contains("format") ? args.at("format") : "bin"; MString name = args.contains("out") ? args.at("out") : "out.bin";
MString outfmt = args.contains("format") ? args.at("format") : (GetExt(name) == "nc" ? "nc" : "bin");
if(outfmt == "bin") if(outfmt == "bin")
{ {
BFileW fw; BFileW fw;
MString name = args.contains("out") ? args.at("out") : "out.bin";
fw.Create(name, 3); fw.Create(name, 3);
fw.SetColumnName(1, "Longitude"); fw.SetColumnName(1, "Longitude");
@ -75,7 +75,6 @@ template<class D> MString ActionTSC::DoAction(const CLArgs& args, D& ds)
if(outfmt == "nc" || outfmt == "netcdf") if(outfmt == "nc" || outfmt == "netcdf")
{ {
MString name = args.contains("out") ? args.at("out") : "out.nc";
int ret; int ret;
int ncid, dimid, dimidxy[2]; int ncid, dimid, dimidxy[2];
int lonid, latid, vid; int lonid, latid, vid;

1
include/ParseArgs.h

@ -6,3 +6,4 @@ using michlib::SList;
using CLArgs = std::map<MString, MString>; using CLArgs = std::map<MString, MString>;
CLArgs ParseArgs(int argc, char** argv); CLArgs ParseArgs(int argc, char** argv);
MString GetExt(const MString& fname);

7
src/ParseArgs.cpp

@ -33,3 +33,10 @@ CLArgs ParseArgs(int argc, char** argv)
return out; return out;
} }
MString GetExt(const MString& fname)
{
for(size_t i = fname.Len(); i != 0; i--)
if(fname[i - 1] == '.') return fname.SubStr(i + 1, fname.Len() - i);
return "";
}

Loading…
Cancel
Save