翻译一下function format = stlGetFormat(fileName) %STLGETFORMAT identifies the format of the STL file and returns 'binary' or %'ascii' fid = fopen(fileName); % Check the file size first, since binary files MUST have a size of 84+(50*n) fseek(fid,0,1); % Go to the end of the file fidSIZE = ftell(fid); % Check the size of the file if rem(fidSIZE-84,50) > 0 format = 'ascii'; else % Files with a size of 84+(50*n), might be either ascii or binary... % Read first 80 characters of the file. % For an ASCII file, the data should begin immediately (give or take a few % blank lines or spaces) and the first word must be 'solid'. % For a binary file, the first 80 characters contains the header. % It is bad practice to begin the header of a binary file with the word % 'solid', so it can be used to identify whether the file is ASCII or % binary. fseek(fid,0,-1); % go to the beginning of the file header = strtrim(char(fread(fid,80,'uchar')')); % trim leading and trailing spaces isSolid = strcmp(header(1:min(5,length(header))),'solid'); % take first 5 char fseek(fid,-80,1); % go to the end of the file minus 80 characters tail = char(fread(fid,80,'uchar')'); isEndSolid = findstr(tail,'endsolid'); % Double check by reading the last 80 characters of the file. % For an ASCII file, the data should end (give or take a few % blank lines or spaces) with 'endsolid <object_name>'. % If the last 80 characters contains the word 'endsolid' then this % confirms that the file is indeed ASCII. if isSolid & isEndSolid format = 'ascii'; else format = 'binary'; end end fclose(fid);
时间: 2023-06-24 19:09:00 浏览: 95
这段代码的作用是识别STL文件的格式并返回'binary'或'ascii'。首先打开文件并检查文件大小,如果文件大小为84+(50*n),则该文件可能是ASCII或二进制格式。接着读取文件的前80个字符,并检查第一个单词是否为'solid'。如果是,则该文件为ASCII格式;否则,该文件为二进制格式。最后关闭文件并返回格式。
相关问题
以下是一篇即将投稿Minerals期刊(MDPI出版社)的论文初稿的部分内容,请按照该期刊对论文格式的要求,将以下内容进行压缩凝练(注意:可对内容进行删减,对错误进行修正,对语句顺序进行调整,符合美式英语标准,符合英语母语者语言习惯,句子简明易懂,术语使用准确,保留文章结构、不偏离论文主要内容): Rocks and ore components directly enter the soil and water system sediments through physical weathering and chemical weathering, and the geochemical anomalies originally present in the rocks further spread with the entry into the soil or directly into the water system, forming soil anomalies and water system sediment anoma-lies.Geochemical anomaly detection is essentially the detection of signal anomalies in geochemical data, which refers to finding out the anomalous distribution of chemical elements themselves and the anomalous distribution of multiple elements in combination through feature extraction and analysis processing of geochemical data in the study area, and reflecting the mineral distribution through the distribution of geochemical ele-ments.Through the method of geochemical anomaly finding, the detected anomalies may contain information indicating specific minerals, which facilitates the rapid tracing of prospective areas and favorable areas for mineralization, identifies possible mineralizing elements and distribution characteristics in the work area, provides basic information for the strategic deployment of mineralization search, and provides good indications for later mineralization search.
Rocks and ore components enter soil and water system sediments through physical and chemical weathering, causing the spread of geochemical anomalies. Detecting geochemical anomalies involves identifying anomalous chemical element distributions through feature extraction and analysis of geochemical data. These anomalies can reveal specific minerals and their distribution characteristics, aiding in the identification of prospective mineralization areas and elements. Geochemical anomaly detection provides valuable information for strategic mineralization search deployment and subsequent exploration efforts.
Consider the following information about the pharmacies, patients and drugs: ● (1) Patients are identified by an SSN, and their names, addresses, and ages must be recorded. ● (2) Doctors are identified by an SSN. For each doctor, the name, specialty, and years of experience must be recorded. ● (3) Each pharmaceutical company (制药公司) is identified by name and has a phone number. ● (4) For each drug, the trade name and formula(成份)must be recorded. Each drug is produced by a given pharmaceutical company, and the trade name identifies a drug uniquely from among the products of that company. ● (5) Each pharmacy(药房) has a name, address, and phone number. Each pharmacy is identified by ID. ●(6) Every patient has a primary doctor. Every doctor has at least one patient. ● (7) Each pharmacy sells several drugs and has a price for each. A drug could be sold at several pharmacies, and the price could vary from one pharmacy to another. ● (8) Doctors prescribe drugs for patients. A doctor could prescribe one or more drugs for several patients, and a patient could obtain prescriptions from several doctors. Each prescription has a date and a quantity associated with it. ●(9) Pharmaceutical companies have long term contracts with pharmacies. A pharmaceutical company can contract with several pharmacies, and a pharmacy can contract with several pharmaceutical companies. For each contract, you have to store a start date, an end date. 用ER图进行描述用python代码表示
根据上述信息,可以设计以下实体和关系:
实体:
- Patient (SSN, Name, Address, Age)
- Doctor (SSN, Name, Specialty, Years of Experience)
- Pharmaceutical Company (Name, Phone Number)
- Drug (Trade Name, Formula)
- Pharmacy (ID, Name, Address, Phone Number)
关系:
- Produces (Pharmaceutical Company, Trade Name)
- Sells (Pharmacy, Trade Name, Price)
- Prescribes (Doctor, SSN, Trade Name, Patient, SSN, Date, Quantity)
- Contracts (Pharmaceutical Company, Pharmacy, Start Date, End Date)
- Has Primary Doctor (Patient, SSN, Doctor, SSN)
以下是用Python代码表示的实体和关系:
```python
# 实体类
class Patient:
def __init__(self, ssn, name, address, age):
self.ssn = ssn
self.name = name
self.address = address
self.age = age
class Doctor:
def __init__(self, ssn, name, specialty, years_of_experience):
self.ssn = ssn
self.name = name
self.specialty = specialty
self.years_of_experience = years_of_experience
class PharmaceuticalCompany:
def __init__(self, name, phone_number):
self.name = name
self.phone_number = phone_number
class Drug:
def __init__(self, trade_name, formula, pharmaceutical_company):
self.trade_name = trade_name
self.formula = formula
self.pharmaceutical_company = pharmaceutical_company
class Pharmacy:
def __init__(self, id, name, address, phone_number):
self.id = id
self.name = name
self.address = address
self.phone_number = phone_number
# 关系类
class Produces:
def __init__(self, pharmaceutical_company, drug):
self.pharmaceutical_company = pharmaceutical_company
self.drug = drug
class Sells:
def __init__(self, pharmacy, drug, price):
self.pharmacy = pharmacy
self.drug = drug
self.price = price
class Prescribes:
def __init__(self, doctor, patient, drug, date, quantity):
self.doctor = doctor
self.patient = patient
self.drug = drug
self.date = date
self.quantity = quantity
class Contracts:
def __init__(self, pharmaceutical_company, pharmacy, start_date, end_date):
self.pharmaceutical_company = pharmaceutical_company
self.pharmacy = pharmacy
self.start_date = start_date
self.end_date = end_date
class HasPrimaryDoctor:
def __init__(self, patient, doctor):
self.patient = patient
self.doctor = doctor
```
注意:上述代码只是一种示例实现,具体实现方式可能会因具体情况而有所不同。
阅读全文