mbl | Bonjour,
je cherche à remplir un tableau avec un fichier qui me permettrait de balancer le tout sur un géné de type HP 33120.
J'ai trouvé un programme qui semble le faire, le problème est qu'il me balance des boucles for et que en gros tu rentres tout à la main comme un bête gars.
Je voulais savoir comment faire pour lui indiquer un fichier de type csv ou txt avec la suite de bit qui remplirait directement la condition.
J'ai pas des connaissances exceptionnelles en c(enfin ca ressemble à du c) et donc je voulais votre avis et vos conseils pour rediriger l'entrée standard vers un fichier.
la partie qui gère le foutage en tableau des données est la fonction : void get_data(void)
Merci à tous !
Code :
- This program uses the arbitrary waveform function to download and
- output a square wave pulse with a calculated rise time and fall time.
- The waveform consists of 4000 points downloaded over the GPIB
- interface as ASCII data.
- ***************************************************************************/
- #include <stdio.h> /* Used for printf() */
- #include <stdlib.h> /* Used for malloc(), free(), atoi() */
- #include <string.h> /* Used for strlen() */
- #include <cfunc.h> /* Header file from GPIB Command Library */
- #define ISC 7L /* Assign GPIB select code */
- #define ADDR 710L /* Set GPIB address for function generator */
- /* Function Prototypes */
- void rst_clear(void);
- void get_data(void);
- void download_data(float *waveform, int num_points);
- void out_waveform(void);
- void command_exe(char *commands[], int length);
- void check_error(char *func_name);
- /**************************************************************************/
- void main(void) /* Start of main() */
- {
- rst_clear(); /* Reset the instrument and clear error queue */
- get_data(); /* Calculate the waveform data points */
- out_waveform(); /* Download points and output arb waveform */
- }
- /**************************************************************************/
- void rst_clear(void)
- {
- /* Reset the function generator, clear the error queue, and wait for
- commands to complete. A "1" is sent to the output buffer from the
- *OPC? command when *RST and *CLS are completed. */
- float value;
- IOOUTPUTS(ADDR, "*RST;*CLS;*OPC?", 15);
- IOENTER(ADDR, &value);
- }
- /**************************************************************************/
- void get_data(void)
- {
- /* Load 4000 points into an array to set the rise time and fall time
- to 250 ns and the pulse width to 10 us (the output frequency is set
- to 5 kHz in the "out_waveform" function). */
- float *waveform;
- int loop, num_points = 4000;
- waveform = (float*) malloc (num_points * sizeof(float));
- for (loop = 1; loop <= 5; loop++)
- {
- waveform[loop] = (float)(loop-1)/5; /* Set rise time (5 points) */
- }
- for (loop = 6; loop <= 205; loop++)
- {
- waveform[loop] = 1; /* Set pulse width (10 points) */
- }
- for (loop = 206; loop <= 210; loop++)
- {
- waveform[loop] = (float)(210-loop)/5; /* Set fall time (5 points) */
- }
- 6
- for (loop = 211; loop <= 4000; loop++)
- {
- waveform[loop] = 0; /* Set remaining points to zero */
- }
- /* Call function to download the 4000 data points to volatile memory */
- download_data(waveform, num_points);
- /* Free memory allocated for data points */
- free(waveform);
- }
- /**************************************************************************/
- void download_data(float *waveform, int num_points)
- {
- /* Download the waveform array (4000 points) to volatile memory.
- The function generator expects to receive the arb waveform data as
- one contiguous block. To do this, suppress the carriage return (CR)
- and line feed (LF) before downloading the data. */
- static char state[2] = {13, 10}; /* ASCII 13 = carriage return
- ASCII 10 = line feed */
- /* First, disable EOI (End-or-Identify) and EOL (End-of-Line) */
- IOEOI (ISC,0); IOEOL (ISC, " ", 0);
- /* Send "DATA VOLATILE" header and suppress CR/LF */
- printf("Downloading Arb...\n\n" );
- IOOUTPUTS (ADDR, "DATA VOLATILE,", 14);
- /* Re-enable EOI and EOL for normal GPIB operation and send the data */
- IOEOI (ISC,1); IOEOL (ISC, state, 2);
- /* Use the IOOUTPUTA to output the waveform data as an ASCII array */
- IOOUTPUTA (ADDR, waveform, num_points); printf("Download Complete\n\n" );
- /* Call the function to check for errors */
- check_error("download_data" );
- }
- /**************************************************************************/
- void out_waveform(void)
- {
- /* Set the output frequency to 5 kHz with an amplitude of 10 Vpp and
- output the arbitrary waveform. */
- static char *cmd_string[]=
- {
- /* Copy arb waveform to non-volatile memory with name "PULSE" */
- "DATA:COPY PULSE, VOLATILE",
- "FUNC:USER PULSE", /* Select the active arb waveform */
- "FUNC:SHAP USER" /* Output the selected arb waveform */
- };
- /* Call the function to execute the command strings shown above */
- command_exe(cmd_string, sizeof(cmd_string)/sizeof(char*));
- /* Call the function to check for errors */
- check_error("out_waveform" );
- }
- /**************************************************************************/
- void command_exe(char *commands[], int length)
- {
- /* Execute one command string at a time using loop */
- int loop;
- for (loop = 0; loop < length; loop++)
- {
- IOOUTPUTS(ADDR, commands[loop], strlen(commands[loop]));
- }
- /* Set output termination to 50 ohms and output frequency to 5 kHz @ 5 Vpp */
- IOOUTPUTS(ADDR, "OUTP:LOAD 50", 12);
- IOOUTPUTS(ADDR, "FREQ 5000;VOLT 5", 16);
- }
- /**************************************************************************/
- void check_error(char *func_name)
- {
- /* Read error queue to determine if errors have occurred */
- char message[80];
- int length = 80;
- IOOUTPUTS(ADDR, "SYST:ERR?", 9); /* Read the error queue */
- IOENTERS(ADDR, message, &length); /* Enter error string */
- while (atoi(message) != 0) /* Loop until all errors are read */
- {
- printf("Error %s in function %s\n\n", message, func_name);
- IOOUTPUTS(ADDR, "SYST:ERR?", 9);
- IOENTERS(ADDR, message, &length);
- }
- }
- /**************************************************************************/
- End of Program 3
|
Message édité par mbl le 27-06-2006 à 14:12:21
|