Sponsored Content
Top Forums UNIX for Advanced & Expert Users Conversion from ASCII to binary for physical simulation code in C/C++ Post 302507406 by Cybertib on Wednesday 23rd of March 2011 06:37:25 PM
Old 03-23-2011
Thank you for your answer.

Code:
double close_enough=3.14;
        FILE *fout=fopen("filename", "w");
        write(&close_enough, 1, sizeof(close_enough), fout);
        fclose(fout);

This is almost what I've used to produce the 4 times larger file. Smilie
I used fwrite and a buffer instead (to collect whole the datas to put in a line) as follows

Code:
sprintf(buffer, "%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\t%lg\n", 
							fluence, t, x, z, Te(i,j), 
							Ti(i,j), eDensity(i,j), hDensity(i,j), Intensity(i), intensity(i,j), 
							H(i,j), phase(i,j), angleIncidence, angleRefracted(i,j));
						fwrite(buffer, 1, sizeof(buffer), MainOutput);

Do you think it is same as you proposed ?
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Convert ASCII to BINARY

Here is what I did . . . . I FTP'd several *.pdf files from a web site to a UNIX server, and did not set the transfer mode to BIN, now Adobe thinks that the documents are corrupted. Is there a way to convert the *.pdf files to Binary so that Adobe can open them again. I would just re-download... (2 Replies)
Discussion started by: pc9456
2 Replies

2. Shell Programming and Scripting

ascii conversion

after converting my ebcidic file to ascii i get the following output 2097152+0 records in 1797345+1 records out Why is there a difference in number of records. Is the converson chopping off any records. All i am doing is just a conversion using the following script dd if=xaa cbs=152 ... (0 Replies)
Discussion started by: rintingtong
0 Replies

3. SCO

ascii to binary conversion in sco 5.0.5

Here is what I did . . . . I FTP'd several *.dbf zipped files from a SCO 5.0.5 server to winXP machine, and did not set the transfer mode to BIN, now when i was uncompressing these files in SCO 5.0.5 , it was giving "Bad Decode Table error. Is there a way to convert the *.dbf.Z files to Binary so... (1 Reply)
Discussion started by: sameek1211
1 Replies

4. Shell Programming and Scripting

binary to ascii

Hi, Is there a way to convert the binary file to ascii . the binary file is pipe delimited. from source the file(pipe delimited) is ftped to mainframe and from mainframe it is ftped to the unix box using binary format. Is there a way to change it back to ascii and view it? Thanks! (3 Replies)
Discussion started by: dnat
3 Replies

5. UNIX for Dummies Questions & Answers

Ascii or Binary?

Hello all, I am working with ftp servers in unix, and always I have to get and put files but I don't know exactly if I have to get or put them as an ascii or binary. Some files that I use are: .txt, .sav, .fmb, .pct, .sh, .ksh, .dat, .log. Somebody can tell me what is the difference between... (2 Replies)
Discussion started by: Geller
2 Replies

6. Shell Programming and Scripting

binary to ascii conversion

Hi, I have got a library file, created by compiling C code. The file information with "file" command, gives it a "application/x-archive" type file. I want to extract the release string of my software from this file, so that i can know which version of C files were used to create the lib. Can... (3 Replies)
Discussion started by: atulmt
3 Replies

7. Solaris

EBCDIC to ASCII Binary conversion issue on Solaris i-series Unix

Hi All, I am facing EBCDIC to ASCII Binary conversion on Solaris i-series Unix system. However this is working fine on Solaris Sparc Unix system. Input file having EBCDIC format does not work on Solaris i-series Unix system. Could you please tell me, what will be the root cause for same? (14 Replies)
Discussion started by: amodkavi
14 Replies

8. Shell Programming and Scripting

Bash - binary data to ascii code

Hello, With bash-script (ubunto server) I'm trying to read a binary file and, for each character, give back its ascii code (including extended ascii). For example: HEX => ASCII => PRINT f5 => 245 => õ 50 => 80 => P To load the binary file into a variable I tried in this way: ... (2 Replies)
Discussion started by: math4
2 Replies

9. Solaris

