📄 arrayfile.c
字号:
#include <ansi_c.h>
/*---------------------------------------------------------------------------*/
/* */
/* FILE: arrayfile.c */
/* */
/* PURPOSE: This example illustrates how to use the Formatting and IO */
/* functions ArrayToFile and fileToArray to write/read a data file. */
/* */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Include files */
/*---------------------------------------------------------------------------*/
#include <cvirte.h>
#include <userint.h>
#include <formatio.h>
#include <utility.h>
#include <stdlib.h>
#include "arrayfile.h"
/*---------------------------------------------------------------------------*/
/* Defines */
/*---------------------------------------------------------------------------*/
#define IN_COUNT 80000 // 输入文件大小
#define OUT_COUNT 80000 // 输出文件大小
#define PIN_COUNT 1500 //引脚最大数
/*---------------------------------------------------------------------------*/
/* Module-globals */
/*---------------------------------------------------------------------------*/
static char proj_dir[MAX_PATHNAME_LEN];
static char file_name[MAX_PATHNAME_LEN];
static char infile[IN_COUNT];
static char outfile[OUT_COUNT];
static int PinCount;
static int OutCount;
static int handle;
static int err;
static char temp[40];
/*---------------------------------------------------------------------------*/
/* Macros */
/*---------------------------------------------------------------------------*/
error_check(char *temp, int err);
/*---------------------------------------------------------------------------*/
/* This is the application's entry-point. */
/*---------------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1;
GetProjectDir (proj_dir);
handle = LoadPanel (0, "arrayfile.uir", Examp1);
SetPanelAttribute(handle, ATTR_TITLE, "TXT 2 UCF");
DisplayPanel (handle);
RunUserInterface ();
DiscardPanel (handle);
CloseCVIRTE ();
return 0;
}
/*---------------------------------------------------------------------------*/
/* Plot some data to the Graph control. */
/*---------------------------------------------------------------------------*/
int outstring(int i,char string1[])
{
int l,p;
l = strlen(string1);
for(p=0;p<l;p++)
{
outfile[i+p] = string1[p];
}
return i+l;
}
int CVICALLBACK Plot (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
int x,i,j,k;
char Pin[PIN_COUNT][10];
char Net[PIN_COUNT][40];
char temp[40];
if (event == EVENT_COMMIT)
{
//----------------------------------------------------------
i=0;
for(k=0;k<PIN_COUNT;k++)
{
for(;i<IN_COUNT;i++)//找引脚
{
if(infile[i]=='.') break;
}
if(i>=IN_COUNT) break;
for(j=0;j<10;j++) Pin[k][j]=0;
for(j=1;j<11;j++)//拷贝引脚
{
Pin[k][j-1] = infile[i+j];
if(infile[i+j+1]=='[')
{
i=i+j;
break;
}
}
//////
for(;i<IN_COUNT;i++)//找网表
{
if(infile[i]==']') break;
}
if(i>=IN_COUNT) break;
for(j=0;j<20;j++) Net[k][j]=0;
for(j=2;j<22;j++)//拷贝网表
{
Net[k][j-2] = infile[i+j];
if(infile[i+j+1]==' ' || infile[i+j+1]==0x0d)
{
i=i+j;
break;
}
}
if(infile[i+4]==0 && infile[i+5]==0) break;//找结束
}
PinCount = k;
//----------------------------------------------------------
//替换网表
GetCtrlVal (panel, Examp1_CHECKBOX_2, &x);
if(x==1)
{
for(i=0;i<PinCount;i++)
{
k = strlen(Net[i]);
if(Net[i][k-1]<='9' && Net[i][k-1]>='0' )
{
if(Net[i][k-2]<='9' && Net[i][k-2]>='0' )
{
if(Net[i][k-3]<='9' && Net[i][k-3]>='0' )
{
Net[i][k+1] = '>' ;
Net[i][k]=Net[i][k-1] ;
Net[i][k-1]=Net[i][k-2] ;
Net[i][k-2]=Net[i][k-3] ;
Net[i][k-3] = '<' ;
}
else
{
Net[i][k+1] = '>' ;
Net[i][k]=Net[i][k-1] ;
Net[i][k-1]=Net[i][k-2] ;
Net[i][k-2] = '<' ;
}
}
else
{
Net[i][k+1] = '>' ;
Net[i][k]=Net[i][k-1] ;
Net[i][k-1] = '<' ;
}
}
}
}
//----------------------------------------------------------
/*冒泡排序
for(i=n-2;i>=0;i--)
for(j=n-1;j>=n-i-1;j--)
{
if(strcmp(str[j],str[j-1])<0)
{
strcpy(temp,str[j]);
strcpy(str[j],str[j-1]);
strcpy(str[j-1],temp);
}
}
*/
//顺序排序
GetCtrlVal (panel, Examp1_CHECKBOX, &x);
if(x==1)
{
for(i=0;i<PinCount-1;i++)
{
for(j=i+1;j<PinCount;j++)
{
if( strlen(Net[j]) < strlen(Net[i]) )
{
strcpy(temp,Net[j]);
strcpy(Net[j],Net[i]);
strcpy(Net[i],temp);
strcpy(temp,Pin[j]);
strcpy(Pin[j],Pin[i]);
strcpy(Pin[i],temp);
}
if( strlen(Net[j]) == strlen(Net[i]) )
{
if(strcmp(Net[j],Net[i])<0)
{
strcpy(temp,Net[j]);
strcpy(Net[j],Net[i]);
strcpy(Net[i],temp);
strcpy(temp,Pin[j]);
strcpy(Pin[j],Pin[i]);
strcpy(Pin[i],temp);
}
}
}
}
}
//----------------------------------------------------------
GetCtrlVal (panel, Examp1_select, &x);
if(x==0)
{
for (i=0;i<OUT_COUNT;i++) outfile[i] = 0 ;
i=0;
for(k=0;k<PinCount;k++)
{
i = outstring( i , "NET \"");
i = outstring(i,Net[k]);
i = outstring(i,"\" LOC=\"");
i = outstring(i,Pin[k]);
i = outstring(i,"\" | IOSTANDARD=LVTTL;#\n");
}
OutCount=i;
}
else
{
for (i=0;i<OUT_COUNT;i++) outfile[i] = 0 ;
i=0;
for(k=0;k<PinCount;k++)
{
i = outstring( i , "set_location_assignment PIN_");
i = outstring(i,Pin[k]);
i = outstring(i," -to ");
i = outstring(i,Net[k]);
i = outstring(i,"\n");
}
OutCount=i;
}
//DeleteGraphPlot (handle, Examp1_Graph, -1, 1);
//PlotY (handle, Examp1_Graph, wave, COUNT, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
SetCtrlAttribute (handle, Examp1_Save, ATTR_DIMMED, 0);
}
return 0;
}
/*---------------------------------------------------------------------------*/
/* This function brings up a File Selection dialog and allows you to enter a */
/* file name with a .dat extension. After the file name is entered or */
/* selected, that file is opened and assigned a file handle. */
/* This file handle is used anytime action is performed on the file. The */
/* file is written using the ArrayToFile function, then closed. */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Save (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
int i;
int fileType;
if (event == EVENT_COMMIT)
{
if (FileSelectPopup (proj_dir, "*.txt", "*.txt",
"Name of File to Save", VAL_OK_BUTTON, 0, 1, 1,
0, file_name) > 0)
{
//GetCtrlVal (handle, Examp1_OutputType, &fileType);
ArrayToFile (file_name, outfile, VAL_CHAR, OutCount, 1,
VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS,
VAL_CONST_WIDTH, 10, VAL_BINARY, VAL_TRUNCATE);
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
/* Read data from the file into our array, then plot it. */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Read (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
int i;
int status;
int fileType;
if (event == EVENT_COMMIT)
{
if (FileSelectPopup ("", "*.txt", "*.txt", "Name of File to Read",
VAL_OK_BUTTON, 0, 1, 1, 0, file_name) > 0)
{
//GetCtrlVal (handle, Examp1_InputType, &fileType);
for(i=0;i<IN_COUNT;i++) infile[i]=0;
FileToArray (file_name, infile, VAL_CHAR, IN_COUNT, 1,
VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS, VAL_BINARY);
SetCtrlAttribute (handle, Examp1_Plot, ATTR_DIMMED, 0);
SetCtrlAttribute (handle, Examp1_Save, ATTR_DIMMED, 1);
//DeleteGraphPlot (handle, Examp1_Graph2, -1, 1);
//PlotY (handle, Examp1_Graph2, wave, COUNT, VAL_DOUBLE,VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_RED);
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
/* Quit the application */
/*---------------------------------------------------------------------------*/
int CVICALLBACK Quit (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
QuitUserInterface (0);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -