CurrentlyI am assigned to read in a file from our terminal window, which will contain a list of integers. From this list we must read the values and calculate the average, I believe I have done this correctly.
My only problem is I do not understand how to use the fstat() correctly, I read the man page but am still having a hard time understanding. In my code below, I am wanting to use fstat() to find the size of the file being read so I can then allocate the correct amount of space for my array where I store the values read off the input file. I just need to know the proper usage and syntax of fstat() and from there I believe I can make significant progress. Thanks in advance!
But as @chux (deleted post) answered, it tells you the file size in bytes, not in integers. The function fscanf() inputs the data from text, so there is no direct correlation between file size, and number of fields.
So unfortunately, in answer to your titled question, using fstat() to determine the file size is of no practical use to you. Your secondary implied question is how to allocate enough memory for the array. I posted an answer to that, in a different context where at the outset the array size is unknown. C reading a text file separated by spaces with unbounded word size
But here I use a simpler technique - parse the file twice to find out how many textual integers it contains. It then rewinds the file and allocates memory for the array, although, in this example, the array isn't necessary to calculate the sum and average of the values, and the double file parse isn't necessary either, unless you plan to do more with the values.
The p4 fstat command dumps information about eachfile, with information for each field on a separate line. The output isbest used within aHelix C/C++ APIapplication, where the items can be accessed as variables, but the output is alsosuitable for parsing by scripts.
The head type fields, for example, headTime, returninformation for the file revision provided for the file argument. If nospecific revision is given, it returns information for the headrevision. See also the Timestamp and Unix epoch time information.
For scripting purposes or automated reporting processes: reportfile information on a list of valid file arguments in full depotsyntax with a valid revision number. File specifications that donot meet these requirements are silently ignored.
Fetch and display the attribute values set by the p4attribute command. Each attribute value is fetched from its storage location, which is either the trait depot or the db.traits table. Attributes fetched from the trait depot might impact performance. See also the -On option.
If the path comes from an import or a component view, the path permissions are printed as readonly or writable, where readonly allows the file be opened for edit, but changes cannot be submitted, and writable allows both edit and submit.
If the path comes from a component view, the effectiveComponentType is printed, where the effective component type is the most restrictive component type in a chain of components. From most restrictive to least restrictive are readonly, writeimport+, and writeall
To search for text containing characters that are filter expressionoperators, escape the characters with a backslash (\)character. To match the backslash character, escape it with an additionalbacklash (\\). Using backslashes to escape search querieshas two special cases: you can escape theHelix Core Server"..." wildcard with \..., and you can searchfor empty fields with \0.
The -On option shows the storage location of attributes rather than their values. In this example, the value of the black-and-white and size traits are stored in the db.traits table, but the value of the preview trait is stored in the trait depot, which is represented as .p4traits:
Some months ago I run a calculation of the F-statistics on a set of SNP data from contiguous populations using the fstat() from hierfstat. I recently noticed that these were quite incomplete due to lack of hierarchical information, hence I've settled to repeat the calculation.Trouble is, R doesn't find any function with this name after ade4, vcfR, adegenet and hierfstat itself have been installed. I'm perplexed.
Here my commands and the machine response. I tried to install hierfstat using force = T but the result is... not the one I expected? I'm even more perplexed.I'd be very grateful if someone can give me a hint on what's happening:
Thanks to both of you.Unfortunately, that doesn't seem to work. I try to restart R both by a trivial Ctr+SHift+F10 and .rs.restartR(), together with the rm command, but the issue keep occurring.I tested install.packages("hierfstat")+ library(hierfstat) in a restarted session as well as into a new window, but none worked, again.However, I noticed that several hierfstat functions are available to use, such as fstat2dos() o fst.dosage(). It seems that the issue concerns mostly these baseline functions.
I may have reached a solution: I wasn't able to find the functions... because they weren't in the last version of the package, which I installed (05.7). Instead, they are available in the 04.22 version,I thank very much you both for the help in my troubles!
There is no problem per se apart from your understanding.
You appear to have an unjustified and mistaken belief that there is something called fstat that you think should be in package hierfstat. It seems you are wrong, but I don't know what misled you. You have said nothing to justify your belief.
@nirgrahamuk, I admit that I am low key confused myself. hope you could help.
my colleague told me that obviously, in the newest version of hierfstat, "fstat" has been disabled. and I would need the fstat to analyze my data in R.
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.
To investigate further, I created two cgo versions of this code:
A. where the Readdirnames and loop for the files is done on the Go side, and the actual stat call is on the cgo side
B. where the entire activity is done on the C side (the cgo side is basically identical to my C example), and the Go side is a single function call to the cgo side
To further diagnose the situation, I also made a dummy version from (A), where the C code just returns a static value without calling fstat. There were some spurious futex calls, but it ran almost as fast as the pure C version. I replaced the static value with a pid() call, and got a result that was 3x slower than C (inbetween static values and fstat calls).
The p4 fstat command dumps information about each file, with information for each field on a separate line. The output is best used within a Perforce API application where the items can be accessed as variables, but is also suitable for parsing by scripts.
The only argument required for the p4 fstat command, is the file[rev] argument. All other options relate to limiting the set of files operated on or controlling the amount and display of information for the selected files.
For scripting purposes or automated reporting processes: report file information on a list of valid file arguments in full depot syntax with a valid revision number. File specifications that do not meet these requirements are silently ignored.
The -s global option (which prefixes each line of output with a tag describing the type of output as error, warning, info, text, or exit) can be particularly useful when used with p4 fstat.
Search results can be narrowed by matching values within specific fields with the filter syntax "fieldname=value". The value must be a single token, including both alphanumeric characters and punctuation.
To search for text containing characters that are filter expression operators, escape the characters with a backslash (\) character. To match the backslash character, escape it with an additional backlash (\\). Using backslashes to escape search queries has two special cases: you can escape the Perforce "..." wildcard with \..., and you can search for empty fields with \0.
What I don't get is why would they have to think about that code at all when bootstrapping. There is an architecturally neutral implementation of fstat() and friends, and all the person working on the porting should need to do is to connect each system call implementation to the low-level mechanism the particular architecture employs to jump from userland to the kernel. Why glibc's fstat() is slow Posted Oct 7, 2023 14:54 UTC (Sat) by izbyshev (subscriber, #107996) [Link]
I think this is a misreading of Viro's (terse) message. He doesn't say anything about POSIX, the Linux man page says that AT_EMPTY_PATH is a non-portable Linux extension, and just to be sure I don't see it in POSIX at all.I think what he meant is that Linux itself effectively mandates this behavior, in that the current implementation of fstatat(fd, NULL, &stat_buf, AT_EMPTY_PATH is to return -EFAULT, and so userspace libraries like glibc don't have the option of setting it to NULL. That is, the problem is not that glibc is being weird by passing a non-NULL pointer to an empty string that the kernel has to go look at, the problem is that glibc has no choice but to pass a non-NULL pointer to an empty string.But it seems to me (as a non-expert) that this is something Linux could relax - if you notice that the pointer is NULL, check for AT_EMPTY_PATH before throwing -EFAULT. It wouldn't help glibc for a long while, but it would be worth doing for several years from now, when glibc has inevitably dropped support for existing kernel versions for other reasons.To the more general point, that the kernel shouldn't be looking at the pointer at all when AT_EMPTY_PATH is specified even if it's non-NULL, as the parent messages in that subthread point out, the kernel defines a specific non-error behavior for that case, which is to ignore AT_EMPTY_PATH and actually use the provided path, and that behavior could not be changed without technically breaking backwards compatibility for userspace - even though it's hard to imagine that anyone is relying on it. But I believe an error case (getting -EFAULT when passing NULL) can be turned into a non-error case without violating the kernel's promises about breaking userspace. Why glibc's fstat() is slow Posted Sep 15, 2023 6:38 UTC (Fri) by NN (subscriber, #163788) [Link]
3a8082e126