ASN Binary to ASCII

Dears, I need help to convert the binary file into ASCII format. Actually we have CDRs which is generated by telecom switch at this is in ASN1 format or binary format, I need to convert those binary formatted file into ASCII format using Perl, or shell scripting. Is there any way to solve... (3 Replies)
Discussion started by: PRINCESS_RORO
3 Replies

10. Shell Programming and Scripting

File conversion from Binary to ASCII though UNIX command

Hi All , I have a mainframe file which contains the data in EBCDIC format.I have downloaded this file from mainframe to windows in binary format(unreadable raw data).Now I want convert this file to ASCII format(readable format data) through Unix command.I have tried iconv but that is not working... (2 Replies)
Discussion started by: STCET22
2 Replies
explain_fwrite(3)					     Library Functions Manual						 explain_fwrite(3)

NAME
explain_fwrite - explain fwrite(3) errors SYNOPSIS
#include <libexplain/fwrite.h> const char *explain_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp); const char *explain_errno_fwrite(int errnum, const void *ptr, size_t size, size_t nmemb, FILE *fp); void explain_message_fwrite(char *message, int message_size, const void *ptr, size_t size, size_t nmemb, FILE *fp); void explain_message_errno_fwrite(char *message, int message_size, int errnum, const void *ptr, size_t size, size_t nmemb, FILE *fp); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the fwrite(3) system call. explain_fwrite const char *explain_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp); The explain_fwrite function is used to obtain an explanation of an error returned by the fwrite(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (fwrite(ptr, size, nmemb, fp) < 0) { fprintf(stderr, "%s ", explain_fwrite(ptr, size, nmemb, fp)); exit(EXIT_FAILURE); } ptr The original ptr, exactly as passed to the fwrite(3) system call. size The original size, exactly as passed to the fwrite(3) system call. nmemb The original nmemb, exactly as passed to the fwrite(3) system call. fp The original fp, exactly as passed to the fwrite(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_fwrite const char *explain_errno_fwrite(int errnum, const void *ptr, size_t size, size_t nmemb, FILE *fp); The explain_errno_fwrite function is used to obtain an explanation of an error returned by the fwrite(3) system call. The least the mes- sage will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (fwrite(ptr, size, nmemb, fp) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_fwrite(err, ptr, size, nmemb, fp)); exit(EXIT_FAILURE); } errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. ptr The original ptr, exactly as passed to the fwrite(3) system call. size The original size, exactly as passed to the fwrite(3) system call. nmemb The original nmemb, exactly as passed to the fwrite(3) system call. fp The original fp, exactly as passed to the fwrite(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_fwrite void explain_message_fwrite(char *message, int message_size, const void *ptr, size_t size, size_t nmemb, FILE *fp); The explain_message_fwrite function may be used to obtain an explanation of an error returned by the fwrite(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (fwrite(ptr, size, nmemb, fp) < 0) { char message[3000]; explain_message_fwrite(message, sizeof(message), ptr, size, nmemb, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. ptr The original ptr, exactly as passed to the fwrite(3) system call. size The original size, exactly as passed to the fwrite(3) system call. nmemb The original nmemb, exactly as passed to the fwrite(3) system call. fp The original fp, exactly as passed to the fwrite(3) system call. explain_message_errno_fwrite void explain_message_errno_fwrite(char *message, int message_size, int errnum, const void *ptr, size_t size, size_t nmemb, FILE *fp); The explain_message_errno_fwrite function may be used to obtain an explanation of an error returned by the fwrite(3) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (fwrite(ptr, size, nmemb, fp) < 0) { int err = errno; char message[3000]; explain_message_errno_fwrite(message, sizeof(message), err, ptr, size, nmemb, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. ptr The original ptr, exactly as passed to the fwrite(3) system call. size The original size, exactly as passed to the fwrite(3) system call. nmemb The original nmemb, exactly as passed to the fwrite(3) system call. fp The original fp, exactly as passed to the fwrite(3) system call. SEE ALSO
fwrite(3) binary stream output explain_fwrite_or_die(3) binary stream output and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_fwrite(3)
All times are GMT -4. The time now is 01:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy