Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 198: iefielkit aux functions other commands #201

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

DenisseO
Copy link
Contributor

No description provided.

@DenisseO DenisseO changed the title Issue 198: iefielkit aux functions Issue 198: iefielkit aux functions other commands Nov 11, 2021
@luizaandrade luizaandrade requested review from kbjarkefur and luizaandrade and removed request for kbjarkefur November 11, 2021 21:15
@luizaandrade
Copy link
Collaborator

@kbjarkefur @bbdaniels , can you take a look at these since you know the commands better? the idea is just to remove code that is repeated across commands

local file = substr("`using'", `r_lastslash' + 2, .)

* If a filename was specified, separate the file name from the file format
if "`file'" != "" {
Copy link
Contributor

@kbjarkefur kbjarkefur Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this be empty? using/ is required and folders are defined as anything before a /. So if / exists then folders are anything before / and file is whatever is after and if there is no / then file is the same as using/? Right? Or is there any input for which this command stores somethin in folder but file is empty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if using/ is folderA/folderB/. But then the input is no longer a filename and it is a path. I think that that should either be an error or the command should be called ieaux_parse_filepath and then a path without a filename should be just as valid input as a filename with or without path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if there is no / then file is the same as using/

Copy link
Contributor Author

@DenisseO DenisseO Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the best option is to change the name to ieaux_parse_filepath.
I made some changes for this to be a valid imput.
2d80a4b
7279d5c

cap program drop ieaux_folderpath
program ieaux_folderpath

syntax, [description(string) folderpath(string)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are both these options optional? When does it make sense to run this command without any options specified?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command could have an option to recursively create a path that does not exist.

Copy link
Contributor Author

@DenisseO DenisseO Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this command to have as input ieaux_parse_filepath command
9cac6b2

/*******************************************************************************
TEST IF THE FILE EXTENSION IS THE CORRECT
- option "fileext" is a namelist of the correct extensions that the file may only have
- option "testfileext" is the current file extension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "current" file extension mean? Based on my understanding when reading the code I think a better name for this option would be defaultextension() as it is applied as the default to the filename when no file extension is used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I read this again. This is the extension that we should test? I think it is much better if we were to get that from using. So take the content of using/ and use the command ieaux_filename/ieaux_parse_filename/ieaux_parse_filepath (or whatever it will be called) to get the extension in using/ (if any) and then test it towards the elements in fileext(namelist). In addition to the main commands in iefieldkit benefitting from on these aux/utility commands, these aux/utility commands should benefit from each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with this.
I added these changes here:
506a71e

@luizaandrade luizaandrade changed the base branch from develop to issue-198 November 30, 2021 19:20
@luizaandrade luizaandrade changed the base branch from issue-198 to develop November 30, 2021 19:23
Comment on lines 82 to 106
syntax using/, testfileext(string)
ieaux_filename using `using'

if !missing("`r(file)'") {
* Check if the file extension is the correct
local ext ""
foreach value in `testfileext' {
if (".`value'" == "`r(fileext)'") local errorfile 1
local ext `".`value' `ext'"'
}

local wcount = `: word count `testfileext''
if ("`errorfile'" != "1") & ("`r(fileext)'" != "1") {
if `wcount' > 1 local pluralms= "s"
noi di as error `"{phang}The file {bf:`using'} may only have the extension format`pluralms' [`ext']. The format [`r(fileext)'] is not allowed.{p_end}"'
error 198
}

* If no file extension was used, then add the extension
if "`r(fileext)'" == "1" {
local ext = word("`testfileext'",1) // If there are more than one extension, get first
local using "`using'.`ext'"
}
}
return local using `using'
Copy link
Contributor

@kbjarkefur kbjarkefur Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
syntax using/, testfileext(string)
ieaux_filename using `using'
if !missing("`r(file)'") {
* Check if the file extension is the correct
local ext ""
foreach value in `testfileext' {
if (".`value'" == "`r(fileext)'") local errorfile 1
local ext `".`value' `ext'"'
}
local wcount = `: word count `testfileext''
if ("`errorfile'" != "1") & ("`r(fileext)'" != "1") {
if `wcount' > 1 local pluralms= "s"
noi di as error `"{phang}The file {bf:`using'} may only have the extension format`pluralms' [`ext']. The format [`r(fileext)'] is not allowed.{p_end}"'
error 198
}
* If no file extension was used, then add the extension
if "`r(fileext)'" == "1" {
local ext = word("`testfileext'",1) // If there are more than one extension, get first
local using "`using'.`ext'"
}
}
return local using `using'
syntax using/, allowed_exts(string) [default_ext(string)]
*Parse the unput
ieaux_filename using `using'
local this_file "`r(file)'"
local this_ext = subinstr("`r(file)'",".","")
*Test if using has no file
if missing("`this_file'") {
noi di as error `"{phang}The path {bf:`using'} does not have a file name for which extension can be tested.{p_end}"'
error 198
}
*Test is using has no file extension
else if missing("`this_ext'") {
*Test if no deafult ext was provided
if missing("`default_ext'") {
noi di as error `"{phang}The file in {bf:`using'} does not have a file extension and no default was provided.{p_end}"'
error 198
}
*Apply the deafult extension
else {
local return_file "`using'.`default_ext'"
}
}
* Using has both file and extension
else {
* Test if extension is among the allowed extensions
if `: list this_ext in allowed_exts' == 1 {
*Extension is allowed, return file name as is
local return_file "`using'"
}
* File extension used is not allowed
else {
noi di as error `"{phang}The file extension [`this_ext'] in file {bf:`using'} is not allowed. Allowed extensions: [`allowed_exts'].{p_end}"'
error 198
}
}
*Return checked filename
return local filename "`return_file'"

I would approach this command like this

@luizaandrade luizaandrade mentioned this pull request Feb 10, 2022
4 tasks
Base automatically changed from develop to v2.1 February 10, 2022 19:59
Base automatically changed from v2.1 to main February 14, 2022 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants